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

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

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unrelated GrBuffer::onGpuMemorySize() lack of override keyword compile error Created 4 years, 8 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/GrStencilAttachment.h » ('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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrResourceCache.h" 9 #include "GrResourceCache.h"
10 #include "GrGpuResourceCacheAccess.h" 10 #include "GrGpuResourceCacheAccess.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->resourcePriv().isExternal()); 149 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 SkASSERT(!resource->isPurgeable()); 369 SkASSERT(!resource->isPurgeable());
370 return; 370 return;
371 } 371 }
372 372
373 SkASSERT(resource->isPurgeable()); 373 SkASSERT(resource->isPurgeable());
374 this->removeFromNonpurgeableArray(resource); 374 this->removeFromNonpurgeableArray(resource);
375 fPurgeableQueue.insert(resource); 375 fPurgeableQueue.insert(resource);
376 376
377 if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) { 377 if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
378 // Check whether this resource could still be used as a scratch resource . 378 // Check whether this resource could still be used as a scratch resource .
379 if (!resource->resourcePriv().isExternal() && 379 if (!resource->resourcePriv().refsWrappedObjects() &&
380 resource->resourcePriv().getScratchKey().isValid()) { 380 resource->resourcePriv().getScratchKey().isValid()) {
381 // We won't purge an existing resource to make room for this one. 381 // We won't purge an existing resource to make room for this one.
382 if (fBudgetedCount < fMaxCount && 382 if (fBudgetedCount < fMaxCount &&
383 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { 383 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) {
384 resource->resourcePriv().makeBudgeted(); 384 resource->resourcePriv().makeBudgeted();
385 return; 385 return;
386 } 386 }
387 } 387 }
388 } else { 388 } else {
389 // Purge the resource immediately if we're over budget 389 // Purge the resource immediately if we're over budget
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 fBytes += resource->gpuMemorySize(); 654 fBytes += resource->gpuMemorySize();
655 655
656 if (!resource->isPurgeable()) { 656 if (!resource->isPurgeable()) {
657 ++fLocked; 657 ++fLocked;
658 } 658 }
659 659
660 if (resource->cacheAccess().isScratch()) { 660 if (resource->cacheAccess().isScratch()) {
661 SkASSERT(!resource->getUniqueKey().isValid()); 661 SkASSERT(!resource->getUniqueKey().isValid());
662 ++fScratch; 662 ++fScratch;
663 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc ratchKey())); 663 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc ratchKey()));
664 SkASSERT(!resource->resourcePriv().isExternal()); 664 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
665 } else if (resource->resourcePriv().getScratchKey().isValid()) { 665 } else if (resource->resourcePriv().getScratchKey().isValid()) {
666 SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted( ) || 666 SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted( ) ||
667 resource->getUniqueKey().isValid()); 667 resource->getUniqueKey().isValid());
668 ++fCouldBeScratch; 668 ++fCouldBeScratch;
669 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc ratchKey())); 669 SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getSc ratchKey()));
670 SkASSERT(!resource->resourcePriv().isExternal()); 670 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
671 } 671 }
672 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); 672 const GrUniqueKey& uniqueKey = resource->getUniqueKey();
673 if (uniqueKey.isValid()) { 673 if (uniqueKey.isValid()) {
674 ++fContent; 674 ++fContent;
675 SkASSERT(fUniqueHash->find(uniqueKey) == resource); 675 SkASSERT(fUniqueHash->find(uniqueKey) == resource);
676 SkASSERT(!resource->resourcePriv().isExternal()); 676 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
677 SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted ()); 677 SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted ());
678 } 678 }
679 679
680 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { 680 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
681 ++fBudgetedCount; 681 ++fBudgetedCount;
682 fBudgetedBytes += resource->gpuMemorySize(); 682 fBudgetedBytes += resource->gpuMemorySize();
683 } 683 }
684 } 684 }
685 }; 685 };
686 686
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 return true; 732 return true;
733 } 733 }
734 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { 734 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) {
735 return true; 735 return true;
736 } 736 }
737 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che."); 737 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che.");
738 return false; 738 return false;
739 } 739 }
740 740
741 #endif 741 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/GrStencilAttachment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698