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 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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*>(sk_malloc_throw(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; |
112 block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize; | 112 block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize; |
113 block->fPrevPtr = 0; // gcc warns on assigning NULL to an intptr_t. | 113 block->fPrevPtr = 0; // gcc warns on assigning NULL to an intptr_t. |
114 return block; | 114 return block; |
115 } | 115 } |
116 | 116 |
117 void GrMemoryPool::DeleteBlock(BlockHeader* block) { | 117 void GrMemoryPool::DeleteBlock(BlockHeader* block) { |
118 GrFree(block); | 118 sk_free(block); |
119 } | 119 } |
120 | 120 |
121 void GrMemoryPool::validate() { | 121 void GrMemoryPool::validate() { |
122 #ifdef SK_DEBUG | 122 #ifdef SK_DEBUG |
123 BlockHeader* block = fHead; | 123 BlockHeader* block = fHead; |
124 BlockHeader* prev = NULL; | 124 BlockHeader* prev = NULL; |
125 SkASSERT(block); | 125 SkASSERT(block); |
126 int allocCount = 0; | 126 int allocCount = 0; |
127 do { | 127 do { |
128 allocCount += block->fLiveCount; | 128 allocCount += block->fLiveCount; |
(...skipping 23 matching lines...) Expand all Loading... |
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 } |
OLD | NEW |