Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| index fbae8739478899e73a50fbdd7910a19c98595335..422cc3cceb9130447c2f2ee54d9cef140697274c 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| @@ -32,6 +32,7 @@ |
| #include "bindings/core/v8/ScriptController.h" |
| #include "core/HTMLNames.h" |
| #include "core/InputTypeNames.h" |
| +#include "core/dom/DOMNodeIds.h" |
|
xidachen
2016/11/11 16:54:00
Do we need to include this header here?
Justin Novosad
2016/11/11 22:09:00
Done.
|
| #include "core/dom/Document.h" |
| #include "core/dom/Element.h" |
| #include "core/dom/ElementTraversal.h" |
| @@ -145,6 +146,8 @@ HTMLCanvasElement::~HTMLCanvasElement() { |
| } |
| void HTMLCanvasElement::dispose() { |
| + releasePlaceholderFrame(); |
| + |
| if (m_context) { |
| m_context->detachCanvas(); |
| m_context = nullptr; |
| @@ -470,8 +473,9 @@ void HTMLCanvasElement::reset() { |
| } |
| bool HTMLCanvasElement::paintsIntoCanvasBuffer() const { |
| + if (placeholderFrame()) |
| + return false; |
| DCHECK(m_context); |
| - |
| if (!m_context->isAccelerated()) |
| return true; |
| if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) |
| @@ -515,7 +519,7 @@ void HTMLCanvasElement::notifyListenersCanvasChanged() { |
| void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) { |
| // FIXME: crbug.com/438240; there is a bug with the new CSS blending and |
| // compositing feature. |
| - if (!m_context) |
| + if (!m_context && !placeholderFrame()) |
| return; |
| const ComputedStyle* style = ensureComputedStyle(); |
| @@ -536,6 +540,12 @@ void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) { |
| if (!paintsIntoCanvasBuffer() && !document().printing()) |
| return; |
| + if (placeholderFrame()) { |
| + DCHECK(document().printing()); |
| + context.drawImage(placeholderFrame().get(), pixelSnappedIntRect(r)); |
| + return; |
| + } |
| + |
| // TODO(junov): Paint is currently only implemented by ImageBitmap contexts. |
| // We could improve the abstraction by making all context types paint |
| // themselves (implement paint()). |
| @@ -619,19 +629,22 @@ ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer, |
| imageData = ImageData::create(m_size); |
| - if (!m_context || !imageData) |
| + if ((!m_context || !imageData) && !placeholderFrame()) |
| return imageData; |
| - DCHECK(m_context->is2d()); |
| + DCHECK((m_context && m_context->is2d()) || placeholderFrame()); |
| + sk_sp<SkImage> snapshot; |
| if (hasImageBuffer()) { |
| - sk_sp<SkImage> snapshot = |
| - buffer()->newSkImageSnapshot(PreferNoAcceleration, reason); |
| - if (snapshot) { |
| - SkImageInfo imageInfo = SkImageInfo::Make( |
| - width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); |
| - snapshot->readPixels(imageInfo, imageData->data()->data(), |
| - imageInfo.minRowBytes(), 0, 0); |
| - } |
| + snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason); |
| + } else if (placeholderFrame()) { |
| + snapshot = placeholderFrame()->imageForCurrentFrame(); |
| + } |
| + |
| + if (snapshot) { |
| + SkImageInfo imageInfo = SkImageInfo::Make( |
| + width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); |
| + snapshot->readPixels(imageInfo, imageData->data()->data(), |
| + imageInfo.minRowBytes(), 0, 0); |
| } |
| return imageData; |
| @@ -683,13 +696,6 @@ String HTMLCanvasElement::toDataURLInternal( |
| String HTMLCanvasElement::toDataURL(const String& mimeType, |
| const ScriptValue& qualityArgument, |
| ExceptionState& exceptionState) const { |
| - if (surfaceLayerBridge()) { |
| - exceptionState.throwDOMException(InvalidStateError, |
| - "canvas.toDataURL is not allowed for a " |
| - "canvas that has transferred its control " |
| - "to offscreen."); |
| - return String(); |
| - } |
| if (!originClean()) { |
| exceptionState.throwSecurityError("Tainted canvases may not be exported."); |
| return String(); |
| @@ -709,14 +715,6 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback, |
| const String& mimeType, |
| const ScriptValue& qualityArgument, |
| ExceptionState& exceptionState) { |
| - if (surfaceLayerBridge()) { |
| - exceptionState.throwDOMException(InvalidStateError, |
| - "canvas.toBlob is not allowed for a " |
| - "canvas that has transferred its control " |
| - "to offscreen."); |
| - return; |
| - } |
| - |
| if (!originClean()) { |
| exceptionState.throwSecurityError("Tainted canvases may not be exported."); |
| return; |
| @@ -1200,6 +1198,11 @@ PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas( |
| return nullptr; |
| } |
| + if (placeholderFrame()) { |
| + *status = NormalSourceImageStatus; |
| + return placeholderFrame(); |
| + } |
| + |
| if (!m_context) { |
| *status = NormalSourceImageStatus; |
| return createTransparentImage(size()); |