Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
flutter::LayerTree Class Reference

#include <layer_tree.h>

Classes

struct  Config
 

Public Member Functions

 LayerTree (const Config &config, 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 ()
 
uint32_t rasterizer_tracing_threshold () const
 
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 Config config,
const SkISize frame_size 
)

Definition at line 21 of file layer_tree.cc.

22 : root_layer_(config.root_layer),
23 frame_size_(frame_size),
24 rasterizer_tracing_threshold_(config.rasterizer_tracing_threshold),
25 checkerboard_raster_cache_images_(
26 config.checkerboard_raster_cache_images),
27 checkerboard_offscreen_layers_(config.checkerboard_offscreen_layers) {}
const SkISize & frame_size() const
Definition layer_tree.h:58

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 raterization of leaf layers is collected.

This is not supported in the Impeller backend.

See: LayerSnapshotStore

Definition at line 76 of file layer_tree.h.

76 {
77 enable_leaf_layer_tracing_ = enable;
78 }

◆ 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 158 of file layer_tree.cc.

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

◆ frame_size()

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

Definition at line 58 of file layer_tree.h.

58{ return frame_size_; }

◆ is_leaf_layer_tracing_enabled()

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

Definition at line 80 of file layer_tree.h.

80 {
81 return enable_leaf_layer_tracing_;
82 }

◆ Paint()

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

Definition at line 101 of file layer_tree.cc.

102 {
103 TRACE_EVENT0("flutter", "LayerTree::Paint");
104
105 if (!root_layer_) {
106 FML_LOG(ERROR) << "The scene did not specify any layers to paint.";
107 return;
108 }
109
110 LayerStateStack state_stack;
111
112 // DrawCheckerboard is not supported on Impeller.
113 if (checkerboard_offscreen_layers_ && !frame.aiks_context()) {
114 state_stack.set_checkerboard_func(DrawCheckerboard);
115 }
116
117 DlCanvas* canvas = frame.canvas();
118 state_stack.set_delegate(canvas);
119
120 // clear the previous snapshots.
121 LayerSnapshotStore* snapshot_store = nullptr;
122 if (enable_leaf_layer_tracing_) {
123 frame.context().snapshot_store().Clear();
124 snapshot_store = &frame.context().snapshot_store();
125 }
126
127 SkColorSpace* color_space = GetColorSpace(frame.canvas());
128 RasterCache* cache =
129 ignore_raster_cache ? nullptr : &frame.context().raster_cache();
130 PaintContext context = {
131 // clang-format off
132 .state_stack = state_stack,
133 .canvas = canvas,
134 .gr_context = frame.gr_context(),
135 .dst_color_space = sk_ref_sp(color_space),
136 .view_embedder = frame.view_embedder(),
137 .raster_time = frame.context().raster_time(),
138 .ui_time = frame.context().ui_time(),
139 .texture_registry = frame.context().texture_registry(),
140 .raster_cache = cache,
141 .layer_snapshot_store = snapshot_store,
142 .enable_leaf_layer_tracing = enable_leaf_layer_tracing_,
143 .impeller_enabled = !!frame.aiks_context(),
144 .aiks_context = frame.aiks_context(),
145 // clang-format on
146 };
147
148 if (cache) {
149 cache->EvictUnusedCacheEntries();
150 TryToRasterCache(raster_cache_items_, &context, ignore_raster_cache);
151 }
152
153 if (root_layer_->needs_painting(context)) {
154 root_layer_->Paint(context);
155 }
156}
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:73
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:29
void DrawCheckerboard(DlCanvas *canvas, const SkRect &rect)
#define ERROR(message)

◆ paint_region_map() [1/2]

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

Definition at line 61 of file layer_tree.h.

61{ return paint_region_map_; }

◆ paint_region_map() [2/2]

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

Definition at line 60 of file layer_tree.h.

60{ return paint_region_map_; }

◆ Preroll()

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

Definition at line 33 of file layer_tree.cc.

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

◆ rasterizer_tracing_threshold()

uint32_t flutter::LayerTree::rasterizer_tracing_threshold ( ) const
inline

Definition at line 66 of file layer_tree.h.

66 {
67 return rasterizer_tracing_threshold_;
68 }

◆ root_layer()

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

Definition at line 57 of file layer_tree.h.

57{ 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 73 of file layer_tree.cc.

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

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