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 #ifndef FLUTTER_IMPELLER_ENTITY_ENTITY_H_
6 #define FLUTTER_IMPELLER_ENTITY_ENTITY_H_
7 
8 #include <cstdint>
9 
10 #include "impeller/core/capture.h"
14 #include "impeller/geometry/rect.h"
15 
16 namespace impeller {
17 
18 class Renderer;
19 class RenderPass;
20 
21 class Entity {
22  public:
25 
26  enum class RenderingMode {
27  /// In direct mode, the Entity's transform is used as the current
28  /// local-to-screen transform 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 transform 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 {
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 clip_depth = 0);
69 
70  Entity();
71 
72  ~Entity();
73 
74  Entity(Entity&&) = default;
75 
76  /// @brief Get the global transform matrix for this Entity.
77  const Matrix& GetTransform() const;
78 
79  /// @brief Set the global transform matrix for this Entity.
80  void SetTransform(const Matrix& transform);
81 
82  std::optional<Rect> GetCoverage() const;
83 
85  const std::optional<Rect>& current_clip_coverage) const;
86 
87  bool ShouldRender(const std::optional<Rect>& clip_coverage) const;
88 
89  void SetContents(std::shared_ptr<Contents> contents);
90 
91  const std::shared_ptr<Contents>& GetContents() const;
92 
93  void SetClipDepth(uint32_t clip_depth);
94 
95  void IncrementStencilDepth(uint32_t increment);
96 
97  uint32_t GetClipDepth() const;
98 
99  void SetBlendMode(BlendMode blend_mode);
100 
101  BlendMode GetBlendMode() const;
102 
103  bool Render(const ContentContext& renderer, RenderPass& parent_pass) const;
104 
105  static bool IsBlendModeDestructive(BlendMode blend_mode);
106 
107  bool CanInheritOpacity() const;
108 
109  bool SetInheritedOpacity(Scalar alpha);
110 
111  std::optional<Color> AsBackgroundColor(ISize target_size) const;
112 
113  Scalar DeriveTextScale() const;
114 
115  Capture& GetCapture() const;
116 
117  void SetCapture(Capture capture) const;
118 
119  Entity Clone() const;
120 
121  private:
122  Entity(const Entity&) = default;
123 
124  Matrix transform_;
125  std::shared_ptr<Contents> contents_;
126  BlendMode blend_mode_ = BlendMode::kSourceOver;
127  uint32_t clip_depth_ = 0u;
128  mutable Capture capture_;
129 };
130 
131 } // namespace impeller
132 
133 #endif // FLUTTER_IMPELLER_ENTITY_ENTITY_H_
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
impeller::Entity::SetClipDepth
void SetClipDepth(uint32_t clip_depth)
Definition: entity.cc:89
impeller::Entity::TileMode::kClamp
@ kClamp
impeller::Entity::kLastPipelineBlendMode
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:23
impeller::Capture
Definition: capture.h:231
capture.h
contents.h
impeller::Entity::ClipOperation::kDifference
@ kDifference
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Entity::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: entity.cc:101
impeller::Entity::GetCapture
Capture & GetCapture() const
Definition: entity.cc:177
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:49
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::BlendMode::kLuminosity
@ kLuminosity
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:142
impeller::Entity::IncrementStencilDepth
void IncrementStencilDepth(uint32_t increment)
Definition: entity.cc:97
impeller::Entity::~Entity
~Entity()
impeller::Entity::Entity
Entity()
impeller::Entity::TileMode::kRepeat
@ kRepeat
impeller::BlendMode::kModulate
@ kModulate
impeller::Entity::SetCapture
void SetCapture(Capture capture) const
Definition: entity.cc:185
impeller::Entity::TileMode::kMirror
@ kMirror
impeller::Entity::SetContents
void SetContents(std::shared_ptr< Contents > contents)
Definition: entity.cc:81
impeller::Entity::CanInheritOpacity
bool CanInheritOpacity() const
Definition: entity.cc:109
matrix.h
impeller::Entity
Definition: entity.h:21
impeller::TSize< int64_t >
impeller::Entity::ShouldRender
bool ShouldRender(const std::optional< Rect > &clip_coverage) const
Definition: entity.cc:73
impeller::Entity::Render
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition: entity.cc:159
impeller::Entity::SetInheritedOpacity
bool SetInheritedOpacity(Scalar alpha)
Definition: entity.cc:120
impeller::Entity::kLastAdvancedBlendMode
static constexpr BlendMode kLastAdvancedBlendMode
Definition: entity.h:24
impeller::Entity::GetContents
const std::shared_ptr< Contents > & GetContents() const
Definition: entity.cc:85
impeller::Entity::RenderingMode::kDirect
@ kDirect
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::Entity::RenderingMode::kSubpass
@ kSubpass
impeller::Entity::GetBlendMode
BlendMode GetBlendMode() const
Definition: entity.cc:105
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
impeller::Entity::GetClipDepth
uint32_t GetClipDepth() const
Definition: entity.cc:93
impeller::Entity::AsBackgroundColor
std::optional< Color > AsBackgroundColor(ISize target_size) const
Definition: entity.cc:131
impeller::Entity::GetCoverage
std::optional< Rect > GetCoverage() const
Definition: entity.cc:57
impeller::Entity::SetTransform
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
Definition: entity.cc:53
rect.h
impeller::Entity::Clone
Entity Clone() const
Definition: entity.cc:181
impeller::Contents::ClipCoverage
Definition: contents.h:40
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:59
color.h
impeller::Entity::GetClipCoverage
Contents::ClipCoverage GetClipCoverage(const std::optional< Rect > &current_clip_coverage) const
Definition: entity.cc:65
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:26
impeller::Entity::DeriveTextScale
Scalar DeriveTextScale() 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 clip_depth=0)
Create an entity that can be used to render a given snapshot.
Definition: entity.cc:21
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::BlendMode::kSourceOver
@ kSourceOver