diff options
| author | 2023-05-09 20:24:48 +0200 | |
|---|---|---|
| committer | 2023-05-18 10:45:18 +0200 | |
| commit | 44db040f6c07b63642bc7ae72040d09851d70df7 (patch) | |
| tree | dfeaf033e51f9bd6086d747f5406b28c360601bf /graphics/java/android | |
| parent | 94b48e8c6c737b17f4b2bfbfc42208d5631fcff4 (diff) | |
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
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/HardwareRenderer.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java index 9ed3d9c3c94b..9cde1878d9d8 100644 --- a/graphics/java/android/graphics/HardwareRenderer.java +++ b/graphics/java/android/graphics/HardwareRenderer.java @@ -144,6 +144,32 @@ public class HardwareRenderer { public @interface DumpFlags { } + + /** + * Trims all Skia caches. + * @hide + */ + public static final int CACHE_TRIM_ALL = 0; + /** + * Trims Skia font caches. + * @hide + */ + public static final int CACHE_TRIM_FONT = 1; + /** + * Trims Skia resource caches. + * @hide + */ + public static final int CACHE_TRIM_RESOURCES = 2; + + /** @hide */ + @IntDef(prefix = {"CACHE_TRIM_"}, value = { + CACHE_TRIM_ALL, + CACHE_TRIM_FONT, + CACHE_TRIM_RESOURCES + }) + @Retention(RetentionPolicy.SOURCE) + public @interface CacheTrimLevel {} + /** * Name of the file that holds the shaders cache. */ @@ -1131,6 +1157,20 @@ public class HardwareRenderer { nTrimMemory(level); } + /** + * Invoke this when all font caches should be flushed. This can cause jank on next render + * commands so use it only after expensive font allocation operations which would + * allocate large amount of temporary memory. + * + * @param level Hint about which caches to trim. See {@link #CACHE_TRIM_ALL}, + * {@link #CACHE_TRIM_FONT}, {@link #CACHE_TRIM_RESOURCES} + * + * @hide + */ + public static void trimCaches(@CacheTrimLevel int level) { + nTrimCaches(level); + } + /** @hide */ public static void overrideProperty(@NonNull String name, @NonNull String value) { if (name == null || value == null) { @@ -1497,6 +1537,8 @@ public class HardwareRenderer { private static native void nTrimMemory(int level); + private static native void nTrimCaches(int level); + private static native void nOverrideProperty(String name, String value); private static native void nFence(long nativeProxy); |