Title: [290413] trunk/Source/WebKit
Revision
290413
Author
commit-qu...@webkit.org
Date
2022-02-23 22:35:55 -0800 (Wed, 23 Feb 2022)

Log Message

REGRESSION(r290175): Texture upload from video and user media is slower than expected for non-GPUP WebGL
https://bugs.webkit.org/show_bug.cgi?id=237034

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-02-23
Reviewed by Youenn Fablet.

Add back the code-path to obtain the IOSurface backed CVPixelBuffers directly
via IPC transfer. This is used on macOS where WebGL is in WP.

* GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
(WebKit::RemoteVideoFrameObjectHeap::pixelBuffer):
* GPUProcess/media/RemoteVideoFrameObjectHeap.h:
* GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in:
* WebProcess/GPU/media/RemoteVideoFrameProxy.cpp:
(WebKit::RemoteVideoFrameProxy::pixelBuffer const):
* WebProcess/GPU/media/RemoteVideoFrameProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290412 => 290413)


--- trunk/Source/WebKit/ChangeLog	2022-02-24 06:16:30 UTC (rev 290412)
+++ trunk/Source/WebKit/ChangeLog	2022-02-24 06:35:55 UTC (rev 290413)
@@ -1,3 +1,21 @@
+2022-02-23  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        REGRESSION(r290175): Texture upload from video and user media is slower than expected for non-GPUP WebGL
+        https://bugs.webkit.org/show_bug.cgi?id=237034
+
+        Reviewed by Youenn Fablet.
+
+        Add back the code-path to obtain the IOSurface backed CVPixelBuffers directly
+        via IPC transfer. This is used on macOS where WebGL is in WP.
+
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
+        (WebKit::RemoteVideoFrameObjectHeap::pixelBuffer):
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.h:
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in:
+        * WebProcess/GPU/media/RemoteVideoFrameProxy.cpp:
+        (WebKit::RemoteVideoFrameProxy::pixelBuffer const):
+        * WebProcess/GPU/media/RemoteVideoFrameProxy.h:
+
 2022-02-23  Don Olmstead  <don.olmst...@sony.com>
 
         Fix !ENABLE(SERVICE_WORKER) build after r290387

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp (290412 => 290413)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-02-24 06:16:30 UTC (rev 290412)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-02-24 06:35:55 UTC (rev 290413)
@@ -117,6 +117,28 @@
     }
     m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::NewVideoFrameBuffer { identifier }, 0);
 }
+
+void RemoteVideoFrameObjectHeap::pixelBuffer(RemoteVideoFrameReadReference&& read, CompletionHandler<void(RetainPtr<CVPixelBufferRef>)>&& completionHandler)
+{
+    auto videoFrame = retire(WTFMove(read), defaultTimeout);
+    if (!videoFrame) {
+        ASSERT_IS_TESTING_IPC();
+        completionHandler(nullptr);
+        return;
+    }
+    RetainPtr<CVPixelBufferRef> pixelBuffer;
+    if (is<VideoFrameCV>(videoFrame))
+        pixelBuffer = downcast<VideoFrameCV>(*videoFrame).pixelBuffer();
+    else if (is<MediaSampleAVFObjC>(*videoFrame))
+        pixelBuffer = downcast<MediaSampleAVFObjC>(*videoFrame).pixelBuffer();
+    else {
+        ASSERT_NOT_REACHED();
+        completionHandler(nullptr);
+        return;
+    }
+    completionHandler(pixelBuffer);
+}
+
 #endif
 
 }

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h (290412 => 290413)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-02-24 06:16:30 UTC (rev 290412)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-02-24 06:35:55 UTC (rev 290413)
@@ -57,12 +57,15 @@
 
     // IPC::MessageReceiver overrides.
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+    bool didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, UniqueRef<IPC::Encoder>&) final;
 
     // Messages.
     void releaseVideoFrame(RemoteVideoFrameWriteReference&&);
 #if PLATFORM(COCOA)
     void getVideoFrameBuffer(RemoteVideoFrameReadReference&&);
+    void pixelBuffer(RemoteVideoFrameReadReference&&, CompletionHandler<void(RetainPtr<CVPixelBufferRef>)>&&);
 #endif
+    inline static Seconds defaultTimeout = 10_s;
 
     GPUConnectionToWebProcess* m_gpuConnectionToWebProcess WTF_GUARDED_BY_CAPABILITY(m_consumeThread);
     const Ref<IPC::Connection> m_connection;

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in (290412 => 290413)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in	2022-02-24 06:16:30 UTC (rev 290412)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in	2022-02-24 06:35:55 UTC (rev 290413)
@@ -24,8 +24,9 @@
 #if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 messages -> RemoteVideoFrameObjectHeap NotRefCounted {
 #if PLATFORM(COCOA)
-    GetVideoFrameBuffer(WebKit::RemoteVideoFrameReadReference identifier)
+    GetVideoFrameBuffer(WebKit::RemoteVideoFrameReadReference read)
+    PixelBuffer(WebKit::RemoteVideoFrameReadReference read) -> (RetainPtr<CVPixelBufferRef> result) Synchronous
 #endif
-    ReleaseVideoFrame(WebKit::RemoteVideoFrameWriteReference identifier)
+    ReleaseVideoFrame(WebKit::RemoteVideoFrameWriteReference write)
 }
 #endif

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.cpp (290412 => 290413)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.cpp	2022-02-24 06:16:30 UTC (rev 290412)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.cpp	2022-02-24 06:35:55 UTC (rev 290413)
@@ -32,9 +32,11 @@
 #include "RemoteVideoFrameObjectHeapProxy.h"
 
 #if PLATFORM(COCOA)
+#include "WebProcess.h"
 #include <WebCore/CVUtilities.h>
 #include <WebCore/RealtimeIncomingVideoSourceCocoa.h>
 #include <WebCore/VideoFrameCV.h>
+#include <wtf/MainThread.h>
 #include <wtf/threads/BinarySemaphore.h>
 #endif
 
@@ -107,18 +109,27 @@
 {
     Locker lock(m_pixelBufferLock);
     if (!m_pixelBuffer && m_videoFrameObjectHeapProxy) {
-        BinarySemaphore semaphore;
-        m_videoFrameObjectHeapProxy->getVideoFrameBuffer(*this, [this, &semaphore](auto pixelBuffer) {
-            m_pixelBuffer = WTFMove(pixelBuffer);
-            if (!m_pixelBuffer) {
-                // Some code paths do not like empty pixel buffers.
-                m_pixelBuffer = WebCore::createBlackPixelBuffer(static_cast<size_t>(m_size.width()), static_cast<size_t>(m_size.height()));
-            }
-            semaphore.signal();
-        });
-        semaphore.wait();
-        m_videoFrameObjectHeapProxy = nullptr;
+        auto videoFrameObjectHeapProxy = std::exchange(m_videoFrameObjectHeapProxy, nullptr);
+
+        bool canSendSync = isMainRunLoop(); // FIXME: we should be able to sendSync from other threads too.
+        // Currently we just key with this, as there is no condition for "has access to IOKit".
+        if (WebProcess::singleton().shouldUseRemoteRenderingForWebGL() || !canSendSync) {
+            BinarySemaphore semaphore;
+            videoFrameObjectHeapProxy->getVideoFrameBuffer(*this, [this, &semaphore](auto pixelBuffer) {
+                m_pixelBuffer = WTFMove(pixelBuffer);
+                semaphore.signal();
+            });
+            semaphore.wait();
+        } else {
+            RetainPtr<CVPixelBufferRef> pixelBuffer;
+            auto result = m_connection->sendSync(Messages::RemoteVideoFrameObjectHeap::PixelBuffer(read()), Messages::RemoteVideoFrameObjectHeap::PixelBuffer::Reply(pixelBuffer), 0, defaultTimeout);
+            if (result)
+                m_pixelBuffer = WTFMove(pixelBuffer);
+        }
     }
+    // FIXME: Some code paths do not like empty pixel buffers.
+    if (!m_pixelBuffer)
+        m_pixelBuffer = WebCore::createBlackPixelBuffer(static_cast<size_t>(m_size.width()), static_cast<size_t>(m_size.height()));
     return m_pixelBuffer.get();
 }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.h (290412 => 290413)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.h	2022-02-24 06:16:30 UTC (rev 290412)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.h	2022-02-24 06:35:55 UTC (rev 290413)
@@ -94,6 +94,7 @@
 
 private:
     RemoteVideoFrameProxy(IPC::Connection&, RemoteVideoFrameObjectHeapProxy&, Properties&&);
+    static inline Seconds defaultTimeout = 10_s;
 
     const Ref<IPC::Connection> m_connection;
     RemoteVideoFrameReferenceTracker m_referenceTracker;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to