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 ()
 
const MatrixGetTransformation () const
 
void SetTransformation (const Matrix &transformation)
 
std::optional< RectGetCoverage () const
 
Contents::StencilCoverage GetStencilCoverage (const std::optional< Rect > &current_stencil_coverage) const
 
bool ShouldRender (const std::optional< Rect > &stencil_coverage) const
 
void SetContents (std::shared_ptr< Contents > contents)
 
const std::shared_ptr< Contents > & GetContents () const
 
void SetStencilDepth (uint32_t stencil_depth)
 
void IncrementStencilDepth (uint32_t increment)
 
uint32_t GetStencilDepth () 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
 

Static Public Member Functions

static std::optional< EntityFromSnapshot (const std::optional< Snapshot > &snapshot, BlendMode blend_mode=BlendMode::kSourceOver, uint32_t stencil_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 transformation 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 transformation 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 transformation 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 transformation 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()

impeller::Entity::Entity ( )
default

◆ ~Entity()

impeller::Entity::~Entity ( )
default

Member Function Documentation

◆ AsBackgroundColor()

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

Definition at line 127 of file entity.cc.

127  {
128  return contents_->AsBackgroundColor(*this, target_size);
129 }

◆ CanInheritOpacity()

bool impeller::Entity::CanInheritOpacity ( ) const

Definition at line 105 of file entity.cc.

105  {
106  if (!contents_) {
107  return false;
108  }
109  if (!((blend_mode_ == BlendMode::kSource && contents_->IsOpaque()) ||
110  blend_mode_ == BlendMode::kSourceOver)) {
111  return false;
112  }
113  return contents_->CanInheritOpacity(*this);
114 }

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

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

◆ DeriveTextScale()

Scalar impeller::Entity::DeriveTextScale ( ) const

Definition at line 169 of file entity.cc.

169  {
171 }

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

◆ FromSnapshot()

std::optional< Entity > impeller::Entity::FromSnapshot ( const std::optional< Snapshot > &  snapshot,
BlendMode  blend_mode = BlendMode::kSourceOver,
uint32_t  stencil_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.SetStencilDepth(stencil_depth);
40  entity.SetTransformation(snapshot->transform);
41  entity.SetContents(contents);
42  return entity;
43 }

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

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

◆ GetBlendMode()

BlendMode impeller::Entity::GetBlendMode ( ) const

◆ GetCapture()

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

Definition at line 173 of file entity.cc.

173  {
174  return capture_;
175 }

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

◆ GetContents()

const std::shared_ptr< Contents > & impeller::Entity::GetContents ( ) const

◆ 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().

◆ GetStencilCoverage()

Contents::StencilCoverage impeller::Entity::GetStencilCoverage ( const std::optional< Rect > &  current_stencil_coverage) const

Definition at line 65 of file entity.cc.

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

◆ GetStencilDepth()

◆ GetTransformation()

◆ IncrementStencilDepth()

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

Definition at line 93 of file entity.cc.

93  {
94  stencil_depth_ += increment;
95 }

◆ 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 138 of file entity.cc.

138  {
139  switch (blend_mode) {
140  case BlendMode::kClear:
141  case BlendMode::kSource:
147  case BlendMode::kXor:
149  return true;
150  default:
151  return false;
152  }
153 }

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 155 of file entity.cc.

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

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 177 of file entity.cc.

177  {
178  capture_ = std::move(capture);
179 }

◆ SetContents()

◆ SetInheritedOpacity()

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

Definition at line 116 of file entity.cc.

116  {
117  if (!CanInheritOpacity()) {
118  return false;
119  }
120  if (blend_mode_ == BlendMode::kSource && contents_->IsOpaque()) {
121  blend_mode_ = BlendMode::kSourceOver;
122  }
123  contents_->SetInheritedOpacity(alpha);
124  return true;
125 }

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

◆ SetStencilDepth()

◆ SetTransformation()

◆ ShouldRender()

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

Definition at line 73 of file entity.cc.

73  {
74  return contents_->ShouldRender(*this, stencil_coverage);
75 }

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::kSourceIn
@ kSourceIn
impeller::Entity::Entity
Entity()
impeller::BlendMode::kDestinationIn
@ kDestinationIn
impeller::BlendMode::kXor
@ kXor
impeller::Entity::GetTransformation
const Matrix & GetTransformation() const
Definition: entity.cc:49
impeller::Entity::CanInheritOpacity
bool CanInheritOpacity() const
Definition: entity.cc:105
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::BlendMode::kDestinationATop
@ kDestinationATop
impeller::BlendMode::kDestinationOut
@ kDestinationOut
impeller::BlendMode::kDifference
@ kDifference
impeller::SamplerAddressMode::kMirror
@ kMirror
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:52
impeller::BlendMode::kClear
@ kClear
impeller::BlendMode::kModulate
@ kModulate
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:28
impeller::BlendMode::kSourceOut
@ kSourceOut
impeller::BlendMode::kSource
@ kSource
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...