From 2d74fafdaf9a5adb74bb336a0052206da629feaa Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Mon, 18 Dec 2017 19:21:27 +0100 Subject: Fix starting of animations We need to manually process the first animation frame as mStartTime of ValueAnimator would only be set when processing the next animation frame. Test: go/wm-smoke Test: Add some additional tracing about current playing time and observe no delay. Bug: 64674361 Change-Id: Iad753bfb7b86cfd57f265b5084a3d24f967dcaf3 --- .../java/com/android/server/wm/SurfaceAnimationRunner.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/SurfaceAnimationRunner.java b/services/core/java/com/android/server/wm/SurfaceAnimationRunner.java index 86afd4eda9aa..3a41eb0e2afc 100644 --- a/services/core/java/com/android/server/wm/SurfaceAnimationRunner.java +++ b/services/core/java/com/android/server/wm/SurfaceAnimationRunner.java @@ -16,6 +16,7 @@ package com.android.server.wm; +import static android.util.TimeUtils.NANOS_PER_MS; import static android.view.Choreographer.CALLBACK_TRAVERSAL; import static android.view.Choreographer.getSfInstance; @@ -25,7 +26,6 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.Nullable; -import android.os.SystemClock; import android.util.ArrayMap; import android.view.Choreographer; import android.view.SurfaceControl; @@ -144,10 +144,6 @@ class SurfaceAnimationRunner { scheduleApplyTransaction(); }); - if (a.mAnimSpec.canSkipFirstFrame()) { - anim.setCurrentPlayTime(Choreographer.getFrameDelay()); - } - anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { @@ -173,6 +169,14 @@ class SurfaceAnimationRunner { } }); anim.start(); + if (a.mAnimSpec.canSkipFirstFrame()) { + // If we can skip the first frame, we start one frame later. + anim.setCurrentPlayTime(mChoreographer.getFrameIntervalNanos() / NANOS_PER_MS); + } + + // Immediately start the animation by manually applying an animation frame. Otherwise, the + // start time would only be set in the next frame, leading to a delay. + anim.doAnimationFrame(mChoreographer.getFrameTime()); a.mAnim = anim; mRunningAnimations.put(a.mLeash, a); } -- cgit v1.2.3-59-g8ed1b