GCC Code Coverage Report


Directory: ./
File: src/client/subsurface.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 79 88 89.8%
Branches: 18 35 51.4%

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 "subsurface.h"
21 #include "surface.h"
22 #include "wayland_pointer_p.h"
23 // Wayland
24 #include <wayland-client-protocol.h>
25
26 namespace Wrapland
27 {
28 namespace Client
29 {
30
31 class Q_DECL_HIDDEN SubSurface::Private
32 {
33 public:
34 Private(QPointer<Surface> surface, QPointer<Surface> parentSurface, SubSurface* q);
35 void setup(wl_subsurface* subsurface);
36
37 WaylandPointer<wl_subsurface, wl_subsurface_destroy> subSurface;
38 QPointer<Surface> surface;
39 QPointer<Surface> parentSurface;
40 27 Mode mode = Mode::Synchronized;
41 27 QPoint pos = QPoint(0, 0);
42
43 static SubSurface* cast(wl_subsurface* native);
44
45 private:
46 SubSurface* q;
47 };
48
49 27 SubSurface::Private::Private(QPointer<Surface> surface,
50 QPointer<Surface> parentSurface,
51 SubSurface* q)
52 27 : surface(surface)
53 27 , parentSurface(parentSurface)
54 27 , q(q)
55 {
56 27 }
57
58 27 void SubSurface::Private::setup(wl_subsurface* subsurface)
59 {
60
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 Q_ASSERT(subsurface);
61
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 Q_ASSERT(!subSurface.isValid());
62 27 subSurface.setup(subsurface);
63 27 wl_subsurface_set_user_data(subsurface, this);
64 27 }
65
66 1 SubSurface* SubSurface::Private::cast(wl_subsurface* native)
67 {
68 1 return reinterpret_cast<Private*>(wl_subsurface_get_user_data(native))->q;
69 }
70
71 27 SubSurface::SubSurface(QPointer<Surface> surface, QPointer<Surface> parentSurface, QObject* parent)
72 27 : QObject(parent)
73
2/6
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
27 , d(new Private(surface, parentSurface, this))
74 27 {
75 27 }
76
77 54 SubSurface::~SubSurface()
78 54 {
79
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 release();
80 54 }
81
82 27 void SubSurface::setup(wl_subsurface* subsurface)
83 {
84 27 d->setup(subsurface);
85 27 }
86
87 29 void SubSurface::release()
88 {
89 29 d->subSurface.release();
90 29 }
91
92 5 bool SubSurface::isValid() const
93 {
94 5 return d->subSurface.isValid();
95 }
96
97 8 QPointer<Surface> SubSurface::surface() const
98 {
99 8 return d->surface;
100 }
101
102 QPointer<Surface> SubSurface::parentSurface() const
103 {
104 return d->parentSurface;
105 }
106
107 13 void SubSurface::setMode(SubSurface::Mode mode)
108 {
109
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 if (mode == d->mode) {
110 1 return;
111 }
112 12 d->mode = mode;
113
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
12 switch (d->mode) {
114 case Mode::Synchronized:
115 1 wl_subsurface_set_sync(d->subSurface);
116 1 break;
117 case Mode::Desynchronized:
118 11 wl_subsurface_set_desync(d->subSurface);
119 11 break;
120 }
121 13 }
122
123 4 SubSurface::Mode SubSurface::mode() const
124 {
125 4 return d->mode;
126 }
127
128 5 void SubSurface::setPosition(QPoint const& pos)
129 {
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (pos == d->pos) {
131 return;
132 }
133 5 d->pos = pos;
134 5 wl_subsurface_set_position(d->subSurface, pos.x(), pos.y());
135 5 }
136
137 3 QPoint SubSurface::position() const
138 {
139 3 return d->pos;
140 }
141
142 1 void SubSurface::raise()
143 {
144
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 placeAbove(d->parentSurface);
145 1 }
146
147 4 void SubSurface::placeAbove(QPointer<SubSurface> sibling)
148 {
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (sibling.isNull()) {
150 return;
151 }
152
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 placeAbove(sibling->surface());
153 4 }
154
155 5 void SubSurface::placeAbove(QPointer<Surface> sibling)
156 {
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (sibling.isNull()) {
158 return;
159 }
160 5 wl_subsurface_place_above(d->subSurface, *sibling);
161 5 }
162
163 1 void SubSurface::lower()
164 {
165
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 placeBelow(d->parentSurface);
166 1 }
167
168 5 void SubSurface::placeBelow(QPointer<Surface> sibling)
169 {
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (sibling.isNull()) {
171 return;
172 }
173 5 wl_subsurface_place_below(d->subSurface, *sibling);
174 5 }
175
176 4 void SubSurface::placeBelow(QPointer<SubSurface> sibling)
177 {
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (sibling.isNull()) {
179 return;
180 }
181
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 placeBelow(sibling->surface());
182 4 }
183
184 1 QPointer<SubSurface> SubSurface::get(wl_subsurface* native)
185 {
186 1 return QPointer<SubSurface>(Private::cast(native));
187 }
188
189 SubSurface::operator wl_subsurface*() const
190 {
191 return d->subSurface;
192 }
193
194 1 SubSurface::operator wl_subsurface*()
195 {
196 1 return d->subSurface;
197 }
198
199 }
200 }
201