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_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ |
6 | #define FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ |
7 | |
8 | #include <cstdint> |
9 | #include <memory> |
10 | #include <vector> |
11 | |
12 | #include "flutter/flow/layers/container_layer.h" |
13 | #include "flutter/lib/ui/compositing/scene.h" |
14 | #include "flutter/lib/ui/dart_wrapper.h" |
15 | #include "flutter/lib/ui/painting/color_filter.h" |
16 | #include "flutter/lib/ui/painting/engine_layer.h" |
17 | #include "flutter/lib/ui/painting/image_filter.h" |
18 | #include "flutter/lib/ui/painting/path.h" |
19 | #include "flutter/lib/ui/painting/picture.h" |
20 | #include "flutter/lib/ui/painting/rrect.h" |
21 | #include "flutter/lib/ui/painting/shader.h" |
22 | #include "third_party/tonic/typed_data/typed_list.h" |
23 | |
24 | namespace flutter { |
25 | |
26 | class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> { |
27 | DEFINE_WRAPPERTYPEINFO(); |
28 | FML_FRIEND_MAKE_REF_COUNTED(SceneBuilder); |
29 | |
30 | public: |
31 | static void Create(Dart_Handle wrapper) { |
32 | UIDartState::ThrowIfUIOperationsProhibited(); |
33 | auto res = fml::MakeRefCounted<SceneBuilder>(); |
34 | res->AssociateWithDartWrapper(wrappable: wrapper); |
35 | } |
36 | |
37 | ~SceneBuilder() override; |
38 | |
39 | void pushTransformHandle(Dart_Handle layer_handle, |
40 | Dart_Handle matrix4_handle, |
41 | fml::RefPtr<EngineLayer> oldLayer) { |
42 | tonic::Float64List matrix4(matrix4_handle); |
43 | pushTransform(layer_handle, matrix4, oldLayer); |
44 | } |
45 | void pushTransform(Dart_Handle layer_handle, |
46 | tonic::Float64List& matrix4, |
47 | const fml::RefPtr<EngineLayer>& oldLayer); |
48 | void pushOffset(Dart_Handle layer_handle, |
49 | double dx, |
50 | double dy, |
51 | const fml::RefPtr<EngineLayer>& oldLayer); |
52 | void pushClipRect(Dart_Handle layer_handle, |
53 | double left, |
54 | double right, |
55 | double top, |
56 | double bottom, |
57 | int clipBehavior, |
58 | const fml::RefPtr<EngineLayer>& oldLayer); |
59 | void pushClipRRect(Dart_Handle layer_handle, |
60 | const RRect& rrect, |
61 | int clipBehavior, |
62 | const fml::RefPtr<EngineLayer>& oldLayer); |
63 | void pushClipPath(Dart_Handle layer_handle, |
64 | const CanvasPath* path, |
65 | int clipBehavior, |
66 | const fml::RefPtr<EngineLayer>& oldLayer); |
67 | void pushOpacity(Dart_Handle layer_handle, |
68 | int alpha, |
69 | double dx, |
70 | double dy, |
71 | const fml::RefPtr<EngineLayer>& oldLayer); |
72 | void pushColorFilter(Dart_Handle layer_handle, |
73 | const ColorFilter* color_filter, |
74 | const fml::RefPtr<EngineLayer>& oldLayer); |
75 | void pushImageFilter(Dart_Handle layer_handle, |
76 | const ImageFilter* image_filter, |
77 | double dx, |
78 | double dy, |
79 | const fml::RefPtr<EngineLayer>& oldLayer); |
80 | void pushBackdropFilter(Dart_Handle layer_handle, |
81 | ImageFilter* filter, |
82 | int blendMode, |
83 | const fml::RefPtr<EngineLayer>& oldLayer); |
84 | void pushShaderMask(Dart_Handle layer_handle, |
85 | Shader* shader, |
86 | double maskRectLeft, |
87 | double maskRectRight, |
88 | double maskRectTop, |
89 | double maskRectBottom, |
90 | int blendMode, |
91 | int filterQualityIndex, |
92 | const fml::RefPtr<EngineLayer>& oldLayer); |
93 | |
94 | void addRetained(const fml::RefPtr<EngineLayer>& retainedLayer); |
95 | |
96 | void pop(); |
97 | |
98 | void addPerformanceOverlay(uint64_t enabledOptions, |
99 | double left, |
100 | double right, |
101 | double top, |
102 | double bottom); |
103 | |
104 | void addPicture(double dx, double dy, Picture* picture, int hints); |
105 | |
106 | void addTexture(double dx, |
107 | double dy, |
108 | double width, |
109 | double height, |
110 | int64_t textureId, |
111 | bool freeze, |
112 | int filterQuality); |
113 | |
114 | void addPlatformView(double dx, |
115 | double dy, |
116 | double width, |
117 | double height, |
118 | int64_t viewId); |
119 | |
120 | void setRasterizerTracingThreshold(uint32_t frameInterval); |
121 | void setCheckerboardRasterCacheImages(bool checkerboard); |
122 | void setCheckerboardOffscreenLayers(bool checkerboard); |
123 | |
124 | void build(Dart_Handle scene_handle); |
125 | |
126 | const std::vector<std::shared_ptr<ContainerLayer>>& layer_stack() { |
127 | return layer_stack_; |
128 | } |
129 | |
130 | private: |
131 | SceneBuilder(); |
132 | |
133 | void AddLayer(std::shared_ptr<Layer> layer); |
134 | void PushLayer(std::shared_ptr<ContainerLayer> layer); |
135 | void PopLayer(); |
136 | |
137 | std::vector<std::shared_ptr<ContainerLayer>> layer_stack_; |
138 | int rasterizer_tracing_threshold_ = 0; |
139 | bool checkerboard_raster_cache_images_ = false; |
140 | bool checkerboard_offscreen_layers_ = false; |
141 | |
142 | FML_DISALLOW_COPY_AND_ASSIGN(SceneBuilder); |
143 | }; |
144 | |
145 | } // namespace flutter |
146 | |
147 | #endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ |
148 | |