Title: [273213] trunk
Revision
273213
Author
peng.l...@apple.com
Date
2021-02-20 18:05:38 -0800 (Sat, 20 Feb 2021)

Log Message

Video elements do not work as sources for TexImage2D calls in GPU Process
https://bugs.webkit.org/show_bug.cgi?id=218184

Reviewed by Jer Noble.

Source/WebCore:

Add a function `GraphicsContextGL::copyTextureFromMedia()` which can be used by the graphics
context to copy video texture from a video element (player).

This patch also replaces `MediaPlayer::copyVideoTextureToPlatformTexture()` with
`MediaPlayer::pixelBufferForCurrentTime()` on Cocoa ports. The motivation is that
`RemoteGraphicsContextGL::copyTextureFromMedia()` will run in a background thread
("RemoteGraphicsContextGL work queue") and it is difficult to make
`MediaPlayer::copyVideoTextureToPlatformTexture()` thread-safe. In addition, we cannot
simply run it on the main thread because it uses graphic context internally. Adding a
function `MediaPlayer::pixelBufferForCurrentTime()` solves the problem.

Manually tested.
We need to enable both "GPU Process: Media" and "GPU Process: WebGL" to test the feature.

* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::copyVideoTextureToPlatformTexture): Deleted.
* html/HTMLVideoElement.h:

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::texImageSourceHelper):
* platform/graphics/GraphicsContextGL.h:

* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::pixelBufferForCurrentTime):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::pixelBufferForCurrentTime):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::pixelBufferForCurrentTime):
(WebCore::MediaPlayerPrivateAVFoundationObjC::copyVideoTextureToPlatformTexture): Deleted.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pixelBufferForCurrentTime):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::copyVideoTextureToPlatformTexture): Deleted.

* platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
(WebCore::GraphicsContextGLOpenGL::copyTextureFromMedia):
* platform/graphics/opengl/GraphicsContextGLOpenGL.h:

Source/WebKit:

Add an IPC message `RemoteGraphicsContextGL::CopyTextureFromMedia` to implement
`RemoteGraphicsContextGLProxy::copyTextureFromMedia()` in the Web process.

* GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::copyTextureFromMedia):
* GPUProcess/graphics/RemoteGraphicsContextGL.h:
We should use `m_gpuConnectionToWebProcess` in the main thread only.

* GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:

* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
(WebKit::RemoteGraphicsContextGLProxy::copyTextureFromMedia):
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:

* WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
* WebProcess/GPU/media/MediaPlayerPrivateRemote.h:

Tools:

* Scripts/generate-gpup-webgl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273212 => 273213)


--- trunk/Source/WebCore/ChangeLog	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/ChangeLog	2021-02-21 02:05:38 UTC (rev 273213)
@@ -1,3 +1,50 @@
+2021-02-20  Peng Liu  <peng.l...@apple.com>
+
+        Video elements do not work as sources for TexImage2D calls in GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=218184
+
+        Reviewed by Jer Noble.
+
+        Add a function `GraphicsContextGL::copyTextureFromMedia()` which can be used by the graphics
+        context to copy video texture from a video element (player).
+        
+        This patch also replaces `MediaPlayer::copyVideoTextureToPlatformTexture()` with
+        `MediaPlayer::pixelBufferForCurrentTime()` on Cocoa ports. The motivation is that
+        `RemoteGraphicsContextGL::copyTextureFromMedia()` will run in a background thread
+        ("RemoteGraphicsContextGL work queue") and it is difficult to make
+        `MediaPlayer::copyVideoTextureToPlatformTexture()` thread-safe. In addition, we cannot
+        simply run it on the main thread because it uses graphic context internally. Adding a
+        function `MediaPlayer::pixelBufferForCurrentTime()` solves the problem.
+
+        Manually tested.
+        We need to enable both "GPU Process: Media" and "GPU Process: WebGL" to test the feature.
+
+        * html/HTMLVideoElement.cpp:
+        (WebCore::HTMLVideoElement::copyVideoTextureToPlatformTexture): Deleted.
+        * html/HTMLVideoElement.h:
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::texImageSourceHelper):
+        * platform/graphics/GraphicsContextGL.h:
+
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::pixelBufferForCurrentTime):
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::pixelBufferForCurrentTime):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::pixelBufferForCurrentTime):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::copyVideoTextureToPlatformTexture): Deleted.
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pixelBufferForCurrentTime):
+        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::copyVideoTextureToPlatformTexture): Deleted.
+
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
+        (WebCore::GraphicsContextGLOpenGL::copyTextureFromMedia):
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+
 2021-02-20  Sam Weinig  <wei...@apple.com>
 
         color(lab ...) should serialize as color(lab ...) not lab() according to latest CSS Color 4 spec

Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (273212 => 273213)


--- trunk/Source/WebCore/html/HTMLVideoElement.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -300,13 +300,6 @@
     context.paintFrameForMedia(*player, destRect);
 }
 
-bool HTMLVideoElement::copyVideoTextureToPlatformTexture(GraphicsContextGL* context, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
-{
-    if (!player())
-        return false;
-    return player()->copyVideoTextureToPlatformTexture(context, texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY);
-}
-
 bool HTMLVideoElement::hasAvailableVideoFrame() const
 {
     if (!player())

Modified: trunk/Source/WebCore/html/HTMLVideoElement.h (273212 => 273213)


--- trunk/Source/WebCore/html/HTMLVideoElement.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/html/HTMLVideoElement.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -77,10 +77,6 @@
 
     RefPtr<NativeImage> nativeImageForCurrentTime();
 
-    // Used by WebGL to do GPU-GPU textures copy if possible.
-    // See more details at MediaPlayer::copyVideoTextureToPlatformTexture() defined in Source/WebCore/platform/graphics/MediaPlayer.h.
-    bool copyVideoTextureToPlatformTexture(GraphicsContextGL*, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY);
-
     WEBCORE_EXPORT bool shouldDisplayPosterImage() const;
 
     URL posterImageURL() const;

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (273212 => 273213)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -4881,7 +4881,7 @@
             && (format == GraphicsContextGL::RGB || format == GraphicsContextGL::RGBA)
             && type == GraphicsContextGL::UNSIGNED_BYTE
             && !level) {
-            if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->object(), target, level, internalformat, format, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
+            if (video->player() && m_context->copyTextureFromMedia(*video->player(), texture->object(), target, level, internalformat, format, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
 #if !USE(ANGLE)
                 texture->setLevelInfo(target, level, internalformat, video->videoWidth(), video->videoHeight(), type);
 #endif // !USE(ANGLE)

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -32,6 +32,7 @@
 #include "Image.h"
 #include "IntRect.h"
 #include "IntSize.h"
+#include "MediaPlayer.h"
 #include "PlatformLayer.h"
 #include <wtf/HashSet.h>
 #include <wtf/RefCounted.h>
@@ -1306,8 +1307,8 @@
     // Returns interface for CV interaction if the functionality is present.
     virtual GraphicsContextGLCV* asCV() = 0;
 #endif
+    virtual bool copyTextureFromMedia(MediaPlayer&, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) = 0;
 
-
     IntSize getInternalFramebufferSize() const { return IntSize(m_currentWidth, m_currentHeight); }
 
     static unsigned getClearBitsByAttachmentType(GCGLenum);

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -1006,11 +1006,22 @@
     m_private->paint(p, r);
 }
 
+#if !USE(AVFOUNDATION)
+
 bool MediaPlayer::copyVideoTextureToPlatformTexture(GraphicsContextGL* context, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
 {
     return m_private->copyVideoTextureToPlatformTexture(context, texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY);
 }
 
+#else
+
+CVPixelBufferRef MediaPlayer::pixelBufferForCurrentTime()
+{
+    return m_private->pixelBufferForCurrentTime();
+}
+
+#endif
+
 RefPtr<NativeImage> MediaPlayer::nativeImageForCurrentTime()
 {
     return m_private->nativeImageForCurrentTime();

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -62,6 +62,10 @@
 OBJC_CLASS AVPlayer;
 OBJC_CLASS NSArray;
 
+#if ENABLE(WEBGL) && USE(AVFOUNDATION)
+typedef struct __CVBuffer* CVPixelBufferRef;
+#endif
+
 namespace WebCore {
 
 class AudioSourceProvider;
@@ -437,8 +441,11 @@
     // In the GPU-GPU textures copy, the source texture(Video texture) should have valid target, internalFormat and size, etc.
     // The destination texture may need to be resized to to the dimensions of the source texture or re-defined to the required internalFormat.
     // The current restrictions require that format shoud be RGB or RGBA, type should be UNSIGNED_BYTE and level should be 0. It may be lifted in the future.
-
+#if !USE(AVFOUNDATION)
     bool copyVideoTextureToPlatformTexture(GraphicsContextGL*, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY);
+#else
+    CVPixelBufferRef pixelBufferForCurrentTime();
+#endif
 
     RefPtr<NativeImage> nativeImageForCurrentTime();
 

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -161,7 +161,11 @@
     virtual void paint(GraphicsContext&, const FloatRect&) = 0;
 
     virtual void paintCurrentFrameInContext(GraphicsContext& c, const FloatRect& r) { paint(c, r); }
+#if !USE(AVFOUNDATION)
     virtual bool copyVideoTextureToPlatformTexture(GraphicsContextGL*, PlatformGLObject, GCGLenum, GCGLint, GCGLenum, GCGLenum, GCGLenum, bool, bool) { return false; }
+#else
+    virtual CVPixelBufferRef pixelBufferForCurrentTime() { return nullptr; }
+#endif
     virtual RefPtr<NativeImage> nativeImageForCurrentTime() { return nullptr; }
 
     virtual void setPreload(MediaPlayer::Preload) { }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -254,7 +254,7 @@
     RefPtr<NativeImage> nativeImageForCurrentTime() final;
     void waitForVideoOutputMediaDataWillChange();
 
-    bool copyVideoTextureToPlatformTexture(GraphicsContextGL*, PlatformGLObject, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) final;
+    CVPixelBufferRef pixelBufferForCurrentTime() final;
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     void keyAdded() final;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2021-02-21 02:05:38 UTC (rev 273213)
@@ -2388,20 +2388,13 @@
 
 }
 
-bool MediaPlayerPrivateAVFoundationObjC::copyVideoTextureToPlatformTexture(GraphicsContextGL* context, PlatformGLObject outputTexture, GCGLenum outputTarget, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
+CVPixelBufferRef MediaPlayerPrivateAVFoundationObjC::pixelBufferForCurrentTime()
 {
-    ASSERT(context);
-
     updateLastPixelBuffer();
     if (!m_lastPixelBuffer)
-        return false;
+        return nullptr;
 
-    auto contextCV = context->asCV();
-    if (!contextCV)
-        return false;
-    UNUSED_VARIABLE(premultiplyAlpha);
-    ASSERT_UNUSED(outputTarget, outputTarget == GraphicsContextGL::TEXTURE_2D);
-    return contextCV->copyPixelBufferToTexture(m_lastPixelBuffer.get(), outputTexture, level, internalFormat, format, type, GraphicsContextGL::FlipY(flipY));
+    return m_lastPixelBuffer.get();
 }
 
 RefPtr<NativeImage> MediaPlayerPrivateAVFoundationObjC::nativeImageForCurrentTime()

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -221,7 +221,7 @@
     bool updateLastImage();
     void paint(GraphicsContext&, const FloatRect&) override;
     void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&) override;
-    bool copyVideoTextureToPlatformTexture(GraphicsContextGL*, PlatformGLObject, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) override;
+    CVPixelBufferRef pixelBufferForCurrentTime() final;
 
     bool supportsAcceleratedRendering() const override;
     // called when the rendering system flips the into or out of accelerated rendering mode.

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2021-02-21 02:05:38 UTC (rev 273213)
@@ -623,7 +623,7 @@
     context.drawNativeImage(*image, imageRect.size(), outputRect, imageRect);
 }
 
-bool MediaPlayerPrivateMediaSourceAVFObjC::copyVideoTextureToPlatformTexture(GraphicsContextGL* context, PlatformGLObject outputTexture, GCGLenum outputTarget, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
+CVPixelBufferRef MediaPlayerPrivateMediaSourceAVFObjC::pixelBufferForCurrentTime()
 {
     // We have been asked to paint into a WebGL canvas, so take that as a signal to create
     // a decompression session, even if that means the native video can't also be displayed
@@ -633,18 +633,12 @@
         acceleratedRenderingStateChanged();
     }
 
-    ASSERT(context);
-
     if (updateLastPixelBuffer()) {
         if (!m_lastPixelBuffer)
-            return false;
+            return nullptr;
     }
-    auto contextCV = context->asCV();
-    if (!contextCV)
-        return false;
-    UNUSED_VARIABLE(premultiplyAlpha);
-    ASSERT_UNUSED(outputTarget, outputTarget == GraphicsContextGL::TEXTURE_2D);
-    return contextCV->copyPixelBufferToTexture(m_lastPixelBuffer.get(), outputTexture, level, internalFormat, format, type, GraphicsContextGLCV::FlipY(flipY));
+
+    return m_lastPixelBuffer.get();
 }
 
 bool MediaPlayerPrivateMediaSourceAVFObjC::hasAvailableVideoFrame() const

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -33,8 +33,13 @@
 #include "ExtensionsGL.h"
 #include "ImageBuffer.h"
 #include "ImageData.h"
+#include "MediaPlayerPrivate.h"
 #include <wtf/UniqueArray.h>
 
+#if USE(AVFOUNDATION)
+#include "GraphicsContextGLCV.h"
+#endif
+
 namespace WebCore {
 
 void GraphicsContextGLOpenGL::resetBuffersToAutoClear()
@@ -253,6 +258,25 @@
 }
 #endif
 
+bool GraphicsContextGLOpenGL::copyTextureFromMedia(MediaPlayer& player, PlatformGLObject outputTexture, GCGLenum outputTarget, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
+{
+#if USE(AVFOUNDATION)
+    auto pixelBuffer = player.pixelBufferForCurrentTime();
+    if (!pixelBuffer)
+        return false;
+
+    auto contextCV = asCV();
+    if (!contextCV)
+        return false;
+
+    UNUSED_VARIABLE(premultiplyAlpha);
+    ASSERT_UNUSED(outputTarget, outputTarget == GraphicsContextGL::TEXTURE_2D);
+    return contextCV->copyPixelBufferToTexture(pixelBuffer, outputTexture, level, internalFormat, format, type, GraphicsContextGL::FlipY(flipY));
+#else
+    return player.copyVideoTextureToPlatformTexture(this, outputTexture, outputTarget, level, internalFormat, format, type, premultiplyAlpha, flipY);
+#endif
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGL)

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (273212 => 273213)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -86,6 +86,7 @@
 class HostWindow;
 class ImageBuffer;
 class ImageData;
+class MediaPlayer;
 #if USE(TEXTURE_MAPPER)
 class TextureMapperGCGLPlatformLayer;
 #endif
@@ -465,6 +466,8 @@
     RefPtr<ImageData> readRenderingResultsForPainting();
     RefPtr<ImageData> readCompositedResultsForPainting();
 
+    bool copyTextureFromMedia(MediaPlayer&, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) final;
+
 #if USE(OPENGL) && ENABLE(WEBGL2)
     void primitiveRestartIndex(GCGLuint);
 #endif

Modified: trunk/Source/WebKit/ChangeLog (273212 => 273213)


--- trunk/Source/WebKit/ChangeLog	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/ChangeLog	2021-02-21 02:05:38 UTC (rev 273213)
@@ -1,3 +1,27 @@
+2021-02-20  Peng Liu  <peng.l...@apple.com>
+
+        Video elements do not work as sources for TexImage2D calls in GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=218184
+
+        Reviewed by Jer Noble.
+
+        Add an IPC message `RemoteGraphicsContextGL::CopyTextureFromMedia` to implement
+        `RemoteGraphicsContextGLProxy::copyTextureFromMedia()` in the Web process.
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
+        (WebKit::RemoteGraphicsContextGL::copyTextureFromMedia):
+        * GPUProcess/graphics/RemoteGraphicsContextGL.h:
+        We should use `m_gpuConnectionToWebProcess` in the main thread only.
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
+
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
+        (WebKit::RemoteGraphicsContextGLProxy::copyTextureFromMedia):
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
+
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
+
 2021-02-20  Youenn Fablet  <you...@apple.com>
 
         Add support for adding/removing/clearing mock devices in GPUProcess

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp (273212 => 273213)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -34,8 +34,13 @@
 #include "StreamConnectionWorkQueue.h"
 #include <WebCore/GraphicsContextGLOpenGL.h>
 #include <WebCore/NotImplemented.h>
+#include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 
+#if USE(AVFOUNDATION)
+#include <WebCore/GraphicsContextGLCV.h>
+#endif
+
 namespace WebKit {
 
 using namespace WebCore;
@@ -58,7 +63,8 @@
 #endif
 
 RemoteGraphicsContextGL::RemoteGraphicsContextGL(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
-    : m_streamConnection(IPC::StreamServerConnection<RemoteGraphicsContextGL>::create(gpuConnectionToWebProcess.connection(), WTFMove(stream), remoteGraphicsContextGLStreamWorkQueue()))
+    : m_gpuConnectionToWebProcess(makeWeakPtr(gpuConnectionToWebProcess))
+    , m_streamConnection(IPC::StreamServerConnection<RemoteGraphicsContextGL>::create(gpuConnectionToWebProcess.connection(), WTFMove(stream), remoteGraphicsContextGLStreamWorkQueue()))
     , m_graphicsContextGLIdentifier(graphicsContextGLIdentifier)
     , m_renderingBackend(makeRef(renderingBackend))
 {
@@ -201,6 +207,54 @@
     completionHandler();
 }
 
+void RemoteGraphicsContextGL::copyTextureFromMedia(WebCore::MediaPlayerIdentifier mediaPlayerIdentifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY, CompletionHandler<void(bool)>&& completionHandler)
+{
+#if USE(AVFOUNDATION)
+    UNUSED_VARIABLE(premultiplyAlpha);
+    ASSERT_UNUSED(target, target == GraphicsContextGL::TEXTURE_2D);
+
+    RetainPtr<CVPixelBufferRef> pixelBuffer;
+    auto getPixelBuffer = [&] {
+        if (!m_gpuConnectionToWebProcess)
+            return;
+
+        if (auto mediaPlayer = m_gpuConnectionToWebProcess->remoteMediaPlayerManagerProxy().mediaPlayer(mediaPlayerIdentifier))
+            pixelBuffer = mediaPlayer->pixelBufferForCurrentTime();
+    };
+
+    if (isMainThread())
+        getPixelBuffer();
+    else
+        callOnMainThreadAndWait(WTFMove(getPixelBuffer));
+
+    if (!pixelBuffer) {
+        completionHandler(false);
+        return;
+    }
+
+    auto contextCV = m_context->asCV();
+    if (!contextCV) {
+        completionHandler(false);
+        return;
+    }
+
+    completionHandler(contextCV->copyPixelBufferToTexture(pixelBuffer.get(), texture, level, internalFormat, format, type, GraphicsContextGL::FlipY(flipY)));
+#else
+    UNUSED_VARIABLE(mediaPlayerIdentifier);
+    UNUSED_VARIABLE(texture);
+    UNUSED_VARIABLE(target);
+    UNUSED_VARIABLE(level);
+    UNUSED_VARIABLE(internalFormat);
+    UNUSED_VARIABLE(format);
+    UNUSED_VARIABLE(type);
+    UNUSED_VARIABLE(premultiplyAlpha);
+    UNUSED_VARIABLE(flipY);
+
+    notImplemented();
+    completionHandler(false);
+#endif
+}
+
 } // namespace WebKit
 
 #endif

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h (273212 => 273213)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -91,11 +91,13 @@
     void synthesizeGLError(uint32_t error);
     void paintRenderingResultsToCanvas(WebCore::RenderingResourceIdentifier, CompletionHandler<void()>&&);
     void paintCompositedResultsToCanvas(WebCore::RenderingResourceIdentifier, CompletionHandler<void()>&&);
+    void copyTextureFromMedia(WebCore::MediaPlayerIdentifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY, CompletionHandler<void(bool)>&&);
 
 #include "RemoteGraphicsContextGLFunctionsGenerated.h" // NOLINT
 
     void paintImageDataToImageBuffer(RefPtr<WebCore::ImageData>&&, WebCore::RenderingResourceIdentifier, CompletionHandler<void()>&&);
 
+    WeakPtr<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
     RefPtr<IPC::StreamServerConnection<RemoteGraphicsContextGL>> m_streamConnection;
     RefPtr<WebCore::GraphicsContextGLOpenGL> m_context;
     GraphicsContextGLIdentifier m_graphicsContextGLIdentifier;

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in (273212 => 273213)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in	2021-02-21 02:05:38 UTC (rev 273213)
@@ -36,10 +36,10 @@
     void NotifyMarkContextChanged()
     void SynthesizeGLError(uint32_t error)
     void GetError() -> (uint32_t returnValue) Synchronous
-    void PaintRenderingResultsToCanvas(WebCore::RenderingResourceIdentifier identifier) -> () Synchronous
-    void PaintCompositedResultsToCanvas(WebCore::RenderingResourceIdentifier identifier) -> () Synchronous
+    void PaintRenderingResultsToCanvas(WebCore::RenderingResourceIdentifier imageBuffer) -> () Synchronous
+    void PaintCompositedResultsToCanvas(WebCore::RenderingResourceIdentifier imageBuffer) -> () Synchronous
+    void CopyTextureFromMedia(WebCore::MediaPlayerIdentifier identifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY) -> (bool success) Synchronous
 
-
     void SetFailNextGPUStatusCheck()
     void MoveErrorsToSyntheticErrorList() -> (bool returnValue) Synchronous
     void ActiveTexture(uint32_t texture)

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp (273212 => 273213)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -164,6 +164,18 @@
     }
 }
 
+bool RemoteGraphicsContextGLProxy::copyTextureFromMedia(MediaPlayer& mediaPlayer, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
+{
+    bool result = false;
+    auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::CopyTextureFromMedia(mediaPlayer.identifier(), texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY), Messages::RemoteGraphicsContextGL::CopyTextureFromMedia::Reply(result));
+    if (!sendResult) {
+        markContextLost();
+        return false;
+    }
+
+    return result;
+}
+
 void RemoteGraphicsContextGLProxy::synthesizeGLError(GCGLenum error)
 {
     if (!isContextLost()) {

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h (273212 => 273213)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -70,6 +70,8 @@
     void synthesizeGLError(GCGLenum error) final;
     GCGLenum getError() final;
 
+    bool copyTextureFromMedia(WebCore::MediaPlayer&, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) final;
+
     // Functions with a generated implementation. This list is used by generate-gpup-webgl script.
     void setFailNextGPUStatusCheck() final;
     bool moveErrorsToSyntheticErrorList() final;

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp (273212 => 273213)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2021-02-21 02:05:38 UTC (rev 273213)
@@ -848,11 +848,13 @@
     notImplemented();
 }
 
+#if !USE(AVFOUNDATION)
 bool MediaPlayerPrivateRemote::copyVideoTextureToPlatformTexture(WebCore::GraphicsContextGL*, PlatformGLObject, GCGLenum, GCGLint, GCGLenum, GCGLenum, GCGLenum, bool, bool)
 {
     notImplemented();
     return false;
 }
+#endif
 
 RefPtr<NativeImage> MediaPlayerPrivateRemote::nativeImageForCurrentTime()
 {

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h (273212 => 273213)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2021-02-21 02:05:38 UTC (rev 273213)
@@ -281,7 +281,9 @@
 
     void paint(WebCore::GraphicsContext&, const WebCore::FloatRect&) final;
     void paintCurrentFrameInContext(WebCore::GraphicsContext&, const WebCore::FloatRect&) final;
+#if !USE(AVFOUNDATION)
     bool copyVideoTextureToPlatformTexture(WebCore::GraphicsContextGL*, PlatformGLObject, GCGLenum, GCGLint, GCGLenum, GCGLenum, GCGLenum, bool, bool) final;
+#endif
     RefPtr<WebCore::NativeImage> nativeImageForCurrentTime() final;
 
     WebCore::MediaPlayerIdentifier identifier() const final;

Modified: trunk/Tools/ChangeLog (273212 => 273213)


--- trunk/Tools/ChangeLog	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Tools/ChangeLog	2021-02-21 02:05:38 UTC (rev 273213)
@@ -1,3 +1,12 @@
+2021-02-20  Peng Liu  <peng.l...@apple.com>
+
+        Video elements do not work as sources for TexImage2D calls in GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=218184
+
+        Reviewed by Jer Noble.
+
+        * Scripts/generate-gpup-webgl:
+
 2021-02-20  Jiewen Tan  <jiewen_...@apple.com>
 
         PCM: Store and report source unlinkable tokens

Modified: trunk/Tools/Scripts/generate-gpup-webgl (273212 => 273213)


--- trunk/Tools/Scripts/generate-gpup-webgl	2021-02-21 01:06:59 UTC (rev 273212)
+++ trunk/Tools/Scripts/generate-gpup-webgl	2021-02-21 02:05:38 UTC (rev 273213)
@@ -103,12 +103,11 @@
     void GetError() -> (uint32_t returnValue) Synchronous
     void PaintRenderingResultsToCanvas(WebCore::RenderingResourceIdentifier imageBuffer) -> () Synchronous
     void PaintCompositedResultsToCanvas(WebCore::RenderingResourceIdentifier imageBuffer) -> () Synchronous
-
+    void CopyTextureFromMedia(WebCore::MediaPlayerIdentifier identifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY) -> (bool success) Synchronous
 {}
 }}
 
 #endif
-
 """
 )
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to