compositing.dart 9.4 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of dart_ui;

A
Adam Barth 已提交
7
/// An opaque object representing a composited scene.
H
Hixie 已提交
8 9 10 11 12 13 14 15 16 17 18 19
///
/// To create a Scene object, use a [SceneBuilder].
///
/// Scene objects can be displayed on the screen using the
/// [Window.render] method.
class Scene extends NativeFieldWrapperClass2 {
  /// Creates an uninitialized Scene object.
  ///
  /// Calling the Scene constructor directly will not create a useable
  /// object. To create a Scene object, use a [SceneBuilder].
  Scene(); // (this constructor is here just so we can document it)

A
Adam Barth 已提交
20 21 22
  /// Releases the resources used by this scene.
  ///
  /// After calling this function, the scene is cannot be used further.
23 24 25
  void dispose() native "Scene_dispose";
}

A
Adam Barth 已提交
26
/// Builds a [Scene] containing the given visuals.
H
Hixie 已提交
27 28 29 30 31 32
///
/// A [Scene] can then be rendered using [Window.render].
///
/// To draw graphical operations onto a [Scene], first create a
/// [Picture] using a [PictureRecorder] and a [Canvas], and then add
/// it to the scene using [addPicture].
33
class SceneBuilder extends NativeFieldWrapperClass2 {
H
Hixie 已提交
34 35
  /// Creates an empty [SceneBuilder] object.
  SceneBuilder() { _constructor(); }
A
Adam Barth 已提交
36
  void _constructor() native "SceneBuilder_constructor";
37

A
Adam Barth 已提交
38 39 40 41 42
  /// Pushes a transform operation onto the operation stack.
  ///
  /// The objects are transformed by the given matrix before rasterization.
  ///
  /// See [pop] for details about the operation stack.
43 44 45 46 47 48 49 50
  void pushTransform(Float64List matrix4) {
    if (matrix4 == null)
      throw new ArgumentError("[matrix4] argument cannot be null");
    if (matrix4.length != 16)
      throw new ArgumentError("[matrix4] must have 16 entries.");
    _pushTransform(matrix4);
  }
  void _pushTransform(Float64List matrix4) native "SceneBuilder_pushTransform";
A
Adam Barth 已提交
51 52 53 54 55 56

  /// Pushes a rectangular clip operation onto the operation stack.
  ///
  /// Rasterization outside the given rectangle is discarded.
  ///
  /// See [pop] for details about the operation stack.
57 58 59 60 61 62 63
  void pushClipRect(Rect rect) {
    _pushClipRect(rect.left, rect.right, rect.top, rect.bottom);
  }
  void _pushClipRect(double left,
                     double right,
                     double top,
                     double bottom) native "SceneBuilder_pushClipRect";
A
Adam Barth 已提交
64 65 66 67 68 69

  /// Pushes a rounded-rectangular clip operation onto the operation stack.
  ///
  /// Rasterization outside the given rounded rectangle is discarded.
  ///
  /// See [pop] for details about the operation stack.
70 71
  void pushClipRRect(RRect rrect) => _pushClipRRect(rrect._value);
  void _pushClipRRect(Float32List rrect) native "SceneBuilder_pushClipRRect";
A
Adam Barth 已提交
72 73 74 75 76 77

  /// Pushes a path clip operation onto the operation stack.
  ///
  /// Rasterization outside the given path is discarded.
  ///
  /// See [pop] for details about the operation stack.
A
Adam Barth 已提交
78
  void pushClipPath(Path path) native "SceneBuilder_pushClipPath";
A
Adam Barth 已提交
79 80 81 82 83 84 85 86 87

  /// Pushes an opacity operation onto the operation stack.
  ///
  /// The given alpha value is blended into the alpha value of the objects'
  /// rasterization. An alpha value of 0 makes the objects entirely invisible.
  /// An alpha value of 255 has no effect (i.e., the objects retain the current
  /// opacity).
  ///
  /// See [pop] for details about the operation stack.
A
Adam Barth 已提交
88
  void pushOpacity(int alpha) native "SceneBuilder_pushOpacity";
A
Adam Barth 已提交
89 90 91 92 93 94 95

  /// Pushes a color filter operation onto the operation stack.
  ///
  /// The given color is applied to the objects' rasterization using the given
  /// transfer mode.
  ///
  /// See [pop] for details about the operation stack.
96 97 98 99
  void pushColorFilter(Color color, TransferMode transferMode) {
    _pushColorFilter(color.value, transferMode.index);
  }
  void _pushColorFilter(int color, int transferMode) native "SceneBuilder_pushColorFilter";
A
Adam Barth 已提交
100

101 102 103 104 105 106 107 108
  /// Pushes a backdrop filter operation onto the operation stack.
  ///
  /// The given filter is applied to the current contents of the scene prior to
  /// rasterizing the given objects.
  ///
  /// See [pop] for details about the operation stack.
  void pushBackdropFilter(ImageFilter filter) native "SceneBuilder_pushBackdropFilter";

A
Adam Barth 已提交
109 110 111 112 113 114
  /// Pushes a shader mask operation onto the operation stack.
  ///
  /// The given shader is applied to the object's rasterization in the given
  /// rectangle using the given transfer mode.
  ///
  /// See [pop] for details about the operation stack.
115 116 117 118 119 120 121 122 123 124 125 126 127 128
  void pushShaderMask(Shader shader, Rect maskRect, TransferMode transferMode) {
    _pushShaderMask(shader,
                    maskRect.left,
                    maskRect.right,
                    maskRect.top,
                    maskRect.bottom,
                    transferMode.index);
  }
  void _pushShaderMask(Shader shader,
                       double maskRectLeft,
                       double maskRectRight,
                       double maskRectTop,
                       double maskRectBottom,
                       int transferMode) native "SceneBuilder_pushShaderMask";
129

A
Adam Barth 已提交
130 131 132 133 134 135
  /// Ends the effect of the most recently pushed operation.
  ///
  /// Internally the scene builder maintains a stack of operations. Each of the
  /// operations in the stack applies to each of the objects added to the scene.
  /// Calling this function removes the most recently added operation from the
  /// stack.
136 137
  void pop() native "SceneBuilder_pop";

A
Adam Barth 已提交
138 139 140 141 142
  /// Adds an object to the scene that displays performance statistics.
  ///
  /// Useful during development to assess the performance of the application.
  /// The enabledOptions controls which statistics are displayed. The bounds
  /// controls where the statistics are displayed.
H
Hixie 已提交
143 144
  ///
  /// enabledOptions is a bit field with the following bits defined:
H
Hixie 已提交
145 146 147 148
  ///  - 0x01: displayRasterizerStatistics - show GPU thread frame time
  ///  - 0x02: visualizeRasterizerStatistics - graph GPU thread frame times
  ///  - 0x04: displayEngineStatistics - show UI thread frame time
  ///  - 0x08: visualizeEngineStatistics - graph UI thread frame times
H
Hixie 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161
  /// Set enabledOptions to 0x0F to enable all the currently defined features.
  ///
  /// The "UI thread" is the thread that includes all the execution of
  /// the main Dart isolate (the isolate that can call
  /// [Window.render]). The UI thread frame time is the total time
  /// spent executing the [Window.onBeginFrame] callback. The "GPU
  /// thread" is the thread (running on the CPU) that subsequently
  /// processes the [Scene] provided by the Dart code to turn it into
  /// GPU commands and send it to the GPU.
  ///
  /// See also the [PerformanceOverlayOption] enum in the rendering library.
  /// for more details.
  // Values above must match constants in //engine/src/sky/compositor/performance_overlay_layer.h
162 163 164 165 166 167 168 169 170 171 172 173
  void addPerformanceOverlay(int enabledOptions, Rect bounds) {
    _addPerformanceOverlay(enabledOptions,
                           bounds.left,
                           bounds.right,
                           bounds.top,
                           bounds.bottom);
  }
  void _addPerformanceOverlay(int enabledOptions,
                              double left,
                              double right,
                              double top,
                              double bottom) native "SceneBuilder_addPerformanceOverlay";
A
Adam Barth 已提交
174

H
Hixie 已提交
175
  /// Adds a [Picture] to the scene.
A
Adam Barth 已提交
176 177
  ///
  /// The picture is rasterized at the given offset.
A
Adam Barth 已提交
178
  void addPicture(Offset offset, Picture picture, { bool isComplexHint: false, bool willChangeHint: false }) {
179
    int hints = 0;
A
Adam Barth 已提交
180
    if (isComplexHint)
181
      hints |= 1;
A
Adam Barth 已提交
182
    if (willChangeHint)
183 184
      hints |= 2;
    _addPicture(offset.dx, offset.dy, picture, hints);
185
  }
186
  void _addPicture(double dx, double dy, Picture picture, int hints) native "SceneBuilder_addPicture";
A
Adam Barth 已提交
187

188 189
  /// (Fuchsia-only) Adds a scene rendered by another application to the scene
  /// for this application.
A
Adam Barth 已提交
190 191
  ///
  /// Applications typically obtain scene tokens when embedding other views via
192 193
  /// the Fuchsia view manager, but this function is agnostic as to the source
  /// of scene token.
194
  void addChildScene(Offset offset,
195
                     double devicePixelRatio,
196 197
                     int physicalWidth,
                     int physicalHeight,
198 199 200 201 202 203 204 205 206 207 208 209 210 211
                     int sceneToken) {
    _addChildScene(offset.dx,
                   offset.dy,
                   devicePixelRatio,
                   physicalWidth,
                   physicalHeight,
                   sceneToken);
  }
  void _addChildScene(double dx,
                      double dy,
                      double devicePixelRatio,
                      int physicalWidth,
                      int physicalHeight,
                      int sceneToken) native "SceneBuilder_addChildScene";
A
Adam Barth 已提交
212 213 214 215 216 217 218

  /// Sets a threshold after which additional debugging information should be recorded.
  ///
  /// Currently this interface is difficult to use by end-developers. If you're
  /// interested in using this feature, please contact [flutter-dev](https://groups.google.com/forum/#!forum/flutter-dev).
  /// We'll hopefully be able to figure out how to make this feature more useful
  /// to you.
219 220
  void setRasterizerTracingThreshold(int frameInterval) native "SceneBuilder_setRasterizerTracingThreshold";

A
Adam Barth 已提交
221 222
  /// Finishes building the scene.
  ///
H
Hixie 已提交
223 224 225
  /// Returns a [Scene] containing the objects that have been added to
  /// this scene builder. The [Scene] can then be displayed on the
  /// screen with [Window.render].
A
Adam Barth 已提交
226 227 228
  ///
  /// After calling this function, the scene builder object is invalid and
  /// cannot be used further.
229 230
  Scene build() native "SceneBuilder_build";
}