summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2015-01-20 04:12:18 +0100
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2015-01-20 12:03:57 +0100
commit145ad1964389d363e389490be4b9acad1b6b7b99 (patch)
tree907fc0f38489d7202e7d0707f69a648b6cf699b9
parent99f809c7eb0a2298f9c0044aeabdfc1bb72e2287 (diff)
some debug code for finding leaked OpenGLContexts
Change-Id: I10e8c344ae6aa2e0a4ef562154f57e2070c70e2f
-rw-r--r--include/vcl/opengl/OpenGLContext.hxx11
-rw-r--r--vcl/opengl/gdiimpl.cxx16
-rw-r--r--vcl/source/app/svdata.cxx6
-rw-r--r--vcl/source/app/svmain.cxx6
-rw-r--r--vcl/source/opengl/OpenGLContext.cxx21
5 files changed, 60 insertions, 0 deletions
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx
index 18fc710a2f73..0178e21ebcd0 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -56,9 +56,12 @@ class NSOpenGLView;
#include <tools/gen.hxx>
#include <vcl/syschild.hxx>
+#include <set>
+
class OpenGLFramebuffer;
class OpenGLProgram;
class OpenGLTexture;
+class SalGraphicsImpl;
/// Holds the information of our new child window
struct GLWindow
@@ -189,8 +192,13 @@ public:
bool AcquireDefaultFramebuffer();
OpenGLFramebuffer* AcquireFramebuffer( const OpenGLTexture& rTexture );
void ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer );
+#ifdef DBG_UTIL
+ void AddRef(SalGraphicsImpl*);
+ void DeRef(SalGraphicsImpl*);
+#else
void AddRef();
void DeRef();
+#endif
void ReleaseFramebuffer( const OpenGLTexture& rTexture );
void ReleaseFramebuffers();
@@ -260,6 +268,9 @@ private:
boost::ptr_map<ProgramKey, OpenGLProgram> maPrograms;
OpenGLProgram* mpCurrentProgram;
+#ifdef DBG_UTIL
+ std::set<SalGraphicsImpl*> maParents;
+#endif
public:
vcl::Region maClipRegion;
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index bae53023dba5..da2ace3fce62 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -80,7 +80,11 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
{
if( mpContext->isInitialized() )
return true;
+#ifdef DBG_UTIL
+ mpContext->DeRef(this);
+#else
mpContext->DeRef();
+#endif
}
@@ -94,7 +98,13 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
}
if( pContext )
+ {
+#ifdef DBG_UTIL
+ pContext->AddRef(this);
+#else
pContext->AddRef();
+#endif
+ }
else
pContext = mbOffscreen ? GetDefaultContext() : CreateWinContext();
@@ -105,7 +115,13 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
bool OpenGLSalGraphicsImpl::ReleaseContext()
{
if( mpContext )
+ {
+#ifdef DBG_UTIL
+ mpContext->DeRef(this);
+#else
mpContext->DeRef();
+#endif
+ }
mpContext = NULL;
return true;
}
diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index c539a7637866..155b5cc0ba3c 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -130,7 +130,13 @@ vcl::Window* 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
+ }
}
Application::GetSolarMutex().release();
}
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 8ae359276b23..c0979a651892 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -444,7 +444,13 @@ void DeInitVCL()
{
OpenGLContext* pContext = pSVData->mpDefaultWin->GetGraphics()->GetOpenGLContext();
if( pContext )
+ {
+#ifdef DBG_UTIL
+ pContext->DeRef(NULL);
+#else
pContext->DeRef();
+#endif
+ }
delete pSVData->mpDefaultWin;
pSVData->mpDefaultWin = NULL;
}
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index 32d2c28a2cd7..d2372494f970 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -103,6 +103,26 @@ OpenGLContext::~OpenGLContext()
pSVData->maGDIData.mpLastContext = mpPrevContext;
}
+#ifdef DBG_UTIL
+void OpenGLContext::AddRef(SalGraphicsImpl* pImpl)
+{
+ assert(mnRefCount > 0);
+ mnRefCount++;
+
+ maParents.insert(pImpl);
+}
+
+void OpenGLContext::DeRef(SalGraphicsImpl* pImpl)
+{
+ assert(mnRefCount > 0);
+ if( --mnRefCount == 0 )
+ delete this;
+
+ auto it = maParents.find(pImpl);
+ if(it != maParents.end())
+ maParents.erase(it);
+}
+#else
void OpenGLContext::AddRef()
{
assert(mnRefCount > 0);
@@ -115,6 +135,7 @@ void OpenGLContext::DeRef()
if( --mnRefCount == 0 )
delete this;
}
+#endif
void OpenGLContext::requestLegacyContext()
{