Skia
2D Graphics Library
SkSGColorFilter.h
Go to the documentation of this file.
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 SkSGColorFilter_DEFINED
9 #define SkSGColorFilter_DEFINED
10 
12 
14 
15 #include <vector>
16 
17 class SkColorFilter;
18 
19 namespace sksg {
20 
21 class Color;
22 
26 class ColorFilter : public EffectNode {
27 protected:
29 
30  void onRender(SkCanvas*, const RenderContext*) const final;
31  const RenderNode* onNodeAt(const SkPoint&) const final;
32 
34 
36 
37 private:
38  sk_sp<SkColorFilter> fColorFilter;
39 
40  using INHERITED = EffectNode;
41 };
42 
48 class ExternalColorFilter final : public EffectNode {
49 public:
51 
53 
55 
56 protected:
57  void onRender(SkCanvas*, const RenderContext*) const override;
58 
59 private:
61 
62  sk_sp<SkColorFilter> fColorFilter;
63 
64  using INHERITED = EffectNode;
65 };
66 
70 class ModeColorFilter final : public ColorFilter {
71 public:
72  ~ModeColorFilter() override;
73 
75  sk_sp<Color> color,
76  SkBlendMode mode);
77 
78 protected:
80 
81 private:
83 
84  const sk_sp<Color> fColor;
85  const SkBlendMode fMode;
86 
87  using INHERITED = ColorFilter;
88 };
89 
95 class GradientColorFilter final : public ColorFilter {
96 public:
98 
100  sk_sp<Color> c0, sk_sp<Color> c1);
102  std::vector<sk_sp<Color>>);
103 
104  SG_ATTRIBUTE(Weight, float, fWeight)
105 
106 protected:
108 
109 private:
111 
112  const std::vector<sk_sp<Color>> fColors;
113 
114  float fWeight = 0;
115 
116  using INHERITED = ColorFilter;
117 };
118 
119 } // namespace sksg
120 
121 #endif // SkSGColorFilter_DEFINED
SkBlendMode
Blends are operators that take in two colors (source, destination) and return a new color.
Definition: SkBlendMode.h:38
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:99
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:35
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Base class for nodes which apply a color filter when rendering their descendants.
Definition: SkSGColorFilter.h:26
const RenderNode * onNodeAt(const SkPoint &) const final
virtual sk_sp< SkColorFilter > onRevalidateFilter()=0
ColorFilter(sk_sp< RenderNode >)
SkRect onRevalidate(InvalidationController *, const SkMatrix &) final
void onRender(SkCanvas *, const RenderContext *) const final
Base class for nodes which apply some transformation when rendering their descendants.
Definition: SkSGEffectNode.h:21
EffectNode(sk_sp< RenderNode >, uint32_t inval_traits=0)
Wrapper for externally-managed SkColorFilters.
Definition: SkSGColorFilter.h:48
static sk_sp< ExternalColorFilter > Make(sk_sp< RenderNode > child)
void onRender(SkCanvas *, const RenderContext *) const override
Tint/multi-tone color effect: maps RGB colors to the [C0,C1][C1,C2]..[Cn-1,Cn] gradient based on inpu...
Definition: SkSGColorFilter.h:95
static sk_sp< GradientColorFilter > Make(sk_sp< RenderNode > child, sk_sp< Color > c0, sk_sp< Color > c1)
static sk_sp< GradientColorFilter > Make(sk_sp< RenderNode > child, std::vector< sk_sp< Color >>)
sk_sp< SkColorFilter > onRevalidateFilter() override
Receiver for invalidation events.
Definition: SkSGInvalidationController.h:25
Concrete SkBlendModeColorFilter Effect node.
Definition: SkSGColorFilter.h:70
~ModeColorFilter() override
sk_sp< SkColorFilter > onRevalidateFilter() override
static sk_sp< ModeColorFilter > Make(sk_sp< RenderNode > child, sk_sp< Color > color, SkBlendMode mode)
Base class for nodes which can render to a canvas.
Definition: SkSGRenderNode.h:27
SK_API sk_sp< SkShader > Color(SkColor)
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
Definition: SkSGRenderNode.h:53