Flutter Engine
The Flutter Engine
image_filter.cc
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
9
10namespace impeller {
11
12/*******************************************************************************
13 ******* ImageFilter
14 ******************************************************************************/
15
16ImageFilter::ImageFilter() = default;
17
19
20std::shared_ptr<ImageFilter> ImageFilter::MakeBlur(
21 Sigma sigma_x,
22 Sigma sigma_y,
24 Entity::TileMode tile_mode) {
25 return std::make_shared<BlurImageFilter>(sigma_x, sigma_y, blur_style,
26 tile_mode);
27}
28
29std::shared_ptr<ImageFilter> ImageFilter::MakeDilate(Radius radius_x,
30 Radius radius_y) {
31 return std::make_shared<DilateImageFilter>(radius_x, radius_y);
32}
33
34std::shared_ptr<ImageFilter> ImageFilter::MakeErode(Radius radius_x,
35 Radius radius_y) {
36 return std::make_shared<ErodeImageFilter>(radius_x, radius_y);
37}
38
39std::shared_ptr<ImageFilter> ImageFilter::MakeMatrix(
40 const Matrix& matrix,
41 SamplerDescriptor sampler_descriptor) {
42 return std::make_shared<MatrixImageFilter>(matrix,
43 std::move(sampler_descriptor));
44}
45
46std::shared_ptr<ImageFilter> ImageFilter::MakeCompose(
47 const ImageFilter& inner,
48 const ImageFilter& outer) {
49 return std::make_shared<ComposeImageFilter>(inner, outer);
50}
51
52std::shared_ptr<ImageFilter> ImageFilter::MakeFromColorFilter(
54 return std::make_shared<ColorImageFilter>(color_filter);
55}
56
57std::shared_ptr<ImageFilter> ImageFilter::MakeLocalMatrix(
58 const Matrix& matrix,
59 const ImageFilter& internal_filter) {
60 return std::make_shared<LocalMatrixImageFilter>(matrix, internal_filter);
61}
62
63std::shared_ptr<FilterContents> ImageFilter::GetFilterContents() const {
65}
66
67/*******************************************************************************
68 ******* BlurImageFilter
69 ******************************************************************************/
70
72 Sigma sigma_y,
74 Entity::TileMode tile_mode)
75 : sigma_x_(sigma_x),
76 sigma_y_(sigma_y),
77 blur_style_(blur_style),
78 tile_mode_(tile_mode) {}
79
81
82std::shared_ptr<FilterContents> BlurImageFilter::WrapInput(
83 const FilterInput::Ref& input) const {
84 return FilterContents::MakeGaussianBlur(input, sigma_x_, sigma_y_, tile_mode_,
85 blur_style_);
86}
87
88std::shared_ptr<ImageFilter> BlurImageFilter::Clone() const {
89 return std::make_shared<BlurImageFilter>(*this);
90}
91
92/*******************************************************************************
93 ******* DilateImageFilter
94 ******************************************************************************/
95
97 : radius_x_(radius_x), radius_y_(radius_y) {}
98
100
101std::shared_ptr<FilterContents> DilateImageFilter::WrapInput(
102 const FilterInput::Ref& input) const {
103 return FilterContents::MakeMorphology(input, radius_x_, radius_y_,
105}
106
107std::shared_ptr<ImageFilter> DilateImageFilter::Clone() const {
108 return std::make_shared<DilateImageFilter>(*this);
109}
110
111/*******************************************************************************
112 ******* ErodeImageFilter
113 ******************************************************************************/
114
116 : radius_x_(radius_x), radius_y_(radius_y) {}
117
119
120std::shared_ptr<FilterContents> ErodeImageFilter::WrapInput(
121 const FilterInput::Ref& input) const {
122 return FilterContents::MakeMorphology(input, radius_x_, radius_y_,
124}
125
126std::shared_ptr<ImageFilter> ErodeImageFilter::Clone() const {
127 return std::make_shared<ErodeImageFilter>(*this);
128}
129
130/*******************************************************************************
131 ******* MatrixImageFilter
132 ******************************************************************************/
133
135 SamplerDescriptor sampler_descriptor)
136 : matrix_(matrix), sampler_descriptor_(std::move(sampler_descriptor)) {}
137
139
140std::shared_ptr<FilterContents> MatrixImageFilter::WrapInput(
141 const FilterInput::Ref& input) const {
142 return FilterContents::MakeMatrixFilter(input, matrix_, sampler_descriptor_);
143}
144
145std::shared_ptr<ImageFilter> MatrixImageFilter::Clone() const {
146 return std::make_shared<MatrixImageFilter>(*this);
147}
148
149/*******************************************************************************
150 ******* ComposeImageFilter
151 ******************************************************************************/
152
154 const ImageFilter& outer)
155 : inner_(inner.Clone()), outer_(outer.Clone()) {}
156
158
159std::shared_ptr<FilterContents> ComposeImageFilter::WrapInput(
160 const FilterInput::Ref& input) const {
161 return outer_->WrapInput(FilterInput::Make(inner_->WrapInput(input)));
162}
163
164std::shared_ptr<ImageFilter> ComposeImageFilter::Clone() const {
165 return std::make_shared<ComposeImageFilter>(*this);
166}
167
168/*******************************************************************************
169 ******* ColorImageFilter
170 ******************************************************************************/
171
173 : color_filter_(color_filter.Clone()) {}
174
176
177std::shared_ptr<FilterContents> ColorImageFilter::WrapInput(
178 const FilterInput::Ref& input) const {
179 return color_filter_->WrapWithGPUColorFilter(
181}
182
183std::shared_ptr<ImageFilter> ColorImageFilter::Clone() const {
184 return std::make_shared<ColorImageFilter>(*this);
185}
186
187/*******************************************************************************
188 ******* LocalMatrixImageFilter
189 ******************************************************************************/
190
192 const Matrix& matrix,
193 const ImageFilter& internal_filter)
194 : matrix_(matrix), internal_filter_(internal_filter.Clone()) {}
195
197
198std::shared_ptr<FilterContents> LocalMatrixImageFilter::WrapInput(
199 const FilterInput::Ref& input) const {
201 FilterInput::Make(internal_filter_->WrapInput(input)), matrix_);
202}
203
204std::shared_ptr<ImageFilter> LocalMatrixImageFilter::Clone() const {
205 return std::make_shared<LocalMatrixImageFilter>(*this);
206}
207
208} // namespace impeller
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:88
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
BlurImageFilter(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Definition: image_filter.cc:71
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
std::shared_ptr< ImageFilter > Clone() const override
ColorImageFilter(const ColorFilter &color_filter)
ComposeImageFilter(const ImageFilter &inner, const ImageFilter &outer)
std::shared_ptr< ImageFilter > Clone() const override
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
std::shared_ptr< ImageFilter > Clone() const override
DilateImageFilter(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:96
std::shared_ptr< ImageFilter > Clone() const override
ErodeImageFilter(Radius radius_x, Radius radius_y)
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, BlurStyle mask_blur_style=BlurStyle::kNormal, const std::shared_ptr< Geometry > &mask_geometry=nullptr)
static std::shared_ptr< FilterContents > MakeMorphology(FilterInput::Ref input, Radius radius_x, Radius radius_y, MorphType morph_type)
static std::shared_ptr< FilterContents > MakeLocalMatrixFilter(FilterInput::Ref input, const Matrix &matrix)
static std::shared_ptr< FilterContents > MakeMatrixFilter(FilterInput::Ref input, const Matrix &matrix, const SamplerDescriptor &desc)
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
static std::shared_ptr< ImageFilter > MakeMatrix(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
Definition: image_filter.cc:39
static std::shared_ptr< ImageFilter > MakeLocalMatrix(const Matrix &matrix, const ImageFilter &internal_filter)
Definition: image_filter.cc:57
static std::shared_ptr< ImageFilter > MakeErode(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:34
virtual std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const =0
Wraps the given filter input with a GPU-based image filter.
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
static std::shared_ptr< ImageFilter > MakeDilate(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:29
static std::shared_ptr< ImageFilter > MakeFromColorFilter(const ColorFilter &color_filter)
Definition: image_filter.cc:52
std::shared_ptr< FilterContents > GetFilterContents() const
Generate a new FilterContents using this filter's configuration.
Definition: image_filter.cc:63
static std::shared_ptr< ImageFilter > MakeCompose(const ImageFilter &inner, const ImageFilter &outer)
Definition: image_filter.cc:46
LocalMatrixImageFilter(const Matrix &matrix, const ImageFilter &internal_filter)
std::shared_ptr< ImageFilter > Clone() const override
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
std::shared_ptr< ImageFilter > Clone() const override
MatrixImageFilter(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
TRect< Scalar > Rect
Definition: rect.h:769
Definition: ref_ptr.h:256
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition: sigma.h:48
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32