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

Commit 35078a2

Browse files
committed
Add DlRegion class
1 parent 456aa79 commit 35078a2

File tree

7 files changed

+551
-0
lines changed

7 files changed

+551
-0
lines changed

BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ group("flutter") {
116116
public_deps += [
117117
"//flutter/display_list:display_list_benchmarks",
118118
"//flutter/display_list:display_list_builder_benchmarks",
119+
"//flutter/display_list:display_list_region_benchmarks",
119120
"//flutter/fml:fml_benchmarks",
120121
"//flutter/impeller/geometry:geometry_benchmarks",
121122
"//flutter/lib/ui:ui_benchmarks",

ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_gl.h + ../../..
714714
ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_helper.h + ../../../flutter/LICENSE
715715
ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_metal.cc + ../../../flutter/LICENSE
716716
ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_metal.h + ../../../flutter/LICENSE
717+
ORIGIN: ../../../flutter/display_list/benchmarking/dl_region_benchmarks.cc + ../../../flutter/LICENSE
717718
ORIGIN: ../../../flutter/display_list/display_list.cc + ../../../flutter/LICENSE
718719
ORIGIN: ../../../flutter/display_list/display_list.h + ../../../flutter/LICENSE
719720
ORIGIN: ../../../flutter/display_list/dl_attributes.h + ../../../flutter/LICENSE
@@ -748,6 +749,8 @@ ORIGIN: ../../../flutter/display_list/effects/dl_path_effect.cc + ../../../flutt
748749
ORIGIN: ../../../flutter/display_list/effects/dl_path_effect.h + ../../../flutter/LICENSE
749750
ORIGIN: ../../../flutter/display_list/effects/dl_runtime_effect.cc + ../../../flutter/LICENSE
750751
ORIGIN: ../../../flutter/display_list/effects/dl_runtime_effect.h + ../../../flutter/LICENSE
752+
ORIGIN: ../../../flutter/display_list/geometry/dl_region.cc + ../../../flutter/LICENSE
753+
ORIGIN: ../../../flutter/display_list/geometry/dl_region.h + ../../../flutter/LICENSE
751754
ORIGIN: ../../../flutter/display_list/geometry/dl_rtree.cc + ../../../flutter/LICENSE
752755
ORIGIN: ../../../flutter/display_list/geometry/dl_rtree.h + ../../../flutter/LICENSE
753756
ORIGIN: ../../../flutter/display_list/image/dl_image.cc + ../../../flutter/LICENSE
@@ -3371,6 +3374,7 @@ FILE: ../../../flutter/display_list/benchmarking/dl_complexity_gl.h
33713374
FILE: ../../../flutter/display_list/benchmarking/dl_complexity_helper.h
33723375
FILE: ../../../flutter/display_list/benchmarking/dl_complexity_metal.cc
33733376
FILE: ../../../flutter/display_list/benchmarking/dl_complexity_metal.h
3377+
FILE: ../../../flutter/display_list/benchmarking/dl_region_benchmarks.cc
33743378
FILE: ../../../flutter/display_list/display_list.cc
33753379
FILE: ../../../flutter/display_list/display_list.h
33763380
FILE: ../../../flutter/display_list/dl_attributes.h
@@ -3405,6 +3409,8 @@ FILE: ../../../flutter/display_list/effects/dl_path_effect.cc
34053409
FILE: ../../../flutter/display_list/effects/dl_path_effect.h
34063410
FILE: ../../../flutter/display_list/effects/dl_runtime_effect.cc
34073411
FILE: ../../../flutter/display_list/effects/dl_runtime_effect.h
3412+
FILE: ../../../flutter/display_list/geometry/dl_region.cc
3413+
FILE: ../../../flutter/display_list/geometry/dl_region.h
34083414
FILE: ../../../flutter/display_list/geometry/dl_rtree.cc
34093415
FILE: ../../../flutter/display_list/geometry/dl_rtree.h
34103416
FILE: ../../../flutter/display_list/image/dl_image.cc

display_list/BUILD.gn

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ source_set("display_list") {
5757
"effects/dl_path_effect.h",
5858
"effects/dl_runtime_effect.cc",
5959
"effects/dl_runtime_effect.h",
60+
"geometry/dl_region.cc",
61+
"geometry/dl_region.h",
6062
"geometry/dl_rtree.cc",
6163
"geometry/dl_rtree.h",
6264
"image/dl_image.cc",
@@ -112,6 +114,7 @@ if (enable_unittests) {
112114
"effects/dl_image_filter_unittests.cc",
113115
"effects/dl_mask_filter_unittests.cc",
114116
"effects/dl_path_effect_unittests.cc",
117+
"geometry/dl_region_unittests.cc",
115118
"geometry/dl_rtree_unittests.cc",
116119
"skia/dl_sk_conversions_unittests.cc",
117120
"skia/dl_sk_paint_dispatcher_unittests.cc",
@@ -181,6 +184,18 @@ if (enable_unittests) {
181184
"//flutter/testing:testing_lib",
182185
]
183186
}
187+
188+
executable("display_list_region_benchmarks") {
189+
testonly = true
190+
191+
sources = [ "benchmarking/dl_region_benchmarks.cc" ]
192+
193+
deps = [
194+
":display_list_fixtures",
195+
"//flutter/benchmarking",
196+
"//flutter/testing:testing_lib",
197+
]
198+
}
184199
}
185200

186201
fixtures_location("display_list_benchmarks_fixtures") {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/benchmarking/benchmarking.h"
6+
7+
#include "flutter/display_list/geometry/dl_region.h"
8+
#include "third_party/skia/include/core/SkRegion.h"
9+
10+
#include <random>
11+
12+
class SkRegionAdapter {
13+
public:
14+
void addRect(const SkIRect& rect) { region_.op(rect, SkRegion::kUnion_Op); }
15+
16+
std::vector<SkIRect> getRects() {
17+
std::vector<SkIRect> rects;
18+
SkRegion::Iterator it(region_);
19+
while (!it.done()) {
20+
rects.push_back(it.rect());
21+
it.next();
22+
}
23+
return rects;
24+
}
25+
26+
private:
27+
SkRegion region_;
28+
};
29+
30+
template <typename Region>
31+
void RunRegionBenchmark(benchmark::State& state, int maxSize) {
32+
while (state.KeepRunning()) {
33+
std::random_device d;
34+
std::seed_seq seed{2, 1, 3};
35+
std::mt19937 rng(seed);
36+
37+
std::uniform_int_distribution pos(0, 4000);
38+
std::uniform_int_distribution size(1, maxSize);
39+
40+
Region region;
41+
42+
for (int i = 0; i < 2000; ++i) {
43+
SkIRect rect =
44+
SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
45+
region.addRect(rect);
46+
}
47+
48+
auto vec2 = region.getRects();
49+
}
50+
}
51+
52+
namespace flutter {
53+
54+
static void BM_RegionBenchmarkSkRegion(benchmark::State& state, int maxSize) {
55+
RunRegionBenchmark<SkRegionAdapter>(state, maxSize);
56+
}
57+
58+
static void BM_RegionBenchmarkDlRegion(benchmark::State& state, int maxSize) {
59+
RunRegionBenchmark<DlRegion>(state, maxSize);
60+
}
61+
62+
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Small, 100)
63+
->Unit(benchmark::kMicrosecond);
64+
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Small, 100)
65+
->Unit(benchmark::kMicrosecond);
66+
67+
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Medium, 400)
68+
->Unit(benchmark::kMicrosecond);
69+
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Medium, 400)
70+
->Unit(benchmark::kMicrosecond);
71+
72+
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Large, 1500)
73+
->Unit(benchmark::kMicrosecond);
74+
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Large, 1500)
75+
->Unit(benchmark::kMicrosecond);
76+
77+
} // namespace flutter

0 commit comments

Comments
 (0)