| 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::kSubpassAppendSnapshotTransform, RenderingMode::kSubpassPrependSnapshotTransform }
enum | TileMode { TileMode::kClamp, TileMode::kRepeat, TileMode::kMirror, TileMode::kDecal }
enum | ClipOperation { ClipOperation::kDifference, ClipOperation::kIntersect }

## Public Member Functions
| Entity ()
| ~Entity ()
| Entity (Entity &&)
Entity & | operator= (Entity &&)
const Matrix & | GetTransform () const
| Get the global transform matrix for this Entity. More...
Matrix | GetShaderTransform (const RenderPass &pass) const
| Get the vertex shader transform used for drawing this Entity. More...
void | SetTransform (const Matrix &transform)
| Set the global transform matrix for this Entity. More...
std::optional< Rect > | GetCoverage () const
void | SetContents (std::shared_ptr< Contents > contents)
const std::shared_ptr< Contents > & | GetContents () const
void | SetClipDepth (uint32_t clip_depth)
uint32_t | GetClipDepth () const
float | GetShaderClipDepth () const
void | SetBlendMode (BlendMode blend_mode)
BlendMode | GetBlendMode () const
bool | Render (const ContentContext &renderer, RenderPass &parent_pass) const
bool | SetInheritedOpacity (Scalar alpha)
std::optional< Color > | AsBackgroundColor (ISize target_size) const
Entity | Clone () const

## Static Public Member Functions
static Entity | FromSnapshot (const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSourceOver)
| Create an entity that can be used to render a given snapshot. More...
static Matrix | GetShaderTransform (Scalar clip_depth, const RenderPass &pass, const Matrix &transform)
| Static utility that computes the vertex shader transform used for drawing an Entity with a given the clip depth and RenderPass size. More...
static float | GetShaderClipDepth (uint32_t clip_depth)
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
static constexpr Scalar | kDepthEpsilon = 1.0f / 262144.0

## Detailed Description

Definition at line 20 of file entity.h.

## Member Enumeration Documentation

## ◆ ClipOperation

enum impeller::Entity::ClipOperation
| strong

Enumerator
kDifference |
kIntersect |

Definition at line 61 of file entity.h.

61 {
62 kDifference,
63 kIntersect,
64 };

## ◆ 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.
kSubpassAppendSnapshotTransform | 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.
kSubpassPrependSnapshotTransform |

Definition at line 27 of file entity.h.

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

## ◆ 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 42 of file entity.h.

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

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

117 {
118 return contents_->AsBackgroundColor(*this, target_size);
119 }

## ◆ Clone()

Entity impeller::Entity::Clone | ( |  | ) | const

Definition at line 159 of file entity.cc.

159 {
160 return Entity(*this);
161 }

References Entity().

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

## ◆ FromSnapshot()

Entity impeller::Entity::FromSnapshot | ( | const Snapshot & | snapshot,
|  | BlendMode | blend_mode = `BlendMode::kSourceOver`
| ) |  |
| static

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

Definition at line 18 of file entity.cc.

18 {
19 auto texture_rect = Rect::MakeSize(snapshot.texture->GetSize());
20
21 auto contents = TextureContents::MakeRect(texture_rect);
22 contents->SetTexture(snapshot.texture);
23 contents->SetSamplerDescriptor(snapshot.sampler_descriptor);
24 contents->SetSourceRect(texture_rect);
25 contents->SetOpacity(snapshot.opacity);
26
27 Entity entity;
28 entity.SetBlendMode(blend_mode);
29 entity.SetTransform(snapshot.transform);
30 entity.SetContents(contents);
31 return entity;
32 }

References impeller::TextureContents::MakeRect(), impeller::TRect< Scalar >::MakeSize(), impeller::Snapshot::opacity, impeller::Snapshot::sampler_descriptor, SetBlendMode(), SetContents(), SetTransform(), impeller::Snapshot::texture, and impeller::Snapshot::transform.

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::AdvancedBlend(), impeller::ColorSourceContents::DrawGeometry(), impeller::OptionsFromPassAndEntity(), impeller::PipelineBlend(), impeller::SolidRRectBlurContents::Render(), impeller::Canvas::Restore(), and impeller::testing::TEST_P().

## ◆ GetClipDepth()

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

Definition at line 84 of file entity.cc.

84 {
85 return clip_depth_;
86 }

Referenced by impeller::ColorSourceContents::DrawGeometry(), and impeller::FilterContents::Render().

## ◆ GetContents()

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

Definition at line 76 of file entity.cc.

76 {
77 return contents_;
78 }

Referenced by impeller::AdvancedBlend(), impeller::ContentsFilterInput::GetSnapshot(), impeller::PipelineBlend(), and impeller::Canvas::Restore().

## ◆ GetCoverage()

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

Definition at line 64 of file entity.cc.

64 {
65 if (!contents_) {
66 return std::nullopt;
67 }
68
69 return contents_->GetCoverage(*this);
70 }

Referenced by impeller::Canvas::Restore(), and impeller::testing::TEST_P().

## ◆ GetShaderClipDepth() [1/2]

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

Definition at line 88 of file entity.cc.

88 {
89 return Entity::GetShaderClipDepth(clip_depth_);
90 }

Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::GetShaderClipDepth(), GetShaderTransform(), impeller::SolidRRectBlurContents::Render(), and impeller::TextContents::Render().

## ◆ GetShaderClipDepth() [2/2]

Scalar impeller::Entity::GetShaderClipDepth | ( | uint32_t | clip_depth | ) |
| static

Definition at line 92 of file entity.cc.

92 {
93 Scalar result = std::clamp(clip_depth * kDepthEpsilon, 0.0f, 1.0f);
94 return std::min(result, 1.0f - kDepthEpsilon);
95 }

References kDepthEpsilon.

## ◆ GetShaderTransform() [1/2]

Matrix impeller::Entity::GetShaderTransform | ( | const RenderPass & | pass | ) | const

Get the vertex shader transform used for drawing this Entity.

Definition at line 48 of file entity.cc.

48 {
49 return Entity::GetShaderTransform(GetShaderClipDepth(), pass, transform_);
50 }

References GetShaderClipDepth().

Referenced by impeller::Geometry::ComputePositionGeometry(), impeller::RectGeometry::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::SolidRRectBlurContents::Render(), impeller::AtlasContents::Render(), impeller::TextContents::Render(), and impeller::TextureContents::Render().

## ◆ GetShaderTransform() [2/2]

Matrix impeller::Entity::GetShaderTransform | ( | Scalar | clip_depth,
|  | const RenderPass & | pass,
|  | const Matrix & | transform
| ) |  |
| static

Static utility that computes the vertex shader transform used for drawing an Entity with a given the clip depth and RenderPass size.

Definition at line 52 of file entity.cc.

54 {
55 return Matrix::MakeTranslateScale({1, 1, Entity::kDepthEpsilon},
56 {0, 0, shader_clip_depth}) *
57 pass.GetOrthographicTransform() * transform;
58 }

References impeller::RenderPass::GetOrthographicTransform(), kDepthEpsilon, impeller::Matrix::MakeTranslateScale(), and transform.

## ◆ GetTransform()

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

Get the global transform matrix for this Entity.

Definition at line 44 of file entity.cc.

44 {
45 return transform_;
46 }

Referenced by impeller::SolidColorContents::AsBackgroundColor(), impeller::SolidColorContents::GetCoverage(), impeller::SolidRRectBlurContents::GetCoverage(), impeller::VerticesSimpleBlendContents::GetCoverage(), impeller::AtlasContents::GetCoverage(), impeller::TextureContents::GetCoverage(), impeller::TextContents::GetCoverage(), impeller::ColorSourceContents::GetCoverage(), impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterContentsFilterInput::GetLocalTransform(), impeller::FilterContentsFilterInput::GetTransform(), impeller::FilterInput::GetTransform(), impeller::TiledTextureContents::Render(), impeller::SolidColorContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::RenderToSnapshot(), impeller::Contents::RenderToSnapshot(), impeller::Canvas::Restore(), SetInheritedOpacity(), and impeller::testing::TEST_P().

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

128 {
129 switch (blend_mode) {
130 case BlendMode::kClear:
131 case BlendMode::kSource:
132 case BlendMode::kSourceIn:
133 case BlendMode::kDestinationIn:
134 case BlendMode::kSourceOut:
135 case BlendMode::kDestinationOut:
136 case BlendMode::kDestinationATop:
137 case BlendMode::kXor:
138 case BlendMode::kModulate:
139 return true;
140 default:
141 return false;
142 }
143 }

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

Referenced by impeller::Canvas::SaveLayer().

## ◆ operator=()

Entity & impeller::Entity::operator= | ( | Entity && |  | ) |
| default

## ◆ Render()

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

Definition at line 145 of file entity.cc.

146 {
147 if (!contents_) {
148 return true;
149 }
150
151 if (!contents_->GetCoverageHint().has_value()) {
152 contents_->SetCoverageHint(
153 Rect::MakeSize(parent_pass.GetRenderTargetSize()));
154 }
155
156 return contents_->Render(renderer, *this, parent_pass);
157 }

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

Referenced by impeller::EntityPlayground::OpenPlaygroundHere(), impeller::PipelineBlend(), impeller::Canvas::Restore(), impeller::Canvas::SaveLayer(), 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::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::DrawRoundRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::DlImageImpeller::MakeFromYUVTextures(), impeller::PipelineBlend(), impeller::Contents::RenderToSnapshot(), impeller::Canvas::Restore(), impeller::Canvas::SaveLayer(), and impeller::testing::TEST_P().

## ◆ SetClipDepth()

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

Definition at line 80 of file entity.cc.

80 {
81 clip_depth_ = clip_depth;
82 }

Referenced by impeller::Canvas::ClipGeometry(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::Restore(), and impeller::Canvas::SaveLayer().

## ◆ SetContents()

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

Definition at line 72 of file entity.cc.

72 {
73 contents_ = std::move(contents);
74 }

Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::PipelineBlend(), impeller::Canvas::Restore(), impeller::Canvas::SaveLayer(), and impeller::testing::TEST_P().

## ◆ SetInheritedOpacity()

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

Definition at line 105 of file entity.cc.

105 {
106 if (alpha >= 1.0) {
107 return true;
108 }
109 if (blend_mode_ == BlendMode::kSource &&
110 contents_->IsOpaque(GetTransform())) {
111 blend_mode_ = BlendMode::kSourceOver;
112 }
113 contents_->SetInheritedOpacity(alpha);
114 return true;
115 }

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

## ◆ SetTransform()

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

Set the global transform matrix for this Entity.

Definition at line 60 of file entity.cc.

60 {
61 transform_ = transform;
62 }

References transform.

Referenced by impeller::Canvas::ClipGeometry(), 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::DrawRoundRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::GetLocalCoverage(), impeller::Contents::RenderToSnapshot(), impeller::Canvas::Restore(), impeller::Canvas::SaveLayer(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## Member Data Documentation

## ◆ kDepthEpsilon

constexpr Scalar impeller::Entity::kDepthEpsilon = 1.0f / 262144.0
| static constexpr

Definition at line 25 of file entity.h.

Referenced by GetShaderClipDepth(), and GetShaderTransform().

## ◆ kLastAdvancedBlendMode

constexpr BlendMode impeller::Entity::kLastAdvancedBlendMode = BlendMode::kLuminosity
| static constexpr

Definition at line 23 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 22 of file entity.h.

Referenced by impeller::ContentContextOptions::ApplyToPipelineDescriptor(), impeller::ColorFilterContents::MakeBlend(), impeller::VerticesSimpleBlendContents::Render(), impeller::RequiresReadbackForBlends(), impeller::Canvas::Restore(), 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::Entity::GetShaderTransform
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:48
impeller::BlendMode::kDestinationATop
@ kDestinationATop
impeller::Entity::GetShaderClipDepth
float GetShaderClipDepth() const
Definition: entity.cc:88
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::SamplerAddressMode::kDecal
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
impeller::Entity::kDepthEpsilon
static constexpr Scalar kDepthEpsilon
Definition: entity.h:25
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
impeller::SamplerAddressMode::kMirror
@ kMirror
impeller::Matrix::MakeTranslateScale
static constexpr Matrix MakeTranslateScale(const Vector3 &s, const Vector3 &t)
Definition: matrix.h:113
impeller::BlendMode::kSource
@ kSource
impeller::Entity::Entity
Entity()
impeller::BlendSelectValues::kDifference
@ kDifference
impeller::BlendMode::kModulate
@ kModulate
impeller::BlendMode::kSourceOut
@ kSourceOut
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller::BlendMode::kClear
@ kClear
impeller::SamplerAddressMode::kRepeat
@ kRepeat
impeller::BlendMode::kDestinationIn
@ kDestinationIn
impeller::BlendMode::kDestinationOut
@ kDestinationOut
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
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:28
impeller::BlendMode::kSourceOver
@ kSourceOver