aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrMemoryPool.cpp
diff options
context:
space:
mode:
authorGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-24 21:36:16 +0000
committerGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-24 21:36:16 +0000
commitdcba4c2cc30cc64f08def991376c6dab65cfb51c (patch)
treef17229202c0086678dad57d94e00b5c94fa1ffeb /src/gpu/GrMemoryPool.cpp
parent6e502fe0677feaf960e4a37603da3bbeada38389 (diff)
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
Diffstat (limited to 'src/gpu/GrMemoryPool.cpp')
-rw-r--r--src/gpu/GrMemoryPool.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/gpu/GrMemoryPool.cpp b/src/gpu/GrMemoryPool.cpp
index 597f88cbb8..01f303fb69 100644
--- a/src/gpu/GrMemoryPool.cpp
+++ b/src/gpu/GrMemoryPool.cpp
@@ -57,6 +57,7 @@ void* GrMemoryPool::allocate(size_t size) {
// 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 @@ void GrMemoryPool::release(void* p) {
}
} 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 @@ GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) {
block->fLiveCount = 0;
block->fFreeSize = size;
block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize;
+ block->fPrevPtr = NULL;
return block;
}