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

Unified Diff: src/core/SkResourceCache.cpp

Issue 1271033002: private iterator to visit all resource cache entries (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add iter for fontcache Created 5 years, 4 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
Index: src/core/SkResourceCache.cpp
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp
index 6c76d350c39bda864dae139838924d2f1d92fe16..6febbd2971df44fb8e91115173d35282e327d893 100644
--- a/src/core/SkResourceCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -347,6 +347,18 @@ void SkResourceCache::purgeSharedID(uint64_t sharedID) {
#endif
}
+void SkResourceCache::visitAll(Visitor visitor, 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) {
+ visitor(*rec, context);
+ rec = rec->fPrev;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
size_t prevLimit = fTotalByteLimit;
fTotalByteLimit = newLimit;
@@ -608,6 +620,11 @@ void SkResourceCache::Add(Rec* rec) {
get_cache()->add(rec);
}
+void SkResourceCache::VisitAll(Visitor visitor, void* context) {
+ SkAutoMutexAcquire am(gMutex);
+ get_cache()->visitAll(visitor, context);
+}
+
void SkResourceCache::PostPurgeSharedID(uint64_t sharedID) {
if (sharedID) {
SkMessageBus<PurgeSharedIDMessage>::Post(PurgeSharedIDMessage(sharedID));
@@ -644,3 +661,13 @@ void SkGraphics::PurgeResourceCache() {
return SkResourceCache::PurgeAll();
}
+/////////////
+
+static void dump_visitor(const SkResourceCache::Rec& rec, void*) {
+ SkDebugf("RC: %12s bytes %9lu discardable %p\n",
+ rec.getCategory(), rec.bytesUsed(), rec.diagnostic_only_getDiscardable());
+}
+
+void SkResourceCache::TestDumpMemoryStatistics() {
+ VisitAll(dump_visitor, nullptr);
+}

Powered by Google App Engine
This is Rietveld 408576698