| 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 virtual int GetRequiredMipCount() const { return 1; }
92 };
93
94 /*******************************************************************************
95 ******* BlurImageFilter
96 ******************************************************************************/
97
98 class BlurImageFilter : public ImageFilter {
99 public:
100 BlurImageFilter(Sigma sigma_x,
101 Sigma sigma_y,
102 FilterContents::BlurStyle blur_style,
103 Entity::TileMode tile_mode);
104
105 ~BlurImageFilter() override;
106
107 // |ImageFilter|
108 std::shared_ptr<FilterContents> WrapInput(
109 const FilterInput::Ref& input) const override;
110
111 // |ImageFilter|
112 std::shared_ptr<ImageFilter> Clone() const override;
113
114 // |ImageFilter|
115 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
116
117 int GetRequiredMipCount() const override { return 4; }
118
119 private:
120 Sigma sigma_x_;
121 Sigma sigma_y_;
122 FilterContents::BlurStyle blur_style_;
123 Entity::TileMode tile_mode_;
124 };
125
126 /*******************************************************************************
127 ******* DilateImageFilter
128 ******************************************************************************/
129
130 class DilateImageFilter : public ImageFilter {
131 public:
132 DilateImageFilter(Radius radius_x, Radius radius_y);
133
134 ~DilateImageFilter() override;
135
136 // |ImageFilter|
137 std::shared_ptr<FilterContents> WrapInput(
138 const FilterInput::Ref& input) const override;
139
140 // |ImageFilter|
141 std::shared_ptr<ImageFilter> Clone() const override;
142
143 // |ImageFilter|
144 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
145
146 private:
147 Radius radius_x_;
148 Radius radius_y_;
149 };
150
151 /*******************************************************************************
152 ******* ErodeImageFilter
153 ******************************************************************************/
154
155 class ErodeImageFilter : public ImageFilter {
156 public:
157 ErodeImageFilter(Radius radius_x, Radius radius_y);
158
159 ~ErodeImageFilter() override;
160
161 // |ImageFilter|
162 std::shared_ptr<FilterContents> WrapInput(
163 const FilterInput::Ref& input) const override;
164
165 // |ImageFilter|
166 std::shared_ptr<ImageFilter> Clone() const override;
167
168 // |ImageFilter|
169 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
170
171 private:
172 Radius radius_x_;
173 Radius radius_y_;
174 };
175
176 /*******************************************************************************
177 ******* MatrixImageFilter
178 ******************************************************************************/
179
180 class MatrixImageFilter : public ImageFilter {
181 public:
182 MatrixImageFilter(const Matrix& matrix, SamplerDescriptor sampler_descriptor);
183
184 ~MatrixImageFilter() override;
185
186 // |ImageFilter|
187 std::shared_ptr<FilterContents> WrapInput(
188 const FilterInput::Ref& input) const override;
189
190 // |ImageFilter|
191 std::shared_ptr<ImageFilter> Clone() const override;
192
193 // |ImageFilter|
194 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
195
196 const Matrix& GetMatrix() const { return matrix_; }
197
198 private:
199 Matrix matrix_;
200 SamplerDescriptor sampler_descriptor_;
201 };
202
203 /*******************************************************************************
204 ******* ComposeImageFilter
205 ******************************************************************************/
206
207 class ComposeImageFilter : public ImageFilter {
208 public:
209 ComposeImageFilter(const ImageFilter& inner, const ImageFilter& outer);
210
211 ~ComposeImageFilter() override;
212
213 // |ImageFilter|
214 std::shared_ptr<FilterContents> WrapInput(
215 const FilterInput::Ref& input) const override;
216
217 // |ImageFilter|
218 std::shared_ptr<ImageFilter> Clone() const override;
219
220 // |ImageFilter|
221 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
222
223 private:
224 std::shared_ptr<ImageFilter> inner_;
225 std::shared_ptr<ImageFilter> outer_;
226 };
227
228 /*******************************************************************************
229 ******* ColorImageFilter
230 ******************************************************************************/
231
232 class ColorImageFilter : public ImageFilter {
233 public:
234 explicit ColorImageFilter(const ColorFilter& color_filter);
235
236 ~ColorImageFilter() override;
237
238 // |ImageFilter|
239 std::shared_ptr<FilterContents> WrapInput(
240 const FilterInput::Ref& input) const override;
241
242 // |ImageFilter|
243 std::shared_ptr<ImageFilter> Clone() const override;
244
245 // |ImageFilter|
246 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
247
248 private:
249 std::shared_ptr<ColorFilter> color_filter_;
250 };
251
252 /*******************************************************************************
253 ******* LocalMatrixImageFilter
254 ******************************************************************************/
255
256 class LocalMatrixImageFilter : public ImageFilter {
257 public:
258 LocalMatrixImageFilter(const Matrix& matrix,
259 const ImageFilter& internal_filter);
260
261 ~LocalMatrixImageFilter() override;
262
263 // |ImageFilter|
264 std::shared_ptr<FilterContents> WrapInput(
265 const FilterInput::Ref& input) const override;
266
267 // |ImageFilter|
268 std::shared_ptr<ImageFilter> Clone() const override;
269
270 // |ImageFilter|
271 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
272
273 private:
274 Matrix matrix_;
275 std::shared_ptr<ImageFilter> internal_filter_;
276 };
277
278 } // namespace impeller
279
280 #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:146
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:98
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:248
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:26
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:223
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::ImageFilter::GetRequiredMipCount
virtual int GetRequiredMipCount() const
Definition: image_filter.h:93
impeller::MatrixImageFilter
Definition: image_filter.h:180
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:198
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::BlurImageFilter::GetRequiredMipCount
int GetRequiredMipCount() const override
Definition: image_filter.h:119
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:256
impeller::ErodeImageFilter::Visit
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:171
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:42
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:207
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:273
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:155
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:117
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:232
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:196
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_blend_unittests.cc:18
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:130
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