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

Unified Diff: src/core/SkResourceCache.cpp

Issue 561953002: Make SkBitmapCache remove invalid bitmaps from the SkResourceCache. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cache: Created 6 years, 3 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 73f788cd172a7ac1e6e049a5ce246d2fff92eb64..6400e8a71eccd0e45cc5c0bb2b26cc124fb07815 100644
--- a/src/core/SkResourceCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -286,6 +286,23 @@ void SkResourceCache::unlock(SkResourceCache::ID id) {
}
}
+void SkResourceCache::remove(Rec* rec) {
+ SkASSERT(0 == rec->fLockCount);
+
+ size_t used = rec->bytesUsed();
+ SkASSERT(used <= fTotalBytesUsed);
+
+ this->detach(rec);
+#ifdef USE_HASH
+ fHash->remove(rec->getKey());
+#endif
+
+ SkDELETE(rec);
+
+ fTotalBytesUsed -= used;
+ fCount -= 1;
+}
+
void SkResourceCache::purgeAsNeeded() {
size_t byteLimit;
int countLimit;
@@ -298,34 +315,18 @@ void SkResourceCache::purgeAsNeeded() {
byteLimit = fTotalByteLimit;
}
- size_t bytesUsed = fTotalBytesUsed;
- int countUsed = fCount;
-
Rec* rec = fTail;
while (rec) {
- if (bytesUsed < byteLimit && countUsed < countLimit) {
+ if (fTotalBytesUsed < byteLimit && fCount < countLimit) {
break;
}
Rec* prev = rec->fPrev;
if (0 == rec->fLockCount) {
- size_t used = rec->bytesUsed();
- SkASSERT(used <= bytesUsed);
- this->detach(rec);
-#ifdef USE_HASH
- fHash->remove(rec->getKey());
-#endif
-
- SkDELETE(rec);
-
- bytesUsed -= used;
- countUsed -= 1;
+ this->remove(rec);
}
rec = prev;
}
-
- fTotalBytesUsed = bytesUsed;
- fCount = countUsed;
}
size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
@@ -506,6 +507,28 @@ void SkResourceCache::Unlock(SkResourceCache::ID id) {
// get_cache()->dump();
}
+void SkResourceCache::Remove(SkResourceCache::ID id) {
+ SkAutoMutexAcquire am(gMutex);
+ SkASSERT(id);
+
+#ifdef SK_DEBUG
+ {
+ bool found = false;
+ Rec* rec = get_cache()->fHead;
+ while (rec != NULL) {
+ if (rec == id) {
+ found = true;
+ break;
+ }
+ rec = rec->fNext;
+ }
+ SkASSERT(found);
+ }
+#endif
+ const Rec* rec = id;
+ get_cache()->remove(const_cast<Rec*>(rec));
+}
+
size_t SkResourceCache::GetTotalBytesUsed() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->getTotalBytesUsed();
« 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