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

Commit 0f56f674 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

Refactor PiP2 resize transitions

Refactor PiP2 resize transitions, e.g.
double-tap, flings, and pinch-to-resize to
use config-at-end flipv2.

This should also allow for faster touch interaction
re-enabling than before with double-taps and pinches,
since the flipv2 moves task maniipulation ownership to Shell.

Also cleaned up PipTransition and PipScheduler to simplify resize logic.

Bug: 376104088
Flag: com.android.wm.shell.enable_pip2
Test: enter PiP and resize PiP by double-tap/pinch
Change-Id: I1f43f639193ab2ac189f23957cf5b82f598afb5f
parent a545efde
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -368,10 +368,8 @@ public abstract class PipTransitionController implements Transitions.TransitionH

    /**
     * Finish the current transition if possible.
     *
     * @param tx transaction to be applied with a potentially new draw after finishing.
     */
    public void finishTransition(@Nullable SurfaceControl.Transaction tx) {
    public void finishTransition() {
    }

    /**
+1 −16
Original line number Diff line number Diff line
@@ -192,22 +192,7 @@ public class PipEnterAnimator extends ValueAnimator
     * calculated differently from generic transitions.
     * @param pipChange PiP change received as a transition target.
     */
    public void setEnterStartState(@NonNull TransitionInfo.Change pipChange,
            @NonNull TransitionInfo.Change pipActivityChange) {
        PipUtils.calcEndTransform(pipActivityChange, pipChange, mInitActivityScale,
                mInitActivityPos);
        if (mStartTransaction != null && pipActivityChange.getLeash() != null) {
            mStartTransaction.setCrop(pipActivityChange.getLeash(), null);
            mStartTransaction.setScale(pipActivityChange.getLeash(), mInitActivityScale.x,
                    mInitActivityScale.y);
            mStartTransaction.setPosition(pipActivityChange.getLeash(), mInitActivityPos.x,
                    mInitActivityPos.y);
            mFinishTransaction.setCrop(pipActivityChange.getLeash(), null);
            mFinishTransaction.setScale(pipActivityChange.getLeash(), mInitActivityScale.x,
                    mInitActivityScale.y);
            mFinishTransaction.setPosition(pipActivityChange.getLeash(), mInitActivityPos.x,
                    mInitActivityPos.y);
        }
    public void setEnterStartState(@NonNull TransitionInfo.Change pipChange) {
        PipUtils.calcStartTransform(pipChange, mInitScale, mInitPos, mInitCrop);
    }

+6 −9
Original line number Diff line number Diff line
@@ -752,11 +752,11 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                                PipTransition.BOUNDS_CHANGE_JUMPCUT_DURATION));
                break;
            case PipTransitionState.CHANGING_PIP_BOUNDS:
                SurfaceControl.Transaction startTx = extra.getParcelable(
                final SurfaceControl.Transaction startTx = extra.getParcelable(
                        PipTransition.PIP_START_TX, SurfaceControl.Transaction.class);
                SurfaceControl.Transaction finishTx = extra.getParcelable(
                final SurfaceControl.Transaction finishTx = extra.getParcelable(
                        PipTransition.PIP_FINISH_TX, SurfaceControl.Transaction.class);
                Rect destinationBounds = extra.getParcelable(
                final Rect destinationBounds = extra.getParcelable(
                        PipTransition.PIP_DESTINATION_BOUNDS, Rect.class);
                final int duration = extra.getInt(ANIMATING_BOUNDS_CHANGE_DURATION,
                        PipTransition.BOUNDS_CHANGE_JUMPCUT_DURATION);
@@ -794,7 +794,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        cleanUpHighPerfSessionMaybe();

        // Signal that the transition is done - should update transition state by default.
        mPipScheduler.scheduleFinishResizePip(destinationBounds, false /* configAtEnd */);
        mPipScheduler.scheduleFinishResizePip(destinationBounds);
    }

    private void startResizeAnimation(SurfaceControl.Transaction startTx,
@@ -803,11 +803,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        Preconditions.checkState(pipLeash != null,
                "No leash cached by mPipTransitionState=" + mPipTransitionState);

        startTx.setWindowCrop(pipLeash, mPipBoundsState.getBounds().width(),
                mPipBoundsState.getBounds().height());

        PipResizeAnimator animator = new PipResizeAnimator(mContext, pipLeash,
                startTx, finishTx, mPipBoundsState.getBounds(), mPipBoundsState.getBounds(),
                startTx, finishTx, destinationBounds, mPipBoundsState.getBounds(),
                destinationBounds, duration, 0f /* angle */);
        animator.setAnimationEndCallback(() -> {
            // In case an ongoing drag/fling was present before a deterministic resize transition
@@ -818,7 +815,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,

            cleanUpHighPerfSessionMaybe();
            // Signal that we are done with resize transition
            mPipScheduler.scheduleFinishResizePip(destinationBounds, true /* configAtEnd */);
            mPipScheduler.scheduleFinishResizePip(destinationBounds);
        });
        animator.start();
    }
+8 −10
Original line number Diff line number Diff line
@@ -535,28 +535,26 @@ public class PipResizeGestureHandler implements
                Preconditions.checkState(pipLeash != null,
                        "No leash cached by mPipTransitionState=" + mPipTransitionState);

                SurfaceControl.Transaction startTx = extra.getParcelable(
                final SurfaceControl.Transaction startTx = extra.getParcelable(
                        PipTransition.PIP_START_TX, SurfaceControl.Transaction.class);
                SurfaceControl.Transaction finishTx = extra.getParcelable(
                final SurfaceControl.Transaction finishTx = extra.getParcelable(
                        PipTransition.PIP_FINISH_TX, SurfaceControl.Transaction.class);
                final Rect destinationBounds = extra.getParcelable(
                        PipTransition.PIP_DESTINATION_BOUNDS, Rect.class);
                final int duration = extra.getInt(ANIMATING_BOUNDS_CHANGE_DURATION,
                        PipTransition.BOUNDS_CHANGE_JUMPCUT_DURATION);

                startTx.setWindowCrop(pipLeash, mPipBoundsState.getBounds().width(),
                        mPipBoundsState.getBounds().height());

                PipResizeAnimator animator = new PipResizeAnimator(mContext, pipLeash,
                        startTx, finishTx, mPipBoundsState.getBounds(), mStartBoundsAfterRelease,
                        mLastResizeBounds, duration, mAngle);
                        startTx, finishTx, destinationBounds, mStartBoundsAfterRelease,
                        destinationBounds, duration, mAngle);
                animator.setAnimationEndCallback(() -> {
                    // All motion operations have actually finished, so make bounds cache updates.
                    mUserResizeBounds.set(mLastResizeBounds);
                    mUserResizeBounds.set(destinationBounds);
                    resetState();
                    cleanUpHighPerfSessionMaybe();

                    // Signal that we are done with resize transition
                    mPipScheduler.scheduleFinishResizePip(
                            mLastResizeBounds, true /* configAtEnd */);
                    mPipScheduler.scheduleFinishResizePip(destinationBounds);
                });
                animator.start();
                break;
+4 −14
Original line number Diff line number Diff line
@@ -175,22 +175,12 @@ public class PipScheduler {
     * Note that we do not allow any actual WM Core changes at this point.
     *
     * @param toBounds destination bounds used only for internal state updates - not sent to Core.
     * @param configAtEnd true if we are waiting for config updates at the end of the transition.
     */
    public void scheduleFinishResizePip(Rect toBounds, boolean configAtEnd) {
        // Make updates to the internal state to reflect new bounds
    public void scheduleFinishResizePip(Rect toBounds) {
        // Make updates to the internal state to reflect new bounds before updating any transitions
        // related state; transition state updates can trigger callbacks that use the cached bounds.
        onFinishingPipResize(toBounds);

        SurfaceControl.Transaction tx = null;
        if (configAtEnd) {
            tx = new SurfaceControl.Transaction();
            tx.addTransactionCommittedListener(mMainExecutor, () -> {
                mPipTransitionState.setState(PipTransitionState.CHANGED_PIP_BOUNDS);
            });
        } else {
            mPipTransitionState.setState(PipTransitionState.CHANGED_PIP_BOUNDS);
        }
        mPipTransitionController.finishTransition(tx);
        mPipTransitionController.finishTransition();
    }

    /**
Loading