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

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: Added new interface to LayoutTests. Created 5 years 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 3b5b5c4d0c1f043cee3d8dff903fc75d1bff9dfe..a4cf6dee2a14d274e7be11a4520aab3b9871ca3a 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 (const CanvasDrawListener* listener : m_listeners) {
+ if (listener->needsNewFrame()) {
+ 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->needsNewFrame()) {
+ 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.
@@ -566,6 +596,16 @@ void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c
asyncCreatorRef->scheduleAsyncBlobCreation(false, quality);
}
+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();
@@ -741,6 +781,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