Pass the float9 values in PictureInPictureSurfaceTransaction
For auto enter PiP from landscape when no source rect hint is specified, we should actually use the skew instead scale values to set the matrix transform. Video: http://recall/-/aaaaaabFQoRHlzixHdtY/dpLVOQzIVjdJpn5kg7T4Fc Bug: 179720719 Test: manual use ApiDemos app, see video Change-Id: Ic7072e8354329584f9cb75876911c3d58d78e7f5
This commit is contained in:
@@ -24,6 +24,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.SurfaceControl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -37,10 +38,11 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
public final float mPositionX;
|
||||
public final float mPositionY;
|
||||
|
||||
public final float mScaleX;
|
||||
public final float mScaleY;
|
||||
public final float[] mFloat9;
|
||||
|
||||
// Though this can be determined by mFloat9, it's easier to set the value directly
|
||||
public final float mRotation;
|
||||
|
||||
public final float mCornerRadius;
|
||||
|
||||
private final Rect mWindowCrop = new Rect();
|
||||
@@ -48,21 +50,19 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
public PictureInPictureSurfaceTransaction(Parcel in) {
|
||||
mPositionX = in.readFloat();
|
||||
mPositionY = in.readFloat();
|
||||
mScaleX = in.readFloat();
|
||||
mScaleY = in.readFloat();
|
||||
mFloat9 = new float[9];
|
||||
in.readFloatArray(mFloat9);
|
||||
mRotation = in.readFloat();
|
||||
mCornerRadius = in.readFloat();
|
||||
mWindowCrop.set(Objects.requireNonNull(in.readTypedObject(Rect.CREATOR)));
|
||||
}
|
||||
|
||||
public PictureInPictureSurfaceTransaction(float positionX, float positionY,
|
||||
float scaleX, float scaleY,
|
||||
float rotation, float cornerRadius,
|
||||
float[] float9, float rotation, float cornerRadius,
|
||||
@Nullable Rect windowCrop) {
|
||||
mPositionX = positionX;
|
||||
mPositionY = positionY;
|
||||
mScaleX = scaleX;
|
||||
mScaleY = scaleY;
|
||||
mFloat9 = Arrays.copyOf(float9, 9);
|
||||
mRotation = rotation;
|
||||
mCornerRadius = cornerRadius;
|
||||
if (windowCrop != null) {
|
||||
@@ -72,13 +72,14 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
|
||||
public PictureInPictureSurfaceTransaction(PictureInPictureSurfaceTransaction other) {
|
||||
this(other.mPositionX, other.mPositionY,
|
||||
other.mScaleX, other.mScaleY,
|
||||
other.mRotation, other.mCornerRadius,
|
||||
other.mWindowCrop);
|
||||
other.mFloat9, other.mRotation, other.mCornerRadius, other.mWindowCrop);
|
||||
}
|
||||
|
||||
public Rect getWindowCrop() {
|
||||
return new Rect(mWindowCrop);
|
||||
/** @return {@link Matrix} from {@link #mFloat9} */
|
||||
public Matrix getMatrix() {
|
||||
final Matrix matrix = new Matrix();
|
||||
matrix.setValues(mFloat9);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,8 +89,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
PictureInPictureSurfaceTransaction that = (PictureInPictureSurfaceTransaction) o;
|
||||
return Objects.equals(mPositionX, that.mPositionX)
|
||||
&& Objects.equals(mPositionY, that.mPositionY)
|
||||
&& Objects.equals(mScaleX, that.mScaleX)
|
||||
&& Objects.equals(mScaleY, that.mScaleY)
|
||||
&& Arrays.equals(mFloat9, that.mFloat9)
|
||||
&& Objects.equals(mRotation, that.mRotation)
|
||||
&& Objects.equals(mCornerRadius, that.mCornerRadius)
|
||||
&& Objects.equals(mWindowCrop, that.mWindowCrop);
|
||||
@@ -97,7 +97,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mPositionX, mPositionY, mScaleX, mScaleY,
|
||||
return Objects.hash(mPositionX, mPositionY, Arrays.hashCode(mFloat9),
|
||||
mRotation, mCornerRadius, mWindowCrop);
|
||||
}
|
||||
|
||||
@@ -110,8 +110,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeFloat(mPositionX);
|
||||
out.writeFloat(mPositionY);
|
||||
out.writeFloat(mScaleX);
|
||||
out.writeFloat(mScaleY);
|
||||
out.writeFloatArray(mFloat9);
|
||||
out.writeFloat(mRotation);
|
||||
out.writeFloat(mCornerRadius);
|
||||
out.writeTypedObject(mWindowCrop, 0 /* flags */);
|
||||
@@ -119,11 +118,11 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final Matrix matrix = getMatrix();
|
||||
return "PictureInPictureSurfaceTransaction("
|
||||
+ " posX=" + mPositionX
|
||||
+ " posY=" + mPositionY
|
||||
+ " scaleX=" + mScaleX
|
||||
+ " scaleY=" + mScaleY
|
||||
+ " matrix=" + matrix.toShortString()
|
||||
+ " rotation=" + mRotation
|
||||
+ " cornerRadius=" + mCornerRadius
|
||||
+ " crop=" + mWindowCrop
|
||||
@@ -134,15 +133,11 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable {
|
||||
public static void apply(@NonNull PictureInPictureSurfaceTransaction surfaceTransaction,
|
||||
@NonNull SurfaceControl surfaceControl,
|
||||
@NonNull SurfaceControl.Transaction tx) {
|
||||
final Matrix matrix = new Matrix();
|
||||
matrix.setScale(surfaceTransaction.mScaleX, surfaceTransaction.mScaleY);
|
||||
if (surfaceTransaction.mRotation != 0) {
|
||||
matrix.postRotate(surfaceTransaction.mRotation);
|
||||
}
|
||||
final Matrix matrix = surfaceTransaction.getMatrix();
|
||||
tx.setMatrix(surfaceControl, matrix, new float[9])
|
||||
.setPosition(surfaceControl,
|
||||
surfaceTransaction.mPositionX, surfaceTransaction.mPositionY)
|
||||
.setWindowCrop(surfaceControl, surfaceTransaction.getWindowCrop())
|
||||
.setWindowCrop(surfaceControl, surfaceTransaction.mWindowCrop)
|
||||
.setCornerRadius(surfaceControl, surfaceTransaction.mCornerRadius);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package com.android.systemui.shared.pip;
|
||||
|
||||
import static android.graphics.Matrix.MSCALE_X;
|
||||
import static android.graphics.Matrix.MSCALE_Y;
|
||||
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
@@ -52,8 +49,7 @@ public class PipSurfaceTransactionHelper {
|
||||
.setCornerRadius(leash, mCornerRadius);
|
||||
return new PictureInPictureSurfaceTransaction(
|
||||
mTmpDestinationRectF.left, mTmpDestinationRectF.top,
|
||||
mTmpFloat9[MSCALE_X], mTmpFloat9[MSCALE_Y],
|
||||
0 /* rotation*/, mCornerRadius, sourceBounds);
|
||||
mTmpFloat9, 0 /* rotation */, mCornerRadius, sourceBounds);
|
||||
}
|
||||
|
||||
public PictureInPictureSurfaceTransaction scale(
|
||||
@@ -68,9 +64,7 @@ public class PipSurfaceTransactionHelper {
|
||||
.setPosition(leash, positionX, positionY)
|
||||
.setCornerRadius(leash, mCornerRadius);
|
||||
return new PictureInPictureSurfaceTransaction(
|
||||
positionX, positionY,
|
||||
mTmpFloat9[MSCALE_X], mTmpFloat9[MSCALE_Y],
|
||||
degree, mCornerRadius, sourceBounds);
|
||||
positionX, positionY, mTmpFloat9, degree, mCornerRadius, sourceBounds);
|
||||
}
|
||||
|
||||
public PictureInPictureSurfaceTransaction scaleAndCrop(
|
||||
@@ -92,7 +86,7 @@ public class PipSurfaceTransactionHelper {
|
||||
.setPosition(leash, left, top)
|
||||
.setCornerRadius(leash, mCornerRadius);
|
||||
return new PictureInPictureSurfaceTransaction(
|
||||
left, top, scale, scale, 0 /* rotation */, mCornerRadius, mTmpDestinationRect);
|
||||
left, top, mTmpFloat9, 0 /* rotation */, mCornerRadius, mTmpDestinationRect);
|
||||
}
|
||||
|
||||
public PictureInPictureSurfaceTransaction scaleAndRotate(
|
||||
@@ -114,7 +108,7 @@ public class PipSurfaceTransactionHelper {
|
||||
.setPosition(leash, positionX, positionY)
|
||||
.setCornerRadius(leash, mCornerRadius);
|
||||
return new PictureInPictureSurfaceTransaction(
|
||||
positionX, positionY, scale, scale, degree, mCornerRadius, mTmpDestinationRect);
|
||||
positionX, positionY, mTmpFloat9, degree, mCornerRadius, mTmpDestinationRect);
|
||||
}
|
||||
|
||||
/** @return {@link SurfaceControl.Transaction} instance with vsync-id */
|
||||
|
||||
@@ -257,15 +257,16 @@ class PinnedTaskController {
|
||||
// be rotated.
|
||||
float dx = pipTx.mPositionX;
|
||||
float dy = pipTx.mPositionY;
|
||||
final Matrix matrix = pipTx.getMatrix();
|
||||
if (pipTx.mRotation == 90) {
|
||||
dx = pipTx.mPositionY;
|
||||
dy = areaBounds.right - pipTx.mPositionX;
|
||||
matrix.postRotate(-90);
|
||||
} else if (pipTx.mRotation == -90) {
|
||||
dx = areaBounds.bottom - pipTx.mPositionY;
|
||||
dy = pipTx.mPositionX;
|
||||
matrix.postRotate(90);
|
||||
}
|
||||
final Matrix matrix = new Matrix();
|
||||
matrix.setScale(pipTx.mScaleX, pipTx.mScaleY);
|
||||
matrix.postTranslate(dx, dy);
|
||||
t.setMatrix(pinnedTask.getSurfaceControl(), matrix, new float[9]);
|
||||
Slog.i(TAG, "Seamless rotation PiP tx=" + pipTx + " pos=" + dx + "," + dy);
|
||||
|
||||
Reference in New Issue
Block a user