diff options
author | 2012-07-31 19:23:02 +0000 | |
---|---|---|
committer | 2012-07-31 19:23:02 +0000 | |
commit | 622a17091b69df8d54d318c88f34851677a6d9c2 (patch) | |
tree | e9cf15c0b88a2b5959b31994bd968c138d41b9bb /src/gpu | |
parent | 641f8b19a6799b6d73ac17b9c2d2f8a5e6f5ad4d (diff) |
Fixed minor memory leaks
http://codereview.appspot.com/6453066/
git-svn-id: http://skia.googlecode.com/svn/trunk@4866 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/gl/debug/GrDebugGL.cpp | 7 | ||||
-rw-r--r-- | src/gpu/gl/debug/GrDebugGL.h | 25 | ||||
-rw-r--r-- | src/gpu/gl/debug/GrGLCreateDebugInterface.cpp | 5 |
3 files changed, 32 insertions, 5 deletions
diff --git a/src/gpu/gl/debug/GrDebugGL.cpp b/src/gpu/gl/debug/GrDebugGL.cpp index c4cfe896fc..657003967f 100644 --- a/src/gpu/gl/debug/GrDebugGL.cpp +++ b/src/gpu/gl/debug/GrDebugGL.cpp @@ -16,7 +16,8 @@ #include "GrTextureUnitObj.h" -GrDebugGL GrDebugGL::Obj; +GrDebugGL* GrDebugGL::gObj = NULL; +int GrDebugGL::gStaticRefCount = 0; GrDebugGL::Create GrDebugGL::gFactoryFunc[kObjTypeCount] = { GrTextureObj::createGrTextureObj, GrBufferObj::createGrBufferObj, @@ -40,7 +41,9 @@ GrDebugGL::GrDebugGL() , fTexture(NULL) { for (int i = 0; i < kDefaultMaxTextureUnits; ++i) { - fTextureUnits[i] = GR_CREATE(GrTextureUnitObj, GrDebugGL::kTextureUnit_ObjTypes); + + fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>( + createObj(GrDebugGL::kTextureUnit_ObjTypes)); fTextureUnits[i]->ref(); fTextureUnits[i]->setNumber(i); diff --git a/src/gpu/gl/debug/GrDebugGL.h b/src/gpu/gl/debug/GrDebugGL.h index 4e714ee258..d6697fd211 100644 --- a/src/gpu/gl/debug/GrDebugGL.h +++ b/src/gpu/gl/debug/GrDebugGL.h @@ -84,13 +84,31 @@ public: GrGLint getUnPackRowLength() const { return fUnPackRowLength; } static GrDebugGL *getInstance() { -// static GrDebugGL Obj; + // someone should admit to actually using this class + GrAssert(0 < gStaticRefCount); - return &Obj; + if (NULL == gObj) { + gObj = SkNEW(GrDebugGL); + } + + return gObj; } void report() const; + static void staticRef() { + gStaticRefCount++; + } + + static void staticUnRef() { + GrAssert(gStaticRefCount > 0); + gStaticRefCount--; + if (0 == gStaticRefCount) { + SkDELETE(gObj); + gObj = NULL; + } + } + protected: private: @@ -113,7 +131,8 @@ private: static Create gFactoryFunc[kObjTypeCount]; - static GrDebugGL Obj; + static GrDebugGL* gObj; + static int gStaticRefCount; // global store of all objects SkTArray<GrFakeRefObj *> fObjects; diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp index 22f32dcda1..3f58cc69da 100644 --- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp +++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp @@ -1280,6 +1280,11 @@ public: GrDebugGLInterface() : fWrapped(NULL) { + GrDebugGL::staticRef(); + } + + virtual ~GrDebugGLInterface() { + GrDebugGL::staticUnRef(); } void setWrapped(GrGLInterface *interface) { |