1 /*
2  * Copyright 2018 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 #ifndef SkSGRoundEffect_DEFINED
9 #define SkSGRoundEffect_DEFINED
10 
11 #include "SkSGGeometryNode.h"
12 
13 #include "SkPath.h"
14 
15 namespace sksg {
16 
17 /**
18  * Concrete Geometry node, applying a rounded-corner effect to its child.
19  */
20 class RoundEffect final : public GeometryNode {
21 public:
Make(sk_sp<GeometryNode> child)22     static sk_sp<RoundEffect> Make(sk_sp<GeometryNode> child) {
23         return child ? sk_sp<RoundEffect>(new RoundEffect(std::move(child))) : nullptr;
24     }
25 
26     ~RoundEffect() override;
27 
28     SG_ATTRIBUTE(Radius, SkScalar, fRadius)
29 
30 protected:
31     void onClip(SkCanvas*, bool antiAlias) const override;
32     void onDraw(SkCanvas*, const SkPaint&) const override;
33 
34     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
35     SkPath onAsPath() const override;
36 
37 private:
38     explicit RoundEffect(sk_sp<GeometryNode>);
39 
40     const sk_sp<GeometryNode> fChild;
41 
42     SkPath                    fRoundedPath;
43     SkScalar                  fRadius = 0;
44 
45     using INHERITED = GeometryNode;
46 };
47 
48 } // namespace sksg
49 
50 #endif // SkSGRoundEffect_DEFINED
51