From aa441f5ebff7a8670a542b907c196fc9758afbde Mon Sep 17 00:00:00 2001 From: Mateusz Cicheński Date: Tue, 30 Jan 2024 06:07:51 +0000 Subject: Remove the scaling code This causes a conflict with PipTransition code that is unaware of the scaling factor being applied. Due to the order of actions the PipBounds are being updated first in onDisplayChangedUnchecked() with the scale, and later on in the PipTransition.startAnimation for unhandled case. That latter call uses the pipChange.getEndAbsBounds() value though, which is different than what the scaling code set. As a result the pipBoundsScale is being updated with new value that is smaller/bigger than previous percentage, leading to decrease/increase in PiP size upon screen rotation. Additionally the setWindowCrop() call issued from PipTransition for some reason does not trigger a client call to relayout, so the PiP surface ends up not matching what the final task bounds are, which is visible either as the PiP menu overlay being smaller than e.g. video content OR as shadow that goes beyond the video content (and has only one rounded corner). Finally this code also affect fixed rotation enter PiP. Reverting that change while we figure out a better way to rescale the size. Fixes 3 issues, removes the percentage size adjustment on fold/unfold, and also keeps the PiP size upon screen rotation. Bug: 322091225 Bug: 319083003 Bug: 308093519 Change-Id: I6e405a071fc306c85d722e3f546e6b0e21fd86cb Test: manual Flag: none --- .../android/wm/shell/pip/phone/PipController.java | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index 238e6b5bf2af..c5a01025dcdd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -797,14 +797,20 @@ public class PipController implements PipTransitionController.PipTransitionCallb mPipBoundsAlgorithm.getMovementBounds(postChangeBounds), mPipBoundsState.getStashedState()); - updateDisplayLayout.run(); + // Scale PiP on density dpi change, so it appears to be the same size physically. + final boolean densityDpiChanged = + mPipDisplayLayoutState.getDisplayLayout().densityDpi() != 0 + && (mPipDisplayLayoutState.getDisplayLayout().densityDpi() + != layout.densityDpi()); + if (densityDpiChanged) { + final float scale = (float) layout.densityDpi() + / mPipDisplayLayoutState.getDisplayLayout().densityDpi(); + postChangeBounds.set(0, 0, + (int) (postChangeBounds.width() * scale), + (int) (postChangeBounds.height() * scale)); + } - // Resize the PiP bounds to be at the same scale relative to the new size spec. For - // example, if PiP was resized to 90% of the maximum size on the previous layout, - // make sure it is 90% of the new maximum size spec. - postChangeBounds.set(0, 0, - (int) (mPipBoundsState.getMaxSize().x * mPipBoundsState.getBoundsScale()), - (int) (mPipBoundsState.getMaxSize().y * mPipBoundsState.getBoundsScale())); + updateDisplayLayout.run(); // Calculate the PiP bounds in the new orientation based on same fraction along the // rotated movement bounds. @@ -821,10 +827,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb mPipBoundsState.setHasUserResizedPip(true); mTouchHandler.setUserResizeBounds(postChangeBounds); - final boolean densityDpiChanged = - mPipDisplayLayoutState.getDisplayLayout().densityDpi() != 0 - && (mPipDisplayLayoutState.getDisplayLayout().densityDpi() - != layout.densityDpi()); if (densityDpiChanged) { // Using PipMotionHelper#movePip directly here may cause race condition since // the app content in PiP mode may or may not be updated for the new density dpi. -- cgit v1.2.3-59-g8ed1b