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 | 9 |
10 #include "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 368 |
369 if (!SkToBool(ResourceAccess::kAllCntsReachedZero_RefNotificationFlag & flag
s)) { | 369 if (!SkToBool(ResourceAccess::kAllCntsReachedZero_RefNotificationFlag & flag
s)) { |
370 SkASSERT(!resource->isPurgeable()); | 370 SkASSERT(!resource->isPurgeable()); |
371 return; | 371 return; |
372 } | 372 } |
373 | 373 |
374 SkASSERT(resource->isPurgeable()); | 374 SkASSERT(resource->isPurgeable()); |
375 this->removeFromNonpurgeableArray(resource); | 375 this->removeFromNonpurgeableArray(resource); |
376 fPurgeableQueue.insert(resource); | 376 fPurgeableQueue.insert(resource); |
377 | 377 |
378 if (!resource->resourcePriv().isBudgeted()) { | 378 if (resource->reuseable()) { |
379 // Check whether this resource could still be used as a scratch resource
. | 379 if (!resource->resourcePriv().isBudgeted()) { |
380 if (!resource->cacheAccess().isExternal() && | 380 // Check whether this resource could still be used as a scratch reso
urce. |
381 resource->resourcePriv().getScratchKey().isValid()) { | 381 if (!resource->cacheAccess().isExternal() && |
382 // We won't purge an existing resource to make room for this one. | 382 resource->resourcePriv().getScratchKey().isValid()) { |
383 if (fBudgetedCount < fMaxCount && | 383 // We won't purge an existing resource to make room for this one
. |
384 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { | 384 if (fBudgetedCount < fMaxCount && |
385 resource->resourcePriv().makeBudgeted(); | 385 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { |
| 386 resource->resourcePriv().makeBudgeted(); |
| 387 return; |
| 388 } |
| 389 } |
| 390 } else { |
| 391 // Purge the resource immediately if we're over budget |
| 392 // Also purge if the resource has neither a valid scratch key nor a
unique key. |
| 393 bool noKey = !resource->resourcePriv().getScratchKey().isValid() && |
| 394 !resource->getUniqueKey().isValid(); |
| 395 if (!this->overBudget() && !noKey) { |
386 return; | 396 return; |
387 } | 397 } |
388 } | 398 } |
389 } else { | |
390 // Purge the resource immediately if we're over budget | |
391 // Also purge if the resource has neither a valid scratch key nor a uniq
ue key. | |
392 bool noKey = !resource->resourcePriv().getScratchKey().isValid() && | |
393 !resource->getUniqueKey().isValid(); | |
394 if (!this->overBudget() && !noKey) { | |
395 return; | |
396 } | |
397 } | 399 } |
398 | 400 |
399 SkDEBUGCODE(int beforeCount = this->getResourceCount();) | 401 SkDEBUGCODE(int beforeCount = this->getResourceCount();) |
400 resource->cacheAccess().release(); | 402 resource->cacheAccess().release(); |
401 // We should at least free this resource, perhaps dependent resources as wel
l. | 403 // We should at least free this resource, perhaps dependent resources as wel
l. |
402 SkASSERT(this->getResourceCount() < beforeCount); | 404 SkASSERT(this->getResourceCount() < beforeCount); |
403 this->validate(); | 405 this->validate(); |
404 } | 406 } |
405 | 407 |
406 void GrResourceCache::didChangeGpuMemorySize(const GrGpuResource* resource, size
_t oldSize) { | 408 void GrResourceCache::didChangeGpuMemorySize(const GrGpuResource* resource, size
_t oldSize) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 return true; | 735 return true; |
734 } | 736 } |
735 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 737 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
736 return true; | 738 return true; |
737 } | 739 } |
738 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 740 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
739 return false; | 741 return false; |
740 } | 742 } |
741 | 743 |
742 #endif | 744 #endif |
OLD | NEW |