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

Unified Diff: src/core/SkResourceCache.cpp

Issue 825263005: notify resource caches when pixelref genID goes stale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add test for purge notifications 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/core/SkResourceCache.h ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkResourceCache.cpp
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp
index 4ed889a0aba3095900d934187f812f170217cca8..62263605dea187c95ca3864f31c9a776f2b2b7fb 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);
}
« no previous file with comments | « src/core/SkResourceCache.h ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698