diff options
author | Brian Salomon <bsalomon@google.com> | 2017-03-22 10:04:27 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-22 14:42:11 +0000 |
commit | fbb56ce83fc717b7c6722324bbccd1ae73c350a4 (patch) | |
tree | 0025d8cca6e55eb2fd25b370f7c1bded5e5e910c /src/gpu/GrResourceCache.cpp | |
parent | b667fe2f67a072da74d7a7da32cae4f06a2f0ee4 (diff) |
Add a new GrResourceCache purging mechanism for purging unused resources.
The client may call GrContext::purgeResourceNotUsedSince() with a stead_clock::time_point and all resources that have been purgeable since before that time point are purged.
This is intended to replace the "max unused flushes" purging mechanism once Chrome adopts it.
Change-Id: I28881dd2959cc01c0acca81b2d6001ee5626439d
Reviewed-on: https://skia-review.googlesource.com/8920
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Eric Karl <ericrk@google.com>
Diffstat (limited to 'src/gpu/GrResourceCache.cpp')
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 9462a7384d..97d3b96808 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -365,6 +365,7 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla this->removeFromNonpurgeableArray(resource); fPurgeableQueue.insert(resource); resource->cacheAccess().setFlushCntWhenResourceBecamePurgeable(fExternalFlushCnt); + resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) { // Check whether this resource could still be used as a scratch resource. @@ -504,6 +505,24 @@ void GrResourceCache::purgeAllUnlocked() { this->validate(); } +void GrResourceCache::purgeResourcesNotUsedSince(std::chrono::steady_clock::time_point purgeTime) { + while (fPurgeableQueue.count()) { + const std::chrono::steady_clock::time_point resourceTime = + fPurgeableQueue.peek()->cacheAccess().timeWhenResourceBecamePurgeable(); + if (resourceTime >= purgeTime) { + // Resources were given both LRU timestamps and tagged with a frame number when + // they first became purgeable. The LRU timestamp won't change again until the + // resource is made non-purgeable again. So, at this point all the remaining + // resources in the timestamp-sorted queue will have a frame number >= to this + // one. + break; + } + GrGpuResource* resource = fPurgeableQueue.peek(); + SkASSERT(resource->isPurgeable()); + resource->cacheAccess().release(); + } +} + void GrResourceCache::processInvalidUniqueKeys( const SkTArray<GrUniqueKeyInvalidatedMessage>& msgs) { for (int i = 0; i < msgs.count(); ++i) { |