Flutter Engine
The Flutter Engine
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 class  RenderingMode { kDirect , kSubpassAppendSnapshotTransform , kSubpassPrependSnapshotTransform }
 
enum class  TileMode { kClamp , kRepeat , kMirror , kDecal }
 
enum class  ClipOperation { kDifference , kIntersect }
 

Public Member Functions

 Entity ()
 
 ~Entity ()
 
 Entity (Entity &&)
 
const MatrixGetTransform () 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< RectGetCoverage () 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)
 
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 CanInheritOpacity () const
 
bool SetInheritedOpacity (Scalar alpha)
 
std::optional< ColorAsBackgroundColor (ISize target_size) const
 
Scalar DeriveTextScale () 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

Enumerator
kDifference 
kIntersect 

Definition at line 61 of file entity.h.

61 {
64 };
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver

◆ RenderingMode

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

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

145 {
146 return contents_->AsBackgroundColor(*this, target_size);
147}

◆ CanInheritOpacity()

bool impeller::Entity::CanInheritOpacity ( ) const

Definition at line 123 of file entity.cc.

123 {
124 if (!contents_) {
125 return false;
126 }
127 if (!((blend_mode_ == BlendMode::kSource && contents_->IsOpaque()) ||
128 blend_mode_ == BlendMode::kSourceOver)) {
129 return false;
130 }
131 return contents_->CanInheritOpacity(*this);
132}

◆ Clone()

Entity impeller::Entity::Clone ( ) const

Definition at line 191 of file entity.cc.

191 {
192 return Entity(*this);
193}

◆ DeriveTextScale()

Scalar impeller::Entity::DeriveTextScale ( ) const

Definition at line 187 of file entity.cc.

187 {
189}
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
constexpr Scalar GetMaxBasisLengthXY() const
Definition: matrix.h:300

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

22 {
23 auto texture_rect = Rect::MakeSize(snapshot.texture->GetSize());
24
25 auto contents = TextureContents::MakeRect(texture_rect);
26 contents->SetTexture(snapshot.texture);
27 contents->SetSamplerDescriptor(snapshot.sampler_descriptor);
28 contents->SetSourceRect(texture_rect);
29 contents->SetOpacity(snapshot.opacity);
30
31 Entity entity;
32 entity.SetBlendMode(blend_mode);
33 entity.SetTransform(snapshot.transform);
34 entity.SetContents(contents);
35 return entity;
36}
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
static constexpr TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146

◆ GetBlendMode()

BlendMode impeller::Entity::GetBlendMode ( ) const

Definition at line 119 of file entity.cc.

119 {
120 return blend_mode_;
121}

◆ GetClipCoverage()

Contents::ClipCoverage impeller::Entity::GetClipCoverage ( const std::optional< Rect > &  current_clip_coverage) const

Definition at line 74 of file entity.cc.

75 {
76 if (!contents_) {
77 return {};
78 }
79 return contents_->GetClipCoverage(*this, current_clip_coverage);
80}

◆ GetClipDepth()

uint32_t impeller::Entity::GetClipDepth ( ) const

Definition at line 102 of file entity.cc.

102 {
103 return clip_depth_;
104}

◆ GetContents()

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

Definition at line 94 of file entity.cc.

94 {
95 return contents_;
96}

◆ GetCoverage()

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

Definition at line 66 of file entity.cc.

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

◆ GetShaderClipDepth() [1/2]

Scalar impeller::Entity::GetShaderClipDepth ( ) const

Definition at line 106 of file entity.cc.

106 {
107 return Entity::GetShaderClipDepth(clip_depth_);
108}
float GetShaderClipDepth() const
Definition: entity.cc:106

◆ GetShaderClipDepth() [2/2]

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

Definition at line 110 of file entity.cc.

110 {
111 Scalar result = std::clamp(clip_depth * kDepthEpsilon, 0.0f, 1.0f);
112 return std::min(result, 1.0f - kDepthEpsilon);
113}
static unsigned clamp(SkFixed fx, int max)
static constexpr Scalar kDepthEpsilon
Definition: entity.h:25
GAsyncResult * result
static float min(float r, float g, float b)
Definition: hsl.cpp:48
float Scalar
Definition: scalar.h:18

◆ GetShaderTransform() [1/2]

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

Get the vertex shader transform used for drawing this Entity.

Definition at line 50 of file entity.cc.

50 {
51 return Entity::GetShaderTransform(GetShaderClipDepth(), pass, transform_);
52}
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:50

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

56 {
57 return Matrix::MakeTranslation({0, 0, shader_clip_depth}) *
59 pass.GetOrthographicTransform() * transform;
60}
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104

◆ GetTransform()

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

Get the global transform matrix for this Entity.

Definition at line 46 of file entity.cc.

46 {
47 return transform_;
48}

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

156 {
157 switch (blend_mode) {
165 case BlendMode::kXor:
167 return true;
168 default:
169 return false;
170 }
171}

◆ Render()

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

Definition at line 173 of file entity.cc.

174 {
175 if (!contents_) {
176 return true;
177 }
178
179 if (!contents_->GetCoverageHint().has_value()) {
180 contents_->SetCoverageHint(
181 Rect::MakeSize(parent_pass.GetRenderTargetSize()));
182 }
183
184 return contents_->Render(renderer, *this, parent_pass);
185}

◆ SetBlendMode()

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

Definition at line 115 of file entity.cc.

115 {
116 blend_mode_ = blend_mode;
117}

◆ SetClipDepth()

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

Definition at line 98 of file entity.cc.

98 {
99 clip_depth_ = clip_depth;
100}

◆ SetContents()

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

Definition at line 90 of file entity.cc.

90 {
91 contents_ = std::move(contents);
92}

◆ SetInheritedOpacity()

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

Definition at line 134 of file entity.cc.

134 {
135 if (!CanInheritOpacity()) {
136 return false;
137 }
138 if (blend_mode_ == BlendMode::kSource && contents_->IsOpaque()) {
139 blend_mode_ = BlendMode::kSourceOver;
140 }
141 contents_->SetInheritedOpacity(alpha);
142 return true;
143}
bool CanInheritOpacity() const
Definition: entity.cc:123

◆ SetTransform()

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

Set the global transform matrix for this Entity.

Definition at line 62 of file entity.cc.

62 {
63 transform_ = transform;
64}

◆ ShouldRender()

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

Definition at line 82 of file entity.cc.

82 {
83#ifdef IMPELLER_CONTENT_CULLING
84 return contents_->ShouldRender(*this, clip_coverage);
85#else
86 return true;
87#endif // IMPELLER_CONTENT_CULLING
88}

Member Data Documentation

◆ kDepthEpsilon

constexpr Scalar impeller::Entity::kDepthEpsilon = 1.0f / 262144.0
staticconstexpr

Definition at line 25 of file entity.h.

◆ kLastAdvancedBlendMode

constexpr BlendMode impeller::Entity::kLastAdvancedBlendMode = BlendMode::kLuminosity
staticconstexpr

Definition at line 23 of file entity.h.

◆ kLastPipelineBlendMode

constexpr BlendMode impeller::Entity::kLastPipelineBlendMode = BlendMode::kModulate
staticconstexpr

Definition at line 22 of file entity.h.


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