Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1030)

Unified Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 1234083003: Canvas.toDataURL to use SkBitmap::readPixels to avoid uninitialized memory (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rearranged Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLCanvasElement.cpp
diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp
index a41bd5beb6c08ff3077a3349eed785e68b5293e3..4c6bd64d722fe2fc693610e29db1cccfbf9310e2 100644
--- a/Source/core/html/HTMLCanvasElement.cpp
+++ b/Source/core/html/HTMLCanvasElement.cpp
@@ -469,22 +469,30 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
return String("data:,");
String encodingMimeType = toEncodingMimeType(mimeType);
- if (!m_context) {
- ImageData* imageData = ImageData::create(m_size);
- ScopedDisposal<ImageData> disposer(imageData);
- return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality);
- }
- if (m_context->is3d()) {
+ if (is3D()) {
// Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
ImageData* imageData = m_context->paintRenderingResultsToImageData(sourceBuffer);
ScopedDisposal<ImageData> disposer(imageData);
- if (imageData)
+ if (imageData) {
Stephen White 2015/07/16 19:13:01 I think this would be clearer and have less code d
return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality);
+ }
m_context->paintRenderingResultsToCanvas(sourceBuffer);
+ imageData = ImageData::create(m_size);
+ ScopedDisposal<ImageData> disposer2(imageData);
+ return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality);
+ }
+
+ ImageData* imageData = ImageData::create(m_size);
+ ScopedDisposal<ImageData> disposer(imageData);
+
+ if (m_context) {
+ ASSERT(m_context->is2d());
+ SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
+ buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imageInfo.minRowBytes(), 0, 0);
}
- return buffer()->toDataURL(encodingMimeType, quality);
+ return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality);
}
String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& qualityArgument, ExceptionState& exceptionState) const
« no previous file with comments | « no previous file | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698