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(); 24 25 ~LayerTree(); 26 27 void Preroll(CompositorContext::ScopedFrame& frame, 28 bool ignore_raster_cache = false); 29 30 #if defined(OS_FUCHSIA) 31 void UpdateScene(SceneUpdateContext& context, 32 scenic::ContainerNode& container); 33 #endif 34 35 void Paint(CompositorContext::ScopedFrame& frame, 36 bool ignore_raster_cache = false) const; 37 38 sk_sp<SkPicture> Flatten(const SkRect& bounds); 39 root_layer()40 Layer* root_layer() const { return root_layer_.get(); } 41 set_root_layer(std::shared_ptr<Layer> root_layer)42 void set_root_layer(std::shared_ptr<Layer> root_layer) { 43 root_layer_ = std::move(root_layer); 44 } 45 frame_size()46 const SkISize& frame_size() const { return frame_size_; } 47 set_frame_size(const SkISize & frame_size)48 void set_frame_size(const SkISize& frame_size) { frame_size_ = frame_size; } 49 50 void RecordBuildTime(fml::TimePoint begin_start); build_start()51 fml::TimePoint build_start() const { return build_start_; } build_finish()52 fml::TimePoint build_finish() const { return build_finish_; } build_time()53 fml::TimeDelta build_time() const { return build_finish_ - build_start_; } 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 set_rasterizer_tracing_threshold(uint32_t interval)58 void set_rasterizer_tracing_threshold(uint32_t interval) { 59 rasterizer_tracing_threshold_ = interval; 60 } 61 rasterizer_tracing_threshold()62 uint32_t rasterizer_tracing_threshold() const { 63 return rasterizer_tracing_threshold_; 64 } 65 set_checkerboard_raster_cache_images(bool checkerboard)66 void set_checkerboard_raster_cache_images(bool checkerboard) { 67 checkerboard_raster_cache_images_ = checkerboard; 68 } 69 set_checkerboard_offscreen_layers(bool checkerboard)70 void set_checkerboard_offscreen_layers(bool checkerboard) { 71 checkerboard_offscreen_layers_ = checkerboard; 72 } 73 74 private: 75 SkISize frame_size_; // Physical pixels. 76 std::shared_ptr<Layer> root_layer_; 77 fml::TimePoint build_start_; 78 fml::TimePoint build_finish_; 79 uint32_t rasterizer_tracing_threshold_; 80 bool checkerboard_raster_cache_images_; 81 bool checkerboard_offscreen_layers_; 82 83 FML_DISALLOW_COPY_AND_ASSIGN(LayerTree); 84 }; 85 86 } // namespace flutter 87 88 #endif // FLUTTER_FLOW_LAYERS_LAYER_TREE_H_ 89