#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 &&) | |
Entity & | operator= (Entity &&) |
const Matrix & | GetTransform () const |
Get the global transform matrix for this Entity. More... | |
Matrix | GetShaderTransform (const RenderPass &pass) const |
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::kSrcOver) |
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 |
Represents a renderable object within the Impeller scene.
An Entity combines graphical content (Contents
) with properties like transformation (Matrix
), blend mode (BlendMode
), and stencil clip depth. It serves as the primary unit for constructing and rendering scenes. Entities can be created directly or from Snapshot
objects.
|
strong |
|
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 33 of file entity.h.
|
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).
Definition at line 48 of file entity.h.
|
default |
Referenced by Clone().
|
default |
|
default |
Attempts to represent this entity as a solid background color.
This is an optimization. If the entity's contents can be represented as a solid color covering the entire target area, this method returns that color.
[in] | target_size | The size of the render target. |
std::nullopt
. Entity impeller::Entity::Clone | ( | ) | const |
Definition at line 158 of file entity.cc.
References Entity().
Referenced by impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::GetLocalCoverage(), and impeller::TextShadowCache::Lookup().
|
static |
Create an entity that can be used to render a given snapshot.
Definition at line 18 of file entity.cc.
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().
BlendMode impeller::Entity::GetBlendMode | ( | ) | const |
Definition at line 101 of file entity.cc.
Referenced by impeller::AdvancedBlend(), impeller::ColorSourceContents::DrawGeometry(), impeller::OptionsFromPassAndEntity(), impeller::PipelineBlend(), impeller::SolidRRectLikeBlurContents::Render(), impeller::Canvas::Restore(), and impeller::testing::TEST_P().
uint32_t impeller::Entity::GetClipDepth | ( | ) | const |
Gets the stencil clip depth level for this entity.
Definition at line 84 of file entity.cc.
Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::TextShadowCache::Lookup(), and impeller::FilterContents::Render().
const std::shared_ptr< Contents > & impeller::Entity::GetContents | ( | ) | const |
Definition at line 76 of file entity.cc.
Referenced by impeller::AdvancedBlend(), impeller::ContentsFilterInput::GetSnapshot(), impeller::PipelineBlend(), and impeller::Canvas::Restore().
std::optional< Rect > impeller::Entity::GetCoverage | ( | ) | const |
Calculates the axis-aligned bounding box covering this entity after its transformation is applied.
std::nullopt
if the entity has no contents. Definition at line 64 of file entity.cc.
Referenced by impeller::TextShadowCache::Lookup(), impeller::Canvas::Restore(), impeller::testing::TEST(), and impeller::testing::TEST_P().
Scalar impeller::Entity::GetShaderClipDepth | ( | ) | const |
Gets the shader-compatible depth value based on the entity's current clip depth level (clip_depth_
).
clip_depth_
. Definition at line 88 of file entity.cc.
Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::GetShaderClipDepth(), GetShaderTransform(), impeller::SolidRRectLikeBlurContents::Render(), and impeller::TextContents::Render().
|
static |
Converts an integer clip depth level into a floating-point depth value suitable for use in shaders.
The integer clip_depth
represents discrete layers used for stencil clipping. This function maps that integer to a depth value within the [0, 1) range for the depth buffer. Each increment in clip_depth
corresponds to a small step (kDepthEpsilon
) in the shader depth.
The result is clamped to ensure it stays within the valid depth range and slightly below 1.0 to avoid potential issues with the maximum depth value.
[in] | clip_depth | The integer clip depth level. |
Definition at line 92 of file entity.cc.
References kDepthEpsilon.
Matrix impeller::Entity::GetShaderTransform | ( | const RenderPass & | pass | ) | const |
Calculates the final transformation matrix for rendering in a shader.
This combines the entity's transform with the render pass's orthographic projection and applies the necessary adjustments based on the entity's shader clip depth.
[in] | pass | The current render pass. |
Definition at line 48 of file entity.cc.
References GetShaderClipDepth().
Referenced by impeller::Geometry::ComputePositionGeometry(), impeller::DlVerticesGeometry::GetPositionBuffer(), impeller::FillRectGeometry::GetPositionBuffer(), impeller::StrokeRectGeometry::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::AtlasContents::Render(), impeller::ColorFilterAtlasContents::Render(), impeller::SolidRRectLikeBlurContents::Render(), impeller::TextContents::Render(), and impeller::TextureContents::Render().
|
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.
References impeller::RenderPass::GetOrthographicTransform(), kDepthEpsilon, impeller::Matrix::MakeTranslateScale(), and transform.
const Matrix & impeller::Entity::GetTransform | ( | ) | const |
Get the global transform matrix for this Entity.
Definition at line 44 of file entity.cc.
Referenced by impeller::SolidColorContents::AsBackgroundColor(), impeller::AtlasContents::GetCoverage(), impeller::ColorFilterAtlasContents::GetCoverage(), impeller::ColorSourceContents::GetCoverage(), impeller::FilterContents::GetCoverage(), impeller::LineContents::GetCoverage(), impeller::SolidColorContents::GetCoverage(), impeller::SolidRRectLikeBlurContents::GetCoverage(), impeller::TextContents::GetCoverage(), impeller::TextureContents::GetCoverage(), impeller::VerticesSimpleBlendContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterContentsFilterInput::GetLocalTransform(), impeller::StrokeRectGeometry::GetPositionBuffer(), impeller::FilterInput::GetTransform(), impeller::FilterContentsFilterInput::GetTransform(), impeller::TextShadowCache::Lookup(), impeller::LineContents::Render(), impeller::SolidColorContents::Render(), impeller::SolidRRectLikeBlurContents::Render(), impeller::TextContents::Render(), impeller::TiledTextureContents::Render(), impeller::Contents::RenderToSnapshot(), impeller::TextureContents::RenderToSnapshot(), impeller::Canvas::Restore(), SetInheritedOpacity(), and impeller::testing::TEST_P().
|
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 127 of file entity.cc.
References impeller::kClear, impeller::kDstATop, impeller::kDstIn, impeller::kDstOut, impeller::kModulate, impeller::kSrc, impeller::kSrcIn, impeller::kSrcOut, and impeller::kXor.
Referenced by impeller::Canvas::SaveLayer().
bool impeller::Entity::Render | ( | const ContentContext & | renderer, |
RenderPass & | parent_pass | ||
) | const |
Definition at line 144 of file entity.cc.
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().
void impeller::Entity::SetBlendMode | ( | BlendMode | blend_mode | ) |
Definition at line 97 of file entity.cc.
Referenced by impeller::Canvas::DrawArc(), impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawDashedLine(), impeller::Canvas::DrawDiffRoundRect(), 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::DrawRoundSuperellipse(), 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().
void impeller::Entity::SetClipDepth | ( | uint32_t | clip_depth | ) |
Sets the stencil clip depth for this entity.
The clip depth determines the entity's level within a stack of stencil clips. Higher values indicate the entity is nested deeper within clips. This value is used during rendering to configure stencil buffer operations.
[in] | clip_depth | The integer clip depth level. |
Definition at line 80 of file entity.cc.
Referenced by impeller::Canvas::ClipGeometry(), impeller::Canvas::DrawTextFrame(), impeller::TextShadowCache::Lookup(), impeller::Canvas::Restore(), and impeller::Canvas::SaveLayer().
void impeller::Entity::SetContents | ( | std::shared_ptr< Contents > | contents | ) |
Definition at line 72 of file entity.cc.
Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawLine(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::PipelineBlend(), impeller::Canvas::Restore(), impeller::Canvas::SaveLayer(), and impeller::testing::TEST_P().
bool impeller::Entity::SetInheritedOpacity | ( | Scalar | alpha | ) |
Definition at line 105 of file entity.cc.
References GetTransform(), impeller::kSrc, and impeller::kSrcOver.
void impeller::Entity::SetTransform | ( | const Matrix & | transform | ) |
Set the global transform matrix for this Entity.
Definition at line 60 of file entity.cc.
References transform.
Referenced by impeller::Canvas::ClipGeometry(), impeller::Canvas::DrawArc(), impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawDashedLine(), impeller::Canvas::DrawDiffRoundRect(), 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::DrawRoundSuperellipse(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), FromSnapshot(), impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::GetLocalCoverage(), impeller::TextShadowCache::Lookup(), impeller::Contents::RenderToSnapshot(), impeller::Canvas::Restore(), impeller::Canvas::SaveLayer(), impeller::testing::TEST(), and impeller::testing::TEST_P().
|
staticconstexpr |
Definition at line 31 of file entity.h.
Referenced by GetShaderClipDepth(), and GetShaderTransform().
|
staticconstexpr |
Definition at line 29 of file entity.h.
Referenced by impeller::testing::GetBlendModeSelection(), impeller::ColorFilterContents::MakeBlend(), and impeller::BlendFilterContents::SetBlendMode().
|
staticconstexpr |
Definition at line 28 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().