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 "include/core/SkRefCnt.h" 12 #include "modules/skottie/src/animator/KeyframeAnimator.h" 13 14 #include <cstddef> 15 #include <vector> 16 17 namespace skjson { 18 class ArrayValue; 19 class ObjectValue; 20 class Value; 21 } // namespace skjson 22 23 namespace skottie { 24 class ExpressionManager; 25 } 26 27 namespace skottie::internal { 28 class AnimationBuilder; 29 class Animator; 30 31 class VectorAnimatorBuilder final : public AnimatorBuilder { 32 public: 33 using VectorLenParser = bool(*)(const skjson::Value&, size_t*); 34 using VectorDataParser = bool(*)(const skjson::Value&, size_t, float*); 35 36 VectorAnimatorBuilder(std::vector<float>*, VectorLenParser, VectorDataParser); 37 38 sk_sp<KeyframeAnimator> makeFromKeyframes(const AnimationBuilder&, 39 const skjson::ArrayValue&) override; 40 41 sk_sp<Animator> makeFromExpression(ExpressionManager&, const char*) override; 42 43 private: 44 bool parseValue(const AnimationBuilder&, const skjson::Value&) const override; 45 46 bool parseKFValue(const AnimationBuilder&, 47 const skjson::ObjectValue&, 48 const skjson::Value&, 49 Keyframe::Value*) override; 50 51 const VectorLenParser fParseLen; 52 const VectorDataParser fParseData; 53 54 std::vector<float> fStorage; 55 size_t fVecLen, // size of individual vector values we store 56 fCurrentVec = 0; // vector value index being parsed (corresponding 57 // storage offset is fCurrentVec * fVecLen) 58 std::vector<float>* fTarget; 59 60 using INHERITED = AnimatorBuilder; 61 }; 62 63 } // namespace skottie::internal 64 65 #endif // SkottieVectorKeyframeAnimator_DEFINED 66