summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jorim Jaggi <jjaggi@google.com> 2017-12-18 19:21:27 +0100
committer Jorim Jaggi <jjaggi@google.com> 2017-12-27 15:49:55 +0100
commit2d74fafdaf9a5adb74bb336a0052206da629feaa (patch)
tree7d0f9a1733502c6944d197bba07288915958ebdb
parentb0fc817f284899cf4524b79a840bb1753b966119 (diff)
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
-rw-r--r--services/core/java/com/android/server/wm/SurfaceAnimationRunner.java14
1 files 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);
}