| Flutter Impeller |

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

`#include <atlas_contents.h>`

Inheritance diagram for impeller::AtlasTextureContents:

## Public Member Functions
| AtlasTextureContents (const AtlasContents &parent)
| ~AtlasTextureContents () override
std::optional< Rect > | GetCoverage (const Entity &entity) const override
| Get the screen space bounding rectangle that this contents affects. More...
bool | Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void | SetAlpha (Scalar alpha)
void | SetCoverage (Rect coverage)
void | SetTexture (std::shared_ptr< Texture > texture)
void | SetUseDestination (bool value)
void | SetSubAtlas (const std::shared_ptr< SubAtlasResult > &subatlas)
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 StencilCoverage | GetStencilCoverage (const Entity &entity, const std::optional< Rect > &current_stencil_coverage) const
| Given the current screen space bounding rectangle of the stencil, return the expected stencil coverage after this draw call. This should only be implemented for contents that may write to the stencil 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, const std::string &label="Snapshot") const
| Render this contents to a snapshot, respecting the entity's transform, path, stencil 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 > &stencil_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
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

## ◆ AtlasTextureContents()

impeller::AtlasTextureContents::AtlasTextureContents | ( | const AtlasContents & | parent | ) |
| explicit

Definition at line 334 of file atlas_contents.cc.

335 : parent_(parent) {}

## ◆ ~AtlasTextureContents()

impeller::AtlasTextureContents::~AtlasTextureContents | ( |  | ) |
| override

Definition at line 337 of file atlas_contents.cc.

337 {}

## Member Function Documentation

## ◆ GetCoverage()

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

Get the screen space bounding rectangle that this contents affects.

Implements impeller::Contents.

Definition at line 339 of file atlas_contents.cc.

340 {
341 return coverage_.TransformBounds(entity.GetTransformation());
342 }

References impeller::Entity::GetTransformation(), and impeller::TRect< T >::TransformBounds().

## ◆ Render()

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

Implements impeller::Contents.

Definition at line 365 of file atlas_contents.cc.

367 {
368 using VS = TextureFillVertexShader;
369 using FS = TextureFillFragmentShader;
370
371 auto texture = texture_ ? texture_ : parent_.GetTexture();
372 if (texture == nullptr) {
373 return true;
374 }
375
376 std::vector<Rect> texture_coords;
377 std::vector<Matrix> transforms;
378 if (subatlas_) {
379 texture_coords = use_destination_ ? subatlas_->result_texture_coords
380 : subatlas_->sub_texture_coords;
381 transforms = use_destination_ ? subatlas_->result_transforms
382 : subatlas_->sub_transforms;
383 } else {
384 texture_coords = parent_.GetTextureCoordinates();
385 transforms = parent_.GetTransforms();
386 }
387
388 const Size texture_size(texture->GetSize());
389 VertexBufferBuilder<VS::PerVertexData> vertex_builder;
390 vertex_builder.Reserve(texture_coords.size() * 6);
391 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
392 constexpr Scalar width[6] = {0, 1, 0, 1, 0, 1};
393 constexpr Scalar height[6] = {0, 0, 1, 0, 1, 1};
394 for (size_t i = 0; i < texture_coords.size(); i++) {
395 auto sample_rect = texture_coords[i];
396 auto matrix = transforms[i];
397 auto transformed_points =
398 Rect::MakeSize(sample_rect.size).GetTransformedPoints(matrix);
399
400 for (size_t j = 0; j < 6; j++) {
401 VS::PerVertexData data;
402 data.position = transformed_points[indices[j]];
403 data.texture_coords =
404 (sample_rect.origin + Point(sample_rect.size.width * width[j],
405 sample_rect.size.height * height[j])) /
406 texture_size;
407 vertex_builder.AppendVertex(data);
408 }
409 }
410
411 if (!vertex_builder.HasVertices()) {
412 return true;
413 }
414
415 Command cmd;
416 DEBUG_COMMAND_INFO(cmd, "AtlasTexture");
417
418 auto& host_buffer = pass.GetTransientsBuffer();
419
420 VS::FrameInfo frame_info;
421 frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
422 entity.GetTransformation();
423 frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
424 frame_info.alpha = alpha_;
425
426 auto options = OptionsFromPassAndEntity(pass, entity);
427 cmd.pipeline = renderer.GetTexturePipeline(options);
428 cmd.stencil_reference = entity.GetStencilDepth();
429 cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
430 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
431 FS::BindTextureSampler(cmd, texture,
432 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
433 parent_.GetSamplerDescriptor()));
434 return pass.AddCommand(std::move(cmd));
435 }

References impeller::RenderPass::AddCommand(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendVertex(), impeller::Command::BindVertices(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), DEBUG_COMMAND_INFO, impeller::ContentContext::GetContext(), impeller::RenderPass::GetRenderTargetSize(), impeller::AtlasContents::GetSamplerDescriptor(), impeller::Entity::GetStencilDepth(), impeller::AtlasContents::GetTexture(), impeller::AtlasContents::GetTextureCoordinates(), impeller::ContentContext::GetTexturePipeline(), impeller::Entity::GetTransformation(), impeller::TRect< T >::GetTransformedPoints(), impeller::AtlasContents::GetTransforms(), impeller::RenderPass::GetTransientsBuffer(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::HasVertices(), impeller::Matrix::MakeOrthographic(), impeller::TRect< Scalar >::MakeSize(), impeller::OptionsFromPassAndEntity(), impeller::Command::pipeline, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::Reserve(), and impeller::Command::stencil_reference.

## ◆ SetAlpha()

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

Definition at line 344 of file atlas_contents.cc.

344 {
345 alpha_ = alpha;
346 }

## ◆ SetCoverage()

void impeller::AtlasTextureContents::SetCoverage | ( | Rect | coverage | ) |

Definition at line 348 of file atlas_contents.cc.

348 {
349 coverage_ = coverage;
350 }

## ◆ SetSubAtlas()

void impeller::AtlasTextureContents::SetSubAtlas | ( | const std::shared_ptr< SubAtlasResult > & | subatlas | ) |

Definition at line 356 of file atlas_contents.cc.

357 {
358 subatlas_ = subatlas;
359 }

## ◆ SetTexture()

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

Definition at line 361 of file atlas_contents.cc.

361 {
362 texture_ = std::move(texture);
363 }

## ◆ SetUseDestination()

void impeller::AtlasTextureContents::SetUseDestination | ( | bool | value | ) |

Definition at line 352 of file atlas_contents.cc.

352 {
353 use_destination_ = value;
354 }

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

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

DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:204
impeller::Size
TSize< Scalar > Size
Definition: size.h:135
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:30
impeller::Point
TPoint< Scalar > Point
Definition: point.h:306
impeller::TRect::GetTransformedPoints
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:193
impeller::AtlasContents::GetTransforms
const std::vector< Matrix > & GetTransforms() const
Definition: atlas_contents.cc:178
impeller::AtlasContents::GetTextureCoordinates
const std::vector< Rect > & GetTextureCoordinates() const
Definition: atlas_contents.cc:182
impeller::AtlasContents::GetTexture
std::shared_ptr< Texture > GetTexture() const
Definition: atlas_contents.cc:38
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:52
impeller::Matrix::MakeOrthographic
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition: matrix.h:448
impeller::AtlasContents::GetSamplerDescriptor
const SamplerDescriptor & GetSamplerDescriptor() const
Definition: atlas_contents.cc:174