From 2d5fb12526e24cd91eedc795393aaf46cb6b59b8 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Wed, 24 Jan 2018 14:30:12 -0500 Subject: [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 Commit-Queue: Florin Malita --- experimental/skottie/SkottieAnimator.cpp | 13 +++---------- experimental/skottie/SkottieAnimator.h | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'experimental') 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(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::Parse(k["e"], &fV1)) { + if (!this->isHold() && + (!ValueTraits::Parse(k["e"], &fV1) || + ValueTraits::Cardinality(fV0) != ValueTraits::Cardinality(fV1))) { return false; } + return !prev || ValueTraits::Cardinality(fV0) == ValueTraits::Cardinality(prev->fV0); + } - return ValueTraits::Cardinality(fV0) == ValueTraits::Cardinality(fV1) && - (!prev || ValueTraits::Cardinality(fV0) == ValueTraits::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); } -- cgit v1.2.3