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 
34 #if defined(LEGACY_FUCHSIA_EMBEDDER)
35  void UpdateScene(std::shared_ptr<SceneUpdateContext> context);
36 #endif
37 
39  bool ignore_raster_cache = false) const;
40 
41  sk_sp<SkPicture> Flatten(const SkRect& bounds);
42 
43  Layer* root_layer() const { return root_layer_.get(); }
44 
45  void set_root_layer(std::shared_ptr<Layer> root_layer) {
46  root_layer_ = std::move(root_layer);
47  }
48 
49  const SkISize& frame_size() const { return frame_size_; }
50  float device_pixel_ratio() const { return device_pixel_ratio_; }
51 
55  fml::TimePoint vsync_start() const { return vsync_start_; }
56  fml::TimeDelta vsync_overhead() const { return build_start_ - vsync_start_; }
57  fml::TimePoint build_start() const { return build_start_; }
58  fml::TimePoint build_finish() const { return build_finish_; }
59  fml::TimeDelta build_time() const { return build_finish_ - build_start_; }
60  fml::TimePoint target_time() const { return target_time_; }
61 
62  // The number of frame intervals missed after which the compositor must
63  // trace the rasterized picture to a trace file. Specify 0 to disable all
64  // tracing
65  void set_rasterizer_tracing_threshold(uint32_t interval) {
66  rasterizer_tracing_threshold_ = interval;
67  }
68 
69  uint32_t rasterizer_tracing_threshold() const {
70  return rasterizer_tracing_threshold_;
71  }
72 
73  void set_checkerboard_raster_cache_images(bool checkerboard) {
74  checkerboard_raster_cache_images_ = checkerboard;
75  }
76 
77  void set_checkerboard_offscreen_layers(bool checkerboard) {
78  checkerboard_offscreen_layers_ = checkerboard;
79  }
80 
81  private:
82  std::shared_ptr<Layer> root_layer_;
83  fml::TimePoint vsync_start_;
84  fml::TimePoint build_start_;
85  fml::TimePoint build_finish_;
86  fml::TimePoint target_time_;
87  SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels.
88  const float device_pixel_ratio_; // Logical / Physical pixels ratio.
89  uint32_t rasterizer_tracing_threshold_;
90  bool checkerboard_raster_cache_images_;
91  bool checkerboard_offscreen_layers_;
92 
93  FML_DISALLOW_COPY_AND_ASSIGN(LayerTree);
94 };
95 
96 } // namespace flutter
97 
98 #endif // FLUTTER_FLOW_LAYERS_LAYER_TREE_H_
sk_sp< SkPicture > Flatten(const SkRect &bounds)
Definition: layer_tree.cc:125
fml::TimePoint build_start() const
Definition: layer_tree.h:57
const SkISize & frame_size() const
Definition: layer_tree.h:49
void set_rasterizer_tracing_threshold(uint32_t interval)
Definition: layer_tree.h:65
void set_root_layer(std::shared_ptr< Layer > root_layer)
Definition: layer_tree.h:45
Layer * root_layer() const
Definition: layer_tree.h:43
void set_checkerboard_offscreen_layers(bool checkerboard)
Definition: layer_tree.h:77
fml::TimePoint target_time() const
Definition: layer_tree.h:60
bool Preroll(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false)
Definition: layer_tree.cc:32
uint32_t rasterizer_tracing_threshold() const
Definition: layer_tree.h:69
fml::TimePoint build_finish() const
Definition: layer_tree.h:58
LayerTree(const SkISize &frame_size, float device_pixel_ratio)
Definition: layer_tree.cc:14
fml::TimeDelta build_time() const
Definition: layer_tree.h:59
float device_pixel_ratio() const
Definition: layer_tree.h:50
void RecordBuildTime(fml::TimePoint vsync_start, fml::TimePoint build_start, fml::TimePoint target_time)
Definition: layer_tree.cc:23
void set_checkerboard_raster_cache_images(bool checkerboard)
Definition: layer_tree.h:73
fml::TimePoint vsync_start() const
Definition: layer_tree.h:55
void Paint(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false) const
Definition: layer_tree.cc:89
fml::TimeDelta vsync_overhead() const
Definition: layer_tree.h:56