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

Commit b9df033

Browse files
authored
Migrate DlRTree and DlRegion to DisplayList/Impeller geometry classes (#57175)
Continuing the migration of engine code to the new geometry classes. Only DlRTree and DlRegion are converted in this pass, plus a small amount of associated code.
1 parent 5eedfef commit b9df033

30 files changed

+606
-559
lines changed

display_list/benchmarking/dl_builder_benchmarks.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static void BM_DisplayListDispatchByVectorDefault(
267267
DlOpReceiverIgnore receiver;
268268
while (state.KeepRunning()) {
269269
std::vector<DlIndex> indices =
270-
display_list->GetCulledIndices(display_list->bounds());
270+
display_list->GetCulledIndices(display_list->GetBounds());
271271
for (DlIndex index : indices) {
272272
display_list->Dispatch(receiver, index);
273273
}
@@ -299,8 +299,8 @@ static void BM_DisplayListDispatchByVectorCull(
299299
InvokeAllOps(builder);
300300
}
301301
auto display_list = builder.Build();
302-
SkRect rect = SkRect::MakeLTRB(0, 0, 100, 100);
303-
EXPECT_FALSE(rect.contains(display_list->bounds()));
302+
DlRect rect = DlRect::MakeLTRB(0, 0, 100, 100);
303+
EXPECT_FALSE(rect.Contains(display_list->GetBounds()));
304304
DlOpReceiverIgnore receiver;
305305
while (state.KeepRunning()) {
306306
std::vector<DlIndex> indices = display_list->GetCulledIndices(rect);

display_list/benchmarking/dl_region_benchmarks.cc

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,54 @@
1212

1313
namespace {
1414

15+
using DlIRect = flutter::DlIRect;
16+
1517
template <typename RNG>
16-
std::vector<SkIRect> GenerateRects(RNG& rng,
17-
const SkIRect& bounds,
18+
std::vector<DlIRect> GenerateRects(RNG& rng,
19+
const DlIRect& bounds,
1820
int numRects,
1921
int maxSize) {
20-
auto max_size_x = std::min(maxSize, bounds.width());
21-
auto max_size_y = std::min(maxSize, bounds.height());
22+
auto max_size_x = std::min(maxSize, bounds.GetWidth());
23+
auto max_size_y = std::min(maxSize, bounds.GetHeight());
2224

23-
std::uniform_int_distribution pos_x(bounds.fLeft, bounds.fRight - max_size_x);
24-
std::uniform_int_distribution pos_y(bounds.fTop, bounds.fBottom - max_size_y);
25+
std::uniform_int_distribution pos_x(bounds.GetLeft(),
26+
bounds.GetRight() - max_size_x);
27+
std::uniform_int_distribution pos_y(bounds.GetTop(),
28+
bounds.GetBottom() - max_size_y);
2529
std::uniform_int_distribution size_x(1, max_size_x);
2630
std::uniform_int_distribution size_y(1, max_size_y);
2731

28-
std::vector<SkIRect> rects;
32+
std::vector<DlIRect> rects;
2933
for (int i = 0; i < numRects; ++i) {
30-
SkIRect rect =
31-
SkIRect::MakeXYWH(pos_x(rng), pos_y(rng), size_x(rng), size_y(rng));
34+
DlIRect rect =
35+
DlIRect::MakeXYWH(pos_x(rng), pos_y(rng), size_x(rng), size_y(rng));
3236
rects.push_back(rect);
3337
}
3438
return rects;
3539
}
3640

3741
template <typename RNG>
38-
SkIRect RandomSubRect(RNG& rng, const SkIRect& rect, double size_factor) {
42+
DlIRect RandomSubRect(RNG& rng, const DlIRect& rect, double size_factor) {
3943
FML_DCHECK(size_factor <= 1);
4044

41-
int32_t width = rect.width() * size_factor;
42-
int32_t height = rect.height() * size_factor;
45+
int32_t width = rect.GetWidth() * size_factor;
46+
int32_t height = rect.GetHeight() * size_factor;
4347

44-
std::uniform_int_distribution pos_x(0, rect.width() - width);
45-
std::uniform_int_distribution pos_y(0, rect.height() - height);
48+
std::uniform_int_distribution pos_x(0, rect.GetWidth() - width);
49+
std::uniform_int_distribution pos_y(0, rect.GetHeight() - height);
4650

47-
return SkIRect::MakeXYWH(rect.fLeft + pos_x(rng), rect.fTop + pos_y(rng),
51+
return DlIRect::MakeXYWH(rect.GetLeft() + pos_x(rng),
52+
rect.GetTop() + pos_y(rng), //
4853
width, height);
4954
}
5055

5156
class SkRegionAdapter {
5257
public:
53-
explicit SkRegionAdapter(const std::vector<SkIRect>& rects) {
54-
region_.setRects(rects.data(), rects.size());
58+
explicit SkRegionAdapter(const std::vector<DlIRect>& rects) {
59+
region_.setRects(flutter::ToSkIRects(rects.data()), rects.size());
5560
}
5661

57-
SkIRect getBounds() { return region_.getBounds(); }
62+
DlIRect getBounds() { return flutter::ToDlIRect(region_.getBounds()); }
5863

5964
static SkRegionAdapter unionRegions(const SkRegionAdapter& a1,
6065
const SkRegionAdapter& a2) {
@@ -74,13 +79,15 @@ class SkRegionAdapter {
7479
return region_.intersects(region.region_);
7580
}
7681

77-
bool intersects(const SkIRect& rect) { return region_.intersects(rect); }
82+
bool intersects(const DlIRect& rect) {
83+
return region_.intersects(flutter::ToSkIRect(rect));
84+
}
7885

79-
std::vector<SkIRect> getRects() {
80-
std::vector<SkIRect> rects;
86+
std::vector<DlIRect> getRects() {
87+
std::vector<DlIRect> rects;
8188
SkRegion::Iterator it(region_);
8289
while (!it.done()) {
83-
rects.push_back(it.rect());
90+
rects.push_back(flutter::ToDlIRect(it.rect()));
8491
it.next();
8592
}
8693
return rects;
@@ -92,7 +99,7 @@ class SkRegionAdapter {
9299

93100
class DlRegionAdapter {
94101
public:
95-
explicit DlRegionAdapter(const std::vector<SkIRect>& rects)
102+
explicit DlRegionAdapter(const std::vector<DlIRect>& rects)
96103
: region_(rects) {}
97104

98105
static DlRegionAdapter unionRegions(const DlRegionAdapter& a1,
@@ -107,15 +114,15 @@ class DlRegionAdapter {
107114
flutter::DlRegion::MakeIntersection(a1.region_, a2.region_));
108115
}
109116

110-
SkIRect getBounds() { return region_.bounds(); }
117+
DlIRect getBounds() { return region_.bounds(); }
111118

112119
bool intersects(const DlRegionAdapter& region) {
113120
return region_.intersects(region.region_);
114121
}
115122

116-
bool intersects(const SkIRect& rect) { return region_.intersects(rect); }
123+
bool intersects(const DlIRect& rect) { return region_.intersects(rect); }
117124

118-
std::vector<SkIRect> getRects() { return region_.getRects(false); }
125+
std::vector<DlIRect> getRects() { return region_.getRects(false); }
119126

120127
private:
121128
explicit DlRegionAdapter(flutter::DlRegion&& region)
@@ -133,9 +140,9 @@ void RunFromRectsBenchmark(benchmark::State& state, int maxSize) {
133140
std::uniform_int_distribution pos(0, 4000);
134141
std::uniform_int_distribution size(1, maxSize);
135142

136-
std::vector<SkIRect> rects;
143+
std::vector<DlIRect> rects;
137144
for (int i = 0; i < 2000; ++i) {
138-
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
145+
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
139146
rects.push_back(rect);
140147
}
141148

@@ -153,9 +160,9 @@ void RunGetRectsBenchmark(benchmark::State& state, int maxSize) {
153160
std::uniform_int_distribution pos(0, 4000);
154161
std::uniform_int_distribution size(1, maxSize);
155162

156-
std::vector<SkIRect> rects;
163+
std::vector<DlIRect> rects;
157164
for (int i = 0; i < 2000; ++i) {
158-
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
165+
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
159166
rects.push_back(rect);
160167
}
161168

@@ -178,8 +185,8 @@ void RunRegionOpBenchmark(benchmark::State& state,
178185
std::seed_seq seed{2, 1, 3};
179186
std::mt19937 rng(seed);
180187

181-
SkIRect bounds1 = SkIRect::MakeWH(4000, 4000);
182-
SkIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
188+
DlIRect bounds1 = DlIRect::MakeWH(4000, 4000);
189+
DlIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
183190

184191
auto rects = GenerateRects(rng, bounds1, 500, maxSize);
185192
Region region1(rects);
@@ -210,8 +217,8 @@ void RunIntersectsRegionBenchmark(benchmark::State& state,
210217
std::seed_seq seed{2, 1, 3};
211218
std::mt19937 rng(seed);
212219

213-
SkIRect bounds1 = SkIRect::MakeWH(4000, 4000);
214-
SkIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
220+
DlIRect bounds1 = DlIRect::MakeWH(4000, 4000);
221+
DlIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
215222

216223
auto rects = GenerateRects(rng, bounds1, 500, maxSize);
217224
Region region1(rects);
@@ -233,16 +240,16 @@ void RunIntersectsSingleRectBenchmark(benchmark::State& state, int maxSize) {
233240
std::uniform_int_distribution pos(0, 4000);
234241
std::uniform_int_distribution size(1, maxSize);
235242

236-
std::vector<SkIRect> rects;
243+
std::vector<DlIRect> rects;
237244
for (int i = 0; i < 500; ++i) {
238-
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
245+
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
239246
rects.push_back(rect);
240247
}
241248
Region region1(rects);
242249

243250
rects.clear();
244251
for (int i = 0; i < 100; ++i) {
245-
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
252+
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
246253
rects.push_back(rect);
247254
}
248255

display_list/display_list.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DisplayList::DisplayList()
2020
nested_op_count_(0),
2121
total_depth_(0),
2222
unique_id_(0),
23-
bounds_({0, 0, 0, 0}),
2423
can_apply_group_opacity_(true),
2524
is_ui_thread_safe_(true),
2625
modifies_transparent_black_(false),
@@ -37,7 +36,7 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
3736
size_t nested_byte_count,
3837
uint32_t nested_op_count,
3938
uint32_t total_depth,
40-
const SkRect& bounds,
39+
const DlRect& bounds,
4140
bool can_apply_group_opacity,
4241
bool is_ui_thread_safe,
4342
bool modifies_transparent_black,
@@ -187,16 +186,16 @@ void DisplayList::Dispatch(DlOpReceiver& receiver) const {
187186
}
188187

189188
void DisplayList::Dispatch(DlOpReceiver& receiver,
190-
const SkIRect& cull_rect) const {
191-
Dispatch(receiver, SkRect::Make(cull_rect));
189+
const DlIRect& cull_rect) const {
190+
Dispatch(receiver, DlRect::Make(cull_rect));
192191
}
193192

194193
void DisplayList::Dispatch(DlOpReceiver& receiver,
195-
const SkRect& cull_rect) const {
196-
if (cull_rect.isEmpty()) {
194+
const DlRect& cull_rect) const {
195+
if (cull_rect.IsEmpty()) {
197196
return;
198197
}
199-
if (!has_rtree() || cull_rect.contains(bounds())) {
198+
if (!has_rtree() || cull_rect.Contains(GetBounds())) {
200199
Dispatch(receiver);
201200
} else {
202201
auto op_indices = GetCulledIndices(cull_rect);
@@ -366,9 +365,9 @@ static void FillAllIndices(std::vector<DlIndex>& indices, DlIndex size) {
366365
}
367366

368367
std::vector<DlIndex> DisplayList::GetCulledIndices(
369-
const SkRect& cull_rect) const {
368+
const DlRect& cull_rect) const {
370369
std::vector<DlIndex> indices;
371-
if (!cull_rect.isEmpty()) {
370+
if (!cull_rect.IsEmpty()) {
372371
if (rtree_) {
373372
std::vector<int> rect_indices;
374373
rtree_->search(cull_rect, &rect_indices);

display_list/display_list.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,14 @@ class DisplayList : public SkRefCnt {
271271
~DisplayList();
272272

273273
void Dispatch(DlOpReceiver& ctx) const;
274-
void Dispatch(DlOpReceiver& ctx, const SkRect& cull_rect) const;
275-
void Dispatch(DlOpReceiver& ctx, const SkIRect& cull_rect) const;
274+
void Dispatch(DlOpReceiver& ctx, const SkRect& cull_rect) const {
275+
Dispatch(ctx, ToDlRect(cull_rect));
276+
}
277+
void Dispatch(DlOpReceiver& ctx, const SkIRect& cull_rect) const {
278+
Dispatch(ctx, ToDlIRect(cull_rect));
279+
}
280+
void Dispatch(DlOpReceiver& ctx, const DlRect& cull_rect) const;
281+
void Dispatch(DlOpReceiver& ctx, const DlIRect& cull_rect) const;
276282

277283
// From historical behavior, SkPicture always included nested bytes,
278284
// but nested ops are only included if requested. The defaults used
@@ -290,8 +296,8 @@ class DisplayList : public SkRefCnt {
290296

291297
uint32_t unique_id() const { return unique_id_; }
292298

293-
const SkRect& bounds() const { return bounds_; }
294-
const DlRect& GetBounds() const { return ToDlRect(bounds_); }
299+
const SkRect& bounds() const { return ToSkRect(bounds_); }
300+
const DlRect& GetBounds() const { return bounds_; }
295301

296302
bool has_rtree() const { return rtree_ != nullptr; }
297303
sk_sp<const DlRTree> rtree() const { return rtree_; }
@@ -500,7 +506,7 @@ class DisplayList : public SkRefCnt {
500506
/// primarily for debugging use
501507
///
502508
/// @see |Dispatch(receiver, index)|
503-
std::vector<DlIndex> GetCulledIndices(const SkRect& cull_rect) const;
509+
std::vector<DlIndex> GetCulledIndices(const DlRect& cull_rect) const;
504510

505511
private:
506512
DisplayList(DisplayListStorage&& ptr,
@@ -509,7 +515,7 @@ class DisplayList : public SkRefCnt {
509515
size_t nested_byte_count,
510516
uint32_t nested_op_count,
511517
uint32_t total_depth,
512-
const SkRect& bounds,
518+
const DlRect& bounds,
513519
bool can_apply_group_opacity,
514520
bool is_ui_thread_safe,
515521
bool modifies_transparent_black,
@@ -533,7 +539,7 @@ class DisplayList : public SkRefCnt {
533539
const uint32_t total_depth_;
534540

535541
const uint32_t unique_id_;
536-
const SkRect bounds_;
542+
const DlRect bounds_;
537543

538544
const bool can_apply_group_opacity_;
539545
const bool is_ui_thread_safe_;

0 commit comments

Comments
 (0)