Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
15
16namespace impeller {
17
18class Renderer;
19class RenderPass;
20
21class Entity {
22 public:
25
26 static constexpr Scalar kDepthEpsilon = 1.0f / 262144.0;
27
28 enum class RenderingMode {
29 /// In direct mode, the Entity's transform is used as the current
30 /// local-to-screen transform matrix.
31 kDirect,
32 /// In subpass mode, the Entity passed through the filter is in screen space
33 /// rather than local space, and so some filters (namely,
34 /// MatrixFilterContents) need to interpret the given EffectTransform as the
35 /// current transform matrix.
37 };
38
39 /// An enum to define how to repeat, fold, or omit colors outside of the
40 /// typically defined range of the source of the colors (such as the
41 /// bounds of an image or the defining geometry of a gradient).
42 enum class TileMode {
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 };
60
61 enum class ClipOperation {
64 };
65
66 /// @brief Create an entity that can be used to render a given snapshot.
67 static Entity FromSnapshot(const Snapshot& snapshot,
69
71
73
75
76 /// @brief Get the global transform matrix for this Entity.
77 const Matrix& GetTransform() const;
78
79 /// @brief Get the vertex shader transform used for drawing this Entity.
80 Matrix GetShaderTransform(const RenderPass& pass) const;
81
82 /// @brief Static utility that computes the vertex shader transform used for
83 /// drawing an Entity with a given the clip depth and RenderPass size.
84 static Matrix GetShaderTransform(Scalar clip_depth,
85 const RenderPass& pass,
86 const Matrix& transform);
87
88 /// @brief Set the global transform matrix for this Entity.
89 void SetTransform(const Matrix& transform);
90
91 std::optional<Rect> GetCoverage() const;
92
94 const std::optional<Rect>& current_clip_coverage) const;
95
96 bool ShouldRender(const std::optional<Rect>& clip_coverage) const;
97
98 void SetContents(std::shared_ptr<Contents> contents);
99
100 const std::shared_ptr<Contents>& GetContents() const;
101
102 void SetClipDepth(uint32_t clip_depth);
103
104 uint32_t GetClipDepth() const;
105
106 float GetShaderClipDepth() const;
107
108 static float GetShaderClipDepth(uint32_t clip_depth);
109
110 void SetBlendMode(BlendMode blend_mode);
111
112 BlendMode GetBlendMode() const;
113
114 bool Render(const ContentContext& renderer, RenderPass& parent_pass) const;
115
116 static bool IsBlendModeDestructive(BlendMode blend_mode);
117
118 bool CanInheritOpacity() const;
119
120 bool SetInheritedOpacity(Scalar alpha);
121
122 std::optional<Color> AsBackgroundColor(ISize target_size) const;
123
124 Scalar DeriveTextScale() const;
125
126 Capture& GetCapture() const;
127
128 void SetCapture(Capture capture) const;
129
130 Entity Clone() const;
131
132 private:
133 Entity(const Entity&);
134
135 Matrix transform_;
136 std::shared_ptr<Contents> contents_;
137 BlendMode blend_mode_ = BlendMode::kSourceOver;
138 uint32_t clip_depth_ = 1u;
139 mutable Capture capture_;
140};
141
142} // namespace impeller
143
144#endif // FLUTTER_IMPELLER_ENTITY_ENTITY_H_
void SetCapture(Capture capture) const
Definition entity.cc:199
bool CanInheritOpacity() const
Definition entity.cc:123
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
Definition entity.cc:62
static Entity FromSnapshot(const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSourceOver)
Create an entity that can be used to render a given snapshot.
Definition entity.cc:22
Entity(Entity &&)
std::optional< Rect > GetCoverage() const
Definition entity.cc:66
bool SetInheritedOpacity(Scalar alpha)
Definition entity.cc:134
const std::shared_ptr< Contents > & GetContents() const
Definition entity.cc:94
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition entity.cc:50
void SetClipDepth(uint32_t clip_depth)
Definition entity.cc:98
BlendMode GetBlendMode() const
Definition entity.cc:119
void SetContents(std::shared_ptr< Contents > contents)
Definition entity.cc:90
void SetBlendMode(BlendMode blend_mode)
Definition entity.cc:115
static constexpr BlendMode kLastAdvancedBlendMode
Definition entity.h:24
static constexpr Scalar kDepthEpsilon
Definition entity.h:26
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition entity.cc:173
Scalar DeriveTextScale() const
Definition entity.cc:187
Entity Clone() const
Definition entity.cc:195
std::optional< Color > AsBackgroundColor(ISize target_size) const
Definition entity.cc:145
Capture & GetCapture() const
Definition entity.cc:191
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
static constexpr BlendMode kLastPipelineBlendMode
Definition entity.h:23
uint32_t GetClipDepth() const
Definition entity.cc:102
bool ShouldRender(const std::optional< Rect > &clip_coverage) const
Definition entity.cc:82
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:156
Contents::ClipCoverage GetClipCoverage(const std::optional< Rect > &current_clip_coverage) const
Definition entity.cc:74
float GetShaderClipDepth() const
Definition entity.cc:106
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:33
float Scalar
Definition scalar.h:18
BlendMode
Definition color.h:59
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
A 4x4 matrix using column-major storage.
Definition matrix.h:37
Represents a texture and its intended draw transform/sampler configuration.
Definition snapshot.h:24