Index: src/core/SkResourceCache.cpp |
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp |
index 4ed889a0aba3095900d934187f812f170217cca8..6b3d88e7822a71ccaf0f55f6089ecd857f8975f6 100644 |
--- a/src/core/SkResourceCache.cpp |
+++ b/src/core/SkResourceCache.cpp |
@@ -199,7 +199,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 +294,30 @@ void SkResourceCache::purgeAsNeeded(bool forcePurge) { |
} |
} |
+void SkResourceCache::purge(const void* nameSpace, PurgeVisitor proc, void* context) { |
+ // 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; |
mtklein
2015/02/18 18:49:48
Remind me, what does this break out of? Isn't thi
reed1
2015/02/18 19:30:40
break inside a switch just falls out of the switch
|
+ 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 +556,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); |
} |