Changeset 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 testWindowScaled(); | ||||
52 | void testCompositorRestart_data(); | 53 | void testCompositorRestart_data(); | ||
53 | void testCompositorRestart(); | 54 | void testCompositorRestart(); | ||
54 | }; | 55 | }; | ||
55 | 56 | | |||
56 | void SceneQPainterTest::cleanup() | 57 | void SceneQPainterTest::cleanup() | ||
57 | { | 58 | { | ||
58 | Test::destroyWaylandConnection(); | 59 | Test::destroyWaylandConnection(); | ||
59 | } | 60 | } | ||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 149 | { | |||
185 | // let's move the cursor again | 186 | // let's move the cursor again | ||
186 | KWin::Cursor::setPos(10, 10); | 187 | KWin::Cursor::setPos(10, 10); | ||
187 | QVERIFY(frameRenderedSpy.wait()); | 188 | QVERIFY(frameRenderedSpy.wait()); | ||
188 | painter.fillRect(0, 0, 200, 300, Qt::blue); | 189 | painter.fillRect(0, 0, 200, 300, Qt::blue); | ||
189 | painter.fillRect(5, 5, 10, 10, Qt::red); | 190 | painter.fillRect(5, 5, 10, 10, Qt::red); | ||
190 | QCOMPARE(referenceImage, *scene->backend()->buffer()); | 191 | QCOMPARE(referenceImage, *scene->backend()->buffer()); | ||
191 | } | 192 | } | ||
192 | 193 | | |||
194 | void SceneQPainterTest::testWindowScaled() | ||||
195 | { | ||||
196 | KWin::Cursor::setPos(10, 10); | ||||
197 | // this test verifies that a window is rendered correctly | ||||
198 | using namespace KWayland::Client; | ||||
199 | QVERIFY(Test::waitForWaylandPointer()); | ||||
graesslin: you don't need to do the Test::setupWaylandConnection in the test, that's part of the init() | |||||
200 | QScopedPointer<Surface> s(Test::createSurface()); | ||||
201 | QScopedPointer<ShellSurface> ss(Test::createShellSurface(s.data())); | ||||
202 | QScopedPointer<Pointer> p(Test::waylandSeat()->createPointer()); | ||||
203 | | ||||
the idea of the Test::createShellSurface variant returning a QObject is to have a test_data() with the two supported modes, so that we test both WlShell and XdgShellUnstableV5. You can compare with other tests. If you want to only test WlShell there is a simplified setup method returning a ShellSurface instead of QObject. graesslin: the idea of the Test::createShellSurface variant returning a QObject is to have a test_data()… | |||||
I don't really need a shell surface at all, I can just remove this. davidedmundson: I don't really need a shell surface at all, I can just remove this. | |||||
the test is called "testWindowScaled", but doesn't create a window. I'm slightly confused. graesslin: the test is called "testWindowScaled", but doesn't create a window. I'm slightly confused. | |||||
It creates a surface on line 200. What's the difference between a top level mapped surface and a window? davidedmundson: It creates a surface on line 200.
What's the difference between a top level mapped surface… | |||||
A surface is something you can attach a buffer to. It's not a window but a wrapper for anything which might need a buffer. E.g. a cursor image. That's what you use in this test. You can create a window from a surface by creating a wl_shell or xgd_shell surface (note it's also called a surface) from it. This will on KWin side then create a ShellClient which represents a window. And I think that's what you want to test as that's what needs to be scaled. graesslin: A surface is something you can attach a buffer to. It's not a window but a wrapper for anything… | |||||
davidedmundson: yeah, sorry. I got confused. You were right. | |||||
204 | auto scene = qobject_cast<SceneQPainter*>(KWin::Compositor::self()->scene()); | ||||
205 | QVERIFY(scene); | ||||
206 | QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered); | ||||
207 | QVERIFY(frameRenderedSpy.isValid()); | ||||
208 | | ||||
209 | // now let's set a cursor image | ||||
210 | QScopedPointer<Surface> cs(Test::createSurface()); | ||||
211 | QVERIFY(!cs.isNull()); | ||||
212 | Test::render(cs.data(), QSize(10, 10), Qt::red); | ||||
213 | p->setCursor(cs.data(), QPoint(5, 5)); | ||||
214 | | ||||
215 | // now let's map the window | ||||
216 | s->setScale(2); | ||||
217 | QVERIFY(Test::renderAndWaitForShown(s.data(), QSize(400, 600), Qt::blue)); | ||||
218 | | ||||
219 | // which should trigger a frame | ||||
220 | if (frameRenderedSpy.isEmpty()) { | ||||
221 | QVERIFY(frameRenderedSpy.wait()); | ||||
222 | } | ||||
223 | QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32); | ||||
224 | referenceImage.fill(Qt::black); | ||||
225 | QPainter painter(&referenceImage); | ||||
226 | painter.fillRect(0, 0, 200, 300, Qt::blue); | ||||
227 | painter.fillRect(5, 5, 10, 10, Qt::red); //cursor | ||||
228 | | ||||
229 | QCOMPARE(referenceImage, *scene->backend()->buffer()); | ||||
230 | } | ||||
231 | | ||||
graesslin: why are you saving to the tmp directory? | |||||
193 | void SceneQPainterTest::testCompositorRestart_data() | 232 | void SceneQPainterTest::testCompositorRestart_data() | ||
194 | { | 233 | { | ||
195 | QTest::addColumn<Test::ShellSurfaceType>("type"); | 234 | QTest::addColumn<Test::ShellSurfaceType>("type"); | ||
196 | 235 | | |||
197 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | 236 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | ||
198 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | 237 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | ||
199 | } | 238 | } | ||
200 | 239 | | |||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
you don't need to do the Test::setupWaylandConnection in the test, that's part of the init()