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

Side by Side 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: added toImageData 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLCanvasElement.h ('k') | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 lowercaseMimeType = "image/png"; 456 lowercaseMimeType = "image/png";
457 457
458 return lowercaseMimeType; 458 return lowercaseMimeType;
459 } 459 }
460 460
461 const AtomicString HTMLCanvasElement::imageSourceURL() const 461 const AtomicString HTMLCanvasElement::imageSourceURL() const
462 { 462 {
463 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); 463 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer));
464 } 464 }
465 465
466 ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) cons t
467 {
468 ImageData* imageData;
469 if (is3D()) {
470 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
471 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer);
472 if (imageData)
473 return imageData;
474
475 m_context->paintRenderingResultsToCanvas(sourceBuffer);
476 imageData = ImageData::create(m_size);
477 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType);
478 buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imag eInfo.minRowBytes(), 0, 0);
479 return imageData;
480 }
481
482 imageData = ImageData::create(m_size);
483 ScopedDisposal<ImageData> disposer(imageData);
Stephen White 2015/07/16 22:09:41 It looks like this ScopedDisposal is going to clea
484
485 if (m_context) {
486 ASSERT(m_context->is2d());
487 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType);
488 buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imag eInfo.minRowBytes(), 0, 0);
489 }
490 return imageData;
491 }
492
466 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const 493 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const
467 { 494 {
468 if (!isPaintable()) 495 if (!isPaintable())
469 return String("data:,"); 496 return String("data:,");
470 497
471 String encodingMimeType = toEncodingMimeType(mimeType); 498 String encodingMimeType = toEncodingMimeType(mimeType);
472 if (!m_context) {
473 ImageData* imageData = ImageData::create(m_size);
474 ScopedDisposal<ImageData> disposer(imageData);
475 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toD ataURL(encodingMimeType, quality);
476 }
477 499
478 if (m_context->is3d()) { 500 ImageData* imageData = toImageData(sourceBuffer);
479 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). 501 ScopedDisposal<ImageData> disposer(imageData);
480 ImageData* imageData = m_context->paintRenderingResultsToImageData(sourc eBuffer);
481 ScopedDisposal<ImageData> disposer(imageData);
482 if (imageData)
483 return ImageDataBuffer(imageData->size(), imageData->data()->data()) .toDataURL(encodingMimeType, quality);
484 m_context->paintRenderingResultsToCanvas(sourceBuffer);
485 }
486 502
487 return buffer()->toDataURL(encodingMimeType, quality); 503 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality);
488 } 504 }
489 505
490 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const 506 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const
491 { 507 {
492 if (!originClean()) { 508 if (!originClean()) {
493 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); 509 exceptionState.throwSecurityError("Tainted canvases may not be exported. ");
494 return String(); 510 return String();
495 } 511 }
496 double quality; 512 double quality;
497 double* qualityPtr = nullptr; 513 double* qualityPtr = nullptr;
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 { 877 {
862 return FloatSize(width(), height()); 878 return FloatSize(width(), height());
863 } 879 }
864 880
865 bool HTMLCanvasElement::isOpaque() const 881 bool HTMLCanvasElement::isOpaque() const
866 { 882 {
867 return m_context && !m_context->hasAlpha(); 883 return m_context && !m_context->hasAlpha();
868 } 884 }
869 885
870 } // blink 886 } // blink
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCanvasElement.h ('k') | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698