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

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: batter asan fix 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
Index: Source/core/html/HTMLCanvasElement.cpp
diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp
index a41bd5beb6c08ff3077a3349eed785e68b5293e3..a6b3d958f42631f5ebcfa7fbb1413c2180284ed3 100644
--- a/Source/core/html/HTMLCanvasElement.cpp
+++ b/Source/core/html/HTMLCanvasElement.cpp
@@ -463,28 +463,43 @@ const AtomicString HTMLCanvasElement::imageSourceURL() const
return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer));
}
+ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) const
+{
+ ImageData* imageData;
+ if (is3D()) {
+ // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
+ imageData = m_context->paintRenderingResultsToImageData(sourceBuffer);
+ if (imageData)
+ return imageData;
+
+ m_context->paintRenderingResultsToCanvas(sourceBuffer);
+ imageData = ImageData::create(m_size);
+ SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
+ buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imageInfo.minRowBytes(), 0, 0);
+ return imageData;
+ }
+
+ imageData = ImageData::create(m_size);
+
+ 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 imageData;
+}
+
String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double* quality, SourceDrawingBuffer sourceBuffer) const
{
if (!isPaintable())
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()) {
- // 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)
- return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality);
- m_context->paintRenderingResultsToCanvas(sourceBuffer);
- }
+ ImageData* imageData = toImageData(sourceBuffer);
+ ScopedDisposal<ImageData> disposer(imageData);
- 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

Powered by Google App Engine
This is Rietveld 408576698