| Flutter Impeller |

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

`#include <atlas_contents.h>`

Inheritance diagram for impeller::AtlasColorContents:

## Public Member Functions
| AtlasColorContents (const AtlasContents &parent)
| ~AtlasColorContents () 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 | 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 128 of file atlas_contents.h.

## Constructor & Destructor Documentation

## ◆ AtlasColorContents()

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

Definition at line 440 of file atlas_contents.cc.

441 : parent_(parent) {}

## ◆ ~AtlasColorContents()

impeller::AtlasColorContents::~AtlasColorContents | ( |  | ) |
| override

Definition at line 443 of file atlas_contents.cc.

443 {}

## Member Function Documentation

## ◆ GetCoverage()

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

Get the screen space bounding rectangle that this contents affects.

Implements impeller::Contents.

Definition at line 445 of file atlas_contents.cc.

446 {
447 return coverage_.TransformBounds(entity.GetTransformation());
448 }

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

## ◆ Render()

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

Implements impeller::Contents.

Definition at line 463 of file atlas_contents.cc.

465 {
466 using VS = GeometryColorPipeline::VertexShader;
467 using FS = GeometryColorPipeline::FragmentShader;
468
469 std::vector<Rect> texture_coords;
470 std::vector<Matrix> transforms;
471 std::vector<Color> colors;
472 if (subatlas_) {
473 texture_coords = subatlas_->sub_texture_coords;
474 colors = subatlas_->sub_colors;
475 transforms = subatlas_->sub_transforms;
476 } else {
477 texture_coords = parent_.GetTextureCoordinates();
478 transforms = parent_.GetTransforms();
479 colors = parent_.GetColors();
480 }
481
482 VertexBufferBuilder<VS::PerVertexData> vertex_builder;
483 vertex_builder.Reserve(texture_coords.size() * 6);
484 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
485 for (size_t i = 0; i < texture_coords.size(); i++) {
486 auto sample_rect = texture_coords[i];
487 auto matrix = transforms[i];
488 auto transformed_points =
489 Rect::MakeSize(sample_rect.size).GetTransformedPoints(matrix);
490
491 for (size_t j = 0; j < 6; j++) {
492 VS::PerVertexData data;
493 data.position = transformed_points[indices[j]];
494 data.color = colors[i].Premultiply();
495 vertex_builder.AppendVertex(data);
496 }
497 }
498
499 if (!vertex_builder.HasVertices()) {
500 return true;
501 }
502
503 Command cmd;
504 DEBUG_COMMAND_INFO(cmd, "AtlasColors");
505
506 auto& host_buffer = pass.GetTransientsBuffer();
507
508 VS::FrameInfo frame_info;
509 frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
510 entity.GetTransformation();
511
512 FS::FragInfo frag_info;
513 frag_info.alpha = alpha_;
514
515 auto opts = OptionsFromPassAndEntity(pass, entity);
516 opts.blend_mode = BlendMode::kSourceOver;
517 cmd.pipeline = renderer.GetGeometryColorPipeline(opts);
518 cmd.stencil_reference = entity.GetStencilDepth();
519 cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
520 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
521 FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
522 return pass.AddCommand(std::move(cmd));
523 }

References impeller::RenderPass::AddCommand(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendVertex(), impeller::Command::BindVertices(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), DEBUG_COMMAND_INFO, impeller::AtlasContents::GetColors(), impeller::ContentContext::GetGeometryColorPipeline(), impeller::RenderPass::GetRenderTargetSize(), impeller::Entity::GetStencilDepth(), impeller::AtlasContents::GetTextureCoordinates(), impeller::Entity::GetTransformation(), impeller::TRect< T >::GetTransformedPoints(), impeller::AtlasContents::GetTransforms(), impeller::RenderPass::GetTransientsBuffer(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::HasVertices(), impeller::kSourceOver, 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::AtlasColorContents::SetAlpha | ( | Scalar | alpha | ) |

Definition at line 450 of file atlas_contents.cc.

450 {
451 alpha_ = alpha;
452 }

## ◆ SetCoverage()

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

Definition at line 454 of file atlas_contents.cc.

454 {
455 coverage_ = coverage;
456 }

## ◆ SetSubAtlas()

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

Definition at line 458 of file atlas_contents.cc.

459 {
460 subatlas_ = subatlas;
461 }

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::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:204
impeller::RenderPipelineT::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:91
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:30
impeller::BlendMode::kSourceOver
@ kSourceOver
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::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::RenderPipelineT::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:90
impeller::AtlasContents::GetColors
const std::vector< Color > & GetColors() const
Definition: atlas_contents.cc:186