Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bbed87d authored by Jian-Syuan (Shane) Wong's avatar Jian-Syuan (Shane) Wong Committed by Android (Google) Code Review
Browse files

Merge "Add new APIs to AnimationUtils that set and get expectedPresentationTimeNano"

parents 659d476d 83b22141
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -54921,6 +54921,7 @@ package android.view.animation {
  public class AnimationUtils {
    ctor public AnimationUtils();
    method public static long currentAnimationTimeMillis();
    method public static long getExpectedPresentationTimeNanos();
    method public static android.view.animation.Animation loadAnimation(android.content.Context, @AnimRes int) throws android.content.res.Resources.NotFoundException;
    method public static android.view.animation.Interpolator loadInterpolator(android.content.Context, @AnimRes @InterpolatorRes int) throws android.content.res.Resources.NotFoundException;
    method public static android.view.animation.LayoutAnimationController loadLayoutAnimation(android.content.Context, @AnimRes int) throws android.content.res.Resources.NotFoundException;
+1 −1
Original line number Diff line number Diff line
@@ -3628,7 +3628,7 @@ package android.view.accessibility {
package android.view.animation {

  public class AnimationUtils {
    method public static void lockAnimationClock(long);
    method public static void lockAnimationClock(long, long);
    method public static void unlockAnimationClock();
  }

+2 −1
Original line number Diff line number Diff line
@@ -869,7 +869,8 @@ public final class Choreographer {
                Trace.traceBegin(Trace.TRACE_TAG_VIEW, message);
            }

            AnimationUtils.lockAnimationClock(frameTimeNanos / TimeUtils.NANOS_PER_MS);
            AnimationUtils.lockAnimationClock(frameTimeNanos / TimeUtils.NANOS_PER_MS,
                    timeline.mExpectedPresentationTimeNanos);

            mFrameInfo.markInputHandlingStart();
            doCallbacks(Choreographer.CALLBACK_INPUT, frameIntervalNanos);
+22 −5
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class AnimationUtils {
        boolean animationClockLocked;
        long currentVsyncTimeMillis;
        long lastReportedTimeMillis;
        long mExpectedPresentationTimeNanos;
    };

    private static ThreadLocal<AnimationState> sAnimationState
@@ -62,7 +63,8 @@ public class AnimationUtils {
    };

    /**
     * Locks AnimationUtils{@link #currentAnimationTimeMillis()} to a fixed value for the current
     * Locks AnimationUtils{@link #currentAnimationTimeMillis()} and
     * AnimationUtils{@link #expectedPresentationTimeNanos()} to a fixed value for the current
     * thread. This is used by {@link android.view.Choreographer} to ensure that all accesses
     * during a vsync update are synchronized to the timestamp of the vsync.
     *
@@ -74,8 +76,9 @@ public class AnimationUtils {
     * Note that time is not allowed to "rewind" and must perpetually flow forward. So the
     * lock may fail if the time is in the past from a previously returned value, however
     * time will be frozen for the duration of the lock. The clock is a thread-local, so
     * ensure that {@link #lockAnimationClock(long)}, {@link #unlockAnimationClock()}, and
     * {@link #currentAnimationTimeMillis()} are all called on the same thread.
     * ensure that {@link #lockAnimationClock(long)}, {@link #unlockAnimationClock()},
     * {@link #currentAnimationTimeMillis()}, and {@link #expectedPresentationTimeNanos()}
     * are all called on the same thread.
     *
     * This is also not reference counted in any way. Any call to {@link #unlockAnimationClock()}
     * will unlock the clock for everyone on the same thread. It is therefore recommended
@@ -83,12 +86,13 @@ public class AnimationUtils {
     * {@link android.view.Choreographer} instance.
     *
     * @hide
     * */
     */
    @TestApi
    public static void lockAnimationClock(long vsyncMillis) {
    public static void lockAnimationClock(long vsyncMillis, long expectedPresentationTimeNanos) {
        AnimationState state = sAnimationState.get();
        state.animationClockLocked = true;
        state.currentVsyncTimeMillis = vsyncMillis;
        state.mExpectedPresentationTimeNanos = expectedPresentationTimeNanos;
    }

    /**
@@ -123,6 +127,19 @@ public class AnimationUtils {
        return state.lastReportedTimeMillis;
    }

    /**
     * The expected presentation time of a frame in the {@link System#nanoTime()}.
     * Developers should prefer using this method over {@link #currentAnimationTimeMillis()}
     * because it offers a more accurate time for the calculating animation progress.
     *
     * @return the expected presentation time of a frame in the
     *         {@link System#nanoTime()} time base.
     */
    public static long getExpectedPresentationTimeNanos() {
        AnimationState state = sAnimationState.get();
        return state.mExpectedPresentationTimeNanos;
    }

    /**
     * Loads an {@link Animation} object from a resource
     *