Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0892de0

Browse files
committed
Document the new binding hooks for SceneBuilder, PictureRecorder, Canvas
See flutter/flutter#147271 for context. Do not land until flutter/flutter#147271 has landed.
1 parent 5a96cb1 commit 0892de0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/ui/compositing.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ class ShaderMaskEngineLayer extends _EngineLayerWrapper {
233233
/// To draw graphical operations onto a [Scene], first create a
234234
/// [Picture] using a [PictureRecorder] and a [Canvas], and then add
235235
/// it to the scene using [addPicture].
236+
///
237+
/// ## Use with the Flutter framework
238+
///
239+
/// The Flutter framework's [RendererBinding] provides a hook for creating
240+
/// [SceneBuilder] objects ([RendererBinding.createSceneBuilder]) that allows
241+
/// tests to hook into the scene creation logic. When creating a [SceneBuilder]
242+
/// in the context of the Flutter framework, consider calling
243+
/// [RendererBinding.createSceneBuilder] instead of calling the [new
244+
/// SceneBuilder] constructor directly.
245+
///
246+
/// This does not apply when using the `dart:ui` API directly, without using the
247+
/// Flutter framework bindings, `flutter_test` framework, et al.
236248
abstract class SceneBuilder {
237249
factory SceneBuilder() = _NativeSceneBuilder;
238250

lib/ui/painting.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4964,6 +4964,18 @@ enum ClipOp {
49644964
///
49654965
/// The current transform and clip can be saved and restored using the stack
49664966
/// managed by the [save], [saveLayer], and [restore] methods.
4967+
///
4968+
/// ## Use with the Flutter framework
4969+
///
4970+
/// The Flutter framework's [RendererBinding] provides a hook for creating
4971+
/// [Canvas] objects ([RendererBinding.createCanvas]) that allows tests to hook
4972+
/// into the scene creation logic. When creating a [Canvas] that will be used
4973+
/// with a [PictureLayer] as part of the [Scene] in the context of the Flutter
4974+
/// framework, consider calling [RendererBinding.createCanvas] instead of
4975+
/// calling the [new Canvas] constructor directly.
4976+
///
4977+
/// This does not apply when using a canvas to generate a bitmap for other
4978+
/// purposes, e.g. for generating a PNG image using [Picture.toImage].
49674979
abstract class Canvas {
49684980
/// Creates a canvas for recording graphical operations into the
49694981
/// given picture recorder.
@@ -6415,6 +6427,19 @@ base class _NativePicture extends NativeFieldWrapperClass1 implements Picture {
64156427
///
64166428
/// To begin recording, construct a [Canvas] to record the commands.
64176429
/// To end recording, use the [PictureRecorder.endRecording] method.
6430+
///
6431+
/// ## Use with the Flutter framework
6432+
///
6433+
/// The Flutter framework's [RendererBinding] provides a hook for creating
6434+
/// [PictureRecorder] objects ([RendererBinding.createPictureRecorder]) that
6435+
/// allows tests to hook into the scene creation logic. When creating a
6436+
/// [PictureRecorder] and [Canvas] that will be used with a [PictureLayer] as
6437+
/// part of the [Scene] in the context of the Flutter framework, consider
6438+
/// calling [RendererBinding.createPictureRecorder] instead of calling the [new
6439+
/// PictureRecorder] constructor directly.
6440+
///
6441+
/// This does not apply when using a canvas to generate a bitmap for other
6442+
/// purposes, e.g. for generating a PNG image using [Picture.toImage].
64186443
abstract class PictureRecorder {
64196444
/// Creates a new idle PictureRecorder. To associate it with a
64206445
/// [Canvas] and begin recording, pass this [PictureRecorder] to the

0 commit comments

Comments
 (0)