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

Commit 2e9b38be authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Crop the center when no source rect hint

When there is no source rect hint, forge a crop that matches the given
aspect ratio and centered, therefore we can use a consolidated animation
path and fix the issue with the round corner, which was inproperly
scaled in the past.

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/cfYT91jFXdx5Fd5C1AwOQH
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/c9bvKYnQFaVszr8ouxGkZ6
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/byGhNOhBrN2fVWiSIctxw6
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/hTaRKx1rNQ2WGKqnll0lxI
Flag: NONE bug fix
Bug: 298409662
Test: atest WMShellFlickerTestsPip2:EnterPipViaAppUiButtonTest \
      WMShellFlickerTestsPip2:ExitPipToAppViaIntentTest
Test: Test the overlay in both gesture and button navigation mode,\
      with both YouTube and Google Maps,\
      in both folded and unfolded mode.
Change-Id: Idf191704f6e04d562db8c28d41765da1944c4b68
parent f7caa4df
Loading
Loading
Loading
Loading
+32 −13
Original line number Diff line number Diff line
@@ -583,7 +583,7 @@ public class PipAnimationController {
        }

        static PipTransitionAnimator<Rect> ofBounds(TaskInfo taskInfo, SurfaceControl leash,
                Rect baseValue, Rect startValue, Rect endValue, Rect sourceHintRect,
                Rect baseValue, Rect startValue, Rect endValue, Rect sourceRectHint,
                @PipAnimationController.TransitionDirection int direction, float startingAngle,
                @Surface.Rotation int rotationDelta) {
            final boolean isOutPipDirection = isOutPipDirection(direction);
@@ -613,14 +613,36 @@ public class PipAnimationController {
                initialContainerRect = initialSourceValue;
            }

            final Rect sourceHintRectInsets;
            if (sourceHintRect == null) {
                sourceHintRectInsets = null;
            final Rect adjustedSourceRectHint = new Rect();
            if (sourceRectHint == null || sourceRectHint.isEmpty()) {
                // Crop a Rect matches the aspect ratio and pivots at the center point.
                // This is done for entering case only.
                if (isInPipDirection(direction)) {
                    final float aspectRatio = endValue.width() / (float) endValue.height();
                    if ((startValue.width() / (float) startValue.height()) > aspectRatio) {
                        // use the full height.
                        adjustedSourceRectHint.set(0, 0,
                                (int) (startValue.height() * aspectRatio), startValue.height());
                        adjustedSourceRectHint.offset(
                                (startValue.width() - adjustedSourceRectHint.width()) / 2, 0);
                    } else {
                sourceHintRectInsets = new Rect(sourceHintRect.left - initialContainerRect.left,
                        sourceHintRect.top - initialContainerRect.top,
                        initialContainerRect.right - sourceHintRect.right,
                        initialContainerRect.bottom - sourceHintRect.bottom);
                        // use the full width.
                        adjustedSourceRectHint.set(0, 0,
                                startValue.width(), (int) (startValue.width() / aspectRatio));
                        adjustedSourceRectHint.offset(
                                0, (startValue.height() - adjustedSourceRectHint.height()) / 2);
                    }
                }
            } else {
                adjustedSourceRectHint.set(sourceRectHint);
            }
            final Rect sourceHintRectInsets = new Rect();
            if (!adjustedSourceRectHint.isEmpty()) {
                sourceHintRectInsets.set(
                        adjustedSourceRectHint.left - initialContainerRect.left,
                        adjustedSourceRectHint.top - initialContainerRect.top,
                        initialContainerRect.right - adjustedSourceRectHint.right,
                        initialContainerRect.bottom - adjustedSourceRectHint.bottom);
            }
            final Rect zeroInsets = new Rect(0, 0, 0, 0);

@@ -648,7 +670,7 @@ public class PipAnimationController {
                    }
                    float angle = (1.0f - fraction) * startingAngle;
                    setCurrentValue(bounds);
                    if (inScaleTransition() || sourceHintRect == null) {
                    if (inScaleTransition() || adjustedSourceRectHint.isEmpty()) {
                        if (isOutPipDirection) {
                            getSurfaceTransactionHelper().crop(tx, leash, end)
                                    .scale(tx, leash, end, bounds);
@@ -661,7 +683,7 @@ public class PipAnimationController {
                    } else {
                        final Rect insets = computeInsets(fraction);
                        getSurfaceTransactionHelper().scaleAndCrop(tx, leash,
                                sourceHintRect, initialSourceValue, bounds, insets,
                                adjustedSourceRectHint, initialSourceValue, bounds, insets,
                                isInPipDirection, fraction);
                        if (shouldApplyCornerRadius()) {
                            final Rect sourceBounds = new Rect(initialContainerRect);
@@ -729,9 +751,6 @@ public class PipAnimationController {
                }

                private Rect computeInsets(float fraction) {
                    if (sourceHintRectInsets == null) {
                        return zeroInsets;
                    }
                    final Rect startRect = isOutPipDirection ? sourceHintRectInsets : zeroInsets;
                    final Rect endRect = isOutPipDirection ? zeroInsets : sourceHintRectInsets;
                    return mInsetsEvaluator.evaluate(fraction, startRect, endRect);
+3 −4
Original line number Diff line number Diff line
@@ -226,11 +226,10 @@ public abstract class PipContentOverlay {
                    appBoundsCenterX - mOverlayHalfSize,
                    appBoundsCenterY - mOverlayHalfSize);
            // Scale back the bitmap with the pivot point at center.
            mTmpTransform.postScale(
            final float scale = Math.min(
                    (float) mAppBounds.width() / currentBounds.width(),
                    (float) mAppBounds.height() / currentBounds.height(),
                    appBoundsCenterX,
                    appBoundsCenterY);
                    (float) mAppBounds.height() / currentBounds.height());
            mTmpTransform.postScale(scale, scale, appBoundsCenterX, appBoundsCenterY);
            atomicTx.setMatrix(mLeash, mTmpTransform, mTmpFloat9)
                    .setAlpha(mLeash, fraction < 0.5f ? 0 : (fraction - 0.5f) * 2);
        }
+6 −3
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;
        final float scale, left, top;
        if (isInPipDirection
                && sourceRectHint != null && sourceRectHint.width() < sourceBounds.width()) {
            // scale by sourceRectHint if it's not edge-to-edge, for entering PiP transition only.
@@ -148,12 +148,15 @@ 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;
        }
        final float left = destinationBounds.left - insets.left * scale;
        final float top = destinationBounds.top - insets.top * scale;
        mTmpTransform.setScale(scale, scale);
        tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
                .setCrop(leash, mTmpDestinationRect)
+8 −3
Original line number Diff line number Diff line
@@ -87,10 +87,15 @@ 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;
        final float scale, left, top;
        if (sourceRectHint.isEmpty() || sourceRectHint.width() == sourceBounds.width()) {
            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 + sourceBounds.left) * scale;
            top = scale == 1
                    ? 0 : destinationBounds.top - (insets.top + sourceBounds.top) * scale;
        } else {
            // scale by sourceRectHint if it's not edge-to-edge
            final float endScale = sourceRectHint.width() <= sourceRectHint.height()
@@ -100,9 +105,9 @@ public class PipSurfaceTransactionHelper {
                    ? (float) destinationBounds.width() / sourceBounds.width()
                    : (float) destinationBounds.height() / sourceBounds.height();
            scale = Math.min((1 - progress) * startScale + progress * endScale, 1.0f);
            left = destinationBounds.left - (insets.left + sourceBounds.left) * scale;
            top = destinationBounds.top - (insets.top + sourceBounds.top) * scale;
        }
        final float left = destinationBounds.left - (insets.left + sourceBounds.left) * scale;
        final float top = destinationBounds.top - (insets.top + sourceBounds.top) * scale;
        mTmpTransform.setScale(scale, scale);
        final float cornerRadius = getScaledCornerRadius(mTmpDestinationRect, destinationBounds);
        tx.setMatrix(leash, mTmpTransform, mTmpFloat9)