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

Unified Diff: src/gpu/GrResourceCache.h

Issue 921323002: Make GrResourceCache use a priority queue of purgeable resources. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrGpuResourceCacheAccess.h ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrResourceCache.h
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index 3e4ededc9e0c9eec5724f4c9d74bd1579ffed431..b5984f2344ca9a00532719d3cf9cd0e521bda4d8 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -10,11 +10,13 @@
#define GrResourceCache_DEFINED
#include "GrGpuResource.h"
+#include "GrGpuResourceCacheAccess.h"
#include "GrGpuResourcePriv.h"
#include "GrResourceKey.h"
#include "SkMessageBus.h"
#include "SkRefCnt.h"
#include "SkTArray.h"
+#include "SkTDPQueue.h"
#include "SkTInternalLList.h"
#include "SkTMultiMap.h"
@@ -117,8 +119,7 @@ public:
GrGpuResource* findAndRefContentResource(const GrContentKey& contentKey) {
GrGpuResource* resource = fContentHash.find(contentKey);
if (resource) {
- resource->ref();
- this->makeResourceMRU(resource);
+ this->refAndMakeResourceMRU(resource);
}
return resource;
}
@@ -138,7 +139,7 @@ public:
if (invalidKeyMsgs.count()) {
this->processInvalidContentKeys(invalidKeyMsgs);
}
- if (fPurging || (fBudgetedCount <= fMaxCount && fBudgetedBytes <= fMaxBytes)) {
+ if (fBudgetedCount <= fMaxCount && fBudgetedBytes <= fMaxBytes) {
return;
}
this->internalPurgeAsNeeded();
@@ -179,7 +180,7 @@ private:
void willRemoveScratchKey(const GrGpuResource*);
void willRemoveContentKey(const GrGpuResource*);
void didChangeBudgetStatus(GrGpuResource*);
- void makeResourceMRU(GrGpuResource*);
+ void refAndMakeResourceMRU(GrGpuResource*);
/// @}
void internalPurgeAsNeeded();
@@ -216,9 +217,26 @@ private:
typedef SkTInternalLList<GrGpuResource> ResourceList;
+ static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) {
+ return a->cacheAccess().timestamp() < b->cacheAccess().timestamp();
+ }
+
+ static int* AccessResourceIndex(GrGpuResource* const& res) {
+ return res->cacheAccess().accessCacheIndex();
+ }
+
typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKeyInbox;
+ typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue;
+ // Whenever a resource is added to the cache or the result of a cache lookup, fTimestamp is
+ // assigned as the resource's timestamp and then incremented. fPurgeableQueue orders the
+ // purgeable resources by this value, and thus is used to purge resources in LRU order.
+ uint32_t fTimestamp;
+ PurgeableQueue fPurgeableQueue;
+
+ // TODO: Replace this with an array of nonpurgeable resources
ResourceList fResources;
+
// This map holds all resources that can be used as scratch resources.
ScratchMap fScratchMap;
// This holds all resources that have content keys.
@@ -243,15 +261,10 @@ private:
int fBudgetedCount;
size_t fBudgetedBytes;
- // prevents recursive purging
- bool fPurging;
- bool fNewlyPurgeableResourceWhilePurging;
-
PFOverBudgetCB fOverBudgetCB;
void* fOverBudgetData;
InvalidContentKeyInbox fInvalidContentKeyInbox;
-
};
class GrResourceCache::ResourceAccess {
« no previous file with comments | « src/gpu/GrGpuResourceCacheAccess.h ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698