Flutter Impeller
impeller::AtlasTextureContents Class Referencefinal

#include <atlas_contents.h>

Inheritance diagram for impeller::AtlasTextureContents:
impeller::Contents

Public Member Functions

 AtlasTextureContents (const AtlasContents &parent)
 
 ~AtlasTextureContents () 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 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 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 96 of file atlas_contents.h.

Constructor & Destructor Documentation

◆ AtlasTextureContents()

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

Definition at line 322 of file atlas_contents.cc.

323  : parent_(parent) {}

◆ ~AtlasTextureContents()

impeller::AtlasTextureContents::~AtlasTextureContents ( )
override

Definition at line 325 of file atlas_contents.cc.

325 {}

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::AtlasTextureContents::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 327 of file atlas_contents.cc.

328  {
329  return coverage_.TransformBounds(entity.GetTransform());
330 }

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

◆ Render()

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

Implements impeller::Contents.

Definition at line 353 of file atlas_contents.cc.

355  {
356  using VS = TextureFillVertexShader;
357  using FS = TextureFillFragmentShader;
358 
359  auto texture = texture_ ? texture_ : parent_.GetTexture();
360  if (texture == nullptr) {
361  return true;
362  }
363 
364  std::vector<Rect> texture_coords;
365  std::vector<Matrix> transforms;
366  if (subatlas_) {
367  texture_coords = use_destination_ ? subatlas_->result_texture_coords
368  : subatlas_->sub_texture_coords;
369  transforms = use_destination_ ? subatlas_->result_transforms
370  : subatlas_->sub_transforms;
371  } else {
372  texture_coords = parent_.GetTextureCoordinates();
373  transforms = parent_.GetTransforms();
374  }
375 
376  const Size texture_size(texture->GetSize());
377  VertexBufferBuilder<VS::PerVertexData> vertex_builder;
378  vertex_builder.Reserve(texture_coords.size() * 6);
379  constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
380  for (size_t i = 0; i < texture_coords.size(); i++) {
381  auto sample_rect = texture_coords[i];
382  auto matrix = transforms[i];
383  auto points = sample_rect.GetPoints();
384  auto transformed_points =
385  Rect::MakeSize(sample_rect.GetSize()).GetTransformedPoints(matrix);
386 
387  for (size_t j = 0; j < 6; j++) {
388  VS::PerVertexData data;
389  data.position = transformed_points[indices[j]];
390  data.texture_coords = points[indices[j]] / texture_size;
391  vertex_builder.AppendVertex(data);
392  }
393  }
394 
395  if (!vertex_builder.HasVertices()) {
396  return true;
397  }
398 
399  Command cmd;
400  DEBUG_COMMAND_INFO(cmd, "AtlasTexture");
401 
402  auto& host_buffer = pass.GetTransientsBuffer();
403 
404  VS::FrameInfo frame_info;
405  frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform();
406  frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
407  frame_info.alpha = alpha_;
408 
409  auto options = OptionsFromPassAndEntity(pass, entity);
410  cmd.pipeline = renderer.GetTexturePipeline(options);
411  cmd.stencil_reference = entity.GetClipDepth();
412  cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
413  VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
414  FS::BindTextureSampler(cmd, texture,
415  renderer.GetContext()->GetSamplerLibrary()->GetSampler(
416  parent_.GetSamplerDescriptor()));
417  return pass.AddCommand(std::move(cmd));
418 }

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

332  {
333  alpha_ = alpha;
334 }

◆ SetCoverage()

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

Definition at line 336 of file atlas_contents.cc.

336  {
337  coverage_ = coverage;
338 }

◆ SetSubAtlas()

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

Definition at line 344 of file atlas_contents.cc.

345  {
346  subatlas_ = subatlas;
347 }

◆ SetTexture()

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

Definition at line 349 of file atlas_contents.cc.

349  {
350  texture_ = std::move(texture);
351 }

◆ SetUseDestination()

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

Definition at line 340 of file atlas_contents.cc.

340  {
341  use_destination_ = value;
342 }

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::Size
TSize< Scalar > Size
Definition: size.h:137
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::AtlasContents::GetTexture
std::shared_ptr< Texture > GetTexture() const
Definition: atlas_contents.cc:32
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:44
impeller::AtlasContents::GetSamplerDescriptor
const SamplerDescriptor & GetSamplerDescriptor() const
Definition: atlas_contents.cc:169