diff options
author | 2018-05-14 14:59:30 -0400 | |
---|---|---|
committer | 2018-05-16 18:51:07 -0400 | |
commit | 4afdd1caa4ff5f0890c3f4d73c6d475f9e06cefd (patch) | |
tree | 5273aecef15d3644e794416ababff8cbaacddd94 /graphics/java | |
parent | 1936031cbe804fc53eb7529b3fd60f3457cb1780 (diff) |
AnimatedImageDrawable: Eliminate unnecessary calls to redraw
Bug: 78866720
Test: Manual + systrace; existing CTS
Previously, we set hasAnimations to true when the AnimatedImageDrawable,
so that we would get a call to redraw. But if the image does not need to
show its next frame yet, the redraw was unnecessary.
Instead, add a new field to TreeInfo::Out, representing the delay time
until the image will need to be redrawn - i.e. when the duration of the
current frame has passed. Each call to prepareTree will post at most one
message to redraw, in time for the earliest animated image to be
redrawn. Post the message for one rendered frame ahead of time, so that
when it is time to show the next frame, the image has already gotten the
message to update.
On a screen with a single animated image, this drops the number of calls
to dispatchFrameCallbacks to as infrequent as possible. It is called
only when we need to draw a new frame of the image. On a screen with
multiple animated images, the calls may be redundant, but they will not
be more frequent than they would be without this change.
Switch to nsecs_t and systemTime internally, matching the rest of HWUI.
Remove mDidDraw and related. Its purpose was to prevent advancing the
animation while the image is not being drawn. But it isn't really
necessary. If it's not drawn, onDraw is not called, which is where we
trigger decoding. And onDraw already has a defense against getting too
far ahead - if its timer indicates that it should skip a frame or show
it very briefly, it will back up its timer. More importantly, mDidDraw
caused a bug, when combined with less frequent redraws. If the display
list containing the drawable doesn't need to be redrawn for other
reasons, the drawable's timer never advanced, so its animation stopped.
Fix software drawing. Compute the milliseconds in the future to draw the
next frame, and add that to SystemClock.uptimeMillis() to compute the
time to pass to scheduleSelf.
Change-Id: I13aab49922fa300f73b327be25561d7120c09ec4
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/drawable/AnimatedImageDrawable.java | 22 |
1 files changed, 2 insertions, 20 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java b/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java index 898939edabf0..4f467d9aabae 100644 --- a/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java @@ -31,6 +31,7 @@ import android.graphics.PixelFormat; import android.graphics.Rect; import android.os.Handler; import android.os.Looper; +import android.os.SystemClock; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -348,7 +349,7 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 { if (mRunnable == null) { mRunnable = this::invalidateSelf; } - scheduleSelf(mRunnable, nextUpdate); + scheduleSelf(mRunnable, nextUpdate + SystemClock.uptimeMillis()); } else if (nextUpdate == FINISHED) { // This means the animation was drawn in software mode and ended. postOnAnimationEnd(); @@ -430,23 +431,6 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 { return mState.mAutoMirrored; } - @Override - public boolean setVisible(boolean visible, boolean restart) { - if (!super.setVisible(visible, restart)) { - return false; - } - - if (mState.mNativePtr == 0) { - throw new IllegalStateException("called setVisible on empty AnimatedImageDrawable"); - } - - if (!visible) { - nMarkInvisible(mState.mNativePtr); - } - - return true; - } - // Animatable overrides /** * Return whether the animation is currently running. @@ -616,7 +600,5 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 { @FastNative private static native long nNativeByteSize(long nativePtr); @FastNative - private static native void nMarkInvisible(long nativePtr); - @FastNative private static native void nSetMirrored(long nativePtr, boolean mirror); } |