@@ -44,11 +44,7 @@ namespace Nicosia {
4444using namespace WebCore ;
4545
4646static std::unique_ptr<GLContext> s_windowContext;
47-
48- static void terminateWindowContext ()
49- {
50- s_windowContext = nullptr ;
51- }
47+ static int s_windowContextRefCount = 0 ;
5248
5349std::unique_ptr<GCGLLayer> GCGLLayer::create (WebCore::GraphicsContextGLOpenGL& context)
5450{
@@ -60,7 +56,6 @@ std::unique_ptr<GCGLLayer> GCGLLayer::create(WebCore::GraphicsContextGLOpenGL& c
6056 } else {
6157 if (!s_windowContext) {
6258 s_windowContext = GLContext::createContextForWindow (reinterpret_cast <GLNativeWindowType>(attributes.nativeWindowID ), &PlatformDisplay::sharedDisplayForCompositing ());
63- std::atexit (terminateWindowContext);
6459 }
6560 if (s_windowContext)
6661 return makeUnique<GCGLLayer>(context);
@@ -80,11 +75,21 @@ GCGLLayer::GCGLLayer(GraphicsContextGLOpenGL& context)
8075 : m_context(context)
8176 , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this )))
8277{
78+ ASSERT (s_windowContext);
79+ s_windowContextRefCount++;
8380}
8481
8582GCGLLayer::~GCGLLayer ()
8683{
8784 downcast<ContentLayerTextureMapperImpl>(m_contentLayer->impl ()).invalidateClient ();
85+
86+ if (m_context.contextAttributes ().renderTarget != GraphicsContextGLRenderTarget::Offscreen) {
87+ ASSERT (s_windowContext);
88+ s_windowContextRefCount--;
89+ if (!s_windowContextRefCount) {
90+ s_windowContext = nullptr ;
91+ }
92+ }
8893}
8994
9095bool GCGLLayer::makeContextCurrent ()
0 commit comments