| 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 (const 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 ()
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 Matrix &transform) 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 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, std::string_view 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...
std::optional< Size > | GetColorSourceSize () const
| Return the color source's intrinsic size, if available. More...
void | SetColorSourceSize (Size size)
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 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 26 of file vertices_contents.h.

## Constructor & Destructor Documentation

## ◆ VerticesSimpleBlendContents()

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

Definition at line 49 of file vertices_contents.cc.

49 {}

## ◆ ~VerticesSimpleBlendContents()

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

Definition at line 51 of file vertices_contents.cc.

51 {}

## 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 70 of file vertices_contents.cc.

71 {
72 return geometry_->GetCoverage(entity.GetTransform());
73 }

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 99 of file vertices_contents.cc.

101 {
102 FML_DCHECK(texture_ || lazy_texture_ || blend_mode_ == BlendMode::kDst);
103 BlendMode blend_mode = blend_mode_;
104 if (!geometry_->HasVertexColors()) {
105 blend_mode = BlendMode::kSrc;
106 }
107
108 std::shared_ptr<Texture> texture;
109 if (blend_mode != BlendMode::kDst) {
110 if (!texture_) {
111 texture = lazy_texture_(renderer);
112 } else {
113 texture = texture_;
114 }
115 } else {
116 texture = renderer.GetEmptyTexture();
117 }
118 if (!texture) {
119 VALIDATION_LOG << "Missing texture for VerticesSimpleBlendContents";
120 return false;
121 }
122
123 auto dst_sampler_descriptor = descriptor_;
124 dst_sampler_descriptor.width_address_mode =
125 TileModeToAddressMode(tile_mode_x_, renderer.GetDeviceCapabilities())
126 .value_or(SamplerAddressMode::kClampToEdge);
127 dst_sampler_descriptor.height_address_mode =
128 TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities())
129 .value_or(SamplerAddressMode::kClampToEdge);
130
131 raw_ptr<const Sampler> dst_sampler =
132 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
133 dst_sampler_descriptor);
134
135 GeometryResult geometry_result = geometry_->GetPositionUVColorBuffer(
136 lazy_texture_coverage_.has_value() ? lazy_texture_coverage_.value()
137 : Rect::MakeSize(texture->GetSize()),
138 inverse_matrix_, renderer, entity, pass);
139 if (geometry_result.vertex_buffer.vertex_count == 0) {
140 return true;
141 }
142 FML_DCHECK(geometry_result.mode == GeometryResult::Mode::kNormal);
143
144 if (blend_mode <= Entity::kLastPipelineBlendMode) {
145 using VS = PorterDuffBlendPipeline::VertexShader;
146 using FS = PorterDuffBlendPipeline::FragmentShader;
147
148 #ifdef IMPELLER_DEBUG
149 pass.SetCommandLabel(std::format("DrawVertices Porterduff Blend ({})",
150 BlendModeToString(blend_mode)));
151 #endif // IMPELLER_DEBUG
152 pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
153
154 auto options = OptionsFromPassAndEntity(pass, entity);
155 options.primitive_type = geometry_result.type;
156 auto inverted_blend_mode =
157 InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc);
158 pass.SetPipeline(
159 renderer.GetPorterDuffPipeline(inverted_blend_mode, options));
160
161 FS::BindTextureSamplerDst(pass, texture, dst_sampler);
162
163 VS::FrameInfo frame_info;
164 FS::FragInfo frag_info;
165
166 frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
167 frame_info.mvp = geometry_result.transform;
168
169 frag_info.input_alpha_output_alpha_tmx_tmy =
170 Vector4(1, alpha_, static_cast<int>(tile_mode_x_),
171 static_cast<int>(tile_mode_y_));
172 frag_info.use_strict_source_rect = 0.0;
173
174 auto& host_buffer = renderer.GetTransientsDataBuffer();
175 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
176 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
177
178 return pass.Draw().ok();
179 }
180
181 using VS = VerticesUber1Shader::VertexShader;
182 using FS = VerticesUber1Shader::FragmentShader;
183
184 #ifdef IMPELLER_DEBUG
185 pass.SetCommandLabel(std::format("DrawVertices Advanced Blend ({})",
186 BlendModeToString(blend_mode)));
187 #endif // IMPELLER_DEBUG
188 pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
189
190 auto options = OptionsFromPassAndEntity(pass, entity);
191 options.primitive_type = geometry_result.type;
192 pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(blend_mode, options));
193
194 FS::BindTextureSampler(pass, texture, dst_sampler);
195
196 VS::FrameInfo frame_info;
197 FS::FragInfo frag_info;
198
199 frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
200 frame_info.mvp = geometry_result.transform;
201 frag_info.alpha = alpha_;
202 frag_info.blend_mode = static_cast<int>(blend_mode);
203
204 // These values are ignored if the platform supports native decal mode.
205 frag_info.tmx = static_cast<int>(tile_mode_x_);
206 frag_info.tmy = static_cast<int>(tile_mode_y_);
207
208 auto& host_buffer = renderer.GetTransientsDataBuffer();
209 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
210 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
211
212 return pass.Draw().ok();
213 }
impeller::Entity::kLastPipelineBlendMode
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:28
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:163
impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:164
impeller::SamplerAddressMode::kClampToEdge
@ kClampToEdge
impeller::BlendModeToString
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:47
impeller::FS
LinePipeline::FragmentShader FS
Definition: line_contents.cc:14
impeller::TileModeToAddressMode
static std::optional< SamplerAddressMode > TileModeToAddressMode(Entity::TileMode tile_mode, const Capabilities &capabilities)
Definition: tiled_texture_contents.cc:16
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:51
impeller::BlendMode
BlendMode
Definition: color.h:58
impeller::BlendMode::kDst
@ kDst
impeller::BlendMode::kSrc
@ kSrc
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::SamplerDescriptor::width_address_mode
SamplerAddressMode width_address_mode
Definition: sampler_descriptor.h:19
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BlendModeToString(), impeller::RenderPass::Draw(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), impeller::ContentContext::GetDrawVerticesUberPipeline(), impeller::ContentContext::GetEmptyTexture(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::InvertPorterDuffBlend(), impeller::kClampToEdge, impeller::kDst, impeller::Entity::kLastPipelineBlendMode, impeller::GeometryResult::kNormal, impeller::kSrc, impeller::TRect< Scalar >::MakeSize(), impeller::GeometryResult::mode, impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), 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 58 of file vertices_contents.cc.

58 {
59 alpha_ = alpha;
60 }

## ◆ SetBlendMode()

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

Definition at line 62 of file vertices_contents.cc.

62 {
63 blend_mode_ = blend_mode;
64 }

## ◆ SetEffectTransform()

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

Definition at line 86 of file vertices_contents.cc.

86 {
87 inverse_matrix_ = transform.Invert();
88 }
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214

References transform.

## ◆ SetGeometry()

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

Definition at line 53 of file vertices_contents.cc.

54 {
55 geometry_ = std::move(geometry);
56 }

## ◆ SetLazyTexture()

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

Definition at line 90 of file vertices_contents.cc.

91 {
92 lazy_texture_ = lazy_texture;
93 }

## ◆ SetLazyTextureCoverage()

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

Definition at line 95 of file vertices_contents.cc.

95 {
96 lazy_texture_coverage_ = rect;
97 }

## ◆ SetSamplerDescriptor()

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

Definition at line 75 of file vertices_contents.cc.

76 {
77 descriptor_ = descriptor;
78 }

## ◆ SetTexture()

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

Definition at line 66 of file vertices_contents.cc.

66 {
67 texture_ = std::move(texture);
68 }

## ◆ SetTileMode()

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

Definition at line 80 of file vertices_contents.cc.

81 {
82 tile_mode_x_ = tile_mode_x;
83 tile_mode_y_ = tile_mode_y;
84 }

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

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