diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-09-07 22:21:15 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-09-08 13:04:02 +0100 |
commit | 2456cf8306be22e32130e789ab939c059e5e79e5 (patch) | |
tree | d188be461e188023fd4da0690e6278e76e596c2d /vcl/opengl/gdiimpl.cxx | |
parent | 64c6b0ed6c67d169021732d276ec02706e139261 (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/opengl/gdiimpl.cxx')
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 9a2d72e447b2..54873479b991 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -61,14 +61,14 @@ OpenGLSalGraphicsImpl::~OpenGLSalGraphicsImpl() ReleaseContext(); } -OpenGLContext* OpenGLSalGraphicsImpl::GetOpenGLContext() +rtl::Reference<OpenGLContext> OpenGLSalGraphicsImpl::GetOpenGLContext() { if( !AcquireContext() ) return NULL; return mpContext; } -OpenGLContext* OpenGLSalGraphicsImpl::GetDefaultContext() +rtl::Reference<OpenGLContext> OpenGLSalGraphicsImpl::GetDefaultContext() { return ImplGetDefaultWindow()->GetGraphics()->GetOpenGLContext(); } @@ -77,19 +77,14 @@ bool OpenGLSalGraphicsImpl::AcquireContext( ) { ImplSVData* pSVData = ImplGetSVData(); - if( mpContext ) + if( mpContext.is() ) { if( mpContext->isInitialized() ) return true; -#ifdef DBG_UTIL - mpContext->DeRef(this); -#else - mpContext->DeRef(); -#endif + mpContext.clear(); } - - OpenGLContext* pContext = pSVData->maGDIData.mpLastContext; + OpenGLContext *pContext = pSVData->maGDIData.mpLastContext; while( pContext ) { // check if this context can be used by this SalGraphicsImpl instance @@ -99,31 +94,17 @@ bool OpenGLSalGraphicsImpl::AcquireContext( ) } if( pContext ) - { -#ifdef DBG_UTIL - pContext->AddRef(this); -#else - pContext->AddRef(); -#endif - } + mpContext = pContext; else - pContext = mbOffscreen ? GetDefaultContext() : CreateWinContext(); + mpContext = mbOffscreen ? GetDefaultContext() : CreateWinContext(); - mpContext = pContext; - return (mpContext != NULL); + return mpContext.is(); } bool OpenGLSalGraphicsImpl::ReleaseContext() { - if( mpContext ) - { -#ifdef DBG_UTIL - mpContext->DeRef(this); -#else - mpContext->DeRef(); -#endif - } - mpContext = NULL; + mpContext.clear(); + return true; } @@ -132,7 +113,7 @@ void OpenGLSalGraphicsImpl::Init() mbOffscreen = IsOffscreen(); // check if we can simply re-use the same context - if( mpContext ) + if( mpContext.is() ) { if( !UseContext( mpContext ) ) ReleaseContext(); @@ -143,7 +124,7 @@ void OpenGLSalGraphicsImpl::Init() maOffscreenTex.GetWidth() != GetWidth() || maOffscreenTex.GetHeight() != GetHeight() ) { - if( mpContext ) // valid context + if( mpContext.is() ) // valid context mpContext->ReleaseFramebuffer( maOffscreenTex ); maOffscreenTex = OpenGLTexture(); } @@ -158,7 +139,7 @@ void OpenGLSalGraphicsImpl::DeInit() // let it know. Other eg. VirtualDevice contexts which have // references on and rely on this context continuing to work will // get a shiny new context in AcquireContext:: next PreDraw. - if( mpContext && !IsOffscreen() ) + if( mpContext.is() && !IsOffscreen() ) mpContext->reset(); } @@ -216,7 +197,7 @@ void OpenGLSalGraphicsImpl::ApplyProgramMatrices(float fPixelOffset) void OpenGLSalGraphicsImpl::freeResources() { // TODO Delete shaders, programs and textures if not shared - if( mbOffscreen && mpContext && mpContext->isInitialized() ) + if( mbOffscreen && mpContext.is() && mpContext->isInitialized() ) { mpContext->makeCurrent(); mpContext->ReleaseFramebuffer( maOffscreenTex ); |