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