10#include "third_party/skia/include/core/SkRegion.h"
18template <
typename RNG>
19std::vector<DlIRect> GenerateRects(RNG& rng,
20 const DlIRect& bounds,
23 auto max_size_x = std::min(maxSize, bounds.GetWidth());
24 auto max_size_y = std::min(maxSize, bounds.GetHeight());
26 std::uniform_int_distribution pos_x(bounds.GetLeft(),
27 bounds.GetRight() - max_size_x);
28 std::uniform_int_distribution pos_y(bounds.GetTop(),
29 bounds.GetBottom() - max_size_y);
30 std::uniform_int_distribution size_x(1, max_size_x);
31 std::uniform_int_distribution size_y(1, max_size_y);
33 std::vector<DlIRect> rects;
34 for (
int i = 0;
i < numRects; ++
i) {
36 DlIRect::MakeXYWH(pos_x(rng), pos_y(rng), size_x(rng), size_y(rng));
37 rects.push_back(rect);
42template <
typename RNG>
43DlIRect RandomSubRect(RNG& rng,
const DlIRect& rect,
double size_factor) {
46 int32_t
width = rect.GetWidth() * size_factor;
47 int32_t
height = rect.GetHeight() * size_factor;
49 std::uniform_int_distribution pos_x(0, rect.GetWidth() -
width);
50 std::uniform_int_distribution pos_y(0, rect.GetHeight() -
height);
52 return DlIRect::MakeXYWH(rect.GetLeft() + pos_x(rng),
53 rect.GetTop() + pos_y(rng),
57class SkRegionAdapter {
59 explicit SkRegionAdapter(
const std::vector<DlIRect>& rects) {
65 static SkRegionAdapter unionRegions(
const SkRegionAdapter& a1,
66 const SkRegionAdapter& a2) {
67 SkRegionAdapter result(a1);
68 result.region_.op(a2.region_, SkRegion::kUnion_Op);
72 static SkRegionAdapter intersectRegions(
const SkRegionAdapter& a1,
73 const SkRegionAdapter& a2) {
74 SkRegionAdapter result(a1);
75 result.region_.op(a2.region_, SkRegion::kIntersect_Op);
79 bool intersects(
const SkRegionAdapter& region) {
80 return region_.intersects(region.region_);
83 bool intersects(
const DlIRect& rect) {
87 std::vector<DlIRect> getRects() {
88 std::vector<DlIRect> rects;
89 SkRegion::Iterator it(region_);
101class DlRegionAdapter {
103 explicit DlRegionAdapter(
const std::vector<DlIRect>& rects)
106 static DlRegionAdapter unionRegions(
const DlRegionAdapter& a1,
107 const DlRegionAdapter& a2) {
108 return DlRegionAdapter(
112 static DlRegionAdapter intersectRegions(
const DlRegionAdapter& a1,
113 const DlRegionAdapter& a2) {
114 return DlRegionAdapter(
118 DlIRect getBounds() {
return region_.bounds(); }
120 bool intersects(
const DlRegionAdapter& region) {
121 return region_.intersects(region.region_);
124 bool intersects(
const DlIRect& rect) {
return region_.intersects(rect); }
126 std::vector<DlIRect> getRects() {
return region_.getRects(
false); }
130 : region_(
std::move(region)) {}
135template <
typename Region>
136void RunFromRectsBenchmark(benchmark::State& state,
int maxSize) {
137 std::random_device
d;
138 std::seed_seq seed{2, 1, 3};
139 std::mt19937 rng(seed);
141 std::uniform_int_distribution pos(0, 4000);
142 std::uniform_int_distribution
size(1, maxSize);
144 std::vector<DlIRect> rects;
145 for (
int i = 0;
i < 2000; ++
i) {
146 DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng),
size(rng),
size(rng));
147 rects.push_back(rect);
150 while (state.KeepRunning()) {
151 Region region(rects);
155template <
typename Region>
156void RunGetRectsBenchmark(benchmark::State& state,
int maxSize) {
157 std::random_device
d;
158 std::seed_seq seed{2, 1, 3};
159 std::mt19937 rng(seed);
161 std::uniform_int_distribution pos(0, 4000);
162 std::uniform_int_distribution
size(1, maxSize);
164 std::vector<DlIRect> rects;
165 for (
int i = 0;
i < 2000; ++
i) {
166 DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng),
size(rng),
size(rng));
167 rects.push_back(rect);
170 Region region(rects);
172 while (state.KeepRunning()) {
173 auto vec2 = region.getRects();
177enum RegionOp { kUnion, kIntersection };
179template <
typename Region>
180void RunRegionOpBenchmark(benchmark::State& state,
185 std::random_device
d;
186 std::seed_seq seed{2, 1, 3};
187 std::mt19937 rng(seed);
189 DlIRect bounds1 = DlIRect::MakeWH(4000, 4000);
190 DlIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
192 auto rects = GenerateRects(rng, bounds1, 500, maxSize);
193 Region region1(rects);
195 rects = GenerateRects(rng, bounds2, withSingleRect ? 1 : 500 * sizeFactor,
197 Region region2(rects);
201 while (state.KeepRunning()) {
202 Region::unionRegions(region1, region2);
206 while (state.KeepRunning()) {
207 Region::intersectRegions(region1, region2);
213template <
typename Region>
214void RunIntersectsRegionBenchmark(benchmark::State& state,
217 std::random_device
d;
218 std::seed_seq seed{2, 1, 3};
219 std::mt19937 rng(seed);
221 DlIRect bounds1 = DlIRect::MakeWH(4000, 4000);
222 DlIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
224 auto rects = GenerateRects(rng, bounds1, 500, maxSize);
225 Region region1(rects);
227 rects = GenerateRects(rng, bounds2, 500 * sizeFactor, maxSize);
228 Region region2(rects);
230 while (state.KeepRunning()) {
231 region1.intersects(region2);
235template <
typename Region>
236void RunIntersectsSingleRectBenchmark(benchmark::State& state,
int maxSize) {
237 std::random_device
d;
238 std::seed_seq seed{2, 1, 3};
239 std::mt19937 rng(seed);
241 std::uniform_int_distribution pos(0, 4000);
242 std::uniform_int_distribution
size(1, maxSize);
244 std::vector<DlIRect> rects;
245 for (
int i = 0;
i < 500; ++
i) {
246 DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng),
size(rng),
size(rng));
247 rects.push_back(rect);
249 Region region1(rects);
252 for (
int i = 0;
i < 100; ++
i) {
253 DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng),
size(rng),
size(rng));
254 rects.push_back(rect);
257 while (state.KeepRunning()) {
258 for (
auto& rect : rects) {
259 region1.intersects(rect);
269 RunFromRectsBenchmark<DlRegionAdapter>(state, maxSize);
273 RunFromRectsBenchmark<SkRegionAdapter>(state, maxSize);
277 RunGetRectsBenchmark<DlRegionAdapter>(state, maxSize);
281 RunGetRectsBenchmark<SkRegionAdapter>(state, maxSize);
289 RunRegionOpBenchmark<DlRegionAdapter>(state, op, withSingleRect, maxSize,
298 RunRegionOpBenchmark<SkRegionAdapter>(state, op, withSingleRect, maxSize,
305 RunIntersectsRegionBenchmark<DlRegionAdapter>(state, maxSize, sizeFactor);
311 RunIntersectsRegionBenchmark<SkRegionAdapter>(state, maxSize, sizeFactor);
316 RunIntersectsSingleRectBenchmark<DlRegionAdapter>(state, maxSize);
321 RunIntersectsSingleRectBenchmark<SkRegionAdapter>(state, maxSize);
327 ->Unit(benchmark::kNanosecond);
329 ->Unit(benchmark::kNanosecond);
331 ->Unit(benchmark::kNanosecond);
333 ->Unit(benchmark::kNanosecond);
335 ->Unit(benchmark::kNanosecond);
337 ->Unit(benchmark::kNanosecond);
339 ->Unit(benchmark::kNanosecond);
341 ->Unit(benchmark::kNanosecond);
344 ->Unit(benchmark::kNanosecond);
346 ->Unit(benchmark::kNanosecond);
348 ->Unit(benchmark::kNanosecond);
350 ->Unit(benchmark::kNanosecond);
352 ->Unit(benchmark::kNanosecond);
354 ->Unit(benchmark::kNanosecond);
356 ->Unit(benchmark::kNanosecond);
358 ->Unit(benchmark::kNanosecond);
364 ->Unit(benchmark::kNanosecond);
369 ->Unit(benchmark::kNanosecond);
374 ->Unit(benchmark::kNanosecond);
379 ->Unit(benchmark::kNanosecond);
384 ->Unit(benchmark::kNanosecond);
389 ->Unit(benchmark::kNanosecond);
394 ->Unit(benchmark::kNanosecond);
399 ->Unit(benchmark::kNanosecond);
407 ->Unit(benchmark::kMicrosecond);
414 ->Unit(benchmark::kMicrosecond);
421 ->Unit(benchmark::kMicrosecond);
428 ->Unit(benchmark::kMicrosecond);
435 ->Unit(benchmark::kMicrosecond);
442 ->Unit(benchmark::kMicrosecond);
449 ->Unit(benchmark::kMicrosecond);
456 ->Unit(benchmark::kMicrosecond);
459 Union_TinyAsymmetric,
464 ->Unit(benchmark::kMicrosecond);
466 Union_TinyAsymmetric,
471 ->Unit(benchmark::kMicrosecond);
473 Union_SmallAsymmetric,
478 ->Unit(benchmark::kMicrosecond);
480 Union_SmallAsymmetric,
485 ->Unit(benchmark::kMicrosecond);
487 Union_MediumAsymmetric,
492 ->Unit(benchmark::kMicrosecond);
494 Union_MediumAsymmetric,
499 ->Unit(benchmark::kMicrosecond);
501 Union_LargeAsymmetric,
506 ->Unit(benchmark::kMicrosecond);
508 Union_LargeAsymmetric,
513 ->Unit(benchmark::kMicrosecond);
517 RegionOp::kIntersection,
521 ->Unit(benchmark::kMicrosecond);
524 RegionOp::kIntersection,
528 ->Unit(benchmark::kMicrosecond);
531 RegionOp::kIntersection,
535 ->Unit(benchmark::kMicrosecond);
538 RegionOp::kIntersection,
542 ->Unit(benchmark::kMicrosecond);
545 RegionOp::kIntersection,
549 ->Unit(benchmark::kMicrosecond);
552 RegionOp::kIntersection,
556 ->Unit(benchmark::kMicrosecond);
559 RegionOp::kIntersection,
563 ->Unit(benchmark::kMicrosecond);
566 RegionOp::kIntersection,
570 ->Unit(benchmark::kMicrosecond);
573 Intersection_TinyAsymmetric,
574 RegionOp::kIntersection,
578 ->Unit(benchmark::kMicrosecond);
580 Intersection_TinyAsymmetric,
581 RegionOp::kIntersection,
585 ->Unit(benchmark::kMicrosecond);
587 Intersection_SmallAsymmetric,
588 RegionOp::kIntersection,
592 ->Unit(benchmark::kMicrosecond);
594 Intersection_SmallAsymmetric,
595 RegionOp::kIntersection,
599 ->Unit(benchmark::kMicrosecond);
601 Intersection_MediumAsymmetric,
602 RegionOp::kIntersection,
606 ->Unit(benchmark::kMicrosecond);
608 Intersection_MediumAsymmetric,
609 RegionOp::kIntersection,
613 ->Unit(benchmark::kMicrosecond);
615 Intersection_LargeAsymmetric,
616 RegionOp::kIntersection,
620 ->Unit(benchmark::kMicrosecond);
622 Intersection_LargeAsymmetric,
623 RegionOp::kIntersection,
627 ->Unit(benchmark::kMicrosecond);
630 Intersection_SingleRect_Tiny,
631 RegionOp::kIntersection,
635 ->Unit(benchmark::kMicrosecond);
637 Intersection_SingleRect_Tiny,
638 RegionOp::kIntersection,
642 ->Unit(benchmark::kMicrosecond);
644 Intersection_SingleRect_Small,
645 RegionOp::kIntersection,
649 ->Unit(benchmark::kMicrosecond);
651 Intersection_SingleRect_Small,
652 RegionOp::kIntersection,
656 ->Unit(benchmark::kMicrosecond);
658 Intersection_SingleRect_Medium,
659 RegionOp::kIntersection,
663 ->Unit(benchmark::kMicrosecond);
665 Intersection_SingleRect_Medium,
666 RegionOp::kIntersection,
670 ->Unit(benchmark::kMicrosecond);
672 Intersection_SingleRect_Large,
673 RegionOp::kIntersection,
677 ->Unit(benchmark::kMicrosecond);
679 Intersection_SingleRect_Large,
680 RegionOp::kIntersection,
684 ->Unit(benchmark::kMicrosecond);
687 ->Unit(benchmark::kMicrosecond);
689 ->Unit(benchmark::kMicrosecond);
691 ->Unit(benchmark::kMicrosecond);
693 ->Unit(benchmark::kMicrosecond);
695 ->Unit(benchmark::kMicrosecond);
697 ->Unit(benchmark::kMicrosecond);
699 ->Unit(benchmark::kMicrosecond);
701 ->Unit(benchmark::kMicrosecond);
704 ->Unit(benchmark::kMicrosecond);
706 ->Unit(benchmark::kMicrosecond);
708 ->Unit(benchmark::kMicrosecond);
710 ->Unit(benchmark::kMicrosecond);
712 ->Unit(benchmark::kMicrosecond);
714 ->Unit(benchmark::kMicrosecond);
716 ->Unit(benchmark::kMicrosecond);
718 ->Unit(benchmark::kMicrosecond);
static DlRegion MakeIntersection(const DlRegion &a, const DlRegion &b)
static DlRegion MakeUnion(const DlRegion &a, const DlRegion &b)
#define FML_DCHECK(condition)
static void BM_DlRegion_Operation(benchmark::State &state, RegionOp op, bool withSingleRect, int maxSize, double sizeFactor)
static void BM_SkRegion_IntersectsSingleRect(benchmark::State &state, int maxSize)
static void BM_DlRegion_GetRects(benchmark::State &state, int maxSize)
const SkIRect & ToSkIRect(const DlIRect &rect)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static void BM_SkRegion_FromRects(benchmark::State &state, int maxSize)
static void BM_SkRegion_GetRects(benchmark::State &state, int maxSize)
static void BM_DlRegion_IntersectsRegion(benchmark::State &state, int maxSize, double sizeFactor)
const double kSizeFactorSmall
impeller::IRect32 DlIRect
static void BM_DlRegion_FromRects(benchmark::State &state, int maxSize)
const DlIRect & ToDlIRect(const SkIRect &rect)
static void BM_SkRegion_Operation(benchmark::State &state, RegionOp op, bool withSingleRect, int maxSize, double sizeFactor)
static void BM_SkRegion_IntersectsRegion(benchmark::State &state, int maxSize, double sizeFactor)
static void BM_DlRegion_IntersectsSingleRect(benchmark::State &state, int maxSize)
BENCHMARK_CAPTURE(BM_DisplayListBuilderDefault, kDefault, DisplayListBuilderBenchmarkType::kDefault) -> Unit(benchmark::kMicrosecond)
const SkIRect * ToSkIRects(const DlIRect *rects)