aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkResourceCache.h
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-02-19 08:22:54 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-19 08:22:54 -0800
commit4675819b9dbb3ad71ec851776e5de26d342f29fe (patch)
treeba268a491ce8a458f5c8ac9f0f6e5f8bfd5f658e /src/core/SkResourceCache.h
parent67b21a7eef393bbee86482c75b7ea8dfc474d08a (diff)
notify resource caches when pixelref genID goes stale
Diffstat (limited to 'src/core/SkResourceCache.h')
-rw-r--r--src/core/SkResourceCache.h38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/core/SkResourceCache.h b/src/core/SkResourceCache.h
index 88ccb87ed8..36ca27cd73 100644
--- a/src/core/SkResourceCache.h
+++ b/src/core/SkResourceCache.h
@@ -35,6 +35,8 @@ public:
// length must be a multiple of 4
void init(void* nameSpace, size_t length);
+ void* getNamespace() const { return fNamespace; }
+
// This is only valid after having called init().
uint32_t hash() const { return fHash; }
@@ -92,7 +94,21 @@ public:
* true, then the Rec is considered "valid". If false is returned, the Rec will be considered
* "stale" and will be purged from the cache.
*/
- typedef bool (*VisitorProc)(const Rec&, void* context);
+ typedef bool (*FindVisitor)(const Rec&, void* context);
+
+ enum PurgeVisitorResult {
+ kRetainAndContinue_PurgeVisitorResult,
+ kPurgeAndContinue_PurgeVisitorResult,
+ kRetainAndStop_PurgeVisitorResult,
+ kPurgeAndStop_PurgeVisitorResult,
+ };
+
+ /**
+ * Callback function for purge(). If called, the cache will have found a match for the
+ * specified Key, and will pass in the corresponding Rec, along with a caller-specified
+ * context. The function can read the data in Rec.
+ */
+ typedef PurgeVisitorResult (*PurgeVisitor)(const Rec&, void* context);
/**
* Returns a locked/pinned SkDiscardableMemory instance for the specified
@@ -114,7 +130,7 @@ public:
* true : Rec is valid
* false : Rec is "stale" -- the cache will purge it.
*/
- static bool Find(const Key& key, VisitorProc, void* context);
+ static bool Find(const Key& key, FindVisitor, void* context);
static void Add(Rec*);
static size_t GetTotalBytesUsed();
@@ -125,6 +141,12 @@ public:
static size_t GetSingleAllocationByteLimit();
static size_t GetEffectiveSingleAllocationByteLimit();
+ /**
+ * Visit all Rec that match the specified namespace, and purge entries as indicated by the
+ * visitor.
+ */
+ static void Purge(const void* nameSpace, PurgeVisitor, void* context);
+
static void PurgeAll();
/**
@@ -174,7 +196,7 @@ public:
* true : Rec is valid
* false : Rec is "stale" -- the cache will purge it.
*/
- bool find(const Key&, VisitorProc, void* context);
+ bool find(const Key&, FindVisitor, void* context);
void add(Rec*);
size_t getTotalBytesUsed() const { return fTotalBytesUsed; }
@@ -198,8 +220,12 @@ public:
*/
size_t setTotalByteLimit(size_t newLimit);
+ void purge(const void* nameSpace, PurgeVisitor, void* context);
+
void purgeAll() {
+ fInsidePurgeAllCounter += 1;
this->purgeAsNeeded(true);
+ fInsidePurgeAllCounter -= 1;
}
DiscardableFactory discardableFactory() const { return fDiscardableFactory; }
@@ -228,6 +254,12 @@ private:
size_t fSingleAllocationByteLimit;
int fCount;
+ bool insidePurgeAll() const {
+ SkASSERT(fInsidePurgeAllCounter >= 0);
+ return fInsidePurgeAllCounter > 0;
+ }
+ int fInsidePurgeAllCounter;
+
void purgeAsNeeded(bool forcePurge = false);
// linklist management