Use GrMemoryPool to manage GrCustomStage allocations.
Improve memory reclamation of GrMemoryPool for new/delete/new/delete pattern.
http://codereview.appspot.com/6438046/
git-svn-id: http://skia.googlecode.com/svn/trunk@4744 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrCustomStage.cpp b/src/gpu/GrCustomStage.cpp
index 66b78a6..43de5ae 100644
--- a/src/gpu/GrCustomStage.cpp
+++ b/src/gpu/GrCustomStage.cpp
@@ -7,9 +7,27 @@
#include "GrContext.h"
#include "GrCustomStage.h"
+#include "GrMemoryPool.h"
+#include "SkTLS.h"
SK_DEFINE_INST_COUNT(GrCustomStage)
+class GrCustomStage_Globals {
+public:
+ static GrMemoryPool* GetTLS() {
+ return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
+ }
+
+private:
+ static void* CreateTLS() {
+ return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
+ }
+
+ static void DeleteTLS(void* pool) {
+ SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
+ }
+};
+
int32_t GrProgramStageFactory::fCurrStageClassID =
GrProgramStageFactory::kIllegalStageClassID;
@@ -45,3 +63,11 @@
return NULL;
}
+void * GrCustomStage::operator new(size_t size) {
+ return GrCustomStage_Globals::GetTLS()->allocate(size);
+}
+
+void GrCustomStage::operator delete(void* target) {
+ GrCustomStage_Globals::GetTLS()->release(target);
+}
+