- Revision
- 294057
- Author
- [email protected]
- Date
- 2022-05-11 10:20:36 -0700 (Wed, 11 May 2022)
Log Message
Introduce a canvas-drawImage specific method to get a NativeImage from a video element
https://bugs.webkit.org/show_bug.cgi?id=240275
Reviewed by Eric Carlson.
Source/WebCore:
Introduce shouldGetNativeImageForCanvasDrawing in HTMLVideoElement/MediaPlayer/MediaPlayerPrivate.
If returning true, we call videoFrameForCurrentTime when drawing a video to canvas.
Otherwise, we directly use video.paintCurrentFrameInContext code path.
This allows skipping a code path where videoFrameForCurrentTime is less efficient than video.paintCurrentFrameInContext.
Covered by existing canvas tests.
* html/HTMLVideoElement.cpp:
* html/HTMLVideoElement.h:
* platform/graphics/MediaPlayer.cpp:
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
Source/WebKit:
Implement shouldGetNativeImageForCanvasDrawing in MediaPlayerPrivateRemote to return false.
This allows to not do sync IPC in the code path where everything can be done in GPUProcess.
* WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
* WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
* WebProcess/GPU/media/cocoa/MediaPlayerPrivateRemoteCocoa.mm:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (294056 => 294057)
--- trunk/Source/WebCore/ChangeLog 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/ChangeLog 2022-05-11 17:20:36 UTC (rev 294057)
@@ -1,3 +1,23 @@
+2022-05-11 Youenn Fablet <[email protected]>
+
+ Introduce a canvas-drawImage specific method to get a NativeImage from a video element
+ https://bugs.webkit.org/show_bug.cgi?id=240275
+
+ Reviewed by Eric Carlson.
+
+ Introduce shouldGetNativeImageForCanvasDrawing in HTMLVideoElement/MediaPlayer/MediaPlayerPrivate.
+ If returning true, we call videoFrameForCurrentTime when drawing a video to canvas.
+ Otherwise, we directly use video.paintCurrentFrameInContext code path.
+ This allows skipping a code path where videoFrameForCurrentTime is less efficient than video.paintCurrentFrameInContext.
+
+ Covered by existing canvas tests.
+
+ * html/HTMLVideoElement.cpp:
+ * html/HTMLVideoElement.h:
+ * platform/graphics/MediaPlayer.cpp:
+ * platform/graphics/MediaPlayer.h:
+ * platform/graphics/MediaPlayerPrivate.h:
+
2022-05-10 Brent Fulgham <[email protected]>
Remove the unneeded StylePropertiesBase after Bug 240244
Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (294056 => 294057)
--- trunk/Source/WebCore/html/HTMLVideoElement.cpp 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp 2022-05-11 17:20:36 UTC (rev 294057)
@@ -319,6 +319,14 @@
return player()->hasVideo() && player()->hasAvailableVideoFrame();
}
+bool HTMLVideoElement::shouldGetNativeImageForCanvasDrawing() const
+{
+ if (!player())
+ return false;
+
+ return player()->shouldGetNativeImageForCanvasDrawing();
+}
+
RefPtr<NativeImage> HTMLVideoElement::nativeImageForCurrentTime()
{
if (!player())
Modified: trunk/Source/WebCore/html/HTMLVideoElement.h (294056 => 294057)
--- trunk/Source/WebCore/html/HTMLVideoElement.h 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/html/HTMLVideoElement.h 2022-05-11 17:20:36 UTC (rev 294057)
@@ -79,6 +79,7 @@
// Used by canvas to gain raw pixel access
void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&);
+ bool shouldGetNativeImageForCanvasDrawing() const;
WEBCORE_EXPORT RefPtr<NativeImage> nativeImageForCurrentTime();
std::optional<DestinationColorSpace> colorSpace() const;
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (294056 => 294057)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2022-05-11 17:20:36 UTC (rev 294057)
@@ -1654,7 +1654,7 @@
bool repaintEntireCanvas = rectContainsCanvas(dstRect);
#if USE(CG)
- if (c->hasPlatformContext()) {
+ if (c->hasPlatformContext() && video.shouldGetNativeImageForCanvasDrawing()) {
if (auto image = video.nativeImageForCurrentTime()) {
c->drawNativeImage(*image, FloatSize(video.videoWidth(), video.videoHeight()), dstRect, srcRect);
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (294056 => 294057)
--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp 2022-05-11 17:20:36 UTC (rev 294057)
@@ -1099,6 +1099,11 @@
return m_private->colorSpace();
}
+bool MediaPlayer::shouldGetNativeImageForCanvasDrawing() const
+{
+ return m_private->shouldGetNativeImageForCanvasDrawing();
+}
+
MediaPlayer::SupportsType MediaPlayer::supportsType(const MediaEngineSupportParameters& parameters)
{
// 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (294056 => 294057)
--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h 2022-05-11 17:20:36 UTC (rev 294057)
@@ -476,6 +476,7 @@
RefPtr<VideoFrame> videoFrameForCurrentTime();
RefPtr<NativeImage> nativeImageForCurrentTime();
DestinationColorSpace colorSpace();
+ bool shouldGetNativeImageForCanvasDrawing() const;
using MediaPlayerEnums::NetworkState;
NetworkState networkState();
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (294056 => 294057)
--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h 2022-05-11 17:20:36 UTC (rev 294057)
@@ -185,6 +185,7 @@
virtual RefPtr<VideoFrame> videoFrameForCurrentTime() { return nullptr; }
virtual RefPtr<NativeImage> nativeImageForCurrentTime() { return nullptr; }
virtual DestinationColorSpace colorSpace() = 0;
+ virtual bool shouldGetNativeImageForCanvasDrawing() const { return true; }
virtual void setPreload(MediaPlayer::Preload) { }
Modified: trunk/Source/WebKit/ChangeLog (294056 => 294057)
--- trunk/Source/WebKit/ChangeLog 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebKit/ChangeLog 2022-05-11 17:20:36 UTC (rev 294057)
@@ -1,3 +1,17 @@
+2022-05-11 Youenn Fablet <[email protected]>
+
+ Introduce a canvas-drawImage specific method to get a NativeImage from a video element
+ https://bugs.webkit.org/show_bug.cgi?id=240275
+
+ Reviewed by Eric Carlson.
+
+ Implement shouldGetNativeImageForCanvasDrawing in MediaPlayerPrivateRemote to return false.
+ This allows to not do sync IPC in the code path where everything can be done in GPUProcess.
+
+ * WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
+ * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
+ * WebProcess/GPU/media/cocoa/MediaPlayerPrivateRemoteCocoa.mm:
+
2022-05-10 Brent Fulgham <[email protected]>
Remove abandoned CSSDeferredParser implementation and feature flag
Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h (294056 => 294057)
--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h 2022-05-11 17:13:01 UTC (rev 294056)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h 2022-05-11 17:20:36 UTC (rev 294057)
@@ -298,6 +298,9 @@
RefPtr<WebCore::VideoFrame> videoFrameForCurrentTime() final;
RefPtr<WebCore::NativeImage> nativeImageForCurrentTime() final;
WebCore::DestinationColorSpace colorSpace() final;
+#if PLATFORM(COCOA)
+ bool shouldGetNativeImageForCanvasDrawing() const final { return false; }
+#endif
WebCore::MediaPlayerIdentifier identifier() const final;