18 : geometry_(geometry) {}
32 tile_mode_ = tile_mode;
36 colors_ = std::move(colors);
40 stops_ = std::move(stops);
55 for (
auto color : colors_) {
56 if (!color.IsOpaque()) {
63 #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
64 #define UNIFORM_FRAG_INFO(t) \
65 t##GradientUniformFillPipeline::FragmentShader::FragInfo
66 #define UNIFORM_COLOR_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Radial)::colors)
67 #define UNIFORM_STOP_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Radial)::stop_pairs)
75 return RenderSSBO(renderer, entity, pass);
79 return RenderUniform(renderer, entity, pass);
81 return RenderTexture(renderer, entity, pass);
84 bool RadialGradientContents::RenderSSBO(
const ContentContext& renderer,
90 VS::FrameInfo frame_info;
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_;
112 frag_info.colors_length = colors.size();
113 auto color_buffer = data_host_buffer.Emplace(
114 colors.data(), colors.size() *
sizeof(StopData),
118 pass.SetCommandLabel(
"RadialGradientSSBOFill");
119 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
120 FS::BindColorData(pass, color_buffer);
126 bool RadialGradientContents::RenderUniform(
const ContentContext& renderer,
127 const Entity& entity,
128 RenderPass& pass)
const {
132 VS::FrameInfo frame_info;
136 [&renderer](ContentContextOptions options) {
137 return renderer.GetRadialGradientUniformFillPipeline(options);
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_);
150 colors_, stops_, frag_info.colors, frag_info.stop_pairs);
151 frag_info.decal_border_color = decal_border_color_;
153 pass.SetCommandLabel(
"RadialGradientUniformFill");
156 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
162 bool RadialGradientContents::RenderTexture(
const ContentContext& renderer,
163 const Entity& entity,
164 RenderPass& pass)
const {
169 auto gradient_texture =
171 if (gradient_texture ==
nullptr) {
175 VS::FrameInfo frame_info;
179 [&renderer](ContentContextOptions options) {
180 return renderer.GetRadialGradientFillPipeline(options);
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();
195 frag_info.half_texel =
196 Vector2(0.5 / gradient_texture->GetSize().width,
197 0.5 / gradient_texture->GetSize().height);
199 SamplerDescriptor sampler_desc;
203 pass.SetCommandLabel(
"RadialGradientFill");
206 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
207 FS::BindTextureSampler(
208 pass, gradient_texture,
209 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
218 for (
Color& color : colors_) {
219 color = color_filter_proc(color);
221 decal_border_color_ = color_filter_proc(decal_border_color_);
virtual size_t GetMinimumStorageBufferAlignment() const
The minimum alignment of storage buffer value offsets in bytes.
virtual bool SupportsSSBO() const =0
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
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
const Capabilities & GetDeviceCapabilities() const
PipelineRef GetRadialGradientSSBOFillPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
std::function< Color(Color)> ColorFilterProc
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
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)
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
RadialGradientContents(const Geometry *geometry)
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.