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 e04ea2b304f96f0bc3e3c80e013ff43918bbac47..bfadca239903a8988c083d31a916c9b846ac6eaf 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
@@ -283,6 +283,8 @@ void HTMLCanvasElement::didDraw(const FloatRect& rect) |
void HTMLCanvasElement::didFinalizeFrame() |
{ |
+ notifyListenersCanvasChanged(); |
+ |
if (m_dirtyRect.isEmpty()) |
return; |
@@ -393,13 +395,41 @@ 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; |
+ } |
+ |
+ bool listenerNeedsNewFrameCapture = false; |
+ for (CanvasDrawListener* listener : m_listeners) { |
esprehn
2015/12/03 18:47:34
const ?
emircan
2015/12/04 03:23:25
Done.
|
+ if (listener->needsNewFrameCapture()) { |
+ listenerNeedsNewFrameCapture = true; |
+ } |
+ } |
+ |
+ if (listenerNeedsNewFrameCapture) { |
+ SourceImageStatus status; |
+ RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferNoAcceleration); |
+ if (status != NormalSourceImageStatus) |
+ return; |
+ RefPtr<SkImage> image = sourceImage->imageForCurrentFrame(); |
+ for (CanvasDrawListener* listener : m_listeners) { |
+ if (listener->needsNewFrameCapture()) { |
+ listener->sendNewFrame(image); |
+ } |
+ } |
+ } |
+ |
+} |
+ |
void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) |
{ |
// FIXME: crbug.com/438240; there is a bug with the new CSS blending and compositing feature. |
@@ -568,6 +598,16 @@ void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c |
} |
} |
+void HTMLCanvasElement::addListener(CanvasDrawListener* listener) |
+{ |
+ m_listeners.add(listener); |
+} |
+ |
+void HTMLCanvasElement::removeListener(CanvasDrawListener* listener) |
+{ |
+ m_listeners.remove(listener); |
+} |
+ |
SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
{ |
return document().securityOrigin(); |
@@ -743,6 +783,7 @@ void HTMLCanvasElement::notifySurfaceInvalid() |
DEFINE_TRACE(HTMLCanvasElement) |
{ |
+ visitor->trace(m_listeners); |
visitor->trace(m_context); |
DocumentVisibilityObserver::trace(visitor); |
HTMLElement::trace(visitor); |