diff options
author | Leon Scroggins III <scroggo@google.com> | 2018-01-20 10:33:24 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-22 18:53:47 +0000 |
commit | 4c11945a971f18177aa494b773b24d88a942bba6 (patch) | |
tree | d413112fe36318bc3dd201fb298413bbf7c5cb27 /include/android | |
parent | 19dd8fbabfbf38644c47af4b0feac2392e9049fc (diff) |
Respect repetition count in SkAnimatedImage
Bug: b/63908092
By default use the repetition count stored in the encoded data (if
any). Allow setting the repetition count manually, so that the
animation will stop after n+1 total cycles (unless -1 is used for
infinite).
If the animation is complete, make start reset it.
When the animation is not running, make update return max double (i.e.
no need to update any time soon).
Fix a bug where the first call to update returned -1.
Share write_bm with CodecAnimTest, for debugging.
Update Sample to check isRunning rather than keeping its own record
of whether the animation is running.
Change-Id: I883e4d7325f7a7b23a422fa9d756f9ea3018f0f8
Reviewed-on: https://skia-review.googlesource.com/97082
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 | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/android/SkAnimatedImage.h b/include/android/SkAnimatedImage.h index 1c1a2fc039..d74c6bec49 100644 --- a/include/android/SkAnimatedImage.h +++ b/include/android/SkAnimatedImage.h @@ -76,6 +76,17 @@ public: */ double update(double msecs); + /** + * Change the repetition count. + * + * By default, the image will repeat the number of times indicated in the + * encoded data. + * + * Use SkCodec::kRepetitionCountInfinite for infinite, and 0 to show all + * frames once and then stop. + */ + void setRepetitionCount(int count); + protected: SkRect onGetBounds() override; void onDraw(SkCanvas*) override; @@ -95,6 +106,7 @@ private: const SkImageInfo fDecodeInfo; const SkIRect fCropRect; const sk_sp<SkPicture> fPostProcess; + const int fFrameCount; const bool fSimple; // no crop, scale, or postprocess SkMatrix fMatrix; // used only if !fSimple @@ -104,9 +116,15 @@ private: double fRemainingMS; Frame fActiveFrame; Frame fRestoreFrame; + int fRepetitionCount; + int fRepetitionsCompleted; SkAnimatedImage(std::unique_ptr<SkAndroidCodec>, SkISize scaledSize, SkImageInfo decodeInfo, SkIRect cropRect, sk_sp<SkPicture> postProcess); + SkAnimatedImage(std::unique_ptr<SkAndroidCodec>); + + int computeNextFrame(int current, bool* animationEnded); + double finish(); typedef SkDrawable INHERITED; }; |