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

Unified Diff: Source/core/html/HTMLVideoElement.cpp

Issue 181693006: Refactoring source image usage in CanvasRenderingContext2D (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months 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: Source/core/html/HTMLVideoElement.cpp
diff --git a/Source/core/html/HTMLVideoElement.cpp b/Source/core/html/HTMLVideoElement.cpp
index d0b8b8d57e1bbd379de5dc66273ee639758867a4..13aa49d32cc3437d43f0218133bc36999e3d2cdd 100644
--- a/Source/core/html/HTMLVideoElement.cpp
+++ b/Source/core/html/HTMLVideoElement.cpp
@@ -33,6 +33,7 @@
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/html/HTMLImageLoader.h"
+#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/frame/Settings.h"
#include "core/rendering/RenderImage.h"
@@ -173,7 +174,7 @@ void HTMLVideoElement::updateDisplayState()
setDisplayMode(Poster);
}
-void HTMLVideoElement::paintCurrentFrameInContext(GraphicsContext* context, const IntRect& destRect)
+void HTMLVideoElement::paintCurrentFrameInContext(GraphicsContext* context, const IntRect& destRect) const
{
MediaPlayer* player = HTMLMediaElement::player();
if (!player)
@@ -232,4 +233,32 @@ KURL HTMLVideoElement::mediaPlayerPosterURL()
return posterImageURL();
}
+PassRefPtr<Image> HTMLVideoElement::getSourceImageForCanvas(HTMLCanvasElement* canvas, ExceptionState& exceptionState, CanvasImageSourceUsage usage, bool* isVolatile) const
+{
+ ASSERT(usage != DrawCanvasImageSourceUsage); // Drawing should use paintCurrentFrameInContext
+ if (isVolatile)
+ *isVolatile = false;
+ if (!hasAvailableVideoFrame())
+ return nullptr;
+
+ IntSize intrinsicSize(videoWidth(), videoHeight());
+ OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(intrinsicSize);
+ if (!imageBuffer)
+ return nullptr;
+
+ paintCurrentFrameInContext(imageBuffer->context(), IntRect(IntPoint(0, 0), intrinsicSize));
+
+ return imageBuffer->copyImage(imageBuffer->fastCopyImageMode(), Unscaled);
+}
+
+bool HTMLVideoElement::wouldTaintOrigin(CanvasRenderingContext* destinationContext) const
+{
+ return !hasSingleSecurityOrigin() || (!(player() && player()->didPassCORSAccessCheck()) && destinationContext->wouldTaintOrigin(currentSrc()));
+}
+
+FloatSize HTMLVideoElement::sourceSize() const
+{
+ return FloatSize(videoWidth(), videoHeight());
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698