Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip2/animation/PipExpandAnimator.java +17 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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(); Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java +1 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip2/animation/PipExpandAnimatorTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip2/animation/PipExpandAnimator.java +17 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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(); Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java +1 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip2/animation/PipExpandAnimatorTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -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; Loading