2014-08-22 09:10:18 +00:00
|
|
|
/********************************************************************
|
2014-09-17 13:57:56 +00:00
|
|
|
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-09-17 13:57:56 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) version 3, or any
|
|
|
|
later version accepted by the membership of KDE e.V. (or its
|
|
|
|
successor approved by the membership of KDE e.V.), which shall
|
|
|
|
act as a proxy defined in Section 6 of version 3 of the license.
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-09-17 13:57:56 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
2014-08-22 09:10:18 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-09-17 13:57:56 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-09-17 13:57:56 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2014-08-22 09:10:18 +00:00
|
|
|
*********************************************************************/
|
|
|
|
// Qt
|
|
|
|
#include <QtTest/QtTest>
|
2014-08-28 12:22:53 +00:00
|
|
|
#include <QImage>
|
2014-08-22 09:10:18 +00:00
|
|
|
// KWin
|
2014-09-17 12:35:33 +00:00
|
|
|
#include "../../src/client/compositor.h"
|
|
|
|
#include "../../src/client/connection_thread.h"
|
|
|
|
#include "../../src/client/surface.h"
|
2014-10-16 12:59:01 +00:00
|
|
|
#include "../../src/client/region.h"
|
2014-09-17 12:35:33 +00:00
|
|
|
#include "../../src/client/registry.h"
|
|
|
|
#include "../../src/client/shm_pool.h"
|
|
|
|
#include "../../src/server/buffer_interface.h"
|
|
|
|
#include "../../src/server/compositor_interface.h"
|
|
|
|
#include "../../src/server/display.h"
|
|
|
|
#include "../../src/server/surface_interface.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();
|
2014-09-22 09:14:05 +00:00
|
|
|
void testDestroy();
|
2014-08-22 09:10:18 +00:00
|
|
|
|
|
|
|
private:
|
2014-09-17 14:10:38 +00:00
|
|
|
KWayland::Server::Display *m_display;
|
|
|
|
KWayland::Server::CompositorInterface *m_compositorInterface;
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
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()
|
|
|
|
{
|
2014-09-17 14:10:38 +00:00
|
|
|
using namespace KWayland::Server;
|
2014-08-28 07:52:35 +00:00
|
|
|
delete m_display;
|
|
|
|
m_display = new Display(this);
|
|
|
|
m_display->setSocketName(s_socketName);
|
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
|
|
|
m_compositorInterface = m_display->createCompositor(m_display);
|
|
|
|
QVERIFY(m_compositorInterface);
|
|
|
|
m_compositorInterface->create();
|
|
|
|
QVERIFY(m_compositorInterface->isValid());
|
|
|
|
|
|
|
|
// setup connection
|
2014-09-17 14:17:26 +00:00
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2014-08-28 07:52:35 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, SIGNAL(connected()));
|
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, m_connection,
|
|
|
|
[this]() {
|
|
|
|
if (m_connection->display()) {
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
}
|
2014-08-22 09:10:18 +00:00
|
|
|
}
|
2014-08-28 07:52:35 +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());
|
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2014-08-22 09:10:18 +00:00
|
|
|
QSignalSpy compositorSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32)));
|
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();
|
|
|
|
QVERIFY(compositorSpy.wait());
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::cleanup()
|
|
|
|
{
|
|
|
|
if (m_compositor) {
|
|
|
|
delete m_compositor;
|
|
|
|
m_compositor = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
delete m_connection;
|
|
|
|
m_connection = nullptr;
|
|
|
|
|
|
|
|
delete m_compositorInterface;
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
|
|
|
|
delete m_display;
|
|
|
|
m_display = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testStaticAccessor()
|
|
|
|
{
|
2014-09-17 14:10:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
QVERIFY(KWayland::Client::Surface::all().isEmpty());
|
|
|
|
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);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::all().first(), s1);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s1), s1);
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2014-08-22 09:10:18 +00:00
|
|
|
|
2014-08-22 11:48:50 +00:00
|
|
|
QVERIFY(!s1->size().isValid());
|
|
|
|
QSignalSpy sizeChangedSpy(s1, SIGNAL(sizeChanged(QSize)));
|
|
|
|
QVERIFY(sizeChangedSpy.isValid());
|
|
|
|
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
|
2014-09-17 14:17:26 +00:00
|
|
|
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);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::all().first(), s1);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::all().last(), s2);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s1), s1);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s2), s2);
|
2014-08-28 07:52:35 +00:00
|
|
|
serverSurfaceCreated.clear();
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2014-08-22 09:10:18 +00:00
|
|
|
|
|
|
|
// delete s2 again
|
|
|
|
delete s2;
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(KWayland::Client::Surface::all().count(), 1);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::all().first(), s1);
|
|
|
|
QCOMPARE(KWayland::Client::Surface::get(*s1), s1);
|
2014-08-22 09:10:18 +00:00
|
|
|
|
|
|
|
// and finally delete the last one
|
|
|
|
delete s1;
|
2014-09-17 14:17:26 +00:00
|
|
|
QVERIFY(KWayland::Client::Surface::all().isEmpty());
|
|
|
|
QVERIFY(!KWayland::Client::Surface::get(nullptr));
|
2014-08-22 09:10:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 07:52:35 +00:00
|
|
|
void TestWaylandSurface::testDamage()
|
|
|
|
{
|
2014-09-17 14:10:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2014-09-17 14:10:38 +00:00
|
|
|
KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
QCOMPARE(serverSurface->damage(), QRegion());
|
2014-11-20 15:40:14 +00:00
|
|
|
QVERIFY(serverSurface->parentResource());
|
2014-08-28 07:52:35 +00:00
|
|
|
|
|
|
|
QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion)));
|
|
|
|
QVERIFY(damageSpy.isValid());
|
|
|
|
|
|
|
|
// TODO: actually we would need to attach a buffer first
|
|
|
|
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());
|
|
|
|
QCOMPARE(serverSurface->damage(), QRegion(0, 0, 10, 10));
|
|
|
|
QCOMPARE(damageSpy.first().first().value<QRegion>(), QRegion(0, 0, 10, 10));
|
|
|
|
|
|
|
|
// damage multiple times
|
|
|
|
QRegion testRegion(5, 8, 3, 6);
|
|
|
|
testRegion = testRegion.united(QRect(10, 20, 30, 15));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testFrameCallback()
|
|
|
|
{
|
2014-09-17 14:10:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2014-09-17 14:10:38 +00:00
|
|
|
KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
|
2014-08-28 07:52:35 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion)));
|
|
|
|
QVERIFY(damageSpy.isValid());
|
|
|
|
|
|
|
|
QSignalSpy frameRenderedSpy(s, SIGNAL(frameRendered()));
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
// here we need a shm pool
|
|
|
|
m_display->createShm();
|
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2014-08-28 12:22:53 +00:00
|
|
|
QSignalSpy shmSpy(®istry, SIGNAL(shmAnnounced(quint32,quint32)));
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(shmSpy.wait());
|
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::ShmPool pool;
|
2014-08-28 12:22:53 +00:00
|
|
|
pool.setup(registry.bindShm(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>()));
|
|
|
|
QVERIFY(pool.isValid());
|
|
|
|
|
|
|
|
// create the surface
|
2014-09-17 14:10:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
2014-08-28 12:22:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface();
|
2014-08-28 12:22:53 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
2014-09-17 14:10:38 +00:00
|
|
|
KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
|
2014-08-28 12:22:53 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
// create two 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);
|
|
|
|
QImage red(24, 24, QImage::Format_ARGB32);
|
|
|
|
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
|
|
|
|
2014-09-22 07:54:10 +00:00
|
|
|
wl_buffer *blackBuffer = *(pool.createBuffer(black).data());
|
|
|
|
auto redBuffer = pool.createBuffer(red);
|
|
|
|
auto blueBuffer = pool.createBuffer(blue).toStrongRef();
|
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);
|
2014-08-28 12:22:53 +00:00
|
|
|
QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion)));
|
|
|
|
QVERIFY(damageSpy.isValid());
|
|
|
|
QVERIFY(damageSpy.wait());
|
|
|
|
|
|
|
|
// now the ServerSurface should have the black image attached as a buffer
|
2014-09-17 14:10:38 +00:00
|
|
|
KWayland::Server::BufferInterface *buffer = serverSurface->buffer();
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer->ref();
|
|
|
|
QVERIFY(buffer->shmBuffer());
|
|
|
|
QCOMPARE(buffer->data(), black);
|
2014-09-19 12:53:03 +00:00
|
|
|
QCOMPARE(buffer->data().format(), QImage::Format_RGB32);
|
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());
|
2014-09-17 14:10:38 +00:00
|
|
|
KWayland::Server::BufferInterface *buffer2 = serverSurface->buffer();
|
2014-08-28 12:22:53 +00:00
|
|
|
buffer2->ref();
|
|
|
|
QVERIFY(buffer2->shmBuffer());
|
|
|
|
QCOMPARE(buffer2->data(), red);
|
2014-09-19 12:53:03 +00:00
|
|
|
QCOMPARE(buffer2->data().format(), QImage::Format_ARGB32);
|
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));
|
2014-09-20 14:28:47 +00:00
|
|
|
QSignalSpy frameRenderedSpy(s, SIGNAL(frameRendered()));
|
|
|
|
QVERIFY(frameRenderedSpy.isValid());
|
|
|
|
s->commit();
|
2014-09-19 12:53:03 +00:00
|
|
|
damageSpy.clear();
|
|
|
|
QVERIFY(damageSpy.wait());
|
2014-09-20 13:11:40 +00:00
|
|
|
QVERIFY(!buffer2->isReferenced());
|
|
|
|
delete buffer2;
|
|
|
|
// TODO: we should have a signal on when the Buffer gets released
|
|
|
|
QTest::qWait(100);
|
2014-09-22 07:54:10 +00:00
|
|
|
QVERIFY(redBuffer.data()->isReleased());
|
2014-09-20 13:11:40 +00:00
|
|
|
|
2014-09-19 12:53:03 +00:00
|
|
|
KWayland::Server::BufferInterface *buffer3 = serverSurface->buffer();
|
|
|
|
buffer3->ref();
|
|
|
|
QVERIFY(buffer3->shmBuffer());
|
|
|
|
QCOMPARE(buffer3->data().format(), QImage::Format_ARGB32);
|
|
|
|
QCOMPARE(buffer3->data().width(), 24);
|
|
|
|
QCOMPARE(buffer3->data().height(), 24);
|
|
|
|
for (int i = 0; i < 24; ++i) {
|
|
|
|
for (int j = 0; j < 24; ++j) {
|
|
|
|
// it's premultiplied in the format
|
|
|
|
QCOMPARE(buffer3->data().pixel(i, j), qRgba(0, 0, 128, 128));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-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()
|
|
|
|
{
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
using namespace KWayland::Server;
|
|
|
|
// here we need a shm pool
|
|
|
|
m_display->createShm();
|
|
|
|
|
|
|
|
Registry registry;
|
|
|
|
QSignalSpy shmSpy(®istry, SIGNAL(shmAnnounced(quint32,quint32)));
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(shmSpy.wait());
|
|
|
|
|
|
|
|
ShmPool pool1;
|
|
|
|
ShmPool pool2;
|
|
|
|
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
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
|
|
|
QScopedPointer<Surface> s1(m_compositor->createSurface());
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
SurfaceInterface *serverSurface1 = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
|
|
|
|
QVERIFY(serverSurface1);
|
|
|
|
//second surface
|
|
|
|
QScopedPointer<Surface> s2(m_compositor->createSurface());
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
SurfaceInterface *serverSurface2 = serverSurfaceCreated.last().first().value<KWayland::Server::SurfaceInterface*>();
|
|
|
|
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);
|
|
|
|
QImage red(24, 24, QImage::Format_ARGB32);
|
|
|
|
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));
|
|
|
|
s1->commit(Surface::CommitFlag::None);
|
|
|
|
QSignalSpy damageSpy1(serverSurface1, SIGNAL(damaged(QRegion)));
|
|
|
|
QVERIFY(damageSpy1.isValid());
|
|
|
|
QVERIFY(damageSpy1.wait());
|
|
|
|
|
|
|
|
// now the ServerSurface should have the black image attached as a buffer
|
|
|
|
BufferInterface *buffer1 = serverSurface1->buffer();
|
|
|
|
QVERIFY(buffer1);
|
|
|
|
QImage buffer1Data = buffer1->data();
|
|
|
|
QCOMPARE(buffer1Data, black);
|
|
|
|
// accessing the same buffer is OK
|
|
|
|
QImage buffer1Data2 = buffer1->data();
|
|
|
|
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));
|
|
|
|
s2->commit(Surface::CommitFlag::None);
|
|
|
|
QSignalSpy damageSpy2(serverSurface2, SIGNAL(damaged(QRegion)));
|
|
|
|
QVERIFY(damageSpy2.isValid());
|
|
|
|
QVERIFY(damageSpy2.wait());
|
|
|
|
|
|
|
|
BufferInterface *buffer2 = serverSurface2->buffer();
|
|
|
|
QVERIFY(buffer2);
|
|
|
|
QImage buffer2Data = buffer2->data();
|
|
|
|
QCOMPARE(buffer2Data, red);
|
|
|
|
|
|
|
|
// while buffer2 is accessed we cannot access buffer1
|
|
|
|
buffer1Data = buffer1->data();
|
|
|
|
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
|
|
|
|
buffer1Data = buffer1->data();
|
|
|
|
QVERIFY(!buffer1Data.isNull());
|
|
|
|
QCOMPARE(buffer1Data, black);
|
|
|
|
}
|
|
|
|
|
2014-10-16 12:59:01 +00:00
|
|
|
void TestWaylandSurface::testOpaque()
|
|
|
|
{
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
using namespace KWayland::Server;
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
|
|
|
Surface *s = m_compositor->createSurface();
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
|
|
|
|
QVERIFY(serverSurface);
|
|
|
|
QSignalSpy opaqueRegionChangedSpy(serverSurface, SIGNAL(opaqueChanged(QRegion)));
|
|
|
|
QVERIFY(opaqueRegionChangedSpy.isValid());
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
// the region should only be applied after the surface got commited
|
|
|
|
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
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
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
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion(0, 10, 20, 30));
|
|
|
|
|
|
|
|
// let's change the opaque region
|
|
|
|
s->setOpaqueRegion(m_compositor->createRegion(QRegion(10, 20, 30, 40)).get());
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(opaqueRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.last().first().value<QRegion>(), QRegion(10, 20, 30, 40));
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion(10, 20, 30, 40));
|
|
|
|
|
|
|
|
// and let's go back to an empty region
|
|
|
|
s->setOpaqueRegion();
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(opaqueRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.count(), 3);
|
|
|
|
QCOMPARE(opaqueRegionChangedSpy.last().first().value<QRegion>(), QRegion());
|
|
|
|
QCOMPARE(serverSurface->opaque(), QRegion());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSurface::testInput()
|
|
|
|
{
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
using namespace KWayland::Server;
|
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
|
|
|
Surface *s = m_compositor->createSurface();
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
|
|
|
|
QVERIFY(serverSurface);
|
|
|
|
QSignalSpy inputRegionChangedSpy(serverSurface, SIGNAL(inputChanged(QRegion)));
|
|
|
|
QVERIFY(inputRegionChangedSpy.isValid());
|
|
|
|
|
|
|
|
// by default there should be an empty == infinite input region
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion());
|
|
|
|
QCOMPARE(serverSurface->inputIsInfitine(), true);
|
|
|
|
|
|
|
|
// let's install an input region
|
|
|
|
s->setInputRegion(m_compositor->createRegion(QRegion(0, 10, 20, 30)).get());
|
|
|
|
// the region should only be applied after the surface got commited
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion());
|
|
|
|
QCOMPARE(serverSurface->inputIsInfitine(), true);
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 0);
|
|
|
|
|
|
|
|
// so let's commit to get the new region
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(inputRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(inputRegionChangedSpy.last().first().value<QRegion>(), QRegion(0, 10, 20, 30));
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 10, 20, 30));
|
|
|
|
QCOMPARE(serverSurface->inputIsInfitine(), false);
|
|
|
|
|
|
|
|
// committing without setting a new region shouldn't change
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(0, 10, 20, 30));
|
|
|
|
QCOMPARE(serverSurface->inputIsInfitine(), false);
|
|
|
|
|
|
|
|
// let's change the input region
|
|
|
|
s->setInputRegion(m_compositor->createRegion(QRegion(10, 20, 30, 40)).get());
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(inputRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(inputRegionChangedSpy.last().first().value<QRegion>(), QRegion(10, 20, 30, 40));
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion(10, 20, 30, 40));
|
|
|
|
QCOMPARE(serverSurface->inputIsInfitine(), false);
|
|
|
|
|
|
|
|
// and let's go back to an empty region
|
|
|
|
s->setInputRegion();
|
|
|
|
s->commit(Surface::CommitFlag::None);
|
|
|
|
QVERIFY(inputRegionChangedSpy.wait());
|
|
|
|
QCOMPARE(inputRegionChangedSpy.count(), 3);
|
|
|
|
QCOMPARE(inputRegionChangedSpy.last().first().value<QRegion>(), QRegion());
|
|
|
|
QCOMPARE(serverSurface->input(), QRegion());
|
|
|
|
QCOMPARE(serverSurface->inputIsInfitine(), true);
|
|
|
|
}
|
|
|
|
|
2014-09-22 09:14:05 +00:00
|
|
|
void TestWaylandSurface::testDestroy()
|
|
|
|
{
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
Surface *s = m_compositor->createSurface();
|
|
|
|
|
|
|
|
connect(m_connection, &ConnectionThread::connectionDied, s, &Surface::destroy);
|
|
|
|
connect(m_connection, &ConnectionThread::connectionDied, m_compositor, &Compositor::destroy);
|
|
|
|
QVERIFY(s->isValid());
|
|
|
|
|
|
|
|
QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied()));
|
|
|
|
QVERIFY(connectionDiedSpy.isValid());
|
|
|
|
delete m_display;
|
|
|
|
m_display = nullptr;
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
QVERIFY(connectionDiedSpy.wait());
|
|
|
|
|
|
|
|
// now the Surface should be destroyed;
|
|
|
|
QVERIFY(!s->isValid());
|
|
|
|
|
|
|
|
// calling destroy again should not fail
|
|
|
|
s->destroy();
|
|
|
|
}
|
|
|
|
|
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"
|