Flutter Engine
 
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 74 of file conical_gradient_contents.cc.

◆ UNIFORM_COLOR_SIZE

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

Definition at line 77 of file conical_gradient_contents.cc.

◆ UNIFORM_FRAG_INFO

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

Definition at line 75 of file conical_gradient_contents.cc.

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