summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2015-09-07 22:21:15 +0100
committerMichael Meeks <michael.meeks@collabora.com>2015-09-08 13:04:02 +0100
commit2456cf8306be22e32130e789ab939c059e5e79e5 (patch)
treed188be461e188023fd4da0690e6278e76e596c2d /vcl/source
parent64c6b0ed6c67d169021732d276ec02706e139261 (diff)
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
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/app/svdata.cxx12
-rw-r--r--vcl/source/gdi/salgdilayout.cxx2
-rw-r--r--vcl/source/opengl/OpenGLContext.cxx48
3 files changed, 15 insertions, 47 deletions
diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index bfc2bb402ee7..ca815a2f3103 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -140,15 +140,9 @@ vcl::Window* ImplGetDefaultWindow()
pSVData->mpDefaultWin->SetText( OUString( "VCL ImplGetDefaultWindow" ) );
// Add a reference to the default context so it never gets deleted
- OpenGLContext* pContext = pSVData->mpDefaultWin->GetGraphics()->GetOpenGLContext();
- if( pContext )
- {
-#ifdef DBG_UTIL
- pContext->AddRef(NULL);
-#else
- pContext->AddRef();
-#endif
- }
+ rtl::Reference<OpenGLContext> pContext = pSVData->mpDefaultWin->GetGraphics()->GetOpenGLContext();
+ if( pContext.is() )
+ pContext->acquire();
}
Application::GetSolarMutex().release();
}
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 46f76ffb33cc..945f7ae9f687 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -76,7 +76,7 @@ SalGraphics::~SalGraphics()
{
}
-OpenGLContext* SalGraphics::GetOpenGLContext() const
+rtl::Reference<OpenGLContext> SalGraphics::GetOpenGLContext() const
{
OpenGLSalGraphicsImpl *pImpl = dynamic_cast<OpenGLSalGraphicsImpl*>(GetImpl());
if (pImpl)
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> 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<OpenGLContext>(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<OpenGLContext> 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<OpenGLContext> pCurrentCtx = pSVData->maGDIData.mpLastContext;
- if ( !pCurrentCtx )
+ if ( !pCurrentCtx.is() )
return; // Not using OpenGL
SAL_INFO("vcl.opengl", "Unbinding contexts in preparation for yield");