Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
conical_gradient_contents.cc File Reference

Go to the source code of this file.

Namespaces

namespace  impeller
 

Macros

#define ARRAY_LEN(a)   (sizeof(a) / sizeof(a[0]))
 
#define UNIFORM_FRAG_INFO(t)    t##GradientUniformFillConicalPipeline::FragmentShader::FragInfo
 
#define UNIFORM_COLOR_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Conical)::colors)
 
#define UNIFORM_STOP_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Conical)::stop_pairs)
 

Macro Definition Documentation

◆ ARRAY_LEN

#define ARRAY_LEN (   a)    (sizeof(a) / sizeof(a[0]))

Definition at line 79 of file conical_gradient_contents.cc.

◆ UNIFORM_COLOR_SIZE

#define UNIFORM_COLOR_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Conical)::colors)

Definition at line 82 of file conical_gradient_contents.cc.

◆ UNIFORM_FRAG_INFO

#define UNIFORM_FRAG_INFO (   t)     t##GradientUniformFillConicalPipeline::FragmentShader::FragInfo

Definition at line 80 of file conical_gradient_contents.cc.

89 {
90 if (renderer.GetDeviceCapabilities().SupportsSSBO()) {
91 return RenderSSBO(renderer, entity, pass);
92 }
93 if (colors_.size() <= kMaxUniformGradientStops &&
94 stops_.size() <= kMaxUniformGradientStops) {
95 return RenderUniform(renderer, entity, pass);
96 }
97 return RenderTexture(renderer, entity, pass);
98}
99
100bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer,
101 const Entity& entity,
102 RenderPass& pass) const {
103 using VS = ConicalGradientSSBOFillPipeline::VertexShader;
104 using FS = ConicalGradientSSBOFillPipeline::FragmentShader;
105
106 VS::FrameInfo frame_info;
107 frame_info.matrix = GetInverseEffectTransform();
108
109 ConicalKind kind = GetConicalKind(center_, radius_, focus_, focus_radius_);
110 PipelineBuilderCallback pipeline_callback =
111 [&renderer, kind](ContentContextOptions options) {
112 return renderer.GetConicalGradientSSBOFillPipeline(options, kind);
113 };
114 return ColorSourceContents::DrawGeometry<VS>(
115 renderer, entity, pass, pipeline_callback, frame_info,
116 [this, &renderer, &entity](RenderPass& pass) {
117 FS::FragInfo frag_info;
118 frag_info.center = center_;
119 frag_info.radius = radius_;
120 frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
121 frag_info.decal_border_color = decal_border_color_;
122 frag_info.alpha =
123 GetOpacityFactor() *
124 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
125 if (focus_) {
126 frag_info.focus = focus_.value();
127 frag_info.focus_radius = focus_radius_;
128 } else {
129 frag_info.focus = center_;
130 frag_info.focus_radius = 0.0;
131 }
132
133 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
134 auto colors = CreateGradientColors(colors_, stops_);
135
136 frag_info.colors_length = colors.size();
137 auto color_buffer = data_host_buffer.Emplace(
138 colors.data(), colors.size() * sizeof(StopData),
139 renderer.GetDeviceCapabilities()
140 .GetMinimumStorageBufferAlignment());
141
142 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
143 FS::BindColorData(pass, color_buffer);
144
145 pass.SetCommandLabel("ConicalGradientSSBOFill");
146 return true;
147 });
148}
149
150bool ConicalGradientContents::RenderUniform(const ContentContext& renderer,
151 const Entity& entity,
152 RenderPass& pass) const {
153 using VS = ConicalGradientUniformFillConicalPipeline::VertexShader;
154 using FS = ConicalGradientUniformFillConicalPipeline::FragmentShader;
155
156 VS::FrameInfo frame_info;
157 frame_info.matrix = GetInverseEffectTransform();
158
159 ConicalKind kind = GetConicalKind(center_, radius_, focus_, focus_radius_);
160 PipelineBuilderCallback pipeline_callback =
161 [&renderer, kind](ContentContextOptions options) {
162 return renderer.GetConicalGradientUniformFillPipeline(options, kind);
163 };
164 return ColorSourceContents::DrawGeometry<VS>(
165 renderer, entity, pass, pipeline_callback, frame_info,
166 [this, &renderer, &entity](RenderPass& pass) {
167 FS::FragInfo frag_info;
168 frag_info.center = center_;
169 if (focus_) {
170 frag_info.focus = focus_.value();
171 frag_info.focus_radius = focus_radius_;
172 } else {
173 frag_info.focus = center_;
174 frag_info.focus_radius = 0.0;
175 }
176 frag_info.radius = radius_;
177 frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
178 frag_info.alpha =
179 GetOpacityFactor() *
180 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
181 frag_info.colors_length = PopulateUniformGradientColors(
182 colors_, stops_, frag_info.colors, frag_info.stop_pairs);
183 frag_info.decal_border_color = decal_border_color_;
184
185 pass.SetCommandLabel("ConicalGradientUniformFill");
186
187 FS::BindFragInfo(
188 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
189
190 return true;
191 });
192}
193
194bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
195 const Entity& entity,
196 RenderPass& pass) const {
197 using VS = ConicalGradientFillConicalPipeline::VertexShader;
198 using FS = ConicalGradientFillConicalPipeline::FragmentShader;
199
200 auto gradient_data = CreateGradientBuffer(colors_, stops_);
201 auto gradient_texture =
202 CreateGradientTexture(gradient_data, renderer.GetContext());
203 if (gradient_texture == nullptr) {
204 return false;
205 }
206
207 VS::FrameInfo frame_info;
208 frame_info.matrix = GetInverseEffectTransform();
209
210 ConicalKind kind = GetConicalKind(center_, radius_, focus_, focus_radius_);
211 PipelineBuilderCallback pipeline_callback =
212 [&renderer, kind](ContentContextOptions options) {
213 return renderer.GetConicalGradientFillPipeline(options, kind);
214 };
215 return ColorSourceContents::DrawGeometry<VS>(
216 renderer, entity, pass, pipeline_callback, frame_info,
217 [this, &renderer, &gradient_texture, &entity](RenderPass& pass) {
218 FS::FragInfo frag_info;
219 frag_info.center = center_;
220 frag_info.radius = radius_;
221 frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
222 frag_info.decal_border_color = decal_border_color_;
223 frag_info.texture_sampler_y_coord_scale =
224 gradient_texture->GetYCoordScale();
225 frag_info.alpha =
226 GetOpacityFactor() *
227 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
228 frag_info.half_texel =
229 Vector2(0.5 / gradient_texture->GetSize().width,
230 0.5 / gradient_texture->GetSize().height);
231 if (focus_) {
232 frag_info.focus = focus_.value();
233 frag_info.focus_radius = focus_radius_;
234 } else {
235 frag_info.focus = center_;
236 frag_info.focus_radius = 0.0;
237 }
238
239 pass.SetCommandLabel("ConicalGradientFill");
240
241 FS::BindFragInfo(
242 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
243 SamplerDescriptor sampler_desc;
244 sampler_desc.min_filter = MinMagFilter::kLinear;
245 sampler_desc.mag_filter = MinMagFilter::kLinear;
246 FS::BindTextureSampler(
247 pass, gradient_texture,
248 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
249 sampler_desc));
250
251 return true;
252 });
253}
254
255bool ConicalGradientContents::ApplyColorFilter(
256 const ColorFilterProc& color_filter_proc) {
257 for (Color& color : colors_) {
258 color = color_filter_proc(color);
259 }
260 decal_border_color_ = color_filter_proc(decal_border_color_);
261 return true;
262}
263
264} // namespace impeller
Point Vector2
Definition point.h:430
float Scalar
Definition scalar.h:19
LinePipeline::FragmentShader FS
int PopulateUniformGradientColors(const std::vector< Color > &colors, const std::vector< Scalar > &stops, Vector4 frag_info_colors[kMaxUniformGradientStops], Vector4 frag_info_stop_pairs[kMaxUniformGradientStops/2])
Populate 2 arrays with the colors and stop data for a gradient.
std::vector< StopData > CreateGradientColors(const std::vector< Color > &colors, const std::vector< Scalar > &stops)
Populate a vector with the color and stop data for a gradient.
LinePipeline::VertexShader VS
std::shared_ptr< Texture > CreateGradientTexture(const GradientData &gradient_data, const std::shared_ptr< impeller::Context > &context)
Create a host visible texture that contains the gradient defined by the provided gradient data.
GradientData CreateGradientBuffer(const std::vector< Color > &colors, const std::vector< Scalar > &stops)
Populate a vector with the interpolated color bytes for the linear gradient described by colors and s...
Definition gradient.cc:20

◆ UNIFORM_STOP_SIZE

#define UNIFORM_STOP_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Conical)::stop_pairs)

Definition at line 83 of file conical_gradient_contents.cc.