Skia
2D Graphics Library
SkSGPaint.h
Go to the documentation of this file.
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 
12 
14 #include "include/core/SkColor.h"
15 #include "include/core/SkPaint.h"
16 
17 namespace skottie::internal {
18 class AnimationBuilder;
19 } // namespace skottie::internal
20 namespace sksg {
21 
22 class Shader;
23 
30 class PaintNode : public Node {
31 public:
32  SkPaint makePaint() const;
33 
34  SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
35  SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
36  SG_ATTRIBUTE(BlendMode , SkBlendMode , fBlendMode )
37  SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
38  SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
39  SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
40  SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
41  SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
42 
43 protected:
45 
46  virtual void onApplyToPaint(SkPaint*) const = 0;
47 
48 private:
49  SkScalar fOpacity = 1,
50  fStrokeWidth = 1,
51  fStrokeMiter = 4;
52  bool fAntiAlias = false;
55  SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
56  SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
57 
58  using INHERITED = Node;
59 };
60 
64 class Color : public PaintNode {
65 public:
67 
68  SG_ATTRIBUTE(Color, SkColor, fColor)
69 
70 protected:
72 
73  void onApplyToPaint(SkPaint*) const override;
74 
75 private:
76  explicit Color(SkColor);
77 
78  SkColor fColor;
79 
81 };
82 
86 class ShaderPaint final : public PaintNode {
87 public:
88  ~ShaderPaint() override;
89 
91 
92 protected:
94 
95  void onApplyToPaint(SkPaint*) const override;
96 
97 private:
98  explicit ShaderPaint(sk_sp<Shader>);
99 
100  const sk_sp<Shader> fShader;
101 
102  using INHERITED = PaintNode;
103 };
104 
105 } // namespace sksg
106 
107 #endif // SkSGPaint_DEFINED
SkBlendMode
Blends are operators that take in two colors (source, destination) and return a new color.
Definition: SkBlendMode.h:38
@ kSrcOver
r = s + (1-sa)*d
Types, consts, functions, and macros for colors.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:99
float SkScalar
Definition: SkScalar.h:14
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
Cap
Definition: SkPaint.h:333
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
Style
Definition: SkPaint.h:192
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
Join
Definition: SkPaint.h:358
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
Definition: SkRefCnt.h:119
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Concrete Paint node, wrapping an SkColor.
Definition: SkSGPaint.h:64
static sk_sp< Color > Make(SkColor c)
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
friend class skottie::internal::AnimationBuilder
Definition: SkSGPaint.h:80
void onApplyToPaint(SkPaint *) const override
Receiver for invalidation events.
Definition: SkSGInvalidationController.h:25
Base class for all scene graph nodes.
Definition: SkSGNode.h:32
Node(uint32_t invalTraits)
Base class for nodes which provide a 'paint' (as opposed to geometry) for drawing (e....
Definition: SkSGPaint.h:30
SkPaint makePaint() const
virtual void onApplyToPaint(SkPaint *) const =0
Shader-based paint.
Definition: SkSGPaint.h:86
~ShaderPaint() override
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
static sk_sp< ShaderPaint > Make(sk_sp< Shader >)
void onApplyToPaint(SkPaint *) const override
Definition: Skottie.h:39
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582