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

Commit 78d7128

Browse files
authored
Get bounds from RTree in DLBuilder::Build() (#50253)
This optimization was discovered when reviewing the bounds accumulation code in DisplayListBuilder. There is trivially wasted work in the `Build()` method that can be easily avoided. When a Builder is preparing an RTree, it accumulates a list of bounds for every rendering op, but doesn't union them up front. If you ask the Builder for the bounds of the accumulated ops, it will have to union all of the rectangles to produce an answer. But, if you ask the Builder to produce an RTree, that process will implicitly combine all of the rectangles as a side effect of creating the tree structure - and that RTree object has a bounds method that can return the result directly. This change leverages the construction of the RTree to avoid having to union all of the rects twice which can only save time when constructing the majority of DisplayList objects used in a scene.
1 parent 9040e45 commit 78d7128

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

display_list/dl_builder.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
7676
bool is_safe = is_ui_thread_safe_;
7777
bool affects_transparency = current_layer_->affects_transparent_layer();
7878

79+
sk_sp<DlRTree> rtree = this->rtree();
80+
SkRect bounds = rtree ? rtree->bounds() : this->bounds();
81+
7982
used_ = allocated_ = render_op_count_ = op_index_ = 0;
8083
nested_bytes_ = nested_op_count_ = 0;
8184
is_ui_thread_safe_ = true;
@@ -86,8 +89,8 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
8689
current_ = DlPaint();
8790

8891
return sk_sp<DisplayList>(new DisplayList(
89-
std::move(storage_), bytes, count, nested_bytes, nested_count, bounds(),
90-
compatible, is_safe, affects_transparency, rtree()));
92+
std::move(storage_), bytes, count, nested_bytes, nested_count, bounds,
93+
compatible, is_safe, affects_transparency, std::move(rtree)));
9194
}
9295

9396
DisplayListBuilder::DisplayListBuilder(const SkRect& cull_rect,

display_list/dl_op_records.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct SetRuntimeEffectColorSourceOp : DLOp {
277277
struct SetSceneColorSourceOp : DLOp {
278278
static const auto kType = DisplayListOpType::kSetSceneColorSource;
279279

280-
SetSceneColorSourceOp(const DlSceneColorSource* source)
280+
explicit SetSceneColorSourceOp(const DlSceneColorSource* source)
281281
: source(source->scene_node(), source->camera_matrix()) {}
282282

283283
const DlSceneColorSource source;

0 commit comments

Comments
 (0)