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

Side by Side Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 1236173005: Revert of Canvas.toDataURL to use SkBitmap::readPixels to avoid uninitialized memory (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
484 if (m_context) {
485 ASSERT(m_context->is2d());
486 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType);
487 buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imag eInfo.minRowBytes(), 0, 0);
488 }
489 return imageData;
490 }
491
492 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const 466 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const
493 { 467 {
494 if (!isPaintable()) 468 if (!isPaintable())
495 return String("data:,"); 469 return String("data:,");
496 470
497 String encodingMimeType = toEncodingMimeType(mimeType); 471 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 }
498 477
499 ImageData* imageData = toImageData(sourceBuffer); 478 if (m_context->is3d()) {
500 ScopedDisposal<ImageData> disposer(imageData); 479 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
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 }
501 486
502 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality); 487 return buffer()->toDataURL(encodingMimeType, quality);
503 } 488 }
504 489
505 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const 490 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const
506 { 491 {
507 if (!originClean()) { 492 if (!originClean()) {
508 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); 493 exceptionState.throwSecurityError("Tainted canvases may not be exported. ");
509 return String(); 494 return String();
510 } 495 }
511 double quality; 496 double quality;
512 double* qualityPtr = nullptr; 497 double* qualityPtr = nullptr;
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 { 861 {
877 return FloatSize(width(), height()); 862 return FloatSize(width(), height());
878 } 863 }
879 864
880 bool HTMLCanvasElement::isOpaque() const 865 bool HTMLCanvasElement::isOpaque() const
881 { 866 {
882 return m_context && !m_context->hasAlpha(); 867 return m_context && !m_context->hasAlpha();
883 } 868 }
884 869
885 } // blink 870 } // 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