From 19da8aeb71a0e5ef1ef23337acae353a0da50663 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 12 May 2023 17:10:54 +0800 Subject: [PATCH] Reduce flickering when swiping auto-pip with orientation change This reuses the partial legacy path to avoid sending additional configuration change from display rotation to PiP task before setting the destinations PiP bounds. The rough steps: Transient transition finishes -> Update task to pip -> Transition with pip and display change -> PipTransition applies surface transform in new rotation (handleSwipePipToHomeTransition, the startTransaction contains display projection) -> onFinishResize applies the PiP bounds in new rotation. Bug: 281741016 Test: Swipe an auto-pip activity from landscape to portrait. No obvious flickering. Change-Id: I0f6cc6f09cecb3b3e2b6365827002f76ae13d57f --- .../java/com/android/server/wm/Transition.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java index bfd0d96a04abf..4f573e7ae644d 100644 --- a/services/core/java/com/android/server/wm/Transition.java +++ b/services/core/java/com/android/server/wm/Transition.java @@ -21,6 +21,8 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.ROTATION_UNDEFINED; +import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; +import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.INVALID_DISPLAY; @@ -959,8 +961,20 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener { true /* beforeStopping */)) { return false; } - return mController.mAtm.enterPictureInPictureMode(ar, ar.pictureInPictureArgs, - false /* fromClient */, true /* isAutoEnter */); + final int prevMode = ar.getTask().getWindowingMode(); + final boolean inPip = mController.mAtm.enterPictureInPictureMode(ar, + ar.pictureInPictureArgs, false /* fromClient */, true /* isAutoEnter */); + final int currentMode = ar.getTask().getWindowingMode(); + if (prevMode == WINDOWING_MODE_FULLSCREEN && currentMode == WINDOWING_MODE_PINNED + && mTransientLaunches != null + && ar.mDisplayContent.hasTopFixedRotationLaunchingApp()) { + // There will be a display configuration change after finishing this transition. + // Skip dispatching the change for PiP task to avoid its activity drawing for the + // intermediate state which will cause flickering. The final PiP bounds in new + // rotation will be applied by PipTransition. + ar.mDisplayContent.mPinnedTaskController.setEnterPipTransaction(null); + } + return inPip; } // Legacy pip-entry (not via isAutoEnterEnabled).