12
12
13
13
namespace {
14
14
15
+ using DlIRect = flutter::DlIRect;
16
+
15
17
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,
18
20
int numRects,
19
21
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 ());
22
24
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);
25
29
std::uniform_int_distribution size_x (1 , max_size_x);
26
30
std::uniform_int_distribution size_y (1 , max_size_y);
27
31
28
- std::vector<SkIRect > rects;
32
+ std::vector<DlIRect > rects;
29
33
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));
32
36
rects.push_back (rect);
33
37
}
34
38
return rects;
35
39
}
36
40
37
41
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) {
39
43
FML_DCHECK (size_factor <= 1 );
40
44
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;
43
47
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);
46
50
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), //
48
53
width, height);
49
54
}
50
55
51
56
class SkRegionAdapter {
52
57
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 ());
55
60
}
56
61
57
- SkIRect getBounds () { return region_.getBounds (); }
62
+ DlIRect getBounds () { return flutter::ToDlIRect ( region_.getBounds () ); }
58
63
59
64
static SkRegionAdapter unionRegions (const SkRegionAdapter& a1,
60
65
const SkRegionAdapter& a2) {
@@ -74,13 +79,15 @@ class SkRegionAdapter {
74
79
return region_.intersects (region.region_ );
75
80
}
76
81
77
- bool intersects (const SkIRect& rect) { return region_.intersects (rect); }
82
+ bool intersects (const DlIRect& rect) {
83
+ return region_.intersects (flutter::ToSkIRect (rect));
84
+ }
78
85
79
- std::vector<SkIRect > getRects () {
80
- std::vector<SkIRect > rects;
86
+ std::vector<DlIRect > getRects () {
87
+ std::vector<DlIRect > rects;
81
88
SkRegion::Iterator it (region_);
82
89
while (!it.done ()) {
83
- rects.push_back (it.rect ());
90
+ rects.push_back (flutter::ToDlIRect ( it.rect () ));
84
91
it.next ();
85
92
}
86
93
return rects;
@@ -92,7 +99,7 @@ class SkRegionAdapter {
92
99
93
100
class DlRegionAdapter {
94
101
public:
95
- explicit DlRegionAdapter (const std::vector<SkIRect >& rects)
102
+ explicit DlRegionAdapter (const std::vector<DlIRect >& rects)
96
103
: region_(rects) {}
97
104
98
105
static DlRegionAdapter unionRegions (const DlRegionAdapter& a1,
@@ -107,15 +114,15 @@ class DlRegionAdapter {
107
114
flutter::DlRegion::MakeIntersection (a1.region_ , a2.region_ ));
108
115
}
109
116
110
- SkIRect getBounds () { return region_.bounds (); }
117
+ DlIRect getBounds () { return region_.bounds (); }
111
118
112
119
bool intersects (const DlRegionAdapter& region) {
113
120
return region_.intersects (region.region_ );
114
121
}
115
122
116
- bool intersects (const SkIRect & rect) { return region_.intersects (rect); }
123
+ bool intersects (const DlIRect & rect) { return region_.intersects (rect); }
117
124
118
- std::vector<SkIRect > getRects () { return region_.getRects (false ); }
125
+ std::vector<DlIRect > getRects () { return region_.getRects (false ); }
119
126
120
127
private:
121
128
explicit DlRegionAdapter (flutter::DlRegion&& region)
@@ -133,9 +140,9 @@ void RunFromRectsBenchmark(benchmark::State& state, int maxSize) {
133
140
std::uniform_int_distribution pos (0 , 4000 );
134
141
std::uniform_int_distribution size (1 , maxSize);
135
142
136
- std::vector<SkIRect > rects;
143
+ std::vector<DlIRect > rects;
137
144
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));
139
146
rects.push_back (rect);
140
147
}
141
148
@@ -153,9 +160,9 @@ void RunGetRectsBenchmark(benchmark::State& state, int maxSize) {
153
160
std::uniform_int_distribution pos (0 , 4000 );
154
161
std::uniform_int_distribution size (1 , maxSize);
155
162
156
- std::vector<SkIRect > rects;
163
+ std::vector<DlIRect > rects;
157
164
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));
159
166
rects.push_back (rect);
160
167
}
161
168
@@ -178,8 +185,8 @@ void RunRegionOpBenchmark(benchmark::State& state,
178
185
std::seed_seq seed{2 , 1 , 3 };
179
186
std::mt19937 rng (seed);
180
187
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);
183
190
184
191
auto rects = GenerateRects (rng, bounds1, 500 , maxSize);
185
192
Region region1 (rects);
@@ -210,8 +217,8 @@ void RunIntersectsRegionBenchmark(benchmark::State& state,
210
217
std::seed_seq seed{2 , 1 , 3 };
211
218
std::mt19937 rng (seed);
212
219
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);
215
222
216
223
auto rects = GenerateRects (rng, bounds1, 500 , maxSize);
217
224
Region region1 (rects);
@@ -233,16 +240,16 @@ void RunIntersectsSingleRectBenchmark(benchmark::State& state, int maxSize) {
233
240
std::uniform_int_distribution pos (0 , 4000 );
234
241
std::uniform_int_distribution size (1 , maxSize);
235
242
236
- std::vector<SkIRect > rects;
243
+ std::vector<DlIRect > rects;
237
244
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));
239
246
rects.push_back (rect);
240
247
}
241
248
Region region1 (rects);
242
249
243
250
rects.clear ();
244
251
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));
246
253
rects.push_back (rect);
247
254
}
248
255
0 commit comments