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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 ++fBudgetedCount; | 140 ++fBudgetedCount; |
141 fBudgetedBytes += size; | 141 fBudgetedBytes += size; |
142 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget
", "used", | 142 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget
", "used", |
143 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); | 143 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); |
144 #if GR_CACHE_STATS | 144 #if GR_CACHE_STATS |
145 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount
); | 145 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount
); |
146 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes
); | 146 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes
); |
147 #endif | 147 #endif |
148 } | 148 } |
149 if (resource->resourcePriv().getScratchKey().isValid()) { | 149 if (resource->resourcePriv().getScratchKey().isValid()) { |
150 SkASSERT(!resource->cacheAccess().isExternal()); | 150 SkASSERT(!resource->resourcePriv().isExternal()); |
151 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); | 151 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); |
152 } | 152 } |
153 | 153 |
154 this->purgeAsNeeded(); | 154 this->purgeAsNeeded(); |
155 } | 155 } |
156 | 156 |
157 void GrResourceCache::removeResource(GrGpuResource* resource) { | 157 void GrResourceCache::removeResource(GrGpuResource* resource) { |
158 this->validate(); | 158 this->validate(); |
159 SkASSERT(this->isInCache(resource)); | 159 SkASSERT(this->isInCache(resource)); |
160 | 160 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->resourcePriv().isBudgeted()) { |
379 // Check whether this resource could still be used as a scratch resource
. | 379 // Check whether this resource could still be used as a scratch resource
. |
380 if (!resource->cacheAccess().isExternal() && | 380 if (!resource->resourcePriv().isExternal() && |
381 resource->resourcePriv().getScratchKey().isValid()) { | 381 resource->resourcePriv().getScratchKey().isValid()) { |
382 // We won't purge an existing resource to make room for this one. | 382 // We won't purge an existing resource to make room for this one. |
383 if (fBudgetedCount < fMaxCount && | 383 if (fBudgetedCount < fMaxCount && |
384 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { | 384 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { |
385 resource->resourcePriv().makeBudgeted(); | 385 resource->resourcePriv().makeBudgeted(); |
386 return; | 386 return; |
387 } | 387 } |
388 } | 388 } |
389 } else { | 389 } else { |
390 // Purge the resource immediately if we're over budget | 390 // Purge the resource immediately if we're over budget |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 fBytes += resource->gpuMemorySize(); | 655 fBytes += resource->gpuMemorySize(); |
656 | 656 |
657 if (!resource->isPurgeable()) { | 657 if (!resource->isPurgeable()) { |
658 ++fLocked; | 658 ++fLocked; |
659 } | 659 } |
660 | 660 |
661 if (resource->cacheAccess().isScratch()) { | 661 if (resource->cacheAccess().isScratch()) { |
662 SkASSERT(!resource->getUniqueKey().isValid()); | 662 SkASSERT(!resource->getUniqueKey().isValid()); |
663 ++fScratch; | 663 ++fScratch; |
664 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); | 664 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); |
665 SkASSERT(!resource->cacheAccess().isExternal()); | 665 SkASSERT(!resource->resourcePriv().isExternal()); |
666 } else if (resource->resourcePriv().getScratchKey().isValid()) { | 666 } else if (resource->resourcePriv().getScratchKey().isValid()) { |
667 SkASSERT(!resource->resourcePriv().isBudgeted() || | 667 SkASSERT(!resource->resourcePriv().isBudgeted() || |
668 resource->getUniqueKey().isValid()); | 668 resource->getUniqueKey().isValid()); |
669 ++fCouldBeScratch; | 669 ++fCouldBeScratch; |
670 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); | 670 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); |
671 SkASSERT(!resource->cacheAccess().isExternal()); | 671 SkASSERT(!resource->resourcePriv().isExternal()); |
672 } | 672 } |
673 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); | 673 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); |
674 if (uniqueKey.isValid()) { | 674 if (uniqueKey.isValid()) { |
675 ++fContent; | 675 ++fContent; |
676 SkASSERT(fUniqueHash->find(uniqueKey) == resource); | 676 SkASSERT(fUniqueHash->find(uniqueKey) == resource); |
677 SkASSERT(!resource->cacheAccess().isExternal()); | 677 SkASSERT(!resource->resourcePriv().isExternal()); |
678 SkASSERT(resource->resourcePriv().isBudgeted()); | 678 SkASSERT(resource->resourcePriv().isBudgeted()); |
679 } | 679 } |
680 | 680 |
681 if (resource->resourcePriv().isBudgeted()) { | 681 if (resource->resourcePriv().isBudgeted()) { |
682 ++fBudgetedCount; | 682 ++fBudgetedCount; |
683 fBudgetedBytes += resource->gpuMemorySize(); | 683 fBudgetedBytes += resource->gpuMemorySize(); |
684 } | 684 } |
685 } | 685 } |
686 }; | 686 }; |
687 | 687 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 return true; | 733 return true; |
734 } | 734 } |
735 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 735 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
736 return true; | 736 return true; |
737 } | 737 } |
738 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 738 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
739 return false; | 739 return false; |
740 } | 740 } |
741 | 741 |
742 #endif | 742 #endif |
OLD | NEW |