Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: src/gpu/GrMemoryPool.cpp

Issue 23703010: Replace uses of GR_DEBUGCODE by SkDEBUGCODE. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrDrawState.cpp ('k') | src/gpu/gl/GrGLPath.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrMemoryPool.h" 8 #include "GrMemoryPool.h"
9 9
10 #ifdef SK_DEBUG 10 #ifdef SK_DEBUG
11 #define VALIDATE this->validate() 11 #define VALIDATE this->validate()
12 #else 12 #else
13 #define VALIDATE 13 #define VALIDATE
14 #endif 14 #endif
15 15
16 GrMemoryPool::GrMemoryPool(size_t preallocSize, size_t minAllocSize) { 16 GrMemoryPool::GrMemoryPool(size_t preallocSize, size_t minAllocSize) {
17 GR_DEBUGCODE(fAllocationCnt = 0); 17 SkDEBUGCODE(fAllocationCnt = 0);
18 18
19 minAllocSize = GrMax<size_t>(minAllocSize, 1 << 10); 19 minAllocSize = GrMax<size_t>(minAllocSize, 1 << 10);
20 fMinAllocSize = GrSizeAlignUp(minAllocSize + kPerAllocPad, kAlignment), 20 fMinAllocSize = GrSizeAlignUp(minAllocSize + kPerAllocPad, kAlignment),
21 fPreallocSize = GrSizeAlignUp(preallocSize + kPerAllocPad, kAlignment); 21 fPreallocSize = GrSizeAlignUp(preallocSize + kPerAllocPad, kAlignment);
22 fPreallocSize = GrMax(fPreallocSize, fMinAllocSize); 22 fPreallocSize = GrMax(fPreallocSize, fMinAllocSize);
23 23
24 fHead = CreateBlock(fPreallocSize); 24 fHead = CreateBlock(fPreallocSize);
25 fTail = fHead; 25 fTail = fHead;
26 fHead->fNext = NULL; 26 fHead->fNext = NULL;
27 fHead->fPrev = NULL; 27 fHead->fPrev = NULL;
(...skipping 26 matching lines...) Expand all
54 SkASSERT(fTail->fFreeSize >= size); 54 SkASSERT(fTail->fFreeSize >= size);
55 intptr_t ptr = fTail->fCurrPtr; 55 intptr_t ptr = fTail->fCurrPtr;
56 // We stash a pointer to the block header, just before the allocated space, 56 // We stash a pointer to the block header, just before the allocated space,
57 // so that we can decrement the live count on delete in constant time. 57 // so that we can decrement the live count on delete in constant time.
58 *reinterpret_cast<BlockHeader**>(ptr) = fTail; 58 *reinterpret_cast<BlockHeader**>(ptr) = fTail;
59 ptr += kPerAllocPad; 59 ptr += kPerAllocPad;
60 fTail->fPrevPtr = fTail->fCurrPtr; 60 fTail->fPrevPtr = fTail->fCurrPtr;
61 fTail->fCurrPtr += size; 61 fTail->fCurrPtr += size;
62 fTail->fFreeSize -= size; 62 fTail->fFreeSize -= size;
63 fTail->fLiveCount += 1; 63 fTail->fLiveCount += 1;
64 GR_DEBUGCODE(++fAllocationCnt); 64 SkDEBUGCODE(++fAllocationCnt);
65 VALIDATE; 65 VALIDATE;
66 return reinterpret_cast<void*>(ptr); 66 return reinterpret_cast<void*>(ptr);
67 } 67 }
68 68
69 void GrMemoryPool::release(void* p) { 69 void GrMemoryPool::release(void* p) {
70 VALIDATE; 70 VALIDATE;
71 intptr_t ptr = reinterpret_cast<intptr_t>(p) - kPerAllocPad; 71 intptr_t ptr = reinterpret_cast<intptr_t>(p) - kPerAllocPad;
72 BlockHeader* block = *reinterpret_cast<BlockHeader**>(ptr); 72 BlockHeader* block = *reinterpret_cast<BlockHeader**>(ptr);
73 if (1 == block->fLiveCount) { 73 if (1 == block->fLiveCount) {
74 // the head block is special, it is reset rather than deleted 74 // the head block is special, it is reset rather than deleted
(...skipping 16 matching lines...) Expand all
91 DeleteBlock(block); 91 DeleteBlock(block);
92 } 92 }
93 } else { 93 } else {
94 --block->fLiveCount; 94 --block->fLiveCount;
95 // Trivial reclaim: if we're releasing the most recent allocation, reuse it 95 // Trivial reclaim: if we're releasing the most recent allocation, reuse it
96 if (block->fPrevPtr == ptr) { 96 if (block->fPrevPtr == ptr) {
97 block->fFreeSize += (block->fCurrPtr - block->fPrevPtr); 97 block->fFreeSize += (block->fCurrPtr - block->fPrevPtr);
98 block->fCurrPtr = block->fPrevPtr; 98 block->fCurrPtr = block->fPrevPtr;
99 } 99 }
100 } 100 }
101 GR_DEBUGCODE(--fAllocationCnt); 101 SkDEBUGCODE(--fAllocationCnt);
102 VALIDATE; 102 VALIDATE;
103 } 103 }
104 104
105 GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) { 105 GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) {
106 BlockHeader* block = 106 BlockHeader* block =
107 reinterpret_cast<BlockHeader*>(GrMalloc(size + kHeaderSize)); 107 reinterpret_cast<BlockHeader*>(GrMalloc(size + kHeaderSize));
108 // we assume malloc gives us aligned memory 108 // we assume malloc gives us aligned memory
109 SkASSERT(!(reinterpret_cast<intptr_t>(block) % kAlignment)); 109 SkASSERT(!(reinterpret_cast<intptr_t>(block) % kAlignment));
110 block->fLiveCount = 0; 110 block->fLiveCount = 0;
111 block->fFreeSize = size; 111 block->fFreeSize = size;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 SkASSERT(userStart == block->fCurrPtr); 152 SkASSERT(userStart == block->fCurrPtr);
153 } else { 153 } else {
154 SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart)); 154 SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart));
155 } 155 }
156 prev = block; 156 prev = block;
157 } while ((block = block->fNext)); 157 } while ((block = block->fNext));
158 SkASSERT(allocCount == fAllocationCnt); 158 SkASSERT(allocCount == fAllocationCnt);
159 SkASSERT(prev == fTail); 159 SkASSERT(prev == fTail);
160 #endif 160 #endif
161 } 161 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.cpp ('k') | src/gpu/gl/GrGLPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698