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

SurfaceFrame root DisplayLists will no longer prepare an RTree #48422

Merged
merged 1 commit into from
Nov 27, 2023
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
7 changes: 1 addition & 6 deletions display_list/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,12 @@ void DisplayList::Dispatch(DlOpReceiver& receiver,
if (cull_rect.isEmpty()) {
return;
}
if (cull_rect.contains(bounds())) {
if (!has_rtree() || cull_rect.contains(bounds())) {
Dispatch(receiver);
return;
}
const DlRTree* rtree = this->rtree().get();
FML_DCHECK(rtree != nullptr);
if (rtree == nullptr) {
FML_LOG(ERROR) << "dispatched with culling rect on DL with no rtree";
Dispatch(receiver);
return;
}
uint8_t* ptr = storage_.get();
std::vector<int> rect_indices;
rtree->search(cull_rect, &rect_indices);
Expand Down
1 change: 1 addition & 0 deletions flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DlCanvas* DisplayListEmbedderViewSlice::canvas() {

void DisplayListEmbedderViewSlice::end_recording() {
display_list_ = builder_->Build();
FML_DCHECK(display_list_->has_rtree());
builder_ = nullptr;
}

Expand Down
9 changes: 7 additions & 2 deletions flow/surface_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
canvas_ = &adapter_;
} else if (display_list_fallback) {
FML_DCHECK(!frame_size.isEmpty());
dl_builder_ =
sk_make_sp<DisplayListBuilder>(SkRect::Make(frame_size), true);
// The root frame of a surface will be filled by the layer_tree which
// performs branch culling so it will be unlikely to need an rtree for
// further culling during `DisplayList::Dispatch`. Further, this canvas
// will live underneath any platform views so we do not need to compute
// exact coverage to describe "pixel ownership" to the platform.
dl_builder_ = sk_make_sp<DisplayListBuilder>(SkRect::Make(frame_size),
/*prepare_rtree=*/false);
canvas_ = dl_builder_.get();
}
}
Expand Down
38 changes: 28 additions & 10 deletions flow/surface_frame_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,45 @@ namespace flutter {

TEST(FlowTest, SurfaceFrameDoesNotSubmitInDtor) {
SurfaceFrame::FramebufferInfo framebuffer_info;
auto callback = [](const SurfaceFrame&, DlCanvas*) {
EXPECT_FALSE(true);
return true;
};
auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/
[](const SurfaceFrame&, DlCanvas*) {
EXPECT_FALSE(true);
return true;
},
SkISize::Make(800, 600));
/*surface=*/nullptr,
/*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/callback,
/*frame_size=*/SkISize::Make(800, 600));
surface_frame.reset();
}

TEST(FlowTest, SurfaceFrameDoesNotHaveEmptyCanvas) {
SurfaceFrame::FramebufferInfo framebuffer_info;
auto callback = [](const SurfaceFrame&, DlCanvas*) { return true; };
SurfaceFrame frame(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; },
/*surface=*/nullptr,
/*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/callback,
/*frame_size=*/SkISize::Make(800, 600),
/*context_result=*/nullptr, /*display_list_fallback=*/true);
/*context_result=*/nullptr,
/*display_list_fallback=*/true);

EXPECT_FALSE(frame.Canvas()->GetLocalClipBounds().isEmpty());
EXPECT_FALSE(frame.Canvas()->QuickReject(SkRect::MakeLTRB(10, 10, 50, 50)));
}

TEST(FlowTest, SurfaceFrameDoesNotPrepareRtree) {
SurfaceFrame::FramebufferInfo framebuffer_info;
auto callback = [](const SurfaceFrame&, DlCanvas*) { return true; };
auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr,
/*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/callback,
/*frame_size=*/SkISize::Make(800, 600),
/*context_result=*/nullptr,
/*display_list_fallback=*/true);
surface_frame->Canvas()->DrawRect(SkRect::MakeWH(100, 100), DlPaint());
EXPECT_FALSE(surface_frame->BuildDisplayList()->has_rtree());
}

} // namespace flutter
6 changes: 4 additions & 2 deletions lib/ui/painting/picture_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ void PictureRecorder::endRecording(Dart_Handle dart_picture) {
return;
}

Picture::CreateAndAssociateWithDartWrapper(dart_picture,
display_list_builder_->Build());
auto display_list = display_list_builder_->Build();
display_list_builder_ = nullptr;

FML_DCHECK(display_list->has_rtree());
Picture::CreateAndAssociateWithDartWrapper(dart_picture, display_list);

canvas_->Invalidate();
canvas_ = nullptr;
ClearDartWrapper();
Expand Down