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