From ad62bda3cf679e4da3c689784d20c6bb4d4305ff Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 6 Apr 2022 23:53:24 +0800 Subject: [PATCH] Do not set report-orientation-changed for window without surface Otherwise the state may remain to the next new surface when the window becomes visible, and it will get ViewRootImpl #mForceNextWindowRelayout=true from WindowState#resize. And then its pre-allocated buffers from ThreadedRenderer#allocateBuffers will be dropped by ThreadedRenderer#updateSurface. And then allocate again in each frame, which is very wasteful. Bug: 228223340 Test: 1. Launch a landscape app from portrait launcher. 2. Use command "record_android_trace sched view wm am gfx". 3. Swipe up to return to launcher. 4. The trace of launcher should not show "setSurface". And there should not have "allocateHelper" in "DrawFrames". Change-Id: If66cde35837b0362ca51eee018d8828416d118ec --- services/core/java/com/android/server/wm/DisplayContent.java | 3 ++- services/core/java/com/android/server/wm/WindowState.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 81560d4f8676e..0893207a1cbef 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1992,7 +1992,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp scheduleAnimation(); forAllWindows(w -> { - if (w.mHasSurface && !rotateSeamlessly) { + if (!w.mHasSurface) return; + if (!rotateSeamlessly) { ProtoLog.v(WM_DEBUG_ORIENTATION, "Set mOrientationChanging of %s", w); w.setOrientationChanging(true); } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 51d68bc0177ad..46882458e67a2 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -3602,6 +3602,10 @@ class WindowState extends WindowContainer implements WindowManagerP mAnimatingExit = false; ProtoLog.d(WM_DEBUG_ANIM, "Clear animatingExit: reason=destroySurface win=%s", this); + // Clear the flag so the buffer requested for the next new surface won't be dropped by + // mistaking the surface size needs to update. + mReportOrientationChanged = false; + if (useBLASTSync()) { immediatelyNotifyBlastSync(); }