aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkResourceCache.cpp
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.cpp
parent67b21a7eef393bbee86482c75b7ea8dfc474d08a (diff)
notify resource caches when pixelref genID goes stale
Diffstat (limited to 'src/core/SkResourceCache.cpp')
-rw-r--r--src/core/SkResourceCache.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp
index 4ed889a0ab..62263605de 100644
--- a/src/core/SkResourceCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -61,6 +61,8 @@ void SkResourceCache::init() {
// One of these should be explicit set by the caller after we return.
fTotalByteLimit = 0;
fDiscardableFactory = NULL;
+
+ fInsidePurgeAllCounter = 0;
}
#include "SkDiscardableMemory.h"
@@ -199,7 +201,7 @@ SkResourceCache::~SkResourceCache() {
////////////////////////////////////////////////////////////////////////////////
-bool SkResourceCache::find(const Key& key, VisitorProc visitor, void* context) {
+bool SkResourceCache::find(const Key& key, FindVisitor visitor, void* context) {
Rec* rec = fHash->find(key);
if (rec) {
if (visitor(*rec, context)) {
@@ -294,6 +296,34 @@ void SkResourceCache::purgeAsNeeded(bool forcePurge) {
}
}
+void SkResourceCache::purge(const void* nameSpace, PurgeVisitor proc, void* context) {
+ if (this->insidePurgeAll()) {
+ return;
+ }
+
+ // go backwards, just like purgeAsNeeded, just to make the code similar.
+ // could iterate either direction and still be correct.
+ Rec* rec = fTail;
+ while (rec) {
+ Rec* prev = rec->fPrev;
+ if (rec->getKey().getNamespace() == nameSpace) {
+ switch (proc(*rec, context)) {
+ case kRetainAndContinue_PurgeVisitorResult:
+ break;
+ case kPurgeAndContinue_PurgeVisitorResult:
+ this->remove(rec);
+ break;
+ case kRetainAndStop_PurgeVisitorResult:
+ return;
+ case kPurgeAndStop_PurgeVisitorResult:
+ this->remove(rec);
+ return;
+ }
+ }
+ rec = prev;
+ }
+}
+
size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
size_t prevLimit = fTotalByteLimit;
fTotalByteLimit = newLimit;
@@ -532,12 +562,17 @@ size_t SkResourceCache::GetEffectiveSingleAllocationByteLimit() {
return get_cache()->getEffectiveSingleAllocationByteLimit();
}
+void SkResourceCache::Purge(const void* nameSpace, PurgeVisitor proc, void* context) {
+ SkAutoMutexAcquire am(gMutex);
+ return get_cache()->purge(nameSpace, proc, context);
+}
+
void SkResourceCache::PurgeAll() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->purgeAll();
}
-bool SkResourceCache::Find(const Key& key, VisitorProc visitor, void* context) {
+bool SkResourceCache::Find(const Key& key, FindVisitor visitor, void* context) {
SkAutoMutexAcquire am(gMutex);
return get_cache()->find(key, visitor, context);
}