Flutter Engine
 
Loading...
Searching...
No Matches
dl_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_DISPLAY_LIST_EFFECTS_DL_IMAGE_FILTER_H_
6#define FLUTTER_DISPLAY_LIST_EFFECTS_DL_IMAGE_FILTER_H_
7
15
16namespace flutter {
17
18// The DisplayList ImageFilter class. This class implements all of the
19// facilities and adheres to the design goals of the |DlAttribute| base
20// class.
21//
22// The objects here define operations that can take a location and one or
23// more input pixels and produce a color for that output pixel
24
25// An enumerated type for the supported ImageFilter operations.
36
37class DlBlurImageFilter;
38class DlDilateImageFilter;
39class DlErodeImageFilter;
40class DlMatrixImageFilter;
41class DlRuntimeEffectImageFilter;
42class DlColorFilterImageFilter;
43class DlComposeImageFilter;
44class DlLocalMatrixImageFilter;
45
46class DlImageFilter : public DlAttribute<DlImageFilter, DlImageFilterType> {
47 public:
48 enum class MatrixCapability {
52 };
53
54 static std::shared_ptr<DlImageFilter> MakeBlur(DlScalar sigma_x,
55 DlScalar sigma_y,
56 DlTileMode tile_mode);
57
58 static std::shared_ptr<DlImageFilter> MakeDilate(DlScalar radius_x,
59 DlScalar radius_y);
60
61 static std::shared_ptr<DlImageFilter> MakeErode(DlScalar radius_x,
62 DlScalar radius_y);
63
64 static std::shared_ptr<DlImageFilter> MakeMatrix(const DlMatrix& matrix,
65 DlImageSampling sampling);
66
67 static std::shared_ptr<DlImageFilter> MakeRuntimeEffect(
68 sk_sp<DlRuntimeEffect> runtime_effect,
69 std::vector<std::shared_ptr<DlColorSource>> samplers,
70 std::shared_ptr<std::vector<uint8_t>> uniform_data);
71
72 static std::shared_ptr<DlImageFilter> MakeColorFilter(
73 const std::shared_ptr<const DlColorFilter>& filter);
74
75 static std::shared_ptr<DlImageFilter> MakeCompose(
76 const std::shared_ptr<DlImageFilter>& outer,
77 const std::shared_ptr<DlImageFilter>& inner);
78
79 // Return a DlBlurImageFilter pointer to this object iff it is a Blur
80 // type of ImageFilter, otherwise return nullptr.
81 virtual const DlBlurImageFilter* asBlur() const { return nullptr; }
82
83 // Return a DlDilateImageFilter pointer to this object iff it is a Dilate
84 // type of ImageFilter, otherwise return nullptr.
85 virtual const DlDilateImageFilter* asDilate() const { return nullptr; }
86
87 // Return a DlErodeImageFilter pointer to this object iff it is an Erode
88 // type of ImageFilter, otherwise return nullptr.
89 virtual const DlErodeImageFilter* asErode() const { return nullptr; }
90
91 // Return a DlMatrixImageFilter pointer to this object iff it is a Matrix
92 // type of ImageFilter, otherwise return nullptr.
93 virtual const DlMatrixImageFilter* asMatrix() const { return nullptr; }
94
95 virtual const DlLocalMatrixImageFilter* asLocalMatrix() const {
96 return nullptr;
97 }
98
99 virtual std::shared_ptr<DlImageFilter> makeWithLocalMatrix(
100 const DlMatrix& matrix) const;
101
102 // Return a DlComposeImageFilter pointer to this object iff it is a Compose
103 // type of ImageFilter, otherwise return nullptr.
104 virtual const DlComposeImageFilter* asCompose() const { return nullptr; }
105
106 // Return a DlColorFilterImageFilter pointer to this object iff it is a
107 // ColorFilter type of ImageFilter, otherwise return nullptr.
109 return nullptr;
110 }
111
112 // Return a DlRuntimeEffectImageFilter pointer to this object iff it is a
113 // DlRuntimeEffectImageFilter type of ImageFilter, otherwise return nullptr.
115 return nullptr;
116 }
117
118 // Return a boolean indicating whether the image filtering operation will
119 // modify transparent black. This is typically used to determine if applying
120 // the ImageFilter to a temporary saveLayer buffer will turn the surrounding
121 // pixels non-transparent and therefore expand the bounds.
122 virtual bool modifies_transparent_black() const = 0;
123
124 // Return the bounds of the output for this image filtering operation
125 // based on the supplied input bounds where both are measured in the local
126 // (untransformed) coordinate space.
127 //
128 // The method will return a pointer to the output_bounds parameter if it
129 // can successfully compute the output bounds of the filter, otherwise the
130 // method will return a nullptr and the output_bounds will be filled with
131 // a best guess for the answer, even if just a copy of the input_bounds.
132 virtual DlRect* map_local_bounds(const DlRect& input_bounds,
133 DlRect& output_bounds) const = 0;
134
135 // Return the device bounds of the output for this image filtering operation
136 // based on the supplied input device bounds where both are measured in the
137 // pixel coordinate space and relative to the given rendering ctm. The
138 // transform matrix is used to adjust the filter parameters for when it
139 // is used in a rendering operation (for example, the blur radius of a
140 // Blur filter will expand based on the ctm).
141 //
142 // The method will return a pointer to the output_bounds parameter if it
143 // can successfully compute the output bounds of the filter, otherwise the
144 // method will return a nullptr and the output_bounds will be filled with
145 // a best guess for the answer, even if just a copy of the input_bounds.
146 virtual DlIRect* map_device_bounds(const DlIRect& input_bounds,
147 const DlMatrix& ctm,
148 DlIRect& output_bounds) const = 0;
149
150 // Return the input bounds that will be needed in order for the filter to
151 // properly fill the indicated output_bounds under the specified
152 // transformation matrix. Both output_bounds and input_bounds are taken to
153 // be relative to the transformed coordinate space of the provided |ctm|.
154 //
155 // The method will return a pointer to the input_bounds parameter if it
156 // can successfully compute the required input bounds, otherwise the
157 // method will return a nullptr and the input_bounds will be filled with
158 // a best guess for the answer, even if just a copy of the output_bounds.
159 virtual DlIRect* get_input_device_bounds(const DlIRect& output_bounds,
160 const DlMatrix& ctm,
161 DlIRect& input_bounds) const = 0;
162
166
167 protected:
168 static DlVector2 map_vectors_affine(const DlMatrix& ctm,
169 DlScalar x,
170 DlScalar y);
171
172 static DlIRect* inset_device_bounds(const DlIRect& input_bounds,
173 DlScalar radius_x,
174 DlScalar radius_y,
175 const DlMatrix& ctm,
176 DlIRect& output_bounds);
177
178 static DlIRect* outset_device_bounds(const DlIRect& input_bounds,
179 DlScalar radius_x,
180 DlScalar radius_y,
181 const DlMatrix& ctm,
182 DlIRect& output_bounds);
183};
184
185} // namespace flutter
186
187#endif // FLUTTER_DISPLAY_LIST_EFFECTS_DL_IMAGE_FILTER_H_
virtual const DlLocalMatrixImageFilter * asLocalMatrix() const
static std::shared_ptr< DlImageFilter > MakeDilate(DlScalar radius_x, DlScalar radius_y)
virtual std::shared_ptr< DlImageFilter > makeWithLocalMatrix(const DlMatrix &matrix) const
virtual DlIRect * map_device_bounds(const DlIRect &input_bounds, const DlMatrix &ctm, DlIRect &output_bounds) const =0
virtual const DlColorFilterImageFilter * asColorFilter() const
static std::shared_ptr< DlImageFilter > MakeBlur(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode)
static DlIRect * outset_device_bounds(const DlIRect &input_bounds, DlScalar radius_x, DlScalar radius_y, const DlMatrix &ctm, DlIRect &output_bounds)
static std::shared_ptr< DlImageFilter > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
static std::shared_ptr< DlImageFilter > MakeColorFilter(const std::shared_ptr< const DlColorFilter > &filter)
virtual DlRect * map_local_bounds(const DlRect &input_bounds, DlRect &output_bounds) const =0
static DlVector2 map_vectors_affine(const DlMatrix &ctm, DlScalar x, DlScalar y)
virtual const DlRuntimeEffectImageFilter * asRuntimeEffectFilter() const
virtual const DlMatrixImageFilter * asMatrix() const
virtual bool modifies_transparent_black() const =0
static DlIRect * inset_device_bounds(const DlIRect &input_bounds, DlScalar radius_x, DlScalar radius_y, const DlMatrix &ctm, DlIRect &output_bounds)
virtual const DlComposeImageFilter * asCompose() const
static std::shared_ptr< DlImageFilter > MakeMatrix(const DlMatrix &matrix, DlImageSampling sampling)
static std::shared_ptr< DlImageFilter > MakeCompose(const std::shared_ptr< DlImageFilter > &outer, const std::shared_ptr< DlImageFilter > &inner)
virtual MatrixCapability matrix_capability() const
virtual DlIRect * get_input_device_bounds(const DlIRect &output_bounds, const DlMatrix &ctm, DlIRect &input_bounds) const =0
virtual const DlBlurImageFilter * asBlur() const
static std::shared_ptr< DlImageFilter > MakeErode(DlScalar radius_x, DlScalar radius_y)
virtual const DlDilateImageFilter * asDilate() const
virtual const DlErodeImageFilter * asErode() const
int32_t x
double y
impeller::Scalar DlScalar
@ kBlur
Definition paint.cc:61
A 4x4 matrix using column-major storage.
Definition matrix.h:37