[skottie] Animation::animationTick() -> Animation::seek()
Replace poorly defined animationTick() with a normalized seek() method.
TBR=
Change-Id: Id2ea17bb426fe86fede0d6c8a3d93236902f10af
Reviewed-on: https://skia-review.googlesource.com/130508
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skottie/src/Skottie.cpp b/modules/skottie/src/Skottie.cpp
index 8396b5b..ddea1be 100644
--- a/modules/skottie/src/Skottie.cpp
+++ b/modules/skottie/src/Skottie.cpp
@@ -733,9 +733,7 @@
protected:
void onTick(float t) {
- // map back from frame # to ms.
- const auto t_ms = t * 1000 / fFrameRate;
- fAnimation->animationTick(t_ms);
+ fAnimation->seek(t * fFrameRate / fAnimation->frameRate());
}
private:
@@ -1288,7 +1286,7 @@
fScene = sksg::Scene::Make(std::move(root), std::move(animators));
// In case the client calls render before the first tick.
- this->animationTick(0);
+ this->seek(0);
}
Animation::~Animation() = default;
@@ -1312,16 +1310,11 @@
fScene->render(canvas);
}
-void Animation::animationTick(SkMSec ms) {
+void Animation::seek(SkScalar t) {
if (!fScene)
return;
- // 't' in the BM model really means 'frame #'
- auto t = static_cast<float>(ms) * fFrameRate / 1000;
-
- t = fInPoint + std::fmod(t, fOutPoint - fInPoint);
-
- fScene->animate(t);
+ fScene->animate(fInPoint + SkTPin(t, 0.0f, 1.0f) * (fOutPoint - fInPoint));
}
} // namespace skottie