Make SkAnimatedImage::update return sentinel when stopped

Bug: b/63908092
Change-Id: I585f3d3efde1db4d5be36b11f19fe6e88f131608
Reviewed-on: https://skia-review.googlesource.com/98062
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
This commit is contained in:
Leon Scroggins III 2018-01-22 12:31:21 -05:00 committed by Skia Commit-Bot
parent 980a48de64
commit 8524c30a97
3 changed files with 15 additions and 8 deletions

View File

@ -74,13 +74,17 @@ public:
*/
bool isFinished() const { return fFinished; }
/**
* Returned by update if the animation is not running.
*/
static constexpr double kNotRunning = -2.0;
/**
* Update the current time. If the image is animating, this may decode
* a new frame.
*
* @return the time to show the next frame.
* Returns numeric_limits<double>::max() if there is no max frame to
* show, and -1.0 if the animation is not running.
* @return the time to show the next frame, or kNotRunning if the animation
* is not running.
*/
double update(double msecs);

View File

@ -156,12 +156,12 @@ int SkAnimatedImage::computeNextFrame(int current, bool* animationEnded) {
double SkAnimatedImage::finish() {
fFinished = true;
fRunning = false;
return std::numeric_limits<double>::max();
return kNotRunning;
}
double SkAnimatedImage::update(double msecs) {
if (fFinished) {
return std::numeric_limits<double>::max();
return kNotRunning;
}
const double lastUpdateMS = fNowMS;
@ -175,7 +175,7 @@ double SkAnimatedImage::update(double msecs) {
fNowMS = lastUpdateMS;
} else {
if (!fRunning) {
return std::numeric_limits<double>::max();
return kNotRunning;
}
if (lastUpdateMS == kInit) {

View File

@ -130,7 +130,7 @@ DEF_TEST(AnimatedImage, r) {
for (size_t i = 0; i < frameInfos.size(); ++i) {
double next = animatedImage->update(currentTime);
if (i == frameInfos.size() - 1 && defaultRepetitionCount == 0) {
REPORTER_ASSERT(r, next == std::numeric_limits<double>::max());
REPORTER_ASSERT(r, next == SkAnimatedImage::kNotRunning);
REPORTER_ASSERT(r, !animatedImage->isRunning());
REPORTER_ASSERT(r, animatedImage->isFinished());
} else {
@ -188,7 +188,7 @@ DEF_TEST(AnimatedImage, r) {
currentTime = next;
double stoppedNext = animatedImage->update(currentTime);
REPORTER_ASSERT(r, stoppedNext == std::numeric_limits<double>::max());
REPORTER_ASSERT(r, stoppedNext == SkAnimatedImage::kNotRunning);
if (!testDraw(animatedImage, i)) {
ERRORF(r, "Advanced the frame while stopped?");
failed = true;
@ -223,9 +223,12 @@ DEF_TEST(AnimatedImage, r) {
double next = animatedImage->update(currentTime);
if (animatedImage->isRunning()) {
currentTime = next;
} else {
REPORTER_ASSERT(r, next == SkAnimatedImage::kNotRunning);
}
}
}
if (animatedImage->isRunning()) {
ERRORF(r, "%s animation still running after %i loops", file, loopCount);
}