27 tile_mode_ = tile_mode;
31 colors_ = std::move(
colors);
35 stops_ = std::move(stops);
50 for (
auto color : colors_) {
51 if (!
color.IsOpaque()) {
61 if (
renderer.GetDeviceCapabilities().SupportsSSBO()) {
62 return RenderSSBO(
renderer, entity, pass);
64 return RenderTexture(
renderer, entity, pass);
73 VS::FrameInfo frame_info;
80 return ColorSourceContents::DrawGeometry<VS>(
81 renderer, entity, pass, pipeline_callback, frame_info,
82 [
this, &
renderer, &entity](RenderPass& pass) {
83 FS::FragInfo frag_info;
84 frag_info.center = center_;
85 frag_info.radius = radius_;
86 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
87 frag_info.decal_border_color = decal_border_color_;
91 auto& host_buffer =
renderer.GetTransientsBuffer();
94 frag_info.colors_length =
colors.size();
96 host_buffer.Emplace(
colors.data(),
colors.size() *
sizeof(StopData),
99 pass.SetCommandLabel(
"RadialGradientSSBOFill");
101 pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
102 FS::BindColorData(pass, color_buffer);
108bool RadialGradientContents::RenderTexture(
const ContentContext&
renderer,
109 const Entity& entity,
110 RenderPass& pass)
const {
115 auto gradient_texture =
117 if (gradient_texture ==
nullptr) {
121 VS::FrameInfo frame_info;
128 return ColorSourceContents::DrawGeometry<VS>(
129 renderer, entity, pass, pipeline_callback, frame_info,
130 [
this, &
renderer, &gradient_texture, &entity](RenderPass& pass) {
131 FS::FragInfo frag_info;
132 frag_info.center = center_;
133 frag_info.radius = radius_;
134 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
135 frag_info.decal_border_color = decal_border_color_;
136 frag_info.texture_sampler_y_coord_scale =
137 gradient_texture->GetYCoordScale();
140 frag_info.half_texel =
141 Vector2(0.5 / gradient_texture->GetSize().width,
142 0.5 / gradient_texture->GetSize().height);
144 SamplerDescriptor sampler_desc;
148 pass.SetCommandLabel(
"RadialGradientFill");
151 pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
152 FS::BindTextureSampler(
153 pass, gradient_texture,
154 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
166 decal_border_color_ = color_filter_proc(decal_border_color_);
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)> PipelineBuilderCallback
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
std::function< Color(Color)> ColorFilterProc
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)
bool IsOpaque() const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
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
PODArray< SkColor > colors
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.
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()