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/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index 31b4b20..224c878 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -231,6 +231,15 @@
}
}
+void RenderProxy::trimCaches(int level) {
+ // Avoid creating a RenderThread to do a trimMemory.
+ if (RenderThread::hasInstance()) {
+ RenderThread& thread = RenderThread::getInstance();
+ const auto trimLevel = static_cast<CacheTrimLevel>(level);
+ thread.queue().post([&thread, trimLevel]() { thread.trimCaches(trimLevel); });
+ }
+}
+
void RenderProxy::purgeCaches() {
if (RenderThread::hasInstance()) {
RenderThread& thread = RenderThread::getInstance();