7#include "flutter/fml/logging.h"
29 scale_ = 1 / (t1 - t0);
33 colors_ = std::move(
colors);
37 stops_ = std::move(stops);
41 tile_mode_ = tile_mode;
56 for (
auto color : colors_) {
57 if (!
color.IsOpaque()) {
67 if (
renderer.GetDeviceCapabilities().SupportsSSBO()) {
68 return RenderSSBO(
renderer, entity, pass);
70 return RenderTexture(
renderer, entity, pass);
79 VS::FrameInfo frame_info;
81 VS::BindFrameInfo(pass,
82 renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
88 return ColorSourceContents::DrawGeometry<VS>(
89 renderer, entity, pass, pipeline_callback, frame_info,
90 [
this, &
renderer, &entity](RenderPass& pass) {
91 FS::FragInfo frag_info;
92 frag_info.center = center_;
93 frag_info.bias = bias_;
94 frag_info.scale = scale_;
95 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
96 frag_info.decal_border_color = decal_border_color_;
100 auto& host_buffer =
renderer.GetTransientsBuffer();
103 frag_info.colors_length =
colors.size();
105 host_buffer.Emplace(
colors.data(),
colors.size() *
sizeof(StopData),
108 pass.SetCommandLabel(
"SweepGradientSSBOFill");
111 pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
112 FS::BindColorData(pass, color_buffer);
118bool SweepGradientContents::RenderTexture(
const ContentContext&
renderer,
119 const Entity& entity,
120 RenderPass& pass)
const {
125 auto gradient_texture =
127 if (gradient_texture ==
nullptr) {
131 VS::FrameInfo frame_info;
138 return ColorSourceContents::DrawGeometry<VS>(
139 renderer, entity, pass, pipeline_callback, frame_info,
140 [
this, &
renderer, &gradient_texture, &entity](RenderPass& pass) {
141 FS::FragInfo frag_info;
142 frag_info.center = center_;
143 frag_info.bias = bias_;
144 frag_info.scale = scale_;
145 frag_info.texture_sampler_y_coord_scale =
146 gradient_texture->GetYCoordScale();
147 frag_info.tile_mode =
static_cast<Scalar>(tile_mode_);
148 frag_info.decal_border_color = decal_border_color_;
151 frag_info.half_texel =
152 Vector2(0.5 / gradient_texture->GetSize().width,
153 0.5 / gradient_texture->GetSize().height);
155 SamplerDescriptor sampler_desc;
159 pass.SetCommandLabel(
"SweepGradientFill");
162 pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
163 FS::BindTextureSampler(
164 pass, gradient_texture,
165 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
177 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
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.
bool IsOpaque() 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)
void SetColors(std::vector< Color > colors)
#define FML_DCHECK(condition)
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()