2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2015-08-26 12:42:58 +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
|
|
|
|
*/
|
2015-08-26 12:42:58 +00:00
|
|
|
// Qt
|
2018-11-06 06:22:36 +00:00
|
|
|
#include <QtTest>
|
2015-08-26 12:42:58 +00:00
|
|
|
// KWin
|
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/surface.h"
|
|
|
|
#include "KWayland/Client/blur.h"
|
2015-08-26 12:42:58 +00:00
|
|
|
#include "../../src/server/display.h"
|
|
|
|
#include "../../src/server/compositor_interface.h"
|
|
|
|
#include "../../src/server/region_interface.h"
|
|
|
|
#include "../../src/server/blur_interface.h"
|
|
|
|
|
2016-05-30 07:49:38 +00:00
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
2015-08-26 12:42:58 +00:00
|
|
|
class TestBlur : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestBlur(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testCreate();
|
2016-05-30 07:53:53 +00:00
|
|
|
void testSurfaceDestroy();
|
2015-08-26 12:42:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-04-29 14:56:38 +00:00
|
|
|
KWaylandServer::Display *m_display;
|
|
|
|
KWaylandServer::CompositorInterface *m_compositorInterface;
|
|
|
|
KWaylandServer::BlurManagerInterface *m_blurManagerInterface;
|
2015-08-26 12:42:58 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
|
|
|
KWayland::Client::BlurManager *m_blurManager;
|
|
|
|
KWayland::Client::EventQueue *m_queue;
|
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-blur-0");
|
|
|
|
|
|
|
|
TestBlur::TestBlur(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
|
|
|
, m_queue(nullptr)
|
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestBlur::init()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2015-08-26 12:42:58 +00:00
|
|
|
delete m_display;
|
|
|
|
m_display = new Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2015-08-26 12:42:58 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2016-05-30 07:49:38 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected);
|
|
|
|
QVERIFY(connectedSpy.isValid());
|
2015-08-26 12:42:58 +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());
|
|
|
|
|
2016-05-30 07:49:38 +00:00
|
|
|
Registry registry;
|
|
|
|
QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced);
|
2015-08-26 12:42:58 +00:00
|
|
|
QVERIFY(compositorSpy.isValid());
|
|
|
|
|
2016-05-30 07:49:38 +00:00
|
|
|
QSignalSpy blurSpy(®istry, &Registry::blurAnnounced);
|
2015-08-26 12:42:58 +00:00
|
|
|
QVERIFY(blurSpy.isValid());
|
|
|
|
|
2016-05-30 07:49:38 +00:00
|
|
|
QVERIFY(!registry.eventQueue());
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
QCOMPARE(registry.eventQueue(), m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
2015-08-26 12:42:58 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
2015-08-26 12:42:58 +00:00
|
|
|
QVERIFY(compositorSpy.wait());
|
2016-05-30 07:49:38 +00:00
|
|
|
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
|
2015-08-26 12:42:58 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_blurManagerInterface = new BlurManagerInterface(m_display, m_display);
|
2015-08-26 12:42:58 +00:00
|
|
|
QVERIFY(blurSpy.wait());
|
2016-05-30 07:49:38 +00:00
|
|
|
m_blurManager = registry.createBlurManager(blurSpy.first().first().value<quint32>(), blurSpy.first().last().value<quint32>(), this);
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestBlur::cleanup()
|
|
|
|
{
|
2016-05-30 07:49:38 +00:00
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
2016-05-30 07:49:38 +00:00
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_blurManager)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
2016-05-30 07:49:38 +00:00
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
2020-10-30 13:36:24 +00:00
|
|
|
|
|
|
|
// these are the children of the display
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
m_blurManagerInterface = nullptr;
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestBlur::testCreate()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWaylandServer::SurfaceInterface*)));
|
2015-08-26 12:42:58 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
|
|
|
|
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
auto serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface*>();
|
2015-08-26 12:42:58 +00:00
|
|
|
QSignalSpy blurChanged(serverSurface, SIGNAL(blurChanged()));
|
|
|
|
|
|
|
|
auto blur = m_blurManager->createBlur(surface.data(), surface.data());
|
|
|
|
blur->setRegion(m_compositor->createRegion(QRegion(0, 0, 10, 20), nullptr));
|
|
|
|
blur->commit();
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
|
|
|
|
QVERIFY(blurChanged.wait());
|
|
|
|
QCOMPARE(serverSurface->blur()->region(), QRegion(0, 0, 10, 20));
|
2016-05-25 08:04:17 +00:00
|
|
|
|
|
|
|
// and destroy
|
2016-06-14 09:22:58 +00:00
|
|
|
QSignalSpy destroyedSpy(serverSurface->blur().data(), &QObject::destroyed);
|
2016-05-25 08:04:17 +00:00
|
|
|
QVERIFY(destroyedSpy.isValid());
|
|
|
|
delete blur;
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 07:53:53 +00:00
|
|
|
void TestBlur::testSurfaceDestroy()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWaylandServer::CompositorInterface::surfaceCreated);
|
2016-05-30 07:53:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
|
|
|
|
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
auto serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface*>();
|
|
|
|
QSignalSpy blurChanged(serverSurface, &KWaylandServer::SurfaceInterface::blurChanged);
|
2016-05-30 07:53:53 +00:00
|
|
|
QVERIFY(blurChanged.isValid());
|
|
|
|
|
|
|
|
QScopedPointer<KWayland::Client::Blur> blur(m_blurManager->createBlur(surface.data()));
|
|
|
|
blur->setRegion(m_compositor->createRegion(QRegion(0, 0, 10, 20), nullptr));
|
|
|
|
blur->commit();
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
|
|
|
|
QVERIFY(blurChanged.wait());
|
|
|
|
QCOMPARE(serverSurface->blur()->region(), QRegion(0, 0, 10, 20));
|
|
|
|
|
|
|
|
// destroy the parent surface
|
|
|
|
QSignalSpy surfaceDestroyedSpy(serverSurface, &QObject::destroyed);
|
|
|
|
QVERIFY(surfaceDestroyedSpy.isValid());
|
2016-06-30 14:45:29 +00:00
|
|
|
QSignalSpy blurDestroyedSpy(serverSurface->blur().data(), &QObject::destroyed);
|
2016-05-30 07:53:53 +00:00
|
|
|
QVERIFY(blurDestroyedSpy.isValid());
|
|
|
|
surface.reset();
|
|
|
|
QVERIFY(surfaceDestroyedSpy.wait());
|
|
|
|
QVERIFY(blurDestroyedSpy.isEmpty());
|
|
|
|
// destroy the blur
|
|
|
|
blur.reset();
|
|
|
|
QVERIFY(blurDestroyedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:36:31 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestBlur)
|
2015-08-26 12:42:58 +00:00
|
|
|
#include "test_wayland_blur.moc"
|