summaryrefslogtreecommitdiffstats
path: root/WebCore/platform
diff options
context:
space:
mode:
authorCary Clark <cary@android.com>2010-05-24 10:44:10 -0400
committerCary Clark <cary@android.com>2010-05-24 10:44:10 -0400
commitded190db41af0886b9cf1a4a86597e8d8dd06d5d (patch)
treef576af75b30251543c39083343ffce59e1323723 /WebCore/platform
parenta6b27f6414840349e0cc946ce02d9e9f37a12340 (diff)
downloadexternal_webkit-ded190db41af0886b9cf1a4a86597e8d8dd06d5d.zip
external_webkit-ded190db41af0886b9cf1a4a86597e8d8dd06d5d.tar.gz
external_webkit-ded190db41af0886b9cf1a4a86597e8d8dd06d5d.tar.bz2
implement Canvas.toDataURL
The Chrome implementation serves as the base for this code. The test is at http://philip.html5.org/tests/canvas/suite/tests/index.toDataURL.html Change-Id: I873518362793fbe1c99686fbe240cfe7c27d1493 http://b/2620678
Diffstat (limited to 'WebCore/platform')
-rw-r--r--WebCore/platform/graphics/android/ImageBufferAndroid.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/WebCore/platform/graphics/android/ImageBufferAndroid.cpp b/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
index 6efccfe..92c585f 100644
--- a/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
+++ b/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
@@ -24,11 +24,11 @@
*/
#include "config.h"
-#include "BitmapImage.h"
#include "ImageBuffer.h"
-#include "ImageData.h"
-#include "NotImplemented.h"
+#include "Base64.h"
+#include "BitmapImage.h"
+#include "ImageData.h"
#include "android_graphics.h"
#include "GraphicsContext.h"
#include "PlatformGraphicsContext.h"
@@ -36,6 +36,8 @@
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkDevice.h"
+#include "SkImageEncoder.h"
+#include "SkStream.h"
#include "SkUnPreMultiply.h"
using namespace std;
@@ -208,10 +210,22 @@ void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sou
String ImageBuffer::toDataURL(const String&) const
-{
- // leaving this unimplemented, until I understand what its for (and what it
- // really is).
- return "data:,"; // I think this means we couldn't make the data url
+{
+ // Encode the image into a vector.
+ SkDynamicMemoryWStream pngStream;
+ const SkBitmap& dst = android_gc2canvas(context())->getDevice()->accessBitmap(true);
+ SkImageEncoder::EncodeStream(&pngStream, dst, SkImageEncoder::kPNG_Type, 100);
+
+ // Convert it into base64.
+ Vector<char> pngEncodedData;
+ pngEncodedData.append(pngStream.getStream(), pngStream.getOffset());
+ Vector<char> base64EncodedData;
+ base64Encode(pngEncodedData, base64EncodedData);
+ // Append with a \0 so that it's a valid string.
+ base64EncodedData.append('\0');
+
+ // And the resulting string.
+ return String::format("data:image/png;base64,%s", base64EncodedData.data());
}
}