From 2456cf8306be22e32130e789ab939c059e5e79e5 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Mon, 7 Sep 2015 22:21:15 +0100 Subject: tdf#94006 - re-factor to use rtl::Reference for OpenGLContexts. Don't use rtl::Reference for the global / list state, so the ref-count reflects the number of real users. Hold a reference during ~OpenGLContext. Change-Id: I4e57a7246159acd58ae7d5a0dfc8704b9795c894 --- vcl/source/opengl/OpenGLContext.cxx | 48 +++++++++---------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) (limited to 'vcl/source/opengl/OpenGLContext.cxx') diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index df8c6a60c18b..d070e3fb3b6b 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -58,7 +58,7 @@ OpenGLContext::OpenGLContext(): mpWindow(NULL), m_pChildWindow(NULL), mbInitialized(false), - mnRefCount(1), + mnRefCount(0), mbRequestLegacyContext(false), mbUseDoubleBufferedRendering(true), mnFramebufferCount(0), @@ -93,6 +93,9 @@ OpenGLContext::OpenGLContext(): OpenGLContext::~OpenGLContext() { VCL_GL_INFO("vcl.opengl", "delete context: " << this); + assert (mnRefCount == 0); + + mnRefCount = 1; // guard the shutdown paths. reset(); ImplSVData* pSVData = ImplGetSVData(); @@ -106,42 +109,13 @@ OpenGLContext::~OpenGLContext() pSVData->maGDIData.mpLastContext = mpPrevContext; m_pChildWindow.disposeAndClear(); + assert (mnRefCount == 1); } -#ifdef DBG_UTIL -void OpenGLContext::AddRef(SalGraphicsImpl* pImpl) -{ - assert(mnRefCount > 0); - mnRefCount++; - - maParents.insert(pImpl); -} - -void OpenGLContext::DeRef(SalGraphicsImpl* pImpl) +rtl::Reference OpenGLContext::Create() { - - auto it = maParents.find(pImpl); - if(it != maParents.end()) - maParents.erase(it); - - assert(mnRefCount > 0); - if( --mnRefCount == 0 ) - delete this; + return rtl::Reference(new OpenGLContext); } -#else -void OpenGLContext::AddRef() -{ - assert(mnRefCount > 0); - mnRefCount++; -} - -void OpenGLContext::DeRef() -{ - assert(mnRefCount > 0); - if( --mnRefCount == 0 ) - delete this; -} -#endif void OpenGLContext::requestLegacyContext() { @@ -1337,8 +1311,8 @@ void OpenGLContext::clearCurrent() // release all framebuffers from the old context so we can re-attach the // texture in the new context - OpenGLContext* pCurrentCtx = pSVData->maGDIData.mpLastContext; - if( pCurrentCtx && pCurrentCtx->isCurrent() ) + rtl::Reference pCurrentCtx = pSVData->maGDIData.mpLastContext; + if( pCurrentCtx.is() && pCurrentCtx->isCurrent() ) pCurrentCtx->ReleaseFramebuffers(); } @@ -1348,9 +1322,9 @@ void OpenGLContext::prepareForYield() // release all framebuffers from the old context so we can re-attach the // texture in the new context - OpenGLContext* pCurrentCtx = pSVData->maGDIData.mpLastContext; + rtl::Reference pCurrentCtx = pSVData->maGDIData.mpLastContext; - if ( !pCurrentCtx ) + if ( !pCurrentCtx.is() ) return; // Not using OpenGL SAL_INFO("vcl.opengl", "Unbinding contexts in preparation for yield"); -- cgit v1.2.3