Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8450647 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Use source rect hint from stopSwipePipToHome of home

So shell side doesn't need to simulate the same calculation from
different info (e.g. based on transition info). To make the crop
of animation by home and the transition end state have the same
appearance.

Bug: 331315278
Test: Assume the target app support auto-pip and it doesn't draw
      under display cutout.
      E.g. LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
      Enter PiP from 90 degrees to home with 0 degrees.
      The left side of pip should not flicker.
Change-Id: I6a58d42c4b57dfcf42f2e656ce72185da7c56738
parent bf22c39a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -53,9 +53,11 @@ interface IPip {
     * @param destinationBounds the destination bounds the PiP window lands into
     * @param overlay an optional overlay to fade out after entering PiP
     * @param appBounds the bounds used to set the buffer size of the optional content overlay
     * @param sourceRectHint the bounds to show in the transition to PiP
     */
    oneway void stopSwipePipToHome(int taskId, in ComponentName componentName,
            in Rect destinationBounds, in SurfaceControl overlay, in Rect appBounds) = 2;
            in Rect destinationBounds, in SurfaceControl overlay, in Rect appBounds,
            in Rect sourceRectHint) = 2;

    /**
     * Notifies the swiping Activity to PiP onto home transition is aborted
+20 −1
Original line number Diff line number Diff line
@@ -373,6 +373,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    @NonNull
    final Rect mAppBounds = new Rect();

    /** The source rect hint from stopSwipePipToHome(). */
    @Nullable
    private Rect mSwipeSourceRectHint;

    public PipTaskOrganizer(Context context,
            @NonNull SyncTransactionQueue syncTransactionQueue,
            @NonNull PipTransitionState pipTransitionState,
@@ -504,7 +508,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
     * Expect {@link #onTaskAppeared(ActivityManager.RunningTaskInfo, SurfaceControl)} afterwards.
     */
    public void stopSwipePipToHome(int taskId, ComponentName componentName, Rect destinationBounds,
            SurfaceControl overlay, Rect appBounds) {
            SurfaceControl overlay, Rect appBounds, Rect sourceRectHint) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "stopSwipePipToHome: %s, stat=%s", componentName, mPipTransitionState);
        // do nothing if there is no startSwipePipToHome being called before
@@ -513,6 +517,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        }
        mPipBoundsState.setBounds(destinationBounds);
        setContentOverlay(overlay, appBounds);
        mSwipeSourceRectHint = sourceRectHint;
        if (ENABLE_SHELL_TRANSITIONS && overlay != null) {
            // With Shell transition, the overlay was attached to the remote transition leash, which
            // will be removed when the current transition is finished, so we need to reparent it
@@ -529,6 +534,20 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        }
    }

    /**
     * Returns non-null Rect if the pip is entering from swipe-to-home with a specified source hint.
     * This also consumes the rect hint.
     */
    @Nullable
    Rect takeSwipeSourceRectHint() {
        final Rect sourceRectHint = mSwipeSourceRectHint;
        if (sourceRectHint == null || sourceRectHint.isEmpty()) {
            return null;
        }
        mSwipeSourceRectHint = null;
        return mPipTransitionState.getInSwipePipToHomeTransition() ? sourceRectHint : null;
    }

    private void mayRemoveContentOverlay(SurfaceControl overlay) {
        final WeakReference<SurfaceControl> overlayRef = new WeakReference<>(overlay);
        final long timeoutDuration = (mEnterAnimationDuration
+5 −2
Original line number Diff line number Diff line
@@ -989,8 +989,11 @@ public class PipTransition extends PipTransitionController {
        final Rect currentBounds = pipChange.getStartAbsBounds();

        int rotationDelta = deltaRotation(startRotation, endRotation);
        Rect sourceHintRect = PipBoundsAlgorithm.getValidSourceHintRect(
        Rect sourceHintRect = mPipOrganizer.takeSwipeSourceRectHint();
        if (sourceHintRect == null) {
            sourceHintRect = PipBoundsAlgorithm.getValidSourceHintRect(
                    taskInfo.pictureInPictureParams, currentBounds, destinationBounds);
        }
        if (rotationDelta != Surface.ROTATION_0
                && endRotation != mPipDisplayLayoutState.getRotation()) {
            // Computes the destination bounds in new rotation.
+6 −4
Original line number Diff line number Diff line
@@ -998,9 +998,9 @@ public class PipController implements PipTransitionController.PipTransitionCallb
    }

    private void stopSwipePipToHome(int taskId, ComponentName componentName, Rect destinationBounds,
            SurfaceControl overlay, Rect appBounds) {
            SurfaceControl overlay, Rect appBounds, Rect sourceRectHint) {
        mPipTaskOrganizer.stopSwipePipToHome(taskId, componentName, destinationBounds, overlay,
                appBounds);
                appBounds, sourceRectHint);
    }

    private void abortSwipePipToHome(int taskId, ComponentName componentName) {
@@ -1287,13 +1287,15 @@ public class PipController implements PipTransitionController.PipTransitionCallb

        @Override
        public void stopSwipePipToHome(int taskId, ComponentName componentName,
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds) {
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds,
                Rect sourceRectHint) {
            if (overlay != null) {
                overlay.setUnreleasedWarningCallSite("PipController.stopSwipePipToHome");
            }
            executeRemoteCallWithTaskPermission(mController, "stopSwipePipToHome",
                    (controller) -> controller.stopSwipePipToHome(
                            taskId, componentName, destinationBounds, overlay, appBounds));
                            taskId, componentName, destinationBounds, overlay, appBounds,
                            sourceRectHint));
        }

        @Override
+6 −3
Original line number Diff line number Diff line
@@ -193,7 +193,8 @@ public class PipController implements ConfigurationChangeListener,
    }

    private void onSwipePipToHomeAnimationStart(int taskId, ComponentName componentName,
            Rect destinationBounds, SurfaceControl overlay, Rect appBounds) {
            Rect destinationBounds, SurfaceControl overlay, Rect appBounds,
            Rect sourceRectHint) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "onSwipePipToHomeAnimationStart: %s", componentName);
        mPipScheduler.setInSwipePipToHomeTransition(true);
@@ -234,13 +235,15 @@ public class PipController implements ConfigurationChangeListener,

        @Override
        public void stopSwipePipToHome(int taskId, ComponentName componentName,
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds) {
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds,
                Rect sourceRectHint) {
            if (overlay != null) {
                overlay.setUnreleasedWarningCallSite("PipController.stopSwipePipToHome");
            }
            executeRemoteCallWithTaskPermission(mController, "stopSwipePipToHome",
                    (controller) -> controller.onSwipePipToHomeAnimationStart(
                            taskId, componentName, destinationBounds, overlay, appBounds));
                            taskId, componentName, destinationBounds, overlay, appBounds,
                            sourceRectHint));
        }

        @Override