From 56647c4c75915f2dde42823dd86d6e23019efa0f Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 8 Dec 2022 00:50:07 +0800 Subject: [PATCH] Keep rotation transform for exiting PiP with fixed rotation The exact fix is the one line change in PipTransition. The example: The landscape PiP activity is expanding to fullscreen portrait. So at the end of animation, the task needs to keep the 90 degree transform. Otherwise it cannot match the area of portrait display. And then display will continue to update to landscape seamlessly and the default finish transaction will reset the rotation transform. The other changes are just small cleanup on the way. Bug: 260925940 Test: Enable shell transition. Use Chrome to play a Youtube video in fullscreen landscape. Enter PiP mode by swiping to home. Press the PiP window to expand to fullscreen landscape. There should be no flickering by inconsistent orientation. Change-Id: I241eb8fc59af4733794a0e0b4d4438e59edbfe10 --- .../Shell/src/com/android/wm/shell/pip/PipTransition.java | 6 ++++-- services/core/java/com/android/server/wm/Task.java | 8 +++----- services/core/java/com/android/server/wm/WindowToken.java | 2 -- 3 files changed, 7 insertions(+), 9 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 85bad174194c8..e6c7e101d0789 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 @@ -358,8 +358,10 @@ public class PipTransition extends PipTransitionController { WindowContainerTransaction wct = null; if (isOutPipDirection(direction)) { // Only need to reset surface properties. The server-side operations were already - // done at the start. - if (tx != null) { + // done at the start. But if it is running fixed rotation, there will be a seamless + // display transition later. So the last rotation transform needs to be kept to + // avoid flickering, and then the display transition will reset the transform. + if (tx != null && !mInFixedRotation) { mFinishTransaction.merge(tx); } } else { diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 84e30142f9835..c00dc8edff847 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -1924,7 +1924,6 @@ class Task extends TaskFragment { mTaskSupervisor.scheduleUpdateMultiWindowMode(this); } - final int newWinMode = getWindowingMode(); if (shouldStartChangeTransition(prevWinMode, mTmpPrevBounds)) { initializeChangeTransition(mTmpPrevBounds); } @@ -1938,16 +1937,15 @@ class Task extends TaskFragment { } } - if (pipChanging && wasInPictureInPicture) { + if (pipChanging && wasInPictureInPicture + && !mTransitionController.isShellTransitionsEnabled()) { // If the top activity is changing from PiP to fullscreen with fixed rotation, // clear the crop and rotation matrix of task because fixed rotation will handle // the transformation on activity level. This also avoids flickering caused by the // latency of fullscreen task organizer configuring the surface. final ActivityRecord r = topRunningActivity(); if (r != null && mDisplayContent.isFixedRotationLaunchingApp(r)) { - getSyncTransaction().setWindowCrop(mSurfaceControl, null) - .setCornerRadius(mSurfaceControl, 0f) - .setMatrix(mSurfaceControl, Matrix.IDENTITY_MATRIX, new float[9]); + resetSurfaceControlTransforms(); } } diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index 805559035ef9f..364ae16291bac 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -588,9 +588,7 @@ class WindowToken extends WindowContainer { .setCallsite("WindowToken.getOrCreateFixedRotationLeash") .build(); t.setPosition(leash, mLastSurfacePosition.x, mLastSurfacePosition.y); - t.show(leash); t.reparent(getSurfaceControl(), leash); - t.setAlpha(getSurfaceControl(), 1.f); mFixedRotationTransformLeash = leash; updateSurfaceRotation(t, rotation, mFixedRotationTransformLeash); return mFixedRotationTransformLeash;