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

Commit b5a7a126 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Position PiP animation based on actual coordinates

In the previous patchset, we assumed the left/top to be 0/0 which is not
always the case. This could break, for instance, in ActivityEmbedding
setup, where the pip-ing app is on the left side.

Changed also to use the Math.floor value for positions at the beginning
of the animation to avoid rounding errors (1 pixel off).

Flag: NONE test fix
Bug: 345327260
Test: atest FlickerTestsOther:SecondaryActivityEnterPipTest \
            WMShellFlickerTestsPip1 \
            WMShellFlickerTestsPip2 \
            WMShellFlickerTestsPip3 \
            PipAnimationControllerTest
Change-Id: I74739af591dd546c8cb35123fa580cfc6625fca4
parent 4031a2df
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.internal.protolog.common.ProtoLog
import com.android.wm.shell.Flags
import com.android.wm.shell.protolog.ShellProtoLogGroup
import kotlin.math.abs
import kotlin.math.roundToInt

/** A class that includes convenience methods.  */
object PipUtils {
@@ -149,16 +150,16 @@ object PipUtils {
        val appBoundsAspRatio = appBounds.width().toFloat() / appBounds.height()
        val width: Int
        val height: Int
        var left = 0
        var top = 0
        var left = appBounds.left
        var top = appBounds.top
        if (appBoundsAspRatio < aspectRatio) {
            width = appBounds.width()
            height = Math.round(width / aspectRatio)
            top = (appBounds.height() - height) / 2
            height = (width / aspectRatio).roundToInt()
            top = appBounds.top + (appBounds.height() - height) / 2
        } else {
            height = appBounds.height()
            width = Math.round(height * aspectRatio)
            left = (appBounds.width() - width) / 2
            width = (height * aspectRatio).roundToInt()
            left = appBounds.left + (appBounds.width() - width) / 2
        }
        return Rect(left, top, left + width, top + height)
    }
+9 −6
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ public class PipSurfaceTransactionHelper {
        mTmpDestinationRect.inset(insets);
        // Scale to the bounds no smaller than the destination and offset such that the top/left
        // of the scaled inset source rect aligns with the top/left of the destination bounds
        final float scale, left, top;
        final float scale;
        if (isInPipDirection
                && sourceRectHint != null && sourceRectHint.width() < sourceBounds.width()) {
            // scale by sourceRectHint if it's not edge-to-edge, for entering PiP transition only.
@@ -148,14 +148,17 @@ public class PipSurfaceTransactionHelper {
                    ? (float) destinationBounds.width() / sourceBounds.width()
                    : (float) destinationBounds.height() / sourceBounds.height();
            scale = (1 - fraction) * startScale + fraction * endScale;
            left = destinationBounds.left - insets.left * scale;
            top = destinationBounds.top - insets.top * scale;
        } else {
            scale = Math.max((float) destinationBounds.width() / sourceBounds.width(),
                    (float) destinationBounds.height() / sourceBounds.height());
            // Work around the rounding error by fix the position at very beginning.
            left = scale == 1 ? 0 : destinationBounds.left - insets.left * scale;
            top = scale == 1 ? 0 : destinationBounds.top - insets.top * scale;
        }
        float left = destinationBounds.left - insets.left * scale;
        float top = destinationBounds.top - insets.top * scale;
        if (scale == 1) {
            // Work around the 1 pixel off error by rounding the position down at very beginning.
            // We noticed such error from flicker tests, not visually.
            left = sourceBounds.left;
            top = sourceBounds.top;
        }
        mTmpTransform.setScale(scale, scale);
        tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
+4 −1
Original line number Diff line number Diff line
@@ -88,8 +88,11 @@ public class PipAnimationControllerTest extends ShellTestCase {

    @Test
    public void getAnimator_withBounds_returnBoundsAnimator() {
        final Rect baseValue = new Rect(0, 0, 100, 100);
        final Rect startValue = new Rect(0, 0, 100, 100);
        final Rect endValue1 = new Rect(100, 100, 200, 200);
        final PipAnimationController.PipTransitionAnimator animator = mPipAnimationController
                .getAnimator(mTaskInfo, mLeash, new Rect(), new Rect(), new Rect(), null,
                .getAnimator(mTaskInfo, mLeash, baseValue, startValue, endValue1, null,
                        TRANSITION_DIRECTION_TO_PIP, 0, ROTATION_0);

        assertEquals("Expect ANIM_TYPE_BOUNDS animation",