Debian Codegraph @

modules/sksg/include/SkSGPaint.h

raw
1 /*
2 * Copyright 2017 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 SkSGPaint_DEFINED
9 #define SkSGPaint_DEFINED
10
11 #include "include/core/SkBlendMode.h"
12 #include "include/core/SkColor.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkRect.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "modules/sksg/include/SkSGNode.h"
18
19 class SkMatrix;
20
21 namespace skottie::internal {
22 class AnimationBuilder;
23 } // namespace skottie::internal
24
25 namespace sksg {
26 class InvalidationController;
27 class Shader;
28
29 /**
30 * Base class for nodes which provide a 'paint' (as opposed to geometry) for
31 * drawing (e.g. colors, gradients, patterns).
32 *
33 * Roughly equivalent to Skia's SkPaint.
34 */
35 class PaintNode : public Node {
36 public:
37 SkPaint makePaint() const;
38
39 SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
40 SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
41 SG_ATTRIBUTE(BlendMode , SkBlendMode , fBlendMode )
42 SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
43 SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
44 SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
45 SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
46 SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
47
48 protected:
49 PaintNode();
50
51 virtual void onApplyToPaint(SkPaint*) const = 0;
52
53 private:
54 SkScalar fOpacity = 1,
55 fStrokeWidth = 1,
56 fStrokeMiter = 4;
57 bool fAntiAlias = false;
58 SkBlendMode fBlendMode = SkBlendMode::kSrcOver;
59 SkPaint::Style fStyle = SkPaint::kFill_Style;
60 SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
61 SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
62
63 using INHERITED = Node;
64 };
65
66 /**
67 * Concrete Paint node, wrapping an SkColor.
68 */
69 class Color : public PaintNode {
70 public:
71 static sk_sp<Color> Make(SkColor c);
72
73 SG_ATTRIBUTE(Color, SkColor, fColor)
74
75 protected:
76 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
77
78 void onApplyToPaint(SkPaint*) const override;
79
80 private:
81 explicit Color(SkColor);
82
83 SkColor fColor;
84
85 friend class skottie::internal::AnimationBuilder;
86 };
87
88 /**
89 * Shader-based paint.
90 */
91 class ShaderPaint final : public PaintNode {
92 public:
93 ~ShaderPaint() override;
94
95 static sk_sp<ShaderPaint> Make(sk_sp<Shader>);
96
97 protected:
98 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
99
100 void onApplyToPaint(SkPaint*) const override;
101
102 private:
103 explicit ShaderPaint(sk_sp<Shader>);
104
105 const sk_sp<Shader> fShader;
106
107 using INHERITED = PaintNode;
108 };
109
110 } // namespace sksg
111
112 #endif // SkSGPaint_DEFINED