Florin Malita | af99f3e | 2020-02-03 12:09:15 -0500 | [diff] [blame] | 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: |
| 21 | PathAdapter(const skjson::Value& jpath, const AnimationBuilder& abuilder) |
| 22 | : INHERITED(sksg::Path::Make()) { |
| 23 | this->bind(abuilder, jpath, fShape); |
| 24 | } |
| 25 | |
| 26 | private: |
| 27 | void onSync() override { |
| 28 | const auto& path_node = this->node(); |
| 29 | |
Florin Malita | eeaabc4 | 2020-04-01 10:48:36 -0400 | [diff] [blame] | 30 | SkPath path = fShape; |
Florin Malita | af99f3e | 2020-02-03 12:09:15 -0500 | [diff] [blame] | 31 | |
| 32 | // FillType is tracked in the SG node, not in keyframes -- make sure we preserve it. |
| 33 | path.setFillType(path_node->getFillType()); |
Florin Malita | eeaabc4 | 2020-04-01 10:48:36 -0400 | [diff] [blame] | 34 | path.setIsVolatile(!this->isStatic()); |
| 35 | |
Florin Malita | af99f3e | 2020-02-03 12:09:15 -0500 | [diff] [blame] | 36 | path_node->setPath(path); |
| 37 | } |
| 38 | |
| 39 | ShapeValue fShape; |
| 40 | |
| 41 | using INHERITED = DiscardableAdapterBase<PathAdapter, sksg::Path>; |
| 42 | }; |
| 43 | |
| 44 | } // namespace |
| 45 | |
| 46 | sk_sp<sksg::Path> AnimationBuilder::attachPath(const skjson::Value& jpath) const { |
Ben Wagner | 9339266 | 2020-03-20 14:45:24 -0400 | [diff] [blame] | 47 | return this->attachDiscardableAdapter<PathAdapter>(jpath, *this); |
Florin Malita | af99f3e | 2020-02-03 12:09:15 -0500 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | } // namespace internal |
| 51 | } // namespace skottie |