diff options
author | 2017-05-25 16:43:59 -0400 | |
---|---|---|
committer | 2017-05-26 18:14:33 +0000 | |
commit | 5480a18d8799511034d0da219c72932cd8f25274 (patch) | |
tree | 0be82d1f2275f2df75a5bf77eb330fadf677166b /src/gpu/GrResourceCache.cpp | |
parent | dc8c34455849574e4e0260ea35485f093723c10d (diff) |
Add method to GrContext to purge unlocked resources.
Beyond setting the total cache limits this method enables clients to
request to purge a specific number of bytes, as well as specify their
preference to purge scratch resources over resources of other types.
Change-Id: I9259d5544d34251575d77eebe599388f213ff3ce
Reviewed-on: https://skia-review.googlesource.com/17987
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
Diffstat (limited to 'src/gpu/GrResourceCache.cpp')
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 53a62c05c0..ef703e2474 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -536,6 +536,47 @@ void GrResourceCache::purgeResourcesNotUsedSince(GrStdSteadyClock::time_point pu } } +void GrResourceCache::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { + + const size_t tmpByteBudget = SkTMax((size_t)0, fBytes - bytesToPurge); + bool stillOverbudget = tmpByteBudget < fBytes; + + if (preferScratchResources && bytesToPurge < fPurgeableBytes) { + // Sort the queue + fPurgeableQueue.sort(); + + // Make a list of the scratch resources to delete + SkTDArray<GrGpuResource*> scratchResources; + size_t scratchByteCount = 0; + for (int i = 0; i < fPurgeableQueue.count() && stillOverbudget; i++) { + GrGpuResource* resource = fPurgeableQueue.at(i); + SkASSERT(resource->isPurgeable()); + if (!resource->getUniqueKey().isValid()) { + *scratchResources.append() = resource; + scratchByteCount += resource->gpuMemorySize(); + stillOverbudget = tmpByteBudget < fBytes - scratchByteCount; + } + } + + // 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(); + } + stillOverbudget = tmpByteBudget < fBytes; + + this->validate(); + } + + // Purge any remaining resources in LRU order + if (stillOverbudget) { + const size_t cachedByteCount = fMaxBytes; + fMaxBytes = tmpByteBudget; + this->purgeAsNeeded(); + fMaxBytes = cachedByteCount; + } +} + void GrResourceCache::processInvalidUniqueKeys( const SkTArray<GrUniqueKeyInvalidatedMessage>& msgs) { for (int i = 0; i < msgs.count(); ++i) { |