OLD | NEW |
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 SkDEBUGCODE(fAllocationCnt = 0); | 17 SkDEBUGCODE(fAllocationCnt = 0); |
18 SkDEBUGCODE(fAllocBlockCnt = 0); | 18 SkDEBUGCODE(fAllocBlockCnt = 0); |
19 | 19 |
20 minAllocSize = SkTMax<size_t>(minAllocSize, 1 << 10); | 20 minAllocSize = SkTMax<size_t>(minAllocSize, 1 << 10); |
21 fMinAllocSize = GrSizeAlignUp(minAllocSize + kPerAllocPad, kAlignment), | 21 fMinAllocSize = GrSizeAlignUp(minAllocSize + kPerAllocPad, kAlignment), |
22 fPreallocSize = GrSizeAlignUp(preallocSize + kPerAllocPad, kAlignment); | 22 fPreallocSize = GrSizeAlignUp(preallocSize + kPerAllocPad, kAlignment); |
23 fPreallocSize = SkTMax(fPreallocSize, fMinAllocSize); | 23 fPreallocSize = SkTMax(fPreallocSize, fMinAllocSize); |
24 fSize = fPreallocSize; | 24 fSize = 0; |
25 | 25 |
26 fHead = CreateBlock(fPreallocSize); | 26 fHead = CreateBlock(fPreallocSize); |
27 fTail = fHead; | 27 fTail = fHead; |
28 fHead->fNext = nullptr; | 28 fHead->fNext = nullptr; |
29 fHead->fPrev = nullptr; | 29 fHead->fPrev = nullptr; |
30 VALIDATE; | 30 VALIDATE; |
31 }; | 31 }; |
32 | 32 |
33 GrMemoryPool::~GrMemoryPool() { | 33 GrMemoryPool::~GrMemoryPool() { |
34 VALIDATE; | 34 VALIDATE; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (!block->fLiveCount) { | 158 if (!block->fLiveCount) { |
159 SkASSERT(ptrOffset == kHeaderSize); | 159 SkASSERT(ptrOffset == kHeaderSize); |
160 SkASSERT(userStart == block->fCurrPtr); | 160 SkASSERT(userStart == block->fCurrPtr); |
161 } else { | 161 } else { |
162 SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart)); | 162 SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart)); |
163 } | 163 } |
164 prev = block; | 164 prev = block; |
165 } while ((block = block->fNext)); | 165 } while ((block = block->fNext)); |
166 SkASSERT(allocCount == fAllocationCnt); | 166 SkASSERT(allocCount == fAllocationCnt); |
167 SkASSERT(prev == fTail); | 167 SkASSERT(prev == fTail); |
168 SkASSERT(fAllocBlockCnt != 0 || fSize == fPreallocSize); | 168 SkASSERT(fAllocBlockCnt != 0 || fSize == 0); |
169 #endif | 169 #endif |
170 } | 170 } |
OLD | NEW |