Merge "Polish enter PiP animation on back pressed" into tm-qpr-dev
This commit is contained in:
@@ -591,7 +591,7 @@ public class PipAnimationController {
|
|||||||
final Rect insets = computeInsets(fraction);
|
final Rect insets = computeInsets(fraction);
|
||||||
getSurfaceTransactionHelper().scaleAndCrop(tx, leash,
|
getSurfaceTransactionHelper().scaleAndCrop(tx, leash,
|
||||||
sourceHintRect, initialSourceValue, bounds, insets,
|
sourceHintRect, initialSourceValue, bounds, insets,
|
||||||
isInPipDirection);
|
isInPipDirection, fraction);
|
||||||
if (shouldApplyCornerRadius()) {
|
if (shouldApplyCornerRadius()) {
|
||||||
final Rect sourceBounds = new Rect(initialContainerRect);
|
final Rect sourceBounds = new Rect(initialContainerRect);
|
||||||
sourceBounds.inset(insets);
|
sourceBounds.inset(insets);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class PipSurfaceTransactionHelper {
|
|||||||
public PipSurfaceTransactionHelper scaleAndCrop(SurfaceControl.Transaction tx,
|
public PipSurfaceTransactionHelper scaleAndCrop(SurfaceControl.Transaction tx,
|
||||||
SurfaceControl leash, Rect sourceRectHint,
|
SurfaceControl leash, Rect sourceRectHint,
|
||||||
Rect sourceBounds, Rect destinationBounds, Rect insets,
|
Rect sourceBounds, Rect destinationBounds, Rect insets,
|
||||||
boolean isInPipDirection) {
|
boolean isInPipDirection, float fraction) {
|
||||||
mTmpDestinationRect.set(sourceBounds);
|
mTmpDestinationRect.set(sourceBounds);
|
||||||
// Similar to {@link #scale}, we want to position the surface relative to the screen
|
// Similar to {@link #scale}, we want to position the surface relative to the screen
|
||||||
// coordinates so offset the bounds to 0,0
|
// coordinates so offset the bounds to 0,0
|
||||||
@@ -116,9 +116,13 @@ public class PipSurfaceTransactionHelper {
|
|||||||
if (isInPipDirection
|
if (isInPipDirection
|
||||||
&& sourceRectHint != null && sourceRectHint.width() < sourceBounds.width()) {
|
&& sourceRectHint != null && sourceRectHint.width() < sourceBounds.width()) {
|
||||||
// scale by sourceRectHint if it's not edge-to-edge, for entering PiP transition only.
|
// scale by sourceRectHint if it's not edge-to-edge, for entering PiP transition only.
|
||||||
scale = sourceBounds.width() <= sourceBounds.height()
|
final float endScale = sourceBounds.width() <= sourceBounds.height()
|
||||||
? (float) destinationBounds.width() / sourceRectHint.width()
|
? (float) destinationBounds.width() / sourceRectHint.width()
|
||||||
: (float) destinationBounds.height() / sourceRectHint.height();
|
: (float) destinationBounds.height() / sourceRectHint.height();
|
||||||
|
final float startScale = sourceBounds.width() <= sourceBounds.height()
|
||||||
|
? (float) destinationBounds.width() / sourceBounds.width()
|
||||||
|
: (float) destinationBounds.height() / sourceBounds.height();
|
||||||
|
scale = (1 - fraction) * startScale + fraction * endScale;
|
||||||
} else {
|
} else {
|
||||||
scale = sourceBounds.width() <= sourceBounds.height()
|
scale = sourceBounds.width() <= sourceBounds.height()
|
||||||
? (float) destinationBounds.width() / sourceBounds.width()
|
? (float) destinationBounds.width() / sourceBounds.width()
|
||||||
|
|||||||
@@ -1472,6 +1472,11 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
|
|||||||
"%s: Abort animation, invalid leash", TAG);
|
"%s: Abort animation, invalid leash", TAG);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (isInPipDirection(direction)
|
||||||
|
&& !isSourceRectHintValidForEnterPip(sourceHintRect, destinationBounds)) {
|
||||||
|
// The given source rect hint is too small for enter PiP animation, reset it to null.
|
||||||
|
sourceHintRect = null;
|
||||||
|
}
|
||||||
final int rotationDelta = mWaitForFixedRotation
|
final int rotationDelta = mWaitForFixedRotation
|
||||||
? deltaRotation(mCurrentRotation, mNextRotation)
|
? deltaRotation(mCurrentRotation, mNextRotation)
|
||||||
: Surface.ROTATION_0;
|
: Surface.ROTATION_0;
|
||||||
@@ -1545,6 +1550,20 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
|
|||||||
return sourceHintRect;
|
return sourceHintRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a situation in which the source rect hint on at least one axis is smaller
|
||||||
|
* than the destination bounds, which represents a problem because we would have to scale
|
||||||
|
* up that axis to fit the bounds. So instead, just fallback to the non-source hint
|
||||||
|
* animation in this case.
|
||||||
|
*
|
||||||
|
* @return {@code false} if the given source is too small to use for the entering animation.
|
||||||
|
*/
|
||||||
|
private boolean isSourceRectHintValidForEnterPip(Rect sourceRectHint, Rect destinationBounds) {
|
||||||
|
return sourceRectHint != null
|
||||||
|
&& sourceRectHint.width() > destinationBounds.width()
|
||||||
|
&& sourceRectHint.height() > destinationBounds.height();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync with {@link SplitScreenController} on destination bounds if PiP is going to
|
* Sync with {@link SplitScreenController} on destination bounds if PiP is going to
|
||||||
* split screen.
|
* split screen.
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ public class PipSurfaceTransactionHelper {
|
|||||||
|
|
||||||
public PictureInPictureSurfaceTransaction scaleAndCrop(
|
public PictureInPictureSurfaceTransaction scaleAndCrop(
|
||||||
SurfaceControl.Transaction tx, SurfaceControl leash,
|
SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||||
Rect sourceRectHint, Rect sourceBounds, Rect destinationBounds, Rect insets) {
|
Rect sourceRectHint, Rect sourceBounds, Rect destinationBounds, Rect insets,
|
||||||
|
float progress) {
|
||||||
mTmpSourceRectF.set(sourceBounds);
|
mTmpSourceRectF.set(sourceBounds);
|
||||||
mTmpDestinationRect.set(sourceBounds);
|
mTmpDestinationRect.set(sourceBounds);
|
||||||
mTmpDestinationRect.inset(insets);
|
mTmpDestinationRect.inset(insets);
|
||||||
@@ -93,9 +94,13 @@ public class PipSurfaceTransactionHelper {
|
|||||||
: (float) destinationBounds.height() / sourceBounds.height();
|
: (float) destinationBounds.height() / sourceBounds.height();
|
||||||
} else {
|
} else {
|
||||||
// scale by sourceRectHint if it's not edge-to-edge
|
// scale by sourceRectHint if it's not edge-to-edge
|
||||||
scale = sourceRectHint.width() <= sourceRectHint.height()
|
final float endScale = sourceRectHint.width() <= sourceRectHint.height()
|
||||||
? (float) destinationBounds.width() / sourceRectHint.width()
|
? (float) destinationBounds.width() / sourceRectHint.width()
|
||||||
: (float) destinationBounds.height() / sourceRectHint.height();
|
: (float) destinationBounds.height() / sourceRectHint.height();
|
||||||
|
final float startScale = sourceRectHint.width() <= sourceRectHint.height()
|
||||||
|
? (float) destinationBounds.width() / sourceBounds.width()
|
||||||
|
: (float) destinationBounds.height() / sourceBounds.height();
|
||||||
|
scale = (1 - progress) * startScale + progress * endScale;
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user