Don't offset snapshot surface position

The snapshot surface will be offset with its parent, so no need to
offset itself.

Bug: 196173550
Test: test with demo app on click back from split to split.
Change-Id: I1c65bf2e4b1b8c489ad7fe5eec1418707d590d13
This commit is contained in:
Chris Li
2021-09-24 10:23:57 +08:00
parent 2f47fab607
commit a09442c099
2 changed files with 14 additions and 6 deletions

View File

@@ -16,6 +16,7 @@
package androidx.window.extensions.embedding;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.Choreographer;
import android.view.RemoteAnimationTarget;
@@ -24,6 +25,7 @@ import android.view.animation.Animation;
import android.view.animation.Transformation;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Wrapper to handle the TaskFragment animation update in one {@link SurfaceControl.Transaction}.
@@ -33,6 +35,7 @@ class TaskFragmentAnimationAdapter {
private final RemoteAnimationTarget mTarget;
private final SurfaceControl mLeash;
private final boolean mSizeChanged;
private final Point mPosition;
private final Transformation mTransformation = new Transformation();
private final float[] mMatrix = new float[9];
private final float[] mVecs = new float[4];
@@ -41,7 +44,7 @@ class TaskFragmentAnimationAdapter {
TaskFragmentAnimationAdapter(@NonNull Animation animation,
@NonNull RemoteAnimationTarget target) {
this(animation, target, target.leash, false /* sizeChanged */);
this(animation, target, target.leash, false /* sizeChanged */, null /* position */);
}
/**
@@ -49,11 +52,14 @@ class TaskFragmentAnimationAdapter {
*/
TaskFragmentAnimationAdapter(@NonNull Animation animation,
@NonNull RemoteAnimationTarget target, @NonNull SurfaceControl leash,
boolean sizeChanged) {
boolean sizeChanged, @Nullable Point position) {
mAnimation = animation;
mTarget = target;
mLeash = leash;
mSizeChanged = sizeChanged;
mPosition = position != null
? position
: new Point(target.localBounds.left, target.localBounds.top);
}
/** Called on frame update. */
@@ -65,8 +71,7 @@ class TaskFragmentAnimationAdapter {
currentPlayTime = Math.min(currentPlayTime, mAnimation.getDuration());
mAnimation.getTransformation(currentPlayTime, mTransformation);
mTransformation.getMatrix().postTranslate(
mTarget.localBounds.left, mTarget.localBounds.top);
mTransformation.getMatrix().postTranslate(mPosition.x, mPosition.y);
t.setMatrix(mLeash, mTransformation.getMatrix(), mMatrix);
t.setAlpha(mLeash, mTransformation.getAlpha());
t.setFrameTimelineVsync(Choreographer.getInstance().getVsyncId());

View File

@@ -23,6 +23,7 @@ import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_OPEN;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.graphics.Point;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
@@ -193,10 +194,12 @@ class TaskFragmentAnimationRunner extends IRemoteAnimationRunner.Stub {
if (target.startBounds != null) {
final Animation[] animations =
mAnimationSpec.createChangeBoundsChangeAnimations(target);
// The snapshot surface will always be at (0, 0) of its parent.
adapters.add(new TaskFragmentAnimationAdapter(animations[0], target,
target.startLeash, false /* sizeChanged */));
target.startLeash, false /* sizeChanged */, new Point(0, 0)));
// The end surface will have size change for scaling.
adapters.add(new TaskFragmentAnimationAdapter(animations[1], target,
target.leash, true /* sizeChanged */));
target.leash, true /* sizeChanged */, null /* position */));
continue;
}