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 #include "modules/skottie/src/Adapter.h" 9 #include "modules/skottie/src/SkottieJson.h" 10 #include "modules/skottie/src/SkottiePriv.h" 11 #include "modules/skottie/src/SkottieValue.h" 12 #include "modules/sksg/include/SkSGPath.h" 13 14 namespace skottie { 15 namespace internal { 16 17 namespace { 18 19 class PathAdapter final : public DiscardableAdapterBase<PathAdapter, sksg::Path> { 20 public: PathAdapter(const skjson::Value & jpath,const AnimationBuilder & abuilder)21 PathAdapter(const skjson::Value& jpath, const AnimationBuilder& abuilder) 22 : INHERITED(sksg::Path::Make()) { 23 this->bind(abuilder, jpath, fShape); 24 } 25 26 private: onSync()27 void onSync() override { 28 const auto& path_node = this->node(); 29 30 auto path = ValueTraits<ShapeValue>::As<SkPath>(fShape); 31 32 // FillType is tracked in the SG node, not in keyframes -- make sure we preserve it. 33 path.setFillType(path_node->getFillType()); 34 path_node->setPath(path); 35 } 36 37 ShapeValue fShape; 38 39 using INHERITED = DiscardableAdapterBase<PathAdapter, sksg::Path>; 40 }; 41 42 } // namespace 43 attachPath(const skjson::Value & jpath) const44sk_sp<sksg::Path> AnimationBuilder::attachPath(const skjson::Value& jpath) const { 45 return this->attachDiscardableAdapter<PathAdapter, sk_sp<sksg::Path>>(jpath, *this); 46 } 47 48 } // namespace internal 49 } // namespace skottie 50