5#include "flutter/benchmarking/benchmarking.h"
7#include "flutter/display_list/geometry/dl_region.h"
8#include "flutter/fml/logging.h"
15template <
typename RNG>
16std::vector<SkIRect> GenerateRects(RNG& rng,
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
size_x(1, max_size_x);
26 std::uniform_int_distribution
size_y(1, max_size_y);
28 std::vector<SkIRect> rects;
29 for (
int i = 0;
i < numRects; ++
i) {
32 rects.push_back(
rect);
37template <
typename RNG>
41 int32_t
width =
rect.width() * size_factor;
44 std::uniform_int_distribution pos_x(0,
rect.width() -
width);
45 std::uniform_int_distribution pos_y(0,
rect.height() -
height);
51class SkRegionAdapter {
53 explicit SkRegionAdapter(
const std::vector<SkIRect>& rects) {
54 region_.setRects(rects.data(), rects.size());
57 SkIRect getBounds() {
return region_.getBounds(); }
59 static SkRegionAdapter unionRegions(
const SkRegionAdapter& a1,
60 const SkRegionAdapter& a2) {
61 SkRegionAdapter
result(a1);
66 static SkRegionAdapter intersectRegions(
const SkRegionAdapter& a1,
67 const SkRegionAdapter& a2) {
68 SkRegionAdapter
result(a1);
73 bool intersects(
const SkRegionAdapter&
region) {
74 return region_.intersects(
region.region_);
77 bool intersects(
const SkIRect&
rect) {
return region_.intersects(
rect); }
79 std::vector<SkIRect> getRects() {
80 std::vector<SkIRect> rects;
83 rects.push_back(it.rect());
93class DlRegionAdapter {
95 explicit DlRegionAdapter(
const std::vector<SkIRect>& rects)
98 static DlRegionAdapter unionRegions(
const DlRegionAdapter& a1,
99 const DlRegionAdapter& a2) {
100 return DlRegionAdapter(
104 static DlRegionAdapter intersectRegions(
const DlRegionAdapter& a1,
105 const DlRegionAdapter& a2) {
106 return DlRegionAdapter(
110 SkIRect getBounds() {
return region_.bounds(); }
112 bool intersects(
const DlRegionAdapter&
region) {
113 return region_.intersects(
region.region_);
116 bool intersects(
const SkIRect&
rect) {
return region_.intersects(
rect); }
118 std::vector<SkIRect> getRects() {
return region_.getRects(
false); }
127template <
typename Region>
129 std::random_device
d;
130 std::seed_seq seed{2, 1, 3};
131 std::mt19937 rng(seed);
133 std::uniform_int_distribution
pos(0, 4000);
134 std::uniform_int_distribution
size(1, maxSize);
136 std::vector<SkIRect> rects;
137 for (
int i = 0;
i < 2000; ++
i) {
139 rects.push_back(
rect);
142 while (
state.KeepRunning()) {
147template <
typename Region>
149 std::random_device
d;
150 std::seed_seq seed{2, 1, 3};
151 std::mt19937 rng(seed);
153 std::uniform_int_distribution
pos(0, 4000);
154 std::uniform_int_distribution
size(1, maxSize);
156 std::vector<SkIRect> rects;
157 for (
int i = 0;
i < 2000; ++
i) {
159 rects.push_back(
rect);
164 while (
state.KeepRunning()) {
165 auto vec2 =
region.getRects();
169enum RegionOp {
kUnion, kIntersection };
171template <
typename Region>
177 std::random_device
d;
178 std::seed_seq seed{2, 1, 3};
179 std::mt19937 rng(seed);
182 SkIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
184 auto rects = GenerateRects(rng, bounds1, 500, maxSize);
185 Region region1(rects);
187 rects = GenerateRects(rng, bounds2, withSingleRect ? 1 : 500 * sizeFactor,
189 Region region2(rects);
193 while (
state.KeepRunning()) {
194 Region::unionRegions(region1, region2);
198 while (
state.KeepRunning()) {
199 Region::intersectRegions(region1, region2);
205template <
typename Region>
209 std::random_device
d;
210 std::seed_seq seed{2, 1, 3};
211 std::mt19937 rng(seed);
214 SkIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
216 auto rects = GenerateRects(rng, bounds1, 500, maxSize);
217 Region region1(rects);
219 rects = GenerateRects(rng, bounds2, 500 * sizeFactor, maxSize);
220 Region region2(rects);
222 while (
state.KeepRunning()) {
223 region1.intersects(region2);
227template <
typename Region>
229 std::random_device
d;
230 std::seed_seq seed{2, 1, 3};
231 std::mt19937 rng(seed);
233 std::uniform_int_distribution
pos(0, 4000);
234 std::uniform_int_distribution
size(1, maxSize);
236 std::vector<SkIRect> rects;
237 for (
int i = 0;
i < 500; ++
i) {
239 rects.push_back(
rect);
241 Region region1(rects);
244 for (
int i = 0;
i < 100; ++
i) {
246 rects.push_back(
rect);
249 while (
state.KeepRunning()) {
250 for (
auto&
rect : rects) {
251 region1.intersects(
rect);
261 RunFromRectsBenchmark<DlRegionAdapter>(
state, maxSize);
265 RunFromRectsBenchmark<SkRegionAdapter>(
state, maxSize);
269 RunGetRectsBenchmark<DlRegionAdapter>(
state, maxSize);
273 RunGetRectsBenchmark<SkRegionAdapter>(
state, maxSize);
281 RunRegionOpBenchmark<DlRegionAdapter>(
state, op, withSingleRect, maxSize,
290 RunRegionOpBenchmark<SkRegionAdapter>(
state, op, withSingleRect, maxSize,
297 RunIntersectsRegionBenchmark<DlRegionAdapter>(
state, maxSize, sizeFactor);
303 RunIntersectsRegionBenchmark<SkRegionAdapter>(
state, maxSize, sizeFactor);
308 RunIntersectsSingleRectBenchmark<DlRegionAdapter>(
state, maxSize);
313 RunIntersectsSingleRectBenchmark<SkRegionAdapter>(
state, maxSize);
319 ->Unit(benchmark::kNanosecond);
321 ->Unit(benchmark::kNanosecond);
323 ->Unit(benchmark::kNanosecond);
325 ->Unit(benchmark::kNanosecond);
327 ->Unit(benchmark::kNanosecond);
329 ->Unit(benchmark::kNanosecond);
331 ->Unit(benchmark::kNanosecond);
333 ->Unit(benchmark::kNanosecond);
336 ->Unit(benchmark::kNanosecond);
338 ->Unit(benchmark::kNanosecond);
340 ->Unit(benchmark::kNanosecond);
342 ->Unit(benchmark::kNanosecond);
344 ->Unit(benchmark::kNanosecond);
346 ->Unit(benchmark::kNanosecond);
348 ->Unit(benchmark::kNanosecond);
350 ->Unit(benchmark::kNanosecond);
356 ->Unit(benchmark::kNanosecond);
361 ->Unit(benchmark::kNanosecond);
366 ->Unit(benchmark::kNanosecond);
371 ->Unit(benchmark::kNanosecond);
376 ->Unit(benchmark::kNanosecond);
381 ->Unit(benchmark::kNanosecond);
386 ->Unit(benchmark::kNanosecond);
391 ->Unit(benchmark::kNanosecond);
399 ->Unit(benchmark::kMicrosecond);
406 ->Unit(benchmark::kMicrosecond);
413 ->Unit(benchmark::kMicrosecond);
420 ->Unit(benchmark::kMicrosecond);
427 ->Unit(benchmark::kMicrosecond);
434 ->Unit(benchmark::kMicrosecond);
441 ->Unit(benchmark::kMicrosecond);
448 ->Unit(benchmark::kMicrosecond);
451 Union_TinyAsymmetric,
456 ->Unit(benchmark::kMicrosecond);
458 Union_TinyAsymmetric,
463 ->Unit(benchmark::kMicrosecond);
465 Union_SmallAsymmetric,
470 ->Unit(benchmark::kMicrosecond);
472 Union_SmallAsymmetric,
477 ->Unit(benchmark::kMicrosecond);
479 Union_MediumAsymmetric,
484 ->Unit(benchmark::kMicrosecond);
486 Union_MediumAsymmetric,
491 ->Unit(benchmark::kMicrosecond);
493 Union_LargeAsymmetric,
498 ->Unit(benchmark::kMicrosecond);
500 Union_LargeAsymmetric,
505 ->Unit(benchmark::kMicrosecond);
509 RegionOp::kIntersection,
513 ->Unit(benchmark::kMicrosecond);
516 RegionOp::kIntersection,
520 ->Unit(benchmark::kMicrosecond);
523 RegionOp::kIntersection,
527 ->Unit(benchmark::kMicrosecond);
530 RegionOp::kIntersection,
534 ->Unit(benchmark::kMicrosecond);
537 RegionOp::kIntersection,
541 ->Unit(benchmark::kMicrosecond);
544 RegionOp::kIntersection,
548 ->Unit(benchmark::kMicrosecond);
551 RegionOp::kIntersection,
555 ->Unit(benchmark::kMicrosecond);
558 RegionOp::kIntersection,
562 ->Unit(benchmark::kMicrosecond);
565 Intersection_TinyAsymmetric,
566 RegionOp::kIntersection,
570 ->Unit(benchmark::kMicrosecond);
572 Intersection_TinyAsymmetric,
573 RegionOp::kIntersection,
577 ->Unit(benchmark::kMicrosecond);
579 Intersection_SmallAsymmetric,
580 RegionOp::kIntersection,
584 ->Unit(benchmark::kMicrosecond);
586 Intersection_SmallAsymmetric,
587 RegionOp::kIntersection,
591 ->Unit(benchmark::kMicrosecond);
593 Intersection_MediumAsymmetric,
594 RegionOp::kIntersection,
598 ->Unit(benchmark::kMicrosecond);
600 Intersection_MediumAsymmetric,
601 RegionOp::kIntersection,
605 ->Unit(benchmark::kMicrosecond);
607 Intersection_LargeAsymmetric,
608 RegionOp::kIntersection,
612 ->Unit(benchmark::kMicrosecond);
614 Intersection_LargeAsymmetric,
615 RegionOp::kIntersection,
619 ->Unit(benchmark::kMicrosecond);
622 Intersection_SingleRect_Tiny,
623 RegionOp::kIntersection,
627 ->Unit(benchmark::kMicrosecond);
629 Intersection_SingleRect_Tiny,
630 RegionOp::kIntersection,
634 ->Unit(benchmark::kMicrosecond);
636 Intersection_SingleRect_Small,
637 RegionOp::kIntersection,
641 ->Unit(benchmark::kMicrosecond);
643 Intersection_SingleRect_Small,
644 RegionOp::kIntersection,
648 ->Unit(benchmark::kMicrosecond);
650 Intersection_SingleRect_Medium,
651 RegionOp::kIntersection,
655 ->Unit(benchmark::kMicrosecond);
657 Intersection_SingleRect_Medium,
658 RegionOp::kIntersection,
662 ->Unit(benchmark::kMicrosecond);
664 Intersection_SingleRect_Large,
665 RegionOp::kIntersection,
669 ->Unit(benchmark::kMicrosecond);
671 Intersection_SingleRect_Large,
672 RegionOp::kIntersection,
676 ->Unit(benchmark::kMicrosecond);
679 ->Unit(benchmark::kMicrosecond);
681 ->Unit(benchmark::kMicrosecond);
683 ->Unit(benchmark::kMicrosecond);
685 ->Unit(benchmark::kMicrosecond);
687 ->Unit(benchmark::kMicrosecond);
689 ->Unit(benchmark::kMicrosecond);
691 ->Unit(benchmark::kMicrosecond);
693 ->Unit(benchmark::kMicrosecond);
696 ->Unit(benchmark::kMicrosecond);
698 ->Unit(benchmark::kMicrosecond);
700 ->Unit(benchmark::kMicrosecond);
702 ->Unit(benchmark::kMicrosecond);
704 ->Unit(benchmark::kMicrosecond);
706 ->Unit(benchmark::kMicrosecond);
708 ->Unit(benchmark::kMicrosecond);
710 ->Unit(benchmark::kMicrosecond);
@ kUnion_Op
target unioned with operand
@ kIntersect_Op
target intersected with operand
static DlRegion MakeIntersection(const DlRegion &a, const DlRegion &b)
static DlRegion MakeUnion(const DlRegion &a, const DlRegion &b)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
#define FML_DCHECK(condition)
static float min(float r, float g, float b)
Optional< SkRect > bounds
ClipOpAndAA opAA SkRegion region
sk_sp< SkBlender > blender SkRect rect
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)
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
static void BM_DlRegion_FromRects(benchmark::State &state, int maxSize)
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)
it will be possible to load the file into Perfetto s trace viewer 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 constexpr SkIRect MakeWH(int32_t w, int32_t h)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)