Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
sweep_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##GradientUniformFillPipeline::FragmentShader::FragInfo
 
#define UNIFORM_COLOR_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Sweep)::colors)
 
#define UNIFORM_STOP_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Sweep)::stop_pairs)
 

Macro Definition Documentation

◆ ARRAY_LEN

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

Definition at line 69 of file sweep_gradient_contents.cc.

◆ UNIFORM_COLOR_SIZE

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

Definition at line 72 of file sweep_gradient_contents.cc.

◆ UNIFORM_FRAG_INFO

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

Definition at line 70 of file sweep_gradient_contents.cc.

79 {
80 if (renderer.GetDeviceCapabilities().SupportsSSBO()) {
81 return RenderSSBO(renderer, entity, pass);
82 }
83 if (colors_.size() <= kMaxUniformGradientStops &&
84 stops_.size() <= kMaxUniformGradientStops) {
85 return RenderUniform(renderer, entity, pass);
86 }
87 return RenderTexture(renderer, entity, pass);
88}
89
90bool SweepGradientContents::RenderSSBO(const ContentContext& renderer,
91 const Entity& entity,
92 RenderPass& pass) const {
93 using VS = SweepGradientSSBOFillPipeline::VertexShader;
94 using FS = SweepGradientSSBOFillPipeline::FragmentShader;
95
96 VS::FrameInfo frame_info;
97 frame_info.matrix = GetInverseEffectTransform();
98 VS::BindFrameInfo(
99 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frame_info));
100
101 PipelineBuilderCallback pipeline_callback =
102 [&renderer](ContentContextOptions options) {
103 return renderer.GetSweepGradientSSBOFillPipeline(options);
104 };
105 return ColorSourceContents::DrawGeometry<VS>(
106 renderer, entity, pass, pipeline_callback, frame_info,
107 [this, &renderer, &entity](RenderPass& pass) {
108 FS::FragInfo frag_info;
109 frag_info.center = center_;
110 frag_info.bias = bias_;
111 frag_info.scale = scale_;
112 frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
113 frag_info.decal_border_color = decal_border_color_;
114 frag_info.alpha =
115 GetOpacityFactor() *
116 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
117
118 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
119 auto colors = CreateGradientColors(colors_, stops_);
120
121 frag_info.colors_length = colors.size();
122 auto color_buffer = data_host_buffer.Emplace(
123 colors.data(), colors.size() * sizeof(StopData),
124 renderer.GetDeviceCapabilities()
125 .GetMinimumStorageBufferAlignment());
126
127 pass.SetCommandLabel("SweepGradientSSBOFill");
128
129 FS::BindFragInfo(
130 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
131 FS::BindColorData(pass, color_buffer);
132
133 return true;
134 });
135}
136
137bool SweepGradientContents::RenderUniform(const ContentContext& renderer,
138 const Entity& entity,
139 RenderPass& pass) const {
140 using VS = SweepGradientUniformFillPipeline::VertexShader;
141 using FS = SweepGradientUniformFillPipeline::FragmentShader;
142
143 VS::FrameInfo frame_info;
144 frame_info.matrix = GetInverseEffectTransform();
145 VS::BindFrameInfo(
146 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frame_info));
147
148 PipelineBuilderCallback pipeline_callback =
149 [&renderer](ContentContextOptions options) {
150 return renderer.GetSweepGradientUniformFillPipeline(options);
151 };
152 return ColorSourceContents::DrawGeometry<VS>(
153 renderer, entity, pass, pipeline_callback, frame_info,
154 [this, &renderer, &entity](RenderPass& pass) {
155 FS::FragInfo frag_info;
156 frag_info.center = center_;
157 frag_info.bias = bias_;
158 frag_info.scale = scale_;
159 frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
160 frag_info.alpha =
161 GetOpacityFactor() *
162 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
163 frag_info.colors_length = PopulateUniformGradientColors(
164 colors_, stops_, frag_info.colors, frag_info.stop_pairs);
165
166 frag_info.decal_border_color = decal_border_color_;
167
168 pass.SetCommandLabel("SweepGradientUniformFill");
169
170 FS::BindFragInfo(
171 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
172
173 return true;
174 });
175}
176
177bool SweepGradientContents::RenderTexture(const ContentContext& renderer,
178 const Entity& entity,
179 RenderPass& pass) const {
180 using VS = SweepGradientFillPipeline::VertexShader;
181 using FS = SweepGradientFillPipeline::FragmentShader;
182
183 auto gradient_data = CreateGradientBuffer(colors_, stops_);
184 auto gradient_texture =
185 CreateGradientTexture(gradient_data, renderer.GetContext());
186 if (gradient_texture == nullptr) {
187 return false;
188 }
189
190 VS::FrameInfo frame_info;
191 frame_info.matrix = GetInverseEffectTransform();
192
193 PipelineBuilderCallback pipeline_callback =
194 [&renderer](ContentContextOptions options) {
195 return renderer.GetSweepGradientFillPipeline(options);
196 };
197 return ColorSourceContents::DrawGeometry<VS>(
198 renderer, entity, pass, pipeline_callback, frame_info,
199 [this, &renderer, &gradient_texture, &entity](RenderPass& pass) {
200 FS::FragInfo frag_info;
201 frag_info.center = center_;
202 frag_info.bias = bias_;
203 frag_info.scale = scale_;
204 frag_info.texture_sampler_y_coord_scale =
205 gradient_texture->GetYCoordScale();
206 frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
207 frag_info.decal_border_color = decal_border_color_;
208 frag_info.alpha =
209 GetOpacityFactor() *
210 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
211 frag_info.half_texel =
212 Vector2(0.5 / gradient_texture->GetSize().width,
213 0.5 / gradient_texture->GetSize().height);
214
215 SamplerDescriptor sampler_desc;
216 sampler_desc.min_filter = MinMagFilter::kLinear;
217 sampler_desc.mag_filter = MinMagFilter::kLinear;
218
219 pass.SetCommandLabel("SweepGradientFill");
220
221 FS::BindFragInfo(
222 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
223 FS::BindTextureSampler(
224 pass, gradient_texture,
225 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
226 sampler_desc));
227
228 return true;
229 });
230}
231
232bool SweepGradientContents::ApplyColorFilter(
233 const ColorFilterProc& color_filter_proc) {
234 for (Color& color : colors_) {
235 color = color_filter_proc(color);
236 }
237 decal_border_color_ = color_filter_proc(decal_border_color_);
238 return true;
239}
240
241} // 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(Sweep)::stop_pairs)

Definition at line 73 of file sweep_gradient_contents.cc.