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 VectorAnimatorBuilder final : public AnimatorBuilder { 18 public: 19 using VectorLenParser = bool(*)(const skjson::Value&, size_t*); 20 using VectorDataParser = bool(*)(const skjson::Value&, size_t, float*); 21 22 VectorAnimatorBuilder(std::vector<float>*, VectorLenParser, VectorDataParser); 23 24 sk_sp<KeyframeAnimator> makeFromKeyframes(const AnimationBuilder&, 25 const skjson::ArrayValue&) override; 26 27 sk_sp<Animator> makeFromExpression(ExpressionManager&, const char*) override; 28 29 private: 30 bool parseValue(const AnimationBuilder&, const skjson::Value&) const override; 31 32 bool parseKFValue(const AnimationBuilder&, 33 const skjson::ObjectValue&, 34 const skjson::Value&, 35 Keyframe::Value*) override; 36 37 const VectorLenParser fParseLen; 38 const VectorDataParser fParseData; 39 40 std::vector<float> fStorage; 41 size_t fVecLen, // size of individual vector values we store 42 fCurrentVec = 0; // vector value index being parsed (corresponding 43 // storage offset is fCurrentVec * fVecLen) 44 std::vector<float>* fTarget; 45 46 using INHERITED = AnimatorBuilder; 47 }; 48 49 } // namespace skottie::internal 50 51 #endif // SkottieVectorKeyframeAnimator_DEFINED 52