summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2015-01-20 04:12:18 +0100
committerMichael Meeks <michael.meeks@collabora.com>2015-01-28 14:13:15 +0000
commitd2819f2f47f8a98e0ee58242d9a2b54fca383add (patch)
treee4ac8e026c730787d940a9cf963c7becc19fb65b
parente471f3861bda5575742eac3f1d9747108e5e8e7a (diff)
some debug code for finding leaked OpenGLContexts
Change-Id: I10e8c344ae6aa2e0a4ef562154f57e2070c70e2f Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
-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 7d721233582f..717502309fd9 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
@@ -212,8 +215,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();
@@ -283,6 +291,9 @@ private:
boost::unordered_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 13bfca963b87..519837589cdd 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -78,7 +78,11 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
{
if( mpContext->isInitialized() )
return true;
+#ifdef DBG_UTIL
+ mpContext->DeRef(this);
+#else
mpContext->DeRef();
+#endif
}
@@ -92,7 +96,13 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
}
if( pContext )
+ {
+#ifdef DBG_UTIL
+ pContext->AddRef(this);
+#else
pContext->AddRef();
+#endif
+ }
else
pContext = mbOffscreen ? GetDefaultContext() : CreateWinContext();
@@ -103,7 +113,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 1485305166ee..d8934d9d9c0b 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -139,7 +139,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 2fc122c35d56..90bca1f7cb1c 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -453,7 +453,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 5cccd73bc78a..6c085fb5646e 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()
{