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

Commit 77b450c9 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Expand PiP with pseudo source rect hint" into main

parents 1e202bd1 3af677f3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -149,11 +149,11 @@ object PipUtils {


    /**
     * Returns a fake source rect hint for animation purposes when app-provided one is invalid.
     * Returns a pseudo source rect hint for animation purposes when app-provided one is invalid.
     * Resulting adjusted source rect hint lets the app icon in the content overlay to stay visible.
     */
    @JvmStatic
    fun getEnterPipWithOverlaySrcRectHint(appBounds: Rect, aspectRatio: Float): Rect {
    fun getPseudoSourceRectHint(appBounds: Rect, aspectRatio: Float): Rect {
        val appBoundsAspRatio = appBounds.width().toFloat() / appBounds.height()
        val width: Int
        val height: Int
+1 −1
Original line number Diff line number Diff line
@@ -675,7 +675,7 @@ public class PipAnimationController {
                // This is done for entering case only.
                if (isInPipDirection(direction)) {
                    final float aspectRatio = endBounds.width() / (float) endBounds.height();
                    adjustedSourceRectHint.set(PipUtils.getEnterPipWithOverlaySrcRectHint(
                    adjustedSourceRectHint.set(PipUtils.getPseudoSourceRectHint(
                            startBounds, aspectRatio));
                }
            } else {
+17 −9
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import androidx.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
import com.android.wm.shell.R;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.pip2.PipSurfaceTransactionHelper;
import com.android.wm.shell.shared.animation.Interpolators;

@@ -55,7 +56,7 @@ public class PipExpandAnimator extends ValueAnimator {
    private final Rect mStartBounds = new Rect();
    private final Rect mEndBounds = new Rect();

    @Nullable private final Rect mSourceRectHint;
    private final Rect mSourceRectHint = new Rect();
    private final Rect mSourceRectHintInsets = new Rect();
    private final Rect mZeroInsets = new Rect(0, 0, 0, 0);

@@ -134,15 +135,22 @@ public class PipExpandAnimator extends ValueAnimator {
        mRotation = rotation;
        mIsPipInDesktopMode = isPipInDesktopMode;

        mSourceRectHint = sourceRectHint != null ? new Rect(sourceRectHint) : null;
        if (mSourceRectHint != null) {
        if (sourceRectHint == null || sourceRectHint.isEmpty()) {
            // Similar to enter animation, use a pseudo source rect hint on exit if app does not
            // provide one to get a unified exit animation experience.
            final float aspectRatio = mStartBounds.width() / (float) mStartBounds.height();
            mSourceRectHint.set(
                    PipUtils.getPseudoSourceRectHint(mBaseBounds, aspectRatio));
            mSourceRectHint.offsetTo(mBaseBounds.left, mBaseBounds.top);
        } else {
            mSourceRectHint.set(sourceRectHint);
        }
        mSourceRectHintInsets.set(
                mSourceRectHint.left - mBaseBounds.left,
                mSourceRectHint.top - mBaseBounds.top,
                mBaseBounds.right - mSourceRectHint.right,
                mBaseBounds.bottom - mSourceRectHint.bottom
        );
        }

        mSurfaceControlTransactionFactory =
                new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory();
+1 −1
Original line number Diff line number Diff line
@@ -790,7 +790,7 @@ public class PipTransition extends PipTransitionController implements
            // app icon overlay animation.
            float aspectRatio = mPipBoundsAlgorithm.getAspectRatioOrDefault(params);
            adjustedSourceRectHint.set(
                    PipUtils.getEnterPipWithOverlaySrcRectHint(startBounds, aspectRatio));
                    PipUtils.getPseudoSourceRectHint(startBounds, aspectRatio));
        }
        return adjustedSourceRectHint;
    }
+52 −0
Original line number Diff line number Diff line
@@ -173,6 +173,58 @@ public class PipExpandAnimatorTest {
        verify(mMockEndCallback).run();
    }

    @Test
    public void onAnimationStart_withSourceRectHint_cropToHint() {
        mRotation = Surface.ROTATION_0;
        mBaseBounds = new Rect(0, 0, 1_000, 2_000);
        mSourceRectHint = new Rect(0, 0, 1_000, 1_000);
        mStartBounds = new Rect(500, 1_000, 1_000, 2_000);
        mEndBounds = new Rect(mBaseBounds);
        mPipExpandAnimator = new PipExpandAnimator(mMockContext,
                new PipSurfaceTransactionHelper(mMockContext), mTestLeash,
                mMockStartTransaction, mMockFinishTransaction,
                mBaseBounds, mStartBounds, mEndBounds, mSourceRectHint,
                mRotation, false /* isPipInDesktopMode */);
        mPipExpandAnimator.setSurfaceControlTransactionFactory(mMockFactory);

        mPipExpandAnimator.setAnimationStartCallback(mMockStartCallback);
        mPipExpandAnimator.setAnimationEndCallback(mMockEndCallback);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            // animator is not started intentionally to avoid double invocation
            clearInvocations(mMockTransaction);
            mPipExpandAnimator.setCurrentFraction(0f);
        });

        verify(mMockTransaction).setCrop(mTestLeash, mSourceRectHint);
    }

    @Test
    public void onAnimationStart_withoutSourceRectHint_cropToPseudoHint() {
        mRotation = Surface.ROTATION_0;
        mBaseBounds = new Rect(0, 0, 1_000, 2_000);
        mSourceRectHint = null;
        // Set the aspect ratio to be 1:1, pseudo bounds would be (0, 0 - 1000, 1000)
        mStartBounds = new Rect(500, 1_000, 1_000, 1_500);
        final Rect pseudoSourceRectHint = new Rect(0, 0, 1_000, 1_000);
        mEndBounds = new Rect(mBaseBounds);
        mPipExpandAnimator = new PipExpandAnimator(mMockContext,
                new PipSurfaceTransactionHelper(mMockContext), mTestLeash,
                mMockStartTransaction, mMockFinishTransaction,
                mBaseBounds, mStartBounds, mEndBounds, mSourceRectHint,
                mRotation, false /* isPipInDesktopMode */);
        mPipExpandAnimator.setSurfaceControlTransactionFactory(mMockFactory);

        mPipExpandAnimator.setAnimationStartCallback(mMockStartCallback);
        mPipExpandAnimator.setAnimationEndCallback(mMockEndCallback);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            // animator is not started intentionally to avoid double invocation
            clearInvocations(mMockTransaction);
            mPipExpandAnimator.setCurrentFraction(0f);
        });

        verify(mMockTransaction).setCrop(mTestLeash, pseudoSourceRectHint);
    }

    @Test
    public void onAnimationUpdate_expand_setRoundCornersWithoutShadow() {
        mRotation = Surface.ROTATION_0;