27 tile_mode_ = tile_mode;
31 colors_ = std::move(colors);
35 stops_ = std::move(stops);
50 for (
auto color : colors_) {
51 if (!color.IsOpaque()) {
58 #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
59 #define UNIFORM_FRAG_INFO(t) \
60 t##GradientUniformFillPipeline::FragmentShader::FragInfo
61 #define UNIFORM_COLOR_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Radial)::colors)
62 #define UNIFORM_STOP_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Radial)::stop_pairs)
70 return RenderSSBO(renderer, entity, pass);
74 return RenderUniform(renderer, entity, pass);
76 return RenderTexture(renderer, entity, pass);
79 bool RadialGradientContents::RenderSSBO(
const ContentContext& renderer,
85 VS::FrameInfo frame_info;
92 return ColorSourceContents::DrawGeometry<VS>(
93 renderer, entity, pass, pipeline_callback, frame_info,
94 [
this, &renderer, &entity](RenderPass& pass) {
95 FS::FragInfo frag_info;
96 frag_info.center = center_;
97 frag_info.radius = radius_;
98 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
99 frag_info.decal_border_color = decal_border_color_;
107 frag_info.colors_length = colors.size();
109 host_buffer.Emplace(colors.data(), colors.size() *
sizeof(StopData),
110 host_buffer.GetMinimumUniformAlignment());
112 pass.SetCommandLabel(
"RadialGradientSSBOFill");
115 FS::BindColorData(pass, color_buffer);
121 bool RadialGradientContents::RenderUniform(
const ContentContext& renderer,
122 const Entity& entity,
123 RenderPass& pass)
const {
127 VS::FrameInfo frame_info;
131 [&renderer](ContentContextOptions options) {
132 return renderer.GetRadialGradientUniformFillPipeline(options);
134 return ColorSourceContents::DrawGeometry<VS>(
135 renderer, entity, pass, pipeline_callback, frame_info,
136 [
this, &renderer, &entity](RenderPass& pass) {
137 FS::FragInfo frag_info;
138 frag_info.center = center_;
139 frag_info.radius = radius_;
140 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
145 colors_, stops_, frag_info.colors, frag_info.stop_pairs);
146 frag_info.decal_border_color = decal_border_color_;
148 pass.SetCommandLabel(
"RadialGradientUniformFill");
151 pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
157 bool RadialGradientContents::RenderTexture(
const ContentContext& renderer,
158 const Entity& entity,
159 RenderPass& pass)
const {
164 auto gradient_texture =
166 if (gradient_texture ==
nullptr) {
170 VS::FrameInfo frame_info;
174 [&renderer](ContentContextOptions options) {
175 return renderer.GetRadialGradientFillPipeline(options);
177 return ColorSourceContents::DrawGeometry<VS>(
178 renderer, entity, pass, pipeline_callback, frame_info,
179 [
this, &renderer, &gradient_texture, &entity](RenderPass& pass) {
180 FS::FragInfo frag_info;
181 frag_info.center = center_;
182 frag_info.radius = radius_;
183 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
184 frag_info.decal_border_color = decal_border_color_;
185 frag_info.texture_sampler_y_coord_scale =
186 gradient_texture->GetYCoordScale();
190 frag_info.half_texel =
191 Vector2(0.5 / gradient_texture->GetSize().width,
192 0.5 / gradient_texture->GetSize().height);
194 SamplerDescriptor sampler_desc;
198 pass.SetCommandLabel(
"RadialGradientFill");
201 pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
202 FS::BindTextureSampler(
203 pass, gradient_texture,
204 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
213 for (
Color& color : colors_) {
214 color = color_filter_proc(color);
216 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.
bool AppliesAlphaForStrokeCoverage(const Matrix &transform) const
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverag...
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
const Capabilities & GetDeviceCapabilities() const
PipelineRef GetRadialGradientSSBOFillPipeline(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...
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
void SetTileMode(Entity::TileMode tile_mode)
~RadialGradientContents() override
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetCenterAndRadius(Point center, Scalar radius)
void SetStops(std::vector< Scalar > stops)
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
void SetColors(std::vector< Color > colors)
const std::vector< Scalar > & GetStops() const
const std::vector< Color > & GetColors() const
Render passes encode render commands directed as one specific render target into an underlying comman...
VertexShader_ VertexShader
FragmentShader_ FragmentShader
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...
static constexpr uint32_t kMaxUniformGradientStops
#define UNIFORM_STOP_SIZE
#define UNIFORM_COLOR_SIZE
A 4x4 matrix using column-major storage.