7 #include "flutter/fml/logging.h"
18 : geometry_(geometry) {}
34 scale_ = 1 / (t1 - t0);
38 colors_ = std::move(colors);
42 stops_ = std::move(stops);
46 tile_mode_ = tile_mode;
61 for (
auto color : colors_) {
62 if (!color.IsOpaque()) {
69 #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
70 #define UNIFORM_FRAG_INFO(t) \
71 t##GradientUniformFillPipeline::FragmentShader::FragInfo
72 #define UNIFORM_COLOR_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Sweep)::colors)
73 #define UNIFORM_STOP_SIZE ARRAY_LEN(UNIFORM_FRAG_INFO(Sweep)::stop_pairs)
81 return RenderSSBO(renderer, entity, pass);
85 return RenderUniform(renderer, entity, pass);
87 return RenderTexture(renderer, entity, pass);
90 bool SweepGradientContents::RenderSSBO(
const ContentContext& renderer,
96 VS::FrameInfo frame_info;
105 return ColorSourceContents::DrawGeometry<VS>(
106 renderer, entity, pass, pipeline_callback, frame_info,
107 [
this, &renderer, &entity](RenderPass& pass) {
108 FS::FragInfo frag_info;
109 frag_info.center = center_;
110 frag_info.bias = bias_;
111 frag_info.scale = scale_;
112 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
113 frag_info.decal_border_color = decal_border_color_;
121 frag_info.colors_length = colors.size();
122 auto color_buffer = data_host_buffer.Emplace(
123 colors.data(), colors.size() *
sizeof(StopData),
127 pass.SetCommandLabel(
"SweepGradientSSBOFill");
131 FS::BindColorData(pass, color_buffer);
137 bool SweepGradientContents::RenderUniform(
const ContentContext& renderer,
138 const Entity& entity,
139 RenderPass& pass)
const {
143 VS::FrameInfo frame_info;
146 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frame_info));
149 [&renderer](ContentContextOptions options) {
150 return renderer.GetSweepGradientUniformFillPipeline(options);
152 return ColorSourceContents::DrawGeometry<VS>(
153 renderer, entity, pass, pipeline_callback, frame_info,
154 [
this, &renderer, &entity](RenderPass& pass) {
155 FS::FragInfo frag_info;
156 frag_info.center = center_;
157 frag_info.bias = bias_;
158 frag_info.scale = scale_;
159 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
164 colors_, stops_, frag_info.colors, frag_info.stop_pairs);
166 frag_info.decal_border_color = decal_border_color_;
168 pass.SetCommandLabel(
"SweepGradientUniformFill");
171 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
177 bool SweepGradientContents::RenderTexture(
const ContentContext& renderer,
178 const Entity& entity,
179 RenderPass& pass)
const {
184 auto gradient_texture =
186 if (gradient_texture ==
nullptr) {
190 VS::FrameInfo frame_info;
194 [&renderer](ContentContextOptions options) {
195 return renderer.GetSweepGradientFillPipeline(options);
197 return ColorSourceContents::DrawGeometry<VS>(
198 renderer, entity, pass, pipeline_callback, frame_info,
199 [
this, &renderer, &gradient_texture, &entity](RenderPass& pass) {
200 FS::FragInfo frag_info;
201 frag_info.center = center_;
202 frag_info.bias = bias_;
203 frag_info.scale = scale_;
204 frag_info.texture_sampler_y_coord_scale =
205 gradient_texture->GetYCoordScale();
206 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
207 frag_info.decal_border_color = decal_border_color_;
211 frag_info.half_texel =
212 Vector2(0.5 / gradient_texture->GetSize().width,
213 0.5 / gradient_texture->GetSize().height);
215 SamplerDescriptor sampler_desc;
219 pass.SetCommandLabel(
"SweepGradientFill");
222 pass, renderer.GetTransientsDataBuffer().EmplaceUniform(frag_info));
223 FS::BindTextureSampler(
224 pass, gradient_texture,
225 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
234 for (
Color& color : colors_) {
235 color = color_filter_proc(color);
237 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 GetSweepGradientSSBOFillPipeline(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
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
void SetTileMode(Entity::TileMode tile_mode)
void SetCenterAndAngles(Point center, Degrees start_angle, Degrees end_angle)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
const std::vector< Color > & GetColors() const
const std::vector< Scalar > & GetStops() const
~SweepGradientContents() override
void SetStops(std::vector< Scalar > stops)
SweepGradientContents(const Geometry *geometry)
void SetColors(std::vector< Color > colors)
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
A 4x4 matrix using column-major storage.
#define UNIFORM_STOP_SIZE
#define UNIFORM_COLOR_SIZE