diff options
-rw-r--r-- | include/android/SkAnimatedImage.h | 8 | ||||
-rw-r--r-- | tests/AnimatedImageTest.cpp | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/android/SkAnimatedImage.h b/include/android/SkAnimatedImage.h index d74c6bec49..d2f4e3d66c 100644 --- a/include/android/SkAnimatedImage.h +++ b/include/android/SkAnimatedImage.h @@ -67,6 +67,14 @@ public: bool isRunning() const { return fRunning && !fFinished; } /** + * Whether the animation completed. + * + * Returns true after all repetitions are complete, or an error stops the + * animation. Gets reset to false if the animation is restarted. + */ + bool isFinished() const { return fFinished; } + + /** * Update the current time. If the image is animating, this may decode * a new frame. * diff --git a/tests/AnimatedImageTest.cpp b/tests/AnimatedImageTest.cpp index c8113d3fb1..584a69c383 100644 --- a/tests/AnimatedImageTest.cpp +++ b/tests/AnimatedImageTest.cpp @@ -132,8 +132,10 @@ DEF_TEST(AnimatedImage, r) { if (i == frameInfos.size() - 1 && defaultRepetitionCount == 0) { REPORTER_ASSERT(r, next == std::numeric_limits<double>::max()); REPORTER_ASSERT(r, !animatedImage->isRunning()); + REPORTER_ASSERT(r, animatedImage->isFinished()); } else { REPORTER_ASSERT(r, animatedImage->isRunning()); + REPORTER_ASSERT(r, !animatedImage->isFinished()); double expectedNext = currentTime + frameInfos[i].fDuration; if (next != expectedNext) { ERRORF(r, "Time did not match for frame %i: next: %g expected: %g", @@ -182,6 +184,7 @@ DEF_TEST(AnimatedImage, r) { double interval = next - currentTime; animatedImage->stop(); REPORTER_ASSERT(r, !animatedImage->isRunning()); + REPORTER_ASSERT(r, !animatedImage->isFinished()); currentTime = next; double stoppedNext = animatedImage->update(currentTime); @@ -201,6 +204,7 @@ DEF_TEST(AnimatedImage, r) { } REPORTER_ASSERT(r, animatedImage->isRunning()); + REPORTER_ASSERT(r, !animatedImage->isFinished()); animatedImage->reset(); if (!testDraw(animatedImage, 0)) { ERRORF(r, "reset failed"); @@ -214,6 +218,7 @@ DEF_TEST(AnimatedImage, r) { animatedImage->setRepetitionCount(loopCount); for (int loops = 0; loops <= loopCount; loops++) { REPORTER_ASSERT(r, animatedImage->isRunning()); + REPORTER_ASSERT(r, !animatedImage->isFinished()); for (size_t i = 0; i < frameInfos.size(); ++i) { double next = animatedImage->update(currentTime); if (animatedImage->isRunning()) { @@ -224,6 +229,11 @@ DEF_TEST(AnimatedImage, r) { if (animatedImage->isRunning()) { ERRORF(r, "%s animation still running after %i loops", file, loopCount); } + + if (!animatedImage->isFinished()) { + ERRORF(r, "%s animation should have finished with specified loop count (%i)", + file, loopCount); + } } } } |