Title: [290150] trunk/Source/WebCore
Revision
290150
Author
commit-qu...@webkit.org
Date
2022-02-18 12:17:45 -0800 (Fri, 18 Feb 2022)

Log Message

[TextureMapper] Refactor TextureMapperPlatformLayerProxy into specializable implementations
https://bugs.webkit.org/show_bug.cgi?id=236836

Patch by Zan Dobersek <zdober...@igalia.com> on 2022-02-18
Reviewed by Alejandro G. Castro.

Turn TextureMapperPlatformLayerProxy into an abstract class from which
different specializations can then be derived. Current implementation is
spun off into the TextureMapperPlatformLayerProxyGL class, and type
traits specialization facilities are provided for future parallel
implementations (e.g. a DMABuf-consuming proxy class).

Existing uses of TextureMapperPlatformLayerProxy are updated to use
the TextureMapperPlatformLayerProxyGL class instead. Downcasting is
done as necessary, with asserts checking for the expected implementation
type.

No change in functionality, only refactoring existing code.

* platform/TextureMapper.cmake:
* platform/graphics/gstreamer/GStreamerVideoFrameHolder.h:
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
(WebCore::MediaPlayerPrivateGStreamer::pushTextureToCompositor):
(WebCore::MediaPlayerPrivateGStreamer::triggerRepaint):
(WebCore::MediaPlayerPrivateGStreamer::flushCurrentBuffer):
(WebCore::MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer):
* platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp:
(WebCore::MediaPlayerPrivateHolePunch::MediaPlayerPrivateHolePunch):
(WebCore::MediaPlayerPrivateHolePunch::pushNextHolePunchBuffer):
* platform/graphics/nicosia/NicosiaImageBufferPipe.cpp:
(Nicosia::NicosiaImageBufferPipeSource::handle):
* platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp:
(Nicosia::ContentLayerTextureMapperImpl::createFactory):
(Nicosia::ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl):
* platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h:
* platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
(Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
* platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp:
(Nicosia::GCGLLayer::swapBuffersIfNeeded):
* platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
(WebCore::TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer):
(WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded):
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:
(WebCore::TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::activateOnCompositingThread): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::invalidate): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::pushNextBuffer): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::getAvailableBuffer): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::appendToUnusedBuffers): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::scheduleReleaseUnusedBuffers): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::swapBuffer): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::scheduleUpdateOnCompositorThread): Deleted.
(WebCore::TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired): Deleted.
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.h:
(WebCore::TextureMapperPlatformLayerProxy::isGLBased const):
(WebCore::TextureMapperPlatformLayerProxy::isDMABufBased const):
(WebCore::TextureMapperPlatformLayerProxy::WTF_RETURNS_LOCK):
(WebCore::TextureMapperPlatformLayerProxy::WTF_GUARDED_BY_LOCK): Deleted.
* platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp: Copied from Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp.
(WebCore::TextureMapperPlatformLayerProxyGL::~TextureMapperPlatformLayerProxyGL):
(WebCore::TextureMapperPlatformLayerProxyGL::activateOnCompositingThread):
(WebCore::TextureMapperPlatformLayerProxyGL::invalidate):
(WebCore::TextureMapperPlatformLayerProxyGL::pushNextBuffer):
(WebCore::TextureMapperPlatformLayerProxyGL::getAvailableBuffer):
(WebCore::TextureMapperPlatformLayerProxyGL::appendToUnusedBuffers):
(WebCore::TextureMapperPlatformLayerProxyGL::scheduleReleaseUnusedBuffers):
(WebCore::TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired):
(WebCore::TextureMapperPlatformLayerProxyGL::swapBuffer):
(WebCore::TextureMapperPlatformLayerProxyGL::dropCurrentBufferWhilePreservingTexture):
(WebCore::TextureMapperPlatformLayerProxyGL::scheduleUpdateOnCompositorThread):
(WebCore::TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired):
* platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h: Copied from Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290149 => 290150)


--- trunk/Source/WebCore/ChangeLog	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/ChangeLog	2022-02-18 20:17:45 UTC (rev 290150)
@@ -1,3 +1,81 @@
+2022-02-18  Zan Dobersek  <zdober...@igalia.com>
+
+        [TextureMapper] Refactor TextureMapperPlatformLayerProxy into specializable implementations
+        https://bugs.webkit.org/show_bug.cgi?id=236836
+
+        Reviewed by Alejandro G. Castro.
+
+        Turn TextureMapperPlatformLayerProxy into an abstract class from which
+        different specializations can then be derived. Current implementation is
+        spun off into the TextureMapperPlatformLayerProxyGL class, and type
+        traits specialization facilities are provided for future parallel
+        implementations (e.g. a DMABuf-consuming proxy class).
+
+        Existing uses of TextureMapperPlatformLayerProxy are updated to use
+        the TextureMapperPlatformLayerProxyGL class instead. Downcasting is
+        done as necessary, with asserts checking for the expected implementation
+        type.
+
+        No change in functionality, only refactoring existing code.
+
+        * platform/TextureMapper.cmake:
+        * platform/graphics/gstreamer/GStreamerVideoFrameHolder.h:
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
+        (WebCore::MediaPlayerPrivateGStreamer::pushTextureToCompositor):
+        (WebCore::MediaPlayerPrivateGStreamer::triggerRepaint):
+        (WebCore::MediaPlayerPrivateGStreamer::flushCurrentBuffer):
+        (WebCore::MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer):
+        * platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp:
+        (WebCore::MediaPlayerPrivateHolePunch::MediaPlayerPrivateHolePunch):
+        (WebCore::MediaPlayerPrivateHolePunch::pushNextHolePunchBuffer):
+        * platform/graphics/nicosia/NicosiaImageBufferPipe.cpp:
+        (Nicosia::NicosiaImageBufferPipeSource::handle):
+        * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp:
+        (Nicosia::ContentLayerTextureMapperImpl::createFactory):
+        (Nicosia::ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl):
+        * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h:
+        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
+        (Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
+        * platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp:
+        (Nicosia::GCGLLayer::swapBuffersIfNeeded):
+        * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
+        (WebCore::TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer):
+        (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded):
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:
+        (WebCore::TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::activateOnCompositingThread): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::invalidate): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::pushNextBuffer): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::getAvailableBuffer): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::appendToUnusedBuffers): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::scheduleReleaseUnusedBuffers): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::swapBuffer): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::scheduleUpdateOnCompositorThread): Deleted.
+        (WebCore::TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired): Deleted.
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.h:
+        (WebCore::TextureMapperPlatformLayerProxy::isGLBased const):
+        (WebCore::TextureMapperPlatformLayerProxy::isDMABufBased const):
+        (WebCore::TextureMapperPlatformLayerProxy::WTF_RETURNS_LOCK):
+        (WebCore::TextureMapperPlatformLayerProxy::WTF_GUARDED_BY_LOCK): Deleted.
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp: Copied from Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp.
+        (WebCore::TextureMapperPlatformLayerProxyGL::~TextureMapperPlatformLayerProxyGL):
+        (WebCore::TextureMapperPlatformLayerProxyGL::activateOnCompositingThread):
+        (WebCore::TextureMapperPlatformLayerProxyGL::invalidate):
+        (WebCore::TextureMapperPlatformLayerProxyGL::pushNextBuffer):
+        (WebCore::TextureMapperPlatformLayerProxyGL::getAvailableBuffer):
+        (WebCore::TextureMapperPlatformLayerProxyGL::appendToUnusedBuffers):
+        (WebCore::TextureMapperPlatformLayerProxyGL::scheduleReleaseUnusedBuffers):
+        (WebCore::TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired):
+        (WebCore::TextureMapperPlatformLayerProxyGL::swapBuffer):
+        (WebCore::TextureMapperPlatformLayerProxyGL::dropCurrentBufferWhilePreservingTexture):
+        (WebCore::TextureMapperPlatformLayerProxyGL::scheduleUpdateOnCompositorThread):
+        (WebCore::TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired):
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h: Copied from Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h.
+
 2022-02-18  Brandon Stewart  <brandonstew...@apple.com>
 
         Generate compile_commands.json on macOS Builds

Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (290149 => 290150)


--- trunk/Source/WebCore/platform/TextureMapper.cmake	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake	2022-02-18 20:17:45 UTC (rev 290150)
@@ -36,6 +36,7 @@
     platform/graphics/texmap/TextureMapperLayer.h
     platform/graphics/texmap/TextureMapperPlatformLayer.h
     platform/graphics/texmap/TextureMapperPlatformLayerProxy.h
+    platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h
     platform/graphics/texmap/TextureMapperPlatformLayerProxyProvider.h
     platform/graphics/texmap/TextureMapperSolidColorLayer.h
     platform/graphics/texmap/TextureMapperTile.h
@@ -61,6 +62,7 @@
         platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp
         platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.cpp
         platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp
+        platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp
 
         platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp
         platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h	2022-02-18 20:17:45 UTC (rev 290150)
@@ -24,7 +24,6 @@
 
 #include "MediaPlayerPrivateGStreamer.h"
 #include "TextureMapperPlatformLayerBuffer.h"
-#include "TextureMapperPlatformLayerProxy.h"
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -115,7 +115,7 @@
 #include "GStreamerVideoFrameHolder.h"
 #include "TextureMapperContextAttributes.h"
 #include "TextureMapperPlatformLayerBuffer.h"
-#include "TextureMapperPlatformLayerProxy.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
 #endif // USE(TEXTURE_MAPPER_GL)
 
 #if USE(WPE_VIDEO_PLANE_DISPLAY_DMABUF)
@@ -160,7 +160,7 @@
 #if USE(NICOSIA)
     , m_nicosiaLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this)))
 #else
-    , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxy()))
+    , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxyGL))
 #endif
 #endif
 #if !RELEASE_LOG_DISABLED
@@ -2919,7 +2919,7 @@
 
     ++m_sampleCount;
 
-    auto internalCompositingOperation = [this](TextureMapperPlatformLayerProxy& proxy, std::unique_ptr<GstVideoFrameHolder>&& frameHolder) {
+    auto internalCompositingOperation = [this](TextureMapperPlatformLayerProxyGL& proxy, std::unique_ptr<GstVideoFrameHolder>&& frameHolder) {
         std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer;
         if (frameHolder->hasMappedTextures()) {
             layerBuffer = frameHolder->platformLayerBuffer();
@@ -2941,7 +2941,7 @@
 
 #if USE(WPE_VIDEO_PLANE_DISPLAY_DMABUF)
     auto proxyOperation =
-        [this, internalCompositingOperation](TextureMapperPlatformLayerProxy& proxy)
+        [this, internalCompositingOperation](TextureMapperPlatformLayerProxyGL& proxy)
         {
             Locker locker { proxy.lock() };
 
@@ -2959,7 +2959,7 @@
         };
 #else
     auto proxyOperation =
-        [this, internalCompositingOperation](TextureMapperPlatformLayerProxy& proxy)
+        [this, internalCompositingOperation](TextureMapperPlatformLayerProxyGL& proxy)
         {
             Locker locker { proxy.lock() };
 
@@ -2972,7 +2972,9 @@
 #endif // USE(WPE_VIDEO_PLANE_DISPLAY_DMABUF)
 
 #if USE(NICOSIA)
-    proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy());
+    auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy();
+    ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+    proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy));
 #else
     proxyOperation(*m_platformLayerProxy);
 #endif
@@ -3168,12 +3170,14 @@
     if (m_isUsingFallbackVideoSink) {
         Locker locker { m_drawLock };
         auto proxyOperation =
-            [this](TextureMapperPlatformLayerProxy& proxy)
+            [this](TextureMapperPlatformLayerProxyGL& proxy)
             {
                 return proxy.scheduleUpdateOnCompositorThread([this] { this->pushTextureToCompositor(); });
             };
 #if USE(NICOSIA)
-        if (!proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy()))
+        auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy();
+        ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+        if (!proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy)))
             return;
 #else
         if (!proxyOperation(*m_platformLayerProxy))
@@ -3231,7 +3235,7 @@
     }
 
     bool shouldWait = m_videoDecoderPlatform == GstVideoDecoderPlatform::Video4Linux;
-    auto proxyOperation = [shouldWait, pipeline = pipeline()](TextureMapperPlatformLayerProxy& proxy) {
+    auto proxyOperation = [shouldWait, pipeline = pipeline()](TextureMapperPlatformLayerProxyGL& proxy) {
         GST_DEBUG_OBJECT(pipeline, "Flushing video sample %s", shouldWait ? "synchronously" : "");
         if (shouldWait) {
             if (proxy.isActive())
@@ -3244,7 +3248,9 @@
     };
 
 #if USE(NICOSIA)
-    proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy());
+    auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy();
+    if (is<TextureMapperPlatformLayerProxyGL>(proxy))
+        proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy));
 #else
     proxyOperation(*m_platformLayerProxy);
 #endif
@@ -3471,7 +3477,7 @@
 void MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer()
 {
     auto proxyOperation =
-        [this](TextureMapperPlatformLayerProxy& proxy)
+        [this](TextureMapperPlatformLayerProxyGL& proxy)
         {
             Locker locker { proxy.lock() };
             std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(0, m_size, TextureMapperGL::ShouldNotBlend, GL_DONT_CARE);
@@ -3481,7 +3487,9 @@
         };
 
 #if USE(NICOSIA)
-    proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy());
+    auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy();
+    ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+    proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy));
 #else
     proxyOperation(*m_platformLayerProxy);
 #endif

Modified: trunk/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -24,7 +24,7 @@
 #if USE(EXTERNAL_HOLEPUNCH)
 #include "MediaPlayer.h"
 #include "TextureMapperPlatformLayerBuffer.h"
-#include "TextureMapperPlatformLayerProxy.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
 
 namespace WebCore {
 
@@ -36,7 +36,7 @@
 #if USE(NICOSIA)
     , m_nicosiaLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this)))
 #else
-    , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxy()))
+    , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxyGL))
 #endif
 {
     pushNextHolePunchBuffer();
@@ -73,7 +73,7 @@
 void MediaPlayerPrivateHolePunch::pushNextHolePunchBuffer()
 {
     auto proxyOperation =
-        [this](TextureMapperPlatformLayerProxy& proxy)
+        [this](TextureMapperPlatformLayerProxyGL& proxy)
         {
             Locker locker { proxy.lock() };
             std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(0, m_size, TextureMapperGL::ShouldNotBlend, GL_DONT_CARE);
@@ -81,7 +81,9 @@
         };
 
 #if USE(NICOSIA)
-    proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy());
+    auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy();
+    ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+    proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy));
 #else
     proxyOperation(*m_platformLayerProxy);
 #endif

Modified: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -31,7 +31,7 @@
 #include "NativeImage.h"
 #include "NicosiaPlatformLayer.h"
 #include "TextureMapperPlatformLayerBuffer.h"
-#include "TextureMapperPlatformLayerProxy.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
 
 #if USE(CAIRO)
 #include <cairo.h>
@@ -62,7 +62,7 @@
 
     if (!m_imageBuffer) {
         auto proxyOperation = [this] (TextureMapperPlatformLayerProxy& proxy) mutable {
-            return proxy.scheduleUpdateOnCompositorThread([this] () mutable {
+            return downcast<TextureMapperPlatformLayerProxyGL>(proxy).scheduleUpdateOnCompositorThread([this] () mutable {
                 auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy();
                 Locker locker { proxy.lock() };
 
@@ -95,7 +95,7 @@
 
                 auto layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture));
                 layerBuffer->setExtraFlags(TextureMapperGL::ShouldBlend);
-                proxy.pushNextBuffer(WTFMove(layerBuffer));
+                downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer));
             });
         };
         proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy());

Modified: trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -31,7 +31,7 @@
 
 #if USE(TEXTURE_MAPPER)
 
-#include "TextureMapperPlatformLayerProxy.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
 
 namespace Nicosia {
 
@@ -39,12 +39,12 @@
 {
     return Factory(
         [&client](ContentLayer&) {
-            return makeUnique<ContentLayerTextureMapperImpl>(client);
+            return makeUnique<ContentLayerTextureMapperImpl>(client, adoptRef(*new WebCore::TextureMapperPlatformLayerProxyGL));
         });
 }
 
-ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl(Client& client)
-    : m_proxy(adoptRef(*new WebCore::TextureMapperPlatformLayerProxy))
+ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl(Client& client, Ref<WebCore::TextureMapperPlatformLayerProxy>&& proxy)
+    : m_proxy(WTFMove(proxy))
     , m_client { { }, &client }
 {
 }

Modified: trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h	2022-02-18 20:17:45 UTC (rev 290150)
@@ -51,7 +51,7 @@
 
     static Factory createFactory(Client&);
 
-    explicit ContentLayerTextureMapperImpl(Client&);
+    explicit ContentLayerTextureMapperImpl(Client&, Ref<WebCore::TextureMapperPlatformLayerProxy>&&);
     virtual ~ContentLayerTextureMapperImpl();
     bool isTextureMapperImpl() const override { return true; }
 

Modified: trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -36,7 +36,7 @@
 #include "Logging.h"
 #include "TextureMapperGL.h"
 #include "TextureMapperPlatformLayerDmabuf.h"
-#include "TextureMapperPlatformLayerProxy.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
 
 namespace Nicosia {
 
@@ -62,7 +62,8 @@
 
         {
             Locker locker { proxy.lock() };
-            proxy.pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd));
+            ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+            downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd));
         }
 
         m_context.markLayerComposited();
@@ -78,7 +79,8 @@
     auto flags = m_context.contextAttributes().alpha ? BitmapTexture::SupportsAlpha : BitmapTexture::NoFlag;
     {
         Locker locker { proxy.lock() };
-        std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = proxy.getAvailableBuffer(size, m_context.m_internalColorFormat);
+        ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+        std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = downcast<TextureMapperPlatformLayerProxyGL>(proxy).getAvailableBuffer(size, m_context.m_internalColorFormat);
         if (!layerBuffer) {
             auto texture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), flags, m_context.m_internalColorFormat);
             layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture), flags);
@@ -85,7 +87,7 @@
         }
 
         layerBuffer->textureGL().setPendingContents(ImageBuffer::sinkIntoImage(WTFMove(imageBuffer)));
-        proxy.pushNextBuffer(WTFMove(layerBuffer));
+        downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer));
     }
     m_context.markLayerComposited();
 }

Modified: trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -34,7 +34,7 @@
 #if USE(COORDINATED_GRAPHICS)
 #include "TextureMapperGL.h"
 #include "TextureMapperPlatformLayerBuffer.h"
-#include "TextureMapperPlatformLayerProxy.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
 #endif
 
 #include "GLContext.h"
@@ -83,7 +83,8 @@
     {
         auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_contentLayer->impl()).proxy();
         Locker locker { proxy.lock() };
-        proxy.pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat));
+        ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
+        downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat));
     }
 
     m_context.markLayerComposited();

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -44,7 +44,7 @@
 #endif
 
 #if USE(COORDINATED_GRAPHICS)
-    m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxy());
+    m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxyGL);
 #endif
 }
 
@@ -97,7 +97,7 @@
 
     {
         Locker locker { m_platformLayerProxy->lock() };
-        m_platformLayerProxy->pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat));
+        downcast<TextureMapperPlatformLayerProxyGL>(*m_platformLayerProxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat));
     }
 
     m_context.markLayerComposited();

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -28,90 +28,11 @@
 
 #if USE(COORDINATED_GRAPHICS)
 
-#include "BitmapTextureGL.h"
-#include "TextureMapperGL.h"
-#include "TextureMapperLayer.h"
-#include "TextureMapperPlatformLayerBuffer.h"
-
-#if USE(GLIB_EVENT_LOOP)
-#include <wtf/glib/RunLoopSourcePriority.h>
-#endif
-#include <wtf/Scope.h>
-
-static const Seconds releaseUnusedSecondsTolerance { 1_s };
-static const Seconds releaseUnusedBuffersTimerInterval = { 500_ms };
-
 namespace WebCore {
 
-TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy()
-    : m_compositor(nullptr)
-    , m_targetLayer(nullptr)
-{
-}
+TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy() = default;
+TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy() = default;
 
-TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy()
-{
-    Locker locker { m_lock };
-    if (m_targetLayer)
-        m_targetLayer->setContentsLayer(nullptr);
-}
-
-void TextureMapperPlatformLayerProxy::activateOnCompositingThread(Compositor* compositor, TextureMapperLayer* targetLayer)
-{
-#ifndef NDEBUG
-    if (!m_compositorThread)
-        m_compositorThread = &Thread::current();
-#endif
-    ASSERT(m_compositorThread == &Thread::current());
-    ASSERT(compositor);
-    ASSERT(targetLayer);
-    Function<void()> updateFunction;
-    {
-        Locker locker { m_lock };
-        m_compositor = compositor;
-        m_targetLayer = targetLayer;
-        if (m_targetLayer && m_currentBuffer)
-            m_targetLayer->setContentsLayer(m_currentBuffer.get());
-
-        m_releaseUnusedBuffersTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxy>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired);
-        m_compositorThreadUpdateTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxy>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired);
-
-#if USE(GLIB_EVENT_LOOP)
-        m_compositorThreadUpdateTimer->setPriority(RunLoopSourcePriority::CompositingThreadUpdateTimer);
-        m_releaseUnusedBuffersTimer->setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer);
-#endif
-
-        if (!m_compositorThreadUpdateFunction)
-            return;
-        updateFunction = WTFMove(m_compositorThreadUpdateFunction);
-    }
-    updateFunction();
-}
-
-void TextureMapperPlatformLayerProxy::invalidate()
-{
-    ASSERT(m_compositorThread == &Thread::current());
-    Function<void()> updateFunction;
-    {
-        Locker locker { m_lock };
-        m_compositor = nullptr;
-        m_targetLayer = nullptr;
-
-        m_currentBuffer = nullptr;
-        m_pendingBuffer = nullptr;
-        m_releaseUnusedBuffersTimer = nullptr;
-        m_usedBuffers.clear();
-
-        // Clear the timer and dispatch the update function manually now.
-        m_compositorThreadUpdateTimer = nullptr;
-        if (!m_compositorThreadUpdateFunction)
-            return;
-        updateFunction = WTFMove(m_compositorThreadUpdateFunction);
-    }
-
-    updateFunction();
-}
-
 bool TextureMapperPlatformLayerProxy::isActive()
 {
     ASSERT(m_lock.isHeld());
@@ -118,168 +39,6 @@
     return !!m_targetLayer && !!m_compositor;
 }
 
-void TextureMapperPlatformLayerProxy::pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&& newBuffer)
-{
-    ASSERT(m_lock.isHeld());
-#if USE(ANGLE)
-    // When the newBuffer overwrites m_pendingBuffer that is not swapped yet,
-    // the layer related to m_pendingBuffer is flickering since its texture is destroyed.
-    if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture())
-        return;
-#endif
-    m_pendingBuffer = WTFMove(newBuffer);
-    m_wasBufferDropped = false;
-
-    if (m_compositor)
-        m_compositor->onNewBufferAvailable();
-}
-
-std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerProxy::getAvailableBuffer(const IntSize& size, GLint internalFormat)
-{
-    ASSERT(m_lock.isHeld());
-    ASSERT(m_compositorThread == &Thread::current());
-    std::unique_ptr<TextureMapperPlatformLayerBuffer> availableBuffer;
-
-    auto buffers = WTFMove(m_usedBuffers);
-    for (auto& buffer : buffers) {
-        if (!buffer)
-            continue;
-
-        if (!availableBuffer && buffer->canReuseWithoutReset(size, internalFormat)) {
-            availableBuffer = WTFMove(buffer);
-            availableBuffer->markUsed();
-            continue;
-        }
-        m_usedBuffers.append(WTFMove(buffer));
-    }
-
-    if (!m_usedBuffers.isEmpty())
-        scheduleReleaseUnusedBuffers();
-    return availableBuffer;
-}
-
-void TextureMapperPlatformLayerProxy::appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer> buffer)
-{
-    ASSERT(m_lock.isHeld());
-    ASSERT(m_compositorThread == &Thread::current());
-    m_usedBuffers.append(WTFMove(buffer));
-    scheduleReleaseUnusedBuffers();
-}
-
-void TextureMapperPlatformLayerProxy::scheduleReleaseUnusedBuffers()
-{
-    if (!m_releaseUnusedBuffersTimer->isActive())
-        m_releaseUnusedBuffersTimer->startOneShot(releaseUnusedBuffersTimerInterval);
-}
-
-void TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired()
-{
-    Locker locker { m_lock };
-    if (m_usedBuffers.isEmpty())
-        return;
-
-    auto buffers = WTFMove(m_usedBuffers);
-    MonotonicTime minUsedTime = MonotonicTime::now() - releaseUnusedSecondsTolerance;
-
-    for (auto& buffer : buffers) {
-        if (buffer && buffer->lastUsedTime() >= minUsedTime)
-            m_usedBuffers.append(WTFMove(buffer));
-    }
-}
-
-void TextureMapperPlatformLayerProxy::swapBuffer()
-{
-    ASSERT(m_compositorThread == &Thread::current());
-    Locker locker { m_lock };
-    if (!m_targetLayer || !m_pendingBuffer)
-        return;
-
-    auto prevBuffer = WTFMove(m_currentBuffer);
-
-    m_currentBuffer = WTFMove(m_pendingBuffer);
-    m_targetLayer->setContentsLayer(m_currentBuffer.get());
-
-    if (prevBuffer && prevBuffer->hasManagedTexture())
-        appendToUnusedBuffers(WTFMove(prevBuffer));
-}
-
-void TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture(bool shouldWait)
-{
-    if (!shouldWait)
-        ASSERT(m_lock.isHeld());
-
-    if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture()) {
-        m_usedBuffers.append(WTFMove(m_pendingBuffer));
-        scheduleReleaseUnusedBuffers();
-    }
-
-    if (!m_compositorThreadUpdateTimer)
-        return;
-
-    m_compositorThreadUpdateFunction =
-        [this, shouldWait] {
-            Locker locker { m_lock };
-
-            auto maybeNotifySynchronousOperation = makeScopeExit([this, shouldWait]() {
-                if (shouldWait) {
-                    Locker locker { m_wasBufferDroppedLock };
-                    m_wasBufferDropped = true;
-                    m_wasBufferDroppedCondition.notifyAll();
-                }
-            });
-
-            if (!m_compositor || !m_targetLayer || !m_currentBuffer)
-                return;
-
-            m_pendingBuffer = m_currentBuffer->clone();
-            auto prevBuffer = WTFMove(m_currentBuffer);
-            m_currentBuffer = WTFMove(m_pendingBuffer);
-            m_targetLayer->setContentsLayer(m_currentBuffer.get());
-
-            if (prevBuffer->hasManagedTexture())
-                appendToUnusedBuffers(WTFMove(prevBuffer));
-        };
-
-    if (shouldWait) {
-        Locker locker { m_wasBufferDroppedLock };
-        m_wasBufferDropped = false;
-    }
-
-    m_compositorThreadUpdateTimer->startOneShot(0_s);
-    if (shouldWait) {
-        Locker locker { m_wasBufferDroppedLock };
-        m_wasBufferDroppedCondition.wait(m_wasBufferDroppedLock, [this] {
-            assertIsHeld(m_wasBufferDroppedLock);
-            return m_wasBufferDropped;
-        });
-    }
-}
-
-bool TextureMapperPlatformLayerProxy::scheduleUpdateOnCompositorThread(Function<void()>&& updateFunction)
-{
-    Locker locker { m_lock };
-    m_compositorThreadUpdateFunction = WTFMove(updateFunction);
-
-    if (!m_compositorThreadUpdateTimer)
-        return false;
-
-    m_compositorThreadUpdateTimer->startOneShot(0_s);
-    return true;
-}
-
-void TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired()
-{
-    Function<void()> updateFunction;
-    {
-        Locker locker { m_lock };
-        if (!m_compositorThreadUpdateFunction)
-            return;
-        updateFunction = WTFMove(m_compositorThreadUpdateFunction);
-    }
-
-    updateFunction();
-}
-
 } // namespace WebCore
 
 #endif // USE(COORDINATED_GRAPHICS)

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h (290149 => 290150)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h	2022-02-18 20:06:08 UTC (rev 290149)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h	2022-02-18 20:17:45 UTC (rev 290150)
@@ -27,18 +27,9 @@
 
 #if USE(COORDINATED_GRAPHICS)
 
-#include "TextureMapperGLHeaders.h"
-#include <wtf/Condition.h>
-#include <wtf/Function.h>
 #include <wtf/Lock.h>
-#include <wtf/RunLoop.h>
 #include <wtf/ThreadSafeRefCounted.h>
-#include <wtf/Vector.h>
 
-#ifndef NDEBUG
-#include <wtf/Threading.h>
-#endif
-
 namespace WebCore {
 
 class IntSize;
@@ -57,51 +48,27 @@
     TextureMapperPlatformLayerProxy();
     virtual ~TextureMapperPlatformLayerProxy();
 
-    // To avoid multiple lock/release situation to update a single frame,
-    // the implementation of TextureMapperPlatformLayerProxyProvider should
-    // aquire / release the lock explicitly to use below methods.
+    virtual bool isGLBased() const { return false; }
+    virtual bool isDMABufBased() const { return false; }
+
     Lock& lock() WTF_RETURNS_LOCK(m_lock) { return m_lock; }
-    std::unique_ptr<TextureMapperPlatformLayerBuffer> getAvailableBuffer(const IntSize&, GLint internalFormat);
-    void pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&&);
     bool isActive();
 
-    WEBCORE_EXPORT void activateOnCompositingThread(Compositor*, TextureMapperLayer*);
-    WEBCORE_EXPORT void invalidate();
+    virtual void activateOnCompositingThread(Compositor*, TextureMapperLayer*) = 0;
+    virtual void invalidate() = 0;
+    virtual void swapBuffer() = 0;
 
-    WEBCORE_EXPORT void swapBuffer();
-    void dropCurrentBufferWhilePreservingTexture(bool shouldWait = false);
-
-    bool scheduleUpdateOnCompositorThread(Function<void()>&&);
-
-private:
-    void appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer>);
-    void scheduleReleaseUnusedBuffers();
-    void releaseUnusedBuffersTimerFired();
-
-    Compositor* m_compositor;
-    TextureMapperLayer* m_targetLayer;
-
-    std::unique_ptr<TextureMapperPlatformLayerBuffer> m_currentBuffer;
-    std::unique_ptr<TextureMapperPlatformLayerBuffer> m_pendingBuffer;
-
+protected:
     Lock m_lock;
-
-    Lock m_wasBufferDroppedLock;
-    Condition m_wasBufferDroppedCondition;
-    bool m_wasBufferDropped WTF_GUARDED_BY_LOCK(m_wasBufferDroppedLock) { false };
-
-    Vector<std::unique_ptr<TextureMapperPlatformLayerBuffer>> m_usedBuffers;
-    std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxy>> m_releaseUnusedBuffersTimer;
-
-#ifndef NDEBUG
-    RefPtr<Thread> m_compositorThread;
-#endif
-
-    void compositorThreadUpdateTimerFired();
-    std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxy>> m_compositorThreadUpdateTimer;
-    Function<void()> m_compositorThreadUpdateFunction;
+    Compositor* m_compositor { nullptr };
+    TextureMapperLayer* m_targetLayer { nullptr };
 };
 
 } // namespace WebCore
 
+#define SPECIALIZE_TYPE_TRAITS_TEXTUREMAPPER_PLATFORMLAYERPROXY(ToClassName, predicate) \
+    SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
+    static bool isType(const WebCore::TextureMapperPlatformLayerProxy& proxy) { return proxy.predicate; } \
+    SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // USE(COORDINATED_GRAPHICS)

Copied: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp (from rev 290149, trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp) (0 => 290150)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp	2022-02-18 20:17:45 UTC (rev 290150)
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextureMapperPlatformLayerProxyGL.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include "BitmapTextureGL.h"
+#include "TextureMapperGL.h"
+#include "TextureMapperLayer.h"
+#include "TextureMapperPlatformLayerBuffer.h"
+
+#if USE(GLIB_EVENT_LOOP)
+#include <wtf/glib/RunLoopSourcePriority.h>
+#endif
+#include <wtf/Scope.h>
+
+static const Seconds releaseUnusedSecondsTolerance { 1_s };
+static const Seconds releaseUnusedBuffersTimerInterval = { 500_ms };
+
+namespace WebCore {
+
+TextureMapperPlatformLayerProxyGL::TextureMapperPlatformLayerProxyGL() = default;
+
+TextureMapperPlatformLayerProxyGL::~TextureMapperPlatformLayerProxyGL()
+{
+    Locker locker { m_lock };
+    if (m_targetLayer)
+        m_targetLayer->setContentsLayer(nullptr);
+}
+
+void TextureMapperPlatformLayerProxyGL::activateOnCompositingThread(Compositor* compositor, TextureMapperLayer* targetLayer)
+{
+#ifndef NDEBUG
+    if (!m_compositorThread)
+        m_compositorThread = &Thread::current();
+#endif
+    ASSERT(m_compositorThread == &Thread::current());
+    ASSERT(compositor);
+    ASSERT(targetLayer);
+    Function<void()> updateFunction;
+    {
+        Locker locker { m_lock };
+        m_compositor = compositor;
+        m_targetLayer = targetLayer;
+        if (m_targetLayer && m_currentBuffer)
+            m_targetLayer->setContentsLayer(m_currentBuffer.get());
+
+        m_releaseUnusedBuffersTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired);
+        m_compositorThreadUpdateTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired);
+
+#if USE(GLIB_EVENT_LOOP)
+        m_compositorThreadUpdateTimer->setPriority(RunLoopSourcePriority::CompositingThreadUpdateTimer);
+        m_releaseUnusedBuffersTimer->setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer);
+#endif
+
+        if (!m_compositorThreadUpdateFunction)
+            return;
+        updateFunction = WTFMove(m_compositorThreadUpdateFunction);
+    }
+    updateFunction();
+}
+
+void TextureMapperPlatformLayerProxyGL::invalidate()
+{
+    ASSERT(m_compositorThread == &Thread::current());
+    Function<void()> updateFunction;
+    {
+        Locker locker { m_lock };
+        m_compositor = nullptr;
+        m_targetLayer = nullptr;
+
+        m_currentBuffer = nullptr;
+        m_pendingBuffer = nullptr;
+        m_releaseUnusedBuffersTimer = nullptr;
+        m_usedBuffers.clear();
+
+        // Clear the timer and dispatch the update function manually now.
+        m_compositorThreadUpdateTimer = nullptr;
+        if (!m_compositorThreadUpdateFunction)
+            return;
+        updateFunction = WTFMove(m_compositorThreadUpdateFunction);
+    }
+
+    updateFunction();
+}
+
+void TextureMapperPlatformLayerProxyGL::pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&& newBuffer)
+{
+    ASSERT(m_lock.isHeld());
+#if USE(ANGLE)
+    // When the newBuffer overwrites m_pendingBuffer that is not swapped yet,
+    // the layer related to m_pendingBuffer is flickering since its texture is destroyed.
+    if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture())
+        return;
+#endif
+    m_pendingBuffer = WTFMove(newBuffer);
+    m_wasBufferDropped = false;
+
+    if (m_compositor)
+        m_compositor->onNewBufferAvailable();
+}
+
+std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerProxyGL::getAvailableBuffer(const IntSize& size, GLint internalFormat)
+{
+    ASSERT(m_lock.isHeld());
+    ASSERT(m_compositorThread == &Thread::current());
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> availableBuffer;
+
+    auto buffers = WTFMove(m_usedBuffers);
+    for (auto& buffer : buffers) {
+        if (!buffer)
+            continue;
+
+        if (!availableBuffer && buffer->canReuseWithoutReset(size, internalFormat)) {
+            availableBuffer = WTFMove(buffer);
+            availableBuffer->markUsed();
+            continue;
+        }
+        m_usedBuffers.append(WTFMove(buffer));
+    }
+
+    if (!m_usedBuffers.isEmpty())
+        scheduleReleaseUnusedBuffers();
+    return availableBuffer;
+}
+
+void TextureMapperPlatformLayerProxyGL::appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer> buffer)
+{
+    ASSERT(m_lock.isHeld());
+    ASSERT(m_compositorThread == &Thread::current());
+    m_usedBuffers.append(WTFMove(buffer));
+    scheduleReleaseUnusedBuffers();
+}
+
+void TextureMapperPlatformLayerProxyGL::scheduleReleaseUnusedBuffers()
+{
+    if (!m_releaseUnusedBuffersTimer->isActive())
+        m_releaseUnusedBuffersTimer->startOneShot(releaseUnusedBuffersTimerInterval);
+}
+
+void TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired()
+{
+    Locker locker { m_lock };
+    if (m_usedBuffers.isEmpty())
+        return;
+
+    auto buffers = WTFMove(m_usedBuffers);
+    MonotonicTime minUsedTime = MonotonicTime::now() - releaseUnusedSecondsTolerance;
+
+    for (auto& buffer : buffers) {
+        if (buffer && buffer->lastUsedTime() >= minUsedTime)
+            m_usedBuffers.append(WTFMove(buffer));
+    }
+}
+
+void TextureMapperPlatformLayerProxyGL::swapBuffer()
+{
+    ASSERT(m_compositorThread == &Thread::current());
+    Locker locker { m_lock };
+    if (!m_targetLayer || !m_pendingBuffer)
+        return;
+
+    auto prevBuffer = WTFMove(m_currentBuffer);
+
+    m_currentBuffer = WTFMove(m_pendingBuffer);
+    m_targetLayer->setContentsLayer(m_currentBuffer.get());
+
+    if (prevBuffer && prevBuffer->hasManagedTexture())
+        appendToUnusedBuffers(WTFMove(prevBuffer));
+}
+
+void TextureMapperPlatformLayerProxyGL::dropCurrentBufferWhilePreservingTexture(bool shouldWait)
+{
+    if (!shouldWait)
+        ASSERT(m_lock.isHeld());
+
+    if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture()) {
+        m_usedBuffers.append(WTFMove(m_pendingBuffer));
+        scheduleReleaseUnusedBuffers();
+    }
+
+    if (!m_compositorThreadUpdateTimer)
+        return;
+
+    m_compositorThreadUpdateFunction =
+        [this, shouldWait] {
+            Locker locker { m_lock };
+
+            auto maybeNotifySynchronousOperation = makeScopeExit([this, shouldWait]() {
+                if (shouldWait) {
+                    Locker locker { m_wasBufferDroppedLock };
+                    m_wasBufferDropped = true;
+                    m_wasBufferDroppedCondition.notifyAll();
+                }
+            });
+
+            if (!m_compositor || !m_targetLayer || !m_currentBuffer)
+                return;
+
+            m_pendingBuffer = m_currentBuffer->clone();
+            auto prevBuffer = WTFMove(m_currentBuffer);
+            m_currentBuffer = WTFMove(m_pendingBuffer);
+            m_targetLayer->setContentsLayer(m_currentBuffer.get());
+
+            if (prevBuffer->hasManagedTexture())
+                appendToUnusedBuffers(WTFMove(prevBuffer));
+        };
+
+    if (shouldWait) {
+        Locker locker { m_wasBufferDroppedLock };
+        m_wasBufferDropped = false;
+    }
+
+    m_compositorThreadUpdateTimer->startOneShot(0_s);
+    if (shouldWait) {
+        Locker locker { m_wasBufferDroppedLock };
+        m_wasBufferDroppedCondition.wait(m_wasBufferDroppedLock, [this] {
+            assertIsHeld(m_wasBufferDroppedLock);
+            return m_wasBufferDropped;
+        });
+    }
+}
+
+bool TextureMapperPlatformLayerProxyGL::scheduleUpdateOnCompositorThread(Function<void()>&& updateFunction)
+{
+    Locker locker { m_lock };
+    m_compositorThreadUpdateFunction = WTFMove(updateFunction);
+
+    if (!m_compositorThreadUpdateTimer)
+        return false;
+
+    m_compositorThreadUpdateTimer->startOneShot(0_s);
+    return true;
+}
+
+void TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired()
+{
+    Function<void()> updateFunction;
+    {
+        Locker locker { m_lock };
+        if (!m_compositorThreadUpdateFunction)
+            return;
+        updateFunction = WTFMove(m_compositorThreadUpdateFunction);
+    }
+
+    updateFunction();
+}
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS)

Copied: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h (from rev 290149, trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h) (0 => 290150)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h	2022-02-18 20:17:45 UTC (rev 290150)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "TextureMapperPlatformLayerProxy.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include "TextureMapperGLHeaders.h"
+#include <wtf/Condition.h>
+#include <wtf/Function.h>
+#include <wtf/RunLoop.h>
+#include <wtf/Vector.h>
+
+#ifndef NDEBUG
+#include <wtf/Threading.h>
+#endif
+
+namespace WebCore {
+
+class TextureMapperPlatformLayerProxyGL final : public TextureMapperPlatformLayerProxy {
+    WTF_MAKE_FAST_ALLOCATED();
+public:
+    TextureMapperPlatformLayerProxyGL();
+    virtual ~TextureMapperPlatformLayerProxyGL();
+
+    bool isGLBased() const override { return true; }
+
+    WEBCORE_EXPORT void activateOnCompositingThread(Compositor*, TextureMapperLayer*) override;
+    WEBCORE_EXPORT void invalidate() override;
+    WEBCORE_EXPORT void swapBuffer() override;
+
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> getAvailableBuffer(const IntSize&, GLint internalFormat);
+    void pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&&);
+
+    void dropCurrentBufferWhilePreservingTexture(bool shouldWait = false);
+
+    bool scheduleUpdateOnCompositorThread(Function<void()>&&);
+
+private:
+    void appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer>);
+    void scheduleReleaseUnusedBuffers();
+    void releaseUnusedBuffersTimerFired();
+
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> m_currentBuffer;
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> m_pendingBuffer;
+
+    Lock m_wasBufferDroppedLock;
+    Condition m_wasBufferDroppedCondition;
+    bool m_wasBufferDropped WTF_GUARDED_BY_LOCK(m_wasBufferDroppedLock) { false };
+
+    Vector<std::unique_ptr<TextureMapperPlatformLayerBuffer>> m_usedBuffers;
+    std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>> m_releaseUnusedBuffersTimer;
+
+#ifndef NDEBUG
+    RefPtr<Thread> m_compositorThread;
+#endif
+
+    void compositorThreadUpdateTimerFired();
+    std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>> m_compositorThreadUpdateTimer;
+    Function<void()> m_compositorThreadUpdateFunction;
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_TEXTUREMAPPER_PLATFORMLAYERPROXY(TextureMapperPlatformLayerProxyGL, isGLBased());
+
+#endif // USE(COORDINATED_GRAPHICS)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to