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>
|
2021-08-29 05:11:06 +00:00
|
|
|
#include <QtTest>
|
2014-08-22 09:10:18 +00:00
|
|
|
// KWin
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/clientbuffer.h"
|
|
|
|
#include "wayland/compositor_interface.h"
|
|
|
|
#include "wayland/display.h"
|
|
|
|
#include "wayland/idleinhibit_v1_interface.h"
|
|
|
|
#include "wayland/shmclientbuffer.h"
|
|
|
|
#include "wayland/surface_interface.h"
|
|
|
|
|
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
|
|
|
|
2022-08-25 08:02:48 +00:00
|
|
|
#include "../../tests/fakeoutput.h"
|
|
|
|
|
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-11-13 07:30:51 +00:00
|
|
|
void testMultipleSurfaces();
|
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:
|
2020-04-29 14:56:38 +00:00
|
|
|
KWaylandServer::Display *m_display;
|
|
|
|
KWaylandServer::CompositorInterface *m_compositorInterface;
|
2020-07-23 20:09:20 +00:00
|
|
|
KWaylandServer::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()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2014-08-28 07:52:35 +00:00
|
|
|
delete m_display;
|
2022-03-05 12:02:08 +00:00
|
|
|
m_display = new KWaylandServer::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()
|
|
|
|
{
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::CompositorInterface::surfaceCreated);
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
QVERIFY(!KWaylandServer::SurfaceInterface::get(nullptr));
|
|
|
|
QVERIFY(!KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface1 = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2015-02-09 13:31:20 +00:00
|
|
|
QVERIFY(serverSurface1);
|
2020-04-29 14:56:38 +00:00
|
|
|
QCOMPARE(KWaylandServer::SurfaceInterface::get(serverSurface1->resource()), serverSurface1);
|
|
|
|
QCOMPARE(KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface2 = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2015-02-09 13:31:20 +00:00
|
|
|
QVERIFY(serverSurface2);
|
2020-04-29 14:56:38 +00:00
|
|
|
QCOMPARE(KWaylandServer::SurfaceInterface::get(serverSurface1->resource()), serverSurface1);
|
|
|
|
QCOMPARE(KWaylandServer::SurfaceInterface::get(serverSurface1->id(), serverSurface1->client()), serverSurface1);
|
|
|
|
QCOMPARE(KWaylandServer::SurfaceInterface::get(serverSurface2->resource()), serverSurface2);
|
|
|
|
QCOMPARE(KWaylandServer::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));
|
2020-07-04 07:51:33 +00:00
|
|
|
QSignalSpy destroyedSpy(serverSurface1, &KWaylandServer::SurfaceInterface::destroyed);
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
2020-04-29 14:56:38 +00:00
|
|
|
QVERIFY(!KWaylandServer::SurfaceInterface::get(nullptr));
|
2020-09-11 11:01:55 +00:00
|
|
|
QVERIFY(!KWaylandServer::SurfaceInterface::get(surfaceId1, nullptr));
|
|
|
|
QVERIFY(!KWaylandServer::SurfaceInterface::get(surfaceId2, nullptr));
|
2014-08-22 09:10:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 07:52:35 +00:00
|
|
|
void TestWaylandSurface::testDamage()
|
|
|
|
{
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
KWaylandServer::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
QCOMPARE(serverSurface->damage(), QRegion());
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!serverSurface->isMapped());
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWaylandServer::SurfaceInterface::committed);
|
|
|
|
QSignalSpy damageSpy(serverSurface, &KWaylandServer::SurfaceInterface::damaged);
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2014-11-28 07:33:32 +00:00
|
|
|
// send damage without a buffer
|
|
|
|
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());
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!serverSurface->isMapped());
|
2019-02-12 14:06:12 +00:00
|
|
|
QCOMPARE(committedSpy.count(), 1);
|
2014-11-28 07:33:32 +00:00
|
|
|
|
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);
|
2020-02-06 11:20:44 +00:00
|
|
|
s->attachBuffer(b, QPoint(55, 55));
|
2014-08-28 07:52:35 +00:00
|
|
|
s->damage(QRect(0, 0, 10, 10));
|
2014-09-17 14:17:26 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(damageSpy.wait());
|
2020-02-06 11:20:44 +00:00
|
|
|
QCOMPARE(serverSurface->offset(), QPoint(55, 55)); // offset is surface local so scale doesn't change this
|
2019-05-08 07:38:37 +00:00
|
|
|
QCOMPARE(serverSurface->damage(), QRegion(0, 0, 5, 5)); // scale is 2
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), QRegion(0, 0, 5, 5));
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(serverSurface->isMapped());
|
2019-02-12 14:06:12 +00:00
|
|
|
QCOMPARE(committedSpy.count(), 2);
|
2014-08-28 07:52:35 +00:00
|
|
|
|
|
|
|
// damage multiple times
|
|
|
|
QRegion testRegion(5, 8, 3, 6);
|
2019-05-08 07:38:37 +00:00
|
|
|
testRegion = testRegion.united(QRect(10, 11, 6, 1));
|
2017-08-30 08:57:41 +00:00
|
|
|
img = QImage(QSize(40, 35), QImage::Format_ARGB32_Premultiplied);
|
2014-11-28 07:33:32 +00:00
|
|
|
img.fill(Qt::black);
|
|
|
|
b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
2014-08-28 07:52:35 +00:00
|
|
|
s->damage(testRegion);
|
|
|
|
damageSpy.clear();
|
2014-09-17 14:17:26 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->damage(), testRegion);
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), testRegion);
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(serverSurface->isMapped());
|
2019-02-12 14:06:12 +00:00
|
|
|
QCOMPARE(committedSpy.count(), 3);
|
2019-05-08 07:38:37 +00:00
|
|
|
|
|
|
|
// damage buffer
|
|
|
|
const QRegion testRegion2(30, 40, 22, 4);
|
|
|
|
const QRegion cmpRegion2(15, 20, 11, 2); // divided by scale factor
|
|
|
|
img = QImage(QSize(80, 70), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
img.fill(Qt::black);
|
|
|
|
b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
|
|
|
s->damageBuffer(testRegion2);
|
|
|
|
damageSpy.clear();
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->damage(), cmpRegion2);
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), cmpRegion2);
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
|
|
|
|
// combined regular damage and damaged buffer
|
|
|
|
const QRegion testRegion3 = testRegion.united(cmpRegion2);
|
|
|
|
img = QImage(QSize(80, 70), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
img.fill(Qt::black);
|
|
|
|
b = m_shm->createBuffer(img);
|
|
|
|
s->attachBuffer(b);
|
|
|
|
s->damage(testRegion);
|
|
|
|
s->damageBuffer(testRegion2);
|
|
|
|
damageSpy.clear();
|
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
QVERIFY(serverSurface->damage() != testRegion);
|
|
|
|
QVERIFY(serverSurface->damage() != testRegion2);
|
|
|
|
QVERIFY(serverSurface->damage() != cmpRegion2);
|
|
|
|
QCOMPARE(serverSurface->damage(), testRegion3);
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), testRegion3);
|
|
|
|
QVERIFY(serverSurface->isMapped());
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testFrameCallback()
|
|
|
|
{
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
KWaylandServer::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy damageSpy(serverSurface, &KWaylandServer::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
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
KWaylandServer::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::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);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy damageSpy(serverSurface, &KWaylandServer::SurfaceInterface::damaged);
|
|
|
|
QSignalSpy mappedSpy(serverSurface, &KWaylandServer::SurfaceInterface::mapped);
|
|
|
|
QSignalSpy unmappedSpy(serverSurface, &KWaylandServer::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
|
2021-07-20 17:02:13 +00:00
|
|
|
KWaylandServer::ClientBuffer *buffer = serverSurface->buffer();
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer->ref();
|
2021-07-20 17:02:13 +00:00
|
|
|
auto shmBuffer = qobject_cast<KWaylandServer::ShmClientBuffer *>(buffer);
|
|
|
|
QVERIFY(shmBuffer);
|
|
|
|
QCOMPARE(shmBuffer->data(), black);
|
|
|
|
QCOMPARE(shmBuffer->data().format(), QImage::Format_RGB32);
|
|
|
|
QCOMPARE(shmBuffer->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());
|
2021-07-20 17:02:13 +00:00
|
|
|
KWaylandServer::ClientBuffer *buffer2 = serverSurface->buffer();
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer2->ref();
|
2021-07-20 17:02:13 +00:00
|
|
|
auto shmBuffer2 = qobject_cast<KWaylandServer::ShmClientBuffer *>(buffer2);
|
|
|
|
QVERIFY(shmBuffer2);
|
|
|
|
QCOMPARE(shmBuffer2->data().format(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
QCOMPARE(shmBuffer2->size(), QSize(24, 24));
|
2017-08-30 08:57:41 +00:00
|
|
|
for (int i = 0; i < 24; ++i) {
|
|
|
|
for (int j = 0; j < 24; ++j) {
|
|
|
|
// it's premultiplied in the format
|
2021-07-20 17:02:13 +00:00
|
|
|
QCOMPARE(shmBuffer2->data().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
|
|
|
|
2021-07-20 17:02:13 +00:00
|
|
|
KWaylandServer::ClientBuffer *buffer3 = serverSurface->buffer();
|
2014-09-19 12:53:03 +00:00
|
|
|
buffer3->ref();
|
2021-07-20 17:02:13 +00:00
|
|
|
auto shmBuffer3 = qobject_cast<KWaylandServer::ShmClientBuffer *>(buffer3);
|
|
|
|
QVERIFY(shmBuffer3);
|
|
|
|
QCOMPARE(shmBuffer3->data().format(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
QCOMPARE(shmBuffer3->size(), QSize(24, 24));
|
2014-09-19 12:53:03 +00:00
|
|
|
for (int i = 0; i < 24; ++i) {
|
|
|
|
for (int j = 0; j < 24; ++j) {
|
|
|
|
// it's premultiplied in the format
|
2021-07-20 17:02:13 +00:00
|
|
|
QCOMPARE(shmBuffer3->data().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-11-13 07:30:51 +00:00
|
|
|
void TestWaylandSurface::testMultipleSurfaces()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2020-03-24 22:08:36 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy shmSpy(®istry, &KWayland::Client::Registry::shmAnnounced);
|
2014-11-13 07:30:51 +00:00
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(shmSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::ShmPool pool1;
|
|
|
|
KWayland::Client::ShmPool pool2;
|
2014-11-13 07:30:51 +00:00
|
|
|
pool1.setup(registry.bindShm(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>()));
|
|
|
|
pool2.setup(registry.bindShm(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>()));
|
|
|
|
QVERIFY(pool1.isValid());
|
|
|
|
QVERIFY(pool2.isValid());
|
|
|
|
|
|
|
|
// create the surfaces
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s1(m_compositor->createSurface());
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface1 = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(serverSurface1);
|
2021-08-29 05:11:06 +00:00
|
|
|
// second surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s2(m_compositor->createSurface());
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface2 = serverSurfaceCreated.last().first().value<KWaylandServer::SurfaceInterface *>();
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(serverSurface2);
|
2014-11-13 12:05:01 +00:00
|
|
|
QVERIFY(serverSurface1->resource() != serverSurface2->resource());
|
2014-11-13 07:30:51 +00:00
|
|
|
|
|
|
|
// create two images
|
|
|
|
QImage black(24, 24, QImage::Format_RGB32);
|
|
|
|
black.fill(Qt::black);
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage red(24, 24, QImage::Format_ARGB32_Premultiplied);
|
2014-11-13 07:30:51 +00:00
|
|
|
red.fill(QColor(255, 0, 0, 128));
|
|
|
|
|
|
|
|
auto blackBuffer = pool1.createBuffer(black);
|
|
|
|
auto redBuffer = pool2.createBuffer(red);
|
|
|
|
|
|
|
|
s1->attachBuffer(blackBuffer);
|
|
|
|
s1->damage(QRect(0, 0, 24, 24));
|
2022-11-08 21:15:17 +00:00
|
|
|
s1->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy damageSpy1(serverSurface1, &KWaylandServer::SurfaceInterface::damaged);
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(damageSpy1.wait());
|
|
|
|
|
|
|
|
// now the ServerSurface should have the black image attached as a buffer
|
2021-07-20 17:02:13 +00:00
|
|
|
ClientBuffer *buffer1 = serverSurface1->buffer();
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(buffer1);
|
2021-07-20 17:02:13 +00:00
|
|
|
QImage buffer1Data = qobject_cast<ShmClientBuffer *>(buffer1)->data();
|
2014-11-13 07:30:51 +00:00
|
|
|
QCOMPARE(buffer1Data, black);
|
|
|
|
// accessing the same buffer is OK
|
2021-07-20 17:02:13 +00:00
|
|
|
QImage buffer1Data2 = qobject_cast<ShmClientBuffer *>(buffer1)->data();
|
2014-11-13 07:30:51 +00:00
|
|
|
QCOMPARE(buffer1Data2, buffer1Data);
|
|
|
|
buffer1Data = QImage();
|
|
|
|
QVERIFY(buffer1Data.isNull());
|
|
|
|
buffer1Data2 = QImage();
|
|
|
|
QVERIFY(buffer1Data2.isNull());
|
|
|
|
|
|
|
|
// attach a buffer for the other surface
|
|
|
|
s2->attachBuffer(redBuffer);
|
|
|
|
s2->damage(QRect(0, 0, 24, 24));
|
2022-11-08 21:15:17 +00:00
|
|
|
s2->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy damageSpy2(serverSurface2, &KWaylandServer::SurfaceInterface::damaged);
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(damageSpy2.wait());
|
|
|
|
|
2021-07-20 17:02:13 +00:00
|
|
|
ClientBuffer *buffer2 = serverSurface2->buffer();
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(buffer2);
|
2021-07-20 17:02:13 +00:00
|
|
|
QImage buffer2Data = qobject_cast<ShmClientBuffer *>(buffer2)->data();
|
2014-11-13 07:30:51 +00:00
|
|
|
QCOMPARE(buffer2Data, red);
|
|
|
|
|
|
|
|
// while buffer2 is accessed we cannot access buffer1
|
2021-07-20 17:02:13 +00:00
|
|
|
buffer1Data = qobject_cast<ShmClientBuffer *>(buffer1)->data();
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(buffer1Data.isNull());
|
|
|
|
|
|
|
|
// a deep copy can be kept around
|
|
|
|
QImage deepCopy = buffer2Data.copy();
|
|
|
|
QCOMPARE(deepCopy, red);
|
|
|
|
buffer2Data = QImage();
|
|
|
|
QVERIFY(buffer2Data.isNull());
|
|
|
|
QCOMPARE(deepCopy, red);
|
|
|
|
|
|
|
|
// now that buffer2Data is destroyed we can access buffer1 again
|
2021-07-20 17:02:13 +00:00
|
|
|
buffer1Data = qobject_cast<ShmClientBuffer *>(buffer1)->data();
|
2014-11-13 07:30:51 +00:00
|
|
|
QVERIFY(!buffer1Data.isNull());
|
|
|
|
QCOMPARE(buffer1Data, black);
|
|
|
|
}
|
|
|
|
|
2014-10-16 12:59:01 +00:00
|
|
|
void TestWaylandSurface::testOpaque()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(serverSurface);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy opaqueRegionChangedSpy(serverSurface, &KWaylandServer::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()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::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());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2014-10-16 12:59:01 +00:00
|
|
|
QVERIFY(serverSurface);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy inputRegionChangedSpy(serverSurface, &KWaylandServer::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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2016-03-21 08:33:05 +00:00
|
|
|
QVERIFY(serverSurface);
|
2020-06-19 06:58:40 +00:00
|
|
|
QCOMPARE(serverSurface->bufferScale(), 1);
|
2016-03-21 08:33:05 +00:00
|
|
|
|
|
|
|
// let's change the scale factor
|
2020-06-19 06:58:40 +00:00
|
|
|
QSignalSpy bufferScaleChangedSpy(serverSurface, &SurfaceInterface::bufferScaleChanged);
|
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);
|
|
|
|
|
2016-03-21 08:33:05 +00:00
|
|
|
s->setScale(2);
|
|
|
|
QCOMPARE(s->scale(), 2);
|
|
|
|
// needs a commit
|
2020-06-19 06:58:40 +00:00
|
|
|
QVERIFY(!bufferScaleChangedSpy.wait(100));
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-06-19 06:58:40 +00:00
|
|
|
QVERIFY(bufferScaleChangedSpy.wait());
|
|
|
|
QCOMPARE(bufferScaleChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(bufferScaleChangedSpy.first().first().toInt(), 2);
|
|
|
|
QCOMPARE(serverSurface->bufferScale(), 2);
|
2016-03-21 08:33:05 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// even though we've changed the scale, if we don't have a buffer we
|
|
|
|
// don't have a size. If we don't have a size it can't have changed
|
2016-11-07 09:56:32 +00:00
|
|
|
QCOMPARE(sizeChangedSpy.count(), 0);
|
2022-06-13 08:33:52 +00:00
|
|
|
QCOMPARE(serverSurface->size(), QSize(0, 0));
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2016-03-21 08:33:05 +00:00
|
|
|
// let's try changing to same factor, should not emit changed on server
|
|
|
|
s->setScale(2);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-06-19 06:58:40 +00:00
|
|
|
QVERIFY(!bufferScaleChangedSpy.wait(100));
|
2016-03-21 08:33:05 +00:00
|
|
|
|
|
|
|
// but changing to a different value should still work
|
|
|
|
s->setScale(4);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2020-06-19 06:58:40 +00:00
|
|
|
QVERIFY(bufferScaleChangedSpy.wait());
|
|
|
|
QCOMPARE(bufferScaleChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(bufferScaleChangedSpy.first().first().toInt(), 2);
|
|
|
|
QCOMPARE(bufferScaleChangedSpy.last().first().toInt(), 4);
|
|
|
|
QCOMPARE(serverSurface->bufferScale(), 4);
|
|
|
|
bufferScaleChangedSpy.clear();
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// attach a buffer of 100x100, our scale is 4, so this should be a size of 25x25
|
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());
|
2021-08-29 05:11:06 +00:00
|
|
|
s->damage(QRect(0, 0, 25, 25));
|
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);
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(serverSurface->size(), QSize(25, 25));
|
2016-11-07 09:56:32 +00:00
|
|
|
sizeChangedSpy.clear();
|
2020-06-19 06:58:40 +00:00
|
|
|
bufferScaleChangedSpy.clear();
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// set the scale to 1, buffer is still 100x100 so size should change to 100x100
|
2016-11-07 09:56:32 +00:00
|
|
|
s->setScale(1);
|
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);
|
2020-06-19 06:58:40 +00:00
|
|
|
QCOMPARE(bufferScaleChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->bufferScale(), 1);
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(serverSurface->size(), QSize(100, 100));
|
2016-11-07 09:56:32 +00:00
|
|
|
sizeChangedSpy.clear();
|
2020-06-19 06:58:40 +00:00
|
|
|
bufferScaleChangedSpy.clear();
|
2016-11-07 09:56:32 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// set scale and size in one commit, buffer is 50x50 at scale 2 so size should be 25x25
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage blue(50, 50, 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());
|
|
|
|
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());
|
|
|
|
QCOMPARE(sizeChangedSpy.count(), 1);
|
2020-06-19 06:58:40 +00:00
|
|
|
QCOMPARE(bufferScaleChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->bufferScale(), 2);
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(serverSurface->size(), QSize(25, 25));
|
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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface *>();
|
2016-03-30 08:16:39 +00:00
|
|
|
|
|
|
|
QSignalSpy unmappedSpy(serverSurface, &SurfaceInterface::unmapped);
|
2020-06-19 06:58:40 +00:00
|
|
|
QSignalSpy bufferScaleChanged(serverSurface, &SurfaceInterface::bufferScaleChanged);
|
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());
|
2016-03-30 08:16:39 +00:00
|
|
|
s->setScale(2);
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-30 08:16:39 +00:00
|
|
|
|
2020-06-19 06:58:40 +00:00
|
|
|
QVERIFY(bufferScaleChanged.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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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());
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::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;
|
2021-07-20 17:02:13 +00:00
|
|
|
QTRY_VERIFY(serverSurface->buffer()->isDestroyed());
|
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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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);
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QVector<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
|
2022-08-25 08:02:48 +00:00
|
|
|
serverSurface->setOutputs(QVector<OutputInterface *>{serverOutput.get()});
|
|
|
|
QCOMPARE(serverSurface->outputs(), QVector<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());
|
|
|
|
QCOMPARE(s->outputs(), QVector<KWayland::Client::Output *>{clientOutput.get()});
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// adding to same should not trigger
|
2022-08-25 08:02:48 +00:00
|
|
|
serverSurface->setOutputs(QVector<OutputInterface *>{serverOutput.get()});
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// leave again
|
2021-08-29 05:11:06 +00:00
|
|
|
serverSurface->setOutputs(QVector<OutputInterface *>());
|
|
|
|
QCOMPARE(serverSurface->outputs(), QVector<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());
|
|
|
|
QCOMPARE(s->outputs(), QVector<KWayland::Client::Output *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// leave again should not trigger
|
2021-08-29 05:11:06 +00:00
|
|
|
serverSurface->setOutputs(QVector<OutputInterface *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
|
|
|
|
// and enter again, just to verify
|
2022-08-25 08:02:48 +00:00
|
|
|
serverSurface->setOutputs(QVector<OutputInterface *>{serverOutput.get()});
|
|
|
|
QCOMPARE(serverSurface->outputs(), QVector<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());
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(serverSurface->outputs(), QVector<OutputInterface *>());
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 16:28:25 +00:00
|
|
|
void TestWaylandSurface::testInhibit()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
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"
|