| 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 93 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 141 of file atlas_contents.cc.

141 {
142 if (!geometry_) {
143 return std::nullopt;
144 }
145 return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
146 }
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:472

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 156 of file atlas_contents.cc.

158 {
159 if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
160 return true;
161 }
162
163 const SamplerDescriptor& dst_sampler_descriptor =
164 geometry_->GetSamplerDescriptor();
165 raw_ptr<const Sampler> dst_sampler =
166 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
167 dst_sampler_descriptor);
168
169 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
170 if (!geometry_->ShouldUseBlend()) {
171 using VS = TextureFillVertexShader;
172 using FS = TextureFillFragmentShader;
173
174 raw_ptr<const Sampler> dst_sampler =
175 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
176 dst_sampler_descriptor);
177
178 auto pipeline_options = OptionsFromPassAndEntity(pass, entity);
179 pipeline_options.primitive_type = PrimitiveType::kTriangle;
180 pipeline_options.depth_write_enabled =
181 pipeline_options.blend_mode == BlendMode::kSrc;
182
183 pass.SetPipeline(renderer.GetTexturePipeline(pipeline_options));
184 pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(data_host_buffer));
185 #ifdef IMPELLER_DEBUG
186 pass.SetCommandLabel("DrawAtlas");
187 #endif // IMPELLER_DEBUG
188
189 VS::FrameInfo frame_info;
190 frame_info.mvp = entity.GetShaderTransform(pass);
191 frame_info.texture_sampler_y_coord_scale =
192 geometry_->GetAtlas()->GetYCoordScale();
193
194 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
195
196 FS::FragInfo frag_info;
197 frag_info.alpha = alpha_;
198 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
199 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
200 return pass.Draw().ok();
201 }
202
203 BlendMode blend_mode = geometry_->GetBlendMode();
204
205 if (blend_mode <= BlendMode::kModulate) {
206 using VS = PorterDuffBlendPipeline::VertexShader;
207 using FS = PorterDuffBlendPipeline::FragmentShader;
208
209 #ifdef IMPELLER_DEBUG
210 pass.SetCommandLabel("DrawAtlas Blend");
211 #endif // IMPELLER_DEBUG
212 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(data_host_buffer));
213 BlendMode inverted_blend_mode =
214 geometry_->ShouldInvertBlendMode()
215 ? (InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc))
216 : blend_mode;
217 pass.SetPipeline(renderer.GetPorterDuffPipeline(
218 inverted_blend_mode, OptionsFromPassAndEntity(pass, entity)));
219
220 FS::FragInfo frag_info;
221 VS::FrameInfo frame_info;
222
223 FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
224 frame_info.texture_sampler_y_coord_scale =
225 geometry_->GetAtlas()->GetYCoordScale();
226
227 frag_info.input_alpha_output_alpha_tmx_tmy =
228 Vector4(1.0, alpha_, static_cast<int>(Entity::TileMode::kDecal),
229 static_cast<int>(Entity::TileMode::kDecal));
230 if (auto rect = geometry_->GetStrictSrcRect(); rect.has_value()) {
231 Rect src_rect = rect.value();
232 frag_info.source_rect =
233 Vector4(src_rect.GetX(), src_rect.GetY(), src_rect.GetBottom(),
234 src_rect.GetRight());
235 frag_info.use_strict_source_rect = 1.0;
236 } else {
237 frag_info.use_strict_source_rect = 0.0;
238 }
239
240 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
241
242 frame_info.mvp = entity.GetShaderTransform(pass);
243
244 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
245 VS::BindFrameInfo(pass, uniform_view);
246
247 return pass.Draw().ok();
248 }
249
250 using VUS = VerticesUber1Shader::VertexShader;
251 using FS = VerticesUber1Shader::FragmentShader;
252
253 #ifdef IMPELLER_DEBUG
254 pass.SetCommandLabel("DrawAtlas Advanced Blend");
255 #endif // IMPELLER_DEBUG
256 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(data_host_buffer));
257
258 pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(
259 blend_mode, OptionsFromPassAndEntity(pass, entity)));
260 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
261
262 VUS::FrameInfo frame_info;
263 FS::FragInfo frag_info;
264
265 frame_info.texture_sampler_y_coord_scale =
266 geometry_->GetAtlas()->GetYCoordScale();
267 frame_info.mvp = entity.GetShaderTransform(pass);
268
269 frag_info.alpha = alpha_;
270 frag_info.blend_mode = static_cast<int>(blend_mode);
271
272 // These values are ignored on platforms that natively support decal.
273 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
274 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
275
276 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
277 VUS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
278
279 return pass.Draw().ok();
280 }
impeller::AtlasGeometry::GetStrictSrcRect
virtual std::optional< Rect > GetStrictSrcRect() const
The source rect of the draw if a strict source rect should be applied, or nullopt.
Definition: atlas_contents.h:47
impeller::AtlasGeometry::CreateSimpleVertexBuffer
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
impeller::AtlasGeometry::ShouldInvertBlendMode
virtual bool ShouldInvertBlendMode() const
Definition: atlas_contents.h:41
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:163
impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:164
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:788
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::TRect< T >::GetBottom(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDrawVerticesUberPipeline(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::TRect< T >::GetRight(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::AtlasGeometry::GetStrictSrcRect(), impeller::ContentContext::GetTexturePipeline(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), 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 152 of file atlas_contents.cc.

152 {
153 alpha_ = alpha;
154 }

## ◆ SetGeometry()

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

Definition at line 148 of file atlas_contents.cc.

148 {
149 geometry_ = geometry;
150 }

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

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