Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / modules / skottie / src / layers / shapelayer / RoundCorners.cpp
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/skottie/src/layers/shapelayer/ShapeLayer.h"
13 #include "modules/sksg/include/SkSGGeometryEffect.h"
14
15 namespace skottie {
16 namespace internal {
17
18 namespace  {
19
20 class RoundCornersAdapter final : public DiscardableAdapterBase<RoundCornersAdapter,
21                                                                 sksg::RoundEffect> {
22 public:
23     RoundCornersAdapter(const skjson::ObjectValue& jround,
24                         const AnimationBuilder& abuilder,
25                         sk_sp<sksg::GeometryNode> child)
26         : INHERITED(sksg::RoundEffect::Make(std::move(child))) {
27         this->bind(abuilder, jround["r"], fRadius);
28     }
29
30 private:
31     void onSync() override {
32         this->node()->setRadius(fRadius);
33     }
34
35     ScalarValue fRadius = 0;
36
37     using INHERITED = DiscardableAdapterBase<RoundCornersAdapter, sksg::RoundEffect>;
38 };
39
40 } // namespace
41
42 std::vector<sk_sp<sksg::GeometryNode>> ShapeBuilder::AttachRoundGeometryEffect(
43         const skjson::ObjectValue& jround, const AnimationBuilder* abuilder,
44         std::vector<sk_sp<sksg::GeometryNode>>&& geos) {
45     std::vector<sk_sp<sksg::GeometryNode>> rounded;
46     rounded.reserve(geos.size());
47
48     for (auto& g : geos) {
49         rounded.push_back(
50             abuilder->attachDiscardableAdapter<RoundCornersAdapter>
51                         (jround, *abuilder, std::move(g)));
52     }
53
54     return rounded;
55 }
56
57 } // namespace internal
58 } // namespace skottie