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

Side by Side Diff: src/gpu/GrAllocator.h

Issue 22850006: Replace uses of GrAssert by SkASSERT. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 4 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/GrAllocPool.cpp ('k') | src/gpu/GrAtlas.h » ('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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
(...skipping 17 matching lines...) Expand all
28 * @param itemsPerBlock the number of items to allocate at once 28 * @param itemsPerBlock the number of items to allocate at once
29 * @param initialBlock optional memory to use for the first block. 29 * @param initialBlock optional memory to use for the first block.
30 * Must be at least itemSize*itemsPerBlock sized. 30 * Must be at least itemSize*itemsPerBlock sized.
31 * Caller is responsible for freeing this memory. 31 * Caller is responsible for freeing this memory.
32 */ 32 */
33 GrAllocator(size_t itemSize, int itemsPerBlock, void* initialBlock) : 33 GrAllocator(size_t itemSize, int itemsPerBlock, void* initialBlock) :
34 fItemSize(itemSize), 34 fItemSize(itemSize),
35 fItemsPerBlock(itemsPerBlock), 35 fItemsPerBlock(itemsPerBlock),
36 fOwnFirstBlock(NULL == initialBlock), 36 fOwnFirstBlock(NULL == initialBlock),
37 fCount(0) { 37 fCount(0) {
38 GrAssert(itemsPerBlock > 0); 38 SkASSERT(itemsPerBlock > 0);
39 fBlockSize = fItemSize * fItemsPerBlock; 39 fBlockSize = fItemSize * fItemsPerBlock;
40 fBlocks.push_back() = initialBlock; 40 fBlocks.push_back() = initialBlock;
41 GR_DEBUGCODE(if (!fOwnFirstBlock) {*((char*)initialBlock+fBlockSize-1)=' a';} ); 41 GR_DEBUGCODE(if (!fOwnFirstBlock) {*((char*)initialBlock+fBlockSize-1)=' a';} );
42 } 42 }
43 43
44 /** 44 /**
45 * Adds an item and returns pointer to it. 45 * Adds an item and returns pointer to it.
46 * 46 *
47 * @return pointer to the added item. 47 * @return pointer to the added item.
48 */ 48 */
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 /** 89 /**
90 * is the count 0 90 * is the count 0
91 */ 91 */
92 bool empty() const { return fCount == 0; } 92 bool empty() const { return fCount == 0; }
93 93
94 /** 94 /**
95 * access last item, only call if count() != 0 95 * access last item, only call if count() != 0
96 */ 96 */
97 void* back() { 97 void* back() {
98 GrAssert(fCount); 98 SkASSERT(fCount);
99 return (*this)[fCount-1]; 99 return (*this)[fCount-1];
100 } 100 }
101 101
102 /** 102 /**
103 * access last item, only call if count() != 0 103 * access last item, only call if count() != 0
104 */ 104 */
105 const void* back() const { 105 const void* back() const {
106 GrAssert(fCount); 106 SkASSERT(fCount);
107 return (*this)[fCount-1]; 107 return (*this)[fCount-1];
108 } 108 }
109 109
110 /** 110 /**
111 * access item by index. 111 * access item by index.
112 */ 112 */
113 void* operator[] (int i) { 113 void* operator[] (int i) {
114 GrAssert(i >= 0 && i < fCount); 114 SkASSERT(i >= 0 && i < fCount);
115 return (char*)fBlocks[i / fItemsPerBlock] + 115 return (char*)fBlocks[i / fItemsPerBlock] +
116 fItemSize * (i % fItemsPerBlock); 116 fItemSize * (i % fItemsPerBlock);
117 } 117 }
118 118
119 /** 119 /**
120 * access item by index. 120 * access item by index.
121 */ 121 */
122 const void* operator[] (int i) const { 122 const void* operator[] (int i) const {
123 GrAssert(i >= 0 && i < fCount); 123 SkASSERT(i >= 0 && i < fCount);
124 return (const char*)fBlocks[i / fItemsPerBlock] + 124 return (const char*)fBlocks[i / fItemsPerBlock] +
125 fItemSize * (i % fItemsPerBlock); 125 fItemSize * (i % fItemsPerBlock);
126 } 126 }
127 127
128 private: 128 private:
129 static const int NUM_INIT_BLOCK_PTRS = 8; 129 static const int NUM_INIT_BLOCK_PTRS = 8;
130 130
131 SkSTArray<NUM_INIT_BLOCK_PTRS, void*> fBlocks; 131 SkSTArray<NUM_INIT_BLOCK_PTRS, void*> fBlocks;
132 size_t fBlockSize; 132 size_t fBlockSize;
133 size_t fItemSize; 133 size_t fItemSize;
(...skipping 21 matching lines...) Expand all
155 explicit GrTAllocator(int itemsPerBlock) 155 explicit GrTAllocator(int itemsPerBlock)
156 : fAllocator(sizeof(T), itemsPerBlock, NULL) {} 156 : fAllocator(sizeof(T), itemsPerBlock, NULL) {}
157 157
158 /** 158 /**
159 * Adds an item and returns it. 159 * Adds an item and returns it.
160 * 160 *
161 * @return the added item. 161 * @return the added item.
162 */ 162 */
163 T& push_back() { 163 T& push_back() {
164 void* item = fAllocator.push_back(); 164 void* item = fAllocator.push_back();
165 GrAssert(NULL != item); 165 SkASSERT(NULL != item);
166 SkNEW_PLACEMENT(item, T); 166 SkNEW_PLACEMENT(item, T);
167 return *(T*)item; 167 return *(T*)item;
168 } 168 }
169 169
170 T& push_back(const T& t) { 170 T& push_back(const T& t) {
171 void* item = fAllocator.push_back(); 171 void* item = fAllocator.push_back();
172 GrAssert(NULL != item); 172 SkASSERT(NULL != item);
173 SkNEW_PLACEMENT_ARGS(item, T, (t)); 173 SkNEW_PLACEMENT_ARGS(item, T, (t));
174 return *(T*)item; 174 return *(T*)item;
175 } 175 }
176 176
177 /** 177 /**
178 * removes all added items 178 * removes all added items
179 */ 179 */
180 void reset() { 180 void reset() {
181 int c = fAllocator.count(); 181 int c = fAllocator.count();
182 for (int i = 0; i < c; ++i) { 182 for (int i = 0; i < c; ++i) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 public: 242 public:
243 GrSTAllocator() : INHERITED(N, fStorage.get()) { 243 GrSTAllocator() : INHERITED(N, fStorage.get()) {
244 } 244 }
245 245
246 private: 246 private:
247 SkAlignedSTStorage<N, T> fStorage; 247 SkAlignedSTStorage<N, T> fStorage;
248 }; 248 };
249 249
250 #endif 250 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAllocPool.cpp ('k') | src/gpu/GrAtlas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698