Allow triming of font caches through WindowManager
This allows triming of Skia font caches when an app created a lot of
transient font allocations and it knows that it won't need it anymore.
This is primarily meant for persistent processes like SystemUI to avoid
font caches taking up memory after they're not needed anymore.
Bug: 275486055
Test: Tested as part of a follow-up commit, ran
LockscreenWithSwipeMicrobenchmark which showed a noticable
reduction of RSS+anon memory use after unlock.
Change-Id: I6d80003d8baab35cb2ca858d4e4d4696b32f3adf
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp
index c00a270..babce88 100644
--- a/libs/hwui/renderthread/CacheManager.cpp
+++ b/libs/hwui/renderthread/CacheManager.cpp
@@ -139,6 +139,25 @@
}
}
+void CacheManager::trimCaches(CacheTrimLevel mode) {
+ switch (mode) {
+ case CacheTrimLevel::FONT_CACHE:
+ SkGraphics::PurgeFontCache();
+ break;
+ case CacheTrimLevel::RESOURCE_CACHE:
+ SkGraphics::PurgeResourceCache();
+ break;
+ case CacheTrimLevel::ALL_CACHES:
+ SkGraphics::PurgeAllCaches();
+ if (mGrContext) {
+ mGrContext->purgeUnlockedResources(false);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
void CacheManager::trimStaleResources() {
if (!mGrContext) {
return;