summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/CanvasContext.h
diff options
context:
space:
mode:
authorLeon Scroggins III <scroggo@google.com>2018-05-14 14:59:30 -0400
committerLeon Scroggins III <scroggo@google.com>2018-05-16 18:51:07 -0400
commit4afdd1caa4ff5f0890c3f4d73c6d475f9e06cefd (patch)
tree5273aecef15d3644e794416ababff8cbaacddd94 /libs/hwui/renderthread/CanvasContext.h
parent1936031cbe804fc53eb7529b3fd60f3457cb1780 (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 'libs/hwui/renderthread/CanvasContext.h')
-rw-r--r--libs/hwui/renderthread/CanvasContext.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index c2cc72a6917f..e52b6447a611 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -213,6 +213,9 @@ private:
// stopped indicates the CanvasContext will reject actual redraw operations,
// and defer repaint until it is un-stopped
bool mStopped = false;
+ // Incremented each time the CanvasContext is stopped. Used to ignore
+ // delayed messages that are triggered after stopping.
+ int mGenerationID;
// CanvasContext is dirty if it has received an update that it has not
// painted onto its surface.
bool mIsDirty = false;