Merge "Use sourceRectHint to calculate scale when enter PiP" into tm-dev am: 634396baaf

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17697962

Change-Id: Ie0dda4608e2b6bf21976cfad958c5e1c6545cd48
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Hongwei Wang
2022-04-13 17:41:59 +00:00
committed by Automerger Merge Worker
3 changed files with 38 additions and 22 deletions

View File

@@ -250,7 +250,6 @@ public class PipAnimationController {
protected T mCurrentValue; protected T mCurrentValue;
protected T mStartValue; protected T mStartValue;
private T mEndValue; private T mEndValue;
private float mStartingAngle;
private PipAnimationCallback mPipAnimationCallback; private PipAnimationCallback mPipAnimationCallback;
private PipTransactionHandler mPipTransactionHandler; private PipTransactionHandler mPipTransactionHandler;
private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
@@ -260,8 +259,8 @@ public class PipAnimationController {
protected SurfaceControl mContentOverlay; protected SurfaceControl mContentOverlay;
private PipTransitionAnimator(TaskInfo taskInfo, SurfaceControl leash, private PipTransitionAnimator(TaskInfo taskInfo, SurfaceControl leash,
@AnimationType int animationType, Rect destinationBounds, T baseValue, T startValue, @AnimationType int animationType,
T endValue, float startingAngle) { Rect destinationBounds, T baseValue, T startValue, T endValue) {
mTaskInfo = taskInfo; mTaskInfo = taskInfo;
mLeash = leash; mLeash = leash;
mAnimationType = animationType; mAnimationType = animationType;
@@ -269,7 +268,6 @@ public class PipAnimationController {
mBaseValue = baseValue; mBaseValue = baseValue;
mStartValue = startValue; mStartValue = startValue;
mEndValue = endValue; mEndValue = endValue;
mStartingAngle = startingAngle;
addListener(this); addListener(this);
addUpdateListener(this); addUpdateListener(this);
mSurfaceControlTransactionFactory = mSurfaceControlTransactionFactory =
@@ -480,7 +478,7 @@ public class PipAnimationController {
static PipTransitionAnimator<Float> ofAlpha(TaskInfo taskInfo, SurfaceControl leash, static PipTransitionAnimator<Float> ofAlpha(TaskInfo taskInfo, SurfaceControl leash,
Rect destinationBounds, float startValue, float endValue) { Rect destinationBounds, float startValue, float endValue) {
return new PipTransitionAnimator<Float>(taskInfo, leash, ANIM_TYPE_ALPHA, return new PipTransitionAnimator<Float>(taskInfo, leash, ANIM_TYPE_ALPHA,
destinationBounds, startValue, startValue, endValue, 0) { destinationBounds, startValue, startValue, endValue) {
@Override @Override
void applySurfaceControlTransaction(SurfaceControl leash, void applySurfaceControlTransaction(SurfaceControl leash,
SurfaceControl.Transaction tx, float fraction) { SurfaceControl.Transaction tx, float fraction) {
@@ -520,7 +518,7 @@ public class PipAnimationController {
@PipAnimationController.TransitionDirection int direction, float startingAngle, @PipAnimationController.TransitionDirection int direction, float startingAngle,
@Surface.Rotation int rotationDelta) { @Surface.Rotation int rotationDelta) {
final boolean isOutPipDirection = isOutPipDirection(direction); final boolean isOutPipDirection = isOutPipDirection(direction);
final boolean isInPipDirection = isInPipDirection(direction);
// Just for simplicity we'll interpolate between the source rect hint insets and empty // Just for simplicity we'll interpolate between the source rect hint insets and empty
// insets to calculate the window crop // insets to calculate the window crop
final Rect initialSourceValue; final Rect initialSourceValue;
@@ -559,8 +557,7 @@ public class PipAnimationController {
// construct new Rect instances in case they are recycled // construct new Rect instances in case they are recycled
return new PipTransitionAnimator<Rect>(taskInfo, leash, ANIM_TYPE_BOUNDS, return new PipTransitionAnimator<Rect>(taskInfo, leash, ANIM_TYPE_BOUNDS,
endValue, new Rect(baseValue), new Rect(startValue), new Rect(endValue), endValue, new Rect(baseValue), new Rect(startValue), new Rect(endValue)) {
startingAngle) {
private final RectEvaluator mRectEvaluator = new RectEvaluator(new Rect()); private final RectEvaluator mRectEvaluator = new RectEvaluator(new Rect());
private final RectEvaluator mInsetsEvaluator = new RectEvaluator(new Rect()); private final RectEvaluator mInsetsEvaluator = new RectEvaluator(new Rect());
@@ -595,7 +592,8 @@ public class PipAnimationController {
} else { } else {
final Rect insets = computeInsets(fraction); final Rect insets = computeInsets(fraction);
getSurfaceTransactionHelper().scaleAndCrop(tx, leash, getSurfaceTransactionHelper().scaleAndCrop(tx, leash,
initialSourceValue, bounds, insets); sourceHintRect, initialSourceValue, bounds, insets,
isInPipDirection);
if (shouldApplyCornerRadius()) { if (shouldApplyCornerRadius()) {
final Rect sourceBounds = new Rect(initialContainerRect); final Rect sourceBounds = new Rect(initialContainerRect);
sourceBounds.inset(insets); sourceBounds.inset(insets);

View File

@@ -103,21 +103,31 @@ public class PipSurfaceTransactionHelper {
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining * @return same {@link PipSurfaceTransactionHelper} instance for method chaining
*/ */
public PipSurfaceTransactionHelper scaleAndCrop(SurfaceControl.Transaction tx, public PipSurfaceTransactionHelper scaleAndCrop(SurfaceControl.Transaction tx,
SurfaceControl leash, SurfaceControl leash, Rect sourceRectHint,
Rect sourceBounds, Rect destinationBounds, Rect insets) { Rect sourceBounds, Rect destinationBounds, Rect insets,
boolean isInPipDirection) {
mTmpSourceRectF.set(sourceBounds); mTmpSourceRectF.set(sourceBounds);
mTmpDestinationRect.set(sourceBounds); mTmpDestinationRect.set(sourceBounds);
mTmpDestinationRect.inset(insets); mTmpDestinationRect.inset(insets);
// Scale by the shortest edge and offset such that the top/left of the scaled inset source // Scale by the shortest edge and offset such that the top/left of the scaled inset source
// rect aligns with the top/left of the destination bounds // rect aligns with the top/left of the destination bounds
final float scale = sourceBounds.width() <= sourceBounds.height() final float scale;
? (float) destinationBounds.width() / sourceBounds.width() if (isInPipDirection
: (float) destinationBounds.height() / sourceBounds.height(); && sourceRectHint != null && sourceRectHint.width() < sourceBounds.width()) {
// scale by sourceRectHint if it's not edge-to-edge, for entering PiP transition only.
scale = sourceBounds.width() <= sourceBounds.height()
? (float) destinationBounds.width() / sourceRectHint.width()
: (float) destinationBounds.height() / sourceRectHint.height();
} else {
scale = sourceBounds.width() <= sourceBounds.height()
? (float) destinationBounds.width() / sourceBounds.width()
: (float) destinationBounds.height() / sourceBounds.height();
}
final float left = destinationBounds.left - insets.left * scale; final float left = destinationBounds.left - insets.left * scale;
final float top = destinationBounds.top - insets.top * scale; final float top = destinationBounds.top - insets.top * scale;
mTmpTransform.setScale(scale, scale); mTmpTransform.setScale(scale, scale);
tx.setMatrix(leash, mTmpTransform, mTmpFloat9) tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
.setWindowCrop(leash, mTmpDestinationRect) .setCrop(leash, mTmpDestinationRect)
.setPosition(leash, left, top); .setPosition(leash, left, top);
return this; return this;
} }
@@ -163,7 +173,7 @@ public class PipSurfaceTransactionHelper {
mTmpTransform.setScale(scale, scale); mTmpTransform.setScale(scale, scale);
mTmpTransform.postRotate(degrees); mTmpTransform.postRotate(degrees);
mTmpTransform.postTranslate(positionX, positionY); mTmpTransform.postTranslate(positionX, positionY);
tx.setMatrix(leash, mTmpTransform, mTmpFloat9).setWindowCrop(leash, crop); tx.setMatrix(leash, mTmpTransform, mTmpFloat9).setCrop(leash, crop);
return this; return this;
} }

View File

@@ -80,21 +80,29 @@ public class PipSurfaceTransactionHelper {
public PictureInPictureSurfaceTransaction scaleAndCrop( public PictureInPictureSurfaceTransaction scaleAndCrop(
SurfaceControl.Transaction tx, SurfaceControl leash, SurfaceControl.Transaction tx, SurfaceControl leash,
Rect sourceBounds, Rect destinationBounds, Rect insets) { Rect sourceRectHint, Rect sourceBounds, Rect destinationBounds, Rect insets) {
mTmpSourceRectF.set(sourceBounds); mTmpSourceRectF.set(sourceBounds);
mTmpDestinationRect.set(sourceBounds); mTmpDestinationRect.set(sourceBounds);
mTmpDestinationRect.inset(insets); mTmpDestinationRect.inset(insets);
// Scale by the shortest edge and offset such that the top/left of the scaled inset // Scale by the shortest edge and offset such that the top/left of the scaled inset
// source rect aligns with the top/left of the destination bounds // source rect aligns with the top/left of the destination bounds
final float scale = sourceBounds.width() <= sourceBounds.height() final float scale;
? (float) destinationBounds.width() / sourceBounds.width() if (sourceRectHint.isEmpty() || sourceRectHint.width() == sourceBounds.width()) {
: (float) destinationBounds.height() / sourceBounds.height(); scale = sourceBounds.width() <= sourceBounds.height()
? (float) destinationBounds.width() / sourceBounds.width()
: (float) destinationBounds.height() / sourceBounds.height();
} else {
// scale by sourceRectHint if it's not edge-to-edge
scale = sourceRectHint.width() <= sourceRectHint.height()
? (float) destinationBounds.width() / sourceRectHint.width()
: (float) destinationBounds.height() / sourceRectHint.height();
}
final float left = destinationBounds.left - (insets.left + sourceBounds.left) * scale; final float left = destinationBounds.left - (insets.left + sourceBounds.left) * scale;
final float top = destinationBounds.top - (insets.top + sourceBounds.top) * scale; final float top = destinationBounds.top - (insets.top + sourceBounds.top) * scale;
mTmpTransform.setScale(scale, scale); mTmpTransform.setScale(scale, scale);
final float cornerRadius = getScaledCornerRadius(mTmpDestinationRect, destinationBounds); final float cornerRadius = getScaledCornerRadius(mTmpDestinationRect, destinationBounds);
tx.setMatrix(leash, mTmpTransform, mTmpFloat9) tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
.setWindowCrop(leash, mTmpDestinationRect) .setCrop(leash, mTmpDestinationRect)
.setPosition(leash, left, top) .setPosition(leash, left, top)
.setCornerRadius(leash, cornerRadius) .setCornerRadius(leash, cornerRadius)
.setShadowRadius(leash, mShadowRadius); .setShadowRadius(leash, mShadowRadius);
@@ -127,7 +135,7 @@ public class PipSurfaceTransactionHelper {
adjustedPositionY = positionY - insets.left * scale; adjustedPositionY = positionY - insets.left * scale;
} }
tx.setMatrix(leash, mTmpTransform, mTmpFloat9) tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
.setWindowCrop(leash, mTmpDestinationRect) .setCrop(leash, mTmpDestinationRect)
.setPosition(leash, adjustedPositionX, adjustedPositionY) .setPosition(leash, adjustedPositionX, adjustedPositionY)
.setCornerRadius(leash, cornerRadius) .setCornerRadius(leash, cornerRadius)
.setShadowRadius(leash, mShadowRadius); .setShadowRadius(leash, mShadowRadius);