diff options
| author | 2024-10-02 18:49:15 +0000 | |
|---|---|---|
| committer | 2024-10-02 18:49:15 +0000 | |
| commit | 836779f2ec7d3487ea423a8b291546df2ebd06b2 (patch) | |
| tree | 82dc7f0b24d65e5e18321eb52058579031a79f42 | |
| parent | bb12f5c3ff9eeaf854a050f6f7d6e047ea7c5c37 (diff) | |
| parent | 73c182037e115e2a4c7b5216edb98522943447f0 (diff) | |
Merge "Refactor swipe-pip-to-home transition" into main
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java index 1b9bf2acbb96..dc0bc7816859 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java @@ -304,54 +304,28 @@ public class PipTransition extends PipTransitionController implements if (pipChange == null) { return false; } - WindowContainerToken pipTaskToken = pipChange.getContainer(); SurfaceControl pipLeash = pipChange.getLeash(); + Preconditions.checkNotNull(pipLeash, "Leash is null for swipe-up transition."); - if (pipTaskToken == null || pipLeash == null) { - return false; - } - - SurfaceControl overlayLeash = mPipTransitionState.getSwipePipToHomeOverlay(); - PictureInPictureParams params = pipChange.getTaskInfo().pictureInPictureParams; - - Rect appBounds = mPipTransitionState.getSwipePipToHomeAppBounds(); - Rect destinationBounds = pipChange.getEndAbsBounds(); - - float aspectRatio = pipChange.getTaskInfo().pictureInPictureParams.getAspectRatioFloat(); - - // We fake the source rect hint when the one prvided by the app is invalid for - // the animation with an app icon overlay. - Rect animationSrcRectHint = overlayLeash == null ? params.getSourceRectHint() - : PipUtils.getEnterPipWithOverlaySrcRectHint(appBounds, aspectRatio); - - WindowContainerTransaction finishWct = new WindowContainerTransaction(); - SurfaceControl.Transaction tx = new SurfaceControl.Transaction(); - - final float scale = (float) destinationBounds.width() / animationSrcRectHint.width(); - startTransaction.setWindowCrop(pipLeash, animationSrcRectHint); - startTransaction.setPosition(pipLeash, - destinationBounds.left - animationSrcRectHint.left * scale, - destinationBounds.top - animationSrcRectHint.top * scale); - startTransaction.setScale(pipLeash, scale, scale); - - if (overlayLeash != null) { + final Rect destinationBounds = pipChange.getEndAbsBounds(); + final SurfaceControl swipePipToHomeOverlay = mPipTransitionState.getSwipePipToHomeOverlay(); + if (swipePipToHomeOverlay != null) { final int overlaySize = PipContentOverlay.PipAppIconOverlay.getOverlaySize( mPipTransitionState.getSwipePipToHomeAppBounds(), destinationBounds); - - // Overlay needs to be adjusted once a new draw comes in resetting surface transform. - tx.setScale(overlayLeash, 1f, 1f); - tx.setPosition(overlayLeash, (destinationBounds.width() - overlaySize) / 2f, - (destinationBounds.height() - overlaySize) / 2f); + // It is possible we reparent the PIP activity to a new PIP task (in multi-activity + // apps), so we should also reparent the overlay to the final PIP task. + startTransaction.reparent(swipePipToHomeOverlay, pipLeash) + .setLayer(swipePipToHomeOverlay, Integer.MAX_VALUE) + .setScale(swipePipToHomeOverlay, 1f, 1f) + .setPosition(swipePipToHomeOverlay, + (destinationBounds.width() - overlaySize) / 2f, + (destinationBounds.height() - overlaySize) / 2f); } - startTransaction.apply(); - tx.addTransactionCommittedListener(mPipScheduler.getMainExecutor(), - this::onClientDrawAtTransitionEnd); - finishWct.setBoundsChangeTransaction(pipTaskToken, tx); - - // Note that finishWct should be free of any actual WM state changes; we are using - // it for syncing with the client draw after delayed configuration changes are dispatched. - finishCallback.onTransitionFinished(finishWct.isEmpty() ? null : finishWct); + startTransaction.merge(finishTransaction); + startTransaction.apply(); + finishCallback.onTransitionFinished(null /* finishWct */); + onClientDrawAtTransitionEnd(); return true; } |