| 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 "GrResourceCache2.h" | 10 #include "GrResourceCache2.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 fBytes -= size; | 125 fBytes -= size; |
| 126 if (resource->cacheAccess().isBudgeted()) { | 126 if (resource->cacheAccess().isBudgeted()) { |
| 127 --fBudgetedCount; | 127 --fBudgetedCount; |
| 128 fBudgetedBytes -= size; | 128 fBudgetedBytes -= size; |
| 129 } | 129 } |
| 130 | 130 |
| 131 fResources.remove(resource); | 131 fResources.remove(resource); |
| 132 if (resource->cacheAccess().getScratchKey().isValid()) { | 132 if (resource->cacheAccess().getScratchKey().isValid()) { |
| 133 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); | 133 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); |
| 134 } | 134 } |
| 135 if (resource->cacheAccess().getContentKey().isValid()) { | 135 if (resource->getContentKey().isValid()) { |
| 136 fContentHash.remove(resource->cacheAccess().getContentKey()); | 136 fContentHash.remove(resource->getContentKey()); |
| 137 } | 137 } |
| 138 this->validate(); | 138 this->validate(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void GrResourceCache2::abandonAll() { | 141 void GrResourceCache2::abandonAll() { |
| 142 AutoValidate av(this); | 142 AutoValidate av(this); |
| 143 | 143 |
| 144 SkASSERT(!fPurging); | 144 SkASSERT(!fPurging); |
| 145 while (GrGpuResource* head = fResources.head()) { | 145 while (GrGpuResource* head = fResources.head()) { |
| 146 SkASSERT(!head->wasDestroyed()); | 146 SkASSERT(!head->wasDestroyed()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 void GrResourceCache2::willRemoveScratchKey(const GrGpuResource* resource) { | 219 void GrResourceCache2::willRemoveScratchKey(const GrGpuResource* resource) { |
| 220 SkASSERT(resource->cacheAccess().getScratchKey().isValid()); | 220 SkASSERT(resource->cacheAccess().getScratchKey().isValid()); |
| 221 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); | 221 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool GrResourceCache2::didSetContentKey(GrGpuResource* resource) { | 224 bool GrResourceCache2::didSetContentKey(GrGpuResource* resource) { |
| 225 SkASSERT(!fPurging); | 225 SkASSERT(!fPurging); |
| 226 SkASSERT(resource); | 226 SkASSERT(resource); |
| 227 SkASSERT(this->isInCache(resource)); | 227 SkASSERT(this->isInCache(resource)); |
| 228 SkASSERT(resource->cacheAccess().getContentKey().isValid()); | 228 SkASSERT(resource->getContentKey().isValid()); |
| 229 | 229 |
| 230 GrGpuResource* res = fContentHash.find(resource->cacheAccess().getContentKey
()); | 230 GrGpuResource* res = fContentHash.find(resource->getContentKey()); |
| 231 if (NULL != res) { | 231 if (NULL != res) { |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 | 234 |
| 235 fContentHash.add(resource); | 235 fContentHash.add(resource); |
| 236 this->validate(); | 236 this->validate(); |
| 237 return true; | 237 return true; |
| 238 } | 238 } |
| 239 | 239 |
| 240 void GrResourceCache2::makeResourceMRU(GrGpuResource* resource) { | 240 void GrResourceCache2::makeResourceMRU(GrGpuResource* resource) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 } else { | 275 } else { |
| 276 release = true; | 276 release = true; |
| 277 } | 277 } |
| 278 } else { | 278 } else { |
| 279 // Purge the resource if we're over budget | 279 // Purge the resource if we're over budget |
| 280 bool overBudget = fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxByt
es; | 280 bool overBudget = fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxByt
es; |
| 281 | 281 |
| 282 // Also purge if the resource has neither a valid scratch key nor a cont
ent key. | 282 // Also purge if the resource has neither a valid scratch key nor a cont
ent key. |
| 283 bool noKey = !resource->cacheAccess().getScratchKey().isValid() && | 283 bool noKey = !resource->cacheAccess().getScratchKey().isValid() && |
| 284 !resource->cacheAccess().getContentKey().isValid(); | 284 !resource->getContentKey().isValid(); |
| 285 if (overBudget || noKey) { | 285 if (overBudget || noKey) { |
| 286 release = true; | 286 release = true; |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 if (release) { | 290 if (release) { |
| 291 SkDEBUGCODE(int beforeCount = fCount;) | 291 SkDEBUGCODE(int beforeCount = fCount;) |
| 292 resource->cacheAccess().release(); | 292 resource->cacheAccess().release(); |
| 293 // We should at least free this resource, perhaps dependent resources as
well. | 293 // We should at least free this resource, perhaps dependent resources as
well. |
| 294 SkASSERT(fCount < beforeCount); | 294 SkASSERT(fCount < beforeCount); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 GrGpuResource* resource = iter.init(fResources, ResourceList::Iter::kHead_It
erStart); | 428 GrGpuResource* resource = iter.init(fResources, ResourceList::Iter::kHead_It
erStart); |
| 429 for ( ; resource; resource = iter.next()) { | 429 for ( ; resource; resource = iter.next()) { |
| 430 bytes += resource->gpuMemorySize(); | 430 bytes += resource->gpuMemorySize(); |
| 431 ++count; | 431 ++count; |
| 432 | 432 |
| 433 if (!resource->isPurgeable()) { | 433 if (!resource->isPurgeable()) { |
| 434 ++locked; | 434 ++locked; |
| 435 } | 435 } |
| 436 | 436 |
| 437 if (resource->cacheAccess().isScratch()) { | 437 if (resource->cacheAccess().isScratch()) { |
| 438 SkASSERT(!resource->cacheAccess().getContentKey().isValid()); | 438 SkASSERT(!resource->getContentKey().isValid()); |
| 439 ++scratch; | 439 ++scratch; |
| 440 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK
ey())); | 440 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK
ey())); |
| 441 SkASSERT(!resource->cacheAccess().isWrapped()); | 441 SkASSERT(!resource->cacheAccess().isWrapped()); |
| 442 } else if (resource->cacheAccess().getScratchKey().isValid()) { | 442 } else if (resource->cacheAccess().getScratchKey().isValid()) { |
| 443 SkASSERT(!resource->cacheAccess().isBudgeted() || | 443 SkASSERT(!resource->cacheAccess().isBudgeted() || |
| 444 resource->cacheAccess().getContentKey().isValid()); | 444 resource->getContentKey().isValid()); |
| 445 ++couldBeScratch; | 445 ++couldBeScratch; |
| 446 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK
ey())); | 446 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK
ey())); |
| 447 SkASSERT(!resource->cacheAccess().isWrapped()); | 447 SkASSERT(!resource->cacheAccess().isWrapped()); |
| 448 } | 448 } |
| 449 const GrContentKey& contentKey = resource->cacheAccess().getContentKey()
; | 449 const GrContentKey& contentKey = resource->getContentKey(); |
| 450 if (contentKey.isValid()) { | 450 if (contentKey.isValid()) { |
| 451 ++content; | 451 ++content; |
| 452 SkASSERT(fContentHash.find(contentKey) == resource); | 452 SkASSERT(fContentHash.find(contentKey) == resource); |
| 453 SkASSERT(!resource->cacheAccess().isWrapped()); | 453 SkASSERT(!resource->cacheAccess().isWrapped()); |
| 454 SkASSERT(resource->cacheAccess().isBudgeted()); | 454 SkASSERT(resource->cacheAccess().isBudgeted()); |
| 455 } | 455 } |
| 456 | 456 |
| 457 if (resource->cacheAccess().isBudgeted()) { | 457 if (resource->cacheAccess().isBudgeted()) { |
| 458 ++budgetedCount; | 458 ++budgetedCount; |
| 459 budgetedBytes += resource->gpuMemorySize(); | 459 budgetedBytes += resource->gpuMemorySize(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 516 |
| 517 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); | 517 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); |
| 518 SkDebugf("\t\tEntry Count: current %d" | 518 SkDebugf("\t\tEntry Count: current %d" |
| 519 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), hig
h %d\n", | 519 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), hig
h %d\n", |
| 520 fCount, fBudgetedCount, wrapped, locked, scratch, countUtilization, fHig
hWaterCount); | 520 fCount, fBudgetedCount, wrapped, locked, scratch, countUtilization, fHig
hWaterCount); |
| 521 SkDebugf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudget
ed) high %d\n", | 521 SkDebugf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudget
ed) high %d\n", |
| 522 fBytes, fBudgetedBytes, byteUtilization, unbudgetedSize, fHighWa
terBytes); | 522 fBytes, fBudgetedBytes, byteUtilization, unbudgetedSize, fHighWa
terBytes); |
| 523 } | 523 } |
| 524 | 524 |
| 525 #endif | 525 #endif |
| OLD | NEW |