Chromium Code Reviews| 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" |
| 11 #include "GrGpuResourceCacheAccess.h" | 11 #include "GrGpuResourceCacheAccess.h" |
| 12 #include "GrTracing.h" | |
| 12 #include "SkChecksum.h" | 13 #include "SkChecksum.h" |
| 13 #include "SkGr.h" | 14 #include "SkGr.h" |
| 14 #include "SkMessageBus.h" | 15 #include "SkMessageBus.h" |
| 15 #include "SkTSort.h" | 16 #include "SkTSort.h" |
| 16 | 17 |
| 17 DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage); | 18 DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage); |
| 18 | 19 |
| 19 ////////////////////////////////////////////////////////////////////////////// | 20 ////////////////////////////////////////////////////////////////////////////// |
| 20 | 21 |
| 21 GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() { | 22 GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 95 |
| 95 // We must set the timestamp before adding to the array in case the timestam p wraps and we wind | 96 // We must set the timestamp before adding to the array in case the timestam p wraps and we wind |
| 96 // up iterating over all the resources that already have timestamps. | 97 // up iterating over all the resources that already have timestamps. |
| 97 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); | 98 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); |
| 98 | 99 |
| 99 this->addToNonpurgeableArray(resource); | 100 this->addToNonpurgeableArray(resource); |
| 100 | 101 |
| 101 size_t size = resource->gpuMemorySize(); | 102 size_t size = resource->gpuMemorySize(); |
| 102 SkDEBUGCODE(++fCount;) | 103 SkDEBUGCODE(++fCount;) |
| 103 fBytes += size; | 104 fBytes += size; |
| 105 | |
| 106 // TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "fBytes", fByt es); | |
|
bsalomon
2015/03/04 18:08:27
what's with this?
| |
| 107 | |
| 104 #if GR_CACHE_STATS | 108 #if GR_CACHE_STATS |
| 105 fHighWaterCount = SkTMax(this->getResourceCount(), fHighWaterCount); | 109 fHighWaterCount = SkTMax(this->getResourceCount(), fHighWaterCount); |
| 106 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); | 110 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); |
| 107 #endif | 111 #endif |
| 108 if (resource->resourcePriv().isBudgeted()) { | 112 if (resource->resourcePriv().isBudgeted()) { |
| 109 ++fBudgetedCount; | 113 ++fBudgetedCount; |
| 110 fBudgetedBytes += size; | 114 fBudgetedBytes += size; |
| 115 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used", | |
| 116 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); | |
| 111 #if GR_CACHE_STATS | 117 #if GR_CACHE_STATS |
| 112 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount ); | 118 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount ); |
| 113 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); | 119 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); |
| 114 #endif | 120 #endif |
| 115 } | 121 } |
| 116 if (resource->resourcePriv().getScratchKey().isValid()) { | 122 if (resource->resourcePriv().getScratchKey().isValid()) { |
| 117 SkASSERT(!resource->cacheAccess().isWrapped()); | 123 SkASSERT(!resource->cacheAccess().isWrapped()); |
| 118 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); | 124 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); |
| 119 } | 125 } |
| 120 | 126 |
| 121 this->purgeAsNeeded(); | 127 this->purgeAsNeeded(); |
| 122 } | 128 } |
| 123 | 129 |
| 124 void GrResourceCache::removeResource(GrGpuResource* resource) { | 130 void GrResourceCache::removeResource(GrGpuResource* resource) { |
| 125 this->validate(); | 131 this->validate(); |
| 126 SkASSERT(this->isInCache(resource)); | 132 SkASSERT(this->isInCache(resource)); |
| 127 | 133 |
| 128 if (resource->isPurgeable()) { | 134 if (resource->isPurgeable()) { |
| 129 fPurgeableQueue.remove(resource); | 135 fPurgeableQueue.remove(resource); |
| 130 } else { | 136 } else { |
| 131 this->removeFromNonpurgeableArray(resource); | 137 this->removeFromNonpurgeableArray(resource); |
| 132 } | 138 } |
| 133 | 139 |
| 134 size_t size = resource->gpuMemorySize(); | 140 size_t size = resource->gpuMemorySize(); |
| 135 SkDEBUGCODE(--fCount;) | 141 SkDEBUGCODE(--fCount;) |
| 136 fBytes -= size; | 142 fBytes -= size; |
| 137 if (resource->resourcePriv().isBudgeted()) { | 143 if (resource->resourcePriv().isBudgeted()) { |
| 138 --fBudgetedCount; | 144 --fBudgetedCount; |
| 139 fBudgetedBytes -= size; | 145 fBudgetedBytes -= size; |
| 146 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used", | |
| 147 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); | |
| 140 } | 148 } |
| 141 | 149 |
| 142 if (resource->resourcePriv().getScratchKey().isValid()) { | 150 if (resource->resourcePriv().getScratchKey().isValid()) { |
| 143 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); | 151 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); |
| 144 } | 152 } |
| 145 if (resource->getUniqueKey().isValid()) { | 153 if (resource->getUniqueKey().isValid()) { |
| 146 fUniqueHash.remove(resource->getUniqueKey()); | 154 fUniqueHash.remove(resource->getUniqueKey()); |
| 147 } | 155 } |
| 148 this->validate(); | 156 this->validate(); |
| 149 } | 157 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 SkASSERT(this->isInCache(resource)); | 352 SkASSERT(this->isInCache(resource)); |
| 345 | 353 |
| 346 ptrdiff_t delta = resource->gpuMemorySize() - oldSize; | 354 ptrdiff_t delta = resource->gpuMemorySize() - oldSize; |
| 347 | 355 |
| 348 fBytes += delta; | 356 fBytes += delta; |
| 349 #if GR_CACHE_STATS | 357 #if GR_CACHE_STATS |
| 350 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); | 358 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); |
| 351 #endif | 359 #endif |
| 352 if (resource->resourcePriv().isBudgeted()) { | 360 if (resource->resourcePriv().isBudgeted()) { |
| 353 fBudgetedBytes += delta; | 361 fBudgetedBytes += delta; |
| 362 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used", | |
| 363 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); | |
| 354 #if GR_CACHE_STATS | 364 #if GR_CACHE_STATS |
| 355 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); | 365 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); |
| 356 #endif | 366 #endif |
| 357 } | 367 } |
| 358 | 368 |
| 359 this->purgeAsNeeded(); | 369 this->purgeAsNeeded(); |
| 360 this->validate(); | 370 this->validate(); |
| 361 } | 371 } |
| 362 | 372 |
| 363 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { | 373 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { |
| 364 SkASSERT(resource); | 374 SkASSERT(resource); |
| 365 SkASSERT(this->isInCache(resource)); | 375 SkASSERT(this->isInCache(resource)); |
| 366 | 376 |
| 367 size_t size = resource->gpuMemorySize(); | 377 size_t size = resource->gpuMemorySize(); |
| 368 | 378 |
| 369 if (resource->resourcePriv().isBudgeted()) { | 379 if (resource->resourcePriv().isBudgeted()) { |
| 370 ++fBudgetedCount; | 380 ++fBudgetedCount; |
| 371 fBudgetedBytes += size; | 381 fBudgetedBytes += size; |
| 372 #if GR_CACHE_STATS | 382 #if GR_CACHE_STATS |
| 373 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); | 383 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); |
| 374 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount ); | 384 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount ); |
| 375 #endif | 385 #endif |
| 376 this->purgeAsNeeded(); | 386 this->purgeAsNeeded(); |
| 377 } else { | 387 } else { |
| 378 --fBudgetedCount; | 388 --fBudgetedCount; |
| 379 fBudgetedBytes -= size; | 389 fBudgetedBytes -= size; |
| 380 } | 390 } |
| 391 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget", " used", | |
| 392 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); | |
| 381 | 393 |
| 382 this->validate(); | 394 this->validate(); |
| 383 } | 395 } |
| 384 | 396 |
| 385 void GrResourceCache::internalPurgeAsNeeded() { | 397 void GrResourceCache::internalPurgeAsNeeded() { |
| 386 SkASSERT(this->overBudget()); | 398 SkASSERT(this->overBudget()); |
| 387 | 399 |
| 388 bool stillOverbudget = true; | 400 bool stillOverbudget = true; |
| 389 while (fPurgeableQueue.count()) { | 401 while (fPurgeableQueue.count()) { |
| 390 GrGpuResource* resource = fPurgeableQueue.peek(); | 402 GrGpuResource* resource = fPurgeableQueue.peek(); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 return true; | 633 return true; |
| 622 } | 634 } |
| 623 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { | 635 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { |
| 624 return true; | 636 return true; |
| 625 } | 637 } |
| 626 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che."); | 638 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che."); |
| 627 return false; | 639 return false; |
| 628 } | 640 } |
| 629 | 641 |
| 630 #endif | 642 #endif |
| OLD | NEW |