Title: [290540] trunk/Source/WebCore
Revision
290540
Author
hironori.fu...@sony.com
Date
2022-02-25 18:03:23 -0800 (Fri, 25 Feb 2022)

Log Message

[GTK][WPE][WC] Move ANGLE context initialisation to GraphicsContextGLTextureMapper::initialize
https://bugs.webkit.org/show_bug.cgi?id=236769

Reviewed by Chris Lord.

This is the first step for the long-term plan to share more code
in GraphicsContextGLANGLE between Cocoa and non-Cocoa, and
minimise the ifdefs in GraphicsContextGLANGLE.

We are moving the context initialisation and holding to
GraphicsContextGLTextureMapper, away from
GCGLANGLELayer::ANGLEContext and the layer classes in case of
COORDINATED_GRAPHICS. Later on, Cocoa and non-Cocoa can merge
their ::initialize.

No new tests, this is a refactoring patch.

* platform/TextureMapper.cmake:
* platform/graphics/angle/GraphicsContextGLANGLE.h:
* platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
(Nicosia::GCGLANGLELayer::GCGLANGLELayer):
(Nicosia::GCGLANGLELayer::ANGLEContext::errorString): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::lastErrorString): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::createContext): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::ANGLEContext): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::~ANGLEContext): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::makeContextCurrent): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::platformContext const): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::platformDisplay const): Deleted.
(Nicosia::GCGLANGLELayer::ANGLEContext::platformConfig const): Deleted.
(Nicosia::GCGLANGLELayer::makeContextCurrent): Deleted.
(Nicosia::GCGLANGLELayer::platformContext const): Deleted.
(Nicosia::GCGLANGLELayer::platformDisplay const): Deleted.
(Nicosia::GCGLANGLELayer::platformConfig const): Deleted.
* platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h:
* platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
(WebCore::GraphicsContextGLOpenGL::initialize):
* platform/graphics/opengl/GraphicsContextGLOpenGL.h:
* platform/graphics/texmap/ANGLEContext.cpp: Removed.
* platform/graphics/texmap/ANGLEContext.h: Removed.
* platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
(WebCore::GraphicsContextGLTextureMapper::create):
(WebCore::GraphicsContextGLTextureMapper::GraphicsContextGLTextureMapper):
(WebCore::GraphicsContextGLTextureMapper::layerContentsDisplayDelegate):
(WebCore::GraphicsContextGLTextureMapper::platformInitialize):
(): Deleted.
* platform/graphics/texmap/GraphicsContextGLTextureMapper.h:
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE):
(WebCore::GraphicsContextGLTextureMapper::platformInitializeContext):
(WebCore::GraphicsContextGLTextureMapper::platformInitialize):
(WebCore::GraphicsContextGLANGLE::platformDisplay const):
(WebCore::GraphicsContextGLANGLE::platformConfig const):
(WebCore::GraphicsContextGLANGLE::makeContextCurrent):
* platform/graphics/texmap/PlatformLayerDisplayDelegate.h: Copied from Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.h.
* platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
(WebCore::TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer):
(WebCore::TextureMapperGCGLPlatformLayer::~TextureMapperGCGLPlatformLayer):
(WebCore::TextureMapperGCGLPlatformLayer::paintToTextureMapper):
(WebCore::TextureMapperGCGLPlatformLayer::makeContextCurrent): Deleted.
(WebCore::TextureMapperGCGLPlatformLayer::platformContext const): Deleted.
(WebCore::TextureMapperGCGLPlatformLayer::platformDisplay const): Deleted.
(WebCore::TextureMapperGCGLPlatformLayer::platformConfig const): Deleted.
(WebCore::TextureMapperGCGLPlatformLayer::proxy const): Deleted.
(WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): Deleted.
* platform/graphics/texmap/TextureMapperGCGLPlatformLayer.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290539 => 290540)


--- trunk/Source/WebCore/ChangeLog	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/ChangeLog	2022-02-26 02:03:23 UTC (rev 290540)
@@ -1,3 +1,72 @@
+2022-02-25  Alejandro G. Castro  <a...@igalia.com> and Fujii Hironori <hironori.fu...@sony.com>
+
+        [GTK][WPE][WC] Move ANGLE context initialisation to GraphicsContextGLTextureMapper::initialize
+        https://bugs.webkit.org/show_bug.cgi?id=236769
+
+        Reviewed by Chris Lord.
+
+        This is the first step for the long-term plan to share more code
+        in GraphicsContextGLANGLE between Cocoa and non-Cocoa, and
+        minimise the ifdefs in GraphicsContextGLANGLE.
+
+        We are moving the context initialisation and holding to
+        GraphicsContextGLTextureMapper, away from
+        GCGLANGLELayer::ANGLEContext and the layer classes in case of
+        COORDINATED_GRAPHICS. Later on, Cocoa and non-Cocoa can merge
+        their ::initialize.
+
+        No new tests, this is a refactoring patch.
+
+        * platform/TextureMapper.cmake:
+        * platform/graphics/angle/GraphicsContextGLANGLE.h:
+        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
+        (Nicosia::GCGLANGLELayer::GCGLANGLELayer):
+        (Nicosia::GCGLANGLELayer::ANGLEContext::errorString): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::lastErrorString): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::createContext): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::ANGLEContext): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::~ANGLEContext): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::makeContextCurrent): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::platformContext const): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::platformDisplay const): Deleted.
+        (Nicosia::GCGLANGLELayer::ANGLEContext::platformConfig const): Deleted.
+        (Nicosia::GCGLANGLELayer::makeContextCurrent): Deleted.
+        (Nicosia::GCGLANGLELayer::platformContext const): Deleted.
+        (Nicosia::GCGLANGLELayer::platformDisplay const): Deleted.
+        (Nicosia::GCGLANGLELayer::platformConfig const): Deleted.
+        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h:
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
+        (WebCore::GraphicsContextGLOpenGL::initialize):
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+        * platform/graphics/texmap/ANGLEContext.cpp: Removed.
+        * platform/graphics/texmap/ANGLEContext.h: Removed.
+        * platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
+        (WebCore::GraphicsContextGLTextureMapper::create):
+        (WebCore::GraphicsContextGLTextureMapper::GraphicsContextGLTextureMapper):
+        (WebCore::GraphicsContextGLTextureMapper::layerContentsDisplayDelegate):
+        (WebCore::GraphicsContextGLTextureMapper::platformInitialize):
+        (): Deleted.
+        * platform/graphics/texmap/GraphicsContextGLTextureMapper.h:
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
+        (WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE):
+        (WebCore::GraphicsContextGLTextureMapper::platformInitializeContext):
+        (WebCore::GraphicsContextGLTextureMapper::platformInitialize):
+        (WebCore::GraphicsContextGLANGLE::platformDisplay const):
+        (WebCore::GraphicsContextGLANGLE::platformConfig const):
+        (WebCore::GraphicsContextGLANGLE::makeContextCurrent):
+        * platform/graphics/texmap/PlatformLayerDisplayDelegate.h: Copied from Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.h.
+        * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
+        (WebCore::TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer):
+        (WebCore::TextureMapperGCGLPlatformLayer::~TextureMapperGCGLPlatformLayer):
+        (WebCore::TextureMapperGCGLPlatformLayer::paintToTextureMapper):
+        (WebCore::TextureMapperGCGLPlatformLayer::makeContextCurrent): Deleted.
+        (WebCore::TextureMapperGCGLPlatformLayer::platformContext const): Deleted.
+        (WebCore::TextureMapperGCGLPlatformLayer::platformDisplay const): Deleted.
+        (WebCore::TextureMapperGCGLPlatformLayer::platformConfig const): Deleted.
+        (WebCore::TextureMapperGCGLPlatformLayer::proxy const): Deleted.
+        (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): Deleted.
+        * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.h:
+
 2022-02-25  Chris Dumez  <cdu...@apple.com>
 
         Use the modern Hasher more in Content Extensions code

Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (290539 => 290540)


--- trunk/Source/WebCore/platform/TextureMapper.cmake	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake	2022-02-26 02:03:23 UTC (rev 290540)
@@ -6,7 +6,6 @@
 list(APPEND WebCore_SOURCES
     platform/graphics/nicosia/NicosiaAnimation.cpp
 
-    platform/graphics/texmap/ANGLEContext.cpp
     platform/graphics/texmap/BitmapTexture.cpp
     platform/graphics/texmap/BitmapTexturePool.cpp
     platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp
@@ -22,7 +21,6 @@
 list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
     platform/graphics/nicosia/NicosiaAnimation.h
 
-    platform/graphics/texmap/ANGLEContext.h
     platform/graphics/texmap/BitmapTexture.h
     platform/graphics/texmap/ClipStack.h
     platform/graphics/texmap/GraphicsContextGLTextureMapper.h

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h (290539 => 290540)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -453,12 +453,13 @@
     ScopedGLFence m_frameCompletionFences[maxPendingFrames];
     GraphicsContextGLState m_state;
 
+    GCGLDisplay m_displayObj { nullptr };
+    GCGLContext m_contextObj { nullptr };
+    GCGLConfig m_configObj { nullptr };
+
 #if PLATFORM(COCOA)
     // FIXME: Move these to GraphicsContextGLCocoa.
     GraphicsContextGLIOSurfaceSwapChain m_swapChain;
-    GCGLDisplay m_displayObj { nullptr };
-    GCGLContext m_contextObj { nullptr };
-    GCGLConfig m_configObj { nullptr };
     // Backing store for the the buffer which is eventually used for display.
     // When preserveDrawingBuffer == false, this is the drawing buffer backing store.
     // When preserveDrawingBuffer == true, this is blitted to during display prepare.

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


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-02-26 02:03:23 UTC (rev 290540)
@@ -92,175 +92,8 @@
     m_context.markLayerComposited();
 }
 
-const char* GCGLANGLELayer::ANGLEContext::errorString(int statusCode)
-{
-    static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int");
-    switch (statusCode) {
-#define CASE_RETURN_STRING(name) case name: return #name
-        // https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglGetError.xhtml
-        CASE_RETURN_STRING(EGL_SUCCESS);
-        CASE_RETURN_STRING(EGL_NOT_INITIALIZED);
-        CASE_RETURN_STRING(EGL_BAD_ACCESS);
-        CASE_RETURN_STRING(EGL_BAD_ALLOC);
-        CASE_RETURN_STRING(EGL_BAD_ATTRIBUTE);
-        CASE_RETURN_STRING(EGL_BAD_CONTEXT);
-        CASE_RETURN_STRING(EGL_BAD_CONFIG);
-        CASE_RETURN_STRING(EGL_BAD_CURRENT_SURFACE);
-        CASE_RETURN_STRING(EGL_BAD_DISPLAY);
-        CASE_RETURN_STRING(EGL_BAD_SURFACE);
-        CASE_RETURN_STRING(EGL_BAD_MATCH);
-        CASE_RETURN_STRING(EGL_BAD_PARAMETER);
-        CASE_RETURN_STRING(EGL_BAD_NATIVE_PIXMAP);
-        CASE_RETURN_STRING(EGL_BAD_NATIVE_WINDOW);
-        CASE_RETURN_STRING(EGL_CONTEXT_LOST);
-#undef CASE_RETURN_STRING
-    default: return "Unknown EGL error";
-    }
-}
-
-const char* GCGLANGLELayer::ANGLEContext::lastErrorString()
-{
-    return errorString(EGL_GetError());
-}
-
-std::unique_ptr<GCGLANGLELayer::ANGLEContext> GCGLANGLELayer::ANGLEContext::createContext(bool isForWebGL2)
-{
-    Vector<EGLint> displayAttributes {
-        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,
-        EGL_NONE,
-    };
-    EGLDisplay display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes.data());
-    if (display == EGL_NO_DISPLAY)
-        return nullptr;
-
-    EGLint majorVersion, minorVersion;
-    if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
-        LOG(WebGL, "EGLDisplay Initialization failed.");
-        return nullptr;
-    }
-    LOG(WebGL, "ANGLE initialised Major: %d Minor: %d", majorVersion, minorVersion);
-
-    const char* displayExtensions = EGL_QueryString(display, EGL_EXTENSIONS);
-    LOG(WebGL, "Extensions: %s", displayExtensions);
-
-    EGLConfig config;
-    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(display, configAttributes, &config, 1, &numberConfigsReturned);
-    if (numberConfigsReturned != 1) {
-        LOG(WebGL, "EGLConfig Initialization failed.");
-        return nullptr;
-    }
-    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 nullptr;
-    }
-
-    std::vector<EGLint> contextAttributes;
-    if (isForWebGL2) {
-        contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
-        contextAttributes.push_back(3);
-    } else {
-        contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
-        contextAttributes.push_back(2);
-        // ANGLE will upgrade the context to ES3 automatically unless this is specified.
-        contextAttributes.push_back(EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE);
-        contextAttributes.push_back(EGL_FALSE);
-    }
-    contextAttributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
-    contextAttributes.push_back(EGL_TRUE);
-
-    // WebGL requires that all resources are cleared at creation.
-    contextAttributes.push_back(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
-    contextAttributes.push_back(EGL_TRUE);
-
-    // WebGL doesn't allow client arrays.
-    contextAttributes.push_back(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE);
-    contextAttributes.push_back(EGL_FALSE);
-
-    // WebGL doesn't allow implicit creation of objects on bind.
-    contextAttributes.push_back(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM);
-    contextAttributes.push_back(EGL_FALSE);
-
-    if (strstr(displayExtensions, "EGL_ANGLE_power_preference")) {
-        contextAttributes.push_back(EGL_POWER_PREFERENCE_ANGLE);
-        // EGL_LOW_POWER_ANGLE is the default. Change to
-        // EGL_HIGH_POWER_ANGLE if desired.
-        contextAttributes.push_back(EGL_LOW_POWER_ANGLE);
-    }
-    contextAttributes.push_back(EGL_NONE);
-
-    EGLContext context = EGL_CreateContext(display, config, EGL_NO_CONTEXT, contextAttributes.data());
-    if (context == EGL_NO_CONTEXT) {
-        LOG(WebGL, "EGLContext Initialization failed.");
-        return nullptr;
-    }
-    LOG(WebGL, "Got EGLContext");
-
-    return std::unique_ptr<ANGLEContext>(new ANGLEContext(display, config, context, EGL_NO_SURFACE));
-}
-
-GCGLANGLELayer::ANGLEContext::ANGLEContext(EGLDisplay display, EGLConfig config, EGLContext context, EGLSurface surface)
-    : m_display(display)
-    , m_config(config)
-    , m_context(context)
-    , m_surface(surface)
-{
-}
-
-GCGLANGLELayer::ANGLEContext::~ANGLEContext()
-{
-    if (m_context) {
-        GL_BindFramebuffer(GL_FRAMEBUFFER, 0);
-        EGL_MakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-        EGL_DestroyContext(m_display, m_context);
-    }
-
-    if (m_surface)
-        EGL_DestroySurface(m_display, m_surface);
-}
-
-bool GCGLANGLELayer::ANGLEContext::makeContextCurrent()
-{
-    ASSERT(m_context);
-
-    if (EGL_GetCurrentContext() != m_context)
-        return EGL_MakeCurrent(m_display, m_surface, m_surface, m_context);
-    return true;
-}
-
-GCGLContext GCGLANGLELayer::ANGLEContext::platformContext() const
-{
-    return m_context;
-}
-
-GCGLDisplay GCGLANGLELayer::ANGLEContext::platformDisplay() const
-{
-    return m_display;
-}
-
-GCGLConfig GCGLANGLELayer::ANGLEContext::platformConfig() const
-{
-    return m_config;
-}
-
 GCGLANGLELayer::GCGLANGLELayer(GraphicsContextGLANGLE& context)
     : m_context(context)
-    , m_angleContext(ANGLEContext::createContext(context.m_isForWebGL2))
     , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this)))
 {
 }
@@ -270,31 +103,6 @@
     downcast<ContentLayerTextureMapperImpl>(m_contentLayer->impl()).invalidateClient();
 }
 
-bool GCGLANGLELayer::makeContextCurrent()
-{
-    ASSERT(m_angleContext);
-    return m_angleContext->makeContextCurrent();
-
-}
-
-GCGLContext GCGLANGLELayer::platformContext() const
-{
-    ASSERT(m_angleContext);
-    return m_angleContext->platformContext();
-}
-
-GCGLDisplay GCGLANGLELayer::platformDisplay() const
-{
-    ASSERT(m_angleContext);
-    return m_angleContext->platformDisplay();
-}
-
-GCGLConfig GCGLANGLELayer::platformConfig() const
-{
-    ASSERT(m_angleContext);
-    return m_angleContext->platformContext();
-}
-
 } // namespace Nicosia
 
 #endif // USE(NICOSIA) && USE(TEXTURE_MAPPER)

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


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -50,45 +50,14 @@
 class GCGLANGLELayer final : public ContentLayerTextureMapperImpl::Client {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    class ANGLEContext {
-        WTF_MAKE_NONCOPYABLE(ANGLEContext);
-    public:
-        static const char* errorString(int statusCode);
-        static const char* lastErrorString();
-
-        static std::unique_ptr<ANGLEContext> createContext(bool isForWebGL2);
-        virtual ~ANGLEContext();
-
-        bool makeContextCurrent();
-#if ENABLE(WEBGL)
-        GCGLContext platformContext() const;
-        GCGLDisplay platformDisplay() const;
-        GCGLConfig platformConfig() const;
-#endif
-
-    private:
-        ANGLEContext(EGLDisplay, EGLConfig, EGLContext, EGLSurface);
-
-        EGLDisplay m_display { nullptr };
-        EGLConfig m_config { nullptr };
-        EGLContext m_context { nullptr };
-        EGLSurface m_surface { nullptr };
-    };
-
     GCGLANGLELayer(WebCore::GraphicsContextGLANGLE&);
     virtual ~GCGLANGLELayer();
 
-    bool makeContextCurrent();
-    GCGLContext platformContext() const;
-    GCGLDisplay platformDisplay() const;
-    GCGLConfig platformConfig() const;
-
     ContentLayer& contentLayer() const { return m_contentLayer; }
     void swapBuffersIfNeeded() final;
 
 private:
     WebCore::GraphicsContextGLANGLE& m_context;
-    std::unique_ptr<ANGLEContext> m_angleContext;
     Ref<ContentLayer> m_contentLayer;
 };
 

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


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2022-02-26 02:03:23 UTC (rev 290540)
@@ -290,6 +290,11 @@
 #endif
 }
 
+bool GraphicsContextGLOpenGL::initialize()
+{
+    return platformInitialize();
+}
+
 bool GraphicsContextGLOpenGL::makeContextCurrent()
 {
 #if USE(NICOSIA)

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


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -431,6 +431,10 @@
     // Called once by all the public entry points of ExtensionsGLOpenGL/ExtensionGLOpenGLES that eventually call OpenGL.
     bool makeContextCurrent() WARN_UNUSED_RETURN;
 
+    // Initializes the instance. Returns false if the instance should not be used.
+    bool initialize();
+    virtual bool platformInitialize() = 0;
+
     // Take into account the user's requested context creation attributes,
     // in particular stencil and antialias, and determine which could or
     // could not be honored based on the capabilities of the OpenGL

Deleted: trunk/Source/WebCore/platform/graphics/texmap/ANGLEContext.cpp (290539 => 290540)


--- trunk/Source/WebCore/platform/graphics/texmap/ANGLEContext.cpp	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/ANGLEContext.cpp	2022-02-26 02:03:23 UTC (rev 290540)
@@ -1,199 +0,0 @@
-/*
- * Copyright (C) 2018 Metrological Group B.V.
- * Copyright (C) 2018, 2019 Igalia S.L.
- * Copyright (C) 2009-2020 Apple Inc.
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
- *
- * 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * HOLDER OR 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 "ANGLEContext.h"
-
-#if USE(TEXTURE_MAPPER) && USE(ANGLE) && !USE(NICOSIA)
-
-#include "ANGLEHeaders.h"
-#include "Logging.h"
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-const char* ANGLEContext::errorString(int statusCode)
-{
-    static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int");
-    switch (statusCode) {
-#define CASE_RETURN_STRING(name) case name: return #name
-        // https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglGetError.xhtml
-        CASE_RETURN_STRING(EGL_SUCCESS);
-        CASE_RETURN_STRING(EGL_NOT_INITIALIZED);
-        CASE_RETURN_STRING(EGL_BAD_ACCESS);
-        CASE_RETURN_STRING(EGL_BAD_ALLOC);
-        CASE_RETURN_STRING(EGL_BAD_ATTRIBUTE);
-        CASE_RETURN_STRING(EGL_BAD_CONTEXT);
-        CASE_RETURN_STRING(EGL_BAD_CONFIG);
-        CASE_RETURN_STRING(EGL_BAD_CURRENT_SURFACE);
-        CASE_RETURN_STRING(EGL_BAD_DISPLAY);
-        CASE_RETURN_STRING(EGL_BAD_SURFACE);
-        CASE_RETURN_STRING(EGL_BAD_MATCH);
-        CASE_RETURN_STRING(EGL_BAD_PARAMETER);
-        CASE_RETURN_STRING(EGL_BAD_NATIVE_PIXMAP);
-        CASE_RETURN_STRING(EGL_BAD_NATIVE_WINDOW);
-        CASE_RETURN_STRING(EGL_CONTEXT_LOST);
-#undef CASE_RETURN_STRING
-    default: return "Unknown EGL error";
-    }
-}
-
-const char* ANGLEContext::lastErrorString()
-{
-    return errorString(EGL_GetError());
-}
-
-std::unique_ptr<ANGLEContext> ANGLEContext::createContext(EGLContext sharingContext, bool isForWebGL2)
-{
-    EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
-    if (display == EGL_NO_DISPLAY)
-        return nullptr;
-
-    EGLint majorVersion, minorVersion;
-    if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
-        LOG(WebGL, "EGLDisplay Initialization failed.");
-        return nullptr;
-    }
-    LOG(WebGL, "ANGLE initialised Major: %d Minor: %d", majorVersion, minorVersion);
-
-    const char* displayExtensions = EGL_QueryString(display, EGL_EXTENSIONS);
-    LOG(WebGL, "Extensions: %s", displayExtensions);
-
-    EGLConfig config;
-    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_NONE
-    };
-    EGLint numberConfigsReturned = 0;
-    EGL_ChooseConfig(display, configAttributes, &config, 1, &numberConfigsReturned);
-    if (numberConfigsReturned != 1) {
-        LOG(WebGL, "EGLConfig Initialization failed.");
-        return nullptr;
-    }
-    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 nullptr;
-    }
-
-    Vector<EGLint> contextAttributes;
-    if (isForWebGL2) {
-        contextAttributes.append(EGL_CONTEXT_CLIENT_VERSION);
-        contextAttributes.append(3);
-    } else {
-        contextAttributes.append(EGL_CONTEXT_CLIENT_VERSION);
-        contextAttributes.append(2);
-        // ANGLE will upgrade the context to ES3 automatically unless this is specified.
-        contextAttributes.append(EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE);
-        contextAttributes.append(EGL_FALSE);
-    }
-    contextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
-    contextAttributes.append(EGL_TRUE);
-    // WebGL requires that all resources are cleared at creation.
-    contextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
-    contextAttributes.append(EGL_TRUE);
-    // WebGL doesn't allow client arrays.
-    contextAttributes.append(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE);
-    contextAttributes.append(EGL_FALSE);
-    // WebGL doesn't allow implicit creation of objects on bind.
-    contextAttributes.append(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM);
-    contextAttributes.append(EGL_FALSE);
-
-    if (strstr(displayExtensions, "EGL_ANGLE_power_preference")) {
-        contextAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
-        // EGL_LOW_POWER_ANGLE is the default. Change to
-        // EGL_HIGH_POWER_ANGLE if desired.
-        contextAttributes.append(EGL_LOW_POWER_ANGLE);
-    }
-    contextAttributes.append(EGL_NONE);
-
-    EGLContext context = EGL_CreateContext(display, config, sharingContext, contextAttributes.data());
-    if (context == EGL_NO_CONTEXT) {
-        LOG(WebGL, "EGLContext Initialization failed.");
-        return nullptr;
-    }
-    LOG(WebGL, "Got EGLContext");
-
-    return std::unique_ptr<ANGLEContext>(new ANGLEContext(display,  config, context, EGL_NO_SURFACE));
-}
-
-ANGLEContext::ANGLEContext(EGLDisplay display, EGLConfig config, EGLContext context, EGLSurface surface)
-    : m_display(display)
-    , m_config(config)
-    , m_context(context)
-    , m_surface(surface)
-{
-}
-
-ANGLEContext::~ANGLEContext()
-{
-    if (m_context) {
-        GL_BindFramebuffer(GL_FRAMEBUFFER, 0);
-        EGL_MakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-        EGL_DestroyContext(m_display, m_context);
-    }
-
-    if (m_surface)
-        EGL_DestroySurface(m_display, m_surface);
-}
-
-bool ANGLEContext::makeContextCurrent()
-{
-    ASSERT(m_context);
-
-    if (EGL_GetCurrentContext() != m_context)
-        return EGL_MakeCurrent(m_display, m_surface, m_surface, m_context);
-    return true;
-}
-
-EGLContext ANGLEContext::platformContext() const
-{
-    return m_context;
-}
-
-EGLDisplay ANGLEContext::platformDisplay() const
-{
-    return m_display;
-}
-
-EGLConfig ANGLEContext::platformConfig() const
-{
-    return m_config;
-}
-
-} // namespace WebCore
-
-#endif

Deleted: trunk/Source/WebCore/platform/graphics/texmap/ANGLEContext.h (290539 => 290540)


--- trunk/Source/WebCore/platform/graphics/texmap/ANGLEContext.h	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/ANGLEContext.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2018 Metrological Group B.V.
- * Copyright (C) 2018, 2019 Igalia S.L.
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
- *
- * 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * HOLDER OR 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 USE(TEXTURE_MAPPER) && USE(ANGLE) && !USE(NICOSIA)
-
-#include <wtf/Noncopyable.h>
-
-typedef void *EGLConfig;
-typedef void *EGLContext;
-typedef void *EGLDisplay;
-typedef void *EGLSurface;
-
-namespace WebCore {
-
-class ANGLEContext {
-    WTF_MAKE_NONCOPYABLE(ANGLEContext);
-public:
-    static const char* errorString(int statusCode);
-    static const char* lastErrorString();
-
-    static std::unique_ptr<ANGLEContext> createContext(EGLContext sharingContext, bool isForWebGL2);
-    ~ANGLEContext();
-
-    bool makeContextCurrent();
-    EGLContext platformContext() const;
-    EGLDisplay platformDisplay() const;
-    EGLConfig platformConfig() const;
-private:
-    ANGLEContext(EGLDisplay, EGLConfig, EGLContext, EGLSurface);
-
-    EGLDisplay m_display { nullptr };
-    EGLConfig m_config { nullptr };
-    EGLContext m_context { nullptr };
-    EGLSurface m_surface { nullptr };
-};
-
-} // namespace WebCore
-
-#endif

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp (290539 => 290540)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2022-02-26 02:03:23 UTC (rev 290540)
@@ -32,7 +32,6 @@
 #if ENABLE(WEBGL) && USE(TEXTURE_MAPPER)
 
 #include "GraphicsContextGLOpenGLManager.h"
-#include "GraphicsLayerContentsDisplayDelegate.h"
 #include "PixelBuffer.h"
 #include "TextureMapperGCGLPlatformLayer.h"
 #include <wtf/Deque.h>
@@ -56,6 +55,7 @@
 #include "NicosiaGCGLANGLELayer.h"
 #else
 #include "NicosiaGCGLLayer.h"
+#include "PlatformLayerDisplayDelegate.h"
 #endif
 #endif
 
@@ -73,39 +73,11 @@
 
 namespace WebCore {
 
-namespace {
-
-class PlatformLayerDisplayDelegate final : public GraphicsLayerContentsDisplayDelegate {
-public:
-    static Ref<PlatformLayerDisplayDelegate> create(PlatformLayer* platformLayer)
-    {
-        return adoptRef(*new PlatformLayerDisplayDelegate(platformLayer));
-    }
-
-    // GraphicsLayerContentsDisplayDelegate overrides.
-    PlatformLayer* platformLayer() const final
-    {
-        return m_platformLayer;
-    }
-
-private:
-    PlatformLayerDisplayDelegate(PlatformLayer* platformLayer)
-        : m_platformLayer(platformLayer)
-    {
-    }
-
-    PlatformLayer* m_platformLayer;
-};
-
-}
-
 RefPtr<GraphicsContextGLTextureMapper> GraphicsContextGLTextureMapper::create(GraphicsContextGLAttributes&& attributes)
 {
     auto context = adoptRef(*new GraphicsContextGLTextureMapper(WTFMove(attributes)));
-#if USE(ANGLE)
     if (!context->initialize())
         return nullptr;
-#endif
     return context;
 }
 
@@ -113,17 +85,12 @@
 
 GraphicsContextGLTextureMapper::GraphicsContextGLTextureMapper(GraphicsContextGLAttributes&& attributes)
     : GraphicsContextGLTextureMapperBase(WTFMove(attributes))
-#if USE(NICOSIA)
-    , m_layerContentsDisplayDelegate(PlatformLayerDisplayDelegate::create(&m_nicosiaLayer->contentLayer()))
-#else
-    , m_layerContentsDisplayDelegate(PlatformLayerDisplayDelegate::create(m_texmapLayer.get()))
-#endif
 {
 }
 
 RefPtr<GraphicsLayerContentsDisplayDelegate> GraphicsContextGLTextureMapper::layerContentsDisplayDelegate()
 {
-    return m_layerContentsDisplayDelegate.ptr();
+    return m_layerContentsDisplayDelegate;
 }
 
 RefPtr<GraphicsContextGL> createWebProcessGraphicsContextGL(const GraphicsContextGLAttributes& attributes)
@@ -192,6 +159,15 @@
 }
 #endif
 
+#if USE(NICOSIA) && !USE(ANGLE)
+bool GraphicsContextGLTextureMapper::platformInitialize()
+{
+    m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(&m_nicosiaLayer->contentLayer());
+
+    return true;
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER)

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.h (290539 => 290540)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.h	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -45,7 +45,7 @@
 public:
     static RefPtr<GraphicsContextGLTextureMapper> create(WebCore::GraphicsContextGLAttributes&&);
     ~GraphicsContextGLTextureMapper();
-    
+
     // GraphicsContextGLTextureMapperBase overrides.
     RefPtr<GraphicsLayerContentsDisplayDelegate> layerContentsDisplayDelegate() final;
 #if ENABLE(VIDEO)
@@ -60,9 +60,13 @@
     void prepareForDisplay() final;
 #endif
 
-protected:
+private:
+#if USE(ANGLE)
+    bool platformInitializeContext() final;
+#endif
+    bool platformInitialize() final;
     GraphicsContextGLTextureMapper(WebCore::GraphicsContextGLAttributes&&);
-    Ref<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
+    RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
 };
 
 }

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


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-02-26 02:03:23 UTC (rev 290540)
@@ -32,7 +32,9 @@
 #include "ANGLEHeaders.h"
 #include "ANGLEUtilities.h"
 #include "GraphicsContextGLOpenGLManager.h"
+#include "Logging.h"
 #include "PixelBuffer.h"
+#include "PlatformLayerDisplayDelegate.h"
 
 #if USE(NICOSIA)
 #include "GBMDevice.h"
@@ -41,6 +43,8 @@
 #include <fcntl.h>
 #include <gbm.h>
 #else
+#include "GLContext.h"
+#include "PlatformDisplay.h"
 #include "TextureMapperGCGLPlatformLayer.h"
 #endif
 
@@ -49,11 +53,116 @@
 GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attributes)
     : GraphicsContextGL(attributes)
 {
+}
+
+bool GraphicsContextGLTextureMapper::platformInitializeContext()
+{
+    GraphicsContextGLAttributes attributes = contextAttributes();
 #if ENABLE(WEBGL2)
     m_isForWebGL2 = attributes.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);
+
 #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.");
+        return false;
+    }
+    if (!makeContextCurrent()) {
+        LOG(WebGL, "ANGLE makeContextCurrent failed.");
+        return false;
+    }
+    LOG(WebGL, "Got EGLContext");
+    return true;
+}
+
+bool GraphicsContextGLTextureMapper::platformInitialize()
+{
+#if USE(NICOSIA)
     m_nicosiaLayer = makeUnique<Nicosia::GCGLANGLELayer>(*this);
+    m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(&m_nicosiaLayer->contentLayer());
 
     const auto& gbmDevice = GBMDevice::get();
     if (gbmDevice.device()) {
@@ -63,11 +172,10 @@
     }
 #else
     m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
+    m_layerContentsDisplayDelegate = PlatformLayerDisplayDelegate::create(m_texmapLayer.get());
 #endif
     bool success = makeContextCurrent();
     ASSERT_UNUSED(success, success);
-    success = initialize();
-    ASSERT_UNUSED(success, success);
 
     // We require this extension to render into the dmabuf-backed EGLImage.
     RELEASE_ASSERT(supportsExtension("GL_OES_EGL_image"));
@@ -74,7 +182,7 @@
     GL_RequestExtensionANGLE("GL_OES_EGL_image");
 
     validateAttributes();
-    attributes = contextAttributes(); // They may have changed during validation.
+    auto attributes = contextAttributes(); // They may have changed during validation.
 
     GLenum textureTarget = drawingBufferTextureTarget();
     // Create a texture to render into.
@@ -126,6 +234,7 @@
     }
 
     GL_ClearColor(0, 0, 0, 0);
+    return true;
 }
 
 #if USE(NICOSIA)
@@ -238,29 +347,19 @@
 
 GCGLDisplay GraphicsContextGLANGLE::platformDisplay() const
 {
-#if USE(NICOSIA)
-    return m_nicosiaLayer->platformDisplay();
-#else
-    return m_texmapLayer->platformDisplay();
-#endif
+    return m_displayObj;
 }
 
 GCGLConfig GraphicsContextGLANGLE::platformConfig() const
 {
-#if USE(NICOSIA)
-    return m_nicosiaLayer->platformConfig();
-#else
-    return m_texmapLayer->platformConfig();
-#endif
+    return m_configObj;
 }
 
 bool GraphicsContextGLANGLE::makeContextCurrent()
 {
-#if USE(NICOSIA)
-    return m_nicosiaLayer->makeContextCurrent();
-#else
-    return m_texmapLayer->makeContextCurrent();
-#endif
+    if (EGL_GetCurrentContext() == m_contextObj)
+        return true;
+    return EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
 }
 
 void GraphicsContextGLANGLE::checkGPUStatus()

Copied: trunk/Source/WebCore/platform/graphics/texmap/PlatformLayerDisplayDelegate.h (from rev 290539, trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.h) (0 => 290540)


--- trunk/Source/WebCore/platform/graphics/texmap/PlatformLayerDisplayDelegate.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/PlatformLayerDisplayDelegate.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * 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. ``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
+ * 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 "GraphicsLayerContentsDisplayDelegate.h"
+#include "PlatformLayer.h"
+
+namespace WebCore {
+
+class PlatformLayerDisplayDelegate final : public GraphicsLayerContentsDisplayDelegate {
+public:
+    static Ref<PlatformLayerDisplayDelegate> create(PlatformLayer* platformLayer)
+    {
+        return adoptRef(*new PlatformLayerDisplayDelegate(platformLayer));
+    }
+
+    // GraphicsLayerContentsDisplayDelegate overrides.
+    PlatformLayer* platformLayer() const final
+    {
+        return m_platformLayer;
+    }
+
+private:
+    PlatformLayerDisplayDelegate(PlatformLayer* platformLayer)
+        : m_platformLayer(platformLayer)
+    {
+    }
+
+    PlatformLayer* m_platformLayer;
+};
+
+} // namespace WebCore

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


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2022-02-26 02:03:23 UTC (rev 290540)
@@ -23,7 +23,6 @@
 
 #if ENABLE(WEBGL) && USE(TEXTURE_MAPPER) && !USE(NICOSIA)
 
-#include "ANGLEContext.h"
 #include "ANGLEHeaders.h"
 #include "BitmapTextureGL.h"
 #include "GLContext.h"
@@ -36,77 +35,16 @@
 TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer(GraphicsContextGLANGLE& context)
     : m_context(context)
 {
-    auto sharingContext = PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->platformContext();
-#if ENABLE(WEBGL2)
-    m_glContext = ANGLEContext::createContext(sharingContext, context.contextAttributes().webGLVersion == GraphicsContextGLWebGLVersion::WebGL2);
-#else
-    m_glContext = ANGLEContext::createContext(sharingContext, false);
-#endif
-
-#if USE(COORDINATED_GRAPHICS)
-    m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxyGL);
-#endif
 }
 
 TextureMapperGCGLPlatformLayer::~TextureMapperGCGLPlatformLayer()
 {
-#if !USE(COORDINATED_GRAPHICS)
     if (client())
         client()->platformLayerWillBeDestroyed();
-#endif
 }
 
-bool TextureMapperGCGLPlatformLayer::makeContextCurrent()
-{
-    ASSERT(m_glContext);
-    return m_glContext->makeContextCurrent();
-}
-
-GCGLContext TextureMapperGCGLPlatformLayer::platformContext() const
-{
-    ASSERT(m_glContext);
-    return m_glContext->platformContext();
-}
-
-GCGLDisplay TextureMapperGCGLPlatformLayer::platformDisplay() const
-{
-    ASSERT(m_glContext);
-    return m_glContext->platformDisplay();
-}
-
-GCGLConfig TextureMapperGCGLPlatformLayer::platformConfig() const
-{
-    ASSERT(m_glContext);
-    return m_glContext->platformConfig();
-}
-
-#if USE(COORDINATED_GRAPHICS)
-RefPtr<TextureMapperPlatformLayerProxy> TextureMapperGCGLPlatformLayer::proxy() const
-{
-    return m_platformLayerProxy.copyRef();
-}
-
-void TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded()
-{
-    if (m_context.layerComposited())
-        return;
-
-    m_context.prepareTexture();
-    IntSize textureSize(m_context.m_currentWidth, m_context.m_currentHeight);
-    TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context.m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
-
-    {
-        Locker locker { m_platformLayerProxy->lock() };
-        downcast<TextureMapperPlatformLayerProxyGL>(*m_platformLayerProxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat));
-    }
-
-    m_context.markLayerComposited();
-}
-#else
 void TextureMapperGCGLPlatformLayer::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
 {
-    ASSERT(m_glContext);
-
     m_context.markLayerComposited();
 
 #if USE(TEXTURE_MAPPER_GL)
@@ -129,7 +67,6 @@
     texmapGL.drawTexture(m_context.m_texture, flags, textureSize, targetRect, matrix, opacity);
 #endif // USE(TEXTURE_MAPPER_GL)
 }
-#endif // USE(COORDINATED_GRAPHICS)
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.h (290539 => 290540)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.h	2022-02-26 01:47:04 UTC (rev 290539)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.h	2022-02-26 02:03:23 UTC (rev 290540)
@@ -28,7 +28,6 @@
 
 namespace WebCore {
 
-class ANGLEContext;
 class TextureMapperPlatformLayerProxy;
 
 class TextureMapperGCGLPlatformLayer : public PlatformLayer {
@@ -37,25 +36,10 @@
     TextureMapperGCGLPlatformLayer(GraphicsContextGLANGLE&);
     virtual ~TextureMapperGCGLPlatformLayer();
 
-    bool makeContextCurrent();
-    GCGLContext platformContext() const;
-    GCGLDisplay platformDisplay() const;
-    GCGLConfig platformConfig() const;
-
-#if USE(COORDINATED_GRAPHICS)
-    RefPtr<TextureMapperPlatformLayerProxy> proxy() const override;
-    void swapBuffersIfNeeded() override;
-#else
     virtual void paintToTextureMapper(TextureMapper&, const FloatRect& target, const TransformationMatrix&, float opacity);
-#endif
 
 private:
     GraphicsContextGLANGLE& m_context;
-    std::unique_ptr<ANGLEContext> m_glContext;
-
-#if USE(COORDINATED_GRAPHICS)
-    RefPtr<TextureMapperPlatformLayerProxy> m_platformLayerProxy;
-#endif
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to