• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stack>
12 
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 "flutter/lib/ui/ui_dart_state.h"
23 
24 #if defined(OS_FUCHSIA)
25 #include "flutter/lib/ui/compositing/scene_host.h"
26 #endif
27 
28 #include "experimental/svg/model/SkSVGDOM.h"
29 #include "third_party/skia/include/core/SkPaint.h"
30 #include "third_party/skia/include/core/SkPath.h"
31 
32 namespace flutter {
33 
34 class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
35   DEFINE_WRAPPERTYPEINFO();
36   FML_FRIEND_MAKE_REF_COUNTED(SceneBuilder);
37 
38  public:
create()39   static fml::RefPtr<SceneBuilder> create() {
40     return fml::MakeRefCounted<SceneBuilder>();
41   }
42 
43   ~SceneBuilder() override;
44 
45   fml::RefPtr<EngineLayer> pushTransform(tonic::Float64List& matrix4);
46   fml::RefPtr<EngineLayer> pushOffset(double dx, double dy);
47   fml::RefPtr<EngineLayer> pushClipRect(double left,
48                                         double right,
49                                         double top,
50                                         double bottom,
51                                         int clipBehavior);
52   fml::RefPtr<EngineLayer> pushClipRRect(const RRect& rrect, int clipBehavior);
53   fml::RefPtr<EngineLayer> pushClipPath(const CanvasPath* path,
54                                         int clipBehavior);
55   fml::RefPtr<EngineLayer> pushOpacity(int alpha, double dx = 0, double dy = 0);
56   fml::RefPtr<EngineLayer> pushColorFilter(const ColorFilter* color_filter);
57   fml::RefPtr<EngineLayer> pushBackdropFilter(ImageFilter* filter);
58   fml::RefPtr<EngineLayer> pushShaderMask(Shader* shader,
59                                           double maskRectLeft,
60                                           double maskRectRight,
61                                           double maskRectTop,
62                                           double maskRectBottom,
63                                           int blendMode);
64   fml::RefPtr<EngineLayer> pushPhysicalShape(const CanvasPath* path,
65                                              double elevation,
66                                              int color,
67                                              int shadowColor,
68                                              int clipBehavior);
69   fml::RefPtr<EngineLayer> PushGradientColorMask(const SkPaint& maskPaint);
70   fml::RefPtr<EngineLayer> PushSvgMask(const sk_sp<SkSVGDOM>& svgDom, double x, double y, double scaleX, double scaleY);
71   fml::RefPtr<EngineLayer> PushPathMask(const SkPaint& maskPaint, const SkPath& maskPath);
72   fml::RefPtr<EngineLayer> PushFilter(const SkPaint& filterPaint);
73   fml::RefPtr<EngineLayer> PushHole(const SkRect& rect, int32_t hole_id);
74 
75   void addRetained(fml::RefPtr<EngineLayer> retainedLayer);
76 
77   void pop();
78 
79   void addPerformanceOverlay(uint64_t enabledOptions,
80                              double left,
81                              double right,
82                              double top,
83                              double bottom);
84 
85   void addPicture(double dx, double dy, Picture* picture, int hints);
86 
87   void addTexture(double dx,
88                   double dy,
89                   double width,
90                   double height,
91                   int64_t textureId,
92                   bool freeze,
93                   uint8_t opacity);
94 
95   void addPlatformView(double dx,
96                        double dy,
97                        double width,
98                        double height,
99                        int64_t viewId);
100 
101 #if defined(OS_FUCHSIA)
102   void addChildScene(double dx,
103                      double dy,
104                      double width,
105                      double height,
106                      SceneHost* sceneHost,
107                      bool hitTestable);
108 #endif
109 
110   void setRasterizerTracingThreshold(uint32_t frameInterval);
111 
112   void setCheckerboardRasterCacheImages(bool checkerboard);
113   void setCheckerboardOffscreenLayers(bool checkerboard);
114 
115   fml::RefPtr<Scene> build();
116 
117   static void RegisterNatives(tonic::DartLibraryNatives* natives);
118 
119  private:
120   SceneBuilder();
121 
122   std::shared_ptr<flutter::ContainerLayer> root_layer_;
123   flutter::ContainerLayer* current_layer_ = nullptr;
124 
125   int rasterizer_tracing_threshold_ = 0;
126   bool checkerboard_raster_cache_images_ = false;
127   bool checkerboard_offscreen_layers_ = false;
128 
129   void PushLayer(std::shared_ptr<flutter::ContainerLayer> layer);
130 
131   FML_DISALLOW_COPY_AND_ASSIGN(SceneBuilder);
132 };
133 
134 }  // namespace flutter
135 
136 #endif  // FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_
137