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

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: Rebase 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 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);

Powered by Google App Engine
This is Rietveld 408576698