Merge "Polish round corner for auto-enter-pip" into sc-dev am: 628002c70c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14900574 Change-Id: I39b111613b6e50885d5db5e895ec482011a58dad
This commit is contained in:
@@ -633,8 +633,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
|
|||||||
final Rect destinationBounds = mPipBoundsState.getBounds();
|
final Rect destinationBounds = mPipBoundsState.getBounds();
|
||||||
final SurfaceControl swipeToHomeOverlay = mSwipePipToHomeOverlay;
|
final SurfaceControl swipeToHomeOverlay = mSwipePipToHomeOverlay;
|
||||||
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
|
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
|
||||||
mSurfaceTransactionHelper.resetScale(tx, mLeash, destinationBounds);
|
mSurfaceTransactionHelper
|
||||||
mSurfaceTransactionHelper.crop(tx, mLeash, destinationBounds);
|
.resetScale(tx, mLeash, destinationBounds)
|
||||||
|
.crop(tx, mLeash, destinationBounds)
|
||||||
|
.round(tx, mLeash, isInPip());
|
||||||
// The animation is finished in the Launcher and here we directly apply the final touch.
|
// The animation is finished in the Launcher and here we directly apply the final touch.
|
||||||
applyEnterPipSyncTransaction(destinationBounds, () -> {
|
applyEnterPipSyncTransaction(destinationBounds, () -> {
|
||||||
// Ensure menu's settled in its final bounds first.
|
// Ensure menu's settled in its final bounds first.
|
||||||
|
|||||||
@@ -46,12 +46,13 @@ public class PipSurfaceTransactionHelper {
|
|||||||
mTmpSourceRectF.set(sourceBounds);
|
mTmpSourceRectF.set(sourceBounds);
|
||||||
mTmpDestinationRectF.set(destinationBounds);
|
mTmpDestinationRectF.set(destinationBounds);
|
||||||
mTmpTransform.setRectToRect(mTmpSourceRectF, mTmpDestinationRectF, Matrix.ScaleToFit.FILL);
|
mTmpTransform.setRectToRect(mTmpSourceRectF, mTmpDestinationRectF, Matrix.ScaleToFit.FILL);
|
||||||
|
final float cornerRadius = getScaledCornerRadius(sourceBounds, destinationBounds);
|
||||||
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
||||||
.setPosition(leash, mTmpDestinationRectF.left, mTmpDestinationRectF.top)
|
.setPosition(leash, mTmpDestinationRectF.left, mTmpDestinationRectF.top)
|
||||||
.setCornerRadius(leash, mCornerRadius);
|
.setCornerRadius(leash, cornerRadius);
|
||||||
return new PictureInPictureSurfaceTransaction(
|
return new PictureInPictureSurfaceTransaction(
|
||||||
mTmpDestinationRectF.left, mTmpDestinationRectF.top,
|
mTmpDestinationRectF.left, mTmpDestinationRectF.top,
|
||||||
mTmpFloat9, 0 /* rotation */, mCornerRadius, sourceBounds);
|
mTmpFloat9, 0 /* rotation */, cornerRadius, sourceBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PictureInPictureSurfaceTransaction scale(
|
public PictureInPictureSurfaceTransaction scale(
|
||||||
@@ -62,11 +63,12 @@ public class PipSurfaceTransactionHelper {
|
|||||||
mTmpDestinationRectF.set(destinationBounds);
|
mTmpDestinationRectF.set(destinationBounds);
|
||||||
mTmpTransform.setRectToRect(mTmpSourceRectF, mTmpDestinationRectF, Matrix.ScaleToFit.FILL);
|
mTmpTransform.setRectToRect(mTmpSourceRectF, mTmpDestinationRectF, Matrix.ScaleToFit.FILL);
|
||||||
mTmpTransform.postRotate(degree, 0, 0);
|
mTmpTransform.postRotate(degree, 0, 0);
|
||||||
|
final float cornerRadius = getScaledCornerRadius(sourceBounds, destinationBounds);
|
||||||
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
||||||
.setPosition(leash, positionX, positionY)
|
.setPosition(leash, positionX, positionY)
|
||||||
.setCornerRadius(leash, mCornerRadius);
|
.setCornerRadius(leash, cornerRadius);
|
||||||
return new PictureInPictureSurfaceTransaction(
|
return new PictureInPictureSurfaceTransaction(
|
||||||
positionX, positionY, mTmpFloat9, degree, mCornerRadius, sourceBounds);
|
positionX, positionY, mTmpFloat9, degree, cornerRadius, sourceBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PictureInPictureSurfaceTransaction scaleAndCrop(
|
public PictureInPictureSurfaceTransaction scaleAndCrop(
|
||||||
@@ -83,12 +85,15 @@ public class PipSurfaceTransactionHelper {
|
|||||||
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);
|
||||||
|
final Rect cornerRadiusRect = new Rect(destinationBounds);
|
||||||
|
cornerRadiusRect.inset(insets);
|
||||||
|
final float cornerRadius = getScaledCornerRadius(sourceBounds, cornerRadiusRect);
|
||||||
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
||||||
.setWindowCrop(leash, mTmpDestinationRect)
|
.setWindowCrop(leash, mTmpDestinationRect)
|
||||||
.setPosition(leash, left, top)
|
.setPosition(leash, left, top)
|
||||||
.setCornerRadius(leash, mCornerRadius);
|
.setCornerRadius(leash, cornerRadius);
|
||||||
return new PictureInPictureSurfaceTransaction(
|
return new PictureInPictureSurfaceTransaction(
|
||||||
left, top, mTmpFloat9, 0 /* rotation */, mCornerRadius, mTmpDestinationRect);
|
left, top, mTmpFloat9, 0 /* rotation */, cornerRadius, mTmpDestinationRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PictureInPictureSurfaceTransaction scaleAndRotate(
|
public PictureInPictureSurfaceTransaction scaleAndRotate(
|
||||||
@@ -105,12 +110,22 @@ public class PipSurfaceTransactionHelper {
|
|||||||
: (float) destinationBounds.height() / sourceBounds.height();
|
: (float) destinationBounds.height() / sourceBounds.height();
|
||||||
mTmpTransform.setRotate(degree, 0, 0);
|
mTmpTransform.setRotate(degree, 0, 0);
|
||||||
mTmpTransform.postScale(scale, scale);
|
mTmpTransform.postScale(scale, scale);
|
||||||
|
final Rect cornerRadiusRect = new Rect(destinationBounds);
|
||||||
|
cornerRadiusRect.inset(insets);
|
||||||
|
final float cornerRadius = getScaledCornerRadius(sourceBounds, cornerRadiusRect);
|
||||||
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
||||||
.setWindowCrop(leash, mTmpDestinationRect)
|
.setWindowCrop(leash, mTmpDestinationRect)
|
||||||
.setPosition(leash, positionX, positionY)
|
.setPosition(leash, positionX, positionY)
|
||||||
.setCornerRadius(leash, mCornerRadius);
|
.setCornerRadius(leash, cornerRadius);
|
||||||
return new PictureInPictureSurfaceTransaction(
|
return new PictureInPictureSurfaceTransaction(
|
||||||
positionX, positionY, mTmpFloat9, degree, mCornerRadius, mTmpDestinationRect);
|
positionX, positionY, mTmpFloat9, degree, cornerRadius, mTmpDestinationRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the round corner radius scaled by given from and to bounds */
|
||||||
|
private float getScaledCornerRadius(Rect fromBounds, Rect toBounds) {
|
||||||
|
final float scale = (float) (Math.hypot(fromBounds.width(), fromBounds.height())
|
||||||
|
/ Math.hypot(toBounds.width(), toBounds.height()));
|
||||||
|
return mCornerRadius * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link SurfaceControl.Transaction} instance with vsync-id */
|
/** @return {@link SurfaceControl.Transaction} instance with vsync-id */
|
||||||
|
|||||||
Reference in New Issue
Block a user