Flutter Engine
layer_tree.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FLOW_LAYERS_LAYER_TREE_H_
6 #define FLUTTER_FLOW_LAYERS_LAYER_TREE_H_
7 
8 #include <cstdint>
9 #include <memory>
10 
11 #include "flutter/flow/compositor_context.h"
12 #include "flutter/flow/layers/layer.h"
13 #include "flutter/fml/macros.h"
14 #include "flutter/fml/time/time_delta.h"
15 #include "third_party/skia/include/core/SkPicture.h"
16 #include "third_party/skia/include/core/SkSize.h"
17 
18 namespace flutter {
19 
20 class LayerTree {
21  public:
22  LayerTree(const SkISize& frame_size, float device_pixel_ratio);
23 
24  // Perform a preroll pass on the tree and return information about
25  // the tree that affects rendering this frame.
26  //
27  // Returns:
28  // - a boolean indicating whether or not the top level of the
29  // layer tree performs any operations that require readback
30  // from the root surface.
32  bool ignore_raster_cache = false);
33 
35  bool ignore_raster_cache = false) const;
36 
37  sk_sp<SkPicture> Flatten(const SkRect& bounds);
38 
39  Layer* root_layer() const { return root_layer_.get(); }
40 
41  void set_root_layer(std::shared_ptr<Layer> root_layer) {
42  root_layer_ = std::move(root_layer);
43  }
44 
45  const SkISize& frame_size() const { return frame_size_; }
46  float device_pixel_ratio() const { return device_pixel_ratio_; }
47 
48 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
49 
50  const PaintRegionMap& paint_region_map() const { return paint_region_map_; }
51  PaintRegionMap& paint_region_map() { return paint_region_map_; }
52 
53 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
54 
55  // The number of frame intervals missed after which the compositor must
56  // trace the rasterized picture to a trace file. Specify 0 to disable all
57  // tracing
58  void set_rasterizer_tracing_threshold(uint32_t interval) {
59  rasterizer_tracing_threshold_ = interval;
60  }
61 
62  uint32_t rasterizer_tracing_threshold() const {
63  return rasterizer_tracing_threshold_;
64  }
65 
66  void set_checkerboard_raster_cache_images(bool checkerboard) {
67  checkerboard_raster_cache_images_ = checkerboard;
68  }
69 
70  void set_checkerboard_offscreen_layers(bool checkerboard) {
71  checkerboard_offscreen_layers_ = checkerboard;
72  }
73 
74  private:
75  std::shared_ptr<Layer> root_layer_;
76  SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels.
77  const float device_pixel_ratio_; // Logical / Physical pixels ratio.
78  uint32_t rasterizer_tracing_threshold_;
79  bool checkerboard_raster_cache_images_;
80  bool checkerboard_offscreen_layers_;
81 
82 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
83  PaintRegionMap paint_region_map_;
84 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
85 
86  FML_DISALLOW_COPY_AND_ASSIGN(LayerTree);
87 };
88 
89 } // namespace flutter
90 
91 #endif // FLUTTER_FLOW_LAYERS_LAYER_TREE_H_
sk_sp< SkPicture > Flatten(const SkRect &bounds)
Definition: layer_tree.cc:93
const SkISize & frame_size() const
Definition: layer_tree.h:45
void set_rasterizer_tracing_threshold(uint32_t interval)
Definition: layer_tree.h:58
void set_root_layer(std::shared_ptr< Layer > root_layer)
Definition: layer_tree.h:41
Layer * root_layer() const
Definition: layer_tree.h:39
void set_checkerboard_offscreen_layers(bool checkerboard)
Definition: layer_tree.h:70
bool Preroll(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false)
Definition: layer_tree.cc:25
uint32_t rasterizer_tracing_threshold() const
Definition: layer_tree.h:62
LayerTree(const SkISize &frame_size, float device_pixel_ratio)
Definition: layer_tree.cc:16
float device_pixel_ratio() const
Definition: layer_tree.h:46
void set_checkerboard_raster_cache_images(bool checkerboard)
Definition: layer_tree.h:66
void Paint(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false) const
Definition: layer_tree.cc:57