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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
317 if (fEnd == name + 1) { | 317 if (fEnd == name + 1) { |
318 --fEnd; | 318 --fEnd; |
319 return this->takeRef(); | 319 return this->takeRef(); |
320 } | 320 } |
321 | 321 |
322 SparseNameRange* left = SkNEW_ARGS(ContiguousNameRange, (fFirst, name)); | 322 SparseNameRange* left = new ContiguousNameRange(fFirst, name); |
323 SparseNameRange* right = this->takeRef(); | 323 SparseNameRange* right = this->takeRef(); |
324 fFirst = name + 1; | 324 fFirst = name + 1; |
325 return SkNEW_ARGS(SparseNameTree, (left, right)); | 325 return new SparseNameTree(left, right); |
326 } | 326 } |
327 }; | 327 }; |
328 | 328 |
329 GrGLNameAllocator::GrGLNameAllocator(GrGLuint firstName, GrGLuint endName) | 329 GrGLNameAllocator::GrGLNameAllocator(GrGLuint firstName, GrGLuint endName) |
330 : fFirstName(firstName), | 330 : fFirstName(firstName), |
331 fEndName(endName) { | 331 fEndName(endName) { |
332 SkASSERT(firstName > 0); | 332 SkASSERT(firstName > 0); |
333 SkASSERT(endName > firstName); | 333 SkASSERT(endName > firstName); |
334 } | 334 } |
335 | 335 |
336 GrGLNameAllocator::~GrGLNameAllocator() { | 336 GrGLNameAllocator::~GrGLNameAllocator() { |
337 } | 337 } |
338 | 338 |
339 GrGLuint GrGLNameAllocator::allocateName() { | 339 GrGLuint GrGLNameAllocator::allocateName() { |
340 if (NULL == fAllocatedNames.get()) { | 340 if (NULL == fAllocatedNames.get()) { |
341 fAllocatedNames.reset(SkNEW_ARGS(ContiguousNameRange, (fFirstName, fFirs
tName + 1))); | 341 fAllocatedNames.reset(new ContiguousNameRange(fFirstName, fFirstName + 1
)); |
342 return fFirstName; | 342 return fFirstName; |
343 } | 343 } |
344 | 344 |
345 if (fAllocatedNames->first() > fFirstName) { | 345 if (fAllocatedNames->first() > fFirstName) { |
346 return fAllocatedNames->prependNames(1); | 346 return fAllocatedNames->prependNames(1); |
347 } | 347 } |
348 | 348 |
349 GrGLuint name; | 349 GrGLuint name; |
350 fAllocatedNames.reset(fAllocatedNames->internalAllocate(&name)); | 350 fAllocatedNames.reset(fAllocatedNames->internalAllocate(&name)); |
351 if (0 != name) { | 351 if (0 != name) { |
352 return name; | 352 return name; |
353 } | 353 } |
354 | 354 |
355 if (fAllocatedNames->end() < fEndName) { | 355 if (fAllocatedNames->end() < fEndName) { |
356 return fAllocatedNames->appendNames(1); | 356 return fAllocatedNames->appendNames(1); |
357 } | 357 } |
358 | 358 |
359 // Out of names. | 359 // Out of names. |
360 return 0; | 360 return 0; |
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 |