diff options
author | 2017-12-30 12:27:00 -0500 | |
---|---|---|
committer | 2017-12-30 22:55:39 +0000 | |
commit | 094ccde2380bfbb615e25d0d80208148fcd47f17 (patch) | |
tree | d6233c61996a3f268938953608b0b3a2d4590e07 /experimental/skotty/SkottyProperties.h | |
parent | 83b2b08afcf903a455cd0ea999d0c2936088fffd (diff) |
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 <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental/skotty/SkottyProperties.h')
-rw-r--r-- | experimental/skotty/SkottyProperties.h | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/experimental/skotty/SkottyProperties.h b/experimental/skotty/SkottyProperties.h new file mode 100644 index 0000000000..0273aea2f4 --- /dev/null +++ b/experimental/skotty/SkottyProperties.h @@ -0,0 +1,128 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkottyProperties_DEFINED +#define SkottyProperties_DEFINED + +#include "SkPoint.h" +#include "SkSize.h" +#include "SkottyPriv.h" +#include "SkRefCnt.h" +#include "SkTArray.h" +#include "SkTypes.h" + +#include <memory> + +class SkPath; + +namespace sksg { +class RenderNode; +class Transform; +} + +namespace skotty { + +struct BezierVertex { + SkPoint fInPoint, // "in" control point, relative to the vertex + fOutPoint, // "out" control point, relative to the vertex + fVertex; +}; + +struct ScalarValue { + float fVal; + + static bool Parse(const Json::Value&, ScalarValue*); + + ScalarValue() : fVal(0) {} + explicit ScalarValue(SkScalar v) : fVal(v) {} + + ScalarValue& operator=(SkScalar v) { fVal = v; return *this; } + + operator SkScalar() const { return fVal; } + + size_t cardinality() const { return 1; } + + template <typename T> + T as() const; +}; + +template <> +inline SkScalar ScalarValue::as<SkScalar>() const { + return fVal; +} + +struct VectorValue { + SkTArray<ScalarValue, true> fVals; + + static bool Parse(const Json::Value&, VectorValue*); + + VectorValue() = default; + VectorValue(const VectorValue&) = delete; + VectorValue(VectorValue&&) = default; + VectorValue& operator==(const VectorValue&) = delete; + + size_t cardinality() const { return SkTo<size_t>(fVals.count()); } + + template <typename T> + T as() const; +}; + +struct ShapeValue { + SkTArray<BezierVertex, true> fVertices; + bool fClose = false; + + ShapeValue() = default; + ShapeValue(const ShapeValue&) = delete; + ShapeValue(ShapeValue&&) = default; + ShapeValue& operator==(const ShapeValue&) = delete; + + static bool Parse(const Json::Value&, ShapeValue*); + + size_t cardinality() const { return SkTo<size_t>(fVertices.count()); } + + template <typename T> + T as() const; +}; + +// Composite properties. + +#define COMPOSITE_PROPERTY(p_name, p_type, p_default) \ + void set##p_name(const p_type& p) { \ + if (p == f##p_name) return; \ + f##p_name = p; \ + this->apply(); \ + } \ + private: \ + p_type f##p_name = p_default; \ + public: + +class CompositeTransform final : public SkRefCnt { +public: + explicit CompositeTransform(sk_sp<sksg::RenderNode>); + + const sk_sp<sksg::Transform>& node() const { return fTransformNode; } + + COMPOSITE_PROPERTY(AnchorPoint, SkPoint , SkPoint::Make(0, 0)) + COMPOSITE_PROPERTY(Position , SkPoint , SkPoint::Make(0, 0)) + COMPOSITE_PROPERTY(Scale , SkVector, SkPoint::Make(100, 100)) + COMPOSITE_PROPERTY(Rotation , SkScalar, 0) + COMPOSITE_PROPERTY(Skew , SkScalar, 0) + COMPOSITE_PROPERTY(SkewAxis , SkScalar, 0) + +private: + void apply(); + + sk_sp<sksg::Transform> fTransformNode; + + using INHERITED = SkRefCnt; +}; + +#undef COMPOSITE_PROPERTY + +} // namespace skotty + +#endif // SkottyProperties_DEFINED |