Fix for GrTextureStripAtlas memory leak
https://codereview.appspot.com/6549050/
git-svn-id: http://skia.googlecode.com/svn/trunk@5648 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/effects/GrTextureStripAtlas.h b/src/gpu/effects/GrTextureStripAtlas.h
index 1a4c371..a6833e0 100644
--- a/src/gpu/effects/GrTextureStripAtlas.h
+++ b/src/gpu/effects/GrTextureStripAtlas.h
@@ -13,6 +13,7 @@
#include "GrTHashCache.h"
#include "SkGr.h"
#include "SkTDArray.h"
+#include "GrBinHashKey.h"
/**
* Maintains a single large texture whose rows store many textures of a small fixed height,
@@ -129,6 +130,28 @@
void validate();
#endif
+ /**
+ * Clean up callback registered with GrContext. Allows this class to
+ * free up any allocated AtlasEntry and GrTextureStripAtlas objects
+ */
+ static void CleanUp(const GrContext* context, void* info);
+
+ // Hash table entry for atlases
+ class AtlasEntry;
+ typedef GrTBinHashKey<AtlasEntry, sizeof(GrTextureStripAtlas::Desc)> AtlasHashKey;
+ class AtlasEntry : public ::GrNoncopyable {
+ public:
+ AtlasEntry() : fAtlas(NULL) {}
+ ~AtlasEntry() { SkDELETE(fAtlas); }
+ int compare(const AtlasHashKey& key) const { return fKey.compare(key); }
+ AtlasHashKey fKey;
+ GrTextureStripAtlas* fAtlas;
+ };
+
+ static GrTHashTable<AtlasEntry, AtlasHashKey, 8>* gAtlasCache;
+
+ static GrTHashTable<AtlasEntry, AtlasHashKey, 8>* GetCache();
+
// We increment gCacheCount for each atlas
static int32_t gCacheCount;