| Flutter Impeller |

entity.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #pragma once
6
7 #include <variant>
8 #include "impeller/core/capture.h"
9 #include "impeller/entity/contents/contents.h"
10 #include "impeller/geometry/color.h"
11 #include "impeller/geometry/matrix.h"
12 #include "impeller/geometry/path.h"
13 #include "impeller/geometry/rect.h"
14 #include "impeller/image/decompressed_image.h"
15
16 namespace impeller {
17
18 class Renderer;
19 class RenderPass;
20
21 class Entity {
22 public:
23 static constexpr BlendMode kLastPipelineBlendMode = BlendMode::kModulate;
24 static constexpr BlendMode kLastAdvancedBlendMode = BlendMode::kLuminosity;
25
26 enum class RenderingMode {
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 };
36
37 /// An enum to define how to repeat, fold, or omit colors outside of the
38 /// typically defined range of the source of the colors (such as the
39 /// bounds of an image or the defining geometry of a gradient).
40 enum class TileMode {
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 };
58
59 enum class ClipOperation {
60 kDifference,
61 kIntersect,
62 };
63
64 /// @brief Create an entity that can be used to render a given snapshot.
65 static std::optional<Entity> FromSnapshot(
66 const std::optional<Snapshot>& snapshot,
67 BlendMode blend_mode = BlendMode::kSourceOver,
68 uint32_t stencil_depth = 0);
69
70 Entity();
71
72 ~Entity();
73
74 const Matrix& GetTransformation() const;
75
76 void SetTransformation(const Matrix& transformation);
77
78 std::optional<Rect> GetCoverage() const;
79
80 Contents::StencilCoverage GetStencilCoverage(
81 const std::optional<Rect>& current_stencil_coverage) const;
82
83 bool ShouldRender(const std::optional<Rect>& stencil_coverage) const;
84
85 void SetContents(std::shared_ptr<Contents> contents);
86
87 const std::shared_ptr<Contents>& GetContents() const;
88
89 void SetStencilDepth(uint32_t stencil_depth);
90
91 void IncrementStencilDepth(uint32_t increment);
92
93 uint32_t GetStencilDepth() const;
94
95 void SetBlendMode(BlendMode blend_mode);
96
97 BlendMode GetBlendMode() const;
98
99 bool Render(const ContentContext& renderer, RenderPass& parent_pass) const;
100
101 static bool IsBlendModeDestructive(BlendMode blend_mode);
102
103 bool CanInheritOpacity() const;
104
105 bool SetInheritedOpacity(Scalar alpha);
106
107 std::optional<Color> AsBackgroundColor(ISize target_size) const;
108
109 Scalar DeriveTextScale() const;
110
111 Capture& GetCapture() const;
112
113 void SetCapture(Capture capture) const;
114
115 private:
116 Matrix transformation_;
117 std::shared_ptr<Contents> contents_;
118 BlendMode blend_mode_ = BlendMode::kSourceOver;
119 uint32_t stencil_depth_ = 0u;
120 mutable Capture capture_;
121 };
122
123 } // namespace impeller
impeller::BlendMode
BlendMode
Definition: color.h:57
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
path.h
impeller::Entity::TileMode::kClamp
@ kClamp
impeller::Entity::SetTransformation
void SetTransformation(const Matrix &transformation)
Definition: entity.cc:53
impeller::Entity::kLastPipelineBlendMode
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:23
impeller::Capture
Definition: capture.h:226
capture.h
contents.h
impeller::Entity::GetStencilDepth
uint32_t GetStencilDepth() const
Definition: entity.cc:89
impeller::Entity::ClipOperation::kDifference
@ kDifference
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::Entity::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: entity.cc:97
impeller::Entity::GetCapture
Capture & GetCapture() const
Definition: entity.cc:173
impeller::Entity::FromSnapshot
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.
Definition: entity.cc:21
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::Entity::IsBlendModeDestructive
static bool IsBlendModeDestructive(BlendMode blend_mode)
Returns true if the blend mode is "destructive", meaning that even fully transparent source colors wo...
Definition: entity.cc:138
impeller::Entity::IncrementStencilDepth
void IncrementStencilDepth(uint32_t increment)
Definition: entity.cc:93
impeller::Entity::~Entity
~Entity()
impeller::Entity::Entity
Entity()
impeller::Entity::TileMode::kRepeat
@ kRepeat
impeller::BlendMode::kLuminosity
@ kLuminosity
impeller::Entity::SetCapture
void SetCapture(Capture capture) const
Definition: entity.cc:177
impeller::Entity::GetTransformation
const Matrix & GetTransformation() const
Definition: entity.cc:49
impeller::Entity::TileMode::kMirror
@ kMirror
impeller::Entity::SetContents
void SetContents(std::shared_ptr< Contents > contents)
Definition: entity.cc:77
impeller::Entity::CanInheritOpacity
bool CanInheritOpacity() const
Definition: entity.cc:105
matrix.h
impeller::Entity
Definition: entity.h:21
impeller::TSize
Definition: size.h:18
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::Contents::StencilCoverage
Definition: contents.h:39
impeller::Entity::Render
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition: entity.cc:155
impeller::Entity::SetInheritedOpacity
bool SetInheritedOpacity(Scalar alpha)
Definition: entity.cc:116
impeller::Entity::kLastAdvancedBlendMode
static constexpr BlendMode kLastAdvancedBlendMode
Definition: entity.h:24
impeller::Entity::GetContents
const std::shared_ptr< Contents > & GetContents() const
Definition: entity.cc:81
impeller::Entity::RenderingMode::kDirect
@ kDirect
impeller::Entity::GetStencilCoverage
Contents::StencilCoverage GetStencilCoverage(const std::optional< Rect > &current_stencil_coverage) const
Definition: entity.cc:65
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::Entity::RenderingMode::kSubpass
@ kSubpass
impeller::Entity::GetBlendMode
BlendMode GetBlendMode() const
Definition: entity.cc:101
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
decompressed_image.h
impeller::Entity::AsBackgroundColor
std::optional< Color > AsBackgroundColor(ISize target_size) const
Definition: entity.cc:127
impeller::Entity::GetCoverage
std::optional< Rect > GetCoverage() const
Definition: entity.cc:57
rect.h
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:59
color.h
impeller::Entity::SetStencilDepth
void SetStencilDepth(uint32_t stencil_depth)
Definition: entity.cc:85
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:26
impeller::BlendMode::kModulate
@ kModulate
impeller::Entity::DeriveTextScale
Scalar DeriveTextScale() const
Definition: entity.cc:169
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:344
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:36
impeller::Entity::ShouldRender
bool ShouldRender(const std::optional< Rect > &stencil_coverage) const
Definition: entity.cc:73