2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-06-29 17:22:41 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-06-29 17:22:41 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-06-29 17:22:41 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2016-06-29 17:22:41 +00:00
|
|
|
#include "composite.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/platform.h"
|
2016-06-29 17:22:41 +00:00
|
|
|
#include "cursor.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "effectloader.h"
|
2017-08-11 12:59:09 +00:00
|
|
|
#include "effects.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/shmclientbuffer.h"
|
|
|
|
#include "wayland/surface_interface.h"
|
2016-06-29 17:22:41 +00:00
|
|
|
#include "wayland_server.h"
|
2017-07-27 15:09:40 +00:00
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
#include "x11window.h"
|
2016-06-29 17:22:41 +00:00
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <KWayland/Client/pointer.h>
|
2016-07-01 08:31:45 +00:00
|
|
|
#include <KWayland/Client/seat.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
2016-06-29 17:22:41 +00:00
|
|
|
#include <QPainter>
|
|
|
|
|
2017-07-27 15:09:40 +00:00
|
|
|
#include <netwm.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
2016-06-29 17:22:41 +00:00
|
|
|
using namespace KWin;
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_scene_qpainter-0");
|
|
|
|
|
|
|
|
class SceneQPainterTest : public QObject
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_OBJECT
|
2016-06-29 17:22:41 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
2016-07-01 08:31:45 +00:00
|
|
|
void cleanup();
|
2016-06-29 17:22:41 +00:00
|
|
|
void testStartFrame();
|
|
|
|
void testCursorMoving();
|
2016-07-01 08:31:45 +00:00
|
|
|
void testWindow();
|
2016-11-04 16:53:09 +00:00
|
|
|
void testWindowScaled();
|
2016-07-15 14:06:09 +00:00
|
|
|
void testCompositorRestart();
|
2017-07-27 15:09:40 +00:00
|
|
|
void testX11Window();
|
2022-04-13 06:36:23 +00:00
|
|
|
|
|
|
|
private:
|
2022-04-14 12:33:28 +00:00
|
|
|
QImage grab(Output *output);
|
2016-06-29 17:22:41 +00:00
|
|
|
};
|
|
|
|
|
2016-07-01 08:31:45 +00:00
|
|
|
void SceneQPainterTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:22:41 +00:00
|
|
|
void SceneQPainterTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-06-29 17:22:41 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2016-06-29 17:22:41 +00:00
|
|
|
|
|
|
|
// disable all effects - we don't want to have it interact with the rendering
|
|
|
|
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
KConfigGroup plugins(config, QStringLiteral("Plugins"));
|
2021-10-09 15:38:14 +00:00
|
|
|
const auto builtinNames = EffectLoader().listOfKnownEffects();
|
2016-06-29 17:22:41 +00:00
|
|
|
for (QString name : builtinNames) {
|
|
|
|
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
config->sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
2017-09-24 12:51:35 +00:00
|
|
|
if (!QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("icons/DMZ-White/index.theme")).isEmpty()) {
|
|
|
|
qputenv("XCURSOR_THEME", QByteArrayLiteral("DMZ-White"));
|
|
|
|
} else {
|
|
|
|
// might be vanilla-dmz (e.g. Arch, FreeBSD)
|
|
|
|
qputenv("XCURSOR_THEME", QByteArrayLiteral("Vanilla-DMZ"));
|
|
|
|
}
|
2016-06-29 17:22:41 +00:00
|
|
|
qputenv("XCURSOR_SIZE", QByteArrayLiteral("24"));
|
|
|
|
qputenv("KWIN_COMPOSE", QByteArrayLiteral("Q"));
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(Compositor::self());
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
QImage SceneQPainterTest::grab(Output *output)
|
2022-04-13 06:36:23 +00:00
|
|
|
{
|
|
|
|
QImage image;
|
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(),
|
|
|
|
"captureOutput",
|
|
|
|
Qt::DirectConnection,
|
|
|
|
Q_RETURN_ARG(QImage, image),
|
2022-04-14 12:33:28 +00:00
|
|
|
Q_ARG(Output *, output));
|
2022-04-13 06:36:23 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:22:41 +00:00
|
|
|
void SceneQPainterTest::testStartFrame()
|
|
|
|
{
|
|
|
|
// this test verifies that the initial rendering is correct
|
2021-11-09 10:36:24 +00:00
|
|
|
Compositor::self()->scene()->addRepaintFull();
|
2017-08-11 12:59:09 +00:00
|
|
|
auto scene = Compositor::self()->scene();
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(scene);
|
2019-02-16 19:50:46 +00:00
|
|
|
QCOMPARE(kwinApp()->platform()->selectedCompositor(), QPainterCompositing);
|
2016-06-29 17:22:41 +00:00
|
|
|
QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
// now let's render a reference image for comparison
|
|
|
|
QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32);
|
|
|
|
referenceImage.fill(Qt::black);
|
|
|
|
QPainter p(&referenceImage);
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
auto cursor = KWin::Cursors::self()->mouse();
|
|
|
|
const QImage cursorImage = cursor->image();
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(!cursorImage.isNull());
|
2020-04-02 16:18:01 +00:00
|
|
|
p.drawImage(cursor->pos() - cursor->hotspot(), cursorImage);
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2022-04-13 06:36:23 +00:00
|
|
|
QCOMPARE(referenceImage, grab(outputs.constFirst()));
|
2016-06-29 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneQPainterTest::testCursorMoving()
|
|
|
|
{
|
|
|
|
// this test verifies that rendering is correct also after moving the cursor a few times
|
2017-08-11 12:59:09 +00:00
|
|
|
auto scene = Compositor::self()->scene();
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(scene);
|
|
|
|
QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(0, 0);
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(10, 0);
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(10, 12);
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(12, 14);
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(50, 60);
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(45, 45);
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
// now let's render a reference image for comparison
|
|
|
|
QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32);
|
|
|
|
referenceImage.fill(Qt::black);
|
|
|
|
QPainter p(&referenceImage);
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
auto cursor = Cursors::self()->currentCursor();
|
|
|
|
const QImage cursorImage = cursor->image();
|
2016-06-29 17:22:41 +00:00
|
|
|
QVERIFY(!cursorImage.isNull());
|
2020-04-02 16:18:01 +00:00
|
|
|
p.drawImage(QPoint(45, 45) - cursor->hotspot(), cursorImage);
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2022-04-13 06:36:23 +00:00
|
|
|
QCOMPARE(referenceImage, grab(outputs.constFirst()));
|
2016-06-29 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:31:45 +00:00
|
|
|
void SceneQPainterTest::testWindow()
|
|
|
|
{
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(45, 45);
|
2016-07-01 08:31:45 +00:00
|
|
|
// this test verifies that a window is rendered correctly
|
|
|
|
using namespace KWayland::Client;
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
|
2016-07-01 08:31:45 +00:00
|
|
|
QVERIFY(Test::waitForWaylandPointer());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> ss(Test::createXdgToplevelSurface(s.get()));
|
|
|
|
std::unique_ptr<Pointer> p(Test::waylandSeat()->createPointer());
|
2016-07-01 08:31:45 +00:00
|
|
|
|
2017-08-11 12:59:09 +00:00
|
|
|
auto scene = KWin::Compositor::self()->scene();
|
2016-07-01 08:31:45 +00:00
|
|
|
QVERIFY(scene);
|
|
|
|
QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
2016-07-04 06:12:42 +00:00
|
|
|
|
|
|
|
// now let's map the window
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(Test::renderAndWaitForShown(s.get(), QSize(200, 300), Qt::blue));
|
2016-07-04 06:12:42 +00:00
|
|
|
// which should trigger a frame
|
|
|
|
if (frameRenderedSpy.isEmpty()) {
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
}
|
2018-05-01 13:33:33 +00:00
|
|
|
// we didn't set a cursor image on the surface yet, so it should be just black + window and previous cursor
|
2016-07-01 08:31:45 +00:00
|
|
|
QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32);
|
|
|
|
referenceImage.fill(Qt::black);
|
|
|
|
QPainter painter(&referenceImage);
|
|
|
|
painter.fillRect(0, 0, 200, 300, Qt::blue);
|
|
|
|
|
|
|
|
// now let's set a cursor image
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> cs(Test::createSurface());
|
|
|
|
QVERIFY(cs != nullptr);
|
|
|
|
Test::render(cs.get(), QSize(10, 10), Qt::red);
|
|
|
|
p->setCursor(cs.get(), QPoint(5, 5));
|
2016-07-01 08:31:45 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-04-02 16:18:01 +00:00
|
|
|
painter.fillRect(KWin::Cursors::self()->mouse()->pos().x() - 5, KWin::Cursors::self()->mouse()->pos().y() - 5, 10, 10, Qt::red);
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2022-04-13 06:36:23 +00:00
|
|
|
QCOMPARE(referenceImage, grab(outputs.constFirst()));
|
2016-07-01 08:31:45 +00:00
|
|
|
// let's move the cursor again
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(10, 10);
|
2016-07-01 08:31:45 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
painter.fillRect(0, 0, 200, 300, Qt::blue);
|
|
|
|
painter.fillRect(5, 5, 10, 10, Qt::red);
|
2022-04-13 06:36:23 +00:00
|
|
|
QCOMPARE(referenceImage, grab(outputs.constFirst()));
|
2016-07-01 08:31:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 16:53:09 +00:00
|
|
|
void SceneQPainterTest::testWindowScaled()
|
|
|
|
{
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(10, 10);
|
2016-11-04 16:53:09 +00:00
|
|
|
// this test verifies that a window is rendered correctly
|
|
|
|
using namespace KWayland::Client;
|
2017-05-01 15:10:42 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
|
2016-11-04 16:53:09 +00:00
|
|
|
QVERIFY(Test::waitForWaylandPointer());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> ss(Test::createXdgToplevelSurface(s.get()));
|
|
|
|
std::unique_ptr<Pointer> p(Test::waylandSeat()->createPointer());
|
|
|
|
QSignalSpy pointerEnteredSpy(p.get(), &Pointer::entered);
|
2018-05-01 13:33:33 +00:00
|
|
|
QVERIFY(pointerEnteredSpy.isValid());
|
2016-11-04 16:53:09 +00:00
|
|
|
|
2017-08-11 12:59:09 +00:00
|
|
|
auto scene = KWin::Compositor::self()->scene();
|
2016-11-04 16:53:09 +00:00
|
|
|
QVERIFY(scene);
|
|
|
|
QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
|
|
|
|
|
|
|
// now let's set a cursor image
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> cs(Test::createSurface());
|
|
|
|
QVERIFY(cs != nullptr);
|
|
|
|
Test::render(cs.get(), QSize(10, 10), Qt::red);
|
2016-11-04 16:53:09 +00:00
|
|
|
|
|
|
|
// now let's map the window
|
|
|
|
s->setScale(2);
|
2017-07-31 14:12:37 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// draw a blue square@400x600 with red rectangle@200x200 in the middle
|
|
|
|
const QSize size(400, 600);
|
2017-08-30 09:01:55 +00:00
|
|
|
QImage img(size, QImage::Format_ARGB32_Premultiplied);
|
2017-07-31 14:12:37 +00:00
|
|
|
img.fill(Qt::blue);
|
|
|
|
QPainter surfacePainter(&img);
|
2022-03-23 10:13:38 +00:00
|
|
|
surfacePainter.fillRect(200, 300, 200, 200, Qt::red);
|
2017-07-31 14:12:37 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// add buffer
|
2022-08-01 21:29:02 +00:00
|
|
|
Test::render(s.get(), img);
|
2018-05-01 13:33:33 +00:00
|
|
|
QVERIFY(pointerEnteredSpy.wait());
|
2022-08-01 21:29:02 +00:00
|
|
|
p->setCursor(cs.get(), QPoint(5, 5));
|
2016-11-04 16:53:09 +00:00
|
|
|
|
|
|
|
// which should trigger a frame
|
2018-05-01 13:33:33 +00:00
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2016-11-04 16:53:09 +00:00
|
|
|
QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32);
|
|
|
|
referenceImage.fill(Qt::black);
|
|
|
|
QPainter painter(&referenceImage);
|
|
|
|
painter.fillRect(0, 0, 200, 300, Qt::blue);
|
2017-07-31 14:12:37 +00:00
|
|
|
painter.fillRect(100, 150, 100, 100, Qt::red);
|
2022-03-23 10:13:38 +00:00
|
|
|
painter.fillRect(5, 5, 10, 10, Qt::red); // cursor
|
2016-11-04 16:53:09 +00:00
|
|
|
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2022-04-13 06:36:23 +00:00
|
|
|
QCOMPARE(referenceImage, grab(outputs.constFirst()));
|
2016-11-04 16:53:09 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 14:06:09 +00:00
|
|
|
void SceneQPainterTest::testCompositorRestart()
|
|
|
|
{
|
|
|
|
// this test verifies that the compositor/SceneQPainter survive a restart of the compositor and still render correctly
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(400, 400);
|
2016-07-15 14:06:09 +00:00
|
|
|
|
|
|
|
// first create a window
|
|
|
|
using namespace KWayland::Client;
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> ss(Test::createXdgToplevelSurface(s.get()));
|
|
|
|
QVERIFY(Test::renderAndWaitForShown(s.get(), QSize(200, 300), Qt::blue));
|
2016-07-15 14:06:09 +00:00
|
|
|
|
|
|
|
// now let's try to reinitialize the compositing scene
|
|
|
|
auto oldScene = KWin::Compositor::self()->scene();
|
|
|
|
QVERIFY(oldScene);
|
|
|
|
QSignalSpy sceneCreatedSpy(KWin::Compositor::self(), &KWin::Compositor::sceneCreated);
|
|
|
|
QVERIFY(sceneCreatedSpy.isValid());
|
2019-07-02 20:30:27 +00:00
|
|
|
KWin::Compositor::self()->reinitialize();
|
2016-07-15 14:06:09 +00:00
|
|
|
if (sceneCreatedSpy.isEmpty()) {
|
|
|
|
QVERIFY(sceneCreatedSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(sceneCreatedSpy.count(), 1);
|
2017-08-11 12:59:09 +00:00
|
|
|
auto scene = KWin::Compositor::self()->scene();
|
2016-07-15 14:06:09 +00:00
|
|
|
QVERIFY(scene);
|
|
|
|
|
|
|
|
// this should directly trigger a frame
|
2021-11-09 10:36:24 +00:00
|
|
|
KWin::Compositor::self()->scene()->addRepaintFull();
|
2016-07-15 14:06:09 +00:00
|
|
|
QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
|
|
|
|
// render reference image
|
|
|
|
QImage referenceImage(QSize(1280, 1024), QImage::Format_RGB32);
|
|
|
|
referenceImage.fill(Qt::black);
|
|
|
|
QPainter painter(&referenceImage);
|
|
|
|
painter.fillRect(0, 0, 200, 300, Qt::blue);
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
auto cursor = Cursors::self()->mouse();
|
|
|
|
const QImage cursorImage = cursor->image();
|
2016-07-15 14:06:09 +00:00
|
|
|
QVERIFY(!cursorImage.isNull());
|
2020-04-02 16:18:01 +00:00
|
|
|
painter.drawImage(QPoint(400, 400) - cursor->hotspot(), cursorImage);
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2022-04-13 06:36:23 +00:00
|
|
|
QCOMPARE(referenceImage, grab(outputs.constFirst()));
|
2016-07-15 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 15:09:40 +00:00
|
|
|
struct XcbConnectionDeleter
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
void operator()(xcb_connection_t *pointer)
|
2017-07-27 15:09:40 +00:00
|
|
|
{
|
|
|
|
xcb_disconnect(pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
static bool waitForXwaylandBuffer(Window *window, const QSize &size)
|
2021-06-19 08:07:11 +00:00
|
|
|
{
|
|
|
|
// Usually, when an Xwayland surface is created, it has a buffer of size 1x1,
|
|
|
|
// a buffer with the correct size will be committed a bit later.
|
|
|
|
KWaylandServer::SurfaceInterface *surface = window->surface();
|
|
|
|
int attemptCount = 0;
|
|
|
|
do {
|
|
|
|
if (surface->buffer() && surface->buffer()->size() == size) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
QSignalSpy committedSpy(surface, &KWaylandServer::SurfaceInterface::committed);
|
|
|
|
if (!committedSpy.wait()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
++attemptCount;
|
|
|
|
} while (attemptCount <= 3);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-27 15:09:40 +00:00
|
|
|
void SceneQPainterTest::testX11Window()
|
|
|
|
{
|
|
|
|
// this test verifies the condition of BUG: 382748
|
|
|
|
|
|
|
|
// create X11 window
|
|
|
|
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
|
|
|
|
QVERIFY(windowAddedSpy.isValid());
|
|
|
|
|
|
|
|
// create an xcb window
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2017-07-27 15:09:40 +00:00
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
2022-07-20 12:57:50 +00:00
|
|
|
uint32_t value = Xcb::defaultScreen()->white_pixel;
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2017-07-27 15:09:40 +00:00
|
|
|
windowGeometry.x(),
|
|
|
|
windowGeometry.y(),
|
|
|
|
windowGeometry.width(),
|
|
|
|
windowGeometry.height(),
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, XCB_CW_BACK_PIXEL, &value);
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2017-07-27 15:09:40 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2017-07-27 15:09:40 +00:00
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
QVERIFY(window);
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
QCOMPARE(window->clientSize(), QSize(100, 200));
|
|
|
|
QVERIFY(Test::waitForWaylandSurface(window));
|
2022-05-16 20:13:39 +00:00
|
|
|
QVERIFY(waitForXwaylandBuffer(window, window->size().toSize()));
|
|
|
|
QImage compareImage(window->clientSize().toSize(), QImage::Format_RGB32);
|
2017-07-28 19:17:59 +00:00
|
|
|
compareImage.fill(Qt::white);
|
2022-04-23 19:51:16 +00:00
|
|
|
auto buffer = qobject_cast<KWaylandServer::ShmClientBuffer *>(window->surface()->buffer());
|
2022-05-16 20:13:39 +00:00
|
|
|
QCOMPARE(buffer->data().copy(QRectF(window->clientPos(), window->clientSize()).toRect()), compareImage);
|
2017-07-27 15:09:40 +00:00
|
|
|
|
|
|
|
// enough time for rendering the window
|
|
|
|
QTest::qWait(100);
|
|
|
|
|
2017-08-11 12:59:09 +00:00
|
|
|
auto scene = KWin::Compositor::self()->scene();
|
2017-07-27 15:09:40 +00:00
|
|
|
QVERIFY(scene);
|
|
|
|
|
|
|
|
// this should directly trigger a frame
|
2021-11-09 10:36:24 +00:00
|
|
|
KWin::Compositor::self()->scene()->addRepaintFull();
|
2017-07-27 15:09:40 +00:00
|
|
|
QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
const QPointF startPos = window->pos() + window->clientPos();
|
2022-07-11 10:41:15 +00:00
|
|
|
auto image = grab(workspace()->outputs().constFirst());
|
2022-05-16 20:13:39 +00:00
|
|
|
QCOMPARE(image.copy(QRectF(startPos, window->clientSize()).toAlignedRect()), compareImage);
|
2017-07-27 15:09:40 +00:00
|
|
|
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2017-07-27 15:09:40 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2017-07-27 15:09:40 +00:00
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_destroy_window(c.get(), windowId);
|
2017-07-27 15:09:40 +00:00
|
|
|
c.reset();
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:22:41 +00:00
|
|
|
WAYLANDTEST_MAIN(SceneQPainterTest)
|
|
|
|
#include "scene_qpainter_test.moc"
|