27 tile_mode_ = tile_mode;
31 colors_ = std::move(colors);
35 stops_ = std::move(stops);
49 focus_radius_ = radius;
52 #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
53 #define UNIFORM_FRAG_INFO(t) \
54 t##GradientUniformFillPipeline::FragmentShader::FragInfo
55 #define UNIFORM_COLOR_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Conical)::colors)
56 #define UNIFORM_STOP_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Conical)::stop_pairs)
64 return RenderSSBO(renderer, entity, pass);
68 return RenderUniform(renderer, entity, pass);
70 return RenderTexture(renderer, entity, pass);
73 bool ConicalGradientContents::RenderSSBO(
const ContentContext& renderer,
79 VS::FrameInfo frame_info;
86 return ColorSourceContents::DrawGeometry<VS>(
87 renderer, entity, pass, pipeline_callback, frame_info,
88 [
this, &renderer, &entity](RenderPass& pass) {
89 FS::FragInfo frag_info;
90 frag_info.center = center_;
91 frag_info.radius = radius_;
92 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
93 frag_info.decal_border_color = decal_border_color_;
98 frag_info.focus = focus_.value();
99 frag_info.focus_radius = focus_radius_;
101 frag_info.focus = center_;
102 frag_info.focus_radius = 0.0;
108 frag_info.colors_length = colors.size();
110 host_buffer.Emplace(colors.data(), colors.size() *
sizeof(StopData),
115 FS::BindColorData(pass, color_buffer);
117 pass.SetCommandLabel(
"ConicalGradientSSBOFill");
122 bool ConicalGradientContents::RenderUniform(
const ContentContext& renderer,
123 const Entity& entity,
124 RenderPass& pass)
const {
128 VS::FrameInfo frame_info;
132 [&renderer](ContentContextOptions options) {
133 return renderer.GetConicalGradientUniformFillPipeline(options);
135 return ColorSourceContents::DrawGeometry<VS>(
136 renderer, entity, pass, pipeline_callback, frame_info,
137 [
this, &renderer, &entity](RenderPass& pass) {
138 FS::FragInfo frag_info;
139 frag_info.center = center_;
141 frag_info.focus = focus_.value();
142 frag_info.focus_radius = focus_radius_;
144 frag_info.focus = center_;
145 frag_info.focus_radius = 0.0;
147 frag_info.radius = radius_;
148 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
153 colors_, stops_, frag_info.colors, frag_info.stop_pairs);
154 frag_info.decal_border_color = decal_border_color_;
156 pass.SetCommandLabel(
"ConicalGradientUniformFill");
159 pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
165 bool ConicalGradientContents::RenderTexture(
const ContentContext& renderer,
166 const Entity& entity,
167 RenderPass& pass)
const {
172 auto gradient_texture =
174 if (gradient_texture ==
nullptr) {
178 VS::FrameInfo frame_info;
182 [&renderer](ContentContextOptions options) {
183 return renderer.GetConicalGradientFillPipeline(options);
185 return ColorSourceContents::DrawGeometry<VS>(
186 renderer, entity, pass, pipeline_callback, frame_info,
187 [
this, &renderer, &gradient_texture, &entity](RenderPass& pass) {
188 FS::FragInfo frag_info;
189 frag_info.center = center_;
190 frag_info.radius = radius_;
191 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
192 frag_info.decal_border_color = decal_border_color_;
193 frag_info.texture_sampler_y_coord_scale =
194 gradient_texture->GetYCoordScale();
198 frag_info.half_texel =
199 Vector2(0.5 / gradient_texture->GetSize().width,
200 0.5 / gradient_texture->GetSize().height);
202 frag_info.focus = focus_.value();
203 frag_info.focus_radius = focus_radius_;
205 frag_info.focus = center_;
206 frag_info.focus_radius = 0.0;
209 pass.SetCommandLabel(
"ConicalGradientFill");
212 pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
213 SamplerDescriptor sampler_desc;
216 FS::BindTextureSampler(
217 pass, gradient_texture,
218 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
227 for (
Color& color : colors_) {
228 color = color_filter_proc(color);
230 decal_border_color_ = color_filter_proc(decal_border_color_);
virtual bool SupportsSSBO() const =0
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
const Geometry * GetGeometry() const
Get the geometry that this contents will use to render.
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
void SetFocus(std::optional< Point > focus, Scalar radius)
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
void SetStops(std::vector< Scalar > stops)
void SetCenterAndRadius(Point center, Scalar radius)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
const std::vector< Scalar > & GetStops() const
ConicalGradientContents()
void SetTileMode(Entity::TileMode tile_mode)
const std::vector< Color > & GetColors() const
~ConicalGradientContents() override
void SetColors(std::vector< Color > colors)
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
const Capabilities & GetDeviceCapabilities() const
PipelineRef GetConicalGradientSSBOFillPipeline(ContentContextOptions opts) const
std::function< Color(Color)> ColorFilterProc
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
Render passes encode render commands directed as one specific render target into an underlying comman...
VertexShader_ VertexShader
FragmentShader_ FragmentShader
#define UNIFORM_STOP_SIZE
#define UNIFORM_COLOR_SIZE
GlyphAtlasPipeline::VertexShader VS
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.
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.
GlyphAtlasPipeline::FragmentShader FS
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...
constexpr size_t DefaultUniformAlignment()
static constexpr uint32_t kMaxUniformGradientStops