Merge "Polish PiP round corner" into sc-dev

This commit is contained in:
Hongwei Wang
2021-06-08 16:48:28 +00:00
committed by Android (Google) Code Review
5 changed files with 36 additions and 9 deletions

View File

@@ -44,7 +44,7 @@
<dimen name="pip_bottom_offset_buffer">1dp</dimen>
<!-- The corner radius for PiP window. -->
<dimen name="pip_corner_radius">8dp</dimen>
<dimen name="pip_corner_radius">16dp</dimen>
<!-- The bottom margin of the PIP drag to dismiss info text shown when moving a PIP. -->
<dimen name="pip_dismiss_text_bottom_margin">24dp</dimen>

View File

@@ -435,7 +435,8 @@ public class PipAnimationController {
SurfaceControl.Transaction tx, float fraction) {
final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
setCurrentValue(alpha);
getSurfaceTransactionHelper().alpha(tx, leash, alpha);
getSurfaceTransactionHelper().alpha(tx, leash, alpha)
.round(tx, leash, shouldApplyCornerRadius());
tx.apply();
}
@@ -526,16 +527,22 @@ public class PipAnimationController {
float angle = (1.0f - fraction) * startingAngle;
setCurrentValue(bounds);
if (inScaleTransition() || sourceHintRect == null) {
if (isOutPipDirection) {
getSurfaceTransactionHelper().scale(tx, leash, end, bounds);
} else {
getSurfaceTransactionHelper().scale(tx, leash, base, bounds, angle);
getSurfaceTransactionHelper().scale(tx, leash, base, bounds, angle)
.round(tx, leash, base, bounds);
}
} else {
final Rect insets = computeInsets(fraction);
getSurfaceTransactionHelper().scaleAndCrop(tx, leash,
initialSourceValue, bounds, insets);
if (shouldApplyCornerRadius()) {
final Rect destinationBounds = new Rect(bounds);
destinationBounds.inset(insets);
getSurfaceTransactionHelper().round(tx, leash,
initialContainerRect, destinationBounds);
}
}
if (!handlePipTransaction(leash, tx, bounds)) {
tx.apply();
@@ -564,9 +571,11 @@ public class PipAnimationController {
x = fraction * (end.left - start.left) + start.left;
y = fraction * (end.bottom - start.top) + start.top;
}
getSurfaceTransactionHelper().rotateAndScaleWithCrop(tx, leash,
initialContainerRect, bounds, insets, degree, x, y, isOutPipDirection,
rotationDelta == ROTATION_270 /* clockwise */);
getSurfaceTransactionHelper()
.rotateAndScaleWithCrop(tx, leash, initialContainerRect, bounds,
insets, degree, x, y, isOutPipDirection,
rotationDelta == ROTATION_270 /* clockwise */)
.round(tx, leash, initialContainerRect, bounds);
tx.apply();
}

View File

@@ -185,6 +185,18 @@ public class PipSurfaceTransactionHelper {
return this;
}
/**
* Operates the round corner radius on a given transaction and leash, scaled by bounds
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
*/
public PipSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash,
Rect fromBounds, Rect toBounds) {
final float scale = (float) (Math.hypot(fromBounds.width(), fromBounds.height())
/ Math.hypot(toBounds.width(), toBounds.height()));
tx.setCornerRadius(leash, mCornerRadius * scale);
return this;
}
/**
* Re-parents the snapshot to the parent's surface control and shows it.
*/

View File

@@ -184,6 +184,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
mTaskOrganizer.applyTransaction(wct);
// The final task bounds will be applied by onFixedRotationFinished so that all
// coordinates are in new rotation.
mSurfaceTransactionHelper.round(tx, mLeash, isInPip());
mDeferredAnimEndTransaction = tx;
return;
}
@@ -1041,7 +1042,9 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
}
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
mSurfaceTransactionHelper.scale(tx, mLeash, startBounds, toBounds, degrees);
mSurfaceTransactionHelper
.scale(tx, mLeash, startBounds, toBounds, degrees)
.round(tx, mLeash, startBounds, toBounds);
if (mPipMenuController.isMenuVisible()) {
mPipMenuController.movePipMenu(mLeash, tx, toBounds);
} else {
@@ -1216,6 +1219,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
// Just a resize in PIP
taskBounds = destinationBounds;
}
mSurfaceTransactionHelper.round(tx, mLeash, isInPip());
wct.setBounds(mToken, taskBounds);
wct.setBoundsChangeTransaction(mToken, tx);

View File

@@ -268,7 +268,9 @@ class PinnedTaskController {
matrix.postRotate(90);
}
matrix.postTranslate(dx, dy);
t.setMatrix(pinnedTask.getSurfaceControl(), matrix, new float[9]);
final SurfaceControl leash = pinnedTask.getSurfaceControl();
t.setMatrix(leash, matrix, new float[9])
.setCornerRadius(leash, pipTx.mCornerRadius);
Slog.i(TAG, "Seamless rotation PiP tx=" + pipTx + " pos=" + dx + "," + dy);
return;
}