2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2014-08-22 09:10:18 +00:00
|
|
|
// Qt
|
2014-08-28 12:22:53 +00:00
|
|
|
#include <QImage>
|
2016-04-01 06:36:34 +00:00
|
|
|
#include <QPainter>
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2014-08-22 09:10:18 +00:00
|
|
|
// KWin
|
2023-05-25 11:15:57 +00:00
|
|
|
#include "core/graphicsbuffer.h"
|
|
|
|
#include "core/graphicsbufferview.h"
|
2024-01-02 15:17:18 +00:00
|
|
|
#include "wayland/clientconnection.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/idleinhibit_v1.h"
|
|
|
|
#include "wayland/output.h"
|
|
|
|
#include "wayland/surface.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/idleinhibit.h"
|
|
|
|
#include "KWayland/Client/output.h"
|
|
|
|
#include "KWayland/Client/region.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/shm_pool.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/surface.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2023-10-24 17:23:33 +00:00
|
|
|
#include "../../../tests/fakeoutput.h"
|
2022-08-25 08:02:48 +00:00
|
|
|
|
2014-08-22 09:10:18 +00:00
|
|
|
// Wayland
|
|
|
|
#include <wayland-client-protocol.h>
|
|
|
|
|
|
|
|
class TestWaylandSurface : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestWaylandSurface(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testStaticAccessor();
|
2014-08-28 07:52:35 +00:00
|
|
|
void testDamage();
|
|
|
|
void testFrameCallback();
|
2014-08-28 12:22:53 +00:00
|
|
|
void testAttachBuffer();
|
2014-10-16 12:59:01 +00:00
|
|
|
void testOpaque();
|
|
|
|
void testInput();
|
2016-03-21 08:33:05 +00:00
|
|
|
void testScale();
|
2016-03-30 08:16:39 +00:00
|
|
|
void testUnmapOfNotMappedSurface();
|
2016-04-05 12:26:53 +00:00
|
|
|
void testSurfaceAt();
|
2016-04-13 14:09:11 +00:00
|
|
|
void testDestroyAttachedBuffer();
|
2016-05-25 06:59:10 +00:00
|
|
|
void testDestroyWithPendingCallback();
|
2016-08-22 12:18:23 +00:00
|
|
|
void testOutput();
|
2016-05-19 13:17:07 +00:00
|
|
|
void testDisconnect();
|
2017-10-20 16:28:25 +00:00
|
|
|
void testInhibit();
|
2014-08-22 09:10:18 +00:00
|
|
|
|
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display;
|
|
|
|
KWin::CompositorInterface *m_compositorInterface;
|
|
|
|
KWin::IdleInhibitManagerV1Interface *m_idleInhibitInterface;
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
2014-11-28 07:33:32 +00:00
|
|
|
KWayland::Client::ShmPool *m_shm;
|
2015-05-12 13:51:15 +00:00
|
|
|
KWayland::Client::EventQueue *m_queue;
|
2018-05-29 10:23:20 +00:00
|
|
|
KWayland::Client::IdleInhibitManager *m_idleInhibitManager;
|
2014-08-28 07:52:35 +00:00
|
|
|
QThread *m_thread;
|
2014-08-22 09:10:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwin-test-wayland-surface-0");
|
|
|
|
|
|
|
|
TestWaylandSurface::TestWaylandSurface(QObject *parent)
|
|
|
|
: QObject(parent)
|
2014-08-28 07:52:35 +00:00
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
|
|
|
, m_thread(nullptr)
|
2014-08-22 09:10:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::init()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-08-28 07:52:35 +00:00
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2014-08-28 07:52:35 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
2014-11-28 07:33:32 +00:00
|
|
|
m_display->createShm();
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(m_compositorInterface);
|
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_idleInhibitInterface = new IdleInhibitManagerV1Interface(m_display, m_display);
|
2017-10-20 16:28:25 +00:00
|
|
|
QVERIFY(m_idleInhibitInterface);
|
|
|
|
|
2014-08-28 07:52:35 +00:00
|
|
|
// setup connection
|
2014-09-17 14:17:26 +00:00
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2014-08-28 07:52:35 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
2015-05-12 13:51:15 +00:00
|
|
|
/*connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, m_connection,
|
2014-08-28 07:52:35 +00:00
|
|
|
[this]() {
|
|
|
|
if (m_connection->display()) {
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
}
|
2014-08-22 09:10:18 +00:00
|
|
|
}
|
2015-05-12 13:51:15 +00:00
|
|
|
);*/
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-08-28 07:52:35 +00:00
|
|
|
m_connection->initConnection();
|
2014-08-22 09:10:18 +00:00
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
2015-05-12 13:51:15 +00:00
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2015-05-12 13:51:15 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
|
|
|
|
QSignalSpy shmSpy(®istry, &KWayland::Client::Registry::shmAnnounced);
|
|
|
|
QSignalSpy allAnnounced(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
2014-08-28 07:52:35 +00:00
|
|
|
registry.create(m_connection->display());
|
2014-08-22 09:10:18 +00:00
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
2014-11-28 07:33:32 +00:00
|
|
|
QVERIFY(allAnnounced.wait());
|
|
|
|
QVERIFY(!compositorSpy.isEmpty());
|
|
|
|
QVERIFY(!shmSpy.isEmpty());
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-09-19 08:42:44 +00:00
|
|
|
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(m_compositor->isValid());
|
2014-11-28 07:33:32 +00:00
|
|
|
m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this);
|
|
|
|
QVERIFY(m_shm->isValid());
|
2017-10-20 16:28:25 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_idleInhibitManager = registry.createIdleInhibitManager(registry.interface(KWayland::Client::Registry::Interface::IdleInhibitManagerUnstableV1).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::IdleInhibitManagerUnstableV1).version,
|
2021-08-29 05:11:06 +00:00
|
|
|
this);
|
2017-10-20 16:28:25 +00:00
|
|
|
QVERIFY(m_idleInhibitManager->isValid());
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::cleanup()
|
|
|
|
{
|
|
|
|
if (m_compositor) {
|
|
|
|
delete m_compositor;
|
|
|
|
m_compositor = nullptr;
|
|
|
|
}
|
2017-12-18 21:50:31 +00:00
|
|
|
if (m_idleInhibitManager) {
|
|
|
|
delete m_idleInhibitManager;
|
|
|
|
m_idleInhibitManager = nullptr;
|
|
|
|
}
|
2014-11-28 07:33:32 +00:00
|
|
|
if (m_shm) {
|
|
|
|
delete m_shm;
|
|
|
|
m_shm = nullptr;
|
|
|
|
}
|
2015-05-12 13:51:15 +00:00
|
|
|
if (m_queue) {
|
|
|
|
delete m_queue;
|
|
|
|
m_queue = nullptr;
|
|
|
|
}
|
2014-08-28 07:52:35 +00:00
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
delete m_connection;
|
|
|
|
m_connection = nullptr;
|
|
|
|
|
|
|
|
delete m_display;
|
|
|
|
m_display = nullptr;
|
2020-10-30 13:36:24 +00:00
|
|
|
|
|
|
|
// these are the children of the display
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
m_idleInhibitInterface = nullptr;
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testStaticAccessor()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QVERIFY(!KWin::SurfaceInterface::get(nullptr));
|
|
|
|
QVERIFY(!KWin::SurfaceInterface::get(1, nullptr));
|
2014-09-17 14:17:26 +00:00
|
|
|
QVERIFY(KWayland::Client::Surface::all().isEmpty());
|
2022-07-26 17:16:22 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s1(m_compositor->createSurface());
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(s1->isValid());
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().count(), 1);
|
2022-07-26 17:16:22 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().first(), s1.get());
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s1), s1.get());
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
auto serverSurface1 = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2015-02-09 13:31:20 +00:00
|
|
|
QVERIFY(serverSurface1);
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(KWin::SurfaceInterface::get(serverSurface1->resource()), serverSurface1);
|
|
|
|
QCOMPARE(KWin::SurfaceInterface::get(serverSurface1->id(), serverSurface1->client()), serverSurface1);
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-08-22 11:48:50 +00:00
|
|
|
QVERIFY(!s1->size().isValid());
|
2022-07-26 17:16:22 +00:00
|
|
|
QSignalSpy sizeChangedSpy(s1.get(), &KWayland::Client::Surface::sizeChanged);
|
2014-08-22 11:48:50 +00:00
|
|
|
const QSize testSize(200, 300);
|
|
|
|
s1->setSize(testSize);
|
|
|
|
QCOMPARE(s1->size(), testSize);
|
|
|
|
QCOMPARE(sizeChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(sizeChangedSpy.first().first().toSize(), testSize);
|
|
|
|
|
2014-08-22 09:10:18 +00:00
|
|
|
// add another surface
|
2022-07-26 17:16:22 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s2(m_compositor->createSurface());
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(s2->isValid());
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().count(), 2);
|
2022-07-26 17:16:22 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().first(), s1.get());
|
|
|
|
QCOMPARE(KWayland::Client::Surface::all().last(), s2.get());
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s1), s1.get());
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s2), s2.get());
|
2014-08-28 07:52:35 +00:00
|
|
|
serverSurfaceCreated.clear();
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
auto serverSurface2 = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2015-02-09 13:31:20 +00:00
|
|
|
QVERIFY(serverSurface2);
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(KWin::SurfaceInterface::get(serverSurface1->resource()), serverSurface1);
|
|
|
|
QCOMPARE(KWin::SurfaceInterface::get(serverSurface1->id(), serverSurface1->client()), serverSurface1);
|
|
|
|
QCOMPARE(KWin::SurfaceInterface::get(serverSurface2->resource()), serverSurface2);
|
|
|
|
QCOMPARE(KWin::SurfaceInterface::get(serverSurface2->id(), serverSurface2->client()), serverSurface2);
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2020-09-11 11:01:55 +00:00
|
|
|
const quint32 surfaceId1 = serverSurface1->id();
|
|
|
|
const quint32 surfaceId2 = serverSurface2->id();
|
|
|
|
|
2014-08-22 09:10:18 +00:00
|
|
|
// delete s2 again
|
2022-07-26 17:16:22 +00:00
|
|
|
s2.reset();
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().count(), 1);
|
2022-07-26 17:16:22 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().first(), s1.get());
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s1), s1.get());
|
2014-08-22 09:10:18 +00:00
|
|
|
|
|
|
|
// and finally delete the last one
|
2022-07-26 17:16:22 +00:00
|
|
|
s1.reset();
|
2014-09-17 14:17:26 +00:00
|
|
|
QVERIFY(KWayland::Client::Surface::all().isEmpty());
|
|
|
|
QVERIFY(!KWayland::Client::Surface::get(nullptr));
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy destroyedSpy(serverSurface1, &KWin::SurfaceInterface::destroyed);
|
2020-07-04 07:51:33 +00:00
|
|
|
QVERIFY(destroyedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
QVERIFY(!KWin::SurfaceInterface::get(nullptr));
|
|
|
|
QVERIFY(!KWin::SurfaceInterface::get(surfaceId1, nullptr));
|
|
|
|
QVERIFY(!KWin::SurfaceInterface::get(surfaceId2, nullptr));
|
2014-08-22 09:10:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 07:52:35 +00:00
|
|
|
void TestWaylandSurface::testDamage()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-07-26 17:16:22 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2019-05-08 07:38:37 +00:00
|
|
|
s->setScale(2);
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
2023-06-12 11:12:16 +00:00
|
|
|
QCOMPARE(serverSurface->bufferDamage(), QRegion());
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!serverSurface->isMapped());
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
|
|
|
QSignalSpy damageSpy(serverSurface, &KWin::SurfaceInterface::damaged);
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2014-11-28 07:33:32 +00:00
|
|
|
// send damage without a buffer
|
2023-06-12 11:12:16 +00:00
|
|
|
{
|
|
|
|
s->damage(QRect(0, 0, 100, 100));
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QVERIFY(damageSpy.isEmpty());
|
|
|
|
QVERIFY(!serverSurface->isMapped());
|
|
|
|
QCOMPARE(committedSpy.count(), 1);
|
|
|
|
}
|
2014-11-28 07:33:32 +00:00
|
|
|
|
2023-06-12 11:12:16 +00:00
|
|
|
// surface damage
|
|
|
|
{
|
|
|
|
QImage img(QSize(10, 10), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
img.fill(Qt::black);
|
|
|
|
auto b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b, QPoint(55, 55));
|
|
|
|
s->damage(QRect(0, 0, 10, 10));
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->offset(), QPoint(55, 55)); // offset is surface local so scale doesn't change this
|
|
|
|
QCOMPARE(serverSurface->bufferDamage(), QRegion(0, 0, 10, 10));
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), QRegion(0, 0, 10, 10));
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
QCOMPARE(committedSpy.count(), 2);
|
|
|
|
}
|
2014-08-28 07:52:35 +00:00
|
|
|
|
|
|
|
// damage multiple times
|
2023-06-12 11:12:16 +00:00
|
|
|
{
|
|
|
|
const QRegion surfaceDamage = QRegion(5, 8, 3, 6).united(QRect(10, 11, 6, 1));
|
|
|
|
const QRegion expectedDamage = QRegion(10, 16, 6, 12).united(QRect(20, 22, 12, 2));
|
2023-12-20 20:15:38 +00:00
|
|
|
QImage img(QSize(80, 70), QImage::Format_ARGB32_Premultiplied);
|
2023-06-12 11:12:16 +00:00
|
|
|
img.fill(Qt::black);
|
|
|
|
auto b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
|
|
|
s->damage(surfaceDamage);
|
|
|
|
damageSpy.clear();
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->bufferDamage(), expectedDamage);
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), expectedDamage);
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
QCOMPARE(committedSpy.count(), 3);
|
|
|
|
}
|
2019-05-08 07:38:37 +00:00
|
|
|
|
|
|
|
// damage buffer
|
2023-06-12 11:12:16 +00:00
|
|
|
{
|
|
|
|
const QRegion damage(30, 40, 22, 4);
|
|
|
|
QImage img(QSize(80, 70), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
img.fill(Qt::black);
|
|
|
|
auto b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
|
|
|
s->damageBuffer(damage);
|
|
|
|
damageSpy.clear();
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->bufferDamage(), damage);
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), damage);
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
}
|
2019-05-08 07:38:37 +00:00
|
|
|
|
|
|
|
// combined regular damage and damaged buffer
|
2023-06-12 11:12:16 +00:00
|
|
|
{
|
|
|
|
const QRegion surfaceDamage(10, 20, 5, 5);
|
|
|
|
const QRegion bufferDamage(30, 50, 50, 20);
|
|
|
|
const QRegion expectedDamage = QRegion(20, 40, 10, 10).united(QRect(30, 50, 50, 20));
|
|
|
|
QImage img(QSize(80, 70), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
img.fill(Qt::black);
|
|
|
|
auto b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
|
|
|
s->damage(surfaceDamage);
|
|
|
|
s->damageBuffer(bufferDamage);
|
|
|
|
damageSpy.clear();
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->bufferDamage(), expectedDamage);
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), expectedDamage);
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
}
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testFrameCallback()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-07-26 17:16:22 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy damageSpy(serverSurface, &KWin::SurfaceInterface::damaged);
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2022-07-26 17:16:22 +00:00
|
|
|
QSignalSpy frameRenderedSpy(s.get(), &KWayland::Client::Surface::frameRendered);
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage img(QSize(10, 10), QImage::Format_ARGB32_Premultiplied);
|
2014-11-28 07:33:32 +00:00
|
|
|
img.fill(Qt::black);
|
|
|
|
auto b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
2014-08-28 07:52:35 +00:00
|
|
|
s->damage(QRect(0, 0, 10, 10));
|
|
|
|
s->commit();
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
serverSurface->frameRendered(10);
|
|
|
|
QVERIFY(frameRenderedSpy.isEmpty());
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
QVERIFY(!frameRenderedSpy.isEmpty());
|
|
|
|
}
|
|
|
|
|
2014-08-28 12:22:53 +00:00
|
|
|
void TestWaylandSurface::testAttachBuffer()
|
|
|
|
{
|
|
|
|
// create the surface
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-07-26 17:16:22 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2014-08-28 12:22:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2014-08-28 12:22:53 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2017-08-30 08:57:41 +00:00
|
|
|
// create three images
|
2014-09-19 12:53:03 +00:00
|
|
|
QImage black(24, 24, QImage::Format_RGB32);
|
2014-08-28 12:22:53 +00:00
|
|
|
black.fill(Qt::black);
|
2021-08-29 05:11:06 +00:00
|
|
|
QImage red(24, 24, QImage::Format_ARGB32); // Note - deliberately not premultiplied
|
2014-08-28 12:22:53 +00:00
|
|
|
red.fill(QColor(255, 0, 0, 128));
|
2014-09-19 12:53:03 +00:00
|
|
|
QImage blue(24, 24, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
blue.fill(QColor(0, 0, 255, 128));
|
2014-08-28 12:22:53 +00:00
|
|
|
|
2019-09-17 11:36:40 +00:00
|
|
|
QSharedPointer<KWayland::Client::Buffer> blackBufferPtr = m_shm->createBuffer(black).toStrongRef();
|
|
|
|
QVERIFY(blackBufferPtr);
|
|
|
|
wl_buffer *blackBuffer = *(blackBufferPtr.data());
|
|
|
|
QSharedPointer<KWayland::Client::Buffer> redBuffer = m_shm->createBuffer(red).toStrongRef();
|
|
|
|
QVERIFY(redBuffer);
|
|
|
|
QSharedPointer<KWayland::Client::Buffer> blueBuffer = m_shm->createBuffer(blue).toStrongRef();
|
|
|
|
QVERIFY(blueBuffer);
|
2014-09-20 13:11:40 +00:00
|
|
|
|
|
|
|
QCOMPARE(blueBuffer->format(), KWayland::Client::Buffer::Format::ARGB32);
|
|
|
|
QCOMPARE(blueBuffer->size(), blue.size());
|
|
|
|
QVERIFY(!blueBuffer->isReleased());
|
|
|
|
QVERIFY(!blueBuffer->isUsed());
|
|
|
|
QCOMPARE(blueBuffer->stride(), blue.bytesPerLine());
|
2014-08-28 12:22:53 +00:00
|
|
|
|
2014-09-22 07:54:10 +00:00
|
|
|
s->attachBuffer(redBuffer.data());
|
2014-08-28 12:22:53 +00:00
|
|
|
s->attachBuffer(blackBuffer);
|
|
|
|
s->damage(QRect(0, 0, 24, 24));
|
2014-09-17 14:17:26 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy damageSpy(serverSurface, &KWin::SurfaceInterface::damaged);
|
|
|
|
QSignalSpy mappedSpy(serverSurface, &KWin::SurfaceInterface::mapped);
|
|
|
|
QSignalSpy unmappedSpy(serverSurface, &KWin::SurfaceInterface::unmapped);
|
2014-08-28 12:22:53 +00:00
|
|
|
QVERIFY(damageSpy.wait());
|
2020-05-04 11:55:15 +00:00
|
|
|
QCOMPARE(mappedSpy.count(), 1);
|
2014-11-28 07:33:32 +00:00
|
|
|
QVERIFY(unmappedSpy.isEmpty());
|
2014-08-28 12:22:53 +00:00
|
|
|
|
|
|
|
// now the ServerSurface should have the black image attached as a buffer
|
2023-04-28 07:30:18 +00:00
|
|
|
KWin::GraphicsBuffer *buffer = serverSurface->buffer();
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer->ref();
|
2023-05-25 11:15:57 +00:00
|
|
|
{
|
|
|
|
KWin::GraphicsBufferView view(buffer);
|
|
|
|
QVERIFY(view.image());
|
|
|
|
QCOMPARE(*view.image(), black);
|
|
|
|
QCOMPARE(view.image()->format(), QImage::Format_RGB32);
|
|
|
|
QCOMPARE(view.image()->size(), QSize(24, 24));
|
|
|
|
}
|
2014-08-28 12:22:53 +00:00
|
|
|
|
|
|
|
// render another frame
|
|
|
|
s->attachBuffer(redBuffer);
|
|
|
|
s->damage(QRect(0, 0, 24, 24));
|
2014-09-17 14:17:26 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-08-28 12:22:53 +00:00
|
|
|
damageSpy.clear();
|
|
|
|
QVERIFY(damageSpy.wait());
|
2020-05-04 11:55:15 +00:00
|
|
|
QCOMPARE(mappedSpy.count(), 1);
|
2014-11-28 07:33:32 +00:00
|
|
|
QVERIFY(unmappedSpy.isEmpty());
|
2023-04-28 07:30:18 +00:00
|
|
|
KWin::GraphicsBuffer *buffer2 = serverSurface->buffer();
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer2->ref();
|
2023-05-25 11:15:57 +00:00
|
|
|
{
|
|
|
|
KWin::GraphicsBufferView view(buffer2);
|
|
|
|
QVERIFY(view.image());
|
|
|
|
QCOMPARE(view.image()->format(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
QCOMPARE(view.image()->size(), QSize(24, 24));
|
|
|
|
for (int i = 0; i < 24; ++i) {
|
|
|
|
for (int j = 0; j < 24; ++j) {
|
|
|
|
// it's premultiplied in the format
|
|
|
|
QCOMPARE(view.image()->pixel(i, j), qRgba(128, 0, 0, 128));
|
|
|
|
}
|
2017-08-30 08:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer2->unref();
|
2014-09-20 13:11:40 +00:00
|
|
|
QVERIFY(buffer2->isReferenced());
|
2014-09-22 07:54:10 +00:00
|
|
|
QVERIFY(!redBuffer.data()->isReleased());
|
2014-08-28 12:22:53 +00:00
|
|
|
|
2014-09-19 12:53:03 +00:00
|
|
|
// render another frame
|
2014-09-20 13:11:40 +00:00
|
|
|
blueBuffer->setUsed(true);
|
|
|
|
QVERIFY(blueBuffer->isUsed());
|
2014-09-22 07:54:10 +00:00
|
|
|
s->attachBuffer(blueBuffer.data());
|
2014-09-19 12:53:03 +00:00
|
|
|
s->damage(QRect(0, 0, 24, 24));
|
2022-07-26 17:16:22 +00:00
|
|
|
QSignalSpy frameRenderedSpy(s.get(), &KWayland::Client::Surface::frameRendered);
|
2014-09-20 14:28:47 +00:00
|
|
|
s->commit();
|
2014-09-19 12:53:03 +00:00
|
|
|
damageSpy.clear();
|
|
|
|
QVERIFY(damageSpy.wait());
|
2020-05-04 11:55:15 +00:00
|
|
|
QCOMPARE(mappedSpy.count(), 1);
|
2014-11-28 07:33:32 +00:00
|
|
|
QVERIFY(unmappedSpy.isEmpty());
|
2014-09-20 13:11:40 +00:00
|
|
|
QVERIFY(!buffer2->isReferenced());
|
|
|
|
// TODO: we should have a signal on when the Buffer gets released
|
2015-04-21 06:56:19 +00:00
|
|
|
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
|
2015-05-12 13:51:15 +00:00
|
|
|
if (!redBuffer.data()->isReleased()) {
|
|
|
|
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
|
|
|
|
}
|
2014-09-22 07:54:10 +00:00
|
|
|
QVERIFY(redBuffer.data()->isReleased());
|
2014-09-20 13:11:40 +00:00
|
|
|
|
2023-04-28 07:30:18 +00:00
|
|
|
KWin::GraphicsBuffer *buffer3 = serverSurface->buffer();
|
2014-09-19 12:53:03 +00:00
|
|
|
buffer3->ref();
|
2023-05-25 11:15:57 +00:00
|
|
|
{
|
|
|
|
KWin::GraphicsBufferView view(buffer3);
|
|
|
|
QVERIFY(view.image());
|
|
|
|
QCOMPARE(view.image()->format(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
QCOMPARE(view.image()->size(), QSize(24, 24));
|
|
|
|
for (int i = 0; i < 24; ++i) {
|
|
|
|
for (int j = 0; j < 24; ++j) {
|
|
|
|
// it's premultiplied in the format
|
|
|
|
QCOMPARE(view.image()->pixel(i, j), qRgba(0, 0, 128, 128));
|
|
|
|
}
|
2014-09-19 12:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer3->unref();
|
2014-09-20 13:11:40 +00:00
|
|
|
QVERIFY(buffer3->isReferenced());
|
2014-09-19 12:53:03 +00:00
|
|
|
|
2014-09-20 14:28:47 +00:00
|
|
|
serverSurface->frameRendered(1);
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
|
|
|
|
2014-11-28 07:33:32 +00:00
|
|
|
// commit a different value shouldn't change our buffer
|
|
|
|
QCOMPARE(serverSurface->buffer(), buffer3);
|
|
|
|
damageSpy.clear();
|
|
|
|
s->setInputRegion(m_compositor->createRegion(QRegion(0, 0, 24, 24)).get());
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(serverSurface->buffer(), buffer3);
|
|
|
|
QVERIFY(damageSpy.isEmpty());
|
2020-05-04 11:55:15 +00:00
|
|
|
QCOMPARE(mappedSpy.count(), 1);
|
2014-11-28 07:33:32 +00:00
|
|
|
QVERIFY(unmappedSpy.isEmpty());
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(serverSurface->isMapped());
|
2014-11-28 07:33:32 +00:00
|
|
|
|
|
|
|
// clear the surface
|
|
|
|
s->attachBuffer(blackBuffer);
|
|
|
|
s->damage(QRect(0, 0, 1, 1));
|
|
|
|
// TODO: better method
|
2021-08-29 05:11:06 +00:00
|
|
|
s->attachBuffer((wl_buffer *)nullptr);
|
2014-11-28 07:33:32 +00:00
|
|
|
s->damage(QRect(0, 0, 10, 10));
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(unmappedSpy.wait());
|
2020-05-04 11:55:15 +00:00
|
|
|
QCOMPARE(mappedSpy.count(), 1);
|
2014-11-28 07:33:32 +00:00
|
|
|
QCOMPARE(unmappedSpy.count(), 1);
|
|
|
|
QVERIFY(damageSpy.isEmpty());
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!serverSurface->isMapped());
|
2014-11-28 07:33:32 +00:00
|
|
|
|
2014-08-28 12:22:53 +00:00
|
|
|
// TODO: add signal test on release
|
|
|
|
buffer->unref();
|
|
|
|
}
|
|
|
|
|
2014-10-16 12:59:01 +00:00
|
|
|
void TestWaylandSurface::testOpaque()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(serverSurface);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy opaqueRegionChangedSpy(serverSurface, &KWin::SurfaceInterface::opaqueChanged);
|
2014-10-16 12:59:01 +00:00
|
|
|
|
|
|
|
// by default there should be an empty opaque region
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion());
|
|
|
|
|
|
|
|
// let's install an opaque region
|
|
|
|
s->setOpaqueRegion(m_compositor->createRegion(QRegion(0, 10, 20, 30)).get());
|
2014-12-12 07:36:07 +00:00
|
|
|
// the region should only be applied after the surface got committed
|
2014-10-16 12:59:01 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion());
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 0);
|
|
|
|
|
|
|
|
// so let's commit to get the new region
|
2022-04-15 08:53:30 +00:00
|
|
|
QImage black(20, 40, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
black.fill(Qt::black);
|
|
|
|
QSharedPointer<KWayland::Client::Buffer> buffer1 = m_shm->createBuffer(black).toStrongRef();
|
|
|
|
s->attachBuffer(buffer1);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(opaqueRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.last().first().value<QRegion>(), QRegion(0, 10, 20, 30));
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion(0, 10, 20, 30));
|
|
|
|
|
|
|
|
// committing without setting a new region shouldn't change
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-16 12:59:01 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion(0, 10, 20, 30));
|
|
|
|
|
2022-04-15 08:53:30 +00:00
|
|
|
// let's change the opaque region, it will be clipped with rect(0, 0, 20, 40)
|
2014-10-16 12:59:01 +00:00
|
|
|
s->setOpaqueRegion(m_compositor->createRegion(QRegion(10, 20, 30, 40)).get());
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(opaqueRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 2);
|
2022-04-15 08:53:30 +00:00
|
|
|
QCOMPARE(opaqueRegionChangedSpy.last().first().value<QRegion>(), QRegion(10, 20, 10, 20));
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion(10, 20, 10, 20));
|
2014-10-16 12:59:01 +00:00
|
|
|
|
|
|
|
// and let's go back to an empty region
|
|
|
|
s->setOpaqueRegion();
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(opaqueRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 3);
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.last().first().value<QRegion>(), QRegion());
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testInput()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(serverSurface);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy inputRegionChangedSpy(serverSurface, &KWin::SurfaceInterface::inputChanged);
|
2020-10-17 10:16:28 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &SurfaceInterface::committed);
|
2014-10-16 12:59:01 +00:00
|
|
|
|
2020-10-17 10:16:28 +00:00
|
|
|
// the input region should be empty if the surface has no buffer
|
|
|
|
QVERIFY(!serverSurface->isMapped());
|
2014-10-16 12:59:01 +00:00
|
|
|
QCOMPARE(serverSurface->input(), QRegion());
|
2020-10-17 10:16:28 +00:00
|
|
|
|
|
|
|
// the default input region is infinite
|
|
|
|
QImage black(100, 50, QImage::Format_RGB32);
|
|
|
|
black.fill(Qt::black);
|
|
|
|
QSharedPointer<KWayland::Client::Buffer> buffer1 = m_shm->createBuffer(black).toStrongRef();
|
|
|
|
QVERIFY(buffer1);
|
|
|
|
s->attachBuffer(buffer1);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-10-17 10:16:28 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 0, 100, 50));
|
2014-10-16 12:59:01 +00:00
|
|
|
|
|
|
|
// let's install an input region
|
|
|
|
s->setInputRegion(m_compositor->createRegion(QRegion(0, 10, 20, 30)).get());
|
2014-12-12 07:36:07 +00:00
|
|
|
// the region should only be applied after the surface got committed
|
2014-10-16 12:59:01 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2020-10-17 10:16:28 +00:00
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 0, 100, 50));
|
2014-10-16 12:59:01 +00:00
|
|
|
|
|
|
|
// so let's commit to get the new region
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-10-17 10:16:28 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 2);
|
2014-10-16 12:59:01 +00:00
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 10, 20, 30));
|
|
|
|
|
|
|
|
// committing without setting a new region shouldn't change
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-16 12:59:01 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2020-10-17 10:16:28 +00:00
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 2);
|
2014-10-16 12:59:01 +00:00
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 10, 20, 30));
|
|
|
|
|
2020-10-17 10:16:28 +00:00
|
|
|
// let's change the input region, note that the new input region is cropped
|
2014-10-16 12:59:01 +00:00
|
|
|
s->setInputRegion(m_compositor->createRegion(QRegion(10, 20, 30, 40)).get());
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-10-17 10:16:28 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 3);
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(10, 20, 30, 30));
|
2014-10-16 12:59:01 +00:00
|
|
|
|
|
|
|
// and let's go back to an empty region
|
|
|
|
s->setInputRegion();
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-10-17 10:16:28 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 4);
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 0, 100, 50));
|
2014-10-16 12:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 08:33:05 +00:00
|
|
|
void TestWaylandSurface::testScale()
|
|
|
|
{
|
|
|
|
// this test verifies that updating the scale factor is correctly passed to the Wayland server
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-21 08:33:05 +00:00
|
|
|
// create surface
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2016-03-21 08:33:05 +00:00
|
|
|
QCOMPARE(s->scale(), 1);
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2016-03-21 08:33:05 +00:00
|
|
|
QVERIFY(serverSurface);
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// changing the scale implicitly changes the size
|
2016-11-07 09:56:32 +00:00
|
|
|
QSignalSpy sizeChangedSpy(serverSurface, &SurfaceInterface::sizeChanged);
|
|
|
|
|
2023-07-04 12:50:30 +00:00
|
|
|
// attach a buffer of 100x100
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage red(100, 100, QImage::Format_ARGB32_Premultiplied);
|
2016-11-07 09:56:32 +00:00
|
|
|
red.fill(QColor(255, 0, 0, 128));
|
2022-11-08 21:15:17 +00:00
|
|
|
QSharedPointer<KWayland::Client::Buffer> redBuffer = m_shm->createBuffer(red).toStrongRef();
|
2019-09-17 11:36:40 +00:00
|
|
|
QVERIFY(redBuffer);
|
2016-11-07 09:56:32 +00:00
|
|
|
s->attachBuffer(redBuffer.data());
|
2023-07-04 12:50:30 +00:00
|
|
|
s->damageBuffer(QRect(0, 0, 100, 100));
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-07 09:56:32 +00:00
|
|
|
QVERIFY(sizeChangedSpy.wait());
|
|
|
|
QCOMPARE(sizeChangedSpy.count(), 1);
|
2023-07-04 12:50:30 +00:00
|
|
|
QCOMPARE(serverSurface->size(), QSize(100, 100));
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2023-07-04 12:50:30 +00:00
|
|
|
// set the scale to 2, buffer is still 100x100 so size should change to 50x50
|
|
|
|
s->setScale(2);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-07 09:56:32 +00:00
|
|
|
QVERIFY(sizeChangedSpy.wait());
|
2023-07-04 12:50:30 +00:00
|
|
|
QCOMPARE(sizeChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(serverSurface->size(), QSize(50, 50));
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2023-07-04 12:50:30 +00:00
|
|
|
// set scale and size in one commit, buffer is 60x60 at scale 3 so size should be 20x20
|
|
|
|
QImage blue(60, 60, QImage::Format_ARGB32_Premultiplied);
|
2016-11-07 09:56:32 +00:00
|
|
|
red.fill(QColor(255, 0, 0, 128));
|
2022-11-08 21:15:17 +00:00
|
|
|
QSharedPointer<KWayland::Client::Buffer> blueBuffer = m_shm->createBuffer(blue).toStrongRef();
|
2019-09-17 11:36:40 +00:00
|
|
|
QVERIFY(blueBuffer);
|
2016-11-07 09:56:32 +00:00
|
|
|
s->attachBuffer(blueBuffer.data());
|
2023-07-04 12:50:30 +00:00
|
|
|
s->setScale(3);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-11-07 09:56:32 +00:00
|
|
|
QVERIFY(sizeChangedSpy.wait());
|
2023-07-04 12:50:30 +00:00
|
|
|
QCOMPARE(sizeChangedSpy.count(), 3);
|
|
|
|
QCOMPARE(serverSurface->size(), QSize(20, 20));
|
2016-03-21 08:33:05 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 08:16:39 +00:00
|
|
|
void TestWaylandSurface::testUnmapOfNotMappedSurface()
|
|
|
|
{
|
|
|
|
// this test verifies that a surface which doesn't have a buffer attached doesn't trigger the unmapped signal
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-30 08:16:39 +00:00
|
|
|
// create surface
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2016-03-30 08:16:39 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2016-03-30 08:16:39 +00:00
|
|
|
|
|
|
|
QSignalSpy unmappedSpy(serverSurface, &SurfaceInterface::unmapped);
|
2023-07-04 12:50:30 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &SurfaceInterface::committed);
|
2016-03-30 08:16:39 +00:00
|
|
|
|
|
|
|
// let's map a null buffer and change scale to trigger a signal we can wait for
|
2022-11-08 21:15:17 +00:00
|
|
|
s->attachBuffer(KWayland::Client::Buffer::Ptr());
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-30 08:16:39 +00:00
|
|
|
|
2023-07-04 12:50:30 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
2016-03-30 08:16:39 +00:00
|
|
|
QVERIFY(unmappedSpy.isEmpty());
|
|
|
|
}
|
|
|
|
|
2016-04-05 12:26:53 +00:00
|
|
|
void TestWaylandSurface::testSurfaceAt()
|
|
|
|
{
|
|
|
|
// this test verifies that surfaceAt(const QPointF&) works as expected for the case of no children
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-04-05 12:26:53 +00:00
|
|
|
// create surface
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2016-04-05 12:26:53 +00:00
|
|
|
|
|
|
|
// a newly created surface should not be mapped and not provide a surface at a position
|
|
|
|
QVERIFY(!serverSurface->isMapped());
|
|
|
|
QVERIFY(!serverSurface->surfaceAt(QPointF(0, 0)));
|
|
|
|
|
|
|
|
// let's damage this surface
|
|
|
|
QSignalSpy sizeChangedSpy(serverSurface, &SurfaceInterface::sizeChanged);
|
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::red);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
s->damage(QRect(0, 0, 100, 100));
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(sizeChangedSpy.wait());
|
|
|
|
|
|
|
|
// now the surface is mapped and surfaceAt should give the surface
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
QCOMPARE(serverSurface->surfaceAt(QPointF(0, 0)), serverSurface);
|
2022-06-10 10:20:40 +00:00
|
|
|
QCOMPARE(serverSurface->surfaceAt(QPointF(99, 99)), serverSurface);
|
2016-04-05 12:26:53 +00:00
|
|
|
// outside the geometry it should not give a surface
|
2022-06-10 10:20:40 +00:00
|
|
|
QVERIFY(!serverSurface->surfaceAt(QPointF(100, 100)));
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(!serverSurface->surfaceAt(QPointF(-1, -1)));
|
|
|
|
}
|
|
|
|
|
2016-04-13 14:09:11 +00:00
|
|
|
void TestWaylandSurface::testDestroyAttachedBuffer()
|
|
|
|
{
|
|
|
|
// this test verifies that destroying of a buffer attached to a surface works
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-04-13 14:09:11 +00:00
|
|
|
// create surface
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2016-04-13 14:09:11 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
2016-04-13 14:09:11 +00:00
|
|
|
|
|
|
|
// let's damage this surface
|
|
|
|
QSignalSpy damagedSpy(serverSurface, &SurfaceInterface::damaged);
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
2016-04-13 14:09:11 +00:00
|
|
|
image.fill(Qt::red);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
s->damage(QRect(0, 0, 100, 100));
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-13 14:09:11 +00:00
|
|
|
QVERIFY(damagedSpy.wait());
|
|
|
|
QVERIFY(serverSurface->buffer());
|
|
|
|
|
|
|
|
// attach another buffer
|
|
|
|
image.fill(Qt::blue);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
m_connection->flush();
|
|
|
|
|
|
|
|
// Let's try to destroy it
|
|
|
|
delete m_shm;
|
|
|
|
m_shm = nullptr;
|
2023-04-12 08:05:26 +00:00
|
|
|
QTRY_VERIFY(serverSurface->buffer()->isDropped());
|
2016-04-13 14:09:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 06:59:10 +00:00
|
|
|
void TestWaylandSurface::testDestroyWithPendingCallback()
|
|
|
|
{
|
|
|
|
// this test tries to verify that destroying a surface with a pending callback works correctly
|
|
|
|
// first create surface
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(s != nullptr);
|
2016-05-25 06:59:10 +00:00
|
|
|
QVERIFY(s->isValid());
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-05-25 06:59:10 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
// now render to it
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage img(QSize(10, 10), QImage::Format_ARGB32_Premultiplied);
|
2016-05-25 06:59:10 +00:00
|
|
|
img.fill(Qt::black);
|
|
|
|
auto b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
|
|
|
s->damage(QRect(0, 0, 10, 10));
|
|
|
|
// add some frame callbacks
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
wl_surface_frame(*s);
|
|
|
|
}
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::FrameCallback);
|
|
|
|
QSignalSpy damagedSpy(serverSurface, &SurfaceInterface::damaged);
|
|
|
|
QVERIFY(damagedSpy.wait());
|
|
|
|
|
|
|
|
// now try to destroy the Surface again
|
|
|
|
QSignalSpy destroyedSpy(serverSurface, &QObject::destroyed);
|
|
|
|
s.reset();
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2016-05-19 13:17:07 +00:00
|
|
|
void TestWaylandSurface::testDisconnect()
|
|
|
|
{
|
|
|
|
// this test verifies that the server side correctly tears down the resources when the client disconnects
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(s != nullptr);
|
2016-05-19 13:17:07 +00:00
|
|
|
QVERIFY(s->isValid());
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-05-19 13:17:07 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
// destroy client
|
|
|
|
QSignalSpy clientDisconnectedSpy(serverSurface->client(), &ClientConnection::disconnected);
|
|
|
|
QSignalSpy surfaceDestroyedSpy(serverSurface, &QObject::destroyed);
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
QVERIFY(clientDisconnectedSpy.wait());
|
|
|
|
QCOMPARE(clientDisconnectedSpy.count(), 1);
|
2016-08-08 06:38:57 +00:00
|
|
|
if (surfaceDestroyedSpy.isEmpty()) {
|
|
|
|
QVERIFY(surfaceDestroyedSpy.wait());
|
|
|
|
}
|
2016-06-13 12:55:36 +00:00
|
|
|
QTRY_COMPARE(surfaceDestroyedSpy.count(), 1);
|
2016-05-19 13:17:07 +00:00
|
|
|
|
|
|
|
s->destroy();
|
|
|
|
m_shm->destroy();
|
|
|
|
m_compositor->destroy();
|
|
|
|
m_queue->destroy();
|
2017-12-19 07:28:54 +00:00
|
|
|
m_idleInhibitManager->destroy();
|
2016-05-19 13:17:07 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 12:18:23 +00:00
|
|
|
void TestWaylandSurface::testOutput()
|
|
|
|
{
|
|
|
|
// This test verifies that the enter/leave are sent correctly to the Client
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2021-08-29 05:11:06 +00:00
|
|
|
qRegisterMetaType<KWayland::Client::Output *>();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(s != nullptr);
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(s->isValid());
|
|
|
|
QVERIFY(s->outputs().isEmpty());
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy enteredSpy(s.get(), &KWayland::Client::Surface::outputEntered);
|
|
|
|
QSignalSpy leftSpy(s.get(), &KWayland::Client::Surface::outputLeft);
|
2016-08-22 12:18:23 +00:00
|
|
|
// wait for the surface on the Server side
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(serverSurface);
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QList<OutputInterface *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// create another registry to get notified about added outputs
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2016-08-22 12:18:23 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy allAnnounced(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
2016-08-22 12:18:23 +00:00
|
|
|
registry.create(m_connection);
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(allAnnounced.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy outputAnnouncedSpy(®istry, &KWayland::Client::Registry::outputAnnounced);
|
2016-08-22 12:18:23 +00:00
|
|
|
|
2022-08-25 08:02:48 +00:00
|
|
|
auto outputHandle = std::make_unique<FakeOutput>();
|
|
|
|
auto serverOutput = std::make_unique<OutputInterface>(m_display, outputHandle.get());
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(outputAnnouncedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Output> clientOutput(
|
2021-08-29 05:11:06 +00:00
|
|
|
registry.createOutput(outputAnnouncedSpy.first().first().value<quint32>(), outputAnnouncedSpy.first().last().value<quint32>()));
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(clientOutput->isValid());
|
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
// now enter it
|
2023-10-23 17:57:59 +00:00
|
|
|
serverSurface->setOutputs(QList<OutputInterface *>{serverOutput.get()}, serverOutput.get());
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QList<OutputInterface *>{serverOutput.get()});
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(enteredSpy.first().first().value<KWayland::Client::Output *>(), clientOutput.get());
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(s->outputs(), QList<KWayland::Client::Output *>{clientOutput.get()});
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// adding to same should not trigger
|
2023-10-23 17:57:59 +00:00
|
|
|
serverSurface->setOutputs(QList<OutputInterface *>{serverOutput.get()}, serverOutput.get());
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// leave again
|
2023-10-23 17:57:59 +00:00
|
|
|
serverSurface->setOutputs(QList<OutputInterface *>(), nullptr);
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QList<OutputInterface *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
|
|
|
QCOMPARE(leftSpy.count(), 1);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(leftSpy.first().first().value<KWayland::Client::Output *>(), clientOutput.get());
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(s->outputs(), QList<KWayland::Client::Output *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// leave again should not trigger
|
2023-10-23 17:57:59 +00:00
|
|
|
serverSurface->setOutputs(QList<OutputInterface *>(), nullptr);
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// and enter again, just to verify
|
2023-10-23 17:57:59 +00:00
|
|
|
serverSurface->setOutputs(QList<OutputInterface *>{serverOutput.get()}, serverOutput.get());
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QList<OutputInterface *>{serverOutput.get()});
|
2016-08-22 12:18:23 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 2);
|
|
|
|
QCOMPARE(leftSpy.count(), 1);
|
2017-08-18 14:14:36 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// delete output client is on.
|
|
|
|
// client should get an exit and be left on no outputs (which is allowed)
|
2022-08-25 08:02:48 +00:00
|
|
|
serverOutput.reset();
|
|
|
|
outputHandle.reset();
|
2017-08-26 10:53:09 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
2023-10-19 06:50:15 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QList<OutputInterface *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 16:28:25 +00:00
|
|
|
void TestWaylandSurface::testInhibit()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2017-10-20 16:28:25 +00:00
|
|
|
// wait for the surface on the Server side
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2017-10-20 16:28:25 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), false);
|
|
|
|
|
|
|
|
QSignalSpy inhibitsChangedSpy(serverSurface, &SurfaceInterface::inhibitsIdleChanged);
|
|
|
|
|
|
|
|
// now create an idle inhibition
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::IdleInhibitor> inhibitor1(m_idleInhibitManager->createInhibitor(s.get()));
|
2017-10-20 16:28:25 +00:00
|
|
|
QVERIFY(inhibitsChangedSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), true);
|
|
|
|
|
|
|
|
// creating a second idle inhibition should not trigger the signal
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::IdleInhibitor> inhibitor2(m_idleInhibitManager->createInhibitor(s.get()));
|
2018-07-17 09:30:16 +00:00
|
|
|
QVERIFY(!inhibitsChangedSpy.wait(500));
|
2017-10-20 16:28:25 +00:00
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), true);
|
|
|
|
|
|
|
|
// and also deleting the first inhibitor should not yet change the inhibition
|
|
|
|
inhibitor1.reset();
|
2018-07-17 09:30:16 +00:00
|
|
|
QVERIFY(!inhibitsChangedSpy.wait(500));
|
2017-10-20 16:28:25 +00:00
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), true);
|
|
|
|
|
|
|
|
// but deleting also the second inhibitor should trigger
|
|
|
|
inhibitor2.reset();
|
|
|
|
QVERIFY(inhibitsChangedSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), false);
|
|
|
|
QCOMPARE(inhibitsChangedSpy.count(), 2);
|
|
|
|
|
|
|
|
// recreate inhibitor1 should inhibit again
|
2022-08-01 21:29:02 +00:00
|
|
|
inhibitor1.reset(m_idleInhibitManager->createInhibitor(s.get()));
|
2017-10-20 16:28:25 +00:00
|
|
|
QVERIFY(inhibitsChangedSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), true);
|
|
|
|
// and destroying should uninhibit
|
|
|
|
inhibitor1.reset();
|
|
|
|
QVERIFY(inhibitsChangedSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->inhibitsIdle(), false);
|
|
|
|
QCOMPARE(inhibitsChangedSpy.count(), 4);
|
|
|
|
}
|
|
|
|
|
2014-09-23 10:00:17 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestWaylandSurface)
|
2014-08-22 09:10:18 +00:00
|
|
|
#include "test_wayland_surface.moc"
|