Use surface position for starting reveal animation
The surface position is basically relative frame - surface insets.
This aligns the same behavior as WindowState#startAnimation(anim)
that uses mSurfacePosition to animate.
If the app sets surface insets, its content will draw from the offset,
e.g. (50,50), then the surface position will be (-50,-50) to make
the window show at the requested position.
Bug: 328282706
Test: Cold or warm launch an app with calling
getWindow().getDecorView().setElevation(100f);
in onCreate. The activity window should not have a weird
offset when playing starting window reveal animation.
Change-Id: I8c4f79d513014997f28c915682640c27d761a26c
diff --git a/services/core/java/com/android/server/wm/TaskOrganizerController.java b/services/core/java/com/android/server/wm/TaskOrganizerController.java
index 7fc61e1..a84a99a 100644
--- a/services/core/java/com/android/server/wm/TaskOrganizerController.java
+++ b/services/core/java/com/android/server/wm/TaskOrganizerController.java
@@ -573,7 +573,7 @@
// Capture the animation surface control for activity's main window
static class StartingWindowAnimationAdaptor implements AnimationAdapter {
- SurfaceControl mAnimationLeash;
+
@Override
public boolean getShowWallpaper() {
return false;
@@ -582,14 +582,10 @@
@Override
public void startAnimation(SurfaceControl animationLeash, SurfaceControl.Transaction t,
int type, @NonNull SurfaceAnimator.OnAnimationFinishedCallback finishCallback) {
- mAnimationLeash = animationLeash;
}
@Override
public void onAnimationCancelled(SurfaceControl animationLeash) {
- if (mAnimationLeash == animationLeash) {
- mAnimationLeash = null;
- }
}
@Override
@@ -604,9 +600,6 @@
@Override
public void dump(PrintWriter pw, String prefix) {
- pw.print(prefix + "StartingWindowAnimationAdaptor mCapturedLeash=");
- pw.print(mAnimationLeash);
- pw.println();
}
@Override
@@ -616,16 +609,16 @@
static SurfaceControl applyStartingWindowAnimation(WindowState window) {
final SurfaceControl.Transaction t = window.getPendingTransaction();
- final Rect mainFrame = window.getRelativeFrame();
final StartingWindowAnimationAdaptor adaptor = new StartingWindowAnimationAdaptor();
window.startAnimation(t, adaptor, false, ANIMATION_TYPE_STARTING_REVEAL);
- if (adaptor.mAnimationLeash == null) {
+ final SurfaceControl leash = window.getAnimationLeash();
+ if (leash == null) {
Slog.e(TAG, "Cannot start starting window animation, the window " + window
+ " was removed");
return null;
}
- t.setPosition(adaptor.mAnimationLeash, mainFrame.left, mainFrame.top);
- return adaptor.mAnimationLeash;
+ t.setPosition(leash, window.mSurfacePosition.x, window.mSurfacePosition.y);
+ return leash;
}
boolean addStartingWindow(Task task, ActivityRecord activity, int launchTheme,
@@ -696,7 +689,9 @@
removalInfo.roundedCornerRadius =
topActivity.mLetterboxUiController.getRoundedCornersRadius(mainWindow);
removalInfo.windowAnimationLeash = applyStartingWindowAnimation(mainWindow);
- removalInfo.mainFrame = mainWindow.getRelativeFrame();
+ removalInfo.mainFrame = new Rect(mainWindow.getFrame());
+ removalInfo.mainFrame.offsetTo(mainWindow.mSurfacePosition.x,
+ mainWindow.mSurfacePosition.y);
}
}
try {
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 18ac0e7..9450673 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -695,7 +695,8 @@
*/
private boolean mDrawnStateEvaluated;
- private final Point mSurfacePosition = new Point();
+ /** The surface position relative to the parent container. */
+ final Point mSurfacePosition = new Point();
/**
* A region inside of this window to be excluded from touch.