Title: [292025] trunk/Source/WebCore
Revision
292025
Author
commit-qu...@webkit.org
Date
2022-03-29 00:59:35 -0700 (Tue, 29 Mar 2022)

Log Message

[GTK][WPE] Use GBMBufferSwapchain in GraphicsContextGLTextureMapperANGLE
https://bugs.webkit.org/show_bug.cgi?id=237883

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

Use the generic GBMBufferSwapchain for managing dmabuf-based buffer
objects in GraphicsContextGLTextureMapperANGLE. This usage is guarded
behind the USE(TEXTURE_MAPPER_DMABUF) build guards.

When that build guard is enabled, we can avoid using additional textures
but instead have to manage a GBMBufferSwapchain instance from which we
can retrieve buffers that should be acting as backing for the different
draw operations.

This buffer setup is handled in the
GraphicsContextGLTextureMapperANGLE::makeContextCurrent() method. Once
called, if there's a swapchain available (after initial or each
subsequent backing reshaping) a buffer will be retrieved from that
swapchain, a corresponding EGLImage created and associated to the GL
texture that acts as the color attachment for the default buffer. All
subsequent drawing will be done onto this buffer object, all the way
to the prepareForDisplay() method where that buffer is moved into the
display-buffer position, waiting for the display to occur.

The display of this buffer is still handled in Nicosia::GCGLANGLELayer.
In the swapBuffersIfNeeded() method, if the pending buffer is detected,
the dmabuf information is pushed into the
TextureMapperPlatformLayerProxyDMABuf instance and prepared for
presentation.

No new tests -- covered by existing tests, where the ANGLE-backed
GraphicsContextGL continues to improve the overall state of WebGL tests.
Only problem is the software-backed rasterization in the WPE/GTK testing
tooling which disables a few features and to a degree breaks WebGL
content display, but this specific issue will be resolved later.

* platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
(Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
(Nicosia::GCGLANGLELayer::GCGLANGLELayer):
* platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h:
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::makeContextCurrent):
(WebCore::GraphicsContextGLTextureMapperANGLE::~GraphicsContextGLTextureMapperANGLE):
(WebCore::GraphicsContextGLTextureMapperANGLE::platformInitializeContext):
(WebCore::GraphicsContextGLTextureMapperANGLE::platformInitialize):
(WebCore::GraphicsContextGLTextureMapperANGLE::prepareTexture):
(WebCore::GraphicsContextGLTextureMapperANGLE::reshapeDisplayBufferBacking):
(WebCore::GraphicsContextGLTextureMapperANGLE::prepareForDisplay):
(WebCore::GraphicsContextGLTextureMapperANGLE::Swapchain::Swapchain):
(WebCore::GraphicsContextGLTextureMapperANGLE::Swapchain::~Swapchain):
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::EGLImageBacking): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::~EGLImageBacking): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::format const): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::stride const): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::releaseResources): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::isReleased): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::reset): Deleted.
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292024 => 292025)


--- trunk/Source/WebCore/ChangeLog	2022-03-29 05:54:56 UTC (rev 292024)
+++ trunk/Source/WebCore/ChangeLog	2022-03-29 07:59:35 UTC (rev 292025)
@@ -1,3 +1,64 @@
+2022-03-29  Zan Dobersek  <zdober...@igalia.com>
+
+        [GTK][WPE] Use GBMBufferSwapchain in GraphicsContextGLTextureMapperANGLE
+        https://bugs.webkit.org/show_bug.cgi?id=237883
+
+        Reviewed by Alejandro G. Castro.
+
+        Use the generic GBMBufferSwapchain for managing dmabuf-based buffer
+        objects in GraphicsContextGLTextureMapperANGLE. This usage is guarded
+        behind the USE(TEXTURE_MAPPER_DMABUF) build guards.
+
+        When that build guard is enabled, we can avoid using additional textures
+        but instead have to manage a GBMBufferSwapchain instance from which we
+        can retrieve buffers that should be acting as backing for the different
+        draw operations.
+
+        This buffer setup is handled in the
+        GraphicsContextGLTextureMapperANGLE::makeContextCurrent() method. Once
+        called, if there's a swapchain available (after initial or each
+        subsequent backing reshaping) a buffer will be retrieved from that
+        swapchain, a corresponding EGLImage created and associated to the GL
+        texture that acts as the color attachment for the default buffer. All
+        subsequent drawing will be done onto this buffer object, all the way
+        to the prepareForDisplay() method where that buffer is moved into the
+        display-buffer position, waiting for the display to occur.
+
+        The display of this buffer is still handled in Nicosia::GCGLANGLELayer.
+        In the swapBuffersIfNeeded() method, if the pending buffer is detected,
+        the dmabuf information is pushed into the
+        TextureMapperPlatformLayerProxyDMABuf instance and prepared for
+        presentation.
+
+        No new tests -- covered by existing tests, where the ANGLE-backed
+        GraphicsContextGL continues to improve the overall state of WebGL tests.
+        Only problem is the software-backed rasterization in the WPE/GTK testing
+        tooling which disables a few features and to a degree breaks WebGL
+        content display, but this specific issue will be resolved later.
+
+        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
+        (Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
+        (Nicosia::GCGLANGLELayer::GCGLANGLELayer):
+        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h:
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
+        (WebCore::GraphicsContextGLANGLE::makeContextCurrent):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::~GraphicsContextGLTextureMapperANGLE):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::platformInitializeContext):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::platformInitialize):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::prepareTexture):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::reshapeDisplayBufferBacking):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::prepareForDisplay):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::Swapchain::Swapchain):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::Swapchain::~Swapchain):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::EGLImageBacking): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::~EGLImageBacking): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::format const): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::stride const): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::releaseResources): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::isReleased): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::EGLImageBacking::reset): Deleted.
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h:
+
 2022-03-28  Alan Bujtas  <za...@apple.com>
 
         [ macOS & Win ] fast/repaint/list-item-equal-style-change-no-repaint.html is a flaky failure

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


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-03-29 05:54:56 UTC (rev 292024)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-03-29 07:59:35 UTC (rev 292025)
@@ -36,7 +36,8 @@
 #include "ImageBuffer.h"
 #include "Logging.h"
 #include "TextureMapperGL.h"
-#include "TextureMapperPlatformLayerDmabuf.h"
+#include "TextureMapperPlatformLayerBuffer.h"
+#include "TextureMapperPlatformLayerProxyDMABuf.h"
 #include "TextureMapperPlatformLayerProxyGL.h"
 
 namespace Nicosia {
@@ -48,21 +49,25 @@
     auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(contentLayer().impl()).proxy();
     auto size = m_context.getInternalFramebufferSize();
 
-    if (m_context.m_compositorTextureBacking) {
-        if (m_context.m_compositorTextureBacking->isReleased())
-            return;
+#if USE(TEXTURE_MAPPER_DMABUF)
+    if (is<TextureMapperPlatformLayerProxyDMABuf>(proxy)) {
+        auto bo = WTFMove(m_context.m_swapchain.displayBO);
+        if (bo) {
+            Locker locker { proxy.lock() };
 
-        auto format = m_context.m_compositorTextureBacking->format();
-        auto stride = m_context.m_compositorTextureBacking->stride();
-        auto fd = m_context.m_compositorTextureBacking->fd();
+            TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture;
+            if (m_context.contextAttributes().alpha)
+                flags |= TextureMapperGL::ShouldBlend;
 
-        {
-            Locker locker { proxy.lock() };
-            ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
-            downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd));
+            downcast<TextureMapperPlatformLayerProxyDMABuf>(proxy).pushDMABuf(
+                DMABufObject(reinterpret_cast<uintptr_t>(m_context.m_swapchain.swapchain.get()) + bo->handle()),
+                [&](auto&& object) {
+                    return bo->createDMABufObject(object.handle);
+                }, flags);
         }
         return;
     }
+#endif
 
     // Fallback path, read back texture to main memory
     RefPtr<WebCore::ImageBuffer> imageBuffer = ImageBuffer::create(size, RenderingMode::Unaccelerated, 1, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);
@@ -85,9 +90,15 @@
     }
 }
 
+#if USE(TEXTURE_MAPPER_DMABUF)
+using PlatformLayerProxyType = TextureMapperPlatformLayerProxyDMABuf;
+#else
+using PlatformLayerProxyType = TextureMapperPlatformLayerProxyGL;
+#endif
+
 GCGLANGLELayer::GCGLANGLELayer(GraphicsContextGLTextureMapperANGLE& context)
     : m_context(context)
-    , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this)))
+    , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this, adoptRef(*new PlatformLayerProxyType))))
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h (292024 => 292025)


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h	2022-03-29 05:54:56 UTC (rev 292024)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h	2022-03-29 07:59:35 UTC (rev 292025)
@@ -31,7 +31,6 @@
 #if USE(NICOSIA) && USE(TEXTURE_MAPPER)
 
 #include "NicosiaContentLayerTextureMapperImpl.h"
-#include <memory>
 
 typedef void *EGLConfig;
 typedef void *EGLContext;
@@ -40,7 +39,6 @@
 
 namespace WebCore {
 class IntSize;
-class GLContext;
 class GraphicsContextGLTextureMapperANGLE;
 class PlatformDisplay;
 }

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp (292024 => 292025)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-03-29 05:54:56 UTC (rev 292024)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-03-29 07:59:35 UTC (rev 292025)
@@ -91,9 +91,77 @@
 
 bool GraphicsContextGLANGLE::makeContextCurrent()
 {
-    if (EGL_GetCurrentContext() == m_contextObj)
-        return true;
-    return EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
+    auto madeCurrent =
+        [&] {
+            if (EGL_GetCurrentContext() == m_contextObj)
+                return true;
+            return !!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
+        }();
+
+#if USE(TEXTURE_MAPPER_DMABUF)
+    // Once the context is made current, we have to manually provide the back/draw buffer.
+    // If not yet set (due to repetitive makeContextCurrent() calls), we retrieve it from
+    // the swapchain. We also have to provide (i.e. retrieve from the cache or create)
+    // the ANGLE-y EGLImage object that will be backed by this dmabuf and will be targeted
+    // by the texture that's acting as the color attachment of the default framebuffer.
+
+    auto& context = static_cast<GraphicsContextGLTextureMapperANGLE&>(*this);
+    if (madeCurrent && context.m_swapchain.swapchain && !context.m_swapchain.drawBO) {
+        auto size = getInternalFramebufferSize();
+        context.m_swapchain.drawBO = context.m_swapchain.swapchain->getBuffer(
+            GBMBufferSwapchain::BufferDescription {
+                .format = DMABufFormat::create(uint32_t(contextAttributes().alpha ? DMABufFormat::FourCC::ARGB8888 : DMABufFormat::FourCC::XRGB8888)),
+                .width = std::clamp<uint32_t>(size.width(), 0, UINT_MAX),
+                .height = std::clamp<uint32_t>(size.height(), 0, UINT_MAX),
+            });
+
+        GLenum textureTarget = drawingBufferTextureTarget();
+        ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
+
+        auto result = context.m_swapchain.images.ensure(context.m_swapchain.drawBO->handle(),
+            [&] {
+                auto dmabufObject = context.m_swapchain.drawBO->createDMABufObject(0);
+
+                std::initializer_list<EGLint> attributes {
+                    EGL_WIDTH, EGLint(dmabufObject.format.planeWidth(0, dmabufObject.width)),
+                    EGL_HEIGHT, EGLint(dmabufObject.format.planeHeight(0, dmabufObject.height)),
+                    EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLint>(dmabufObject.format.planes[0].fourcc),
+                    EGL_DMA_BUF_PLANE0_FD_EXT, dmabufObject.fd[0],
+                    EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLint>(dmabufObject.stride[0]),
+                    EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
+                    EGL_NONE,
+                };
+                return EGL_CreateImageKHR(context.m_swapchain.platformDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, std::data(attributes));
+            });
+
+        GL_BindTexture(textureTarget, m_texture);
+        GL_EGLImageTargetTexture2DOES(textureTarget, result.iterator->value);
+
+        // If just created, the dmabuf has to be cleared to provide a zeroed-out buffer.
+        // Current color-clear and framebuffer state has to be preserved and re-established after this.
+        if (result.isNewEntry) {
+            GCGLuint boundFBO { 0 };
+            GL_GetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast<GCGLint*>(&boundFBO));
+
+            GCGLuint targetFBO = contextAttributes().antialias ? m_multisampleFBO : m_fbo;
+            if (targetFBO != boundFBO)
+                GL_BindFramebuffer(GL_FRAMEBUFFER, targetFBO);
+
+            std::array<float, 4> clearColor { 0, 0, 0, 0 };
+            GL_GetFloatv(GL_COLOR_CLEAR_VALUE, clearColor.data());
+
+            GL_ClearColor(0, 0, 0, 0);
+            GL_Clear(GL_COLOR_BUFFER_BIT);
+
+            GL_ClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+
+            if (targetFBO != boundFBO)
+                GL_BindFramebuffer(GL_FRAMEBUFFER, boundFBO);
+        }
+    }
+#endif
+
+    return madeCurrent;
 }
 
 void GraphicsContextGLANGLE::checkGPUStatus()
@@ -132,6 +200,7 @@
     bool success = makeContextCurrent();
     ASSERT_UNUSED(success, success);
 
+#if !USE(TEXTURE_MAPPER_DMABUF)
     if (m_compositorTexture)
         GL_DeleteTextures(1, &m_compositorTexture);
 #if USE(COORDINATED_GRAPHICS)
@@ -138,6 +207,7 @@
     if (m_intermediateTexture)
         GL_DeleteTextures(1, &m_intermediateTexture);
 #endif
+#endif
 }
 
 RefPtr<GraphicsLayerContentsDisplayDelegate> GraphicsContextGLTextureMapperANGLE::layerContentsDisplayDelegate()
@@ -166,9 +236,8 @@
 
 bool GraphicsContextGLTextureMapperANGLE::platformInitializeContext()
 {
-    GraphicsContextGLAttributes attributes = contextAttributes();
 #if ENABLE(WEBGL2)
-    m_isForWebGL2 = attributes.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
+    m_isForWebGL2 = contextAttributes().webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
 #endif
 
     Vector<EGLint> displayAttributes {
@@ -272,17 +341,11 @@
 #if USE(NICOSIA)
     m_nicosiaLayer = makeUnique<Nicosia::GCGLANGLELayer>(*this);
     m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(&m_nicosiaLayer->contentLayer());
-
-    const auto& gbmDevice = GBMDevice::singleton();
-    if (gbmDevice.device()) {
-        m_textureBacking = makeUnique<EGLImageBacking>(platformDisplay());
-        m_compositorTextureBacking = makeUnique<EGLImageBacking>(platformDisplay());
-        m_intermediateTextureBacking = makeUnique<EGLImageBacking>(platformDisplay());
-    }
 #else
     m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
     m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(m_texmapLayer.get());
 #endif
+
     bool success = makeContextCurrent();
     ASSERT_UNUSED(success, success);
 
@@ -307,6 +370,7 @@
     GL_GenFramebuffers(1, &m_fbo);
     GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
 
+#if !USE(TEXTURE_MAPPER_DMABUF)
     GL_GenTextures(1, &m_compositorTexture);
     GL_BindTexture(textureTarget, m_compositorTexture);
     GL_TexParameterf(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -324,6 +388,7 @@
 
     GL_BindTexture(textureTarget, 0);
 #endif
+#endif
 
     // Create a multisample FBO.
     ASSERT(m_state.boundReadFBO == m_state.boundDrawFBO);
@@ -353,12 +418,12 @@
     if (contextAttributes().antialias)
         resolveMultisamplingIfNecessary();
 
+#if !USE(TEXTURE_MAPPER_DMABUF)
     std::swap(m_texture, m_compositorTexture);
 #if USE(COORDINATED_GRAPHICS)
     std::swap(m_texture, m_intermediateTexture);
-    std::swap(m_textureBacking, m_compositorTextureBacking);
-    std::swap(m_textureBacking, m_intermediateTextureBacking);
 #endif
+#endif
 
     GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
     GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, drawingBufferTextureTarget(), m_texture, 0);
@@ -381,41 +446,20 @@
     GLuint colorFormat = attrs.alpha ? GL_RGBA : GL_RGB;
     GLenum textureTarget = drawingBufferTextureTarget();
     GLuint internalColorFormat = textureTarget == GL_TEXTURE_2D ? colorFormat : m_internalColorFormat;
+    ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
 
-#if USE(COORDINATED_GRAPHICS)
-    if (m_textureBacking)
-        m_textureBacking->reset(width, height, attrs.alpha);
-    if (m_compositorTextureBacking)
-        m_compositorTextureBacking->reset(width, height, attrs.alpha);
-    if (m_intermediateTextureBacking)
-        m_intermediateTextureBacking->reset(width, height, attrs.alpha);
-#endif
-
-    ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
-#if USE(COORDINATED_GRAPHICS)
-    if (m_compositorTexture) {
-        GL_BindTexture(textureTarget, m_compositorTexture);
-        if (m_compositorTextureBacking && m_compositorTextureBacking->image())
-            GL_EGLImageTargetTexture2DOES(textureTarget, m_compositorTextureBacking->image());
-        else
-            GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
-        GL_BindTexture(textureTarget, m_intermediateTexture);
-        if (m_intermediateTextureBacking && m_intermediateTextureBacking->image())
-            GL_EGLImageTargetTexture2DOES(textureTarget, m_intermediateTextureBacking->image());
-        else
-            GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
-    }
-    GL_BindTexture(textureTarget, m_texture);
-    if (m_textureBacking && m_textureBacking->image())
-        GL_EGLImageTargetTexture2DOES(textureTarget, m_textureBacking->image());
-    else
-        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+#if USE(TEXTURE_MAPPER_DMABUF)
+    m_swapchain = Swapchain(platformDisplay());
 #else
     GL_BindTexture(textureTarget, m_compositorTexture);
     GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+#if USE(COORDINATED_GRAPHICS)
+    GL_BindTexture(textureTarget, m_intermediateTexture);
+    GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+#endif
+#endif
     GL_BindTexture(textureTarget, m_texture);
     GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
-#endif
     GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, m_texture, 0);
 
     return true;
@@ -428,85 +472,25 @@
 
     prepareTexture();
     markLayerComposited();
-}
 
-#if USE(NICOSIA)
-GraphicsContextGLTextureMapperANGLE::EGLImageBacking::EGLImageBacking(GCGLDisplay display)
-    : m_display(display)
-    , m_image(EGL_NO_IMAGE)
-{
+#if USE(TEXTURE_MAPPER_DMABUF)
+    m_swapchain.displayBO = WTFMove(m_swapchain.drawBO);
+#endif
 }
 
-GraphicsContextGLTextureMapperANGLE::EGLImageBacking::~EGLImageBacking()
-{
-    releaseResources();
-}
+#if USE(TEXTURE_MAPPER_DMABUF)
+GraphicsContextGLTextureMapperANGLE::Swapchain::Swapchain(GCGLDisplay platformDisplay)
+    : platformDisplay(platformDisplay)
+    , swapchain(adoptRef(new GBMBufferSwapchain(GBMBufferSwapchain::BufferSwapchainSize::Four)))
+{ }
 
-uint32_t GraphicsContextGLTextureMapperANGLE::EGLImageBacking::format() const
+GraphicsContextGLTextureMapperANGLE::Swapchain::~Swapchain()
 {
-    if (m_BO)
-        return gbm_bo_get_format(m_BO);
-    return 0;
-}
-
-uint32_t GraphicsContextGLTextureMapperANGLE::EGLImageBacking::stride() const
-{
-    if (m_BO)
-        return gbm_bo_get_stride(m_BO);
-    return 0;
-}
-
-void GraphicsContextGLTextureMapperANGLE::EGLImageBacking::releaseResources()
-{
-    if (m_BO) {
-        gbm_bo_destroy(m_BO);
-        m_BO = nullptr;
+    for (EGLImageKHR image : images.values()) {
+        if (image != EGL_NO_IMAGE_KHR)
+            EGL_DestroyImageKHR(platformDisplay, image);
     }
-    if (m_image) {
-        EGL_DestroyImageKHR(m_display, m_image);
-        m_image = EGL_NO_IMAGE;
-    }
-    if (m_FD >= 0) {
-        close(m_FD);
-        m_FD = -1;
-    }
 }
-
-bool GraphicsContextGLTextureMapperANGLE::EGLImageBacking::isReleased()
-{
-    return !m_BO;
-}
-
-bool GraphicsContextGLTextureMapperANGLE::EGLImageBacking::reset(int width, int height, bool hasAlpha)
-{
-    releaseResources();
-
-    if (!width || !height)
-        return false;
-
-    const auto& gbmDevice = GBMDevice::singleton();
-    m_BO = gbm_bo_create(gbmDevice.device(), width, height, hasAlpha ? GBM_BO_FORMAT_ARGB8888 : GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_RENDERING);
-    if (m_BO) {
-        m_FD = gbm_bo_get_fd(m_BO);
-        if (m_FD >= 0) {
-            EGLint imageAttributes[] = {
-                EGL_WIDTH, width,
-                EGL_HEIGHT, height,
-                EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLint>(gbm_bo_get_format(m_BO)),
-                EGL_DMA_BUF_PLANE0_FD_EXT, m_FD,
-                EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLint>(gbm_bo_get_stride(m_BO)),
-                EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
-                EGL_NONE
-            };
-            m_image = EGL_CreateImageKHR(m_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, imageAttributes);
-            if (m_image)
-                return true;
-        }
-    }
-
-    releaseResources();
-    return false;
-}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h (292024 => 292025)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h	2022-03-29 05:54:56 UTC (rev 292024)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h	2022-03-29 07:59:35 UTC (rev 292025)
@@ -29,6 +29,12 @@
 
 #include "GraphicsContextGLANGLE.h"
 
+#if USE(TEXTURE_MAPPER_DMABUF)
+#include "ANGLEHeaders.h"
+#include "GBMBufferSwapchain.h"
+#include <wtf/HashMap.h>
+#endif
+
 #if USE(NICOSIA)
 namespace Nicosia {
 class GCGLANGLELayer;
@@ -73,46 +79,41 @@
 
     RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
 
+#if USE(TEXTURE_MAPPER_DMABUF)
+    struct Swapchain {
+        Swapchain() = default;
+        Swapchain(GCGLDisplay);
+        ~Swapchain();
+
+        GCGLDisplay platformDisplay { EGL_NO_DISPLAY };
+        RefPtr<GBMBufferSwapchain> swapchain;
+        RefPtr<GBMBufferSwapchain::Buffer> drawBO;
+        RefPtr<GBMBufferSwapchain::Buffer> displayBO;
+
+        // Cache for EGLImage objects corresponding to the buffers originating from the swapchain.
+        // The swapchain is regenerated (and these EGLImage objects destroyed) upon each buffer reshaping,
+        // so we should be fine without managing stale buffers and corresponding EGLImages (which shouldn't occur anyway).
+        HashMap<uint32_t, EGLImageKHR, WTF::DefaultHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> images;
+    } m_swapchain;
+#else
     GCGLuint m_compositorTexture { 0 };
 #if USE(COORDINATED_GRAPHICS)
     GCGLuint m_intermediateTexture { 0 };
 #endif
+#endif
 
 #if USE(NICOSIA)
     std::unique_ptr<Nicosia::GCGLANGLELayer> m_nicosiaLayer;
-
-    class EGLImageBacking {
-    WTF_MAKE_FAST_ALLOCATED;
-    public:
-        EGLImageBacking(GCGLDisplay);
-        ~EGLImageBacking();
-
-        bool reset(int width, int height, bool hasAlpha);
-
-        EGLImage image() const { return m_image; }
-        int fd() const { return m_FD; }
-
-        uint32_t format() const;
-        uint32_t stride() const;
-
-        bool isReleased();
-    private:
-        void releaseResources();
-
-        GCGLDisplay m_display;
-
-        gbm_bo* m_BO { nullptr };
-        int m_FD { -1 };
-        EGLImage m_image;
-    };
-
-    std::unique_ptr<EGLImageBacking> m_textureBacking;
-    std::unique_ptr<EGLImageBacking> m_compositorTextureBacking;
-    std::unique_ptr<EGLImageBacking> m_intermediateTextureBacking;
 #else
     std::unique_ptr<TextureMapperGCGLPlatformLayer> m_texmapLayer;
 #endif
 
+#if USE(TEXTURE_MAPPER_DMABUF)
+    // Required (for now) in GraphicsContextGLANGLE::makeContextCurrent()
+    // to construct and set the draw buffer-object.
+    friend class GraphicsContextGLANGLE;
+#endif
+
 #if USE(NICOSIA)
     friend class Nicosia::GCGLANGLELayer;
     friend class Nicosia::GCGLLayer;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to