| Flutter Impeller |

color_filter.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_AIKS_COLOR_FILTER_H_
6 #define FLUTTER_IMPELLER_AIKS_COLOR_FILTER_H_
7
8 #include "impeller/entity/contents/filters/color_filter_contents.h"
9 #include "impeller/geometry/color.h"
10
11 namespace impeller {
12
13 struct Paint;
14
15 /*******************************************************************************
16 ******* ColorFilter
17 ******************************************************************************/
18
19 class ColorFilter {
20 public:
21 /// A procedure that filters a given unpremultiplied color to produce a new
22 /// unpremultiplied color.
23 using ColorFilterProc = std::function<Color(Color)>;
24
25 ColorFilter();
26
27 virtual ~ColorFilter();
28
29 static std::shared_ptr<ColorFilter> MakeBlend(BlendMode blend_mode,
30 Color color);
31
32 static std::shared_ptr<ColorFilter> MakeMatrix(ColorMatrix color_matrix);
33
34 static std::shared_ptr<ColorFilter> MakeSrgbToLinear();
35
36 static std::shared_ptr<ColorFilter> MakeLinearToSrgb();
37
38 static std::shared_ptr<ColorFilter> MakeComposed(
39 const std::shared_ptr<ColorFilter>& outer,
40 const std::shared_ptr<ColorFilter>& inner);
41
42 /// @brief Wraps the given filter input with a GPU-based filter that will
43 /// perform the color operation. The given input will first be
44 /// rendered to a texture and then filtered.
45 ///
46 /// Note that this operation has no consideration for the original
47 /// geometry mask of the filter input. And the entire input texture is
48 /// treated as color information.
49 virtual std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
50 std::shared_ptr<FilterInput> input,
51 ColorFilterContents::AbsorbOpacity absorb_opacity) const = 0;
52
53 /// @brief Returns a function that can be used to filter unpremultiplied
54 /// Impeller Colors on the CPU.
55 virtual ColorFilterProc GetCPUColorFilterProc() const = 0;
56
57 virtual std::shared_ptr<ColorFilter> Clone() const = 0;
58 };
59
60 /*******************************************************************************
61 ******* BlendColorFilter
62 ******************************************************************************/
63
64 class BlendColorFilter final : public ColorFilter {
65 public:
66 BlendColorFilter(BlendMode blend_mode, Color color);
67
68 ~BlendColorFilter() override;
69
70 // |ColorFilter|
71 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
72 std::shared_ptr<FilterInput> input,
73 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
74
75 // |ColorFilter|
76 ColorFilterProc GetCPUColorFilterProc() const override;
77
78 // |ColorFilter|
79 std::shared_ptr<ColorFilter> Clone() const override;
80
81 private:
82 BlendMode blend_mode_;
83 Color color_;
84 };
85
86 /*******************************************************************************
87 ******* MatrixColorFilter
88 ******************************************************************************/
89
90 class MatrixColorFilter final : public ColorFilter {
91 public:
92 explicit MatrixColorFilter(ColorMatrix color_matrix);
93
94 ~MatrixColorFilter() override;
95
96 // |ColorFilter|
97 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
98 std::shared_ptr<FilterInput> input,
99 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
100
101 // |ColorFilter|
102 ColorFilterProc GetCPUColorFilterProc() const override;
103
104 // |ColorFilter|
105 std::shared_ptr<ColorFilter> Clone() const override;
106
107 private:
108 ColorMatrix color_matrix_;
109 };
110
111 /*******************************************************************************
112 ******* SrgbToLinearColorFilter
113 ******************************************************************************/
114
115 class SrgbToLinearColorFilter final : public ColorFilter {
116 public:
117 explicit SrgbToLinearColorFilter();
118
119 ~SrgbToLinearColorFilter() override;
120
121 // |ColorFilter|
122 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
123 std::shared_ptr<FilterInput> input,
124 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
125
126 // |ColorFilter|
127 ColorFilterProc GetCPUColorFilterProc() const override;
128
129 // |ColorFilter|
130 std::shared_ptr<ColorFilter> Clone() const override;
131 };
132
133 /*******************************************************************************
134 ******* LinearToSrgbColorFilter
135 ******************************************************************************/
136
137 class LinearToSrgbColorFilter final : public ColorFilter {
138 public:
139 explicit LinearToSrgbColorFilter();
140
141 ~LinearToSrgbColorFilter() override;
142
143 // |ColorFilter|
144 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
145 std::shared_ptr<FilterInput> input,
146 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
147
148 // |ColorFilter|
149 ColorFilterProc GetCPUColorFilterProc() const override;
150
151 // |ColorFilter|
152 std::shared_ptr<ColorFilter> Clone() const override;
153 };
154
155 /// @brief Applies color filters as f(g(x)), where x is the input color.
156 class ComposedColorFilter final : public ColorFilter {
157 public:
158 ComposedColorFilter(const std::shared_ptr<ColorFilter>& outer,
159 const std::shared_ptr<ColorFilter>& inner);
160
161 ~ComposedColorFilter() override;
162
163 // |ColorFilter|
164 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
165 std::shared_ptr<FilterInput> input,
166 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
167
168 // |ColorFilter|
169 ColorFilterProc GetCPUColorFilterProc() const override;
170
171 // |ColorFilter|
172 std::shared_ptr<ColorFilter> Clone() const override;
173
174 private:
175 std::shared_ptr<ColorFilter> outer_;
176 std::shared_ptr<ColorFilter> inner_;
177 };
178
179 } // namespace impeller
180
181 #endif // FLUTTER_IMPELLER_AIKS_COLOR_FILTER_H_
impeller::ComposedColorFilter
Applies color filters as f(g(x)), where x is the input color.
Definition: color_filter.h:156
impeller::MatrixColorFilter::~MatrixColorFilter
~MatrixColorFilter() override
impeller::ColorFilter
Definition: color_filter.h:19
impeller::MatrixColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:92
impeller::BlendColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:55
impeller::BlendColorFilter::BlendColorFilter
BlendColorFilter(BlendMode blend_mode, Color color)
Definition: color_filter.cc:50
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::Color
Definition: color.h:124
impeller::ColorFilter::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: color_filter.h:25
impeller::ColorFilter::GetCPUColorFilterProc
virtual ColorFilterProc GetCPUColorFilterProc() const =0
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
impeller::ColorFilter::MakeComposed
static std::shared_ptr< ColorFilter > MakeComposed(const std::shared_ptr< ColorFilter > &outer, const std::shared_ptr< ColorFilter > &inner)
Definition: color_filter.cc:40
impeller::MatrixColorFilter::MatrixColorFilter
MatrixColorFilter(ColorMatrix color_matrix)
Definition: color_filter.cc:78
impeller::ColorFilter::Clone
virtual std::shared_ptr< ColorFilter > Clone() const =0
impeller::ColorFilter::ColorFilter
ColorFilter()
impeller::MatrixColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:83
impeller::BlendColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:70
impeller::ComposedColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:176
impeller::SrgbToLinearColorFilter
Definition: color_filter.h:115
impeller::SrgbToLinearColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:124
impeller::LinearToSrgbColorFilter::LinearToSrgbColorFilter
LinearToSrgbColorFilter()
impeller::ColorFilter::MakeBlend
static std::shared_ptr< ColorFilter > MakeBlend(BlendMode blend_mode, Color color)
Definition: color_filter.cc:23
impeller::LinearToSrgbColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:150
impeller::BlendColorFilter::~BlendColorFilter
~BlendColorFilter() override
impeller::ComposedColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:166
impeller::SrgbToLinearColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:111
impeller::SrgbToLinearColorFilter::~SrgbToLinearColorFilter
~SrgbToLinearColorFilter() override
impeller::LinearToSrgbColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:137
impeller::SrgbToLinearColorFilter::SrgbToLinearColorFilter
SrgbToLinearColorFilter()
impeller::LinearToSrgbColorFilter
Definition: color_filter.h:137
impeller::BlendColorFilter
Definition: color_filter.h:64
impeller::ComposedColorFilter::~ComposedColorFilter
~ComposedColorFilter() override
color_filter_contents.h
impeller::MatrixColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:98
impeller::ColorFilter::MakeMatrix
static std::shared_ptr< ColorFilter > MakeMatrix(ColorMatrix color_matrix)
Definition: color_filter.cc:28
impeller::BlendColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:64
impeller::ComposedColorFilter::ComposedColorFilter
ComposedColorFilter(const std::shared_ptr< ColorFilter > &outer, const std::shared_ptr< ColorFilter > &inner)
Definition: color_filter.cc:158
impeller::ColorFilter::~ColorFilter
virtual ~ColorFilter()
impeller::ColorFilter::MakeLinearToSrgb
static std::shared_ptr< ColorFilter > MakeLinearToSrgb()
Definition: color_filter.cc:36
impeller::LinearToSrgbColorFilter::~LinearToSrgbColorFilter
~LinearToSrgbColorFilter() override
impeller::ComposedColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:186
color.h
impeller::ColorFilter::WrapWithGPUColorFilter
virtual std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const =0
Wraps the given filter input with a GPU-based filter that will perform the color operation....
impeller::MatrixColorFilter
Definition: color_filter.h:90
impeller::ColorFilter::MakeSrgbToLinear
static std::shared_ptr< ColorFilter > MakeSrgbToLinear()
Definition: color_filter.cc:32
impeller::LinearToSrgbColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:145
impeller::SrgbToLinearColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:119
impeller::ColorMatrix
Definition: color.h:117
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:14
impeller
Definition: aiks_context.cc:10