diff options
author | Florin Malita <fmalita@chromium.org> | 2018-01-24 14:30:12 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-24 19:52:49 +0000 |
commit | 2d5fb12526e24cd91eedc795393aaf46cb6b59b8 (patch) | |
tree | 697d4a1158f9bf66a6ced63349f5ee3ef27920cc /experimental | |
parent | 04f8b79acbec4a03fbac199d4bb2b561046e2268 (diff) |
[skottie] Clamp keyframe values
We can skip interpolation if |t| is out of range or the interval is
constant ("hold").
TBR=
Change-Id: I0602d36557f46592ab673201ed2b4a96d40dc461
Reviewed-on: https://skia-review.googlesource.com/99420
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/skottie/SkottieAnimator.cpp | 13 | ||||
-rw-r--r-- | experimental/skottie/SkottieAnimator.h | 23 |
2 files changed, 18 insertions, 18 deletions
diff --git a/experimental/skottie/SkottieAnimator.cpp b/experimental/skottie/SkottieAnimator.cpp index da00beb2fe..13f14dbf75 100644 --- a/experimental/skottie/SkottieAnimator.cpp +++ b/experimental/skottie/SkottieAnimator.cpp @@ -69,19 +69,12 @@ bool KeyframeIntervalBase::parse(const Json::Value& k, KeyframeIntervalBase* pre float KeyframeIntervalBase::localT(float t) const { SkASSERT(this->isValid()); - - // 'hold' pins to v0 - if (fHold) { - return 0; - } + SkASSERT(!this->isHold()); + SkASSERT(t > fT0 && t < fT1); auto lt = (t - fT0) / (fT1 - fT0); - if (fCubicMap) { - lt = fCubicMap->computeYFromX(lt); - } - - return SkTPin<float>(lt, 0, 1); + return fCubicMap ? fCubicMap->computeYFromX(lt) : lt; } template <> diff --git a/experimental/skottie/SkottieAnimator.h b/experimental/skottie/SkottieAnimator.h index c03449d11a..062a4d8969 100644 --- a/experimental/skottie/SkottieAnimator.h +++ b/experimental/skottie/SkottieAnimator.h @@ -65,21 +65,28 @@ public: return false; } - if (this->isHold()) { - // Hold v1 == v0. - fV1 = fV0; - } else if (!ValueTraits<T>::Parse(k["e"], &fV1)) { + if (!this->isHold() && + (!ValueTraits<T>::Parse(k["e"], &fV1) || + ValueTraits<T>::Cardinality(fV0) != ValueTraits<T>::Cardinality(fV1))) { return false; } + return !prev || ValueTraits<T>::Cardinality(fV0) == ValueTraits<T>::Cardinality(prev->fV0); + } - return ValueTraits<T>::Cardinality(fV0) == ValueTraits<T>::Cardinality(fV1) && - (!prev || ValueTraits<T>::Cardinality(fV0) == ValueTraits<T>::Cardinality(prev->fV0)); + void eval(float t, T* v) const { + if (this->isHold() || t <= this->t0()) { + *v = fV0; + } else if (t >= this->t1()) { + *v = fV1; + } else { + this->lerp(t, v); + } } +private: void lerp(float t, T*) const; -private: // Start/end values. T fV0, fV1; @@ -134,7 +141,7 @@ public: const auto& frame = this->findFrame(t); ValT val; - frame.lerp(t, &val); + frame.eval(t, &val); fFunc(fTarget.get(), val); } |