@@ -13,8 +13,6 @@ namespace {
13
13
14
14
class SkRegionAdapter {
15
15
public:
16
- SkRegionAdapter () {}
17
-
18
16
explicit SkRegionAdapter (const std::vector<SkIRect>& rects) {
19
17
for (const auto & rect : rects) {
20
18
region_.op (rect, SkRegion::kUnion_Op );
@@ -23,8 +21,11 @@ class SkRegionAdapter {
23
21
24
22
SkIRect getBounds () { return region_.getBounds (); }
25
23
26
- void addRegion (const SkRegionAdapter& region) {
27
- region_.op (region.region_ , SkRegion::kUnion_Op );
24
+ static SkRegionAdapter unionRegions (const SkRegionAdapter& a1,
25
+ const SkRegionAdapter& a2) {
26
+ SkRegionAdapter result (a1);
27
+ result.region_ .op (a2.region_ , SkRegion::kUnion_Op );
28
+ return result;
28
29
}
29
30
30
31
bool intersects (const SkRegionAdapter& region) {
@@ -49,13 +50,13 @@ class SkRegionAdapter {
49
50
50
51
class DlRegionAdapter {
51
52
public:
52
- DlRegionAdapter () {}
53
-
54
53
explicit DlRegionAdapter (const std::vector<SkIRect>& rects)
55
54
: region_(rects) {}
56
55
57
- void addRegion (const DlRegionAdapter& region) {
58
- region_.addRegion (region.region_ );
56
+ static DlRegionAdapter unionRegions (const DlRegionAdapter& a1,
57
+ const DlRegionAdapter& a2) {
58
+ return DlRegionAdapter (
59
+ flutter::DlRegion::MakeUnion (a1.region_ , a2.region_ ));
59
60
}
60
61
61
62
SkIRect getBounds () { return region_.bounds (); }
@@ -68,9 +69,10 @@ class DlRegionAdapter {
68
69
69
70
std::vector<SkIRect> getRects () { return region_.getRects (false ); }
70
71
71
- DlRegionAdapter (const DlRegionAdapter& copy) : region_(copy.region_, true ) {}
72
-
73
72
private:
73
+ explicit DlRegionAdapter (flutter::DlRegion&& region)
74
+ : region_(std::move(region)) {}
75
+
74
76
flutter::DlRegion region_;
75
77
};
76
78
@@ -120,10 +122,7 @@ void RunAddRegionBenchmark(benchmark::State& state, int maxSize) {
120
122
Region region2 (rects);
121
123
122
124
while (state.KeepRunning ()) {
123
- Region copy_of_region1 (region1);
124
- copy_of_region1.addRegion (region2);
125
- // Region copy_of_region2(region2);
126
- // copy_of_region2.addRegion(region1);
125
+ Region::unionRegions (region1, region2);
127
126
}
128
127
}
129
128
0 commit comments