Flutter Engine
The 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/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 LayerTree(const std::shared_ptr<Layer>& root_layer,
25 const SkISize& frame_size);
26
27 // Perform a preroll pass on the tree and return information about
28 // the tree that affects rendering this frame.
29 //
30 // Returns:
31 // - a boolean indicating whether or not the top level of the
32 // layer tree performs any operations that require readback
33 // from the root surface.
35 bool ignore_raster_cache = false,
36 SkRect cull_rect = kGiantRect);
37
38#if !SLIMPELLER
39 static void TryToRasterCache(
40 const std::vector<RasterCacheItem*>& raster_cached_entries,
41 const PaintContext* paint_context,
42 bool ignore_raster_cache = false);
43#endif // !SLIMPELLER
44
46 bool ignore_raster_cache = false) const;
47
49 const SkRect& bounds,
50 const std::shared_ptr<TextureRegistry>& texture_registry = nullptr,
51 GrDirectContext* gr_context = nullptr);
52
53 Layer* root_layer() const { return root_layer_.get(); }
54 const SkISize& frame_size() const { return frame_size_; }
55
56 const PaintRegionMap& paint_region_map() const { return paint_region_map_; }
57 PaintRegionMap& paint_region_map() { return paint_region_map_; }
58
59 /// When `Paint` is called, if leaf layer tracing is enabled, additional
60 /// metadata around rasterization of leaf layers is collected.
61 ///
62 /// This is not supported in the Impeller backend.
63 ///
64 /// See: `LayerSnapshotStore`
65 void enable_leaf_layer_tracing(bool enable) {
66 enable_leaf_layer_tracing_ = enable;
67 }
68
70 return enable_leaf_layer_tracing_;
71 }
72
73 private:
74 std::shared_ptr<Layer> root_layer_;
75 SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels.
76 bool enable_leaf_layer_tracing_ = false;
77
78 PaintRegionMap paint_region_map_;
79
80 std::vector<RasterCacheItem*> raster_cache_items_;
81
82 FML_DISALLOW_COPY_AND_ASSIGN(LayerTree);
83};
84
85// The information to draw a layer tree to a specified view.
87 public:
89 std::unique_ptr<LayerTree> layer_tree,
94
95 /// The target view to draw to.
96 int64_t view_id;
97 /// The target layer tree to be drawn.
98 std::unique_ptr<LayerTree> layer_tree;
99 /// The pixel ratio of the target view.
101
102 private:
103 FML_DISALLOW_COPY_AND_ASSIGN(LayerTreeTask);
104};
105
106} // namespace flutter
107
108#endif // FLUTTER_FLOW_LAYERS_LAYER_TREE_H_
Layer * root_layer() const
Definition: layer_tree.h:53
bool Preroll(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false, SkRect cull_rect=kGiantRect)
Definition: layer_tree.cc:29
LayerTree(const std::shared_ptr< Layer > &root_layer, const SkISize &frame_size)
Definition: layer_tree.cc:21
const SkISize & frame_size() const
Definition: layer_tree.h:54
void enable_leaf_layer_tracing(bool enable)
Definition: layer_tree.h:65
void Paint(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false) const
Definition: layer_tree.cc:97
const PaintRegionMap & paint_region_map() const
Definition: layer_tree.h:56
bool is_leaf_layer_tracing_enabled() const
Definition: layer_tree.h:69
sk_sp< DisplayList > Flatten(const SkRect &bounds, const std::shared_ptr< TextureRegistry > &texture_registry=nullptr, GrDirectContext *gr_context=nullptr)
Definition: layer_tree.cc:157
static void TryToRasterCache(const std::vector< RasterCacheItem * > &raster_cached_entries, const PaintContext *paint_context, bool ignore_raster_cache=false)
Definition: layer_tree.cc:68
PaintRegionMap & paint_region_map()
Definition: layer_tree.h:57
double frame
Definition: examples.cpp:31
Optional< SkRect > bounds
Definition: SkRecords.h:189
std::map< uint64_t, PaintRegion > PaintRegionMap
Definition: diff_context.h:41
static constexpr SkRect kGiantRect
Definition: layer.h:50
Definition: ref_ptr.h:256
Definition: SkSize.h:16
static constexpr SkISize MakeEmpty()
Definition: SkSize.h:22
std::unique_ptr< LayerTree > layer_tree
The target layer tree to be drawn.
Definition: layer_tree.h:98
int64_t view_id
The target view to draw to.
Definition: layer_tree.h:96
float device_pixel_ratio
The pixel ratio of the target view.
Definition: layer_tree.h:100
LayerTreeTask(int64_t view_id, std::unique_ptr< LayerTree > layer_tree, float device_pixel_ratio)
Definition: layer_tree.h:88