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 74 void addRetained(fml::RefPtr<EngineLayer> retainedLayer); 75 76 void pop(); 77 78 void addPerformanceOverlay(uint64_t enabledOptions, 79 double left, 80 double right, 81 double top, 82 double bottom); 83 84 void addPicture(double dx, double dy, Picture* picture, int hints); 85 86 void addTexture(double dx, 87 double dy, 88 double width, 89 double height, 90 int64_t textureId, 91 bool freeze, 92 uint8_t opacity); 93 94 void addPlatformView(double dx, 95 double dy, 96 double width, 97 double height, 98 int64_t viewId); 99 100 #if defined(OS_FUCHSIA) 101 void addChildScene(double dx, 102 double dy, 103 double width, 104 double height, 105 SceneHost* sceneHost, 106 bool hitTestable); 107 #endif 108 109 void setRasterizerTracingThreshold(uint32_t frameInterval); 110 111 void setCheckerboardRasterCacheImages(bool checkerboard); 112 void setCheckerboardOffscreenLayers(bool checkerboard); 113 114 fml::RefPtr<Scene> build(); 115 116 static void RegisterNatives(tonic::DartLibraryNatives* natives); 117 118 private: 119 SceneBuilder(); 120 121 std::shared_ptr<flutter::ContainerLayer> root_layer_; 122 flutter::ContainerLayer* current_layer_ = nullptr; 123 124 int rasterizer_tracing_threshold_ = 0; 125 bool checkerboard_raster_cache_images_ = false; 126 bool checkerboard_offscreen_layers_ = false; 127 128 void PushLayer(std::shared_ptr<flutter::ContainerLayer> layer); 129 130 FML_DISALLOW_COPY_AND_ASSIGN(SceneBuilder); 131 }; 132 133 } // namespace flutter 134 135 #endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ 136