From 0f8981d9b14b866c968757710559feccddb00475 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Mon, 20 Apr 2020 17:38:37 +0800 Subject: [PATCH] Aviod divider surface memory allocated after boot The divider surface buffer will be allocated even if the user does not enter split mode. Avoid it by only copy surface when it show and release it when it hidden. Bug: 150190730 Test: reboot and check adb shell dumpsys SurfaceFlinger Change-Id: Id70a2626b2a921cff6243d992c6b053e329ef92b --- .../android/view/WindowlessWindowManager.java | 23 +++++++++---------- .../android/systemui/wm/SystemWindows.java | 4 ++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java index 95d6d651cc792..15604a2ae2c1a 100644 --- a/core/java/android/view/WindowlessWindowManager.java +++ b/core/java/android/view/WindowlessWindowManager.java @@ -41,6 +41,7 @@ public class WindowlessWindowManager implements IWindowSession { private final static String TAG = "WindowlessWindowManager"; private class State { + //TODO : b/150190730 we should create it when view show and release it when view invisible. SurfaceControl mSurfaceControl; WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(); int mDisplayId; @@ -239,21 +240,19 @@ public class WindowlessWindowManager implements IWindowSession { } WindowManager.LayoutParams attrs = state.mParams; - final Rect surfaceInsets = attrs.surfaceInsets; - int width = surfaceInsets != null ? - attrs.width + surfaceInsets.left + surfaceInsets.right : attrs.width; - int height = surfaceInsets != null ? - attrs.height + surfaceInsets.top + surfaceInsets.bottom : attrs.height; - - t.setBufferSize(sc, width, height) - .setOpaque(sc, isOpaque(attrs)); if (viewFlags == View.VISIBLE) { - t.show(sc); + final Rect surfaceInsets = attrs.surfaceInsets; + int width = surfaceInsets != null + ? attrs.width + surfaceInsets.left + surfaceInsets.right : attrs.width; + int height = surfaceInsets != null + ? attrs.height + surfaceInsets.top + surfaceInsets.bottom : attrs.height; + + t.setBufferSize(sc, width, height).setOpaque(sc, isOpaque(attrs)).show(sc).apply(); + outSurfaceControl.copyFrom(sc); } else { - t.hide(sc); + t.hide(sc).apply(); + outSurfaceControl.release(); } - t.apply(); - outSurfaceControl.copyFrom(sc); outFrame.set(0, 0, attrs.width, attrs.height); mergedConfiguration.setConfiguration(mConfiguration, mConfiguration); diff --git a/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java b/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java index 64cac84ff24e1..93f45c51f0ebc 100644 --- a/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java +++ b/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java @@ -189,8 +189,8 @@ public class SystemWindows { public SurfaceControl getViewSurface(View rootView) { for (int i = 0; i < mPerDisplay.size(); ++i) { for (int iWm = 0; iWm < mPerDisplay.valueAt(i).mWwms.size(); ++iWm) { - SurfaceControl out = - mPerDisplay.valueAt(i).mWwms.get(iWm).getSurfaceControlForWindow(rootView); + SurfaceControl out = mPerDisplay.valueAt(i).mWwms.valueAt(iWm) + .getSurfaceControlForWindow(rootView); if (out != null) { return out; }