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/common/graphics/texture.h"
12#include "flutter/flow/compositor_context.h"
13#include "flutter/flow/layers/layer.h"
14#include "flutter/flow/raster_cache.h"
15#include "flutter/fml/macros.h"
16#include "flutter/fml/time/time_delta.h"
17
18class GrDirectContext;
19
20namespace flutter {
21
22class LayerTree {
23 public:
24 struct Config {
25 std::shared_ptr<Layer> root_layer;
26 uint32_t rasterizer_tracing_threshold = 0;
27 bool checkerboard_raster_cache_images = false;
28 bool checkerboard_offscreen_layers = false;
29 };
30
31 LayerTree(const Config& config, const SkISize& frame_size);
32
33 // Perform a preroll pass on the tree and return information about
34 // the tree that affects rendering this frame.
35 //
36 // Returns:
37 // - a boolean indicating whether or not the top level of the
38 // layer tree performs any operations that require readback
39 // from the root surface.
40 bool Preroll(CompositorContext::ScopedFrame& frame,
41 bool ignore_raster_cache = false,
42 SkRect cull_rect = kGiantRect);
43
44 static void TryToRasterCache(
45 const std::vector<RasterCacheItem*>& raster_cached_entries,
46 const PaintContext* paint_context,
47 bool ignore_raster_cache = false);
48
49 void Paint(CompositorContext::ScopedFrame& frame,
50 bool ignore_raster_cache = false) const;
51
52 sk_sp<DisplayList> Flatten(
53 const SkRect& bounds,
54 const std::shared_ptr<TextureRegistry>& texture_registry = nullptr,
55 GrDirectContext* gr_context = nullptr);
56
57 Layer* root_layer() const { return root_layer_.get(); }
58 const SkISize& frame_size() const { return frame_size_; }
59
60 const PaintRegionMap& paint_region_map() const { return paint_region_map_; }
61 PaintRegionMap& paint_region_map() { return paint_region_map_; }
62
63 // The number of frame intervals missed after which the compositor must
64 // trace the rasterized picture to a trace file. 0 stands for disabling all
65 // tracing.
66 uint32_t rasterizer_tracing_threshold() const {
67 return rasterizer_tracing_threshold_;
68 }
69
70 /// When `Paint` is called, if leaf layer tracing is enabled, additional
71 /// metadata around raterization of leaf layers is collected.
72 ///
73 /// See: `LayerSnapshotStore`
74 void enable_leaf_layer_tracing(bool enable) {
75 enable_leaf_layer_tracing_ = enable;
76 }
77
78 bool is_leaf_layer_tracing_enabled() const {
79 return enable_leaf_layer_tracing_;
80 }
81
82 private:
83 std::shared_ptr<Layer> root_layer_;
84 SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels.
85 uint32_t rasterizer_tracing_threshold_;
86 bool checkerboard_raster_cache_images_;
87 bool checkerboard_offscreen_layers_;
88 bool enable_leaf_layer_tracing_ = false;
89
90 PaintRegionMap paint_region_map_;
91
92 std::vector<RasterCacheItem*> raster_cache_items_;
93
94 FML_DISALLOW_COPY_AND_ASSIGN(LayerTree);
95};
96
97} // namespace flutter
98
99#endif // FLUTTER_FLOW_LAYERS_LAYER_TREE_H_
100

source code of flutter_engine/flutter/flow/layers/layer_tree.h