Flutter Engine
flutter::LayerTree Class Reference

#include <layer_tree.h>

Public Member Functions

 LayerTree (const SkISize &frame_size, float device_pixel_ratio)
 
bool Preroll (CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false)
 
void Paint (CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false) const
 
sk_sp< SkPicture > Flatten (const SkRect &bounds)
 
Layerroot_layer () const
 
void set_root_layer (std::shared_ptr< Layer > root_layer)
 
const SkISize & frame_size () const
 
float device_pixel_ratio () const
 
void RecordBuildTime (fml::TimePoint vsync_start, fml::TimePoint build_start, fml::TimePoint target_time)
 
fml::TimePoint vsync_start () const
 
fml::TimeDelta vsync_overhead () const
 
fml::TimePoint build_start () const
 
fml::TimePoint build_finish () const
 
fml::TimeDelta build_time () const
 
fml::TimePoint target_time () const
 
void set_rasterizer_tracing_threshold (uint32_t interval)
 
uint32_t rasterizer_tracing_threshold () const
 
void set_checkerboard_raster_cache_images (bool checkerboard)
 
void set_checkerboard_offscreen_layers (bool checkerboard)
 

Detailed Description

Definition at line 20 of file layer_tree.h.

Constructor & Destructor Documentation

◆ LayerTree()

flutter::LayerTree::LayerTree ( const SkISize &  frame_size,
float  device_pixel_ratio 
)

Definition at line 14 of file layer_tree.cc.

References FML_CHECK.

15  : frame_size_(frame_size),
16  device_pixel_ratio_(device_pixel_ratio),
17  rasterizer_tracing_threshold_(0),
18  checkerboard_raster_cache_images_(false),
19  checkerboard_offscreen_layers_(false) {
20  FML_CHECK(device_pixel_ratio_ != 0.0f);
21 }
const SkISize & frame_size() const
Definition: layer_tree.h:49
float device_pixel_ratio() const
Definition: layer_tree.h:50
#define FML_CHECK(condition)
Definition: logging.h:68

Member Function Documentation

◆ build_finish()

fml::TimePoint flutter::LayerTree::build_finish ( ) const
inline

Definition at line 58 of file layer_tree.h.

58 { return build_finish_; }

◆ build_start()

fml::TimePoint flutter::LayerTree::build_start ( ) const
inline

Definition at line 57 of file layer_tree.h.

Referenced by device_pixel_ratio(), and RecordBuildTime().

57 { return build_start_; }

◆ build_time()

fml::TimeDelta flutter::LayerTree::build_time ( ) const
inline

Definition at line 59 of file layer_tree.h.

Referenced by flutter::Rasterizer::Draw().

59 { return build_finish_ - build_start_; }

◆ device_pixel_ratio()

float flutter::LayerTree::device_pixel_ratio ( ) const
inline

Definition at line 50 of file layer_tree.h.

References build_start(), RecordBuildTime(), target_time(), and vsync_start().

Referenced by flutter::Rasterizer::Draw(), and flutter_runner::ScopedFrame::ScopedFrame().

50 { return device_pixel_ratio_; }

◆ Flatten()

sk_sp< SkPicture > flutter::LayerTree::Flatten ( const SkRect &  bounds)

Definition at line 125 of file layer_tree.cc.

References flutter::kGiantRect, and TRACE_EVENT0.

125  {
126  TRACE_EVENT0("flutter", "LayerTree::Flatten");
127 
128  SkPictureRecorder recorder;
129  auto* canvas = recorder.beginRecording(bounds);
130 
131  if (!canvas) {
132  return nullptr;
133  }
134 
135  MutatorsStack unused_stack;
136  const Stopwatch unused_stopwatch;
137  TextureRegistry unused_texture_registry;
138  SkMatrix root_surface_transformation;
139  // No root surface transformation. So assume identity.
140  root_surface_transformation.reset();
141 
142  PrerollContext preroll_context{
143  nullptr, // raster_cache (don't consult the cache)
144  nullptr, // gr_context (used for the raster cache)
145  nullptr, // external view embedder
146  unused_stack, // mutator stack
147  nullptr, // SkColorSpace* dst_color_space
148  kGiantRect, // SkRect cull_rect
149  false, // layer reads from surface
150  unused_stopwatch, // frame time (dont care)
151  unused_stopwatch, // engine time (dont care)
152  unused_texture_registry, // texture registry (not supported)
153  false, // checkerboard_offscreen_layers
154  device_pixel_ratio_ // ratio between logical and physical
155  };
156 
157  SkISize canvas_size = canvas->getBaseLayerSize();
158  SkNWayCanvas internal_nodes_canvas(canvas_size.width(), canvas_size.height());
159  internal_nodes_canvas.addCanvas(canvas);
160 
161  Layer::PaintContext paint_context = {
162  static_cast<SkCanvas*>(&internal_nodes_canvas),
163  canvas, // canvas
164  nullptr,
165  nullptr,
166  unused_stopwatch, // frame time (dont care)
167  unused_stopwatch, // engine time (dont care)
168  unused_texture_registry, // texture registry (not supported)
169  nullptr, // raster cache
170  false, // checkerboard offscreen layers
171  device_pixel_ratio_ // ratio between logical and physical
172  };
173 
174  // Even if we don't have a root layer, we still need to create an empty
175  // picture.
176  if (root_layer_) {
177  root_layer_->Preroll(&preroll_context, root_surface_transformation);
178  // The needs painting flag may be set after the preroll. So check it after.
179  if (root_layer_->needs_painting()) {
180  root_layer_->Paint(paint_context);
181  }
182  }
183 
184  return recorder.finishRecordingAsPicture();
185 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
static constexpr SkRect kGiantRect
Definition: layer.h:38

◆ frame_size()

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

◆ Paint()

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

Definition at line 89 of file layer_tree.cc.

References flutter::CompositorContext::ScopedFrame::canvas(), flutter::CompositorContext::ScopedFrame::context(), FML_LOG, flutter::ExternalViewEmbedder::GetCurrentCanvases(), flutter::CompositorContext::ScopedFrame::gr_context(), flutter::CompositorContext::raster_cache(), flutter::CompositorContext::raster_time(), flutter::CompositorContext::texture_registry(), TRACE_EVENT0, flutter::CompositorContext::ui_time(), and flutter::CompositorContext::ScopedFrame::view_embedder().

Referenced by flutter::CompositorContext::ScopedFrame::Raster(), and flutter::testing::TEST_F().

90  {
91  TRACE_EVENT0("flutter", "LayerTree::Paint");
92 
93  if (!root_layer_) {
94  FML_LOG(ERROR) << "The scene did not specify any layers to paint.";
95  return;
96  }
97 
98  SkISize canvas_size = frame.canvas()->getBaseLayerSize();
99  SkNWayCanvas internal_nodes_canvas(canvas_size.width(), canvas_size.height());
100  internal_nodes_canvas.addCanvas(frame.canvas());
101  if (frame.view_embedder() != nullptr) {
102  auto overlay_canvases = frame.view_embedder()->GetCurrentCanvases();
103  for (size_t i = 0; i < overlay_canvases.size(); i++) {
104  internal_nodes_canvas.addCanvas(overlay_canvases[i]);
105  }
106  }
107 
108  Layer::PaintContext context = {
109  static_cast<SkCanvas*>(&internal_nodes_canvas),
110  frame.canvas(),
111  frame.gr_context(),
112  frame.view_embedder(),
113  frame.context().raster_time(),
114  frame.context().ui_time(),
115  frame.context().texture_registry(),
116  ignore_raster_cache ? nullptr : &frame.context().raster_cache(),
117  checkerboard_offscreen_layers_,
118  device_pixel_ratio_};
119 
120  if (root_layer_->needs_painting()) {
121  root_layer_->Paint(context);
122  }
123 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_LOG(severity)
Definition: logging.h:65

◆ Preroll()

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

Definition at line 32 of file layer_tree.cc.

References flutter::CompositorContext::ScopedFrame::canvas(), flutter::CompositorContext::ScopedFrame::context(), flutter::SceneUpdateContext::Entity::entity_node(), FML_LOG, flutter::CompositorContext::ScopedFrame::gr_context(), flutter::kGiantRect, flutter::CompositorContext::raster_cache(), flutter::CompositorContext::raster_time(), flutter::CompositorContext::ScopedFrame::root_surface_transformation(), flutter::RasterCache::SetCheckboardCacheImages(), flutter::PrerollContext::surface_needs_readback, flutter::CompositorContext::texture_registry(), TRACE_EVENT0, flutter::transform, flutter::CompositorContext::ui_time(), and flutter::CompositorContext::ScopedFrame::view_embedder().

Referenced by flutter::CompositorContext::ScopedFrame::Raster(), flutter_runner::ScopedFrame::ScopedFrame(), and flutter::testing::TEST_F().

33  {
34  TRACE_EVENT0("flutter", "LayerTree::Preroll");
35 
36  if (!root_layer_) {
37  FML_LOG(ERROR) << "The scene did not specify any layers.";
38  return false;
39  }
40 
41  SkColorSpace* color_space =
42  frame.canvas() ? frame.canvas()->imageInfo().colorSpace() : nullptr;
43  frame.context().raster_cache().SetCheckboardCacheImages(
44  checkerboard_raster_cache_images_);
45  MutatorsStack stack;
46  PrerollContext context = {
47  ignore_raster_cache ? nullptr : &frame.context().raster_cache(),
48  frame.gr_context(),
49  frame.view_embedder(),
50  stack,
51  color_space,
52  kGiantRect,
53  false,
54  frame.context().raster_time(),
55  frame.context().ui_time(),
56  frame.context().texture_registry(),
57  checkerboard_offscreen_layers_,
58  device_pixel_ratio_};
59 
60  root_layer_->Preroll(&context, frame.root_surface_transformation());
61  return context.surface_needs_readback;
62 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_LOG(severity)
Definition: logging.h:65
static constexpr SkRect kGiantRect
Definition: layer.h:38

◆ rasterizer_tracing_threshold()

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

Definition at line 69 of file layer_tree.h.

69  {
70  return rasterizer_tracing_threshold_;
71  }

◆ RecordBuildTime()

void flutter::LayerTree::RecordBuildTime ( fml::TimePoint  vsync_start,
fml::TimePoint  build_start,
fml::TimePoint  target_time 
)

Definition at line 23 of file layer_tree.cc.

References build_start(), fml::TimePoint::Now(), target_time(), and vsync_start().

Referenced by device_pixel_ratio().

25  {
26  vsync_start_ = vsync_start;
27  build_start_ = build_start;
28  target_time_ = target_time;
29  build_finish_ = fml::TimePoint::Now();
30 }
fml::TimePoint build_start() const
Definition: layer_tree.h:57
fml::TimePoint target_time() const
Definition: layer_tree.h:60
fml::TimePoint vsync_start() const
Definition: layer_tree.h:55
static TimePoint Now()
Definition: time_point.cc:26

◆ root_layer()

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

Definition at line 43 of file layer_tree.h.

43 { return root_layer_.get(); }

◆ set_checkerboard_offscreen_layers()

void flutter::LayerTree::set_checkerboard_offscreen_layers ( bool  checkerboard)
inline

Definition at line 77 of file layer_tree.h.

77  {
78  checkerboard_offscreen_layers_ = checkerboard;
79  }

◆ set_checkerboard_raster_cache_images()

void flutter::LayerTree::set_checkerboard_raster_cache_images ( bool  checkerboard)
inline

Definition at line 73 of file layer_tree.h.

73  {
74  checkerboard_raster_cache_images_ = checkerboard;
75  }

◆ set_rasterizer_tracing_threshold()

void flutter::LayerTree::set_rasterizer_tracing_threshold ( uint32_t  interval)
inline

Definition at line 65 of file layer_tree.h.

65  {
66  rasterizer_tracing_threshold_ = interval;
67  }

◆ set_root_layer()

void flutter::LayerTree::set_root_layer ( std::shared_ptr< Layer root_layer)
inline

Definition at line 45 of file layer_tree.h.

Referenced by flutter::testing::TEST_F().

45  {
46  root_layer_ = std::move(root_layer);
47  }
Layer * root_layer() const
Definition: layer_tree.h:43

◆ target_time()

fml::TimePoint flutter::LayerTree::target_time ( ) const
inline

Definition at line 60 of file layer_tree.h.

Referenced by device_pixel_ratio(), and RecordBuildTime().

60 { return target_time_; }

◆ vsync_overhead()

fml::TimeDelta flutter::LayerTree::vsync_overhead ( ) const
inline

Definition at line 56 of file layer_tree.h.

56 { return build_start_ - vsync_start_; }

◆ vsync_start()

fml::TimePoint flutter::LayerTree::vsync_start ( ) const
inline

Definition at line 55 of file layer_tree.h.

Referenced by device_pixel_ratio(), and RecordBuildTime().

55 { return vsync_start_; }

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