GCC Code Coverage Report


Directory: ./
File: src/client/region.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 60 62 96.8%
Branches: 12 20 60.0%

Line Branch Exec Source
1 /********************************************************************
2 Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #include "region.h"
21 #include "wayland_pointer_p.h"
22 // Qt
23 #include <QRegion>
24 #include <QVector>
25 // Wayland
26 #include <wayland-client-protocol.h>
27
28 namespace Wrapland
29 {
30 namespace Client
31 {
32
33 class Q_DECL_HIDDEN Region::Private
34 {
35 public:
36 Private(QRegion const& region);
37 void installRegion(QRect const& rect);
38 void installRegion(QRegion const& region);
39 void uninstallRegion(QRect const& rect);
40 void uninstallRegion(QRegion const& region);
41
42 WaylandPointer<wl_region, wl_region_destroy> region;
43 QRegion qtRegion;
44 };
45
46 21 Region::Private::Private(QRegion const& region)
47
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 : qtRegion(region)
48 {
49 21 }
50
51 20 void Region::Private::installRegion(QRect const& rect)
52 {
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!region.isValid()) {
54 return;
55 }
56 20 wl_region_add(region, rect.x(), rect.y(), rect.width(), rect.height());
57 20 }
58
59 22 void Region::Private::installRegion(QRegion const& region)
60 {
61
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 22 times.
41 for (QRect const& rect : region) {
62 19 installRegion(rect);
63 }
64 22 }
65
66 2 void Region::Private::uninstallRegion(QRect const& rect)
67 {
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!region.isValid()) {
69 return;
70 }
71 2 wl_region_subtract(region, rect.x(), rect.y(), rect.width(), rect.height());
72 2 }
73
74 1 void Region::Private::uninstallRegion(QRegion const& region)
75 {
76
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (QRect const& rect : region) {
77 1 uninstallRegion(rect);
78 }
79 1 }
80
81 21 Region::Region(QRegion const& region, QObject* parent)
82 21 : QObject(parent)
83
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
21 , d(new Private(region))
84 21 {
85 21 }
86
87 42 Region::~Region()
88 42 {
89
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 release();
90 42 }
91
92 24 void Region::release()
93 {
94 24 d->region.release();
95 24 }
96
97 21 void Region::setup(wl_region* region)
98 {
99
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 Q_ASSERT(region);
100 21 d->region.setup(region);
101 21 d->installRegion(d->qtRegion);
102 21 }
103
104 6 bool Region::isValid() const
105 {
106 6 return d->region.isValid();
107 }
108
109 1 void Region::add(QRect const& rect)
110 {
111 1 d->qtRegion = d->qtRegion.united(rect);
112 1 d->installRegion(rect);
113 1 }
114
115 1 void Region::add(QRegion const& region)
116 {
117 1 d->qtRegion = d->qtRegion.united(region);
118 1 d->installRegion(region);
119 1 }
120
121 1 void Region::subtract(QRect const& rect)
122 {
123
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 d->qtRegion = d->qtRegion.subtracted(rect);
124 1 d->uninstallRegion(rect);
125 1 }
126
127 1 void Region::subtract(QRegion const& region)
128 {
129 1 d->qtRegion = d->qtRegion.subtracted(region);
130 1 d->uninstallRegion(region);
131 1 }
132
133 7 QRegion Region::region() const
134 {
135 7 return d->qtRegion;
136 }
137
138 6 Region::operator wl_region*() const
139 {
140 6 return d->region;
141 }
142
143 8 Region::operator wl_region*()
144 {
145 8 return d->region;
146 }
147
148 }
149 }
150