Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: src/gpu/GrResourceCache.cpp

Issue 1734043002: Revert of Move Budgeted enum out of SkSurface, use in GrTextureProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 this->addToNonpurgeableArray(resource); 130 this->addToNonpurgeableArray(resource);
131 131
132 size_t size = resource->gpuMemorySize(); 132 size_t size = resource->gpuMemorySize();
133 SkDEBUGCODE(++fCount;) 133 SkDEBUGCODE(++fCount;)
134 fBytes += size; 134 fBytes += size;
135 #if GR_CACHE_STATS 135 #if GR_CACHE_STATS
136 fHighWaterCount = SkTMax(this->getResourceCount(), fHighWaterCount); 136 fHighWaterCount = SkTMax(this->getResourceCount(), fHighWaterCount);
137 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); 137 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
138 #endif 138 #endif
139 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { 139 if (resource->resourcePriv().isBudgeted()) {
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()) {
(...skipping 10 matching lines...) Expand all
160 160
161 if (resource->isPurgeable()) { 161 if (resource->isPurgeable()) {
162 fPurgeableQueue.remove(resource); 162 fPurgeableQueue.remove(resource);
163 } else { 163 } else {
164 this->removeFromNonpurgeableArray(resource); 164 this->removeFromNonpurgeableArray(resource);
165 } 165 }
166 166
167 size_t size = resource->gpuMemorySize(); 167 size_t size = resource->gpuMemorySize();
168 SkDEBUGCODE(--fCount;) 168 SkDEBUGCODE(--fCount;)
169 fBytes -= size; 169 fBytes -= size;
170 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { 170 if (resource->resourcePriv().isBudgeted()) {
171 --fBudgetedCount; 171 --fBudgetedCount;
172 fBudgetedBytes -= size; 172 fBudgetedBytes -= size;
173 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used", 173 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used",
174 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); 174 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes);
175 } 175 }
176 176
177 if (resource->resourcePriv().getScratchKey().isValid()) { 177 if (resource->resourcePriv().getScratchKey().isValid()) {
178 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); 178 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
179 } 179 }
180 if (resource->getUniqueKey().isValid()) { 180 if (resource->getUniqueKey().isValid()) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (SkBudgeted::kNo == 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->cacheAccess().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 }
(...skipping 18 matching lines...) Expand all
407 // SkASSERT(!fPurging); GrPathRange increases size during flush. :( 407 // SkASSERT(!fPurging); GrPathRange increases size during flush. :(
408 SkASSERT(resource); 408 SkASSERT(resource);
409 SkASSERT(this->isInCache(resource)); 409 SkASSERT(this->isInCache(resource));
410 410
411 ptrdiff_t delta = resource->gpuMemorySize() - oldSize; 411 ptrdiff_t delta = resource->gpuMemorySize() - oldSize;
412 412
413 fBytes += delta; 413 fBytes += delta;
414 #if GR_CACHE_STATS 414 #if GR_CACHE_STATS
415 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); 415 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
416 #endif 416 #endif
417 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { 417 if (resource->resourcePriv().isBudgeted()) {
418 fBudgetedBytes += delta; 418 fBudgetedBytes += delta;
419 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used", 419 TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget ", "used",
420 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes); 420 fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes);
421 #if GR_CACHE_STATS 421 #if GR_CACHE_STATS
422 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); 422 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes );
423 #endif 423 #endif
424 } 424 }
425 425
426 this->purgeAsNeeded(); 426 this->purgeAsNeeded();
427 this->validate(); 427 this->validate();
428 } 428 }
429 429
430 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { 430 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) {
431 SkASSERT(resource); 431 SkASSERT(resource);
432 SkASSERT(this->isInCache(resource)); 432 SkASSERT(this->isInCache(resource));
433 433
434 size_t size = resource->gpuMemorySize(); 434 size_t size = resource->gpuMemorySize();
435 435
436 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { 436 if (resource->resourcePriv().isBudgeted()) {
437 ++fBudgetedCount; 437 ++fBudgetedCount;
438 fBudgetedBytes += size; 438 fBudgetedBytes += size;
439 #if GR_CACHE_STATS 439 #if GR_CACHE_STATS
440 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); 440 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes );
441 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount ); 441 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount );
442 #endif 442 #endif
443 this->purgeAsNeeded(); 443 this->purgeAsNeeded();
444 } else { 444 } else {
445 --fBudgetedCount; 445 --fBudgetedCount;
446 fBudgetedBytes -= size; 446 fBudgetedBytes -= size;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->cacheAccess().isExternal());
666 } else if (resource->resourcePriv().getScratchKey().isValid()) { 666 } else if (resource->resourcePriv().getScratchKey().isValid()) {
667 SkASSERT(SkBudgeted::kNo == 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->cacheAccess().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->cacheAccess().isExternal());
678 SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted ()); 678 SkASSERT(resource->resourcePriv().isBudgeted());
679 } 679 }
680 680
681 if (SkBudgeted::kYes == 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
688 Stats stats(this); 688 Stats stats(this);
689 689
690 for (int i = 0; i < fNonpurgeableResources.count(); ++i) { 690 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
691 SkASSERT(!fNonpurgeableResources[i]->isPurgeable() || 691 SkASSERT(!fNonpurgeableResources[i]->isPurgeable() ||
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698