diff options
| author | 2024-06-06 00:15:06 +0000 | |
|---|---|---|
| committer | 2024-06-06 00:15:06 +0000 | |
| commit | 050a275f849ec60f6a010d0681db2316fe88ee91 (patch) | |
| tree | cb68ee99ed0b6316e0636766857f16d28334151d | |
| parent | a58353302ba35c6bb4fcd1042450a6fd3c2afd21 (diff) | |
| parent | 2e9b38be83b8a9a1f0c41374217b0e3a923f0996 (diff) | |
Merge "Crop the center when no source rect hint" into main
4 files changed, 49 insertions, 23 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java index eb845db409e3..57c07323d1bb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java @@ -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 { + // use the full width. + adjustedSourceRectHint.set(0, 0, + startValue.width(), (int) (startValue.width() / aspectRatio)); + adjustedSourceRectHint.offset( + 0, (startValue.height() - adjustedSourceRectHint.height()) / 2); + } + } } else { - sourceHintRectInsets = new Rect(sourceHintRect.left - initialContainerRect.left, - sourceHintRect.top - initialContainerRect.top, - initialContainerRect.right - sourceHintRect.right, - initialContainerRect.bottom - sourceHintRect.bottom); + 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); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipContentOverlay.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipContentOverlay.java index e11e8596a7fe..ff2d46e11107 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipContentOverlay.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipContentOverlay.java @@ -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); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java index a58d94ecd19b..202f60dad842 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java @@ -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) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java index c33b7ce1d002..c225cbcc6e81 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java @@ -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) |