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
14namespace skottie {
15namespace internal {
16
17namespace {
18
19class PathAdapter final : public DiscardableAdapterBase<PathAdapter, sksg::Path> {
20public:
21 PathAdapter(const skjson::Value& jpath, const AnimationBuilder& abuilder)
22 : INHERITED(sksg::Path::Make()) {
23 this->bind(abuilder, jpath, fShape);
24 }
25
26private:
27 void onSync() override {
28 const auto& path_node = this->node();
29
30 SkPath path = 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.setIsVolatile(!this->isStatic());
35
36 path_node->setPath(path);
37 }
38
39 ShapeValue fShape;
40
41 using INHERITED = DiscardableAdapterBase<PathAdapter, sksg::Path>;
42};
43
44} // namespace
45
46sk_sp<sksg::Path> AnimationBuilder::attachPath(const skjson::Value& jpath) const {
47 return this->attachDiscardableAdapter<PathAdapter>(jpath, *this);
48}
49
50} // namespace internal
51} // namespace skottie
52