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

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

Issue 742253002: remove GrAllocPool (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to use SkVarAlloc Created 6 years 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
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
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SkDEBUGCODE(--fAllocationCnt); 101 SkDEBUGCODE(--fAllocationCnt);
102 VALIDATE; 102 VALIDATE;
103 } 103 }
104 104
105 void GrMemoryPool::releaseAll() {
106 VALIDATE;
107 while (fTail->fPrev) {
108 BlockHeader* prev = fTail->fPrev;
109 SkDEBUGCODE(fAllocationCnt -= fTail->fLiveCount);
110 DeleteBlock(fTail);
111 fTail = prev;
112 fTail->fNext = NULL;
113 }
114 // now 'free' head block
115 SkDEBUGCODE(fAllocationCnt -= fHead->fLiveCount);
116 fHead->fCurrPtr = reinterpret_cast<intptr_t>(fHead) +
117 kHeaderSize;
118 fHead->fLiveCount = 0;
119 fHead->fFreeSize = fPreallocSize;
120 SkASSERT(0 == fAllocationCnt);
121 SkASSERT(fHead == fTail);
122 SkASSERT(0 == fHead->fLiveCount);
123 VALIDATE;
124 }
125
105 GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) { 126 GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) {
106 BlockHeader* block = 127 BlockHeader* block =
107 reinterpret_cast<BlockHeader*>(sk_malloc_throw(size + kHeaderSize)); 128 reinterpret_cast<BlockHeader*>(sk_malloc_throw(size + kHeaderSize));
108 // we assume malloc gives us aligned memory 129 // we assume malloc gives us aligned memory
109 SkASSERT(!(reinterpret_cast<intptr_t>(block) % kAlignment)); 130 SkASSERT(!(reinterpret_cast<intptr_t>(block) % kAlignment));
110 block->fLiveCount = 0; 131 block->fLiveCount = 0;
111 block->fFreeSize = size; 132 block->fFreeSize = size;
112 block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize; 133 block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize;
113 block->fPrevPtr = 0; // gcc warns on assigning NULL to an intptr_t. 134 block->fPrevPtr = 0; // gcc warns on assigning NULL to an intptr_t.
114 return block; 135 return block;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 SkASSERT(userStart == block->fCurrPtr); 173 SkASSERT(userStart == block->fCurrPtr);
153 } else { 174 } else {
154 SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart)); 175 SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart));
155 } 176 }
156 prev = block; 177 prev = block;
157 } while ((block = block->fNext)); 178 } while ((block = block->fNext));
158 SkASSERT(allocCount == fAllocationCnt); 179 SkASSERT(allocCount == fAllocationCnt);
159 SkASSERT(prev == fTail); 180 SkASSERT(prev == fTail);
160 #endif 181 #endif
161 } 182 }
OLDNEW
« no previous file with comments | « src/gpu/GrMemoryPool.h ('k') | src/gpu/GrTextStrike.h » ('j') | src/gpu/GrTextStrike.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698