[skottie] Animator tweaks

  * reserve SkPath storage to avoid incremental allocations
  * refactor eval() to avoid copying data when interpolation is not
    triggered

Change-Id: I467affbbfd652e8fa2a486acab7d6c7b9165d49f
Reviewed-on: https://skia-review.googlesource.com/146166
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skottie/src/SkottieAnimator.cpp b/modules/skottie/src/SkottieAnimator.cpp
index 20f9d6b..e56271c 100644
--- a/modules/skottie/src/SkottieAnimator.cpp
+++ b/modules/skottie/src/SkottieAnimator.cpp
@@ -187,9 +187,7 @@
 
 protected:
     void onTick(float t) override {
-        this->eval(this->frame(t), t, &fScratch);
-
-        fApplyFunc(fScratch);
+        fApplyFunc(*this->eval(this->frame(t), t, &fScratch));
     }
 
 private:
@@ -213,18 +211,20 @@
         return fVs.count() - 1;
     }
 
-    void eval(const KeyframeRec& rec, float t, T* v) const {
+    const T* eval(const KeyframeRec& rec, float t, T* v) const {
         SkASSERT(rec.isValid());
         if (rec.isConstant() || t <= rec.t0) {
-            *v = fVs[rec.vidx0];
+            return &fVs[rec.vidx0];
         } else if (t >= rec.t1) {
-            *v = fVs[rec.vidx1];
-        } else {
-            const auto lt = this->localT(rec, t);
-            const auto& v0 = fVs[rec.vidx0];
-            const auto& v1 = fVs[rec.vidx1];
-            ValueTraits<T>::Lerp(v0, v1, lt, v);
+            return &fVs[rec.vidx1];
         }
+
+        const auto lt = this->localT(rec, t);
+        const auto& v0 = fVs[rec.vidx0];
+        const auto& v1 = fVs[rec.vidx1];
+        ValueTraits<T>::Lerp(v0, v1, lt, v);
+
+        return v;
     }
 
     const std::function<void(const T&)> fApplyFunc;
diff --git a/modules/skottie/src/SkottieValue.cpp b/modules/skottie/src/SkottieValue.cpp
index f35ea20..d327955 100644
--- a/modules/skottie/src/SkottieValue.cpp
+++ b/modules/skottie/src/SkottieValue.cpp
@@ -123,6 +123,9 @@
     SkPath path;
 
     if (!shape.fVertices.empty()) {
+        // conservatively assume all cubics
+        path.incReserve(1 + SkToU32(shape.fVertices.size() * 3));
+
         path.moveTo(shape.fVertices.front().fVertex);
     }