| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
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 Matrix & | GetTransform () 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< Rect > | GetCoverage () 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< Color > | AsBackgroundColor (ISize target_size) const
Scalar | DeriveTextScale () const
Capture & | GetCapture () const
void | SetCapture (Capture capture) const
Entity | Clone () const

## Static Public Member Functions
static std::optional< Entity > | FromSnapshot (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

enum impeller::Entity::ClipOperation
| strong

Enumerator
kDifference |
kIntersect |

Definition at line 59 of file entity.h.

59 {
60 kDifference,
61 kIntersect,
62 };

## ◆ RenderingMode

enum impeller::Entity::RenderingMode
| strong

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

enum impeller::Entity::TileMode
| strong

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

Definition at line 181 of file entity.cc.

181 {
182 return Entity(*this);
183 }

References Entity().

Referenced by impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::GetLocalCoverage(), and impeller::testing::TEST_P().

## ◆ DeriveTextScale()

Scalar impeller::Entity::DeriveTextScale | ( |  | ) | const

Definition at line 173 of file entity.cc.

173 {
174 return GetTransform().GetMaxBasisLengthXY();
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

Definition at line 105 of file entity.cc.

105 {
106 return blend_mode_;
107 }

Referenced by impeller::EntityPass::AddEntity(), impeller::AdvancedBlend(), impeller::OptionsFromPassAndEntity(), impeller::PipelineBlend(), impeller::SolidRRectBlurContents::Render(), and impeller::testing::TEST_P().

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

uint32_t impeller::Entity::GetClipDepth | ( |  | ) | const

Definition at line 93 of file entity.cc.

93 {
94 return clip_depth_;
95 }

Referenced by impeller::AdvancedBlend(), impeller::PipelineBlend(), impeller::RuntimeEffectContents::Render(), impeller::TiledTextureContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::SolidColorContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::VerticesColorContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::VerticesUVContents::Render(), impeller::AtlasTextureContents::Render(), and impeller::AtlasColorContents::Render().

## ◆ GetContents()

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

Definition at line 85 of file entity.cc.

85 {
86 return contents_;
87 }

Referenced by impeller::EntityPass::AddEntity(), impeller::AdvancedBlend(), impeller::OpacityPeepholePassDelegate::CanCollapseIntoParentPass(), impeller::testing::GetCoverageOfFirstEntity(), impeller::ContentsFilterInput::GetSnapshot(), impeller::PipelineBlend(), and impeller::testing::TEST_P().

## ◆ 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:
146 case BlendMode::kSourceIn:
147 case BlendMode::kDestinationIn:
148 case BlendMode::kSourceOut:
149 case BlendMode::kDestinationOut:
150 case BlendMode::kDestinationATop:
151 case BlendMode::kXor:
152 case BlendMode::kModulate:
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()

void impeller::Entity::SetBlendMode | ( | BlendMode | blend_mode | ) |

Definition at line 101 of file entity.cc.

101 {
102 blend_mode_ = blend_mode;
103 }

Referenced by impeller::EntityPass::AddEntity(), impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawLine(), impeller::Canvas::DrawOval(), impeller::Canvas::DrawPaint(), impeller::Canvas::DrawPath(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::DlImageImpeller::MakeFromYUVTextures(), impeller::PipelineBlend(), and impeller::testing::TEST_P().

## ◆ SetCapture()

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

Definition at line 185 of file entity.cc.

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

## ◆ SetClipDepth()

void impeller::Entity::SetClipDepth | ( | uint32_t | clip_depth | ) |

Definition at line 89 of file entity.cc.

89 {
90 clip_depth_ = depth;
91 }

Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawLine(), impeller::Canvas::DrawOval(), impeller::Canvas::DrawPaint(), impeller::Canvas::DrawPath(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), and FromSnapshot().

## ◆ SetContents()

void impeller::Entity::SetContents | ( | std::shared_ptr< Contents > | contents | ) |

Definition at line 81 of file entity.cc.

81 {
82 contents_ = std::move(contents);
83 }

Referenced by impeller::testing::CreatePassWithRectPath(), impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawLine(), impeller::Canvas::DrawOval(), impeller::Canvas::DrawPaint(), impeller::Canvas::DrawPath(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::PipelineBlend(), and impeller::testing::TEST_P().

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

void impeller::Entity::SetTransform | ( | const Matrix & | transform | ) |

Set the global transform matrix for this Entity.

Definition at line 53 of file entity.cc.

53 {
54 transform_ = transform;
55 }

Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawLine(), impeller::Canvas::DrawOval(), impeller::Canvas::DrawPaint(), impeller::Canvas::DrawPath(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::FilterContents::GetCoverage(), impeller::EntityPass::GetElementsCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::GetLocalCoverage(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ 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
| static constexpr

Definition at line 24 of file entity.h.

Referenced by impeller::testing::GetBlendModeSelection(), impeller::ColorFilterContents::MakeBlend(), and impeller::BlendFilterContents::SetBlendMode().

## ◆ kLastPipelineBlendMode

constexpr BlendMode impeller::Entity::kLastPipelineBlendMode = BlendMode::kModulate
| static constexpr

Definition at line 23 of file entity.h.

Referenced by impeller::EntityPass::AddEntity(), impeller::EntityPass::AddSubpass(), impeller::ContentContextOptions::ApplyToPipelineDescriptor(), impeller::ColorFilterContents::MakeBlend(), impeller::BlendFilterContents::SetBlendMode(), and impeller::testing::TEST_P().

The documentation for this class was generated from the following files:

- impeller/entity/entity.h
- impeller/entity/entity.cc

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...