Skip to content

Commit 39e5423

Browse files
committed
Cherry-pick 301043@main (1d16639f9d57). https://bugs.webkit.org/show_bug.cgi?id=300085
[GTK][WPE] OpenGL assets created by WebGL are not released when destroying the WebGLRenderingContext https://bugs.webkit.org/show_bug.cgi?id=300085 Reviewed by Carlos Garcia Campos. Stop using a singleton for the ANGLE sharing context. Each ANGLE context will use its own ANGLE sharing context instead, that will be created and destroyed together with the ANGLE context. This ensures that all the OpenGL resources that were created by ANGLE will be destroyed when the contexts are destroyed. * Source/WebCore/platform/graphics/PlatformDisplay.cpp: (WebCore::PlatformDisplay::clearGLContexts): * Source/WebCore/platform/graphics/PlatformDisplay.h: * Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h: * Source/WebCore/platform/graphics/angle/PlatformDisplayANGLE.cpp: (WebCore::PlatformDisplay::angleSharingGLContext): (WebCore::PlatformDisplay::clearANGLESharingGLContext): Deleted. * Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp: (WebCore::GraphicsContextGLANGLE::~GraphicsContextGLANGLE): (WebCore::GraphicsContextGLTextureMapperANGLE::platformInitializeContext): Canonical link: https://commits.webkit.org/301043@main
1 parent ac4f27b commit 39e5423

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

Source/WebCore/platform/graphics/PlatformDisplay.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ void PlatformDisplay::clearSharingGLContext()
130130
#endif
131131
#if ENABLE(VIDEO) && USE(GSTREAMER_GL)
132132
m_gstGLContext = nullptr;
133-
#endif
134-
#if ENABLE(WEBGL) && !PLATFORM(WIN)
135-
clearANGLESharingGLContext();
136133
#endif
137134
m_sharingGLContext = nullptr;
138135
}

Source/WebCore/platform/graphics/PlatformDisplay.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,10 @@ class PlatformDisplay {
130130
void invalidateSkiaGLContexts();
131131
#endif
132132

133-
#if ENABLE(WEBGL) && !PLATFORM(WIN)
134-
void clearANGLESharingGLContext();
135-
#endif
136-
137133
void terminateEGLDisplay();
138134

139135
#if ENABLE(WEBGL) && !PLATFORM(WIN)
140136
mutable EGLDisplay m_angleEGLDisplay { nullptr };
141-
EGLContext m_angleSharingGLContext { nullptr };
142137
#endif
143138

144139
#if ENABLE(VIDEO) && USE(GSTREAMER_GL)

Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ class WEBCORE_EXPORT GraphicsContextGLANGLE : public GraphicsContextGL {
443443

444444
GCGLDisplay m_displayObj { nullptr };
445445
GCGLContext m_contextObj { nullptr };
446+
GCGLContext m_angleSharingContextObj { nullptr };
446447
GCGLConfig m_configObj { nullptr };
447448
#if USE(TEXTURE_MAPPER)
448449
GCEGLSurface m_surfaceObj { nullptr };

Source/WebCore/platform/graphics/angle/PlatformDisplayANGLE.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ EGLContext PlatformDisplay::angleSharingGLContext()
8484
#if PLATFORM(WIN)
8585
return sharingGLContext()->platformContext();
8686
#else
87-
if (m_angleSharingGLContext != EGL_NO_CONTEXT)
88-
return m_angleSharingGLContext;
89-
9087
ASSERT(m_angleEGLDisplay != EGL_NO_DISPLAY);
9188
auto sharingContext = sharingGLContext();
9289
if (!sharingContext)
@@ -115,25 +112,10 @@ EGLContext PlatformDisplay::angleSharingGLContext()
115112
EGL_EXTERNAL_CONTEXT_ANGLE, EGL_TRUE,
116113
EGL_NONE
117114
};
118-
m_angleSharingGLContext = EGL_CreateContext(m_angleEGLDisplay, config, EGL_NO_CONTEXT, contextAttributes);
119-
return m_angleSharingGLContext;
120-
#endif
121-
}
122115

123-
#if ENABLE(WEBGL) && !PLATFORM(WIN)
124-
void PlatformDisplay::clearANGLESharingGLContext()
125-
{
126-
if (m_angleSharingGLContext == EGL_NO_CONTEXT)
127-
return;
128-
129-
ASSERT(m_angleEGLDisplay);
130-
ASSERT(m_sharingGLContext);
131-
EGL_MakeCurrent(m_angleEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
132-
EGL_DestroyContext(m_angleEGLDisplay, m_angleSharingGLContext);
133-
m_angleSharingGLContext = EGL_NO_CONTEXT;
134-
}
116+
return EGL_CreateContext(m_angleEGLDisplay, config, EGL_NO_CONTEXT, contextAttributes);
135117
#endif
136-
118+
}
137119

138120
} // namespace WebCore
139121

Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ GraphicsContextGLANGLE::~GraphicsContextGLANGLE()
108108
GL_DeleteFramebuffers(1, &m_fbo);
109109

110110
if (m_contextObj) {
111-
EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
112111
EGL_DestroyContext(m_displayObj, m_contextObj);
113112
}
114113

114+
if (m_angleSharingContextObj)
115+
EGL_DestroyContext(m_displayObj, m_angleSharingContextObj);
116+
117+
// Ideally this should go before the m_contextObj destruction, but there are platforms where it breaks
118+
// the destruction m_contextObj. Putting it here works for all the platforms that I've tested.
119+
EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
120+
115121
if (m_surfaceObj)
116122
EGL_DestroySurface(m_displayObj, m_surfaceObj);
117123
}
@@ -306,7 +312,13 @@ bool GraphicsContextGLTextureMapperANGLE::platformInitializeContext()
306312
}
307313
eglContextAttributes.append(EGL_NONE);
308314

309-
m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, sharedDisplay.angleSharingGLContext(), eglContextAttributes.data());
315+
m_angleSharingContextObj = sharedDisplay.angleSharingGLContext();
316+
if (m_angleSharingContextObj == EGL_NO_CONTEXT) {
317+
LOG(WebGL, "ANGLE sharing EGLContext Initialization failed.");
318+
return false;
319+
}
320+
321+
m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, m_angleSharingContextObj, eglContextAttributes.data());
310322
if (m_contextObj == EGL_NO_CONTEXT) {
311323
LOG(WebGL, "EGLContext Initialization failed.");
312324
return false;

0 commit comments

Comments
 (0)