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 <stdint.h> |
9 | |
10 | #include <memory> |
11 | |
12 | #include "flutter/flow/compositor_context.h" |
13 | #include "flutter/flow/layers/layer.h" |
14 | #include "flutter/fml/macros.h" |
15 | #include "flutter/fml/time/time_delta.h" |
16 | #include "third_party/skia/include/core/SkPicture.h" |
17 | #include "third_party/skia/include/core/SkSize.h" |
18 | |
19 | namespace flutter { |
20 | |
21 | class LayerTree { |
22 | public: |
23 | LayerTree(const SkISize& frame_size, float device_pixel_ratio); |
24 | |
25 | // Perform a preroll pass on the tree and return information about |
26 | // the tree that affects rendering this frame. |
27 | // |
28 | // Returns: |
29 | // - a boolean indicating whether or not the top level of the |
30 | // layer tree performs any operations that require readback |
31 | // from the root surface. |
32 | bool Preroll(CompositorContext::ScopedFrame& frame, |
33 | bool ignore_raster_cache = false); |
34 | |
35 | #if defined(LEGACY_FUCHSIA_EMBEDDER) |
36 | void UpdateScene(SceneUpdateContext& context); |
37 | #endif |
38 | |
39 | void Paint(CompositorContext::ScopedFrame& frame, |
40 | bool ignore_raster_cache = false) const; |
41 | |
42 | sk_sp<SkPicture> Flatten(const SkRect& bounds); |
43 | |
44 | Layer* root_layer() const { return root_layer_.get(); } |
45 | |
46 | void set_root_layer(std::shared_ptr<Layer> root_layer) { |
47 | root_layer_ = std::move(root_layer); |
48 | } |
49 | |
50 | const SkISize& frame_size() const { return frame_size_; } |
51 | float device_pixel_ratio() const { return device_pixel_ratio_; } |
52 | |
53 | void RecordBuildTime(fml::TimePoint vsync_start, |
54 | fml::TimePoint build_start, |
55 | fml::TimePoint target_time); |
56 | fml::TimePoint vsync_start() const { return vsync_start_; } |
57 | fml::TimeDelta vsync_overhead() const { return build_start_ - vsync_start_; } |
58 | fml::TimePoint build_start() const { return build_start_; } |
59 | fml::TimePoint build_finish() const { return build_finish_; } |
60 | fml::TimeDelta build_time() const { return build_finish_ - build_start_; } |
61 | fml::TimePoint target_time() const { return target_time_; } |
62 | |
63 | // The number of frame intervals missed after which the compositor must |
64 | // trace the rasterized picture to a trace file. Specify 0 to disable all |
65 | // tracing |
66 | void set_rasterizer_tracing_threshold(uint32_t interval) { |
67 | rasterizer_tracing_threshold_ = interval; |
68 | } |
69 | |
70 | uint32_t rasterizer_tracing_threshold() const { |
71 | return rasterizer_tracing_threshold_; |
72 | } |
73 | |
74 | void set_checkerboard_raster_cache_images(bool checkerboard) { |
75 | checkerboard_raster_cache_images_ = checkerboard; |
76 | } |
77 | |
78 | void set_checkerboard_offscreen_layers(bool checkerboard) { |
79 | checkerboard_offscreen_layers_ = checkerboard; |
80 | } |
81 | |
82 | private: |
83 | std::shared_ptr<Layer> root_layer_; |
84 | fml::TimePoint vsync_start_; |
85 | fml::TimePoint build_start_; |
86 | fml::TimePoint build_finish_; |
87 | fml::TimePoint target_time_; |
88 | SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels. |
89 | const float device_pixel_ratio_; // Logical / Physical pixels ratio. |
90 | uint32_t rasterizer_tracing_threshold_; |
91 | bool checkerboard_raster_cache_images_; |
92 | bool checkerboard_offscreen_layers_; |
93 | |
94 | FML_DISALLOW_COPY_AND_ASSIGN(LayerTree); |
95 | }; |
96 | |
97 | } // namespace flutter |
98 | |
99 | #endif // FLUTTER_FLOW_LAYERS_LAYER_TREE_H_ |
100 |