| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::VerticesSimpleBlendContents Class Referencefinal

`#include <vertices_contents.h>`

Inheritance diagram for impeller::VerticesSimpleBlendContents:

## Public Types
using | LazyTexture = std::function< std::shared_ptr< Texture >(const ContentContext &renderer)>
Public Types inherited from impeller::Contents
using | ColorFilterProc = std::function< Color(Color)>
using | RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)>
using | CoverageProc = std::function< std::optional< Rect >(const Entity &entity)>

## Public Member Functions
| VerticesSimpleBlendContents ()
| ~VerticesSimpleBlendContents () override
void | SetGeometry (std::shared_ptr< VerticesGeometry > geometry)
void | SetAlpha (Scalar alpha)
void | SetBlendMode (BlendMode blend_mode)
void | SetTexture (std::shared_ptr< Texture > texture)
void | SetLazyTexture (const LazyTexture &lazy_texture)
void | SetSamplerDescriptor (SamplerDescriptor descriptor)
void | SetTileMode (Entity::TileMode tile_mode_x, Entity::TileMode tile_mode_y)
void | SetEffectTransform (Matrix transform)
void | SetLazyTextureCoverage (Rect rect)
std::optional< Rect > | GetCoverage (const Entity &entity) const override
| Get the area of the render pass that will be affected when this contents is rendered. More...
bool | Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Public Member Functions inherited from impeller::Contents
| Contents ()
virtual | ~Contents ()
virtual void | PopulateGlyphAtlas (const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
| Add any text data to the specified lazy atlas. The scale parameter must be used again later when drawing the text. More...
void | SetCoverageHint (std::optional< Rect > coverage_hint)
| Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of `GetCoverage()`. More...
const std::optional< Rect > & | GetCoverageHint () const
virtual bool | IsOpaque () const
| Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity. More...
virtual ClipCoverage | GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
| Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer. More...
virtual std::optional< Snapshot > | RenderToSnapshot (const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &label="Snapshot") const
| Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of `GetCoverage(entity)`. More...
virtual bool | ShouldRender (const Entity &entity, const std::optional< Rect > clip_coverage) const
std::optional< Size > | GetColorSourceSize () const
| Return the color source's intrinsic size, if available. More...
void | SetColorSourceSize (Size size)
virtual bool | CanInheritOpacity (const Entity &entity) const
| Whether or not this contents can accept the opacity peephole optimization. More...
virtual void | SetInheritedOpacity (Scalar opacity)
| Inherit the provided opacity. More...
virtual std::optional< Color > | AsBackgroundColor (const Entity &entity, ISize target_size) const
| Returns a color if this Contents will flood the given `target_size` with a color. This output color is the "Source" color that will be used for the Entity's blend operation. More...
virtual const FilterContents * | AsFilter () const
| Cast to a filter. Returns `nullptr` if this Contents is not a filter. More...
virtual bool | ApplyColorFilter (const ColorFilterProc &color_filter_proc)
| If possible, applies a color filter to this contents inputs on the CPU. More...

## Additional Inherited Members
Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< Contents > | MakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)

## Detailed Description

A vertices contents for (optional) per-color vertices + texture and any blend mode.

Definition at line 20 of file vertices_contents.h.

## Member Typedef Documentation

## ◆ LazyTexture

using impeller::VerticesSimpleBlendContents::LazyTexture = std::function<std::shared_ptr<Texture>(const ContentContext& renderer)>

Definition at line 27 of file vertices_contents.h.

## Constructor & Destructor Documentation

## ◆ VerticesSimpleBlendContents()

impeller::VerticesSimpleBlendContents::VerticesSimpleBlendContents | ( |  | ) |

Definition at line 46 of file vertices_contents.cc.

46 {}

## ◆ ~VerticesSimpleBlendContents()

impeller::VerticesSimpleBlendContents::~VerticesSimpleBlendContents | ( |  | ) |
| override

Definition at line 48 of file vertices_contents.cc.

48 {}

## Member Function Documentation

## ◆ GetCoverage()

std::optional< Rect > impeller::VerticesSimpleBlendContents::GetCoverage | ( | const Entity & | entity | ) | const
| override virtual

Get the area of the render pass that will be affected when this contents is rendered.

During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.

Returns
  The coverage rectangle. An `std::nullopt` result means that rendering this contents has no effect on the output color.

Implements impeller::Contents.

Definition at line 67 of file vertices_contents.cc.

68 {
69 return geometry_->GetCoverage(entity.GetTransform());
70 }

References impeller::Entity::GetTransform().

## ◆ Render()

bool impeller::VerticesSimpleBlendContents::Render | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  | const
| override virtual

Implements impeller::Contents.

Definition at line 96 of file vertices_contents.cc.

98 {
99 FML_DCHECK(texture_ || lazy_texture_ ||
100 blend_mode_ == BlendMode::kDestination);
101 BlendMode blend_mode = blend_mode_;
102 if (!geometry_->HasVertexColors()) {
103 blend_mode = BlendMode::kSource;
104 }
105
106 std::shared_ptr<Texture> texture;
107 if (blend_mode != BlendMode::kDestination) {
108 if (!texture_) {
109 texture = lazy_texture_(renderer);
110 } else {
111 texture = texture_;
112 }
113 } else {
114 texture = renderer.GetEmptyTexture();
115 }
116 if (!texture) {
117 VALIDATION_LOG << "Missing texture for VerticesSimpleBlendContents";
118 return false;
119 }
120
121 auto dst_sampler_descriptor = descriptor_;
122 dst_sampler_descriptor.width_address_mode =
123 TileModeToAddressMode(tile_mode_x_, renderer.GetDeviceCapabilities())
124 .value_or(SamplerAddressMode::kClampToEdge);
125 dst_sampler_descriptor.height_address_mode =
126 TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities())
127 .value_or(SamplerAddressMode::kClampToEdge);
128
129 const std::unique_ptr<const Sampler>& dst_sampler =
130 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
131 dst_sampler_descriptor);
132
133 GeometryResult geometry_result = geometry_->GetPositionUVColorBuffer(
134 lazy_texture_coverage_.has_value() ? lazy_texture_coverage_.value()
135 : Rect::MakeSize(texture->GetSize()),
136 inverse_matrix_, renderer, entity, pass);
137 if (geometry_result.vertex_buffer.vertex_count == 0) {
138 return true;
139 }
140 FML_DCHECK(geometry_result.mode == GeometryResult::Mode::kNormal);
141
142 if (blend_mode <= Entity::kLastPipelineBlendMode) {
143 using VS = PorterDuffBlendPipeline::VertexShader;
144 using FS = PorterDuffBlendPipeline::FragmentShader;
145
146 #ifdef IMPELLER_DEBUG
147 pass.SetCommandLabel(SPrintF("DrawVertices Porterduff Blend (%s)",
148 BlendModeToString(blend_mode)));
149 #endif // IMPELLER_DEBUG
150 pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
151
152 auto options = OptionsFromPassAndEntity(pass, entity);
153 options.primitive_type = geometry_result.type;
154 pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options));
155
156 FS::BindTextureSamplerDst(pass, texture, dst_sampler);
157
158 VS::FrameInfo frame_info;
159 FS::FragInfo frag_info;
160
161 frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
162 frame_info.mvp = geometry_result.transform;
163
164 frag_info.output_alpha = alpha_;
165 frag_info.input_alpha = 1.0;
166
167 auto inverted_blend_mode =
168 InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSource);
169 auto blend_coefficients =
170 kPorterDuffCoefficients[static_cast<int>(inverted_blend_mode)];
171 frag_info.src_coeff = blend_coefficients[0];
172 frag_info.src_coeff_dst_alpha = blend_coefficients[1];
173 frag_info.dst_coeff = blend_coefficients[2];
174 frag_info.dst_coeff_src_alpha = blend_coefficients[3];
175 frag_info.dst_coeff_src_color = blend_coefficients[4];
176
177 // These values are ignored if the platform supports native decal mode.
178 frag_info.tmx = static_cast<int>(tile_mode_x_);
179 frag_info.tmy = static_cast<int>(tile_mode_y_);
180
181 auto& host_buffer = renderer.GetTransientsBuffer();
182 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
183 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
184
185 return pass.Draw().ok();
186 }
187
188 using VS = VerticesUberShader::VertexShader;
189 using FS = VerticesUberShader::FragmentShader;
190
191 #ifdef IMPELLER_DEBUG
192 pass.SetCommandLabel(SPrintF("DrawVertices Advanced Blend (%s)",
193 BlendModeToString(blend_mode)));
194 #endif // IMPELLER_DEBUG
195 pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
196
197 auto options = OptionsFromPassAndEntity(pass, entity);
198 options.primitive_type = geometry_result.type;
199 pass.SetPipeline(renderer.GetDrawVerticesUberShader(options));
200
201 FS::BindTextureSampler(pass, texture, dst_sampler);
202
203 VS::FrameInfo frame_info;
204 FS::FragInfo frag_info;
205
206 frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
207 frame_info.mvp = geometry_result.transform;
208 frag_info.alpha = alpha_;
209 frag_info.blend_mode = static_cast<int>(blend_mode);
210
211 // These values are ignored if the platform supports native decal mode.
212 frag_info.tmx = static_cast<int>(tile_mode_x_);
213 frag_info.tmy = static_cast<int>(tile_mode_y_);
214
215 auto& host_buffer = renderer.GetTransientsBuffer();
216 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
217 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
218
219 return pass.Draw().ok();
220 }

References impeller::BlendModeToString(), impeller::RenderPass::Draw(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), impeller::ContentContext::GetDrawVerticesUberShader(), impeller::ContentContext::GetEmptyTexture(), impeller::ContentContext::GetPorterDuffBlendPipeline(), impeller::ContentContext::GetTransientsBuffer(), impeller::InvertPorterDuffBlend(), impeller::kClampToEdge, impeller::kDestination, impeller::Entity::kLastPipelineBlendMode, impeller::GeometryResult::kNormal, impeller::kPorterDuffCoefficients, impeller::kSource, impeller::TRect< Scalar >::MakeSize(), impeller::GeometryResult::mode, impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::SPrintF(), impeller::TileModeToAddressMode(), impeller::GeometryResult::transform, impeller::GeometryResult::type, VALIDATION_LOG, impeller::GeometryResult::vertex_buffer, impeller::VertexBuffer::vertex_count, and impeller::SamplerDescriptor::width_address_mode.

## ◆ SetAlpha()

void impeller::VerticesSimpleBlendContents::SetAlpha | ( | Scalar | alpha | ) |

Definition at line 55 of file vertices_contents.cc.

55 {
56 alpha_ = alpha;
57 }

## ◆ SetBlendMode()

void impeller::VerticesSimpleBlendContents::SetBlendMode | ( | BlendMode | blend_mode | ) |

Definition at line 59 of file vertices_contents.cc.

59 {
60 blend_mode_ = blend_mode;
61 }

## ◆ SetEffectTransform()

void impeller::VerticesSimpleBlendContents::SetEffectTransform | ( | Matrix | transform | ) |

Definition at line 83 of file vertices_contents.cc.

83 {
84 inverse_matrix_ = transform.Invert();
85 }

References transform.

## ◆ SetGeometry()

void impeller::VerticesSimpleBlendContents::SetGeometry | ( | std::shared_ptr< VerticesGeometry > | geometry | ) |

Definition at line 50 of file vertices_contents.cc.

51 {
52 geometry_ = std::move(geometry);
53 }

## ◆ SetLazyTexture()

void impeller::VerticesSimpleBlendContents::SetLazyTexture | ( | const LazyTexture & | lazy_texture | ) |

Definition at line 87 of file vertices_contents.cc.

88 {
89 lazy_texture_ = lazy_texture;
90 }

## ◆ SetLazyTextureCoverage()

void impeller::VerticesSimpleBlendContents::SetLazyTextureCoverage | ( | Rect | rect | ) |

Definition at line 92 of file vertices_contents.cc.

92 {
93 lazy_texture_coverage_ = rect;
94 }

## ◆ SetSamplerDescriptor()

void impeller::VerticesSimpleBlendContents::SetSamplerDescriptor | ( | SamplerDescriptor | descriptor | ) |

Definition at line 72 of file vertices_contents.cc.

73 {
74 descriptor_ = std::move(descriptor);
75 }

## ◆ SetTexture()

void impeller::VerticesSimpleBlendContents::SetTexture | ( | std::shared_ptr< Texture > | texture | ) |

Definition at line 63 of file vertices_contents.cc.

63 {
64 texture_ = std::move(texture);
65 }

## ◆ SetTileMode()

void impeller::VerticesSimpleBlendContents::SetTileMode | ( | Entity::TileMode | tile_mode_x,
|  | Entity::TileMode | tile_mode_y
| ) |  |

Definition at line 77 of file vertices_contents.cc.

78 {
79 tile_mode_x_ = tile_mode_x;
80 tile_mode_y_ = tile_mode_y;
81 }

The documentation for this class was generated from the following files:

- impeller/entity/contents/vertices_contents.h
- impeller/entity/contents/vertices_contents.cc

impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:107
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::Entity::kLastPipelineBlendMode
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:22
impeller::BlendModeToString
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:47
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::BlendMode::kSource
@ kSource
impeller::BlendMode::kDestination
@ kDestination
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:31
impeller::SamplerAddressMode::kClampToEdge
@ kClampToEdge
impeller::VS
SolidFillVertexShader VS
Definition: stroke_path_geometry.cc:16
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:231
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:106
impeller::SamplerDescriptor::width_address_mode
SamplerAddressMode width_address_mode
Definition: sampler_descriptor.h:20
impeller::kPorterDuffCoefficients
constexpr std::array< std::array< Scalar, 5 >, 15 > kPorterDuffCoefficients
Definition: blend_filter_contents.h:15
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146
impeller::TileModeToAddressMode
static std::optional< SamplerAddressMode > TileModeToAddressMode(Entity::TileMode tile_mode, const Capabilities &capabilities)
Definition: tiled_texture_contents.cc:15