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

Commit c7f83672 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

Fix swipe-PiP-to-home transition with flipv2

Since the new seamless flipv2 is now being used by
config-at-end transitions, we have to adapt the animation
to it as well. Here, I reuse the enter animator to cache
the transforms for activity and task leashes and apply them
with the fraction=1.0.

Bug: 371249390
Flag: com.android.wm.shell.enable_pip2
Test: swipe-up to enter PiP from landscape to portrait
Change-Id: I2e3567a4730984187728d62be77491dbb3b3d120
parent aff00b6b
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -110,8 +110,7 @@ public class PipEnterAnimator extends ValueAnimator
            mAnimationStartCallback.run();
        }
        if (mStartTransaction != null) {
            onEnterAnimationUpdate(mInitScale, mInitPos, mInitCrop,
                    0f /* fraction */, mStartTransaction);
            onEnterAnimationUpdate(0f /* fraction */, mStartTransaction);
            mStartTransaction.apply();
        }
    }
@@ -119,8 +118,7 @@ public class PipEnterAnimator extends ValueAnimator
    @Override
    public void onAnimationEnd(@NonNull Animator animation) {
        if (mFinishTransaction != null) {
            onEnterAnimationUpdate(mInitScale, mInitPos, mInitCrop,
                    1f /* fraction */, mFinishTransaction);
            onEnterAnimationUpdate(1f /* fraction */, mFinishTransaction);
        }
        if (mAnimationEndCallback != null) {
            mAnimationEndCallback.run();
@@ -131,10 +129,20 @@ public class PipEnterAnimator extends ValueAnimator
    public void onAnimationUpdate(@NonNull ValueAnimator animation) {
        final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
        final float fraction = getAnimatedFraction();
        onEnterAnimationUpdate(mInitScale, mInitPos, mInitCrop, fraction, tx);
        onEnterAnimationUpdate(fraction, tx);
        tx.apply();
    }

    /**
     * Updates the transaction to reflect the state of PiP leash at a certain fraction during enter.
     *
     * @param fraction the fraction of the animator going from 0f to 1f.
     * @param tx the transaction to modify the transform of.
     */
    public void onEnterAnimationUpdate(float fraction, SurfaceControl.Transaction tx) {
        onEnterAnimationUpdate(mInitScale, mInitPos, mInitCrop, fraction, tx);
    }

    private void onEnterAnimationUpdate(PointF initScale, PointF initPos, Rect initCrop,
            float fraction, SurfaceControl.Transaction tx) {
        float scaleX = 1 + (initScale.x - 1) * (1 - fraction);
+28 −23
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.PictureInPictureParams;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
@@ -315,6 +314,14 @@ public class PipTransition extends PipTransitionController implements
        if (pipChange == null) {
            return false;
        }

        // We expect the PiP activity as a separate change in a config-at-end transition.
        TransitionInfo.Change pipActivityChange = getDeferConfigActivityChange(info,
                pipChange.getTaskInfo().getToken());
        if (pipActivityChange == null) {
            return false;
        }

        SurfaceControl pipLeash = pipChange.getLeash();
        Preconditions.checkNotNull(pipLeash, "Leash is null for swipe-up transition.");

@@ -332,27 +339,27 @@ public class PipTransition extends PipTransitionController implements
                            (destinationBounds.width() - overlaySize) / 2f,
                            (destinationBounds.height() - overlaySize) / 2f);
        }
        startTransaction.merge(finishTransaction);

        final int startRotation = pipChange.getStartRotation();
        final int endRotation = mPipDisplayLayoutState.getRotation();
        if (endRotation != startRotation) {
            boolean isClockwise = (endRotation - startRotation) == -ROTATION_270;

            // Display bounds were already updated to represent the final orientation,
            // so we just need to readjust the origin, and perform rotation about (0, 0).
            Rect displayBounds = mPipDisplayLayoutState.getDisplayBounds();
            int originTranslateX = isClockwise ? 0 : -displayBounds.width();
            int originTranslateY = isClockwise ? -displayBounds.height() : 0;
        final int delta = endRotation == ROTATION_UNDEFINED ? ROTATION_0
                : startRotation - endRotation;
        if (delta != ROTATION_0) {
            mPipTransitionState.setInFixedRotation(true);
            handleBoundsTypeFixedRotation(pipChange, pipActivityChange, endRotation);
        }

            Matrix transformTensor = new Matrix();
            final float[] matrixTmp = new float[9];
            transformTensor.setTranslate(originTranslateX + destinationBounds.left,
                    originTranslateY + destinationBounds.top);
            final float degrees = (endRotation - startRotation) * 90f;
            transformTensor.postRotate(degrees);
            startTransaction.setMatrix(pipLeash, transformTensor, matrixTmp);
        Rect sourceRectHint = null;
        if (pipChange.getTaskInfo() != null
                && pipChange.getTaskInfo().pictureInPictureParams != null) {
            sourceRectHint = pipChange.getTaskInfo().pictureInPictureParams.getSourceRectHint();
        }

        startTransaction.merge(finishTransaction);
        PipEnterAnimator animator = new PipEnterAnimator(mContext, pipLeash,
                startTransaction, finishTransaction, destinationBounds, sourceRectHint, delta);
        animator.setEnterStartState(pipChange, pipActivityChange);
        animator.onEnterAnimationUpdate(1.0f /* fraction */, startTransaction);
        startTransaction.apply();
        finishInner();
        return true;
@@ -398,7 +405,6 @@ public class PipTransition extends PipTransitionController implements
        }

        Rect endBounds = pipChange.getEndAbsBounds();
        Rect activityEndBounds = pipActivityChange.getEndAbsBounds();
        SurfaceControl pipLeash = mPipTransitionState.mPinnedTaskLeash;
        Preconditions.checkNotNull(pipLeash, "Leash is null for bounds transition.");

@@ -429,7 +435,8 @@ public class PipTransition extends PipTransitionController implements

        if (delta != ROTATION_0) {
            mPipTransitionState.setInFixedRotation(true);
            handleBoundsTypeFixedRotation(pipChange, pipActivityChange, fixedRotationChange);
            handleBoundsTypeFixedRotation(pipChange, pipActivityChange,
                    fixedRotationChange.getEndFixedRotation());
        }

        PipEnterAnimator animator = new PipEnterAnimator(mContext, pipLeash,
@@ -442,12 +449,10 @@ public class PipTransition extends PipTransitionController implements
    }

    private void handleBoundsTypeFixedRotation(TransitionInfo.Change pipTaskChange,
            TransitionInfo.Change pipActivityChange,
            TransitionInfo.Change fixedRotationChange) {
            TransitionInfo.Change pipActivityChange, int endRotation) {
        final Rect endBounds = pipTaskChange.getEndAbsBounds();
        final Rect endActivityBounds = pipActivityChange.getEndAbsBounds();
        int startRotation = pipTaskChange.getStartRotation();
        int endRotation = fixedRotationChange.getEndFixedRotation();

        // Cache the task to activity offset to potentially restore later.
        Point activityEndOffset = new Point(endActivityBounds.left - endBounds.left,