Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Enumerations
display_list.h File Reference
#include <memory>
#include <optional>
#include "flutter/display_list/dl_sampling_options.h"
#include "flutter/display_list/geometry/dl_rtree.h"
#include "flutter/fml/logging.h"

Go to the source code of this file.

Classes

class  flutter::SaveLayerOptions
 
class  flutter::DisplayListStorage
 
class  flutter::DisplayList
 

Namespaces

namespace  flutter
 

Macros

#define FOR_EACH_DISPLAY_LIST_OP(V)
 
#define DL_OP_TO_ENUM_VALUE(name)   k##name,
 

Enumerations

enum class  flutter::DisplayListOpType
 

Macro Definition Documentation

◆ DL_OP_TO_ENUM_VALUE

#define DL_OP_TO_ENUM_VALUE (   name)    k##name,

Definition at line 141 of file display_list.h.

◆ FOR_EACH_DISPLAY_LIST_OP

#define FOR_EACH_DISPLAY_LIST_OP (   V)

Definition at line 57 of file display_list.h.

141 {
143#ifdef IMPELLER_ENABLE_3D
144 DL_OP_TO_ENUM_VALUE(SetSceneColorSource)
145#endif // IMPELLER_ENABLE_3D
146};
147#undef DL_OP_TO_ENUM_VALUE
148
149class DlOpReceiver;
150class DisplayListBuilder;
151
152class SaveLayerOptions {
153 public:
154 static const SaveLayerOptions kWithAttributes;
155 static const SaveLayerOptions kNoAttributes;
156
157 SaveLayerOptions() : flags_(0) {}
158 SaveLayerOptions(const SaveLayerOptions& options) : flags_(options.flags_) {}
159 explicit SaveLayerOptions(const SaveLayerOptions* options)
160 : flags_(options->flags_) {}
161
162 SaveLayerOptions without_optimizations() const {
163 SaveLayerOptions options;
164 options.fRendersWithAttributes = fRendersWithAttributes;
165 options.fBoundsFromCaller = fBoundsFromCaller;
166 return options;
167 }
168
169 bool renders_with_attributes() const { return fRendersWithAttributes; }
170 SaveLayerOptions with_renders_with_attributes() const {
171 SaveLayerOptions options(this);
172 options.fRendersWithAttributes = true;
173 return options;
174 }
175
176 bool can_distribute_opacity() const { return fCanDistributeOpacity; }
177 SaveLayerOptions with_can_distribute_opacity() const {
178 SaveLayerOptions options(this);
179 options.fCanDistributeOpacity = true;
180 return options;
181 }
182
183 // Returns true iff the bounds for the saveLayer operation were provided
184 // by the caller, otherwise the bounds will have been computed by the
185 // DisplayListBuilder and provided for reference.
186 bool bounds_from_caller() const { return fBoundsFromCaller; }
187 SaveLayerOptions with_bounds_from_caller() const {
188 SaveLayerOptions options(this);
189 options.fBoundsFromCaller = true;
190 return options;
191 }
192 SaveLayerOptions without_bounds_from_caller() const {
193 SaveLayerOptions options(this);
194 options.fBoundsFromCaller = false;
195 return options;
196 }
197 bool bounds_were_calculated() const { return !fBoundsFromCaller; }
198
199 // Returns true iff the bounds for the saveLayer do not fully cover the
200 // contained rendering operations. This will only occur if the original
201 // caller supplied bounds and those bounds were not a strict superset
202 // of the content bounds computed by the DisplayListBuilder.
203 bool content_is_clipped() const { return fContentIsClipped; }
204 SaveLayerOptions with_content_is_clipped() const {
205 SaveLayerOptions options(this);
206 options.fContentIsClipped = true;
207 return options;
208 }
209
210 SaveLayerOptions& operator=(const SaveLayerOptions& other) {
211 flags_ = other.flags_;
212 return *this;
213 }
214 bool operator==(const SaveLayerOptions& other) const {
215 return flags_ == other.flags_;
216 }
217 bool operator!=(const SaveLayerOptions& other) const {
218 return flags_ != other.flags_;
219 }
220
221 private:
222 union {
223 struct {
224 unsigned fRendersWithAttributes : 1;
225 unsigned fCanDistributeOpacity : 1;
226 unsigned fBoundsFromCaller : 1;
227 unsigned fContentIsClipped : 1;
228 };
229 uint32_t flags_;
230 };
231};
232
233// Manages a buffer allocated with malloc.
234class DisplayListStorage {
235 public:
236 DisplayListStorage() = default;
237 DisplayListStorage(DisplayListStorage&&) = default;
238
239 uint8_t* get() const { return ptr_.get(); }
240
241 void realloc(size_t count) {
242 ptr_.reset(static_cast<uint8_t*>(std::realloc(ptr_.release(), count)));
243 FML_CHECK(ptr_);
244 }
245
246 private:
247 struct FreeDeleter {
248 void operator()(uint8_t* p) { std::free(p); }
249 };
250 std::unique_ptr<uint8_t, FreeDeleter> ptr_;
251};
252
253class Culler;
254
255// The base class that contains a sequence of rendering operations
256// for dispatch to a DlOpReceiver. These objects must be instantiated
257// through an instance of DisplayListBuilder::build().
258class DisplayList : public SkRefCnt {
259 public:
260 DisplayList();
261
262 ~DisplayList();
263
264 void Dispatch(DlOpReceiver& ctx) const;
265 void Dispatch(DlOpReceiver& ctx, const SkRect& cull_rect) const;
266 void Dispatch(DlOpReceiver& ctx, const SkIRect& cull_rect) const;
267
268 // From historical behavior, SkPicture always included nested bytes,
269 // but nested ops are only included if requested. The defaults used
270 // here for these accessors follow that pattern.
271 size_t bytes(bool nested = true) const {
272 return sizeof(DisplayList) + byte_count_ +
273 (nested ? nested_byte_count_ : 0);
274 }
275
276 uint32_t op_count(bool nested = false) const {
277 return op_count_ + (nested ? nested_op_count_ : 0);
278 }
279
280 uint32_t total_depth() const { return total_depth_; }
281
282 uint32_t unique_id() const { return unique_id_; }
283
284 const SkRect& bounds() const { return bounds_; }
285
286 bool has_rtree() const { return rtree_ != nullptr; }
287 sk_sp<const DlRTree> rtree() const { return rtree_; }
288
289 bool Equals(const DisplayList* other) const;
290 bool Equals(const DisplayList& other) const { return Equals(&other); }
291 bool Equals(const sk_sp<const DisplayList>& other) const {
292 return Equals(other.get());
293 }
294
295 bool can_apply_group_opacity() const { return can_apply_group_opacity_; }
296 bool isUIThreadSafe() const { return is_ui_thread_safe_; }
297
298 /// @brief Indicates if there are any rendering operations in this
299 /// DisplayList that will modify a surface of transparent black
300 /// pixels.
301 ///
302 /// This condition can be used to determine whether to create a cleared
303 /// surface, render a DisplayList into it, and then composite the
304 /// result into a scene. It is not uncommon for code in the engine to
305 /// come across such degenerate DisplayList objects when slicing up a
306 /// frame between platform views.
307 bool modifies_transparent_black() const {
308 return modifies_transparent_black_;
309 }
310
311 private:
312 DisplayList(DisplayListStorage&& ptr,
313 size_t byte_count,
314 uint32_t op_count,
315 size_t nested_byte_count,
316 uint32_t nested_op_count,
317 uint32_t total_depth,
318 const SkRect& bounds,
319 bool can_apply_group_opacity,
320 bool is_ui_thread_safe,
321 bool modifies_transparent_black,
323
324 static uint32_t next_unique_id();
325
326 static void DisposeOps(uint8_t* ptr, uint8_t* end);
327
328 const DisplayListStorage storage_;
329 const size_t byte_count_;
330 const uint32_t op_count_;
331
332 const size_t nested_byte_count_;
333 const uint32_t nested_op_count_;
334
335 const uint32_t total_depth_;
336
337 const uint32_t unique_id_;
338 const SkRect bounds_;
339
340 const bool can_apply_group_opacity_;
341 const bool is_ui_thread_safe_;
342 const bool modifies_transparent_black_;
343
344 const sk_sp<const DlRTree> rtree_;
345
346 void Dispatch(DlOpReceiver& ctx,
347 uint8_t* ptr,
348 uint8_t* end,
349 Culler& culler) const;
350
351 friend class DisplayListBuilder;
352};
353
354} // namespace flutter
355
356#endif // FLUTTER_DISPLAY_LIST_DISPLAY_LIST_H_
const char * options
int count
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
Definition SkRefCnt.h:355
bool Equals(const SkPath &a, const SkPath &b)
T * get() const
Definition SkRefCnt.h:303
#define FOR_EACH_DISPLAY_LIST_OP(V)
#define DL_OP_TO_ENUM_VALUE(name)
bool operator==(const FlutterPoint &a, const FlutterPoint &b)
glong glong end
#define FML_CHECK(condition)
Definition logging.h:85
Optional< SkRect > bounds
Definition SkRecords.h:189
void * realloc(void *ptr, size_t size)
Definition allocation.cc:27