From 5103f76ae265f3474a0c9079c5d9748d3467753a Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 22 May 2023 20:32:11 +0800 Subject: [PATCH] Reduce PiP flickering when switch apps with orientation change The fade state of PiP is only known by shell side. So the default finish transaction of display transition will reset alpha to 1. That may cause one frame to flicker before the fade animation animates from alpha 0 to 1. So for display transition, keep the PiP invisible if it was faded out (it should be only from fixed rotation). And then after the display transition is done, fadeExistingPip(true) will be called to restore the visibility without overlapping with transition. Bug: 283757841 Test: Make an app enter PiP. Launch a landscape app from portrait home. And finish the landscape app. The PiP should not show one visible frame before the fade-in animation runs. Change-Id: I4f0bd06a29c2537c0e3431a0e5be7e00ae7cd9e7 --- .../src/com/android/wm/shell/pip/PipTransition.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index bfc1fb905adeb..3c7ce3c32a88c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -249,11 +249,6 @@ public class PipTransition extends PipTransitionController { finishTransaction); } - // Fade in the fadeout PIP when the fixed rotation is finished. - if (mPipTransitionState.isInPip() && !mInFixedRotation && mHasFadeOut) { - fadeExistingPip(true /* show */); - } - return false; } @@ -1056,6 +1051,12 @@ public class PipTransition extends PipTransitionController { .crop(finishTransaction, leash, destBounds) .round(finishTransaction, leash, isInPip) .shadow(finishTransaction, leash, isInPip); + // Make sure the PiP keeps invisible if it was faded out. If it needs to fade in, that will + // be handled by onFixedRotationFinished(). + if (isInPip && mHasFadeOut) { + startTransaction.setAlpha(leash, 0f); + finishTransaction.setAlpha(leash, 0f); + } } /** Hides and shows the existing PIP during fixed rotation transition of other activities. */