blob: 2c3f51496e36c97f35d40fbf4689dd8aa1a91137 [file] [log] [blame]
Florin Malitaaf99f3e2020-02-03 12:09:15 -05001/*
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
Florin Malitaeeaabc42020-04-01 10:48:36 -040030 SkPath path = fShape;
Florin Malitaaf99f3e2020-02-03 12:09:15 -050031
32 // FillType is tracked in the SG node, not in keyframes -- make sure we preserve it.
33 path.setFillType(path_node->getFillType());
Florin Malitaeeaabc42020-04-01 10:48:36 -040034 path.setIsVolatile(!this->isStatic());
35
Florin Malitaaf99f3e2020-02-03 12:09:15 -050036 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 {
Ben Wagner93392662020-03-20 14:45:24 -040047 return this->attachDiscardableAdapter<PathAdapter>(jpath, *this);
Florin Malitaaf99f3e2020-02-03 12:09:15 -050048}
49
50} // namespace internal
51} // namespace skottie