Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::LayerTree Class Reference

#include <layer_tree.h>

Public Member Functions

 LayerTree (const std::shared_ptr< Layer > &root_layer, const SkISize &frame_size)
 
bool Preroll (CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false, SkRect cull_rect=kGiantRect)
 
void Paint (CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false) const
 
sk_sp< DisplayListFlatten (const SkRect &bounds, const std::shared_ptr< TextureRegistry > &texture_registry=nullptr, GrDirectContext *gr_context=nullptr)
 
Layerroot_layer () const
 
const SkISizeframe_size () const
 
const PaintRegionMappaint_region_map () const
 
PaintRegionMappaint_region_map ()
 
void enable_leaf_layer_tracing (bool enable)
 
bool is_leaf_layer_tracing_enabled () const
 

Static Public Member Functions

static void TryToRasterCache (const std::vector< RasterCacheItem * > &raster_cached_entries, const PaintContext *paint_context, bool ignore_raster_cache=false)
 

Detailed Description

Definition at line 22 of file layer_tree.h.

Constructor & Destructor Documentation

◆ LayerTree()

flutter::LayerTree::LayerTree ( const std::shared_ptr< Layer > &  root_layer,
const SkISize frame_size 
)

Definition at line 21 of file layer_tree.cc.

23 : root_layer_(root_layer), frame_size_(frame_size) {}
Layer * root_layer() const
Definition: layer_tree.h:53
const SkISize & frame_size() const
Definition: layer_tree.h:54

Member Function Documentation

◆ enable_leaf_layer_tracing()

void flutter::LayerTree::enable_leaf_layer_tracing ( bool  enable)
inline

When Paint is called, if leaf layer tracing is enabled, additional metadata around rasterization of leaf layers is collected.

This is not supported in the Impeller backend.

See: LayerSnapshotStore

Definition at line 65 of file layer_tree.h.

65 {
66 enable_leaf_layer_tracing_ = enable;
67 }

◆ Flatten()

sk_sp< DisplayList > flutter::LayerTree::Flatten ( const SkRect bounds,
const std::shared_ptr< TextureRegistry > &  texture_registry = nullptr,
GrDirectContext gr_context = nullptr 
)

Definition at line 157 of file layer_tree.cc.

160 {
161 TRACE_EVENT0("flutter", "LayerTree::Flatten");
162
163 DisplayListBuilder builder(bounds);
164
165 const FixedRefreshRateStopwatch unused_stopwatch;
166
167 LayerStateStack preroll_state_stack;
168 // No root surface transformation. So assume identity.
169 preroll_state_stack.set_preroll_delegate(bounds);
170 PrerollContext preroll_context{
171 // clang-format off
172#if !SLIMPELLER
173 .raster_cache = nullptr,
174#endif // !SLIMPELLER
175 .gr_context = gr_context,
176 .view_embedder = nullptr,
177 .state_stack = preroll_state_stack,
178 .dst_color_space = nullptr,
179 .surface_needs_readback = false,
180 .raster_time = unused_stopwatch,
181 .ui_time = unused_stopwatch,
182 .texture_registry = texture_registry,
183 // clang-format on
184 };
185
186 LayerStateStack paint_state_stack;
187 paint_state_stack.set_delegate(&builder);
188 PaintContext paint_context = {
189 // clang-format off
190 .state_stack = paint_state_stack,
191 .canvas = &builder,
192 .gr_context = gr_context,
193 .dst_color_space = nullptr,
194 .view_embedder = nullptr,
195 .raster_time = unused_stopwatch,
196 .ui_time = unused_stopwatch,
197 .texture_registry = texture_registry,
198#if !SLIMPELLER
199 .raster_cache = nullptr,
200#endif // !SLIMPELLER
201 .layer_snapshot_store = nullptr,
202 .enable_leaf_layer_tracing = false,
203 // clang-format on
204 };
205
206 // Even if we don't have a root layer, we still need to create an empty
207 // picture.
208 if (root_layer_) {
209 root_layer_->Preroll(&preroll_context);
210
211 // The needs painting flag may be set after the preroll. So check it after.
212 if (root_layer_->needs_painting(paint_context)) {
213 root_layer_->Paint(paint_context);
214 }
215 }
216
217 return builder.Build();
218}
Optional< SkRect > bounds
Definition: SkRecords.h:189
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ frame_size()

const SkISize & flutter::LayerTree::frame_size ( ) const
inline

Definition at line 54 of file layer_tree.h.

54{ return frame_size_; }

◆ is_leaf_layer_tracing_enabled()

bool flutter::LayerTree::is_leaf_layer_tracing_enabled ( ) const
inline

Definition at line 69 of file layer_tree.h.

69 {
70 return enable_leaf_layer_tracing_;
71 }

◆ Paint()

void flutter::LayerTree::Paint ( CompositorContext::ScopedFrame frame,
bool  ignore_raster_cache = false 
) const

Definition at line 97 of file layer_tree.cc.

98 {
99 TRACE_EVENT0("flutter", "LayerTree::Paint");
100
101 if (!root_layer_) {
102 FML_LOG(ERROR) << "The scene did not specify any layers to paint.";
103 return;
104 }
105
106 LayerStateStack state_stack;
107
108 DlCanvas* canvas = frame.canvas();
109 state_stack.set_delegate(canvas);
110
111 // clear the previous snapshots.
112 LayerSnapshotStore* snapshot_store = nullptr;
113 if (enable_leaf_layer_tracing_) {
114 frame.context().snapshot_store().Clear();
115 snapshot_store = &frame.context().snapshot_store();
116 }
117
118 SkColorSpace* color_space = GetColorSpace(frame.canvas());
119
120#if !SLIMPELLER
121 RasterCache* cache =
122 ignore_raster_cache ? nullptr : &frame.context().raster_cache();
123#endif // !SLIMPELLER
124
125 PaintContext context = {
126 // clang-format off
127 .state_stack = state_stack,
128 .canvas = canvas,
129 .gr_context = frame.gr_context(),
130 .dst_color_space = sk_ref_sp(color_space),
131 .view_embedder = frame.view_embedder(),
132 .raster_time = frame.context().raster_time(),
133 .ui_time = frame.context().ui_time(),
134 .texture_registry = frame.context().texture_registry(),
135#if !SLIMPELLER
136 .raster_cache = cache,
137#endif // !SLIMPELLER
138 .layer_snapshot_store = snapshot_store,
139 .enable_leaf_layer_tracing = enable_leaf_layer_tracing_,
140 .impeller_enabled = !!frame.aiks_context(),
141 .aiks_context = frame.aiks_context(),
142 // clang-format on
143 };
144
145#if !SLIMPELLER
146 if (cache) {
147 cache->EvictUnusedCacheEntries();
148 TryToRasterCache(raster_cache_items_, &context, ignore_raster_cache);
149 }
150#endif // !SLIMPELLER
151
152 if (root_layer_->needs_painting(context)) {
153 root_layer_->Paint(context);
154 }
155}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static void TryToRasterCache(const std::vector< RasterCacheItem * > &raster_cached_entries, const PaintContext *paint_context, bool ignore_raster_cache=false)
Definition: layer_tree.cc:68
double frame
Definition: examples.cpp:31
#define FML_LOG(severity)
Definition: logging.h:82
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
SkColorSpace * GetColorSpace(DlCanvas *canvas)
Definition: layer_tree.cc:25
flutter::DlCanvas DlCanvas
#define ERROR(message)
Definition: elf_loader.cc:260

◆ paint_region_map() [1/2]

PaintRegionMap & flutter::LayerTree::paint_region_map ( )
inline

Definition at line 57 of file layer_tree.h.

57{ return paint_region_map_; }

◆ paint_region_map() [2/2]

const PaintRegionMap & flutter::LayerTree::paint_region_map ( ) const
inline

Definition at line 56 of file layer_tree.h.

56{ return paint_region_map_; }

◆ Preroll()

bool flutter::LayerTree::Preroll ( CompositorContext::ScopedFrame frame,
bool  ignore_raster_cache = false,
SkRect  cull_rect = kGiantRect 
)

Definition at line 29 of file layer_tree.cc.

31 {
32 TRACE_EVENT0("flutter", "LayerTree::Preroll");
33
34 if (!root_layer_) {
35 FML_LOG(ERROR) << "The scene did not specify any layers.";
36 return false;
37 }
38
39 SkColorSpace* color_space = GetColorSpace(frame.canvas());
40 LayerStateStack state_stack;
41 state_stack.set_preroll_delegate(cull_rect,
42 frame.root_surface_transformation());
43
44 raster_cache_items_.clear();
45
46 PrerollContext context = {
47#if !SLIMPELLER
48 .raster_cache =
49 ignore_raster_cache ? nullptr : &frame.context().raster_cache(),
50#endif // !SLIMPELLER
51 .gr_context = frame.gr_context(),
52 .view_embedder = frame.view_embedder(),
53 .state_stack = state_stack,
54 .dst_color_space = sk_ref_sp<SkColorSpace>(color_space),
55 .surface_needs_readback = false,
56 .raster_time = frame.context().raster_time(),
57 .ui_time = frame.context().ui_time(),
58 .texture_registry = frame.context().texture_registry(),
59 .raster_cached_entries = &raster_cache_items_,
60 };
61
62 root_layer_->Preroll(&context);
63
64 return context.surface_needs_readback;
65}

◆ root_layer()

Layer * flutter::LayerTree::root_layer ( ) const
inline

Definition at line 53 of file layer_tree.h.

53{ return root_layer_.get(); }

◆ TryToRasterCache()

void flutter::LayerTree::TryToRasterCache ( const std::vector< RasterCacheItem * > &  raster_cached_entries,
const PaintContext paint_context,
bool  ignore_raster_cache = false 
)
static

Definition at line 68 of file layer_tree.cc.

71 {
72 unsigned i = 0;
73 const auto item_size = raster_cached_items.size();
74 while (i < item_size) {
75 auto* item = raster_cached_items[i];
76 if (item->need_caching()) {
77 // try to cache current layer
78 // If parent failed to cache, just proceed to the next entry
79 // cache current entry, this entry's parent must not cache
80 if (item->TryToPrepareRasterCache(*paint_context, false)) {
81 // if parent cached, then foreach child layer to touch them.
82 for (unsigned j = 0; j < item->child_items(); j++) {
83 auto* child_item = raster_cached_items[i + j + 1];
84 if (child_item->need_caching()) {
85 child_item->TryToPrepareRasterCache(*paint_context, true);
86 }
87 }
88 i += item->child_items() + 1;
89 continue;
90 }
91 }
92 i++;
93 }
94}

The documentation for this class was generated from the following files: