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/GrMemoryPool.cpp b/src/gpu/GrMemoryPool.cpp
index 597f88c..01f303f 100644
--- a/src/gpu/GrMemoryPool.cpp
+++ b/src/gpu/GrMemoryPool.cpp
@@ -57,6 +57,7 @@
     // so that we can decrement the live count on delete in constant time.
     *reinterpret_cast<BlockHeader**>(ptr) = fTail;
     ptr += kPerAllocPad;
+    fTail->fPrevPtr = fTail->fCurrPtr;
     fTail->fCurrPtr += size;
     fTail->fFreeSize -= size;
     fTail->fLiveCount += 1;
@@ -91,6 +92,11 @@
         }
     } else {
         --block->fLiveCount;
+        // Trivial reclaim: if we're releasing the most recent allocation, reuse it
+        if (block->fPrevPtr == ptr) {
+            block->fFreeSize += (block->fCurrPtr - block->fPrevPtr);
+            block->fCurrPtr = block->fPrevPtr;
+        }
     }
     GR_DEBUGCODE(--fAllocationCnt);
     VALIDATE;
@@ -104,6 +110,7 @@
     block->fLiveCount = 0;
     block->fFreeSize = size;
     block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize;
+    block->fPrevPtr = NULL;
     return block;
 }