2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-10-14 12:04:35 +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-10-14 12:04:35 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2014-10-14 12:04:35 +00:00
|
|
|
// KWin
|
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/subcompositor.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/region.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/shm_pool.h"
|
|
|
|
#include "KWayland/Client/subcompositor.h"
|
|
|
|
#include "KWayland/Client/subsurface.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2014-10-14 12:04:35 +00:00
|
|
|
// Wayland
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
Q_DECLARE_METATYPE(KWayland::Client::SubSurface::Mode)
|
|
|
|
|
2014-10-14 12:04:35 +00:00
|
|
|
class TestSubSurface : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestSubSurface(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testCreate();
|
|
|
|
void testMode();
|
2020-10-31 14:03:30 +00:00
|
|
|
void testPosition_data();
|
2014-10-14 12:04:35 +00:00
|
|
|
void testPosition();
|
|
|
|
void testPlaceAbove();
|
|
|
|
void testPlaceBelow();
|
2016-03-21 13:32:31 +00:00
|
|
|
void testSyncMode();
|
|
|
|
void testDeSyncMode();
|
2016-03-23 15:59:18 +00:00
|
|
|
void testMainSurfaceFromTree();
|
2016-03-24 11:45:46 +00:00
|
|
|
void testRemoveSurface();
|
2016-03-29 13:49:01 +00:00
|
|
|
void testMappingOfSurfaceTree();
|
2016-04-05 12:26:53 +00:00
|
|
|
void testSurfaceAt();
|
2016-04-13 14:09:11 +00:00
|
|
|
void testDestroyAttachedBuffer();
|
2018-02-04 15:57:23 +00:00
|
|
|
void testDestroyParentSurface();
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display;
|
|
|
|
KWin::CompositorInterface *m_compositorInterface;
|
|
|
|
KWin::SubCompositorInterface *m_subcompositorInterface;
|
2014-10-14 12:04:35 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
2016-03-21 13:32:31 +00:00
|
|
|
KWayland::Client::ShmPool *m_shm;
|
2014-10-14 12:04:35 +00:00
|
|
|
KWayland::Client::SubCompositor *m_subCompositor;
|
|
|
|
KWayland::Client::EventQueue *m_queue;
|
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-subsurface-0");
|
|
|
|
|
|
|
|
TestSubSurface::TestSubSurface(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_subcompositorInterface(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
2016-03-21 13:32:31 +00:00
|
|
|
, m_shm(nullptr)
|
2014-10-14 12:04:35 +00:00
|
|
|
, m_subCompositor(nullptr)
|
|
|
|
, m_queue(nullptr)
|
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::init()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-10-14 12:04: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-10-14 12:04:35 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
2016-03-21 13:32:31 +00:00
|
|
|
m_display->createShm();
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2014-10-14 12:04:35 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
|
|
|
|
KWayland::Client::Registry registry;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
|
|
|
|
QSignalSpy subCompositorSpy(®istry, &KWayland::Client::Registry::subCompositorAnnounced);
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(!registry.eventQueue());
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
QCOMPARE(registry.eventQueue(), m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
|
|
|
m_subcompositorInterface = new SubCompositorInterface(m_display, m_display);
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(m_subcompositorInterface);
|
|
|
|
|
|
|
|
QVERIFY(subCompositorSpy.wait());
|
|
|
|
m_subCompositor = registry.createSubCompositor(subCompositorSpy.first().first().value<quint32>(), subCompositorSpy.first().last().value<quint32>(), this);
|
|
|
|
|
|
|
|
if (compositorSpy.isEmpty()) {
|
|
|
|
QVERIFY(compositorSpy.wait());
|
|
|
|
}
|
|
|
|
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
|
2016-03-21 13:32:31 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
m_shm = registry.createShmPool(registry.interface(KWayland::Client::Registry::Interface::Shm).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::Shm).version,
|
|
|
|
this);
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(m_shm->isValid());
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::cleanup()
|
|
|
|
{
|
2016-03-21 13:32:31 +00:00
|
|
|
if (m_shm) {
|
|
|
|
delete m_shm;
|
|
|
|
m_shm = nullptr;
|
|
|
|
}
|
2014-10-14 12:04:35 +00:00
|
|
|
if (m_subCompositor) {
|
|
|
|
delete m_subCompositor;
|
|
|
|
m_subCompositor = nullptr;
|
|
|
|
}
|
|
|
|
if (m_compositor) {
|
|
|
|
delete m_compositor;
|
|
|
|
m_compositor = nullptr;
|
|
|
|
}
|
|
|
|
if (m_queue) {
|
|
|
|
delete m_queue;
|
|
|
|
m_queue = nullptr;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::testCreate()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// create two Surfaces
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
surfaceCreatedSpy.clear();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverParentSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverParentSurface);
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, &KWin::SubCompositorInterface::subSurfaceCreated);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// create subSurface for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface(m_subCompositor->createSubSurface(surface.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface);
|
2014-11-20 15:40:14 +00:00
|
|
|
QVERIFY(serverSubSurface->parentSurface());
|
2020-10-31 14:03:30 +00:00
|
|
|
QCOMPARE(serverSubSurface->parentSurface(), serverParentSurface);
|
|
|
|
QCOMPARE(serverSubSurface->surface(), serverSurface);
|
|
|
|
QCOMPARE(serverSurface->subSurface(), serverSubSurface);
|
|
|
|
QCOMPARE(serverSubSurface->mainSurface(), serverParentSurface);
|
2014-10-14 12:04:35 +00:00
|
|
|
// children are only added after committing the surface
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverParentSurface->below().count(), 0);
|
2016-03-21 14:53:13 +00:00
|
|
|
QEXPECT_FAIL("", "Incorrect adding of child windows to workaround QtWayland behavior", Continue);
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverParentSurface->above().count(), 0);
|
2014-10-14 12:04:35 +00:00
|
|
|
// so let's commit the surface, to apply the stacking change
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverParentSurface->below().count(), 0);
|
|
|
|
QCOMPARE(serverParentSurface->above().count(), 1);
|
|
|
|
QCOMPARE(serverParentSurface->above().constFirst(), serverSubSurface);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// and let's destroy it again
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy destroyedSpy(serverSubSurface, &QObject::destroyed);
|
2014-10-14 12:04:35 +00:00
|
|
|
subSurface.reset();
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
|
|
|
QCOMPARE(serverSurface->subSurface(), QPointer<SubSurfaceInterface>());
|
|
|
|
// only applied after next commit
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverParentSurface->below().count(), 0);
|
2016-03-21 14:53:13 +00:00
|
|
|
QEXPECT_FAIL("", "Incorrect removing of child windows to workaround QtWayland behavior", Continue);
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverParentSurface->above().count(), 1);
|
2014-10-14 12:04:35 +00:00
|
|
|
// but the surface should be invalid
|
2021-06-01 10:50:33 +00:00
|
|
|
if (!serverParentSurface->above().isEmpty()) {
|
|
|
|
QVERIFY(!serverParentSurface->above().constFirst());
|
2016-03-21 14:53:13 +00:00
|
|
|
}
|
2014-10-14 12:04:35 +00:00
|
|
|
// committing the state should solve it
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverParentSurface->below().count(), 0);
|
|
|
|
QCOMPARE(serverParentSurface->above().count(), 0);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::testMode()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-10-14 12:04:35 +00:00
|
|
|
// create two Surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, &KWin::SubCompositorInterface::subSurfaceCreated);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// create the SubSurface for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface(m_subCompositor->createSubSurface(surface.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface);
|
|
|
|
|
|
|
|
// both client and server subsurface should be in synchronized mode
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(subSurface->mode(), KWayland::Client::SubSurface::Mode::Synchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
QCOMPARE(serverSubSurface->mode(), SubSurfaceInterface::Mode::Synchronized);
|
|
|
|
|
|
|
|
// verify that we can change to desynchronized
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy modeChangedSpy(serverSubSurface, &KWin::SubSurfaceInterface::modeChanged);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
|
|
|
QCOMPARE(subSurface->mode(), KWayland::Client::SubSurface::Mode::Desynchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
QVERIFY(modeChangedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(modeChangedSpy.first().first().value<KWin::SubSurfaceInterface::Mode>(), SubSurfaceInterface::Mode::Desynchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
QCOMPARE(serverSubSurface->mode(), SubSurfaceInterface::Mode::Desynchronized);
|
|
|
|
|
|
|
|
// setting the same again won't change
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
|
|
|
QCOMPARE(subSurface->mode(), KWayland::Client::SubSurface::Mode::Desynchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
// not testing the signal, we do that after changing to synchronized
|
|
|
|
|
|
|
|
// and change back to synchronized
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface->setMode(KWayland::Client::SubSurface::Mode::Synchronized);
|
|
|
|
QCOMPARE(subSurface->mode(), KWayland::Client::SubSurface::Mode::Synchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
QVERIFY(modeChangedSpy.wait());
|
|
|
|
QCOMPARE(modeChangedSpy.count(), 2);
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(modeChangedSpy.first().first().value<KWin::SubSurfaceInterface::Mode>(), SubSurfaceInterface::Mode::Desynchronized);
|
|
|
|
QCOMPARE(modeChangedSpy.last().first().value<KWin::SubSurfaceInterface::Mode>(), SubSurfaceInterface::Mode::Synchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
QCOMPARE(serverSubSurface->mode(), SubSurfaceInterface::Mode::Synchronized);
|
|
|
|
}
|
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
void TestSubSurface::testPosition_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWayland::Client::SubSurface::Mode>("commitMode");
|
|
|
|
|
|
|
|
QTest::addRow("sync") << KWayland::Client::SubSurface::Mode::Synchronized;
|
|
|
|
QTest::addRow("desync") << KWayland::Client::SubSurface::Mode::Desynchronized;
|
|
|
|
}
|
|
|
|
|
2014-10-14 12:04:35 +00:00
|
|
|
void TestSubSurface::testPosition()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-10-14 12:04:35 +00:00
|
|
|
// create two Surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, &KWin::SubCompositorInterface::subSurfaceCreated);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// create the SubSurface for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface(m_subCompositor->createSubSurface(surface.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface);
|
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
// put the subsurface in the desired commit mode
|
|
|
|
QFETCH(KWayland::Client::SubSurface::Mode, commitMode);
|
|
|
|
subSurface->setMode(commitMode);
|
|
|
|
|
2014-10-14 12:04:35 +00:00
|
|
|
// both client and server should have a default position
|
|
|
|
QCOMPARE(subSurface->position(), QPoint());
|
|
|
|
QCOMPARE(serverSubSurface->position(), QPoint());
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy positionChangedSpy(serverSubSurface, &KWin::SubSurfaceInterface::positionChanged);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// changing the position should not trigger a direct update on server side
|
|
|
|
subSurface->setPosition(QPoint(10, 20));
|
|
|
|
QCOMPARE(subSurface->position(), QPoint(10, 20));
|
|
|
|
// ensure it's processed on server side
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(serverSubSurface->position(), QPoint());
|
|
|
|
// changing once more
|
|
|
|
subSurface->setPosition(QPoint(20, 30));
|
|
|
|
QCOMPARE(subSurface->position(), QPoint(20, 30));
|
|
|
|
// ensure it's processed on server side
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(serverSubSurface->position(), QPoint());
|
|
|
|
|
|
|
|
// committing the parent surface should update the position
|
2021-02-02 17:27:46 +00:00
|
|
|
QSignalSpy parentCommittedSpy(serverSubSurface->parentSurface(), &SurfaceInterface::committed);
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-02 17:27:46 +00:00
|
|
|
QVERIFY(parentCommittedSpy.wait());
|
2014-10-14 12:04:35 +00:00
|
|
|
QCOMPARE(positionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(positionChangedSpy.first().first().toPoint(), QPoint(20, 30));
|
|
|
|
QCOMPARE(serverSubSurface->position(), QPoint(20, 30));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::testPlaceAbove()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-10-14 12:04:35 +00:00
|
|
|
// create needed Surfaces (one parent, three client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface3(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, &KWin::SubCompositorInterface::subSurfaceCreated);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// create the SubSurfaces for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface1(m_subCompositor->createSubSurface(surface1.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface1 = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface1);
|
|
|
|
subSurfaceCreatedSpy.clear();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface2(m_subCompositor->createSubSurface(surface2.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface2 = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface2);
|
|
|
|
subSurfaceCreatedSpy.clear();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface3(m_subCompositor->createSubSurface(surface3.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface3 = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface3);
|
|
|
|
subSurfaceCreatedSpy.clear();
|
|
|
|
|
|
|
|
// so far the stacking order should still be empty
|
2021-06-01 10:50:33 +00:00
|
|
|
QVERIFY(serverSubSurface1->parentSurface()->below().isEmpty());
|
2016-03-21 14:53:13 +00:00
|
|
|
QEXPECT_FAIL("", "Incorrect adding of child windows to workaround QtWayland behavior", Continue);
|
2021-06-01 10:50:33 +00:00
|
|
|
QVERIFY(serverSubSurface1->parentSurface()->above().isEmpty());
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2014-12-12 07:36:07 +00:00
|
|
|
// committing the parent should create the stacking order
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
// ensure it's processed on server side
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().count(), 0);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface3);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// raising subsurface1 should place it to top of stack
|
2022-08-01 21:29:02 +00:00
|
|
|
subSurface1->placeAbove(subSurface3.get());
|
2014-10-14 12:04:35 +00:00
|
|
|
// ensure it's processed on server side
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
// but as long as parent is not committed it shouldn't change on server side
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface1);
|
2014-10-14 12:04:35 +00:00
|
|
|
// after commit it's changed
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface1);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// try placing 3 above 1, should result in 2, 1, 3
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface3->placeAbove(subSurface1.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface3);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// try placing 3 above 2, should result in 2, 3, 1
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface3->placeAbove(subSurface2.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface1);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// try placing 1 above 3 - shouldn't change
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface1->placeAbove(subSurface3.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface1);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// and 2 above 3 - > 3, 2, 1
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface2->placeAbove(subSurface3.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface1);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::testPlaceBelow()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-10-14 12:04:35 +00:00
|
|
|
// create needed Surfaces (one parent, three client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface3(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, &KWin::SubCompositorInterface::subSurfaceCreated);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// create the SubSurfaces for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface1(m_subCompositor->createSubSurface(surface1.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface1 = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface1);
|
|
|
|
subSurfaceCreatedSpy.clear();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface2(m_subCompositor->createSubSurface(surface2.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface2 = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface2);
|
|
|
|
subSurfaceCreatedSpy.clear();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface3(m_subCompositor->createSubSurface(surface3.get(), parent.get()));
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(subSurfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SubSurfaceInterface *serverSubSurface3 = subSurfaceCreatedSpy.first().first().value<KWin::SubSurfaceInterface *>();
|
2014-10-14 12:04:35 +00:00
|
|
|
QVERIFY(serverSubSurface3);
|
|
|
|
subSurfaceCreatedSpy.clear();
|
|
|
|
|
|
|
|
// so far the stacking order should still be empty
|
2021-06-01 10:50:33 +00:00
|
|
|
QVERIFY(serverSubSurface1->parentSurface()->below().isEmpty());
|
2016-03-21 14:53:13 +00:00
|
|
|
QEXPECT_FAIL("", "Incorrect adding of child windows to workaround QtWayland behavior", Continue);
|
2021-06-01 10:50:33 +00:00
|
|
|
QVERIFY(serverSubSurface1->parentSurface()->above().isEmpty());
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2014-12-12 07:36:07 +00:00
|
|
|
// committing the parent should create the stacking order
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
// ensure it's processed on server side
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(2), serverSubSurface3);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// lowering subsurface3 should place it to the bottom of stack
|
|
|
|
subSurface3->lower();
|
|
|
|
// ensure it's processed on server side
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
// but as long as parent is not committed it shouldn't change on server side
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface1);
|
2014-10-14 12:04:35 +00:00
|
|
|
// after commit it's changed
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().count(), 1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(0), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(1), serverSubSurface2);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// place 1 below 3 -> 1, 3, 2
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface1->placeBelow(subSurface3.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().count(), 2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(0), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(1), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().at(0), serverSubSurface2);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// 2 below 3 -> 1, 2, 3
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface2->placeBelow(subSurface3.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(0), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(1), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(2), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 0);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// 1 below 2 -> shouldn't change
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface1->placeBelow(subSurface2.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(0), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(1), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(2), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 0);
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
// and 3 below 1 -> 3, 1, 2
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface3->placeBelow(subSurface1.get());
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().count(), 3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(0), serverSubSurface3);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(1), serverSubSurface1);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->below().at(2), serverSubSurface2);
|
|
|
|
QCOMPARE(serverSubSurface1->parentSurface()->above().count(), 0);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 13:32:31 +00:00
|
|
|
void TestSubSurface::testSyncMode()
|
|
|
|
{
|
|
|
|
// this test verifies that state is only applied when the parent surface commits its pending state
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(childSurface);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto parentSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(parentSurface);
|
|
|
|
// create subSurface for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface(m_subCompositor->createSubSurface(surface.get(), parent.get()));
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
// let's damage the child surface
|
|
|
|
QSignalSpy childDamagedSpy(childSurface, &SurfaceInterface::damaged);
|
|
|
|
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage image(QSize(200, 200), QImage::Format_ARGB32_Premultiplied);
|
2016-03-21 13:32:31 +00:00
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(QRect(0, 0, 200, 200));
|
|
|
|
surface->commit();
|
|
|
|
|
|
|
|
// state should be applied when the parent surface's state gets applied
|
|
|
|
QVERIFY(!childDamagedSpy.wait(100));
|
|
|
|
QVERIFY(!childSurface->buffer());
|
|
|
|
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!childSurface->isMapped());
|
|
|
|
QVERIFY(!parentSurface->isMapped());
|
|
|
|
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage image2(QSize(400, 400), QImage::Format_ARGB32_Premultiplied);
|
2016-03-21 13:32:31 +00:00
|
|
|
image2.fill(Qt::red);
|
|
|
|
parent->attachBuffer(m_shm->createBuffer(image2));
|
|
|
|
parent->damage(QRect(0, 0, 400, 400));
|
|
|
|
parent->commit();
|
|
|
|
QVERIFY(childDamagedSpy.wait());
|
|
|
|
QCOMPARE(childDamagedSpy.count(), 1);
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(childSurface->isMapped());
|
|
|
|
QVERIFY(parentSurface->isMapped());
|
2016-03-21 13:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSubSurface::testDeSyncMode()
|
|
|
|
{
|
|
|
|
// this test verifies that state gets applied immediately in desync mode
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(childSurface);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto parentSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(parentSurface);
|
|
|
|
// create subSurface for surface of parent
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> subSurface(m_subCompositor->createSubSurface(surface.get(), parent.get()));
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
// let's damage the child surface
|
|
|
|
QSignalSpy childDamagedSpy(childSurface, &SurfaceInterface::damaged);
|
|
|
|
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage image(QSize(200, 200), QImage::Format_ARGB32_Premultiplied);
|
2016-03-21 13:32:31 +00:00
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
// state should be applied when the parent surface's state gets applied or when the subsurface switches to desync
|
|
|
|
QVERIFY(!childDamagedSpy.wait(100));
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!childSurface->isMapped());
|
|
|
|
QVERIFY(!parentSurface->isMapped());
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
// setting to desync should apply the state directly
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(childDamagedSpy.wait());
|
2016-03-29 10:05:05 +00:00
|
|
|
QVERIFY(!childSurface->isMapped());
|
|
|
|
QVERIFY(!parentSurface->isMapped());
|
2016-03-21 13:32:31 +00:00
|
|
|
|
|
|
|
// and damaging again, should directly be applied
|
|
|
|
image.fill(Qt::red);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-21 13:32:31 +00:00
|
|
|
QVERIFY(childDamagedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2016-03-23 15:59:18 +00:00
|
|
|
void TestSubSurface::testMainSurfaceFromTree()
|
|
|
|
{
|
|
|
|
// this test verifies that in a tree of surfaces every surface has the same main surface
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-23 15:59:18 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parentSurface(m_compositor->createSurface());
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto parentServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(parentServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childLevel1Surface(m_compositor->createSurface());
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childLevel1ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(childLevel1ServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childLevel2Surface(m_compositor->createSurface());
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childLevel2ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(childLevel2ServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childLevel3Surface(m_compositor->createSurface());
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childLevel3ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-23 15:59:18 +00:00
|
|
|
QVERIFY(childLevel3ServerSurface);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
m_subCompositor->createSubSurface(childLevel1Surface.get(), parentSurface.get());
|
|
|
|
m_subCompositor->createSubSurface(childLevel2Surface.get(), childLevel1Surface.get());
|
|
|
|
m_subCompositor->createSubSurface(childLevel3Surface.get(), childLevel2Surface.get());
|
2016-03-23 15:59:18 +00:00
|
|
|
|
2021-02-02 17:27:46 +00:00
|
|
|
QSignalSpy parentCommittedSpy(parentServerSurface, &SurfaceInterface::committed);
|
2022-11-08 21:15:17 +00:00
|
|
|
parentSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-02 17:27:46 +00:00
|
|
|
QVERIFY(parentCommittedSpy.wait());
|
2016-03-23 15:59:18 +00:00
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(parentServerSurface->below().count(), 0);
|
|
|
|
QCOMPARE(parentServerSurface->above().count(), 1);
|
|
|
|
auto child = parentServerSurface->above().constFirst();
|
2020-10-31 14:03:30 +00:00
|
|
|
QCOMPARE(child->parentSurface(), parentServerSurface);
|
|
|
|
QCOMPARE(child->mainSurface(), parentServerSurface);
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(child->surface()->below().count(), 0);
|
|
|
|
QCOMPARE(child->surface()->above().count(), 1);
|
|
|
|
auto child2 = child->surface()->above().constFirst();
|
2020-10-31 14:03:30 +00:00
|
|
|
QCOMPARE(child2->parentSurface(), child->surface());
|
|
|
|
QCOMPARE(child2->mainSurface(), parentServerSurface);
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(child2->surface()->below().count(), 0);
|
|
|
|
QCOMPARE(child2->surface()->above().count(), 1);
|
|
|
|
auto child3 = child2->surface()->above().constFirst();
|
2020-10-31 14:03:30 +00:00
|
|
|
QCOMPARE(child3->parentSurface(), child2->surface());
|
|
|
|
QCOMPARE(child3->mainSurface(), parentServerSurface);
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(child3->surface()->below().count(), 0);
|
|
|
|
QCOMPARE(child3->surface()->above().count(), 0);
|
2016-03-23 15:59:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 11:45:46 +00:00
|
|
|
void TestSubSurface::testRemoveSurface()
|
|
|
|
{
|
|
|
|
// this test verifies that removing the surface also removes the sub-surface from the parent
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-24 11:45:46 +00:00
|
|
|
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parentSurface(m_compositor->createSurface());
|
2016-03-24 11:45:46 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto parentServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-24 11:45:46 +00:00
|
|
|
QVERIFY(parentServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childSurface(m_compositor->createSurface());
|
2016-03-24 11:45:46 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-24 11:45:46 +00:00
|
|
|
QVERIFY(childServerSurface);
|
|
|
|
|
2021-02-02 17:27:46 +00:00
|
|
|
QSignalSpy childrenChangedSpy(parentServerSurface, &SurfaceInterface::childSubSurfacesChanged);
|
2016-03-24 11:45:46 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
m_subCompositor->createSubSurface(childSurface.get(), parentSurface.get());
|
2022-11-08 21:15:17 +00:00
|
|
|
parentSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-02 17:27:46 +00:00
|
|
|
QVERIFY(childrenChangedSpy.wait());
|
2016-03-24 11:45:46 +00:00
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(parentServerSurface->below().count(), 0);
|
|
|
|
QCOMPARE(parentServerSurface->above().count(), 1);
|
2016-03-24 11:45:46 +00:00
|
|
|
|
|
|
|
// destroy surface, takes place immediately
|
|
|
|
childSurface.reset();
|
2021-02-02 17:27:46 +00:00
|
|
|
QVERIFY(childrenChangedSpy.wait());
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(parentServerSurface->below().count(), 0);
|
|
|
|
QCOMPARE(parentServerSurface->above().count(), 0);
|
2016-03-24 11:45:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 13:49:01 +00:00
|
|
|
void TestSubSurface::testMappingOfSurfaceTree()
|
|
|
|
{
|
|
|
|
// this test verifies mapping and unmapping of a sub-surface tree
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-29 13:49:01 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parentSurface(m_compositor->createSurface());
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto parentServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(parentServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childLevel1Surface(m_compositor->createSurface());
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childLevel1ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(childLevel1ServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childLevel2Surface(m_compositor->createSurface());
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childLevel2ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(childLevel2ServerSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childLevel3Surface(m_compositor->createSurface());
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto childLevel3ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(childLevel3ServerSurface);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
auto subSurfaceLevel1 = m_subCompositor->createSubSurface(childLevel1Surface.get(), parentSurface.get());
|
|
|
|
auto subSurfaceLevel2 = m_subCompositor->createSubSurface(childLevel2Surface.get(), childLevel1Surface.get());
|
|
|
|
auto subSurfaceLevel3 = m_subCompositor->createSubSurface(childLevel3Surface.get(), childLevel2Surface.get());
|
2016-03-29 13:49:01 +00:00
|
|
|
|
2021-02-02 17:27:46 +00:00
|
|
|
QSignalSpy parentCommittedSpy(parentServerSurface, &SurfaceInterface::committed);
|
2022-11-08 21:15:17 +00:00
|
|
|
parentSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-02 17:27:46 +00:00
|
|
|
QVERIFY(parentCommittedSpy.wait());
|
2016-03-29 13:49:01 +00:00
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(parentServerSurface->below().count(), 0);
|
|
|
|
QCOMPARE(parentServerSurface->above().count(), 1);
|
|
|
|
auto child = parentServerSurface->above().constFirst();
|
|
|
|
QCOMPARE(child->surface()->below().count(), 0);
|
|
|
|
QCOMPARE(child->surface()->above().count(), 1);
|
|
|
|
auto child2 = child->surface()->above().constFirst();
|
|
|
|
QCOMPARE(child2->surface()->below().count(), 0);
|
|
|
|
QCOMPARE(child2->surface()->above().count(), 1);
|
|
|
|
auto child3 = child2->surface()->above().constFirst();
|
2020-10-31 14:03:30 +00:00
|
|
|
QCOMPARE(child3->parentSurface(), child2->surface());
|
|
|
|
QCOMPARE(child3->mainSurface(), parentServerSurface);
|
2021-06-01 10:50:33 +00:00
|
|
|
QCOMPARE(child3->surface()->below().count(), 0);
|
|
|
|
QCOMPARE(child3->surface()->above().count(), 0);
|
2016-03-29 13:49:01 +00:00
|
|
|
|
|
|
|
// so far no surface is mapped
|
|
|
|
QVERIFY(!parentServerSurface->isMapped());
|
|
|
|
QVERIFY(!child->surface()->isMapped());
|
|
|
|
QVERIFY(!child2->surface()->isMapped());
|
|
|
|
QVERIFY(!child3->surface()->isMapped());
|
|
|
|
|
|
|
|
// first set all subsurfaces to desync, to simplify
|
2022-11-08 21:15:17 +00:00
|
|
|
subSurfaceLevel1->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
|
|
|
subSurfaceLevel2->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
|
|
|
subSurfaceLevel3->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
2016-03-29 13:49:01 +00:00
|
|
|
|
|
|
|
// first map the child, should not map it
|
2020-10-31 14:03:30 +00:00
|
|
|
QSignalSpy child3DamageSpy(child3->surface(), &SurfaceInterface::damaged);
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage image(QSize(200, 200), QImage::Format_ARGB32_Premultiplied);
|
2016-03-29 13:49:01 +00:00
|
|
|
image.fill(Qt::black);
|
|
|
|
childLevel3Surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
childLevel3Surface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
childLevel3Surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(child3DamageSpy.wait());
|
|
|
|
QVERIFY(child3->surface()->buffer());
|
|
|
|
QVERIFY(!child3->surface()->isMapped());
|
|
|
|
|
|
|
|
// let's map the top level
|
|
|
|
QSignalSpy parentSpy(parentServerSurface, &SurfaceInterface::damaged);
|
|
|
|
parentSurface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
parentSurface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
parentSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(parentSpy.wait());
|
|
|
|
QVERIFY(parentServerSurface->isMapped());
|
|
|
|
// children should not yet be mapped
|
|
|
|
QVERIFY(!child->surface()->isMapped());
|
|
|
|
QVERIFY(!child2->surface()->isMapped());
|
|
|
|
QVERIFY(!child3->surface()->isMapped());
|
|
|
|
|
|
|
|
// next level
|
2020-10-31 14:03:30 +00:00
|
|
|
QSignalSpy child2DamageSpy(child2->surface(), &SurfaceInterface::damaged);
|
2016-03-29 13:49:01 +00:00
|
|
|
childLevel2Surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
childLevel2Surface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
childLevel2Surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(child2DamageSpy.wait());
|
|
|
|
QVERIFY(parentServerSurface->isMapped());
|
|
|
|
// children should not yet be mapped
|
|
|
|
QVERIFY(!child->surface()->isMapped());
|
|
|
|
QVERIFY(!child2->surface()->isMapped());
|
|
|
|
QVERIFY(!child3->surface()->isMapped());
|
|
|
|
|
|
|
|
// last but not least the first child level, which should map all our subsurfaces
|
2020-10-31 14:03:30 +00:00
|
|
|
QSignalSpy child1DamageSpy(child->surface(), &SurfaceInterface::damaged);
|
2016-03-29 13:49:01 +00:00
|
|
|
childLevel1Surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
childLevel1Surface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
childLevel1Surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(child1DamageSpy.wait());
|
|
|
|
|
|
|
|
// everything is mapped
|
|
|
|
QVERIFY(parentServerSurface->isMapped());
|
|
|
|
QVERIFY(child->surface()->isMapped());
|
|
|
|
QVERIFY(child2->surface()->isMapped());
|
|
|
|
QVERIFY(child3->surface()->isMapped());
|
|
|
|
|
|
|
|
// unmapping a parent should unmap the complete tree
|
2020-10-31 14:03:30 +00:00
|
|
|
QSignalSpy unmappedSpy(child->surface(), &SurfaceInterface::unmapped);
|
2022-11-08 21:15:17 +00:00
|
|
|
childLevel1Surface->attachBuffer(KWayland::Client::Buffer::Ptr());
|
2016-03-29 13:49:01 +00:00
|
|
|
childLevel1Surface->damage(QRect(0, 0, 200, 200));
|
2022-11-08 21:15:17 +00:00
|
|
|
childLevel1Surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-03-29 13:49:01 +00:00
|
|
|
QVERIFY(unmappedSpy.wait());
|
|
|
|
|
|
|
|
QVERIFY(parentServerSurface->isMapped());
|
|
|
|
QVERIFY(!child->surface()->isMapped());
|
|
|
|
QVERIFY(!child2->surface()->isMapped());
|
|
|
|
QVERIFY(!child3->surface()->isMapped());
|
|
|
|
}
|
|
|
|
|
2016-04-05 12:26:53 +00:00
|
|
|
void TestSubSurface::testSurfaceAt()
|
|
|
|
{
|
|
|
|
// this test verifies that the correct surface is picked in a sub-surface tree
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-04-05 12:26:53 +00:00
|
|
|
// first create a parent surface and map it
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2016-04-05 12:26:53 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::red);
|
|
|
|
parent->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
parent->damage(QRect(0, 0, 100, 100));
|
2022-11-08 21:15:17 +00:00
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *parentServerSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2016-04-05 12:26:53 +00:00
|
|
|
|
2021-07-23 17:52:33 +00:00
|
|
|
// directChild1 occupies the top-left quarter of the parent surface
|
|
|
|
QImage directImage(QSize(50, 50), QImage::Format_ARGB32_Premultiplied);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> directChild1(m_compositor->createSurface());
|
2021-07-23 17:52:33 +00:00
|
|
|
directChild1->attachBuffer(m_shm->createBuffer(directImage));
|
|
|
|
directChild1->damage(QRect(0, 0, 50, 50));
|
2022-11-08 21:15:17 +00:00
|
|
|
directChild1->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *directChild1ServerSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2016-06-29 09:24:35 +00:00
|
|
|
QVERIFY(directChild1ServerSurface);
|
2021-07-23 17:52:33 +00:00
|
|
|
|
|
|
|
// directChild2 occupies the bottom-right quarter of the parent surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> directChild2(m_compositor->createSurface());
|
2021-07-23 17:52:33 +00:00
|
|
|
directChild2->attachBuffer(m_shm->createBuffer(directImage));
|
|
|
|
directChild2->damage(QRect(0, 0, 50, 50));
|
2022-11-08 21:15:17 +00:00
|
|
|
directChild2->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *directChild2ServerSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2016-06-29 09:24:35 +00:00
|
|
|
QVERIFY(directChild2ServerSurface);
|
2016-04-05 12:26:53 +00:00
|
|
|
|
|
|
|
// create the sub surfaces for them
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> directChild1SubSurface(m_subCompositor->createSubSurface(directChild1.get(), parent.get()));
|
|
|
|
directChild1SubSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> directChild2SubSurface(m_subCompositor->createSubSurface(directChild2.get(), parent.get()));
|
|
|
|
directChild2SubSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
2021-07-23 17:52:33 +00:00
|
|
|
directChild2SubSurface->setPosition(QPoint(50, 50));
|
|
|
|
|
|
|
|
// unset input regions for direct children
|
|
|
|
QSignalSpy directChild1CommittedSpy(directChild1ServerSurface, &SurfaceInterface::committed);
|
|
|
|
directChild1->setInputRegion(m_compositor->createRegion(QRegion()).get());
|
2022-11-08 21:15:17 +00:00
|
|
|
directChild1->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-07-23 17:52:33 +00:00
|
|
|
QVERIFY(directChild1CommittedSpy.wait());
|
|
|
|
|
|
|
|
QSignalSpy directChild2CommittedSpy(directChild2ServerSurface, &SurfaceInterface::committed);
|
|
|
|
directChild2->setInputRegion(m_compositor->createRegion(QRegion()).get());
|
2022-11-08 21:15:17 +00:00
|
|
|
directChild2->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
parent->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-07-23 17:52:33 +00:00
|
|
|
QVERIFY(directChild2CommittedSpy.wait());
|
2016-04-05 12:26:53 +00:00
|
|
|
|
|
|
|
// each of the children gets a child
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childFor1(m_compositor->createSurface());
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *childFor1ServerSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> childFor2(m_compositor->createSurface());
|
2016-04-05 12:26:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *childFor2ServerSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2016-04-05 12:26:53 +00:00
|
|
|
|
|
|
|
// create sub surfaces for them
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> childFor1SubSurface(m_subCompositor->createSubSurface(childFor1.get(), directChild1.get()));
|
|
|
|
childFor1SubSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> childFor2SubSurface(m_subCompositor->createSubSurface(childFor2.get(), directChild2.get()));
|
|
|
|
childFor2SubSurface->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
2016-04-05 12:26:53 +00:00
|
|
|
|
|
|
|
// now let's render both grand children
|
|
|
|
QImage partImage(QSize(50, 50), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
partImage.fill(Qt::green);
|
|
|
|
childFor1->attachBuffer(m_shm->createBuffer(partImage));
|
|
|
|
childFor1->damage(QRect(0, 0, 50, 50));
|
2022-11-08 21:15:17 +00:00
|
|
|
childFor1->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-05 12:26:53 +00:00
|
|
|
partImage.fill(Qt::blue);
|
2018-10-29 10:09:43 +00:00
|
|
|
|
2021-02-02 17:27:46 +00:00
|
|
|
QSignalSpy childFor2CommittedSpy(childFor2ServerSurface, &SurfaceInterface::committed);
|
2016-04-05 12:26:53 +00:00
|
|
|
childFor2->attachBuffer(m_shm->createBuffer(partImage));
|
2018-10-29 10:09:43 +00:00
|
|
|
// child for 2's input region is subdivided into quadrants, with input mask on the top left and bottom right
|
|
|
|
QRegion region;
|
2021-08-29 05:11:06 +00:00
|
|
|
region += QRect(0, 0, 25, 25);
|
|
|
|
region += QRect(25, 25, 25, 25);
|
2018-10-29 10:09:43 +00:00
|
|
|
childFor2->setInputRegion(m_compositor->createRegion(region).get());
|
2016-04-05 12:26:53 +00:00
|
|
|
childFor2->damage(QRect(0, 0, 50, 50));
|
2022-11-08 21:15:17 +00:00
|
|
|
childFor2->commit(KWayland::Client::Surface::CommitFlag::None);
|
2021-02-02 17:27:46 +00:00
|
|
|
QVERIFY(childFor2CommittedSpy.wait());
|
2016-04-05 12:26:53 +00:00
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
QCOMPARE(directChild1ServerSurface->subSurface()->parentSurface(), parentServerSurface);
|
|
|
|
QCOMPARE(directChild2ServerSurface->subSurface()->parentSurface(), parentServerSurface);
|
|
|
|
QCOMPARE(childFor1ServerSurface->subSurface()->parentSurface(), directChild1ServerSurface);
|
|
|
|
QCOMPARE(childFor2ServerSurface->subSurface()->parentSurface(), directChild2ServerSurface);
|
2016-06-29 09:24:35 +00:00
|
|
|
|
2016-04-05 12:26:53 +00:00
|
|
|
// now let's test a few positions
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(0, 0)), childFor1ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(49, 49)), childFor1ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 50)), childFor2ServerSurface);
|
2022-05-31 17:20:15 +00:00
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(99, 99)), childFor2ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(99, 50)), childFor2ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 99)), childFor2ServerSurface);
|
2016-04-05 12:26:53 +00:00
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(25, 75)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(75, 25)), parentServerSurface);
|
2018-10-29 10:09:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(0, 0)), childFor1ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(49, 49)), childFor1ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(50, 50)), childFor2ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(99, 99)), childFor2ServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(99, 50)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(50, 99)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(25, 75)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(75, 25)), parentServerSurface);
|
|
|
|
|
2016-04-05 12:26:53 +00:00
|
|
|
// outside the geometries should be no surface
|
|
|
|
QVERIFY(!parentServerSurface->surfaceAt(QPointF(-1, -1)));
|
|
|
|
QVERIFY(!parentServerSurface->surfaceAt(QPointF(101, 101)));
|
2022-05-31 17:20:15 +00:00
|
|
|
|
|
|
|
// on the surface edge right/bottom edges should not trigger as contained
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 25)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->surfaceAt(QPointF(25, 50)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(50, 25)), parentServerSurface);
|
|
|
|
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(25, 50)), parentServerSurface);
|
2016-04-05 12:26:53 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 14:09:11 +00:00
|
|
|
void TestSubSurface::testDestroyAttachedBuffer()
|
|
|
|
{
|
|
|
|
// this test verifies that destroying of a buffer attached to a sub-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> parent(m_compositor->createSurface());
|
2016-04-13 14:09:11 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> child(m_compositor->createSurface());
|
2016-04-13 14:09:11 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverChildSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2016-04-13 14:09:11 +00:00
|
|
|
// create sub-surface
|
2022-08-01 21:29:02 +00:00
|
|
|
m_subCompositor->createSubSurface(child.get(), parent.get());
|
2016-04-13 14:09:11 +00:00
|
|
|
|
|
|
|
// let's damage this surface, will be in sub-surface pending state
|
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);
|
|
|
|
child->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
child->damage(QRect(0, 0, 100, 100));
|
2022-11-08 21:15:17 +00:00
|
|
|
child->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-13 14:09:11 +00:00
|
|
|
m_connection->flush();
|
|
|
|
|
|
|
|
// Let's try to destroy it
|
|
|
|
QSignalSpy destroySpy(serverChildSurface, &QObject::destroyed);
|
|
|
|
delete m_shm;
|
|
|
|
m_shm = nullptr;
|
|
|
|
child.reset();
|
|
|
|
QVERIFY(destroySpy.wait());
|
|
|
|
}
|
|
|
|
|
2018-02-04 15:57:23 +00:00
|
|
|
void TestSubSurface::testDestroyParentSurface()
|
|
|
|
{
|
|
|
|
// this test verifies that destroying a parent surface does not create problems
|
|
|
|
// see BUG 389231
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2018-02-04 15:57:23 +00:00
|
|
|
// create surface
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parent(m_compositor->createSurface());
|
2018-02-04 15:57:23 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverParentSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> child(m_compositor->createSurface());
|
2018-02-04 15:57:23 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverChildSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> grandChild(m_compositor->createSurface());
|
2018-02-04 15:57:23 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverGrandChildSurface = serverSurfaceCreated.last().first().value<KWin::SurfaceInterface *>();
|
2018-02-04 15:57:23 +00:00
|
|
|
// create sub-surface in desynchronized mode as Qt uses them
|
2022-08-01 21:29:02 +00:00
|
|
|
auto sub1 = m_subCompositor->createSubSurface(child.get(), parent.get());
|
2022-11-08 21:15:17 +00:00
|
|
|
sub1->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
2022-08-01 21:29:02 +00:00
|
|
|
auto sub2 = m_subCompositor->createSubSurface(grandChild.get(), child.get());
|
2022-11-08 21:15:17 +00:00
|
|
|
sub2->setMode(KWayland::Client::SubSurface::Mode::Desynchronized);
|
2018-02-04 15:57:23 +00:00
|
|
|
|
|
|
|
// let's damage this surface
|
|
|
|
// and at the same time delete the parent surface
|
|
|
|
parent.reset();
|
|
|
|
QSignalSpy parentDestroyedSpy(serverParentSurface, &QObject::destroyed);
|
|
|
|
QVERIFY(parentDestroyedSpy.wait());
|
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::red);
|
|
|
|
grandChild->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
grandChild->damage(QRect(0, 0, 100, 100));
|
2022-11-08 21:15:17 +00:00
|
|
|
grandChild->commit(KWayland::Client::Surface::CommitFlag::None);
|
2018-02-04 15:57:23 +00:00
|
|
|
QSignalSpy damagedSpy(serverGrandChildSurface, &SurfaceInterface::damaged);
|
|
|
|
QVERIFY(damagedSpy.wait());
|
|
|
|
|
|
|
|
// Let's try to destroy it
|
|
|
|
QSignalSpy destroySpy(serverChildSurface, &QObject::destroyed);
|
|
|
|
child.reset();
|
|
|
|
QVERIFY(destroySpy.wait());
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:36:31 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestSubSurface)
|
2014-10-14 12:04:35 +00:00
|
|
|
#include "test_wayland_subsurface.moc"
|