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

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

[PiP2] Properly scale corner radii while animating

If a task leash is scaled by some factor x,
we need to scale the corner raddi by a factor of (1/x)
to make the rounded corners look visually invariant.

We can enforce this during pinching (i.e. schedulerUserResizePip)
and during the resize animation in PipResizeAnimator.

Bug: 397958290
Flag: com.android.wm.shell.enable_pip2
Test: double tap to resize
Test: pinch PiP to resize

Change-Id: I3b4dcdea7e2e5362d2e6504a49de06d73895cb6a
parent ce308321
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -133,6 +133,18 @@ public class PipSurfaceTransactionHelper {
        return this;
    }

    /**
     * Operates the round corner radius on a given transaction and leash, scaled by bounds
     * @return same {@link PipSurfaceTransactionHelper} instance for method chaining
     */
    public PipSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash,
            Rect fromBounds, Rect toBounds) {
        final float scale = (float) (Math.hypot(fromBounds.width(), fromBounds.height())
                / Math.hypot(toBounds.width(), toBounds.height()));
        tx.setCornerRadius(leash, mCornerRadius * scale);
        return this;
    }

    /**
     * Operates the shadow radius on a given transaction and leash
     * @return same {@link PipSurfaceTransactionHelper} instance for method chaining
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ public class PipResizeAnimator extends ValueAnimator {
        transformTensor.postRotate(degrees, targetBounds.centerX(), targetBounds.centerY());

        tx.setMatrix(leash, transformTensor, mMatrixTmp)
                .setCornerRadius(leash, cornerRadius)
                .setCornerRadius(leash, cornerRadius / scaleX)
                .setShadowRadius(leash, shadowRadius);
    }

+4 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class PipScheduler {
    private PipTransitionController mPipTransitionController;
    private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
            mSurfaceControlTransactionFactory;
    private final PipSurfaceTransactionHelper mPipSurfaceTransactionHelper;

    @Nullable private Runnable mUpdateMovementBoundsRunnable;

@@ -75,6 +76,7 @@ public class PipScheduler {

        mSurfaceControlTransactionFactory =
                new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory();
        mPipSurfaceTransactionHelper = new PipSurfaceTransactionHelper(mContext);
        mPipAlphaAnimatorSupplier = PipAlphaAnimator::new;
    }

@@ -214,6 +216,8 @@ public class PipScheduler {
        transformTensor.postTranslate(toBounds.left, toBounds.top);
        transformTensor.postRotate(degrees, toBounds.centerX(), toBounds.centerY());

        mPipSurfaceTransactionHelper.round(tx, leash, mPipBoundsState.getBounds(), toBounds);

        tx.setMatrix(leash, transformTensor, mMatrixTmp);
        tx.apply();
    }