From aefd2bc75738963b9b6579897be32bfbc8fb00af Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Mon, 30 Mar 2009 21:02:14 +0000 Subject: Add SkChunkAlloc::unalloc() to undo the last allocation, useful if the caller wants to treat the allocats like temp memory (see PictureRecord) Call unalloc if a paint (or other cached object) is already in our list for picture recording Use correct CompareType macro in SkCanvas::quickReject git-svn-id: http://skia.googlecode.com/svn/trunk@138 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkChunkAlloc.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/core/SkChunkAlloc.cpp') diff --git a/src/core/SkChunkAlloc.cpp b/src/core/SkChunkAlloc.cpp index ae37ec0839..83272c58eb 100644 --- a/src/core/SkChunkAlloc.cpp +++ b/src/core/SkChunkAlloc.cpp @@ -23,6 +23,10 @@ struct SkChunkAlloc::Block { char* fFreePtr; // data[] follows + char* startOfData() { + return reinterpret_cast(this + 1); + } + void freeChain() { // this can be null Block* block = this; while (block) { @@ -89,7 +93,7 @@ SkChunkAlloc::Block* SkChunkAlloc::newBlock(size_t bytes, AllocFailType ftype) { if (block) { // block->fNext = fBlock; block->fFreeSize = size; - block->fFreePtr = (char*)block + sizeof(Block); + block->fFreePtr = block->startOfData(); fTotalCapacity += size; } @@ -118,3 +122,18 @@ void* SkChunkAlloc::alloc(size_t bytes, AllocFailType ftype) { return ptr; } +size_t SkChunkAlloc::unalloc(void* ptr) { + size_t bytes = 0; + Block* block = fBlock; + if (block) { + char* cPtr = reinterpret_cast(ptr); + char* start = block->startOfData(); + if (start <= cPtr && cPtr < block->fFreePtr) { + bytes = block->fFreePtr - cPtr; + block->fFreeSize += bytes; + block->fFreePtr = cPtr; + } + } + return bytes; +} + -- cgit v1.2.3