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

Commit 0564f08

Browse files
authored
Revert "Display list R-Tree culling (#38429)"
This reverts commit 147ac7d.
1 parent 77db886 commit 0564f08

15 files changed

+375
-1295
lines changed

ci/licenses_golden/excluded_files

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
../../../flutter/display_list/display_list_matrix_clip_tracker_unittests.cc
4040
../../../flutter/display_list/display_list_paint_unittests.cc
4141
../../../flutter/display_list/display_list_path_effect_unittests.cc
42-
../../../flutter/display_list/display_list_rtree_unittests.cc
4342
../../../flutter/display_list/display_list_unittests.cc
4443
../../../flutter/display_list/display_list_utils_unittests.cc
4544
../../../flutter/display_list/display_list_vertices_unittests.cc

display_list/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ if (enable_unittests) {
109109
"display_list_matrix_clip_tracker_unittests.cc",
110110
"display_list_paint_unittests.cc",
111111
"display_list_path_effect_unittests.cc",
112-
"display_list_rtree_unittests.cc",
113112
"display_list_unittests.cc",
114113
"display_list_utils_unittests.cc",
115114
"display_list_vertices_unittests.cc",

display_list/display_list.cc

Lines changed: 11 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -38,144 +38,31 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
3838
op_count_(op_count),
3939
nested_byte_count_(nested_byte_count),
4040
nested_op_count_(nested_op_count),
41-
unique_id_(next_unique_id()),
4241
bounds_(bounds),
4342
can_apply_group_opacity_(can_apply_group_opacity),
44-
rtree_(std::move(rtree)) {}
45-
46-
DisplayList::~DisplayList() {
47-
uint8_t* ptr = storage_.get();
48-
DisposeOps(ptr, ptr + byte_count_);
49-
}
50-
51-
uint32_t DisplayList::next_unique_id() {
43+
rtree_(std::move(rtree)) {
5244
static std::atomic<uint32_t> next_id{1};
53-
uint32_t id;
5445
do {
55-
id = next_id.fetch_add(+1, std::memory_order_relaxed);
56-
} while (id == 0);
57-
return id;
46+
unique_id_ = next_id.fetch_add(+1, std::memory_order_relaxed);
47+
} while (unique_id_ == 0);
5848
}
5949

60-
class Culler {
61-
public:
62-
virtual bool init(DispatchContext& context) = 0;
63-
virtual void update(DispatchContext& context) = 0;
64-
};
65-
class NopCuller : public Culler {
66-
public:
67-
static NopCuller instance;
68-
69-
bool init(DispatchContext& context) override {
70-
// Setting next_render_index to 0 means that
71-
// all rendering ops will be at or after that
72-
// index so they will execute and all restore
73-
// indices will be after it as well so all
74-
// clip and transform operations will execute.
75-
context.next_render_index = 0;
76-
return true;
77-
}
78-
void update(DispatchContext& context) override {}
79-
};
80-
NopCuller NopCuller::instance = NopCuller();
81-
class VectorCuller : public Culler {
82-
public:
83-
VectorCuller(const DlRTree* rtree, const std::vector<int>& rect_indices)
84-
: rtree_(rtree), cur_(rect_indices.begin()), end_(rect_indices.end()) {}
85-
86-
bool init(DispatchContext& context) override {
87-
if (cur_ < end_) {
88-
context.next_render_index = rtree_->id(*cur_++);
89-
return true;
90-
} else {
91-
// Setting next_render_index to MAX_INT means that
92-
// all rendering ops will be "before" that index and
93-
// they will skip themselves and all clip and transform
94-
// ops will see that the next render index is not
95-
// before the next restore index (even if both are MAX_INT)
96-
// and so they will also not execute.
97-
// None of this really matters because returning false
98-
// here should cause the Dispatch operation to abort,
99-
// but this value is conceptually correct if that short
100-
// circuit optimization isn't used.
101-
context.next_render_index = std::numeric_limits<int>::max();
102-
return false;
103-
}
104-
}
105-
void update(DispatchContext& context) override {
106-
if (++context.cur_index > context.next_render_index) {
107-
while (cur_ < end_) {
108-
context.next_render_index = rtree_->id(*cur_++);
109-
if (context.next_render_index >= context.cur_index) {
110-
// It should be rare that we have duplicate indices
111-
// but if we do, then having a while loop is a cheap
112-
// insurance for those cases.
113-
// The main cause of duplicate indices is when a
114-
// DrawDisplayListOp was added to this DisplayList and
115-
// both are computing an R-Tree, in which case the
116-
// builder method will forward all of the child
117-
// DisplayList's rects to this R-Tree with the same
118-
// op_index.
119-
return;
120-
}
121-
}
122-
context.next_render_index = std::numeric_limits<int>::max();
123-
}
124-
}
125-
126-
private:
127-
const DlRTree* rtree_;
128-
std::vector<int>::const_iterator cur_;
129-
std::vector<int>::const_iterator end_;
130-
};
131-
132-
void DisplayList::Dispatch(Dispatcher& ctx) const {
133-
uint8_t* ptr = storage_.get();
134-
Dispatch(ctx, ptr, ptr + byte_count_, NopCuller::instance);
135-
}
136-
void DisplayList::Dispatch(Dispatcher& ctx, const SkRect& cull_rect) const {
137-
if (cull_rect.isEmpty()) {
138-
return;
139-
}
140-
if (cull_rect.contains(bounds())) {
141-
Dispatch(ctx);
142-
return;
143-
}
144-
const DlRTree* rtree = this->rtree().get();
145-
FML_DCHECK(rtree != nullptr);
146-
if (rtree == nullptr) {
147-
FML_LOG(ERROR) << "dispatched with culling rect on DL with no rtree";
148-
Dispatch(ctx);
149-
return;
150-
}
50+
DisplayList::~DisplayList() {
15151
uint8_t* ptr = storage_.get();
152-
std::vector<int> rect_indices;
153-
rtree->search(cull_rect, &rect_indices);
154-
VectorCuller culler(rtree, rect_indices);
155-
Dispatch(ctx, ptr, ptr + byte_count_, culler);
52+
DisposeOps(ptr, ptr + byte_count_);
15653
}
15754

15855
void DisplayList::Dispatch(Dispatcher& dispatcher,
15956
uint8_t* ptr,
160-
uint8_t* end,
161-
Culler& culler) const {
162-
DispatchContext context = {
163-
.dispatcher = dispatcher,
164-
.cur_index = 0,
165-
// next_render_index will be initialized by culler.init()
166-
.next_restore_index = std::numeric_limits<int>::max(),
167-
};
168-
if (!culler.init(context)) {
169-
return;
170-
}
57+
uint8_t* end) const {
17158
while (ptr < end) {
17259
auto op = reinterpret_cast<const DLOp*>(ptr);
17360
ptr += op->size;
17461
FML_DCHECK(ptr <= end);
17562
switch (op->type) {
176-
#define DL_OP_DISPATCH(name) \
177-
case DisplayListOpType::k##name: \
178-
static_cast<const name##Op*>(op)->dispatch(context); \
63+
#define DL_OP_DISPATCH(name) \
64+
case DisplayListOpType::k##name: \
65+
static_cast<const name##Op*>(op)->dispatch(dispatcher); \
17966
break;
18067

18168
FOR_EACH_DISPLAY_LIST_OP(DL_OP_DISPATCH)
@@ -186,7 +73,6 @@ void DisplayList::Dispatch(Dispatcher& dispatcher,
18673
FML_DCHECK(false);
18774
return;
18875
}
189-
culler.update(context);
19076
}
19177
}
19278

@@ -286,20 +172,12 @@ void DisplayList::RenderTo(DisplayListBuilder* builder,
286172
if (!builder) {
287173
return;
288174
}
289-
if (has_rtree()) {
290-
Dispatch(*builder, builder->getLocalClipBounds());
291-
} else {
292-
Dispatch(*builder);
293-
}
175+
Dispatch(*builder);
294176
}
295177

296178
void DisplayList::RenderTo(SkCanvas* canvas, SkScalar opacity) const {
297179
DisplayListCanvasDispatcher dispatcher(canvas, opacity);
298-
if (has_rtree()) {
299-
Dispatch(dispatcher, canvas->getLocalClipBounds());
300-
} else {
301-
Dispatch(dispatcher);
302-
}
180+
Dispatch(dispatcher);
303181
}
304182

305183
bool DisplayList::Equals(const DisplayList* other) const {

display_list/display_list.h

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ class DisplayListStorage {
235235
std::unique_ptr<uint8_t, FreeDeleter> ptr_;
236236
};
237237

238-
class Culler;
239-
240238
// The base class that contains a sequence of rendering operations
241239
// for dispatch to a Dispatcher. These objects must be instantiated
242240
// through an instance of DisplayListBuilder::build().
@@ -246,8 +244,10 @@ class DisplayList : public SkRefCnt {
246244

247245
~DisplayList();
248246

249-
void Dispatch(Dispatcher& ctx) const;
250-
void Dispatch(Dispatcher& ctx, const SkRect& cull_rect) const;
247+
void Dispatch(Dispatcher& ctx) const {
248+
uint8_t* ptr = storage_.get();
249+
Dispatch(ctx, ptr, ptr + byte_count_);
250+
}
251251

252252
void RenderTo(DisplayListBuilder* builder,
253253
SkScalar opacity = SK_Scalar1) const;
@@ -268,18 +268,17 @@ class DisplayList : public SkRefCnt {
268268

269269
uint32_t unique_id() const { return unique_id_; }
270270

271-
const SkRect& bounds() const { return bounds_; }
271+
const SkRect& bounds() { return bounds_; }
272272

273-
bool has_rtree() const { return rtree_ != nullptr; }
274-
sk_sp<const DlRTree> rtree() const { return rtree_; }
273+
sk_sp<const DlRTree> rtree() { return rtree_; }
275274

276275
bool Equals(const DisplayList* other) const;
277276
bool Equals(const DisplayList& other) const { return Equals(&other); }
278277
bool Equals(sk_sp<const DisplayList> other) const {
279278
return Equals(other.get());
280279
}
281280

282-
bool can_apply_group_opacity() const { return can_apply_group_opacity_; }
281+
bool can_apply_group_opacity() { return can_apply_group_opacity_; }
283282

284283
static void DisposeOps(uint8_t* ptr, uint8_t* end);
285284

@@ -293,25 +292,20 @@ class DisplayList : public SkRefCnt {
293292
bool can_apply_group_opacity,
294293
sk_sp<const DlRTree> rtree);
295294

296-
static uint32_t next_unique_id();
297-
298-
const DisplayListStorage storage_;
299-
const size_t byte_count_;
300-
const unsigned int op_count_;
295+
DisplayListStorage storage_;
296+
size_t byte_count_;
297+
unsigned int op_count_;
301298

302-
const size_t nested_byte_count_;
303-
const unsigned int nested_op_count_;
299+
size_t nested_byte_count_;
300+
unsigned int nested_op_count_;
304301

305-
const uint32_t unique_id_;
306-
const SkRect bounds_;
302+
uint32_t unique_id_;
303+
SkRect bounds_;
307304

308-
const bool can_apply_group_opacity_;
309-
const sk_sp<const DlRTree> rtree_;
305+
bool can_apply_group_opacity_;
306+
sk_sp<const DlRTree> rtree_;
310307

311-
void Dispatch(Dispatcher& ctx,
312-
uint8_t* ptr,
313-
uint8_t* end,
314-
Culler& culler) const;
308+
void Dispatch(Dispatcher& ctx, uint8_t* ptr, uint8_t* end) const;
315309

316310
friend class DisplayListBuilder;
317311
};

0 commit comments

Comments
 (0)