Loading core/java/android/view/WindowManagerGlobal.java +6 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.graphics.HardwareRenderer; import android.os.Build; import android.os.IBinder; import android.os.RemoteException; Loading Loading @@ -550,6 +551,11 @@ public final class WindowManagerGlobal { ThreadedRenderer.trimMemory(level); } /** @hide */ public void trimCaches(@HardwareRenderer.CacheTrimLevel int level) { ThreadedRenderer.trimCaches(level); } public void dumpGfxInfo(FileDescriptor fd, String[] args) { FileOutputStream fout = new FileOutputStream(fd); PrintWriter pw = new FastPrintWriter(fout); Loading graphics/java/android/graphics/HardwareRenderer.java +42 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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) { Loading Loading @@ -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); Loading libs/hwui/MemoryPolicy.h +6 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,12 @@ enum class TrimLevel { RUNNING_MODERATE = 5, }; enum class CacheTrimLevel { ALL_CACHES = 0, FONT_CACHE = 1, RESOURCE_CACHE = 2, }; struct MemoryPolicy { // The initial scale factor applied to the display resolution. The default is 1, but // lower values may be used to start with a smaller initial cache size. The cache will Loading libs/hwui/jni/android_graphics_HardwareRenderer.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -362,6 +362,10 @@ static void android_view_ThreadedRenderer_trimMemory(JNIEnv* env, jobject clazz, RenderProxy::trimMemory(level); } static void android_view_ThreadedRenderer_trimCaches(JNIEnv* env, jobject clazz, jint level) { RenderProxy::trimCaches(level); } static void android_view_ThreadedRenderer_overrideProperty(JNIEnv* env, jobject clazz, jstring name, jstring value) { const char* nameCharArray = env->GetStringUTFChars(name, NULL); Loading Loading @@ -1018,6 +1022,7 @@ static const JNINativeMethod gMethods[] = { (void*)android_view_ThreadedRenderer_notifyCallbackPending}, {"nNotifyExpensiveFrame", "(J)V", (void*)android_view_ThreadedRenderer_notifyExpensiveFrame}, {"nTrimCaches", "(I)V", (void*)android_view_ThreadedRenderer_trimCaches}, }; static JavaVM* mJvm = nullptr; Loading libs/hwui/renderthread/CacheManager.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,25 @@ void CacheManager::trimMemory(TrimLevel mode) { } } 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; Loading Loading
core/java/android/view/WindowManagerGlobal.java +6 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.graphics.HardwareRenderer; import android.os.Build; import android.os.IBinder; import android.os.RemoteException; Loading Loading @@ -550,6 +551,11 @@ public final class WindowManagerGlobal { ThreadedRenderer.trimMemory(level); } /** @hide */ public void trimCaches(@HardwareRenderer.CacheTrimLevel int level) { ThreadedRenderer.trimCaches(level); } public void dumpGfxInfo(FileDescriptor fd, String[] args) { FileOutputStream fout = new FileOutputStream(fd); PrintWriter pw = new FastPrintWriter(fout); Loading
graphics/java/android/graphics/HardwareRenderer.java +42 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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) { Loading Loading @@ -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); Loading
libs/hwui/MemoryPolicy.h +6 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,12 @@ enum class TrimLevel { RUNNING_MODERATE = 5, }; enum class CacheTrimLevel { ALL_CACHES = 0, FONT_CACHE = 1, RESOURCE_CACHE = 2, }; struct MemoryPolicy { // The initial scale factor applied to the display resolution. The default is 1, but // lower values may be used to start with a smaller initial cache size. The cache will Loading
libs/hwui/jni/android_graphics_HardwareRenderer.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -362,6 +362,10 @@ static void android_view_ThreadedRenderer_trimMemory(JNIEnv* env, jobject clazz, RenderProxy::trimMemory(level); } static void android_view_ThreadedRenderer_trimCaches(JNIEnv* env, jobject clazz, jint level) { RenderProxy::trimCaches(level); } static void android_view_ThreadedRenderer_overrideProperty(JNIEnv* env, jobject clazz, jstring name, jstring value) { const char* nameCharArray = env->GetStringUTFChars(name, NULL); Loading Loading @@ -1018,6 +1022,7 @@ static const JNINativeMethod gMethods[] = { (void*)android_view_ThreadedRenderer_notifyCallbackPending}, {"nNotifyExpensiveFrame", "(J)V", (void*)android_view_ThreadedRenderer_notifyExpensiveFrame}, {"nTrimCaches", "(I)V", (void*)android_view_ThreadedRenderer_trimCaches}, }; static JavaVM* mJvm = nullptr; Loading
libs/hwui/renderthread/CacheManager.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,25 @@ void CacheManager::trimMemory(TrimLevel mode) { } } 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; Loading