• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     bool onContains(const SkPoint&)        const override;
34 
35     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
36     SkPath onAsPath() const override;
37 
38 private:
39     explicit RoundEffect(sk_sp<GeometryNode>);
40 
41     const sk_sp<GeometryNode> fChild;
42 
43     SkPath                    fRoundedPath;
44     SkScalar                  fRadius = 0;
45 
46     using INHERITED = GeometryNode;
47 };
48 
49 } // namespace sksg
50 
51 #endif // SkSGRoundEffect_DEFINED
52