SurfaceFrame root DisplayLists will no longer prepare an RTree (flutter/engine#48422)

The root slice of a surface frame was requesting the construction of an RTree from its DisplayList when it was built from a layer tree, but since the layer tree already does branch culling, it would not benefit from any further culling during `DisplayList::Dispatch`. Further, if there are platform views present in the layer tree then they will need an RTree to accurately convey "pixel ownership" information to the platform, but the root slice lives below any and all platform views, so it is the only slice that doesn't need an RTree for that case.

The cost of having an RTree in that slice was the accumulation of information and lists of rects that would never prove useful.
This commit is contained in:
Jim Graham
2023-11-27 15:27:34 -08:00
committed by GitHub
parent f9dd3b4dc9
commit 1f0d7cd7ea
5 changed files with 41 additions and 20 deletions

View File

@@ -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);

View File

@@ -18,6 +18,7 @@ DlCanvas* DisplayListEmbedderViewSlice::canvas() {
void DisplayListEmbedderViewSlice::end_recording() {
display_list_ = builder_->Build();
FML_DCHECK(display_list_->has_rtree());
builder_ = nullptr;
}

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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();