Flutter Impeller
impeller::AtlasColorContents Class Referencefinal

#include <atlas_contents.h>

Inheritance diagram for impeller::AtlasColorContents:
impeller::Contents

Public Member Functions

 AtlasColorContents (const AtlasContents &parent)
 
 ~AtlasColorContents () override
 
std::optional< RectGetCoverage (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
 
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 ClipCoverage GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
 Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer. More...
 
virtual std::optional< SnapshotRenderToSnapshot (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, const std::string &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...
 
virtual bool ShouldRender (const Entity &entity, const std::optional< Rect > clip_coverage) const
 
std::optional< SizeGetColorSourceSize () 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< ColorAsBackgroundColor (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 FilterContentsAsFilter () 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< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Detailed Description

Definition at line 133 of file atlas_contents.h.

Constructor & Destructor Documentation

◆ AtlasColorContents()

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

Definition at line 425 of file atlas_contents.cc.

426  : parent_(parent) {}

◆ ~AtlasColorContents()

impeller::AtlasColorContents::~AtlasColorContents ( )
override

Definition at line 428 of file atlas_contents.cc.

428 {}

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::AtlasColorContents::GetCoverage ( const Entity entity) const
overridevirtual

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

431  {
432  return coverage_.TransformBounds(entity.GetTransform());
433 }

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

◆ Render()

bool impeller::AtlasColorContents::Render ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Contents.

Definition at line 448 of file atlas_contents.cc.

450  {
453 
454  std::vector<Rect> texture_coords;
455  std::vector<Matrix> transforms;
456  std::vector<Color> colors;
457  if (subatlas_) {
458  texture_coords = subatlas_->sub_texture_coords;
459  colors = subatlas_->sub_colors;
460  transforms = subatlas_->sub_transforms;
461  } else {
462  texture_coords = parent_.GetTextureCoordinates();
463  transforms = parent_.GetTransforms();
464  colors = parent_.GetColors();
465  }
466 
467  VertexBufferBuilder<VS::PerVertexData> vertex_builder;
468  vertex_builder.Reserve(texture_coords.size() * 6);
469  constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
470  for (size_t i = 0; i < texture_coords.size(); i++) {
471  auto sample_rect = texture_coords[i];
472  auto matrix = transforms[i];
473  auto transformed_points =
474  Rect::MakeSize(sample_rect.GetSize()).GetTransformedPoints(matrix);
475 
476  for (size_t j = 0; j < 6; j++) {
477  VS::PerVertexData data;
478  data.position = transformed_points[indices[j]];
479  data.color = colors[i].Premultiply();
480  vertex_builder.AppendVertex(data);
481  }
482  }
483 
484  if (!vertex_builder.HasVertices()) {
485  return true;
486  }
487 
488  pass.SetCommandLabel("AtlasColors");
489 
490  auto& host_buffer = renderer.GetTransientsBuffer();
491 
492  VS::FrameInfo frame_info;
493  frame_info.mvp = entity.GetShaderTransform(pass);
494 
495  FS::FragInfo frag_info;
496  frag_info.alpha = alpha_;
497 
498  auto opts = OptionsFromPassAndEntity(pass, entity);
499  opts.blend_mode = BlendMode::kSourceOver;
500  pass.SetPipeline(renderer.GetGeometryColorPipeline(opts));
501  pass.SetStencilReference(entity.GetClipDepth());
502  pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
503  VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
504  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
505  return pass.Draw().ok();
506 }

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendVertex(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::RenderPass::Draw(), impeller::Entity::GetClipDepth(), impeller::AtlasContents::GetColors(), impeller::ContentContext::GetGeometryColorPipeline(), impeller::Entity::GetShaderTransform(), impeller::AtlasContents::GetTextureCoordinates(), impeller::TRect< T >::GetTransformedPoints(), impeller::AtlasContents::GetTransforms(), impeller::ContentContext::GetTransientsBuffer(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::HasVertices(), impeller::kSourceOver, impeller::TRect< Scalar >::MakeSize(), impeller::OptionsFromPassAndEntity(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::Reserve(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetStencilReference(), and impeller::RenderPass::SetVertexBuffer().

◆ SetAlpha()

void impeller::AtlasColorContents::SetAlpha ( Scalar  alpha)

Definition at line 435 of file atlas_contents.cc.

435  {
436  alpha_ = alpha;
437 }

◆ SetCoverage()

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

Definition at line 439 of file atlas_contents.cc.

439  {
440  coverage_ = coverage;
441 }

◆ SetSubAtlas()

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

Definition at line 443 of file atlas_contents.cc.

444  {
445  subatlas_ = subatlas;
446 }

The documentation for this class was generated from the following files:
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:405
impeller::RenderPipelineT::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:94
impeller::VS
SolidFillVertexShader VS
Definition: stroke_path_geometry.cc:15
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:37
impeller::TRect::GetTransformedPoints
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:394
impeller::AtlasContents::GetTransforms
const std::vector< Matrix > & GetTransforms() const
Definition: atlas_contents.cc:173
impeller::AtlasContents::GetTextureCoordinates
const std::vector< Rect > & GetTextureCoordinates() const
Definition: atlas_contents.cc:177
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146
impeller::RenderPipelineT::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:93
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::AtlasContents::GetColors
const std::vector< Color > & GetColors() const
Definition: atlas_contents.cc:181