OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 #include "GrGLNameAllocator.h" | 9 #include "GrGLNameAllocator.h" |
10 | 10 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 class GrGLNameAllocator::SparseNameTree : public SparseNameRange { | 126 class GrGLNameAllocator::SparseNameTree : public SparseNameRange { |
127 public: | 127 public: |
128 SparseNameTree(SparseNameRange* left, SparseNameRange* right) | 128 SparseNameTree(SparseNameRange* left, SparseNameRange* right) |
129 : fLeft(left), | 129 : fLeft(left), |
130 fRight(right) { | 130 fRight(right) { |
131 SkASSERT(fLeft.get()); | 131 SkASSERT(fLeft.get()); |
132 SkASSERT(fRight.get()); | 132 SkASSERT(fRight.get()); |
133 this->updateStats(); | 133 this->updateStats(); |
134 } | 134 } |
135 | 135 |
136 SparseNameRange* SK_WARN_UNUSED_RESULT internalAllocate(GrGLuint* outName) S
K_OVERRIDE { | 136 SparseNameRange* SK_WARN_UNUSED_RESULT internalAllocate(GrGLuint* outName) o
verride { |
137 // Try allocating the range inside fLeft's internal gaps. | 137 // Try allocating the range inside fLeft's internal gaps. |
138 fLeft.reset(fLeft->internalAllocate(outName)); | 138 fLeft.reset(fLeft->internalAllocate(outName)); |
139 if (0 != *outName) { | 139 if (0 != *outName) { |
140 this->updateStats(); | 140 this->updateStats(); |
141 return this->rebalance(); | 141 return this->rebalance(); |
142 } | 142 } |
143 | 143 |
144 if (fLeft->end() + 1 == fRight->first()) { | 144 if (fLeft->end() + 1 == fRight->first()) { |
145 // It closed the gap between fLeft and fRight; merge. | 145 // It closed the gap between fLeft and fRight; merge. |
146 GrGLuint removedCount; | 146 GrGLuint removedCount; |
147 fRight.reset(fRight->removeLeftmostContiguousRange(&removedCount)); | 147 fRight.reset(fRight->removeLeftmostContiguousRange(&removedCount)); |
148 *outName = fLeft->appendNames(1 + removedCount); | 148 *outName = fLeft->appendNames(1 + removedCount); |
149 if (NULL == fRight.get()) { | 149 if (NULL == fRight.get()) { |
150 return fLeft.detach(); | 150 return fLeft.detach(); |
151 } | 151 } |
152 this->updateStats(); | 152 this->updateStats(); |
153 return this->rebalance(); | 153 return this->rebalance(); |
154 } | 154 } |
155 | 155 |
156 // There is guaranteed to be a gap between fLeft and fRight, and the | 156 // There is guaranteed to be a gap between fLeft and fRight, and the |
157 // "size 1" case has already been covered. | 157 // "size 1" case has already been covered. |
158 SkASSERT(fLeft->end() + 1 < fRight->first()); | 158 SkASSERT(fLeft->end() + 1 < fRight->first()); |
159 *outName = fLeft->appendNames(1); | 159 *outName = fLeft->appendNames(1); |
160 return this->takeRef(); | 160 return this->takeRef(); |
161 } | 161 } |
162 | 162 |
163 SparseNameRange* SK_WARN_UNUSED_RESULT removeLeftmostContiguousRange(GrGLuin
t* removedCount) SK_OVERRIDE { | 163 SparseNameRange* SK_WARN_UNUSED_RESULT removeLeftmostContiguousRange(GrGLuin
t* removedCount) override { |
164 fLeft.reset(fLeft->removeLeftmostContiguousRange(removedCount)); | 164 fLeft.reset(fLeft->removeLeftmostContiguousRange(removedCount)); |
165 if (NULL == fLeft) { | 165 if (NULL == fLeft) { |
166 return fRight.detach(); | 166 return fRight.detach(); |
167 } | 167 } |
168 this->updateStats(); | 168 this->updateStats(); |
169 return this->rebalance(); | 169 return this->rebalance(); |
170 } | 170 } |
171 | 171 |
172 GrGLuint appendNames(GrGLuint count) SK_OVERRIDE { | 172 GrGLuint appendNames(GrGLuint count) override { |
173 SkASSERT(fEnd + count > fEnd); // Check for integer wrap. | 173 SkASSERT(fEnd + count > fEnd); // Check for integer wrap. |
174 GrGLuint name = fRight->appendNames(count); | 174 GrGLuint name = fRight->appendNames(count); |
175 SkASSERT(fRight->end() == fEnd + count); | 175 SkASSERT(fRight->end() == fEnd + count); |
176 this->updateStats(); | 176 this->updateStats(); |
177 return name; | 177 return name; |
178 } | 178 } |
179 | 179 |
180 GrGLuint prependNames(GrGLuint count) SK_OVERRIDE { | 180 GrGLuint prependNames(GrGLuint count) override { |
181 SkASSERT(fFirst > count); // We can't allocate at or below 0. | 181 SkASSERT(fFirst > count); // We can't allocate at or below 0. |
182 GrGLuint name = fLeft->prependNames(count); | 182 GrGLuint name = fLeft->prependNames(count); |
183 SkASSERT(fLeft->first() == fFirst - count); | 183 SkASSERT(fLeft->first() == fFirst - count); |
184 this->updateStats(); | 184 this->updateStats(); |
185 return name; | 185 return name; |
186 } | 186 } |
187 | 187 |
188 SparseNameRange* SK_WARN_UNUSED_RESULT free(GrGLuint name) SK_OVERRIDE { | 188 SparseNameRange* SK_WARN_UNUSED_RESULT free(GrGLuint name) override { |
189 if (name < fLeft->end()) { | 189 if (name < fLeft->end()) { |
190 fLeft.reset(fLeft->free(name)); | 190 fLeft.reset(fLeft->free(name)); |
191 if (NULL == fLeft) { | 191 if (NULL == fLeft) { |
192 // fLeft became empty after the free. | 192 // fLeft became empty after the free. |
193 return fRight.detach(); | 193 return fRight.detach(); |
194 } | 194 } |
195 this->updateStats(); | 195 this->updateStats(); |
196 return this->rebalance(); | 196 return this->rebalance(); |
197 } else { | 197 } else { |
198 fRight.reset(fRight->free(name)); | 198 fRight.reset(fRight->free(name)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 */ | 273 */ |
274 class GrGLNameAllocator::ContiguousNameRange : public SparseNameRange { | 274 class GrGLNameAllocator::ContiguousNameRange : public SparseNameRange { |
275 public: | 275 public: |
276 ContiguousNameRange(GrGLuint first, GrGLuint end) { | 276 ContiguousNameRange(GrGLuint first, GrGLuint end) { |
277 SkASSERT(first < end); | 277 SkASSERT(first < end); |
278 fFirst = first; | 278 fFirst = first; |
279 fEnd = end; | 279 fEnd = end; |
280 fHeight = 0; | 280 fHeight = 0; |
281 } | 281 } |
282 | 282 |
283 SparseNameRange* SK_WARN_UNUSED_RESULT internalAllocate(GrGLuint* outName) S
K_OVERRIDE { | 283 SparseNameRange* SK_WARN_UNUSED_RESULT internalAllocate(GrGLuint* outName) o
verride { |
284 *outName = 0; // No internal gaps, we are contiguous. | 284 *outName = 0; // No internal gaps, we are contiguous. |
285 return this->takeRef(); | 285 return this->takeRef(); |
286 } | 286 } |
287 | 287 |
288 SparseNameRange* SK_WARN_UNUSED_RESULT removeLeftmostContiguousRange(GrGLuin
t* removedCount) SK_OVERRIDE { | 288 SparseNameRange* SK_WARN_UNUSED_RESULT removeLeftmostContiguousRange(GrGLuin
t* removedCount) override { |
289 *removedCount = fEnd - fFirst; | 289 *removedCount = fEnd - fFirst; |
290 return NULL; | 290 return NULL; |
291 } | 291 } |
292 | 292 |
293 GrGLuint appendNames(GrGLuint count) SK_OVERRIDE { | 293 GrGLuint appendNames(GrGLuint count) override { |
294 SkASSERT(fEnd + count > fEnd); // Check for integer wrap. | 294 SkASSERT(fEnd + count > fEnd); // Check for integer wrap. |
295 GrGLuint name = fEnd; | 295 GrGLuint name = fEnd; |
296 fEnd += count; | 296 fEnd += count; |
297 return name; | 297 return name; |
298 } | 298 } |
299 | 299 |
300 GrGLuint prependNames(GrGLuint count) SK_OVERRIDE { | 300 GrGLuint prependNames(GrGLuint count) override { |
301 SkASSERT(fFirst > count); // We can't allocate at or below 0. | 301 SkASSERT(fFirst > count); // We can't allocate at or below 0. |
302 fFirst -= count; | 302 fFirst -= count; |
303 return fFirst; | 303 return fFirst; |
304 } | 304 } |
305 | 305 |
306 SparseNameRange* SK_WARN_UNUSED_RESULT free(GrGLuint name) SK_OVERRIDE { | 306 SparseNameRange* SK_WARN_UNUSED_RESULT free(GrGLuint name) override { |
307 if (name < fFirst || name >= fEnd) { | 307 if (name < fFirst || name >= fEnd) { |
308 // Not-allocated names are silently ignored. | 308 // Not-allocated names are silently ignored. |
309 return this->takeRef(); | 309 return this->takeRef(); |
310 } | 310 } |
311 | 311 |
312 if (fFirst == name) { | 312 if (fFirst == name) { |
313 ++fFirst; | 313 ++fFirst; |
314 return (fEnd == fFirst) ? NULL : this->takeRef(); | 314 return (fEnd == fFirst) ? NULL : this->takeRef(); |
315 } | 315 } |
316 | 316 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 361 } |
362 | 362 |
363 void GrGLNameAllocator::free(GrGLuint name) { | 363 void GrGLNameAllocator::free(GrGLuint name) { |
364 if (!fAllocatedNames.get()) { | 364 if (!fAllocatedNames.get()) { |
365 // Not-allocated names are silently ignored. | 365 // Not-allocated names are silently ignored. |
366 return; | 366 return; |
367 } | 367 } |
368 | 368 |
369 fAllocatedNames.reset(fAllocatedNames->free(name)); | 369 fAllocatedNames.reset(fAllocatedNames->free(name)); |
370 } | 370 } |
OLD | NEW |