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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 ++fBudgetedCount; | 139 ++fBudgetedCount; |
140 fBudgetedBytes += size; | 140 fBudgetedBytes += size; |
141 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget
", "used", | 141 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget
", "used", |
142 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); | 142 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); |
143 #if GR_CACHE_STATS | 143 #if GR_CACHE_STATS |
144 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount
); | 144 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount
); |
145 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes
); | 145 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes
); |
146 #endif | 146 #endif |
147 } | 147 } |
148 if (resource->resourcePriv().getScratchKey().isValid()) { | 148 if (resource->resourcePriv().getScratchKey().isValid()) { |
149 SkASSERT(!resource->cacheAccess().isWrapped()); | 149 SkASSERT(!resource->cacheAccess().isExternal()); |
150 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); | 150 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); |
151 } | 151 } |
152 | 152 |
153 this->purgeAsNeeded(); | 153 this->purgeAsNeeded(); |
154 } | 154 } |
155 | 155 |
156 void GrResourceCache::removeResource(GrGpuResource* resource) { | 156 void GrResourceCache::removeResource(GrGpuResource* resource) { |
157 this->validate(); | 157 this->validate(); |
158 SkASSERT(this->isInCache(resource)); | 158 SkASSERT(this->isInCache(resource)); |
159 | 159 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 SkASSERT(!resource->isPurgeable()); | 362 SkASSERT(!resource->isPurgeable()); |
363 return; | 363 return; |
364 } | 364 } |
365 | 365 |
366 SkASSERT(resource->isPurgeable()); | 366 SkASSERT(resource->isPurgeable()); |
367 this->removeFromNonpurgeableArray(resource); | 367 this->removeFromNonpurgeableArray(resource); |
368 fPurgeableQueue.insert(resource); | 368 fPurgeableQueue.insert(resource); |
369 | 369 |
370 if (!resource->resourcePriv().isBudgeted()) { | 370 if (!resource->resourcePriv().isBudgeted()) { |
371 // Check whether this resource could still be used as a scratch resource
. | 371 // Check whether this resource could still be used as a scratch resource
. |
372 if (!resource->cacheAccess().isWrapped() && | 372 if (!resource->cacheAccess().isExternal() && |
373 resource->resourcePriv().getScratchKey().isValid()) { | 373 resource->resourcePriv().getScratchKey().isValid()) { |
374 // We won't purge an existing resource to make room for this one. | 374 // We won't purge an existing resource to make room for this one. |
375 if (fBudgetedCount < fMaxCount && | 375 if (fBudgetedCount < fMaxCount && |
376 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { | 376 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { |
377 resource->resourcePriv().makeBudgeted(); | 377 resource->resourcePriv().makeBudgeted(); |
378 return; | 378 return; |
379 } | 379 } |
380 } | 380 } |
381 } else { | 381 } else { |
382 // Purge the resource immediately if we're over budget | 382 // Purge the resource immediately if we're over budget |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 fBytes += resource->gpuMemorySize(); | 638 fBytes += resource->gpuMemorySize(); |
639 | 639 |
640 if (!resource->isPurgeable()) { | 640 if (!resource->isPurgeable()) { |
641 ++fLocked; | 641 ++fLocked; |
642 } | 642 } |
643 | 643 |
644 if (resource->cacheAccess().isScratch()) { | 644 if (resource->cacheAccess().isScratch()) { |
645 SkASSERT(!resource->getUniqueKey().isValid()); | 645 SkASSERT(!resource->getUniqueKey().isValid()); |
646 ++fScratch; | 646 ++fScratch; |
647 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); | 647 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); |
648 SkASSERT(!resource->cacheAccess().isWrapped()); | 648 SkASSERT(!resource->cacheAccess().isExternal()); |
649 } else if (resource->resourcePriv().getScratchKey().isValid()) { | 649 } else if (resource->resourcePriv().getScratchKey().isValid()) { |
650 SkASSERT(!resource->resourcePriv().isBudgeted() || | 650 SkASSERT(!resource->resourcePriv().isBudgeted() || |
651 resource->getUniqueKey().isValid()); | 651 resource->getUniqueKey().isValid()); |
652 ++fCouldBeScratch; | 652 ++fCouldBeScratch; |
653 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); | 653 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc
ratchKey())); |
654 SkASSERT(!resource->cacheAccess().isWrapped()); | 654 SkASSERT(!resource->cacheAccess().isExternal()); |
655 } | 655 } |
656 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); | 656 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); |
657 if (uniqueKey.isValid()) { | 657 if (uniqueKey.isValid()) { |
658 ++fContent; | 658 ++fContent; |
659 SkASSERT(fUniqueHash->find(uniqueKey) == resource); | 659 SkASSERT(fUniqueHash->find(uniqueKey) == resource); |
660 SkASSERT(!resource->cacheAccess().isWrapped()); | 660 SkASSERT(!resource->cacheAccess().isExternal()); |
661 SkASSERT(resource->resourcePriv().isBudgeted()); | 661 SkASSERT(resource->resourcePriv().isBudgeted()); |
662 } | 662 } |
663 | 663 |
664 if (resource->resourcePriv().isBudgeted()) { | 664 if (resource->resourcePriv().isBudgeted()) { |
665 ++fBudgetedCount; | 665 ++fBudgetedCount; |
666 fBudgetedBytes += resource->gpuMemorySize(); | 666 fBudgetedBytes += resource->gpuMemorySize(); |
667 } | 667 } |
668 } | 668 } |
669 }; | 669 }; |
670 | 670 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 return true; | 716 return true; |
717 } | 717 } |
718 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 718 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
719 return true; | 719 return true; |
720 } | 720 } |
721 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 721 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
722 return false; | 722 return false; |
723 } | 723 } |
724 | 724 |
725 #endif | 725 #endif |
OLD | NEW |