Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
radial_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(Radial)::colors)
 
#define UNIFORM_STOP_SIZE   ARRAY_LEN(UNIFORM_FRAG_INFO(Radial)::stop_pairs)
 

Macro Definition Documentation

◆ ARRAY_LEN

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

Definition at line 63 of file radial_gradient_contents.cc.

◆ UNIFORM_COLOR_SIZE

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

Definition at line 66 of file radial_gradient_contents.cc.

◆ UNIFORM_FRAG_INFO

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

Definition at line 64 of file radial_gradient_contents.cc.

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

Definition at line 67 of file radial_gradient_contents.cc.