Lock free app animations (5/n): Reimplement skip first frame

Test: go/wm-smoke
Test: Close app, inspect transition with WindowScope, make sure
first frame of animation is skipped
Bug:

Change-Id: I68c135621df47c50696e318c4394da36ce806922
This commit is contained in:
Jorim Jaggi
2017-11-20 19:49:00 +01:00
parent 988f66885c
commit 2e3c31d092
7 changed files with 35 additions and 6 deletions

View File

@@ -86,8 +86,11 @@ class AppWindowThumbnail implements Animatable {
void startAnimation(Transaction t, Animation anim) {
anim.restrictDuration(MAX_ANIMATION_DURATION);
anim.scaleCurrentDuration(mAppToken.mService.getTransitionAnimationScaleLocked());
mSurfaceAnimator.startAnimation(t, new LocalAnimationAdapter(new WindowAnimationSpec(anim,
new Point()), mAppToken.mService.mSurfaceAnimationRunner),
mSurfaceAnimator.startAnimation(t,
new LocalAnimationAdapter(
new WindowAnimationSpec(anim, new Point(),
mAppToken.mService.mAppTransition.canSkipFirstFrame()),
mAppToken.mService.mSurfaceAnimationRunner),
false /* hidden */);
}
@@ -95,6 +98,7 @@ class AppWindowThumbnail implements Animatable {
}
void setShowing(Transaction pendingTransaction, boolean show) {
// TODO: Not needed anymore once thumbnail is attached to the app.
if (show) {
pendingTransaction.show(mSurfaceControl);
} else {
@@ -129,6 +133,9 @@ class AppWindowThumbnail implements Animatable {
@Override
public void onAnimationLeashDestroyed(Transaction t) {
// TODO: Once attached to app token, we don't need to hide it immediately if thumbnail
// became visible.
t.hide(mSurfaceControl);
}

View File

@@ -1526,7 +1526,9 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
if (a != null) {
final AnimationAdapter adapter = new LocalAnimationAdapter(
new WindowAnimationSpec(a, new Point()), mService.mSurfaceAnimationRunner);
new WindowAnimationSpec(a, new Point(),
mService.mAppTransition.canSkipFirstFrame()),
mService.mSurfaceAnimationRunner);
startAnimation(getPendingTransaction(), adapter, !isVisible());
if (a.getZAdjustment() == Animation.ZORDER_TOP) {
mAppAnimator.animLayerAdjustment = 1;

View File

@@ -108,5 +108,12 @@ class LocalAnimationAdapter implements AnimationAdapter {
* @param currentPlayTime The current time of the animation.
*/
void apply(Transaction t, SurfaceControl leash, long currentPlayTime);
/**
* @see AppTransition#canSkipFirstFrame
*/
default boolean canSkipFirstFrame() {
return false;
}
}
}

View File

@@ -142,6 +142,11 @@ class SurfaceAnimationRunner {
// Transaction will be applied in the commit phase.
scheduleApplyTransaction();
});
if (a.mAnimSpec.canSkipFirstFrame()) {
anim.setCurrentPlayTime(Choreographer.getFrameDelay());
}
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {

View File

@@ -38,10 +38,12 @@ public class WindowAnimationSpec implements AnimationSpec {
private Animation mAnimation;
private final Point mPosition = new Point();
private final ThreadLocal<TmpValues> mThreadLocalTmps = ThreadLocal.withInitial(TmpValues::new);
private final boolean mCanSkipFirstFrame;
public WindowAnimationSpec(Animation animation, Point position) {
public WindowAnimationSpec(Animation animation, Point position, boolean canSkipFirstFrame) {
mAnimation = animation;
mPosition.set(position.x, position.y);
mCanSkipFirstFrame = canSkipFirstFrame;
}
@Override
@@ -88,6 +90,11 @@ public class WindowAnimationSpec implements AnimationSpec {
}
}
@Override
public boolean canSkipFirstFrame() {
return mCanSkipFirstFrame;
}
/**
* Tries to find a {@link TranslateAnimation} inside the {@code animation}.
*

View File

@@ -4276,7 +4276,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
anim.restrictDuration(MAX_ANIMATION_DURATION);
anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
final AnimationAdapter adapter = new LocalAnimationAdapter(
new WindowAnimationSpec(anim, mSurfacePosition), mService.mSurfaceAnimationRunner);
new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
mService.mSurfaceAnimationRunner);
startAnimation(mPendingTransaction, adapter);
commitPendingTransaction();
}

View File

@@ -181,7 +181,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase {
final Animation a = new TranslateAnimation(-10, 10, 0, 0);
a.initialize(0, 0, 0, 0);
a.setDuration(50);
return new WindowAnimationSpec(a, new Point(0, 0));
return new WindowAnimationSpec(a, new Point(0, 0), false /* canSkipFirstFrame */);
}
/**