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, 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 96 of file atlas_contents.h.

Constructor & Destructor Documentation

◆ AtlasTextureContents()

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

Definition at line 325 of file atlas_contents.cc.

326  : parent_(parent) {}

◆ ~AtlasTextureContents()

impeller::AtlasTextureContents::~AtlasTextureContents ( )
override

Definition at line 328 of file atlas_contents.cc.

328 {}

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

331  {
332  return coverage_.TransformBounds(entity.GetTransform());
333 }

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

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

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendVertex(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::RenderPass::Draw(), impeller::Entity::GetClipDepth(), impeller::ContentContext::GetContext(), impeller::AtlasContents::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::AtlasContents::GetTexture(), impeller::AtlasContents::GetTextureCoordinates(), impeller::ContentContext::GetTexturePipeline(), impeller::TRect< T >::GetTransformedPoints(), impeller::AtlasContents::GetTransforms(), impeller::ContentContext::GetTransientsBuffer(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::HasVertices(), 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::AtlasTextureContents::SetAlpha ( Scalar  alpha)

Definition at line 335 of file atlas_contents.cc.

335  {
336  alpha_ = alpha;
337 }

◆ SetCoverage()

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

Definition at line 339 of file atlas_contents.cc.

339  {
340  coverage_ = coverage;
341 }

◆ SetSubAtlas()

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

Definition at line 347 of file atlas_contents.cc.

348  {
349  subatlas_ = subatlas;
350 }

◆ SetTexture()

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

Definition at line 352 of file atlas_contents.cc.

352  {
353  texture_ = std::move(texture);
354 }

◆ SetUseDestination()

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

Definition at line 343 of file atlas_contents.cc.

343  {
344  use_destination_ = value;
345 }

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::Size
TSize< Scalar > Size
Definition: size.h:137
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::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:146
impeller::AtlasContents::GetSamplerDescriptor
const SamplerDescriptor & GetSamplerDescriptor() const
Definition: atlas_contents.cc:169