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 all commits
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
17 changes: 6 additions & 11 deletions flow/layers/layer_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,10 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
}
}

sk_sp<SkPicture> LayerTree::Flatten(const SkRect& bounds) {
sk_sp<DisplayList> LayerTree::Flatten(const SkRect& bounds) {
TRACE_EVENT0("flutter", "LayerTree::Flatten");

SkPictureRecorder recorder;
auto* canvas = recorder.beginRecording(bounds);

if (!canvas) {
return nullptr;
}
DisplayListCanvasRecorder builder(bounds);

MutatorsStack unused_stack;
const FixedRefreshRateStopwatch unused_stopwatch;
Expand All @@ -147,14 +142,14 @@ sk_sp<SkPicture> LayerTree::Flatten(const SkRect& bounds) {
// clang-format on
};

SkISize canvas_size = canvas->getBaseLayerSize();
SkISize canvas_size = builder.getBaseLayerSize();
SkNWayCanvas internal_nodes_canvas(canvas_size.width(), canvas_size.height());
internal_nodes_canvas.addCanvas(canvas);
internal_nodes_canvas.addCanvas(&builder);

Layer::PaintContext paint_context = {
// clang-format off
.internal_nodes_canvas = &internal_nodes_canvas,
.leaf_nodes_canvas = canvas,
.leaf_nodes_canvas = &builder,
.gr_context = nullptr,
.view_embedder = nullptr,
.raster_time = unused_stopwatch,
Expand All @@ -178,7 +173,7 @@ sk_sp<SkPicture> LayerTree::Flatten(const SkRect& bounds) {
}
}

return recorder.finishRecordingAsPicture();
return builder.Build();
}

} // namespace flutter
2 changes: 1 addition & 1 deletion flow/layers/layer_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LayerTree {
void Paint(CompositorContext::ScopedFrame& frame,
bool ignore_raster_cache = false) const;

sk_sp<SkPicture> Flatten(const SkRect& bounds);
sk_sp<DisplayList> Flatten(const SkRect& bounds);

Layer* root_layer() const { return root_layer_.get(); }

Expand Down
20 changes: 10 additions & 10 deletions lib/ui/painting/picture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ Dart_Handle Picture::toImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
if (display_list_.skia_object()) {
return RasterizeToImage(
[display_list = display_list_.skia_object()](SkCanvas* canvas) {
display_list->RenderTo(canvas);
},
width, height, raw_image_callback);
return RasterizeToImage(display_list_.skia_object(), width, height,
raw_image_callback);
} else {
if (!picture_.skia_object()) {
return tonic::ToDart("Picture is null");
}
return RasterizeToImage(picture_.skia_object(), width, height,
raw_image_callback);
return RasterizeToImage(
[picture = picture_.skia_object()](SkCanvas* canvas) {
canvas->drawPicture(picture);
},
width, height, raw_image_callback);
}
}

Expand All @@ -88,13 +88,13 @@ size_t Picture::GetAllocationSize() const {
}
}

Dart_Handle Picture::RasterizeToImage(sk_sp<SkPicture> picture,
Dart_Handle Picture::RasterizeToImage(sk_sp<DisplayList> display_list,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
return RasterizeToImage(
[picture](SkCanvas* canvas) { canvas->drawPicture(picture); }, width,
height, raw_image_callback);
[display_list](SkCanvas* canvas) { display_list->RenderTo(canvas); },
width, height, raw_image_callback);
}

Dart_Handle Picture::RasterizeToImage(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Picture : public RefCountedDartWrappable<Picture> {

static void RegisterNatives(tonic::DartLibraryNatives* natives);

static Dart_Handle RasterizeToImage(sk_sp<SkPicture> picture,
static Dart_Handle RasterizeToImage(sk_sp<DisplayList> display_list,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback);
Expand Down
2 changes: 1 addition & 1 deletion testing/dart/observatory/tracing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ void main() {
}
}
expect(saveLayerRecordCount, 3);
expect(saveLayerCount, 3);
expect(saveLayerCount, 6);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change from 3 to 6? That seems odd, like we are getting double-accounting here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's because scene.toImage now replays the display list.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, actually, it is because the leaf_nodes_builder is not set so DisplayListLayer::Paint will replay its DL into the flattened DL rather than inserting it by reference. Then later the flattened DL will replay the saveLayer calls a second time and they will be double-accounted.

});
}