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 47dfe4296a9a8aeefa3b9b225774817d354caf02..b0dcd8582e59b60aac7f91631e04567e345ef9e2 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
@@ -282,6 +282,8 @@ void HTMLCanvasElement::didDraw(const FloatRect& rect) |
void HTMLCanvasElement::didFinalizeFrame() |
{ |
+ notifyListenersCanvasChanged(); |
+ |
if (m_dirtyRect.isEmpty()) |
return; |
@@ -392,13 +394,30 @@ bool HTMLCanvasElement::paintsIntoCanvasBuffer() const |
if (!m_context->isAccelerated()) |
return true; |
- |
if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) |
return false; |
return true; |
} |
+void HTMLCanvasElement::notifyListenersCanvasChanged() |
+{ |
+ if (!originClean()) { |
+ m_listeners.clear(); |
+ return; |
+ } |
+ |
+ for (CanvasDrawListener* listener : m_listeners) { |
+ if (listener->needsNewFrameCapture()) { |
+ SourceImageStatus status; |
+ RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferNoAcceleration); |
+ if (status != NormalSourceImageStatus) |
+ return; |
+ listener->setNewFrameCapture(sourceImage->imageForCurrentFrame()); |
+ } |
+ } |
+} |
+ |
void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) |
{ |
// FIXME: crbug.com/438240; there is a bug with the new CSS blending and compositing feature. |
@@ -567,6 +586,17 @@ void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c |
} |
} |
+void HTMLCanvasElement::addListener(CanvasDrawListener* listener) |
+{ |
+ m_listeners.add(listener); |
+ notifyListenersCanvasChanged(); |
+} |
+ |
+void HTMLCanvasElement::removeListener(CanvasDrawListener* listener) |
+{ |
+ m_listeners.remove(listener); |
+} |
+ |
SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
{ |
return document().securityOrigin(); |
@@ -742,6 +772,7 @@ void HTMLCanvasElement::notifySurfaceInvalid() |
DEFINE_TRACE(HTMLCanvasElement) |
{ |
+ visitor->trace(m_listeners); |
visitor->trace(m_context); |
DocumentVisibilityObserver::trace(visitor); |
HTMLElement::trace(visitor); |