Title: [292770] trunk/Source/WebCore
Revision
292770
Author
[email protected]
Date
2022-04-12 07:48:54 -0700 (Tue, 12 Apr 2022)

Log Message

[GTK][WPE] Move DMABuf-backed GraphicsContextGLANGLE functionality into a standalone derivation chain
https://bugs.webkit.org/show_bug.cgi?id=239037

Reviewed by Carlos Garcia Campos.

For the purposes of ANGLE-backed WebGL execution, the Linux-y ports are
for now leveraging DMABuf infrastructure through the libgbm dependency.
Right now this could be used for both the current in-WebProcess
execution as well as under-construction in-GPUProcess execution.

The former requires all the GBM bits and bolts that are then tied
together with a Nicosia::GCGLANGLELayer instance that takes care of
presenting the rendered-into DMABuf objects in TextureMapper. The latter
requires just the bits and bolts, but it runs those in the GPUProcess
and then takes the DMABuf objects and transports them over IPC to the
point of integration into the composition engine. At the moment that's
still the TextureMapper in WebProcess, but that can move in the future.

The GraphicsContextGLTextureMapperANGLE class has different parts of
GBM/DMABuf integration removed. Class is now additionally guarded with
the !USE(NICOSIA) flag so that it remains buildable on the Win port
which uses this class for ANGLE integration into the Nicosia-less
TextureMapper configuration.

These parts are now moved into the GraphicsContextGLGBM and
GraphicsContextGLGBMTextureMapper classes. The first one does all the
heavy work, and the second one just adds on top the TextureMapper
integration through the Nicosia::GCGLANGLELayer class.

In the GraphicsContextGLGBMTextureMapper implementation file, the
createWebProcessGraphicsContextGL() function returns an object of that
type, meaning it's the implementation that should be used on the
WebProcess side. The TextureMapper-less GraphicsContextGLGBM class is
the implementation that will be used inside the GPUProcess.

* SourcesGTK.txt:
* SourcesWPE.txt:
* platform/TextureMapper.cmake:
* platform/graphics/gbm/GraphicsContextGLGBM.cpp: Copied from Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp.
(WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE):
(WebCore::GraphicsContextGLANGLE::~GraphicsContextGLANGLE):
(WebCore::GraphicsContextGLANGLE::platformDisplay const):
(WebCore::GraphicsContextGLANGLE::platformConfig const):
(WebCore::GraphicsContextGLANGLE::makeContextCurrent):
(WebCore::GraphicsContextGLANGLE::checkGPUStatus):
(WebCore::GraphicsContextGLANGLE::platformReleaseThreadResources):
(WebCore::GraphicsContextGLANGLE::readCompositedResults):
(WebCore::GraphicsContextGLGBM::create):
(WebCore::GraphicsContextGLGBM::GraphicsContextGLGBM):
(WebCore::GraphicsContextGLGBM::platformInitializeContext):
(WebCore::GraphicsContextGLGBM::platformInitialize):
(WebCore::GraphicsContextGLGBM::prepareTexture):
(WebCore::GraphicsContextGLGBM::layerContentsDisplayDelegate):
(WebCore::GraphicsContextGLGBM::copyTextureFromMedia):
(WebCore::GraphicsContextGLGBM::paintCompositedResultsToVideoFrame):
(WebCore::GraphicsContextGLGBM::setContextVisibility):
(WebCore::GraphicsContextGLGBM::reshapeDisplayBufferBacking):
(WebCore::GraphicsContextGLGBM::prepareForDisplay):
(WebCore::GraphicsContextGLGBM::Swapchain::Swapchain):
(WebCore::GraphicsContextGLGBM::Swapchain::~Swapchain):
* platform/graphics/gbm/GraphicsContextGLGBM.h: Added.
(WebCore::GraphicsContextGLGBM::swapchain):
* platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp: Added.
(WebCore::createWebProcessGraphicsContextGL):
(WebCore::GraphicsContextGLGBMTextureMapper::create):
(WebCore::GraphicsContextGLGBMTextureMapper::GraphicsContextGLGBMTextureMapper):
(WebCore::GraphicsContextGLGBMTextureMapper::layerContentsDisplayDelegate):
(WebCore::GraphicsContextGLGBMTextureMapper::platformInitialize):
* platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.h: Added.
* 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): Deleted.
(WebCore::GraphicsContextGLTextureMapperANGLE::Swapchain::~Swapchain): Deleted.
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292769 => 292770)


--- trunk/Source/WebCore/ChangeLog	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/ChangeLog	2022-04-12 14:48:54 UTC (rev 292770)
@@ -1,3 +1,90 @@
+2022-04-12  Zan Dobersek  <[email protected]>
+
+        [GTK][WPE] Move DMABuf-backed GraphicsContextGLANGLE functionality into a standalone derivation chain
+        https://bugs.webkit.org/show_bug.cgi?id=239037
+
+        Reviewed by Carlos Garcia Campos.
+
+        For the purposes of ANGLE-backed WebGL execution, the Linux-y ports are
+        for now leveraging DMABuf infrastructure through the libgbm dependency.
+        Right now this could be used for both the current in-WebProcess
+        execution as well as under-construction in-GPUProcess execution.
+
+        The former requires all the GBM bits and bolts that are then tied
+        together with a Nicosia::GCGLANGLELayer instance that takes care of
+        presenting the rendered-into DMABuf objects in TextureMapper. The latter
+        requires just the bits and bolts, but it runs those in the GPUProcess
+        and then takes the DMABuf objects and transports them over IPC to the
+        point of integration into the composition engine. At the moment that's
+        still the TextureMapper in WebProcess, but that can move in the future.
+
+        The GraphicsContextGLTextureMapperANGLE class has different parts of
+        GBM/DMABuf integration removed. Class is now additionally guarded with
+        the !USE(NICOSIA) flag so that it remains buildable on the Win port
+        which uses this class for ANGLE integration into the Nicosia-less
+        TextureMapper configuration.
+
+        These parts are now moved into the GraphicsContextGLGBM and
+        GraphicsContextGLGBMTextureMapper classes. The first one does all the
+        heavy work, and the second one just adds on top the TextureMapper
+        integration through the Nicosia::GCGLANGLELayer class.
+
+        In the GraphicsContextGLGBMTextureMapper implementation file, the
+        createWebProcessGraphicsContextGL() function returns an object of that
+        type, meaning it's the implementation that should be used on the
+        WebProcess side. The TextureMapper-less GraphicsContextGLGBM class is
+        the implementation that will be used inside the GPUProcess.
+
+        * SourcesGTK.txt:
+        * SourcesWPE.txt:
+        * platform/TextureMapper.cmake:
+        * platform/graphics/gbm/GraphicsContextGLGBM.cpp: Copied from Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp.
+        (WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE):
+        (WebCore::GraphicsContextGLANGLE::~GraphicsContextGLANGLE):
+        (WebCore::GraphicsContextGLANGLE::platformDisplay const):
+        (WebCore::GraphicsContextGLANGLE::platformConfig const):
+        (WebCore::GraphicsContextGLANGLE::makeContextCurrent):
+        (WebCore::GraphicsContextGLANGLE::checkGPUStatus):
+        (WebCore::GraphicsContextGLANGLE::platformReleaseThreadResources):
+        (WebCore::GraphicsContextGLANGLE::readCompositedResults):
+        (WebCore::GraphicsContextGLGBM::create):
+        (WebCore::GraphicsContextGLGBM::GraphicsContextGLGBM):
+        (WebCore::GraphicsContextGLGBM::platformInitializeContext):
+        (WebCore::GraphicsContextGLGBM::platformInitialize):
+        (WebCore::GraphicsContextGLGBM::prepareTexture):
+        (WebCore::GraphicsContextGLGBM::layerContentsDisplayDelegate):
+        (WebCore::GraphicsContextGLGBM::copyTextureFromMedia):
+        (WebCore::GraphicsContextGLGBM::paintCompositedResultsToVideoFrame):
+        (WebCore::GraphicsContextGLGBM::setContextVisibility):
+        (WebCore::GraphicsContextGLGBM::reshapeDisplayBufferBacking):
+        (WebCore::GraphicsContextGLGBM::prepareForDisplay):
+        (WebCore::GraphicsContextGLGBM::Swapchain::Swapchain):
+        (WebCore::GraphicsContextGLGBM::Swapchain::~Swapchain):
+        * platform/graphics/gbm/GraphicsContextGLGBM.h: Added.
+        (WebCore::GraphicsContextGLGBM::swapchain):
+        * platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp: Added.
+        (WebCore::createWebProcessGraphicsContextGL):
+        (WebCore::GraphicsContextGLGBMTextureMapper::create):
+        (WebCore::GraphicsContextGLGBMTextureMapper::GraphicsContextGLGBMTextureMapper):
+        (WebCore::GraphicsContextGLGBMTextureMapper::layerContentsDisplayDelegate):
+        (WebCore::GraphicsContextGLGBMTextureMapper::platformInitialize):
+        * platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.h: Added.
+        * 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): Deleted.
+        (WebCore::GraphicsContextGLTextureMapperANGLE::Swapchain::~Swapchain): Deleted.
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h:
+
 2022-04-11  Tyler Wilcock  <[email protected]>
 
         AX: Update isolated tree in response to AXReadOnlyStatusChanged, AXRequiredStatusChanged, and AXPressedStateChanged notifications

Modified: trunk/Source/WebCore/SourcesGTK.txt (292769 => 292770)


--- trunk/Source/WebCore/SourcesGTK.txt	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/SourcesGTK.txt	2022-04-12 14:48:54 UTC (rev 292770)
@@ -83,6 +83,8 @@
 
 platform/graphics/gbm/GBMBufferSwapchain.cpp
 platform/graphics/gbm/GBMDevice.cpp
+platform/graphics/gbm/GraphicsContextGLGBM.cpp
+platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp
 
 platform/graphics/glx/GLContextGLX.cpp @no-unify
 

Modified: trunk/Source/WebCore/SourcesWPE.txt (292769 => 292770)


--- trunk/Source/WebCore/SourcesWPE.txt	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/SourcesWPE.txt	2022-04-12 14:48:54 UTC (rev 292770)
@@ -72,6 +72,8 @@
 
 platform/graphics/gbm/GBMBufferSwapchain.cpp
 platform/graphics/gbm/GBMDevice.cpp
+platform/graphics/gbm/GraphicsContextGLGBM.cpp
+platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp
 
 platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
 

Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (292769 => 292770)


--- trunk/Source/WebCore/platform/TextureMapper.cmake	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake	2022-04-12 14:48:54 UTC (rev 292770)
@@ -158,5 +158,7 @@
         platform/graphics/gbm/DMABufReleaseFlag.h
         platform/graphics/gbm/GBMBufferSwapchain.h
         platform/graphics/gbm/GBMDevice.h
+        platform/graphics/gbm/GraphicsContextGLGBM.h
+        platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.h
     )
 endif ()

Copied: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp (from rev 292769, trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp) (0 => 292770)


--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp	2022-04-12 14:48:54 UTC (rev 292770)
@@ -0,0 +1,399 @@
+/*
+ * Copyright (C) 2022 Metrological Group B.V.
+ * Copyright (C) 2022 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 "GraphicsContextGLGBM.h"
+
+#if ENABLE(WEBGL) && USE(LIBGBM) && USE(ANGLE)
+
+#include "ANGLEHeaders.h"
+#include "PixelBuffer.h"
+
+#if ENABLE(MEDIA_STREAM)
+#include "VideoFrame.h"
+#endif
+
+namespace WebCore {
+
+GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attributes)
+    : GraphicsContextGL(attributes)
+{
+}
+
+GraphicsContextGLANGLE::~GraphicsContextGLANGLE()
+{
+    bool success = makeContextCurrent();
+    ASSERT_UNUSED(success, success);
+    if (m_texture)
+        GL_DeleteTextures(1, &m_texture);
+
+    auto attributes = contextAttributes();
+
+    if (attributes.antialias) {
+        GL_DeleteRenderbuffers(1, &m_multisampleColorBuffer);
+        if (attributes.stencil || attributes.depth)
+            GL_DeleteRenderbuffers(1, &m_multisampleDepthStencilBuffer);
+        GL_DeleteFramebuffers(1, &m_multisampleFBO);
+    } else if (attributes.stencil || attributes.depth) {
+        if (m_depthStencilBuffer)
+            GL_DeleteRenderbuffers(1, &m_depthStencilBuffer);
+    }
+    GL_DeleteFramebuffers(1, &m_fbo);
+}
+
+GCGLDisplay GraphicsContextGLANGLE::platformDisplay() const
+{
+    return m_displayObj;
+}
+
+GCGLConfig GraphicsContextGLANGLE::platformConfig() const
+{
+    return m_configObj;
+}
+
+bool GraphicsContextGLANGLE::makeContextCurrent()
+{
+    auto madeCurrent =
+        [&] {
+            if (EGL_GetCurrentContext() == m_contextObj)
+                return true;
+            return !!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
+        }();
+
+    auto& contextSwapchain = static_cast<GraphicsContextGLGBM&>(*this).swapchain();
+    if (madeCurrent && contextSwapchain.swapchain && !contextSwapchain.drawBO) {
+        auto size = getInternalFramebufferSize();
+        contextSwapchain.drawBO = contextSwapchain.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 = contextSwapchain.images.ensure(contextSwapchain.drawBO->handle(),
+            [&] {
+                auto dmabufObject = contextSwapchain.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].value(),
+                    EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLint>(dmabufObject.stride[0]),
+                    EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
+                    EGL_NONE,
+                };
+                return EGL_CreateImageKHR(contextSwapchain.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);
+        }
+    }
+
+    return madeCurrent;
+}
+
+void GraphicsContextGLANGLE::checkGPUStatus()
+{
+}
+
+void GraphicsContextGLANGLE::platformReleaseThreadResources()
+{
+}
+
+std::optional<PixelBuffer> GraphicsContextGLANGLE::readCompositedResults()
+{
+    return readRenderingResults();
+}
+
+RefPtr<GraphicsContextGLGBM> GraphicsContextGLGBM::create(GraphicsContextGLAttributes&& attributes)
+{
+    auto context = adoptRef(*new GraphicsContextGLGBM(WTFMove(attributes)));
+    if (!context->initialize())
+        return nullptr;
+    return context;
+}
+
+GraphicsContextGLGBM::GraphicsContextGLGBM(GraphicsContextGLAttributes&& attributes)
+    : GraphicsContextGLANGLE(WTFMove(attributes))
+{ }
+
+GraphicsContextGLGBM::~GraphicsContextGLGBM() = default;
+
+RefPtr<GraphicsLayerContentsDisplayDelegate> GraphicsContextGLGBM::layerContentsDisplayDelegate()
+{
+    return { };
+}
+
+#if ENABLE(MEDIA_STREAM)
+RefPtr<VideoFrame> GraphicsContextGLGBM::paintCompositedResultsToVideoFrame()
+{
+    return { };
+}
+#endif
+
+#if ENABLE(VIDEO)
+bool GraphicsContextGLGBM::copyTextureFromMedia(MediaPlayer&, PlatformGLObject, GCGLenum, GCGLint, GCGLenum, GCGLenum, GCGLenum, bool, bool)
+{
+    return false;
+}
+#endif
+
+void GraphicsContextGLGBM::setContextVisibility(bool)
+{
+}
+
+void GraphicsContextGLGBM::prepareForDisplay()
+{
+    if (m_layerComposited || !makeContextCurrent())
+        return;
+
+    prepareTexture();
+    markLayerComposited();
+
+    m_swapchain.displayBO = WTFMove(m_swapchain.drawBO);
+}
+
+bool GraphicsContextGLGBM::platformInitializeContext()
+{
+#if ENABLE(WEBGL2)
+    m_isForWebGL2 = contextAttributes().webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
+#endif
+
+    Vector<EGLint> displayAttributes {
+#if !OS(WINDOWS)
+        EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE,
+        EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_EGL_ANGLE,
+        EGL_PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE, EGL_PLATFORM_SURFACELESS_MESA,
+#endif
+        EGL_NONE,
+    };
+
+    m_displayObj = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes.data());
+    if (m_displayObj == EGL_NO_DISPLAY)
+        return false;
+
+    EGLint majorVersion, minorVersion;
+    if (EGL_Initialize(m_displayObj, &majorVersion, &minorVersion) == EGL_FALSE) {
+        LOG(WebGL, "EGLDisplay Initialization failed.");
+        return false;
+    }
+    LOG(WebGL, "ANGLE initialised Major: %d Minor: %d", majorVersion, minorVersion);
+
+    const char* displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
+    LOG(WebGL, "Extensions: %s", displayExtensions);
+
+    EGLint configAttributes[] = {
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+        EGL_RED_SIZE, 8,
+        EGL_GREEN_SIZE, 8,
+        EGL_BLUE_SIZE, 8,
+        EGL_ALPHA_SIZE, 8,
+        EGL_DEPTH_SIZE, 0,
+        EGL_STENCIL_SIZE, 0,
+        EGL_NONE
+    };
+    EGLint numberConfigsReturned = 0;
+    EGL_ChooseConfig(m_displayObj, configAttributes, &m_configObj, 1, &numberConfigsReturned);
+    if (numberConfigsReturned != 1) {
+        LOG(WebGL, "EGLConfig Initialization failed.");
+        return false;
+    }
+    LOG(WebGL, "Got EGLConfig");
+
+    EGL_BindAPI(EGL_OPENGL_ES_API);
+    if (EGL_GetError() != EGL_SUCCESS) {
+        LOG(WebGL, "Unable to bind to OPENGL_ES_API");
+        return false;
+    }
+
+    Vector<EGLint> eglContextAttributes;
+    if (m_isForWebGL2) {
+        eglContextAttributes.append(EGL_CONTEXT_CLIENT_VERSION);
+        eglContextAttributes.append(3);
+    } else {
+        eglContextAttributes.append(EGL_CONTEXT_CLIENT_VERSION);
+        eglContextAttributes.append(2);
+        // ANGLE will upgrade the context to ES3 automatically unless this is specified.
+        eglContextAttributes.append(EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE);
+        eglContextAttributes.append(EGL_FALSE);
+    }
+    eglContextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
+    eglContextAttributes.append(EGL_TRUE);
+    // WebGL requires that all resources are cleared at creation.
+    eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
+    eglContextAttributes.append(EGL_TRUE);
+    // WebGL doesn't allow client arrays.
+    eglContextAttributes.append(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE);
+    eglContextAttributes.append(EGL_FALSE);
+    // WebGL doesn't allow implicit creation of objects on bind.
+    eglContextAttributes.append(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM);
+    eglContextAttributes.append(EGL_FALSE);
+
+    if (strstr(displayExtensions, "EGL_ANGLE_power_preference")) {
+        eglContextAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
+        // EGL_LOW_POWER_ANGLE is the default. Change to
+        // EGL_HIGH_POWER_ANGLE if desired.
+        eglContextAttributes.append(EGL_LOW_POWER_ANGLE);
+    }
+    eglContextAttributes.append(EGL_NONE);
+
+    m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, EGL_NO_CONTEXT, eglContextAttributes.data());
+    if (m_contextObj == EGL_NO_CONTEXT) {
+        LOG(WebGL, "EGLContext Initialization failed.");
+        return false;
+    }
+    if (!makeContextCurrent()) {
+        LOG(WebGL, "ANGLE makeContextCurrent failed.");
+        return false;
+    }
+    LOG(WebGL, "Got EGLContext");
+    return true;
+}
+
+bool GraphicsContextGLGBM::platformInitialize()
+{
+    bool success = makeContextCurrent();
+    ASSERT_UNUSED(success, success);
+
+    // We require this extension to render into the dmabuf-backed EGLImage.
+    RELEASE_ASSERT(supportsExtension("GL_OES_EGL_image"_s));
+    GL_RequestExtensionANGLE("GL_OES_EGL_image");
+
+    validateAttributes();
+    auto attributes = contextAttributes(); // They may have changed during validation.
+
+    GLenum textureTarget = drawingBufferTextureTarget();
+    // Create a texture to render into.
+    GL_GenTextures(1, &m_texture);
+    GL_BindTexture(textureTarget, m_texture);
+    GL_TexParameterf(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    GL_TexParameterf(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    GL_TexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    GL_TexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    GL_BindTexture(textureTarget, 0);
+
+    // Create an FBO.
+    GL_GenFramebuffers(1, &m_fbo);
+    GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+
+    // Create a multisample FBO.
+    ASSERT(m_state.boundReadFBO == m_state.boundDrawFBO);
+    if (attributes.antialias) {
+        GL_GenFramebuffers(1, &m_multisampleFBO);
+        GL_BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
+        m_state.boundDrawFBO = m_state.boundReadFBO = m_multisampleFBO;
+        GL_GenRenderbuffers(1, &m_multisampleColorBuffer);
+        if (attributes.stencil || attributes.depth)
+            GL_GenRenderbuffers(1, &m_multisampleDepthStencilBuffer);
+    } else {
+        // Bind canvas FBO.
+        GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+        m_state.boundDrawFBO = m_state.boundReadFBO = m_fbo;
+        if (attributes.stencil || attributes.depth)
+            GL_GenRenderbuffers(1, &m_depthStencilBuffer);
+    }
+
+    GL_ClearColor(0, 0, 0, 0);
+    return GraphicsContextGLANGLE::platformInitialize();
+}
+
+void GraphicsContextGLGBM::prepareTexture()
+{
+    ASSERT(!m_layerComposited);
+
+    if (contextAttributes().antialias)
+        resolveMultisamplingIfNecessary();
+
+    GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, drawingBufferTextureTarget(), m_texture, 0);
+    GL_Flush();
+
+    if (m_state.boundDrawFBO != m_fbo)
+        GL_BindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_state.boundDrawFBO);
+}
+
+bool GraphicsContextGLGBM::reshapeDisplayBufferBacking()
+{
+    auto attrs = contextAttributes();
+    const auto size = getInternalFramebufferSize();
+    const int width = size.width();
+    const int height = size.height();
+    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);
+
+    m_swapchain = Swapchain(platformDisplay());
+
+    GL_BindTexture(textureTarget, m_texture);
+    GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, m_texture, 0);
+
+    return true;
+}
+
+GraphicsContextGLGBM::Swapchain::Swapchain(GCGLDisplay platformDisplay)
+    : platformDisplay(platformDisplay)
+    , swapchain(adoptRef(new GBMBufferSwapchain(GBMBufferSwapchain::BufferSwapchainSize::Four)))
+{ }
+
+GraphicsContextGLGBM::Swapchain::~Swapchain()
+{
+    for (EGLImageKHR image : images.values()) {
+        if (image != EGL_NO_IMAGE_KHR)
+            EGL_DestroyImageKHR(platformDisplay, image);
+    }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGL) && USE(LIBGBM) && USE(ANGLE)

Added: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.h (0 => 292770)


--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.h	2022-04-12 14:48:54 UTC (rev 292770)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2022 Metrological Group B.V.
+ * Copyright (C) 2022 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
+
+#if ENABLE(WEBGL) && USE(LIBGBM) && USE(ANGLE)
+
+#include "GBMBufferSwapchain.h"
+#include "GraphicsContextGLANGLE.h"
+#include <wtf/HashMap.h>
+
+typedef void *EGLImageKHR;
+
+#if USE(NICOSIA)
+namespace Nicosia {
+class GCGLANGLELayer;
+}
+#endif
+
+namespace WebCore {
+
+class GraphicsContextGLGBM : public GraphicsContextGLANGLE {
+public:
+    static RefPtr<GraphicsContextGLGBM> create(WebCore::GraphicsContextGLAttributes&&);
+    virtual ~GraphicsContextGLGBM();
+
+    // GraphicsContextGL overrides
+    RefPtr<GraphicsLayerContentsDisplayDelegate> layerContentsDisplayDelegate() override;
+
+#if ENABLE(MEDIA_STREAM)
+    RefPtr<VideoFrame> paintCompositedResultsToVideoFrame() override;
+#endif
+#if ENABLE(VIDEO)
+    bool copyTextureFromMedia(MediaPlayer&, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) override;
+#endif
+
+    void setContextVisibility(bool) override;
+    void prepareForDisplay() override;
+
+    // GraphicsContextGLANGLE overrides
+    bool platformInitializeContext() override;
+    bool platformInitialize() override;
+
+    void prepareTexture() override;
+    bool reshapeDisplayBufferBacking() override;
+
+    struct Swapchain {
+        Swapchain() = default;
+        Swapchain(GCGLDisplay);
+        ~Swapchain();
+
+        GCGLDisplay platformDisplay { nullptr };
+        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;
+    };
+
+    Swapchain& swapchain() { return m_swapchain; }
+
+protected:
+    GraphicsContextGLGBM(WebCore::GraphicsContextGLAttributes&&);
+
+private:
+    Swapchain m_swapchain;
+
+#if USE(NICOSIA)
+    friend class Nicosia::GCGLANGLELayer;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGL) && USE(LIBGBM) && USE(ANGLE)

Added: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp (0 => 292770)


--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.cpp	2022-04-12 14:48:54 UTC (rev 292770)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 Metrological Group B.V.
+ * Copyright (C) 2022 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 "GraphicsContextGLGBMTextureMapper.h"
+
+#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)
+
+#include "NicosiaGCGLANGLELayer.h"
+#include "PlatformLayerDisplayDelegate.h"
+
+namespace WebCore {
+
+RefPtr<GraphicsContextGL> createWebProcessGraphicsContextGL(const GraphicsContextGLAttributes& attributes)
+{
+    return GraphicsContextGLGBMTextureMapper::create(GraphicsContextGLAttributes(attributes));
+}
+
+RefPtr<GraphicsContextGLGBMTextureMapper> GraphicsContextGLGBMTextureMapper::create(GraphicsContextGLAttributes&& attributes)
+{
+    auto context = adoptRef(*new GraphicsContextGLGBMTextureMapper(WTFMove(attributes)));
+    if (!context->initialize())
+        return nullptr;
+    return context;
+}
+
+GraphicsContextGLGBMTextureMapper::GraphicsContextGLGBMTextureMapper(GraphicsContextGLAttributes&& attributes)
+    : GraphicsContextGLGBM(WTFMove(attributes))
+{ }
+
+GraphicsContextGLGBMTextureMapper::~GraphicsContextGLGBMTextureMapper() = default;
+
+RefPtr<GraphicsLayerContentsDisplayDelegate> GraphicsContextGLGBMTextureMapper::layerContentsDisplayDelegate()
+{
+    return m_layerContentsDisplayDelegate.copyRef();
+}
+
+bool GraphicsContextGLGBMTextureMapper::platformInitialize()
+{
+    m_nicosiaLayer = makeUnique<Nicosia::GCGLANGLELayer>(*this);
+    m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(&m_nicosiaLayer->contentLayer());
+
+    return GraphicsContextGLGBM::platformInitialize();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)

Added: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.h (0 => 292770)


--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBMTextureMapper.h	2022-04-12 14:48:54 UTC (rev 292770)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2022 Metrological Group B.V.
+ * Copyright (C) 2022 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
+
+#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)
+
+#include "GraphicsContextGLGBM.h"
+#include <memory>
+
+namespace Nicosia {
+class GCGLANGLELayer;
+}
+
+namespace WebCore {
+
+class GraphicsContextGLGBMTextureMapper final : public GraphicsContextGLGBM {
+public:
+    static RefPtr<GraphicsContextGLGBMTextureMapper> create(GraphicsContextGLAttributes&&);
+    virtual ~GraphicsContextGLGBMTextureMapper();
+
+    // GraphicsContextGL overrides
+    RefPtr<GraphicsLayerContentsDisplayDelegate> layerContentsDisplayDelegate() final;
+
+    // GraphicsContextGLANGLE overrides
+    bool platformInitialize() final;
+
+private:
+    GraphicsContextGLGBMTextureMapper(GraphicsContextGLAttributes&&);
+
+    std::unique_ptr<Nicosia::GCGLANGLELayer> m_nicosiaLayer;
+    RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)

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


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-04-12 14:48:54 UTC (rev 292770)
@@ -29,9 +29,9 @@
 #include "config.h"
 #include "NicosiaGCGLANGLELayer.h"
 
-#if USE(NICOSIA) && USE(TEXTURE_MAPPER)
+#if USE(NICOSIA) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)
 
-#include "GraphicsContextGLTextureMapperANGLE.h"
+#include "GraphicsContextGLGBM.h"
 #include "ImageBuffer.h"
 #include "Logging.h"
 #include "TextureMapperGL.h"
@@ -54,7 +54,8 @@
 
 #if USE(TEXTURE_MAPPER_DMABUF)
     if (is<TextureMapperPlatformLayerProxyDMABuf>(proxy)) {
-        auto bo = WTFMove(m_context.m_swapchain.displayBO);
+        auto& swapchain = m_context.swapchain();
+        auto bo = WTFMove(swapchain.displayBO);
         if (bo) {
             Locker locker { proxy.lock() };
 
@@ -63,7 +64,7 @@
                 flags |= TextureMapperGL::ShouldBlend;
 
             downcast<TextureMapperPlatformLayerProxyDMABuf>(proxy).pushDMABuf(
-                DMABufObject(reinterpret_cast<uintptr_t>(m_context.m_swapchain.swapchain.get()) + bo->handle()),
+                DMABufObject(reinterpret_cast<uintptr_t>(swapchain.swapchain.get()) + bo->handle()),
                 [&](auto&& object) {
                     return bo->createDMABufObject(object.handle);
                 }, flags);
@@ -99,7 +100,7 @@
 using PlatformLayerProxyType = TextureMapperPlatformLayerProxyGL;
 #endif
 
-GCGLANGLELayer::GCGLANGLELayer(GraphicsContextGLTextureMapperANGLE& context)
+GCGLANGLELayer::GCGLANGLELayer(GraphicsContextGLGBM& context)
     : m_context(context)
     , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this, adoptRef(*new PlatformLayerProxyType))))
 {
@@ -112,4 +113,4 @@
 
 } // namespace Nicosia
 
-#endif // USE(NICOSIA) && USE(TEXTURE_MAPPER)
+#endif // USE(NICOSIA) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)

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


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h	2022-04-12 14:48:54 UTC (rev 292770)
@@ -28,7 +28,7 @@
 
 #pragma once
 
-#if USE(NICOSIA) && USE(TEXTURE_MAPPER)
+#if USE(NICOSIA) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)
 
 #include "NicosiaContentLayerTextureMapperImpl.h"
 
@@ -39,7 +39,7 @@
 
 namespace WebCore {
 class IntSize;
-class GraphicsContextGLTextureMapperANGLE;
+class GraphicsContextGLGBM;
 class PlatformDisplay;
 }
 
@@ -48,7 +48,7 @@
 class GCGLANGLELayer final : public ContentLayerTextureMapperImpl::Client {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    GCGLANGLELayer(WebCore::GraphicsContextGLTextureMapperANGLE&);
+    GCGLANGLELayer(WebCore::GraphicsContextGLGBM&);
     virtual ~GCGLANGLELayer();
 
     ContentLayer& contentLayer() const { return m_contentLayer; }
@@ -55,10 +55,10 @@
     void swapBuffersIfNeeded() final;
 
 private:
-    WebCore::GraphicsContextGLTextureMapperANGLE& m_context;
+    WebCore::GraphicsContextGLGBM& m_context;
     Ref<ContentLayer> m_contentLayer;
 };
 
 } // namespace Nicosia
 
-#endif // USE(NICOSIA) && USE(TEXTURE_MAPPER)
+#endif // USE(NICOSIA) && USE(TEXTURE_MAPPER) && USE(LIBGBM) && USE(ANGLE)

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


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-04-12 14:48:54 UTC (rev 292770)
@@ -27,7 +27,7 @@
 #include "config.h"
 #include "GraphicsContextGLTextureMapperANGLE.h"
 
-#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(ANGLE)
+#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && !USE(NICOSIA) && USE(ANGLE)
 
 #include "ANGLEHeaders.h"
 #include "ANGLEUtilities.h"
@@ -35,17 +35,9 @@
 #include "PixelBuffer.h"
 #include "PlatformLayerDisplayDelegate.h"
 
-#if USE(NICOSIA)
-#include "GBMDevice.h"
-#include "NicosiaGCGLANGLELayer.h"
-
-#include <fcntl.h>
-#include <gbm.h>
-#else
 #include "GLContext.h"
 #include "PlatformDisplay.h"
 #include "TextureMapperGCGLPlatformLayer.h"
-#endif
 
 #if USE(GSTREAMER) && ENABLE(MEDIA_STREAM)
 #include "VideoFrameGStreamer.h"
@@ -91,77 +83,9 @@
 
 bool GraphicsContextGLANGLE::makeContextCurrent()
 {
-    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].value(),
-                    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;
+    if (EGL_GetCurrentContext() == m_contextObj)
+        return true;
+    return !!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
 }
 
 void GraphicsContextGLANGLE::checkGPUStatus()
@@ -200,7 +124,6 @@
     bool success = makeContextCurrent();
     ASSERT_UNUSED(success, success);
 
-#if !USE(TEXTURE_MAPPER_DMABUF)
     if (m_compositorTexture)
         GL_DeleteTextures(1, &m_compositorTexture);
 #if USE(COORDINATED_GRAPHICS)
@@ -207,7 +130,6 @@
     if (m_intermediateTexture)
         GL_DeleteTextures(1, &m_intermediateTexture);
 #endif
-#endif
 }
 
 RefPtr<GraphicsLayerContentsDisplayDelegate> GraphicsContextGLTextureMapperANGLE::layerContentsDisplayDelegate()
@@ -318,11 +240,7 @@
     }
     eglContextAttributes.append(EGL_NONE);
 
-#if USE(NICOSIA)
-    auto sharingContext = EGL_NO_CONTEXT;
-#else
     auto sharingContext = PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->platformContext();
-#endif
     m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, sharingContext, eglContextAttributes.data());
     if (m_contextObj == EGL_NO_CONTEXT) {
         LOG(WebGL, "EGLContext Initialization failed.");
@@ -338,13 +256,8 @@
 
 bool GraphicsContextGLTextureMapperANGLE::platformInitialize()
 {
-#if USE(NICOSIA)
-    m_nicosiaLayer = makeUnique<Nicosia::GCGLANGLELayer>(*this);
-    m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(&m_nicosiaLayer->contentLayer());
-#else
     m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
     m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(m_texmapLayer.get());
-#endif
 
     bool success = makeContextCurrent();
     ASSERT_UNUSED(success, success);
@@ -370,7 +283,6 @@
     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);
@@ -388,7 +300,6 @@
 
     GL_BindTexture(textureTarget, 0);
 #endif
-#endif
 
     // Create a multisample FBO.
     ASSERT(m_state.boundReadFBO == m_state.boundDrawFBO);
@@ -418,12 +329,10 @@
     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);
 #endif
-#endif
 
     GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
     GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, drawingBufferTextureTarget(), m_texture, 0);
@@ -448,9 +357,6 @@
     GLuint internalColorFormat = textureTarget == GL_TEXTURE_2D ? colorFormat : m_internalColorFormat;
     ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
 
-#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)
@@ -457,7 +363,6 @@
     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);
     GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, m_texture, 0);
@@ -472,27 +377,8 @@
 
     prepareTexture();
     markLayerComposited();
-
-#if USE(TEXTURE_MAPPER_DMABUF)
-    m_swapchain.displayBO = WTFMove(m_swapchain.drawBO);
-#endif
 }
 
-#if USE(TEXTURE_MAPPER_DMABUF)
-GraphicsContextGLTextureMapperANGLE::Swapchain::Swapchain(GCGLDisplay platformDisplay)
-    : platformDisplay(platformDisplay)
-    , swapchain(adoptRef(new GBMBufferSwapchain(GBMBufferSwapchain::BufferSwapchainSize::Four)))
-{ }
-
-GraphicsContextGLTextureMapperANGLE::Swapchain::~Swapchain()
-{
-    for (EGLImageKHR image : images.values()) {
-        if (image != EGL_NO_IMAGE_KHR)
-            EGL_DestroyImageKHR(platformDisplay, image);
-    }
-}
-#endif
-
 } // namespace WebCore
 
-#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(ANGLE)
+#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && !USE(NICOSIA) && USE(ANGLE)

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


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h	2022-04-12 14:06:35 UTC (rev 292769)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h	2022-04-12 14:48:54 UTC (rev 292770)
@@ -25,24 +25,10 @@
 
 #pragma once
 
-#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(ANGLE)
+#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && !USE(NICOSIA) && USE(ANGLE)
 
 #include "GraphicsContextGLANGLE.h"
 
-#if USE(TEXTURE_MAPPER_DMABUF)
-#include "GBMBufferSwapchain.h"
-#include <wtf/HashMap.h>
-#endif
-
-#if USE(NICOSIA)
-namespace Nicosia {
-class GCGLANGLELayer;
-class GCGLLayer;
-}
-
-typedef void *EGLImageKHR;
-#endif
-
 namespace WebCore {
 
 class TextureMapperGCGLPlatformLayer;
@@ -75,49 +61,16 @@
 
     RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
 
-#if USE(TEXTURE_MAPPER_DMABUF)
-    struct Swapchain {
-        Swapchain() = default;
-        Swapchain(GCGLDisplay);
-        ~Swapchain();
-
-        GCGLDisplay platformDisplay { nullptr };
-        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;
-#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;
-#else
     friend class TextureMapperGCGLPlatformLayer;
-#endif
 };
 
 } // namespace WebCore
 
-#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && USE(ANGLE)
+#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && !USE(NICOSIA) && USE(ANGLE)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to