Flutter Impeller
impeller::Entity Class Reference

#include <entity.h>

Public Types

enum  RenderingMode {
  RenderingMode::kDirect,
  RenderingMode::kSubpass
}
 
enum  TileMode {
  TileMode::kClamp,
  TileMode::kRepeat,
  TileMode::kMirror,
  TileMode::kDecal
}
 
enum  ClipOperation {
  ClipOperation::kDifference,
  ClipOperation::kIntersect
}
 

Public Member Functions

 Entity ()
 
 ~Entity ()
 
 Entity (Entity &&)=default
 
const MatrixGetTransform () const
 Get the global transform matrix for this Entity. More...
 
void SetTransform (const Matrix &transform)
 Set the global transform matrix for this Entity. More...
 
std::optional< RectGetCoverage () const
 
Contents::ClipCoverage GetClipCoverage (const std::optional< Rect > &current_clip_coverage) const
 
bool ShouldRender (const std::optional< Rect > &clip_coverage) const
 
void SetContents (std::shared_ptr< Contents > contents)
 
const std::shared_ptr< Contents > & GetContents () const
 
void SetClipDepth (uint32_t clip_depth)
 
void IncrementStencilDepth (uint32_t increment)
 
uint32_t GetClipDepth () const
 
void SetBlendMode (BlendMode blend_mode)
 
BlendMode GetBlendMode () const
 
bool Render (const ContentContext &renderer, RenderPass &parent_pass) const
 
bool CanInheritOpacity () const
 
bool SetInheritedOpacity (Scalar alpha)
 
std::optional< ColorAsBackgroundColor (ISize target_size) const
 
Scalar DeriveTextScale () const
 
CaptureGetCapture () const
 
void SetCapture (Capture capture) const
 
Entity Clone () const
 

Static Public Member Functions

static std::optional< EntityFromSnapshot (const std::optional< Snapshot > &snapshot, BlendMode blend_mode=BlendMode::kSourceOver, uint32_t clip_depth=0)
 Create an entity that can be used to render a given snapshot. More...
 
static bool IsBlendModeDestructive (BlendMode blend_mode)
 Returns true if the blend mode is "destructive", meaning that even fully transparent source colors would result in the destination getting changed. More...
 

Static Public Attributes

static constexpr BlendMode kLastPipelineBlendMode = BlendMode::kModulate
 
static constexpr BlendMode kLastAdvancedBlendMode = BlendMode::kLuminosity
 

Detailed Description

Definition at line 21 of file entity.h.

Member Enumeration Documentation

◆ ClipOperation

Enumerator
kDifference 
kIntersect 

Definition at line 59 of file entity.h.

59  {
61  kIntersect,
62  };

◆ RenderingMode

Enumerator
kDirect 

In direct mode, the Entity's transform is used as the current local-to-screen transform matrix.

kSubpass 

In subpass mode, the Entity passed through the filter is in screen space rather than local space, and so some filters (namely, MatrixFilterContents) need to interpret the given EffectTransform as the current transform matrix.

Definition at line 26 of file entity.h.

26  {
27  /// In direct mode, the Entity's transform is used as the current
28  /// local-to-screen transform matrix.
29  kDirect,
30  /// In subpass mode, the Entity passed through the filter is in screen space
31  /// rather than local space, and so some filters (namely,
32  /// MatrixFilterContents) need to interpret the given EffectTransform as the
33  /// current transform matrix.
34  kSubpass,
35  };

◆ TileMode

An enum to define how to repeat, fold, or omit colors outside of the typically defined range of the source of the colors (such as the bounds of an image or the defining geometry of a gradient).

Enumerator
kClamp 

Replicate the edge color if the shader draws outside of its original bounds.

kRepeat 

Repeat the shader's image horizontally and vertically (or both along and perpendicular to a gradient's geometry).

kMirror 

Repeat the shader's image horizontally and vertically, seamlessly alternating mirrored images.

kDecal 

Render the shader's image pixels only within its original bounds. If the shader draws outside of its original bounds, transparent black is drawn instead.

Definition at line 40 of file entity.h.

40  {
41  /// Replicate the edge color if the shader draws outside of its original
42  /// bounds.
43  kClamp,
44 
45  /// Repeat the shader's image horizontally and vertically (or both along and
46  /// perpendicular to a gradient's geometry).
47  kRepeat,
48 
49  /// Repeat the shader's image horizontally and vertically, seamlessly
50  /// alternating mirrored images.
51  kMirror,
52 
53  /// Render the shader's image pixels only within its original bounds. If the
54  /// shader draws outside of its original bounds, transparent black is drawn
55  /// instead.
56  kDecal,
57  };

Constructor & Destructor Documentation

◆ Entity() [1/2]

impeller::Entity::Entity ( )
default

Referenced by Clone().

◆ ~Entity()

impeller::Entity::~Entity ( )
default

◆ Entity() [2/2]

impeller::Entity::Entity ( Entity &&  )
default

Member Function Documentation

◆ AsBackgroundColor()

std::optional< Color > impeller::Entity::AsBackgroundColor ( ISize  target_size) const

Definition at line 131 of file entity.cc.

131  {
132  return contents_->AsBackgroundColor(*this, target_size);
133 }

◆ CanInheritOpacity()

bool impeller::Entity::CanInheritOpacity ( ) const

Definition at line 109 of file entity.cc.

109  {
110  if (!contents_) {
111  return false;
112  }
113  if (!((blend_mode_ == BlendMode::kSource && contents_->IsOpaque()) ||
114  blend_mode_ == BlendMode::kSourceOver)) {
115  return false;
116  }
117  return contents_->CanInheritOpacity(*this);
118 }

References impeller::kSource, and impeller::kSourceOver.

Referenced by impeller::OpacityPeepholePassDelegate::CanCollapseIntoParentPass(), and SetInheritedOpacity().

◆ Clone()

Entity impeller::Entity::Clone ( ) const

◆ DeriveTextScale()

Scalar impeller::Entity::DeriveTextScale ( ) const

Definition at line 173 of file entity.cc.

173  {
175 }

References impeller::Matrix::GetMaxBasisLengthXY(), and GetTransform().

◆ FromSnapshot()

std::optional< Entity > impeller::Entity::FromSnapshot ( const std::optional< Snapshot > &  snapshot,
BlendMode  blend_mode = BlendMode::kSourceOver,
uint32_t  clip_depth = 0 
)
static

Create an entity that can be used to render a given snapshot.

Definition at line 21 of file entity.cc.

24  {
25  if (!snapshot.has_value()) {
26  return std::nullopt;
27  }
28 
29  auto texture_rect = Rect::MakeSize(snapshot->texture->GetSize());
30 
31  auto contents = TextureContents::MakeRect(texture_rect);
32  contents->SetTexture(snapshot->texture);
33  contents->SetSamplerDescriptor(snapshot->sampler_descriptor);
34  contents->SetSourceRect(texture_rect);
35  contents->SetOpacity(snapshot->opacity);
36 
37  Entity entity;
38  entity.SetBlendMode(blend_mode);
39  entity.SetClipDepth(clip_depth);
40  entity.SetTransform(snapshot->transform);
41  entity.SetContents(contents);
42  return entity;
43 }

References impeller::TextureContents::MakeRect(), impeller::TRect< Scalar >::MakeSize(), SetBlendMode(), SetClipDepth(), SetContents(), and SetTransform().

Referenced by impeller::AdvancedBlend(), and impeller::PipelineBlend().

◆ GetBlendMode()

BlendMode impeller::Entity::GetBlendMode ( ) const

◆ GetCapture()

Capture & impeller::Entity::GetCapture ( ) const

Definition at line 177 of file entity.cc.

177  {
178  return capture_;
179 }

Referenced by impeller::SolidColorContents::Render(), and impeller::TextureContents::Render().

◆ GetClipCoverage()

Contents::ClipCoverage impeller::Entity::GetClipCoverage ( const std::optional< Rect > &  current_clip_coverage) const

Definition at line 65 of file entity.cc.

66  {
67  if (!contents_) {
68  return {};
69  }
70  return contents_->GetClipCoverage(*this, current_clip_coverage);
71 }

◆ GetClipDepth()

◆ GetContents()

◆ GetCoverage()

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

Definition at line 57 of file entity.cc.

57  {
58  if (!contents_) {
59  return std::nullopt;
60  }
61 
62  return contents_->GetCoverage(*this);
63 }

Referenced by impeller::testing::TEST_P().

◆ GetTransform()

const Matrix & impeller::Entity::GetTransform ( ) const

Get the global transform matrix for this Entity.

Definition at line 49 of file entity.cc.

49  {
50  return transform_;
51 }

Referenced by impeller::SolidColorContents::AsBackgroundColor(), impeller::Geometry::ComputePositionGeometry(), impeller::Geometry::ComputePositionUVGeometry(), impeller::ComputeUVGeometryForRect(), DeriveTextScale(), impeller::ClipContents::GetClipCoverage(), impeller::SolidRRectBlurContents::GetCoverage(), impeller::VerticesContents::GetCoverage(), impeller::SolidColorContents::GetCoverage(), impeller::TextContents::GetCoverage(), impeller::TextureContents::GetCoverage(), impeller::AtlasContents::GetCoverage(), impeller::ColorSourceContents::GetCoverage(), impeller::AtlasTextureContents::GetCoverage(), impeller::FilterContents::GetCoverage(), impeller::AtlasColorContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterContentsFilterInput::GetLocalTransform(), impeller::VerticesGeometry::GetPositionBuffer(), impeller::VerticesGeometry::GetPositionColorBuffer(), impeller::VerticesGeometry::GetPositionUVBuffer(), impeller::FilterContentsFilterInput::GetTransform(), impeller::FilterInput::GetTransform(), impeller::SceneContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::AtlasContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), impeller::TextureContents::RenderToSnapshot(), and impeller::testing::TEST_P().

◆ IncrementStencilDepth()

void impeller::Entity::IncrementStencilDepth ( uint32_t  increment)

Definition at line 97 of file entity.cc.

97  {
98  clip_depth_ += increment;
99 }

◆ IsBlendModeDestructive()

bool impeller::Entity::IsBlendModeDestructive ( BlendMode  blend_mode)
static

Returns true if the blend mode is "destructive", meaning that even fully transparent source colors would result in the destination getting changed.

This is useful for determining if EntityPass textures can be shrinkwrapped to their Entities' coverage; they can be shrinkwrapped if all of the contained Entities have non-destructive blends.

Definition at line 142 of file entity.cc.

142  {
143  switch (blend_mode) {
144  case BlendMode::kClear:
145  case BlendMode::kSource:
151  case BlendMode::kXor:
153  return true;
154  default:
155  return false;
156  }
157 }

References impeller::kClear, impeller::kDestinationATop, impeller::kDestinationIn, impeller::kDestinationOut, impeller::kModulate, impeller::kSource, impeller::kSourceIn, impeller::kSourceOut, and impeller::kXor.

◆ Render()

bool impeller::Entity::Render ( const ContentContext renderer,
RenderPass parent_pass 
) const

Definition at line 159 of file entity.cc.

160  {
161  if (!contents_) {
162  return true;
163  }
164 
165  if (!contents_->GetCoverageHint().has_value()) {
166  contents_->SetCoverageHint(
167  Rect::MakeSize(parent_pass.GetRenderTargetSize()));
168  }
169 
170  return contents_->Render(renderer, *this, parent_pass);
171 }

References impeller::RenderPass::GetRenderTargetSize(), and impeller::TRect< Scalar >::MakeSize().

Referenced by impeller::EntityPlayground::OpenPlaygroundHere(), impeller::PipelineBlend(), and impeller::testing::TEST_P().

◆ SetBlendMode()

◆ SetCapture()

void impeller::Entity::SetCapture ( Capture  capture) const

Definition at line 185 of file entity.cc.

185  {
186  capture_ = std::move(capture);
187 }

◆ SetClipDepth()

◆ SetContents()

◆ SetInheritedOpacity()

bool impeller::Entity::SetInheritedOpacity ( Scalar  alpha)

Definition at line 120 of file entity.cc.

120  {
121  if (!CanInheritOpacity()) {
122  return false;
123  }
124  if (blend_mode_ == BlendMode::kSource && contents_->IsOpaque()) {
125  blend_mode_ = BlendMode::kSourceOver;
126  }
127  contents_->SetInheritedOpacity(alpha);
128  return true;
129 }

References CanInheritOpacity(), impeller::kSource, and impeller::kSourceOver.

◆ SetTransform()

◆ ShouldRender()

bool impeller::Entity::ShouldRender ( const std::optional< Rect > &  clip_coverage) const

Definition at line 73 of file entity.cc.

73  {
74 #ifdef IMPELLER_CONTENT_CULLING
75  return contents_->ShouldRender(*this, clip_coverage);
76 #else
77  return true;
78 #endif // IMPELLER_CONTENT_CULLING
79 }

Referenced by impeller::testing::TEST_P().

Member Data Documentation

◆ kLastAdvancedBlendMode

constexpr BlendMode impeller::Entity::kLastAdvancedBlendMode = BlendMode::kLuminosity
staticconstexpr

◆ kLastPipelineBlendMode


The documentation for this class was generated from the following files:
impeller::BlendMode::kDestinationATop
@ kDestinationATop
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:49
impeller::BlendMode::kSource
@ kSource
impeller::Entity::Entity
Entity()
impeller::BlendSelectValues::kDifference
@ kDifference
impeller::BlendMode::kModulate
@ kModulate
impeller::BlendMode::kSourceOut
@ kSourceOut
impeller::Entity::CanInheritOpacity
bool CanInheritOpacity() const
Definition: entity.cc:109
impeller::BlendMode::kClear
@ kClear
impeller::BlendMode::kDestinationIn
@ kDestinationIn
impeller::BlendMode::kDestinationOut
@ kDestinationOut
impeller::SamplerAddressMode::kMirror
@ kMirror
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:44
impeller::BlendMode::kSourceIn
@ kSourceIn
impeller::BlendMode::kXor
@ kXor
impeller::TextureContents::MakeRect
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
Definition: texture_contents.cc:27
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::Matrix::GetMaxBasisLengthXY
Scalar GetMaxBasisLengthXY() const
Definition: matrix.cc:205
impeller::SamplerAddressMode::kRepeat
@ kRepeat
impeller::SamplerAddressMode::kDecal
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...