| Flutter Impeller |

image_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_IMAGE_FILTER_H_
6 #define FLUTTER_IMPELLER_AIKS_IMAGE_FILTER_H_
7
8 #include "impeller/aiks/color_filter.h"
9 #include "impeller/core/sampler_descriptor.h"
10 #include "impeller/entity/contents/filters/filter_contents.h"
11 #include "impeller/entity/entity.h"
12 #include "impeller/geometry/matrix.h"
13 #include "impeller/geometry/sigma.h"
14
15 namespace impeller {
16
17 struct Paint;
18
19 class LocalMatrixImageFilter;
20 class BlurImageFilter;
21 class DilateImageFilter;
22 class ErodeImageFilter;
23 class MatrixImageFilter;
24 class ComposeImageFilter;
25 class ColorImageFilter;
26
27 class ImageFilterVisitor {
28 public:
29 virtual void Visit(const BlurImageFilter& filter) = 0;
30 virtual void Visit(const LocalMatrixImageFilter& filter) = 0;
31 virtual void Visit(const DilateImageFilter& filter) = 0;
32 virtual void Visit(const ErodeImageFilter& filter) = 0;
33 virtual void Visit(const MatrixImageFilter& filter) = 0;
34 virtual void Visit(const ComposeImageFilter& filter) = 0;
35 virtual void Visit(const ColorImageFilter& filter) = 0;
36 };
37
38 /*******************************************************************************
39 ******* ImageFilter
40 ******************************************************************************/
41
42 class ImageFilter {
43 public:
44 ImageFilter();
45
46 virtual ~ImageFilter();
47
48 static std::shared_ptr<ImageFilter> MakeBlur(
49 Sigma sigma_x,
50 Sigma sigma_y,
51 FilterContents::BlurStyle blur_style,
52 Entity::TileMode tile_mode);
53
54 static std::shared_ptr<ImageFilter> MakeDilate(Radius radius_x,
55 Radius radius_y);
56
57 static std::shared_ptr<ImageFilter> MakeErode(Radius radius_x,
58 Radius radius_y);
59
60 static std::shared_ptr<ImageFilter> MakeMatrix(
61 const Matrix& matrix,
62 SamplerDescriptor sampler_descriptor);
63
64 static std::shared_ptr<ImageFilter> MakeCompose(const ImageFilter& inner,
65 const ImageFilter& outer);
66
67 static std::shared_ptr<ImageFilter> MakeFromColorFilter(
68 const ColorFilter& color_filter);
69
70 static std::shared_ptr<ImageFilter> MakeLocalMatrix(
71 const Matrix& matrix,
72 const ImageFilter& internal_filter);
73
74 /// @brief Generate a new FilterContents using this filter's configuration.
75 ///
76 /// This is the same as WrapInput, except no input is set. The input
77 /// for the filter chain can be set later using.
78 /// FilterContents::SetLeafInputs().
79 ///
80 /// @see `FilterContents::SetLeafInputs`
81 std::shared_ptr<FilterContents> GetFilterContents() const;
82
83 /// @brief Wraps the given filter input with a GPU-based image filter.
84 virtual std::shared_ptr<FilterContents> WrapInput(
85 const FilterInput::Ref& input) const = 0;
86
87 virtual std::shared_ptr<ImageFilter> Clone() const = 0;
88
89 virtual void Visit(ImageFilterVisitor& visitor) = 0;
90 };
91
92 /*******************************************************************************
93 ******* BlurImageFilter
94 ******************************************************************************/
95
96 class BlurImageFilter : public ImageFilter {
97 public:
98 BlurImageFilter(Sigma sigma_x,
99 Sigma sigma_y,
100 FilterContents::BlurStyle blur_style,
101 Entity::TileMode tile_mode);
102
103 ~BlurImageFilter() override;
104
105 // |ImageFilter|
106 std::shared_ptr<FilterContents> WrapInput(
107 const FilterInput::Ref& input) const override;
108
109 // |ImageFilter|
110 std::shared_ptr<ImageFilter> Clone() const override;
111
112 // |ImageFilter|
113 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
114
115 private:
116 Sigma sigma_x_;
117 Sigma sigma_y_;
118 FilterContents::BlurStyle blur_style_;
119 Entity::TileMode tile_mode_;
120 };
121
122 /*******************************************************************************
123 ******* DilateImageFilter
124 ******************************************************************************/
125
126 class DilateImageFilter : public ImageFilter {
127 public:
128 DilateImageFilter(Radius radius_x, Radius radius_y);
129
130 ~DilateImageFilter() override;
131
132 // |ImageFilter|
133 std::shared_ptr<FilterContents> WrapInput(
134 const FilterInput::Ref& input) const override;
135
136 // |ImageFilter|
137 std::shared_ptr<ImageFilter> Clone() const override;
138
139 // |ImageFilter|
140 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
141
142 private:
143 Radius radius_x_;
144 Radius radius_y_;
145 };
146
147 /*******************************************************************************
148 ******* ErodeImageFilter
149 ******************************************************************************/
150
151 class ErodeImageFilter : public ImageFilter {
152 public:
153 ErodeImageFilter(Radius radius_x, Radius radius_y);
154
155 ~ErodeImageFilter() override;
156
157 // |ImageFilter|
158 std::shared_ptr<FilterContents> WrapInput(
159 const FilterInput::Ref& input) const override;
160
161 // |ImageFilter|
162 std::shared_ptr<ImageFilter> Clone() const override;
163
164 // |ImageFilter|
165 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
166
167 private:
168 Radius radius_x_;
169 Radius radius_y_;
170 };
171
172 /*******************************************************************************
173 ******* MatrixImageFilter
174 ******************************************************************************/
175
176 class MatrixImageFilter : public ImageFilter {
177 public:
178 MatrixImageFilter(const Matrix& matrix, SamplerDescriptor sampler_descriptor);
179
180 ~MatrixImageFilter() override;
181
182 // |ImageFilter|
183 std::shared_ptr<FilterContents> WrapInput(
184 const FilterInput::Ref& input) const override;
185
186 // |ImageFilter|
187 std::shared_ptr<ImageFilter> Clone() const override;
188
189 // |ImageFilter|
190 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
191
192 const Matrix& GetMatrix() const { return matrix_; }
193
194 private:
195 Matrix matrix_;
196 SamplerDescriptor sampler_descriptor_;
197 };
198
199 /*******************************************************************************
200 ******* ComposeImageFilter
201 ******************************************************************************/
202
203 class ComposeImageFilter : public ImageFilter {
204 public:
205 ComposeImageFilter(const ImageFilter& inner, const ImageFilter& outer);
206
207 ~ComposeImageFilter() override;
208
209 // |ImageFilter|
210 std::shared_ptr<FilterContents> WrapInput(
211 const FilterInput::Ref& input) const override;
212
213 // |ImageFilter|
214 std::shared_ptr<ImageFilter> Clone() const override;
215
216 // |ImageFilter|
217 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
218
219 private:
220 std::shared_ptr<ImageFilter> inner_;
221 std::shared_ptr<ImageFilter> outer_;
222 };
223
224 /*******************************************************************************
225 ******* ColorImageFilter
226 ******************************************************************************/
227
228 class ColorImageFilter : public ImageFilter {
229 public:
230 explicit ColorImageFilter(const ColorFilter& color_filter);
231
232 ~ColorImageFilter() override;
233
234 // |ImageFilter|
235 std::shared_ptr<FilterContents> WrapInput(
236 const FilterInput::Ref& input) const override;
237
238 // |ImageFilter|
239 std::shared_ptr<ImageFilter> Clone() const override;
240
241 // |ImageFilter|
242 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
243
244 private:
245 std::shared_ptr<ColorFilter> color_filter_;
246 };
247
248 /*******************************************************************************
249 ******* LocalMatrixImageFilter
250 ******************************************************************************/
251
252 class LocalMatrixImageFilter : public ImageFilter {
253 public:
254 LocalMatrixImageFilter(const Matrix& matrix,
255 const ImageFilter& internal_filter);
256
257 ~LocalMatrixImageFilter() override;
258
259 // |ImageFilter|
260 std::shared_ptr<FilterContents> WrapInput(
261 const FilterInput::Ref& input) const override;
262
263 // |ImageFilter|
264 std::shared_ptr<ImageFilter> Clone() const override;
265
266 // |ImageFilter|
267 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
268
269 private:
270 Matrix matrix_;
271 std::shared_ptr<ImageFilter> internal_filter_;
272 };
273
274 } // namespace impeller
275
276 #endif // FLUTTER_IMPELLER_AIKS_IMAGE_FILTER_H_
impeller::ImageFilter::Clone
virtual std::shared_ptr< ImageFilter > Clone() const =0
impeller::ColorFilter
Definition: color_filter.h:19
impeller::DilateImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:101
impeller::MatrixImageFilter::MatrixImageFilter
MatrixImageFilter(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
Definition: image_filter.cc:134
impeller::DilateImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:142
impeller::ImageFilter::MakeDilate
static std::shared_ptr< ImageFilter > MakeDilate(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:29
impeller::ImageFilter::WrapInput
virtual std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const =0
Wraps the given filter input with a GPU-based image filter.
impeller::ErodeImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:126
impeller::BlurImageFilter::~BlurImageFilter
~BlurImageFilter() override
impeller::BlurImageFilter
Definition: image_filter.h:96
impeller::DilateImageFilter::DilateImageFilter
DilateImageFilter(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:96
entity.h
impeller::ColorImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:244
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:23
impeller::ComposeImageFilter::~ComposeImageFilter
~ComposeImageFilter() override
impeller::ColorImageFilter::ColorImageFilter
ColorImageFilter(const ColorFilter &color_filter)
Definition: image_filter.cc:172
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
impeller::ComposeImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:219
impeller::ImageFilter::ImageFilter
ImageFilter()
impeller::ImageFilter::MakeBlur
static std::shared_ptr< ImageFilter > MakeBlur(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Definition: image_filter.cc:20
impeller::MatrixImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:140
impeller::LocalMatrixImageFilter::~LocalMatrixImageFilter
~LocalMatrixImageFilter() override
impeller::ImageFilter::MakeFromColorFilter
static std::shared_ptr< ImageFilter > MakeFromColorFilter(const ColorFilter &color_filter)
Definition: image_filter.cc:52
impeller::MatrixImageFilter::~MatrixImageFilter
~MatrixImageFilter() override
impeller::ImageFilter::GetFilterContents
std::shared_ptr< FilterContents > GetFilterContents() const
Generate a new FilterContents using this filter's configuration.
Definition: image_filter.cc:63
impeller::MatrixImageFilter
Definition: image_filter.h:176
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
matrix.h
impeller::ImageFilter::~ImageFilter
virtual ~ImageFilter()
filter_contents.h
impeller::ComposeImageFilter::ComposeImageFilter
ComposeImageFilter(const ImageFilter &inner, const ImageFilter &outer)
Definition: image_filter.cc:153
sigma.h
impeller::Radius
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition: sigma.h:48
impeller::MatrixImageFilter::GetMatrix
const Matrix & GetMatrix() const
Definition: image_filter.h:194
impeller::ImageFilter::MakeLocalMatrix
static std::shared_ptr< ImageFilter > MakeLocalMatrix(const Matrix &matrix, const ImageFilter &internal_filter)
Definition: image_filter.cc:57
impeller::ImageFilter::Visit
virtual void Visit(ImageFilterVisitor &visitor)=0
impeller::Sigma
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32
impeller::LocalMatrixImageFilter::LocalMatrixImageFilter
LocalMatrixImageFilter(const Matrix &matrix, const ImageFilter &internal_filter)
Definition: image_filter.cc:191
impeller::ImageFilter::MakeErode
static std::shared_ptr< ImageFilter > MakeErode(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:34
impeller::LocalMatrixImageFilter
Definition: image_filter.h:252
impeller::ErodeImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:167
impeller::ColorImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:177
impeller::ImageFilter
Definition: image_filter.h:42
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::ImageFilter::MakeMatrix
static std::shared_ptr< ImageFilter > MakeMatrix(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
Definition: image_filter.cc:39
impeller::ErodeImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:120
impeller::ComposeImageFilter
Definition: image_filter.h:203
sampler_descriptor.h
impeller::ImageFilter::MakeCompose
static std::shared_ptr< ImageFilter > MakeCompose(const ImageFilter &inner, const ImageFilter &outer)
Definition: image_filter.cc:46
impeller::ImageFilterVisitor::Visit
virtual void Visit(const BlurImageFilter &filter)=0
impeller::ColorImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:183
impeller::LocalMatrixImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:269
impeller::BlurImageFilter::BlurImageFilter
BlurImageFilter(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Definition: image_filter.cc:71
impeller::ErodeImageFilter
Definition: image_filter.h:151
impeller::ColorImageFilter::~ColorImageFilter
~ColorImageFilter() override
impeller::ComposeImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:159
impeller::ComposeImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:164
impeller::BlurImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:88
impeller::MatrixImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:145
color_filter.h
impeller::BlurImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:115
impeller::LocalMatrixImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:198
impeller::ColorImageFilter
Definition: image_filter.h:228
impeller::ErodeImageFilter::ErodeImageFilter
ErodeImageFilter(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:115
impeller::ImageFilterVisitor
Definition: image_filter.h:27
impeller::ErodeImageFilter::~ErodeImageFilter
~ErodeImageFilter() override
impeller::MatrixImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:192
impeller::BlurImageFilter::WrapInput
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:82
impeller
Definition: aiks_context.cc:10
impeller::LocalMatrixImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:204
impeller::DilateImageFilter::~DilateImageFilter
~DilateImageFilter() override
impeller::DilateImageFilter
Definition: image_filter.h:126
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::DilateImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:107