diff options
author | Florin Malita <fmalita@chromium.org> | 2018-01-24 19:07:59 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-25 00:37:11 +0000 |
commit | a55a591e5ab2a89baea017d987a497570e6803d6 (patch) | |
tree | 3f2446ae3cf12bfa7efc4873c265c88f74d4e5a5 /experimental/skottie | |
parent | 531b3c0a4e1895950e6aeb18a53272c19a8b9169 (diff) |
[skottie] Cache the last keyframe
We can avoid searching on every tick.
TBR=
Change-Id: Ifc3ff40f1f5ec2bf865c09a8e784223aa8a96674
Reviewed-on: https://skia-review.googlesource.com/99580
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental/skottie')
-rw-r--r-- | experimental/skottie/SkottieAnimator.h | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/experimental/skottie/SkottieAnimator.h b/experimental/skottie/SkottieAnimator.h index 7ea4929280..8320ec499e 100644 --- a/experimental/skottie/SkottieAnimator.h +++ b/experimental/skottie/SkottieAnimator.h @@ -130,10 +130,12 @@ public: } void onTick(float t) override { - const auto& frame = this->findFrame(t); + if (!fCurrentFrame || !fCurrentFrame->contains(t)) { + fCurrentFrame = this->findFrame(t); + } T val; - frame.eval(t, &val); + fCurrentFrame->eval(t, &val); fFunc(val); } @@ -143,18 +145,17 @@ private: : fFrames(std::move(frames)) , fFunc(std::move(applyFunc)) {} - const KeyframeInterval<T>& findFrame(float t) const; + const KeyframeInterval<T>* findFrame(float t) const; const SkTArray<KeyframeInterval<T>, true> fFrames; - const ApplyFuncT fFunc; + const ApplyFuncT fFunc; + const KeyframeInterval<T>* fCurrentFrame = nullptr; }; template <typename T> -const KeyframeInterval<T>& Animator<T>::findFrame(float t) const { +const KeyframeInterval<T>* Animator<T>::findFrame(float t) const { SkASSERT(!fFrames.empty()); - // TODO: cache last/current frame? - auto f0 = fFrames.begin(), f1 = fFrames.end() - 1; @@ -162,11 +163,11 @@ const KeyframeInterval<T>& Animator<T>::findFrame(float t) const { SkASSERT(f1->isValid()); if (t < f0->t0()) { - return *f0; + return f0; } if (t > f1->t1()) { - return *f1; + return f1; } while (f0 != f1) { @@ -186,7 +187,7 @@ const KeyframeInterval<T>& Animator<T>::findFrame(float t) const { SkASSERT(f0 == f1); SkASSERT(f0->contains(t)); - return *f0; + return f0; } } // namespace skottie |