| 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 ()
const Matrix & | GetTransformation () const
void | SetTransformation (const Matrix &transformation)
std::optional< Rect > | GetCoverage () 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< Color > | AsBackgroundColor (ISize target_size) const
Scalar | DeriveTextScale () const
Capture & | GetCapture () const
void | SetCapture (Capture capture) const

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

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

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

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

## ◆ DeriveTextScale()

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

Definition at line 173 of file entity.cc.

173 {
174 return GetTransformation().GetMaxBasisLengthXY();
175 }

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

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

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

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

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

Definition at line 93 of file entity.cc.

93 {
94 return stencil_depth_;
95 }

Referenced by impeller::AdvancedBlend(), impeller::PipelineBlend(), impeller::RuntimeEffectContents::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().

## ◆ GetTransformation()

const Matrix & impeller::Entity::GetTransformation | ( |  | ) | const

Definition at line 49 of file entity.cc.

49 {
50 return transformation_;
51 }

Referenced by impeller::SolidColorContents::AsBackgroundColor(), impeller::ComputeUVGeometryForRect(), DeriveTextScale(), 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::ClipContents::GetStencilCoverage(), 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::TiledTextureContents::RenderToSnapshot(), 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 stencil_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::DrawImageRect(), 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 181 of file entity.cc.

181 {
182 capture_ = std::move(capture);
183 }

## ◆ 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::DrawImageRect(), 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.

## ◆ SetStencilDepth()

void impeller::Entity::SetStencilDepth | ( | uint32_t | stencil_depth | ) |

Definition at line 89 of file entity.cc.

89 {
90 stencil_depth_ = depth;
91 }

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

## ◆ SetTransformation()

void impeller::Entity::SetTransformation | ( | const Matrix & | transformation | ) |

Definition at line 53 of file entity.cc.

53 {
54 transformation_ = transformation;
55 }

Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawImageRect(), 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 > & | stencil_coverage | ) | const

Definition at line 73 of file entity.cc.

73 {
74 #ifdef IMPELLER_CONTENT_CULLING
75 return contents_->ShouldRender(*this, stencil_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::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::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:109
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...