1 | /* |
2 | * Copyright 2020 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef SkottieVectorKeyframeAnimator_DEFINED |
9 | #define SkottieVectorKeyframeAnimator_DEFINED |
10 | |
11 | #include "modules/skottie/src/animator/KeyframeAnimator.h" |
12 | |
13 | #include <vector> |
14 | |
15 | namespace skottie::internal { |
16 | |
17 | class VectorKeyframeAnimatorBuilder final : public KeyframeAnimatorBuilder { |
18 | public: |
19 | using VectorLenParser = bool(*)(const skjson::Value&, size_t*); |
20 | using VectorDataParser = bool(*)(const skjson::Value&, size_t, float*); |
21 | |
22 | VectorKeyframeAnimatorBuilder(std::vector<float>*, VectorLenParser, VectorDataParser); |
23 | |
24 | sk_sp<KeyframeAnimator> make(const AnimationBuilder&, const skjson::ArrayValue&) override; |
25 | |
26 | private: |
27 | bool parseValue(const AnimationBuilder&, const skjson::Value&) const override; |
28 | |
29 | bool parseKFValue(const AnimationBuilder&, |
30 | const skjson::ObjectValue&, |
31 | const skjson::Value&, |
32 | Keyframe::Value*) override; |
33 | |
34 | const VectorLenParser fParseLen; |
35 | const VectorDataParser fParseData; |
36 | |
37 | std::vector<float> fStorage; |
38 | size_t fVecLen, // size of individual vector values we store |
39 | fCurrentVec = 0; // vector value index being parsed (corresponding |
40 | // storage offset is fCurrentVec * fVecLen) |
41 | std::vector<float>* fTarget; |
42 | }; |
43 | |
44 | } // namespace skottie::internal |
45 | |
46 | #endif // SkottieVectorKeyframeAnimator_DEFINED |
47 | |