diff options
author | 2018-01-29 19:35:55 -0500 | |
---|---|---|
committer | 2018-01-30 18:46:35 +0000 | |
commit | 495e0f079ced1d2d23368de263f50232eca1ab4a (patch) | |
tree | d9aaf4b24c48c71e4a71b94cc0ecbaacc8a52772 /include/android | |
parent | 4e95956f117f8c188b565e7baefc252085b02653 (diff) |
Simplify SkAnimatedImage
Bug: b/63908092
Rather than keeping track of the time and whether the animation is
running, leave that up to the client. Offer a single method to decode
the next frame, allowing the client to stay one frame ahead.
Change-Id: I546013e32e3a0874181b0dce1349bbec07aaadd4
Reviewed-on: https://skia-review.googlesource.com/101544
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'include/android')
-rw-r--r-- | include/android/SkAnimatedImage.h | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/include/android/SkAnimatedImage.h b/include/android/SkAnimatedImage.h index 4a61a8b62c..51f0e5b84b 100644 --- a/include/android/SkAnimatedImage.h +++ b/include/android/SkAnimatedImage.h @@ -26,7 +26,7 @@ public: * Create an SkAnimatedImage from the SkAndroidCodec. * * Returns null on failure to allocate pixels. On success, this will - * decode the first frame. It will not animate until start() is called. + * decode the first frame. * * @param scaledSize Size to draw the image, possibly requiring scaling. * @param cropRect Rectangle to crop to after scaling. @@ -43,30 +43,11 @@ public: ~SkAnimatedImage() override; /** - * Start or resume the animation. update() must be called to advance the - * time. - */ - void start(); - - /** - * Stop the animation. update() has no effect while the animation is - * stopped. - */ - void stop(); - - /** * Reset the animation to the beginning. */ void reset(); /** - * Whether the animation is active. - * - * If true, update() can be called to animate. - */ - bool isRunning() const { return fRunning && !fFinished; } - - /** * Whether the animation completed. * * Returns true after all repetitions are complete, or an error stops the @@ -75,18 +56,28 @@ public: bool isFinished() const { return fFinished; } /** - * Returned by update if the animation is not running. + * Returned by decodeNextFrame and currentFrameDuration if the animation + * is not running. */ - static constexpr double kNotRunning = -2.0; + static constexpr int kFinished = -1; /** - * Update the current time. If the image is animating, this may decode - * a new frame. + * Decode the next frame. * - * @return the time to show the next frame, or kNotRunning if the animation - * is not running. + * If the animation is on the last frame or has hit an error, returns + * kFinished. */ - double update(double msecs); + int decodeNextFrame(); + + /** + * How long to display the current frame. + * + * Useful for the first frame, for which decodeNextFrame is called + * internally. + */ + int currentFrameDuration() { + return fCurrentFrameDuration; + } /** * Change the repetition count. @@ -130,9 +121,7 @@ private: SkMatrix fMatrix; // used only if !fSimple bool fFinished; - bool fRunning; - double fNowMS; - double fRemainingMS; + int fCurrentFrameDuration; Frame fActiveFrame; Frame fRestoreFrame; int fRepetitionCount; |