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

References FML_CHECK.

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

Member Function Documentation

◆ device_pixel_ratio()

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

Definition at line 46 of file layer_tree.h.

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

46 { return device_pixel_ratio_; }

◆ Flatten()

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

Definition at line 93 of file layer_tree.cc.

References flutter::kGiantRect, and TRACE_EVENT0.

93  {
94  TRACE_EVENT0("flutter", "LayerTree::Flatten");
95 
96  SkPictureRecorder recorder;
97  auto* canvas = recorder.beginRecording(bounds);
98 
99  if (!canvas) {
100  return nullptr;
101  }
102 
103  MutatorsStack unused_stack;
104  const Stopwatch unused_stopwatch;
105  TextureRegistry unused_texture_registry;
106  SkMatrix root_surface_transformation;
107  // No root surface transformation. So assume identity.
108  root_surface_transformation.reset();
109 
110  PrerollContext preroll_context{
111  nullptr, // raster_cache (don't consult the cache)
112  nullptr, // gr_context (used for the raster cache)
113  nullptr, // external view embedder
114  unused_stack, // mutator stack
115  nullptr, // SkColorSpace* dst_color_space
116  kGiantRect, // SkRect cull_rect
117  false, // layer reads from surface
118  unused_stopwatch, // frame time (dont care)
119  unused_stopwatch, // engine time (dont care)
120  unused_texture_registry, // texture registry (not supported)
121  false, // checkerboard_offscreen_layers
122  device_pixel_ratio_ // ratio between logical and physical
123  };
124 
125  SkISize canvas_size = canvas->getBaseLayerSize();
126  SkNWayCanvas internal_nodes_canvas(canvas_size.width(), canvas_size.height());
127  internal_nodes_canvas.addCanvas(canvas);
128 
129  Layer::PaintContext paint_context = {
130  static_cast<SkCanvas*>(&internal_nodes_canvas),
131  canvas, // canvas
132  nullptr,
133  nullptr,
134  unused_stopwatch, // frame time (dont care)
135  unused_stopwatch, // engine time (dont care)
136  unused_texture_registry, // texture registry (not supported)
137  nullptr, // raster cache
138  false, // checkerboard offscreen layers
139  device_pixel_ratio_ // ratio between logical and physical
140  };
141 
142  // Even if we don't have a root layer, we still need to create an empty
143  // picture.
144  if (root_layer_) {
145  root_layer_->Preroll(&preroll_context, root_surface_transformation);
146  // The needs painting flag may be set after the preroll. So check it after.
147  if (root_layer_->needs_painting(paint_context)) {
148  root_layer_->Paint(paint_context);
149  }
150  }
151 
152  return recorder.finishRecordingAsPicture();
153 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
static constexpr SkRect kGiantRect
Definition: layer.h:37

◆ 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 57 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().

58  {
59  TRACE_EVENT0("flutter", "LayerTree::Paint");
60 
61  if (!root_layer_) {
62  FML_LOG(ERROR) << "The scene did not specify any layers to paint.";
63  return;
64  }
65 
66  SkISize canvas_size = frame.canvas()->getBaseLayerSize();
67  SkNWayCanvas internal_nodes_canvas(canvas_size.width(), canvas_size.height());
68  internal_nodes_canvas.addCanvas(frame.canvas());
69  if (frame.view_embedder() != nullptr) {
70  auto overlay_canvases = frame.view_embedder()->GetCurrentCanvases();
71  for (size_t i = 0; i < overlay_canvases.size(); i++) {
72  internal_nodes_canvas.addCanvas(overlay_canvases[i]);
73  }
74  }
75 
76  Layer::PaintContext context = {
77  static_cast<SkCanvas*>(&internal_nodes_canvas),
78  frame.canvas(),
79  frame.gr_context(),
80  frame.view_embedder(),
81  frame.context().raster_time(),
82  frame.context().ui_time(),
83  frame.context().texture_registry(),
84  ignore_raster_cache ? nullptr : &frame.context().raster_cache(),
85  checkerboard_offscreen_layers_,
86  device_pixel_ratio_};
87 
88  if (root_layer_->needs_painting(context)) {
89  root_layer_->Paint(context);
90  }
91 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_LOG(severity)
Definition: logging.h:65

◆ Preroll()

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

Definition at line 25 of file layer_tree.cc.

References flutter::CompositorContext::ScopedFrame::canvas(), flutter::CompositorContext::ScopedFrame::context(), 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::CompositorContext::ui_time(), and flutter::CompositorContext::ScopedFrame::view_embedder().

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

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

◆ rasterizer_tracing_threshold()

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

Definition at line 62 of file layer_tree.h.

62  {
63  return rasterizer_tracing_threshold_;
64  }

◆ root_layer()

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

Definition at line 39 of file layer_tree.h.

39 { return root_layer_.get(); }

◆ set_checkerboard_offscreen_layers()

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

Definition at line 70 of file layer_tree.h.

70  {
71  checkerboard_offscreen_layers_ = checkerboard;
72  }

◆ set_checkerboard_raster_cache_images()

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

Definition at line 66 of file layer_tree.h.

66  {
67  checkerboard_raster_cache_images_ = checkerboard;
68  }

◆ set_rasterizer_tracing_threshold()

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

Definition at line 58 of file layer_tree.h.

58  {
59  rasterizer_tracing_threshold_ = interval;
60  }

◆ set_root_layer()

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

Definition at line 41 of file layer_tree.h.

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

41  {
42  root_layer_ = std::move(root_layer);
43  }
Layer * root_layer() const
Definition: layer_tree.h:39

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