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