Title: [291035] trunk/Source/WebCore
Revision
291035
Author
commit-qu...@webkit.org
Date
2022-03-09 00:36:52 -0800 (Wed, 09 Mar 2022)

Log Message

GraphicsContextGLCocoa manages EGL native displays manually
https://bugs.webkit.org/show_bug.cgi?id=237313

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-03-09
Reviewed by Kenneth Russell.

ANGLE now keys the Metal EGL_DEFAULT_DISPLAY on the EGL_PLATFORM_ANGLE_TYPE_ANGLE.
This means that we do not need to use the default a native display for Metal and an
invented native display for OpenGL.

* platform/graphics/GraphicsTypesGL.h:
* platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::platformInitialize):
(WebCore::GraphicsContextGLANGLE::releaseThreadResources):
* platform/graphics/angle/GraphicsContextGLANGLE.h:
* platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::initializeEGLDisplay):
(WebCore::GraphicsContextGLCocoa::platformInitialize):
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
(WebCore::GraphicsContextGLTextureMapper::platformInitialize):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291034 => 291035)


--- trunk/Source/WebCore/ChangeLog	2022-03-09 08:04:45 UTC (rev 291034)
+++ trunk/Source/WebCore/ChangeLog	2022-03-09 08:36:52 UTC (rev 291035)
@@ -1,3 +1,25 @@
+2022-03-09  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        GraphicsContextGLCocoa manages EGL native displays manually
+        https://bugs.webkit.org/show_bug.cgi?id=237313
+
+        Reviewed by Kenneth Russell.
+
+        ANGLE now keys the Metal EGL_DEFAULT_DISPLAY on the EGL_PLATFORM_ANGLE_TYPE_ANGLE.
+        This means that we do not need to use the default a native display for Metal and an
+        invented native display for OpenGL.
+
+        * platform/graphics/GraphicsTypesGL.h:
+        * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+        (WebCore::GraphicsContextGLANGLE::platformInitialize):
+        (WebCore::GraphicsContextGLANGLE::releaseThreadResources):
+        * platform/graphics/angle/GraphicsContextGLANGLE.h:
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+        (WebCore::initializeEGLDisplay):
+        (WebCore::GraphicsContextGLCocoa::platformInitialize):
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
+        (WebCore::GraphicsContextGLTextureMapper::platformInitialize):
+
 2022-03-09  Youenn Fablet  <you...@apple.com>
 
         Scope capture sources by page identifiers

Modified: trunk/Source/WebCore/platform/graphics/GraphicsTypesGL.h (291034 => 291035)


--- trunk/Source/WebCore/platform/graphics/GraphicsTypesGL.h	2022-03-09 08:04:45 UTC (rev 291034)
+++ trunk/Source/WebCore/platform/graphics/GraphicsTypesGL.h	2022-03-09 08:36:52 UTC (rev 291035)
@@ -67,10 +67,6 @@
 typedef unsigned GLuint;
 #endif
 
-using GCGLNativeDisplayType = int;
-
-inline constexpr GCGLNativeDisplayType gcGLDefaultDisplay = 0;
-
 inline constexpr size_t gcGLSpanDynamicExtent = std::numeric_limits<size_t>::max();
 
 template<typename T, size_t Extent = gcGLSpanDynamicExtent>

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (291034 => 291035)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2022-03-09 08:04:45 UTC (rev 291034)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2022-03-09 08:36:52 UTC (rev 291035)
@@ -37,6 +37,7 @@
 #include "Logging.h"
 #include "NotImplemented.h"
 #include "PixelBuffer.h"
+#include "RuntimeApplicationChecks.h"
 #include <algorithm>
 #include <cstring>
 #include <wtf/Seconds.h>
@@ -57,6 +58,15 @@
 
 static Seconds maxFrameDuration = 5_s;
 
+// List of displays ever instantiated from EGL. When terminating all EGL resources, we need to
+// terminate all displays. However, we cannot ask EGL all the displays it has created.
+// We must know all the displays via this set.
+static HashSet<GCGLDisplay>& usedDisplays()
+{
+    static NeverDestroyed<HashSet<GCGLDisplay>> s_usedDisplays;
+    return s_usedDisplays;
+}
+
 #if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
 static void wipeAlphaChannelFromPixels(int width, int height, unsigned char* pixels)
 {
@@ -89,6 +99,14 @@
 
 bool GraphicsContextGLANGLE::platformInitialize()
 {
+    // EGL resources are only ever released if we run in process mode where EGL is used on host app threads, e.g. WK1
+    // mode.
+    static bool tracksUsedDisplays = !(isInWebProcess() || isInGPUProcess());
+    if (tracksUsedDisplays) {
+        // TODO: Move to ~GraphicsContextGLANGLE() when the function is moved to this file.
+        ASSERT(m_displayObj);
+        usedDisplays().add(m_displayObj);
+    }
     return true;
 }
 
@@ -162,17 +180,9 @@
             ASSERT_NOT_REACHED(); // All resources must have been destroyed.
             EGL_MakeCurrent(currentDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
         }
-        const EGLNativeDisplayType nativeDisplays[] = {
-            reinterpret_cast<EGLNativeDisplayType>(defaultDisplay),
-#if PLATFORM(COCOA)
-            reinterpret_cast<EGLNativeDisplayType>(defaultOpenGLDisplay),
-#endif
-        };
-        for (auto nativeDisplay : nativeDisplays) {
-            EGLDisplay display = EGL_GetDisplay(nativeDisplay);
-            if (display != EGL_NO_DISPLAY)
-                EGL_Terminate(display);
-        }
+        for (auto display : usedDisplays())
+            EGL_Terminate(display);
+        usedDisplays().clear();
     }
     // Called when we do not know if we will ever see another call from this thread again.
     // Unset the EGL current context by releasing whole EGL thread state.

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


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-03-09 08:04:45 UTC (rev 291034)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-03-09 08:36:52 UTC (rev 291035)
@@ -358,12 +358,6 @@
     std::optional<PixelBuffer> readRenderingResultsForPainting();
     std::optional<PixelBuffer> readCompositedResultsForPainting();
 
-    constexpr static GCGLNativeDisplayType defaultDisplay = gcGLDefaultDisplay;
-#if PLATFORM(COCOA)
-    constexpr static GCGLNativeDisplayType defaultOpenGLDisplay = static_cast<GCGLNativeDisplayType>(-1);
-    static_assert(defaultDisplay != defaultOpenGLDisplay);
-#endif
-
 protected:
     GraphicsContextGLANGLE(GraphicsContextGLAttributes);
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (291034 => 291035)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-03-09 08:04:45 UTC (rev 291034)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-03-09 08:36:52 UTC (rev 291035)
@@ -140,7 +140,6 @@
     }
 
     LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal ? "Metal" : "OpenGL");
-    EGLNativeDisplayType nativeDisplay = GraphicsContextGLANGLE::defaultDisplay;
     if (attrs.useMetal) {
         displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
         displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE);
@@ -154,11 +153,10 @@
             displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
             displayAttributes.append(EGL_HIGH_POWER_ANGLE);
         }
-    } else
-        nativeDisplay = GraphicsContextGLANGLE::defaultOpenGLDisplay;
+    }
 
     displayAttributes.append(EGL_NONE);
-    display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(nativeDisplay), displayAttributes.data());
+    display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
 
     if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
         LOG(WebGL, "EGLDisplay Initialization failed.");
@@ -422,7 +420,7 @@
     if (!attributes.useMetal && attributes.effectivePowerPreference() == GraphicsContextGLPowerPreference::HighPerformance)
         m_switchesGPUOnDisplayReconfiguration = true;
 #endif
-    return true;
+    return GraphicsContextGLANGLE::platformInitialize();
 }
 
 GraphicsContextGLANGLE::~GraphicsContextGLANGLE()

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


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-03-09 08:04:45 UTC (rev 291034)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-03-09 08:36:52 UTC (rev 291035)
@@ -233,7 +233,7 @@
     }
 
     GL_ClearColor(0, 0, 0, 0);
-    return true;
+    return GraphicsContextGLANGLE::platformInitialize();
 }
 
 #if USE(NICOSIA)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to