[skottie] Remove inPoint/outPoint/frameRate from public API
TBR=
Change-Id: Ice4de3abe350c4570c22e859a36dbd445527fa41
Reviewed-on: https://skia-review.googlesource.com/131300
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skottie/include/Skottie.h b/modules/skottie/include/Skottie.h
index 5114ae4..a199383 100644
--- a/modules/skottie/include/Skottie.h
+++ b/modules/skottie/include/Skottie.h
@@ -59,7 +59,8 @@
/**
* Updates the animation state for |t|.
*
- * @param t normalized [0..1] frame selector, where 0 == inPoint and 1 == outPoint.
+ * @param t normalized [0..1] frame selector (0 -> first frame, 1 -> final frame)
+ *
*/
void seek(SkScalar t);
@@ -72,9 +73,6 @@
const SkString& version() const { return fVersion; }
const SkSize& size() const { return fSize; }
- SkScalar frameRate() const { return fFrameRate; }
- SkScalar inPoint() const { return fInPoint; }
- SkScalar outPoint() const { return fOutPoint; }
void setShowInval(bool show);
diff --git a/modules/skottie/src/Skottie.cpp b/modules/skottie/src/Skottie.cpp
index 250aa2e..d2c2cce 100644
--- a/modules/skottie/src/Skottie.cpp
+++ b/modules/skottie/src/Skottie.cpp
@@ -62,7 +62,7 @@
struct AttachContext {
const ResourceProvider& fResources;
const AssetMap& fAssets;
- const float fFrameRate;
+ const float fDuration;
sksg::AnimatorList& fAnimators;
};
@@ -724,21 +724,21 @@
class SkottieAnimatorAdapter final : public sksg::Animator {
public:
- SkottieAnimatorAdapter(sk_sp<Animation> animation, float frameRate)
+ SkottieAnimatorAdapter(sk_sp<Animation> animation, float time_scale)
: fAnimation(std::move(animation))
- , fFrameRate(frameRate) {
+ , fTimeScale(time_scale) {
SkASSERT(fAnimation);
- SkASSERT(fFrameRate > 0);
}
protected:
void onTick(float t) {
- fAnimation->seek(t * fFrameRate / fAnimation->frameRate());
+ // TODO: we prolly need more sophisticated timeline mapping for nested animations.
+ fAnimation->seek(t * fTimeScale);
}
private:
const sk_sp<Animation> fAnimation;
- const float fFrameRate;
+ const float fTimeScale;
};
const auto resStream = ctx->fResources.openStream(path);
@@ -753,8 +753,10 @@
return nullptr;
}
- ctx->fAnimators.push_back(skstd::make_unique<SkottieAnimatorAdapter>(animation,
- ctx->fFrameRate));
+
+ ctx->fAnimators.push_back(
+ skstd::make_unique<SkottieAnimatorAdapter>(animation,
+ animation->duration() / ctx->fDuration));
return sk_make_sp<SkottieSGAdapter>(std::move(animation));
}
@@ -1051,7 +1053,7 @@
sksg::AnimatorList layer_animators;
AttachContext local_ctx = { layerCtx->fCtx->fResources,
layerCtx->fCtx->fAssets,
- layerCtx->fCtx->fFrameRate,
+ layerCtx->fCtx->fDuration,
layer_animators};
// Layer attachers may adjust these.
@@ -1283,7 +1285,7 @@
}
sksg::AnimatorList animators;
- AttachContext ctx = { resources, assets, fFrameRate, animators };
+ AttachContext ctx = { resources, assets, this->duration(), animators };
auto root = AttachComposition(json, &ctx);
stats->fAnimatorCount = animators.size();
diff --git a/tools/viewer/SkottieSlide.cpp b/tools/viewer/SkottieSlide.cpp
index 8eecf43..aa08533 100644
--- a/tools/viewer/SkottieSlide.cpp
+++ b/tools/viewer/SkottieSlide.cpp
@@ -65,11 +65,10 @@
if (fAnimation) {
fAnimation->setShowInval(fShowAnimationInval);
- SkDebugf("loaded Bodymovin animation v: %s, size: [%f %f], fr: %f\n",
+ SkDebugf("loaded Bodymovin animation v: %s, size: [%f %f]\n",
fAnimation->version().c_str(),
fAnimation->size().width(),
- fAnimation->size().height(),
- fAnimation->frameRate());
+ fAnimation->size().height());
} else {
SkDebugf("failed to load Bodymovin animation: %s\n", fPath.c_str());
}