Flutter Engine
The Flutter Engine
contents.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_CONTENTS_CONTENTS_H_
6#define FLUTTER_IMPELLER_ENTITY_CONTENTS_CONTENTS_H_
7
8#include <functional>
9#include <memory>
10
16
17namespace impeller {
18
19class ContentContext;
20struct ContentContextOptions;
21class Entity;
22class Surface;
23class RenderPass;
24class FilterContents;
25
26ContentContextOptions OptionsFromPass(const RenderPass& pass);
27
28ContentContextOptions OptionsFromPassAndEntity(const RenderPass& pass,
29 const Entity& entity);
30
31class Contents {
32 public:
33 /// A procedure that filters a given unpremultiplied color to produce a new
34 /// unpremultiplied color.
36
37 struct ClipCoverage {
38 enum class Type { kNoChange, kAppend, kRestore };
39
41 std::optional<Rect> coverage = std::nullopt;
42 };
43
45 const Entity& entity,
46 RenderPass& pass)>;
47 using CoverageProc = std::function<std::optional<Rect>(const Entity& entity)>;
48
49 static std::shared_ptr<Contents> MakeAnonymous(RenderProc render_proc,
50 CoverageProc coverage_proc);
51
53
54 virtual ~Contents();
55
56 /// @brief Add any text data to the specified lazy atlas. The scale parameter
57 /// must be used again later when drawing the text.
58 virtual void PopulateGlyphAtlas(
59 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
60 Scalar scale) {}
61
62 virtual bool Render(const ContentContext& renderer,
63 const Entity& entity,
64 RenderPass& pass) const = 0;
65
66 //----------------------------------------------------------------------------
67 /// @brief Get the area of the render pass that will be affected when this
68 /// contents is rendered.
69 ///
70 /// During rendering, coverage coordinates count pixels from the top
71 /// left corner of the framebuffer.
72 ///
73 /// @return The coverage rectangle. An `std::nullopt` result means that
74 /// rendering this contents has no effect on the output color.
75 ///
76 virtual std::optional<Rect> GetCoverage(const Entity& entity) const = 0;
77
78 //----------------------------------------------------------------------------
79 /// @brief Hint that specifies the coverage area of this Contents that will
80 /// actually be used during rendering. This is for optimization
81 /// purposes only and can not be relied on as a clip. May optionally
82 /// affect the result of `GetCoverage()`.
83 ///
84 void SetCoverageHint(std::optional<Rect> coverage_hint);
85
86 const std::optional<Rect>& GetCoverageHint() const;
87
88 //----------------------------------------------------------------------------
89 /// @brief Whether this Contents only emits opaque source colors from the
90 /// fragment stage. This value does not account for any entity
91 /// properties (e.g. the blend mode), clips/visibility culling, or
92 /// inherited opacity.
93 ///
94 virtual bool IsOpaque() const;
95
96 //----------------------------------------------------------------------------
97 /// @brief Given the current pass space bounding rectangle of the clip
98 /// buffer, return the expected clip coverage after this draw call.
99 /// This should only be implemented for contents that may write to the
100 /// clip buffer.
101 ///
102 /// During rendering, coverage coordinates count pixels from the top
103 /// left corner of the framebuffer.
104 ///
106 const Entity& entity,
107 const std::optional<Rect>& current_clip_coverage) const;
108
109 //----------------------------------------------------------------------------
110 /// @brief Render this contents to a snapshot, respecting the entity's
111 /// transform, path, clip depth, and blend mode.
112 /// The result texture size is always the size of
113 /// `GetCoverage(entity)`.
114 ///
115 virtual std::optional<Snapshot> RenderToSnapshot(
117 const Entity& entity,
118 std::optional<Rect> coverage_limit = std::nullopt,
119 const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
120 bool msaa_enabled = true,
121 int32_t mip_count = 1,
122 const std::string& label = "Snapshot") const;
123
124 virtual bool ShouldRender(const Entity& entity,
125 const std::optional<Rect> clip_coverage) const;
126
127 //----------------------------------------------------------------------------
128 /// @brief Return the color source's intrinsic size, if available.
129 ///
130 /// For example, a gradient has a size based on its end and beginning
131 /// points, ignoring any tiling. Solid colors and runtime effects have
132 /// no size.
133 ///
134 std::optional<Size> GetColorSourceSize() const;
135
137
138 //----------------------------------------------------------------------------
139 /// @brief Whether or not this contents can accept the opacity peephole
140 /// optimization.
141 ///
142 /// By default all contents return false. Contents are responsible
143 /// for determining whether or not their own geometries intersect in
144 /// a way that makes accepting opacity impossible. It is always safe
145 /// to return false, especially if computing overlap would be
146 /// computationally expensive.
147 ///
148 virtual bool CanInheritOpacity(const Entity& entity) const;
149
150 //----------------------------------------------------------------------------
151 /// @brief Inherit the provided opacity.
152 ///
153 /// Use of this method is invalid if CanAcceptOpacity returns false.
154 ///
155 virtual void SetInheritedOpacity(Scalar opacity);
156
157 //----------------------------------------------------------------------------
158 /// @brief Returns a color if this Contents will flood the given `target_size`
159 /// with a color. This output color is the "Source" color that will be
160 /// used for the Entity's blend operation.
161 ///
162 /// This is useful for absorbing full screen solid color draws into
163 /// subpass clear colors.
164 ///
165 virtual std::optional<Color> AsBackgroundColor(const Entity& entity,
166 ISize target_size) const;
167
168 //----------------------------------------------------------------------------
169 /// @brief Cast to a filter. Returns `nullptr` if this Contents is not a
170 /// filter.
171 ///
172 virtual const FilterContents* AsFilter() const;
173
174 //----------------------------------------------------------------------------
175 /// @brief If possible, applies a color filter to this contents inputs on
176 /// the CPU.
177 ///
178 /// This method will either fully apply the color filter or
179 /// perform no action. Partial/incorrect application of the color
180 /// filter will never occur.
181 ///
182 /// @param[in] color_filter_proc A function that filters a given
183 /// unpremultiplied color to produce a new
184 /// unpremultiplied color.
185 ///
186 /// @return True if the color filter was able to be fully applied to all
187 /// all relevant inputs. Otherwise, this operation is a no-op and
188 /// false is returned.
189 ///
190 [[nodiscard]] virtual bool ApplyColorFilter(
191 const ColorFilterProc& color_filter_proc);
192
193 private:
194 std::optional<Rect> coverage_hint_;
195 std::optional<Size> color_source_size_;
196
197 Contents(const Contents&) = delete;
198
199 Contents& operator=(const Contents&) = delete;
200};
201
202} // namespace impeller
203
204#endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_CONTENTS_H_
virtual bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
virtual bool CanInheritOpacity(const Entity &entity) const
Whether or not this contents can accept the opacity peephole optimization.
Definition: contents.cc:131
virtual std::optional< Color > AsBackgroundColor(const Entity &entity, ISize target_size) const
Returns a color if this Contents will flood the given target_size with a color. This output color is ...
Definition: contents.cc:140
virtual std::optional< Rect > GetCoverage(const Entity &entity) const =0
Get the area of the render pass that will be affected when this contents is rendered.
std::optional< Size > GetColorSourceSize() const
Return the color source's intrinsic size, if available.
Definition: contents.cc:177
virtual void PopulateGlyphAtlas(const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
Add any text data to the specified lazy atlas. The scale parameter must be used again later when draw...
Definition: contents.h:58
virtual bool ApplyColorFilter(const ColorFilterProc &color_filter_proc)
If possible, applies a color filter to this contents inputs on the CPU.
Definition: contents.cc:149
const std::optional< Rect > & GetCoverageHint() const
Definition: contents.cc:173
virtual std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &label="Snapshot") const
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
Definition: contents.cc:63
virtual ClipCoverage GetClipCoverage(const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage...
Definition: contents.cc:56
void SetColorSourceSize(Size size)
Definition: contents.cc:181
virtual bool IsOpaque() const
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
Definition: contents.cc:52
virtual bool ShouldRender(const Entity &entity, const std::optional< Rect > clip_coverage) const
Definition: contents.cc:154
std::function< std::optional< Rect >(const Entity &entity)> CoverageProc
Definition: contents.h:47
virtual void SetInheritedOpacity(Scalar opacity)
Inherit the provided opacity.
Definition: contents.cc:135
static std::shared_ptr< Contents > MakeAnonymous(RenderProc render_proc, CoverageProc coverage_proc)
Definition: contents.cc:41
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
void SetCoverageHint(std::optional< Rect > coverage_hint)
Hint that specifies the coverage area of this Contents that will actually be used during rendering....
Definition: contents.cc:169
virtual const FilterContents * AsFilter() const
Cast to a filter. Returns nullptr if this Contents is not a filter.
Definition: contents.cc:145
std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)> RenderProc
Definition: contents.h:46
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
Dart_NativeFunction function
Definition: fuchsia.cc:51
SK_API sk_sp< SkShader > Color(SkColor)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
float Scalar
Definition: scalar.h:18
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
const Scalar scale
std::optional< Rect > coverage
Definition: contents.h:41