| 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 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 {
170 return GetTransformation().GetMaxBasisLengthXY();
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

Definition at line 101 of file entity.cc.

101 {
102 return blend_mode_;
103 }

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

Definition at line 81 of file entity.cc.

81 {
82 return contents_;
83 }

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

89 {
90 return stencil_depth_;
91 }

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 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:
142 case BlendMode::kSourceIn:
143 case BlendMode::kDestinationIn:
144 case BlendMode::kSourceOut:
145 case BlendMode::kDestinationOut:
146 case BlendMode::kDestinationATop:
147 case BlendMode::kXor:
148 case BlendMode::kModulate:
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()

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

Definition at line 97 of file entity.cc.

97 {
98 blend_mode_ = blend_mode;
99 }

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

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

## ◆ SetContents()

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

Definition at line 77 of file entity.cc.

77 {
78 contents_ = std::move(contents);
79 }

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

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

Definition at line 85 of file entity.cc.

85 {
86 stencil_depth_ = depth;
87 }

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 return contents_->ShouldRender(*this, stencil_coverage);
75 }

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