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

424  : parent_(parent) {}

◆ ~AtlasColorContents()

impeller::AtlasColorContents::~AtlasColorContents ( )
override

Definition at line 426 of file atlas_contents.cc.

426 {}

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

429  {
430  return coverage_.TransformBounds(entity.GetTransform());
431 }

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

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

References impeller::RenderPass::AddCommand(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendVertex(), impeller::Command::BindVertices(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), DEBUG_COMMAND_INFO, impeller::Entity::GetClipDepth(), impeller::AtlasContents::GetColors(), impeller::ContentContext::GetGeometryColorPipeline(), impeller::RenderPass::GetOrthographicTransform(), impeller::AtlasContents::GetTextureCoordinates(), impeller::Entity::GetTransform(), impeller::TRect< T >::GetTransformedPoints(), impeller::AtlasContents::GetTransforms(), impeller::RenderPass::GetTransientsBuffer(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::HasVertices(), impeller::kSourceOver, 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 433 of file atlas_contents.cc.

433  {
434  alpha_ = alpha;
435 }

◆ SetCoverage()

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

Definition at line 437 of file atlas_contents.cc.

437  {
438  coverage_ = coverage;
439 }

◆ SetSubAtlas()

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

Definition at line 441 of file atlas_contents.cc.

442  {
443  subatlas_ = subatlas;
444 }

The documentation for this class was generated from the following files:
DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:28
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:264
impeller::RenderPipelineT::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:93
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:28
impeller::TRect::GetTransformedPoints
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:253
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:44
impeller::RenderPipelineT::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:92
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::AtlasContents::GetColors
const std::vector< Color > & GetColors() const
Definition: atlas_contents.cc:181