diff options
author | Robert Phillips <robertphillips@google.com> | 2018-03-28 12:25:42 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-28 18:56:14 +0000 |
commit | 6eba063b63efbf824aff8ec6b32af05e4d54c38b (patch) | |
tree | b3b5ef8a90cd5757ae0fe40caf3471ae6289a96e /src/gpu/GrResourceCache.cpp | |
parent | aa5da735fa27cdb60f55f94bbd2149727c9c0728 (diff) |
Add new GrResourceCache::purgeUnlockedResources variant
TBR=bsalomon@google.com
Change-Id: I05bef1f8a271474db878a046cc1f6ac7b60a15f1
Reviewed-on: https://skia-review.googlesource.com/116801
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrResourceCache.cpp')
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 50b2e9a229..d2eb91c0e8 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -513,13 +513,34 @@ void GrResourceCache::purgeAsNeeded() { } } -void GrResourceCache::purgeAllUnlocked() { - // We could disable maintaining the heap property here, but it would add a lot of complexity. - // Moreover, this is rarely called. - while (fPurgeableQueue.count()) { - GrGpuResource* resource = fPurgeableQueue.peek(); - SkASSERT(resource->isPurgeable()); - resource->cacheAccess().release(); +void GrResourceCache::purgeUnlockedResources(bool scratchResourcesOnly) { + if (!scratchResourcesOnly) { + // We could disable maintaining the heap property here, but it would add a lot of + // complexity. Moreover, this is rarely called. + while (fPurgeableQueue.count()) { + GrGpuResource* resource = fPurgeableQueue.peek(); + SkASSERT(resource->isPurgeable()); + resource->cacheAccess().release(); + } + } else { + // Sort the queue + fPurgeableQueue.sort(); + + // Make a list of the scratch resources to delete + SkTDArray<GrGpuResource*> scratchResources; + for (int i = 0; i < fPurgeableQueue.count(); i++) { + GrGpuResource* resource = fPurgeableQueue.at(i); + SkASSERT(resource->isPurgeable()); + if (!resource->getUniqueKey().isValid()) { + *scratchResources.append() = resource; + } + } + + // Delete the scratch resources. This must be done as a separate pass + // to avoid messing up the sorted order of the queue + for (int i = 0; i < scratchResources.count(); i++) { + scratchResources.getAt(i)->cacheAccess().release(); + } } this->validate(); |