Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/scene_qpainter_test.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | Q_OBJECT | 44 | Q_OBJECT | ||
45 | private Q_SLOTS: | 45 | private Q_SLOTS: | ||
46 | void initTestCase(); | 46 | void initTestCase(); | ||
47 | void cleanup(); | 47 | void cleanup(); | ||
48 | void testStartFrame(); | 48 | void testStartFrame(); | ||
49 | void testCursorMoving(); | 49 | void testCursorMoving(); | ||
50 | void testWindow_data(); | 50 | void testWindow_data(); | ||
51 | void testWindow(); | 51 | void testWindow(); | ||
52 | void testCompositorRestart_data(); | ||||
53 | void testCompositorRestart(); | ||||
52 | }; | 54 | }; | ||
53 | 55 | | |||
54 | void SceneQPainterTest::cleanup() | 56 | void SceneQPainterTest::cleanup() | ||
55 | { | 57 | { | ||
56 | Test::destroyWaylandConnection(); | 58 | Test::destroyWaylandConnection(); | ||
57 | } | 59 | } | ||
58 | 60 | | |||
59 | void SceneQPainterTest::initTestCase() | 61 | void SceneQPainterTest::initTestCase() | ||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | 148 | { | |||
183 | // let's move the cursor again | 185 | // let's move the cursor again | ||
184 | KWin::Cursor::setPos(10, 10); | 186 | KWin::Cursor::setPos(10, 10); | ||
185 | QVERIFY(frameRenderedSpy.wait()); | 187 | QVERIFY(frameRenderedSpy.wait()); | ||
186 | painter.fillRect(0, 0, 200, 300, Qt::blue); | 188 | painter.fillRect(0, 0, 200, 300, Qt::blue); | ||
187 | painter.fillRect(5, 5, 10, 10, Qt::red); | 189 | painter.fillRect(5, 5, 10, 10, Qt::red); | ||
188 | QCOMPARE(referenceImage, *scene->backend()->buffer()); | 190 | QCOMPARE(referenceImage, *scene->backend()->buffer()); | ||
189 | } | 191 | } | ||
190 | 192 | | |||
193 | void SceneQPainterTest::testCompositorRestart_data() | ||||
194 | { | ||||
195 | QTest::addColumn<Test::ShellSurfaceType>("type"); | ||||
196 | | ||||
197 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | ||||
198 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | ||||
199 | } | ||||
200 | | ||||
201 | void SceneQPainterTest::testCompositorRestart() | ||||
202 | { | ||||
203 | // this test verifies that the compositor/SceneQPainter survive a restart of the compositor and still render correctly | ||||
204 | KWin::Cursor::setPos(400, 400); | ||||
205 | | ||||
206 | // first create a window | ||||
207 | using namespace KWayland::Client; | ||||
208 | QVERIFY(Test::setupWaylandConnection(s_socketName)); | ||||
209 | QScopedPointer<Surface> s(Test::createSurface()); | ||||
210 | QFETCH(Test::ShellSurfaceType, type); | ||||
211 | QScopedPointer<QObject> ss(Test::createShellSurface(type, s.data())); | ||||
212 | QVERIFY(Test::renderAndWaitForShown(s.data(), QSize(200, 300), Qt::blue)); | ||||
213 | | ||||
214 | // now let's try to reinitialize the compositing scene | ||||
sebas: let's | |||||
215 | auto oldScene = KWin::Compositor::self()->scene(); | ||||
216 | QVERIFY(oldScene); | ||||
217 | QSignalSpy sceneCreatedSpy(KWin::Compositor::self(), &KWin::Compositor::sceneCreated); | ||||
218 | QVERIFY(sceneCreatedSpy.isValid()); | ||||
219 | KWin::Compositor::self()->slotReinitialize(); | ||||
220 | if (sceneCreatedSpy.isEmpty()) { | ||||
221 | QVERIFY(sceneCreatedSpy.wait()); | ||||
222 | } | ||||
223 | QCOMPARE(sceneCreatedSpy.count(), 1); | ||||
224 | auto scene = qobject_cast<SceneQPainter*>(KWin::Compositor::self()->scene()); | ||||
225 | QVERIFY(scene); | ||||
226 | | ||||
227 | // this should directly trigger a frame | ||||
228 | KWin::Compositor::self()->addRepaintFull(); | ||||
229 | QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered); | ||||
230 | QVERIFY(frameRenderedSpy.isValid()); | ||||
231 | QVERIFY(frameRenderedSpy.wait()); | ||||
232 | | ||||
233 | // render reference image | ||||
234 | QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32); | ||||
235 | referenceImage.fill(Qt::black); | ||||
236 | QPainter painter(&referenceImage); | ||||
237 | painter.fillRect(0, 0, 200, 300, Qt::blue); | ||||
238 | const QImage cursorImage = kwinApp()->platform()->softwareCursor(); | ||||
239 | QVERIFY(!cursorImage.isNull()); | ||||
240 | painter.drawImage(QPoint(400, 400) - kwinApp()->platform()->softwareCursorHotspot(), cursorImage); | ||||
241 | QCOMPARE(referenceImage, *scene->backend()->buffer()); | ||||
242 | } | ||||
243 | | ||||
191 | WAYLANDTEST_MAIN(SceneQPainterTest) | 244 | WAYLANDTEST_MAIN(SceneQPainterTest) | ||
192 | #include "scene_qpainter_test.moc" | 245 | #include "scene_qpainter_test.moc" |
let's