1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "mockclient.h"
43 #include "testcompositor.h"
45 #include <QtTest/QtTest>
47 class tst_WaylandCompositor : public QObject
52 tst_WaylandCompositor() {
53 setenv("XDG_RUNTIME_DIR", ".", 1);
58 void multipleClients();
64 void tst_WaylandCompositor::singleClient()
66 TestCompositor compositor;
70 wl_surface *sa = client.createSurface();
71 QTRY_COMPARE(compositor.surfaces.size(), 1);
73 wl_surface *sb = client.createSurface();
74 QTRY_COMPARE(compositor.surfaces.size(), 2);
76 WaylandClient *ca = compositor.surfaces.at(0)->client();
77 WaylandClient *cb = compositor.surfaces.at(1)->client();
81 QList<WaylandSurface *> surfaces = compositor.surfacesForClient(ca);
82 QCOMPARE(surfaces.size(), 2);
83 QVERIFY((surfaces.at(0) == compositor.surfaces.at(0) && surfaces.at(1) == compositor.surfaces.at(1))
84 || (surfaces.at(0) == compositor.surfaces.at(1) && surfaces.at(1) == compositor.surfaces.at(0)));
86 wl_surface_destroy(sa);
87 QTRY_COMPARE(compositor.surfaces.size(), 1);
89 wl_surface_destroy(sb);
90 QTRY_COMPARE(compositor.surfaces.size(), 0);
93 void tst_WaylandCompositor::multipleClients()
95 TestCompositor compositor;
101 wl_surface *sa = a.createSurface();
102 wl_surface *sb = b.createSurface();
103 wl_surface *sc = c.createSurface();
105 QTRY_COMPARE(compositor.surfaces.size(), 3);
107 WaylandClient *ca = compositor.surfaces.at(0)->client();
108 WaylandClient *cb = compositor.surfaces.at(1)->client();
109 WaylandClient *cc = compositor.surfaces.at(2)->client();
115 QCOMPARE(compositor.surfacesForClient(ca).size(), 1);
116 QCOMPARE(compositor.surfacesForClient(ca).at(0), compositor.surfaces.at(0));
118 QCOMPARE(compositor.surfacesForClient(cb).size(), 1);
119 QCOMPARE(compositor.surfacesForClient(cb).at(0), compositor.surfaces.at(1));
121 QCOMPARE(compositor.surfacesForClient(cc).size(), 1);
122 QCOMPARE(compositor.surfacesForClient(cc).at(0), compositor.surfaces.at(2));
124 wl_surface_destroy(sa);
125 wl_surface_destroy(sb);
126 wl_surface_destroy(sc);
128 QTRY_COMPARE(compositor.surfaces.size(), 0);
131 void tst_WaylandCompositor::geometry()
133 TestCompositor compositor;
135 QRect geometry(0, 0, 4096, 3072);
136 compositor.setOutputGeometry(geometry);
140 QTRY_COMPARE(client.geometry, geometry);
143 void tst_WaylandCompositor::mapSurface()
145 TestCompositor compositor;
149 wl_surface *surface = client.createSurface();
150 QTRY_COMPARE(compositor.surfaces.size(), 1);
152 WaylandSurface *waylandSurface = compositor.surfaces.at(0);
154 QSignalSpy mappedSpy(waylandSurface, SIGNAL(mapped()));
156 QCOMPARE(waylandSurface->size(), QSize());
157 QCOMPARE(waylandSurface->type(), WaylandSurface::Invalid);
159 QSize size(256, 256);
160 ShmBuffer buffer(size, client.shm);
162 wl_surface_attach(surface, buffer.handle, 0, 0);
163 wl_surface_damage(surface, 0, 0, size.width(), size.height());
165 QTRY_COMPARE(waylandSurface->size(), size);
166 QTRY_COMPARE(waylandSurface->type(), WaylandSurface::Shm);
167 QTRY_COMPARE(mappedSpy.count(), 1);
169 wl_surface_destroy(surface);
172 static void frameCallbackFunc(void *data, wl_callback *callback, uint32_t)
174 ++*static_cast<int *>(data);
175 wl_callback_destroy(callback);
178 static void registerFrameCallback(wl_surface *surface, int *counter)
180 static const wl_callback_listener frameCallbackListener = {
184 wl_callback_add_listener(wl_surface_frame(surface), &frameCallbackListener, counter);
187 void tst_WaylandCompositor::frameCallback()
189 TestCompositor compositor;
194 ShmBuffer buffer(size, client.shm);
196 wl_surface *surface = client.createSurface();
197 wl_surface_attach(surface, buffer.handle, 0, 0);
199 int frameCounter = 0;
201 QTRY_COMPARE(compositor.surfaces.size(), 1);
202 WaylandSurface *waylandSurface = compositor.surfaces.at(0);
203 QSignalSpy damagedSpy(waylandSurface, SIGNAL(damaged(const QRect &)));
205 for (int i = 0; i < 10; ++i) {
206 registerFrameCallback(surface, &frameCounter);
207 wl_surface_damage(surface, 0, 0, size.width(), size.height());
209 QTRY_COMPARE(waylandSurface->type(), WaylandSurface::Shm);
210 QTRY_COMPARE(damagedSpy.count(), i + 1);
212 QCOMPARE(waylandSurface->image(), buffer.image);
213 waylandSurface->frameFinished();
215 QTRY_COMPARE(frameCounter, i + 1);
218 wl_surface_destroy(surface);
221 #include <tst_compositor.moc>
222 QTEST_MAIN(tst_WaylandCompositor);