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

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 1467103003: Basic use implementation for MediaStream from Canvas: captureStream() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@ comments. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..08952acdae436450bb6d318ce56846109d988cbe 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,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);
esprehn 2015/12/01 20:04:26 getSourceImageForCanvas is expensive I think it se
emircan 2015/12/01 21:07:34 Done. My bad, I was initially designing it with a
+ 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.
@@ -568,6 +587,17 @@ void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c
}
}
+void HTMLCanvasElement::addListener(CanvasDrawListener* listener)
+{
+ m_listeners.add(listener);
+ notifyListenersCanvasChanged();
esprehn 2015/12/01 20:04:26 hmm, this means we do a sync readback the first ti
emircan 2015/12/01 21:07:34 I see that frame might not be completed. I was try
+}
+
+void HTMLCanvasElement::removeListener(CanvasDrawListener* listener)
+{
+ m_listeners.remove(listener);
+}
+
SecurityOrigin* HTMLCanvasElement::securityOrigin() const
{
return document().securityOrigin();
@@ -743,6 +773,7 @@ void HTMLCanvasElement::notifySurfaceInvalid()
DEFINE_TRACE(HTMLCanvasElement)
{
+ visitor->trace(m_listeners);
visitor->trace(m_context);
DocumentVisibilityObserver::trace(visitor);
HTMLElement::trace(visitor);

Powered by Google App Engine
This is Rietveld 408576698