Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class LayerScene implements ui.Scene {

@override
Future<ui.Image> toImage(int width, int height) {
throw UnsupportedError('LayerScene.toImage not implemented.');
ui.Picture picture = layerTree.flatten();
return picture.toImage(width, height);
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/web_ui/lib/src/engine/canvaskit/layer_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ class LayerTree {
rootLayer!.paint(context);
}
}

/// Flattens the tree into a single [ui.Picture].
///
/// This picture does not contain any platform views.
ui.Picture flatten() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a unit-test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

CkPictureRecorder recorder = CkPictureRecorder();
CkCanvas canvas = recorder.beginRecording(ui.Rect.largest);
if (rootLayer != null) {
final PrerollContext prerollContext = PrerollContext(null, null);
rootLayer!.preroll(prerollContext, Matrix4.identity());

CkNWayCanvas internalNodesCanvas = CkNWayCanvas();
internalNodesCanvas.addCanvas(canvas);
final PaintContext paintContext =
PaintContext(internalNodesCanvas, canvas, null, null);
if (rootLayer!.needsPainting) {
rootLayer!.paint(paintContext);
}
}
return recorder.endRecording();
}
}

/// A single frame to be rendered.
Expand Down