diff options
author | John Reck <jreck@google.com> | 2014-09-22 07:39:18 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2014-09-22 16:01:56 -0700 |
commit | 73840ea3670f1c117843acc6069635c80ba2ffd2 (patch) | |
tree | 913a686d9294af6ea94d7dd615ffcb2febe8df70 /core/java/android/view | |
parent | ee3ef2b8af94b118a91b2f7c454260d191153f7a (diff) | |
download | frameworks_base-73840ea3670f1c117843acc6069635c80ba2ffd2.zip frameworks_base-73840ea3670f1c117843acc6069635c80ba2ffd2.tar.gz frameworks_base-73840ea3670f1c117843acc6069635c80ba2ffd2.tar.bz2 |
Aggressively trim memory for system_process
Bug: 16978006
Don't HWUI-accelerate KeyguardScrim
Aggressively trim memory as soon as a ViewRootImpl
dies or has its visibility changed.
Change-Id: Ie1b7c9d30653456bd2e9f309128174f972999368
Diffstat (limited to 'core/java/android/view')
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 12 | ||||
-rw-r--r-- | core/java/android/view/ViewRootImpl.java | 3 | ||||
-rw-r--r-- | core/java/android/view/WindowManagerGlobal.java | 34 |
3 files changed, 48 insertions, 1 deletions
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index edb3798..904e33f 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -186,6 +186,18 @@ public abstract class HardwareRenderer { } } + public static boolean sTrimForeground = false; + + /** + * Controls whether or not the hardware renderer should aggressively + * trim memory. Note that this must not be set for any process that + * uses WebView! This should be only used by system_process or similar + * that do not go into the background. + */ + public static void enableForegroundTrimming() { + sTrimForeground = true; + } + /** * Indicates whether hardware acceleration is available under any form for * the view hierarchy. diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 43ab4ef..b1d3d45 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -804,6 +804,9 @@ public final class ViewRootImpl implements ViewParent, if (mAppVisible != visible) { mAppVisible = visible; scheduleTraversals(); + if (!mAppVisible) { + WindowManagerGlobal.trimForeground(); + } } } diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index c39ec97..08160c8 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -375,6 +375,9 @@ public final class WindowManagerGlobal { mDyingViews.remove(view); } } + if (HardwareRenderer.sTrimForeground && HardwareRenderer.isAvailable()) { + doTrimForeground(); + } } private int findViewLocked(View view, boolean required) { @@ -413,6 +416,35 @@ public final class WindowManagerGlobal { } HardwareRenderer.trimMemory(level); + + if (HardwareRenderer.sTrimForeground) { + doTrimForeground(); + } + } + } + + public static void trimForeground() { + if (HardwareRenderer.sTrimForeground && HardwareRenderer.isAvailable()) { + WindowManagerGlobal wm = WindowManagerGlobal.getInstance(); + wm.doTrimForeground(); + } + } + + private void doTrimForeground() { + boolean hasVisibleWindows = false; + synchronized (mLock) { + for (int i = mRoots.size() - 1; i >= 0; --i) { + if (mRoots.get(i).getHostVisibility() == View.VISIBLE + && mRoots.get(i).mAttachInfo.mHardwareRenderer != null) { + hasVisibleWindows = true; + } else { + mRoots.get(i).destroyHardwareResources(); + } + } + } + if (!hasVisibleWindows) { + HardwareRenderer.trimMemory( + ComponentCallbacks2.TRIM_MEMORY_COMPLETE); } } @@ -428,7 +460,7 @@ public final class WindowManagerGlobal { for (int i = 0; i < count; i++) { ViewRootImpl root = mRoots.get(i); String name = getWindowName(root); - pw.printf("\n\t%s", name); + pw.printf("\n\t%s (visibility=%d)", name, root.getHostVisibility()); HardwareRenderer renderer = root.getView().mAttachInfo.mHardwareRenderer; |