| Flutter Impeller |

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

`#include <atlas_contents.h>`

Inheritance diagram for impeller::AtlasContents:

## Public Member Functions
| AtlasContents ()
| ~AtlasContents () override
void | SetGeometry (AtlasGeometry *geometry)
void | SetAlpha (Scalar alpha)
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
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)>
Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< Contents > | MakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)

## Detailed Description

Definition at line 81 of file atlas_contents.h.

## Constructor & Destructor Documentation

## ◆ AtlasContents()

impeller::AtlasContents::AtlasContents | ( |  | ) |
| explicit default

## ◆ ~AtlasContents()

impeller::AtlasContents::~AtlasContents | ( |  | ) |
| override default

## Member Function Documentation

## ◆ GetCoverage()

std::optional< Rect > impeller::AtlasContents::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 132 of file atlas_contents.cc.

132 {
133 if (!geometry_) {
134 return std::nullopt;
135 }
136 return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
137 }
impeller::AtlasGeometry::ComputeBoundingBox
virtual Rect ComputeBoundingBox() const =0
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476

References impeller::AtlasGeometry::ComputeBoundingBox(), impeller::Entity::GetTransform(), and impeller::TRect< T >::TransformBounds().

## ◆ Render()

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

Implements impeller::Contents.

Definition at line 147 of file atlas_contents.cc.

149 {
150 if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
151 return true;
152 }
153
154 const SamplerDescriptor& dst_sampler_descriptor =
155 geometry_->GetSamplerDescriptor();
156 raw_ptr<const Sampler> dst_sampler =
157 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
158 dst_sampler_descriptor);
159
160 auto& host_buffer = renderer.GetTransientsBuffer();
161 if (!geometry_->ShouldUseBlend()) {
162 using VS = TextureFillVertexShader;
163 using FS = TextureFillFragmentShader;
164
165 raw_ptr<const Sampler> dst_sampler =
166 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
167 dst_sampler_descriptor);
168
169 auto pipeline_options = OptionsFromPassAndEntity(pass, entity);
170 pipeline_options.primitive_type = PrimitiveType::kTriangle;
171 pipeline_options.depth_write_enabled =
172 pipeline_options.blend_mode == BlendMode::kSrc;
173
174 pass.SetPipeline(renderer.GetTexturePipeline(pipeline_options));
175 pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(host_buffer));
176 #ifdef IMPELLER_DEBUG
177 pass.SetCommandLabel("DrawAtlas");
178 #endif // IMPELLER_DEBUG
179
180 VS::FrameInfo frame_info;
181 frame_info.mvp = entity.GetShaderTransform(pass);
182 frame_info.texture_sampler_y_coord_scale =
183 geometry_->GetAtlas()->GetYCoordScale();
184
185 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
186
187 FS::FragInfo frag_info;
188 frag_info.alpha = alpha_;
189 FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
190 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
191 return pass.Draw().ok();
192 }
193
194 BlendMode blend_mode = geometry_->GetBlendMode();
195
196 if (blend_mode <= BlendMode::kModulate) {
197 using VS = PorterDuffBlendPipeline::VertexShader;
198 using FS = PorterDuffBlendPipeline::FragmentShader;
199
200 #ifdef IMPELLER_DEBUG
201 pass.SetCommandLabel("DrawAtlas Blend");
202 #endif // IMPELLER_DEBUG
203 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
204 BlendMode inverted_blend_mode =
205 geometry_->ShouldInvertBlendMode()
206 ? (InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc))
207 : blend_mode;
208 pass.SetPipeline(renderer.GetPorterDuffPipeline(
209 inverted_blend_mode, OptionsFromPassAndEntity(pass, entity)));
210
211 FS::FragInfo frag_info;
212 VS::FrameInfo frame_info;
213
214 FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
215 frame_info.texture_sampler_y_coord_scale =
216 geometry_->GetAtlas()->GetYCoordScale();
217
218 frag_info.output_alpha = alpha_;
219 frag_info.input_alpha = 1.0;
220
221 // These values are ignored on platforms that natively support decal.
222 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
223 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
224
225 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
226
227 frame_info.mvp = entity.GetShaderTransform(pass);
228
229 auto uniform_view = host_buffer.EmplaceUniform(frame_info);
230 VS::BindFrameInfo(pass, uniform_view);
231
232 return pass.Draw().ok();
233 }
234
235 using VUS = VerticesUber1Shader::VertexShader;
236 using FS = VerticesUber1Shader::FragmentShader;
237
238 #ifdef IMPELLER_DEBUG
239 pass.SetCommandLabel("DrawAtlas Advanced Blend");
240 #endif // IMPELLER_DEBUG
241 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
242
243 renderer.GetDrawVerticesUberPipeline(blend_mode,
244 OptionsFromPassAndEntity(pass, entity));
245 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
246
247 VUS::FrameInfo frame_info;
248 FS::FragInfo frag_info;
249
250 frame_info.texture_sampler_y_coord_scale =
251 geometry_->GetAtlas()->GetYCoordScale();
252 frame_info.mvp = entity.GetShaderTransform(pass);
253
254 frag_info.alpha = alpha_;
255 frag_info.blend_mode = static_cast<int>(blend_mode);
256
257 // These values are ignored on platforms that natively support decal.
258 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
259 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
260
261 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
262 VUS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
263
264 return pass.Draw().ok();
265 }
impeller::AtlasGeometry::CreateSimpleVertexBuffer
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
impeller::AtlasGeometry::ShouldInvertBlendMode
virtual bool ShouldInvertBlendMode() const
Definition: atlas_contents.h:39
impeller::AtlasGeometry::ShouldUseBlend
virtual bool ShouldUseBlend() const =0
impeller::AtlasGeometry::GetSamplerDescriptor
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
impeller::AtlasGeometry::ShouldSkip
virtual bool ShouldSkip() const =0
impeller::AtlasGeometry::CreateBlendVertexBuffer
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
impeller::AtlasGeometry::GetBlendMode
virtual BlendMode GetBlendMode() const =0
impeller::AtlasGeometry::GetAtlas
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:119
impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:120
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::FS
LinePipeline::FragmentShader FS
Definition: line_contents.cc:14
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:51
impeller::BlendMode
BlendMode
Definition: color.h:58
impeller::BlendMode::kModulate
@ kModulate
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

References impeller::AtlasGeometry::CreateBlendVertexBuffer(), impeller::AtlasGeometry::CreateSimpleVertexBuffer(), impeller::RenderPass::Draw(), impeller::AtlasGeometry::GetAtlas(), impeller::AtlasGeometry::GetBlendMode(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDrawVerticesUberPipeline(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTexturePipeline(), impeller::ContentContext::GetTransientsBuffer(), impeller::InvertPorterDuffBlend(), impeller::Entity::kDecal, impeller::kModulate, impeller::kSrc, impeller::kTriangle, impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::AtlasGeometry::ShouldInvertBlendMode(), impeller::AtlasGeometry::ShouldSkip(), and impeller::AtlasGeometry::ShouldUseBlend().

## ◆ SetAlpha()

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

Definition at line 143 of file atlas_contents.cc.

143 {
144 alpha_ = alpha;
145 }

## ◆ SetGeometry()

void impeller::AtlasContents::SetGeometry | ( | AtlasGeometry * | geometry | ) |

Definition at line 139 of file atlas_contents.cc.

139 {
140 geometry_ = geometry;
141 }

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

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