From 094ccde2380bfbb615e25d0d80208148fcd47f17 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Sat, 30 Dec 2017 12:27:00 -0500 Subject: Initial Lottie loader impl (Skotty) Coarse workflow: * Construction 1) build a Json tree 2) collect asset IDs (for preComp/image layer resolution) 3) "attach" pass - traverse the Json tree - build an SkSG dom, one fragment at a time - attach "animator" objects to the dom, for each animated prop 4) done, we can throw away the Json tree * For each animation tick 1) iterate over active animators and poke their respective dom nodes/attributes 2) revalidate the SkSG dom 3) draw the SkSG dom Note: post construction, things are super-simple - we just poke SkSG DOM attributes with interpolated values, and everything else is handled by SkSG (invalidation, revalidation, render). Change-Id: I96a02be7eb4fb4cb3831f59bf2b3908ea190c0dd Reviewed-on: https://skia-review.googlesource.com/89420 Reviewed-by: Mike Reed Commit-Queue: Florin Malita --- experimental/skotty/SkottyAnimator.cpp | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 experimental/skotty/SkottyAnimator.cpp (limited to 'experimental/skotty/SkottyAnimator.cpp') diff --git a/experimental/skotty/SkottyAnimator.cpp b/experimental/skotty/SkottyAnimator.cpp new file mode 100644 index 0000000000..e08cf35995 --- /dev/null +++ b/experimental/skotty/SkottyAnimator.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkottyAnimator.h" + +namespace skotty { + +namespace { + +SkScalar lerp_scalar(SkScalar v0, SkScalar v1, float t) { + SkASSERT(t >= 0 && t <= 1); + return v0 * (1 - t) + v1 * t; +} + +SkPoint lerp_point(const SkPoint& v0, const SkPoint& v1, float t) { + SkASSERT(t >= 0 && t <= 1); + return SkPoint::Make(lerp_scalar(v0.x(), v1.x(), t), + lerp_scalar(v0.y(), v1.y(), t)); +} + +} // namespace + +template <> +void KeyframeInterval::lerp(float t, ScalarValue* v) const { + *v = lerp_scalar(fV0, fV1, t); +} + +template <> +void KeyframeInterval::lerp(float t, VectorValue* v) const { + SkASSERT(fV0.cardinality() == fV1.cardinality()); + SkASSERT(v->cardinality() == 0); + + v->fVals.reserve(fV0.cardinality()); + for (int i = 0; i < fV0.fVals.count(); ++i) { + v->fVals.emplace_back(lerp_scalar(fV0.fVals[i], fV1.fVals[i], t)); + } +} + +template <> +void KeyframeInterval::lerp(float t, ShapeValue* v) const { + SkASSERT(fV0.cardinality() == fV1.cardinality()); + SkASSERT(v->cardinality() == 0); + + v->fVertices.reserve(fV0.cardinality()); + for (int i = 0; i < fV0.fVertices.count(); ++i) { + v->fVertices.push_back( + BezierVertex({ + lerp_point(fV0.fVertices[i].fInPoint , fV1.fVertices[i].fInPoint , t), + lerp_point(fV0.fVertices[i].fOutPoint, fV1.fVertices[i].fOutPoint, t), + lerp_point(fV0.fVertices[i].fVertex , fV1.fVertices[i].fVertex , t) + })); + } +} + +} // namespace skotty -- cgit v1.2.3