Commit fb9846c5 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Port the wl_surface wrapper to the new approach

parent ec1bdbe4
......@@ -296,13 +296,6 @@ void TextInputTest::testEnterLeave()
textInput->enable(surface.data());
QVERIFY(enabledChangedSpy.wait());
//trigger an enter again and leave, but this
//time we try sending an event after the surface is unbound
//but not yet destroyed. It should work without errors
QCOMPARE(textInput->enteredSurface(), surface.data());
connect(serverSurface, &Resource::unbound, [=]() {
m_seatInterface->setFocusedKeyboardSurface(nullptr);
});
//delete the client and wait for the server to catch up
QSignalSpy unboundSpy(serverSurface, &QObject::destroyed);
surface.reset();
......
......@@ -76,7 +76,6 @@ private Q_SLOTS:
void testDataDeviceForKeyboardSurface();
void testTouch();
void testDisconnect();
void testPointerEnterOnUnboundSurface();
void testKeymap();
void testKeymapThroughFd();
......@@ -2309,41 +2308,6 @@ void TestWaylandSeat::testDisconnect()
m_queue->destroy();
}
void TestWaylandSeat::testPointerEnterOnUnboundSurface()
{
using namespace KWayland::Client;
using namespace KWaylandServer;
// create the things we need
m_seatInterface->setHasKeyboard(true);
m_seatInterface->setHasPointer(true);
m_seatInterface->setHasTouch(true);
QSignalSpy pointerChangedSpy(m_seat, &Seat::hasPointerChanged);
QVERIFY(pointerChangedSpy.isValid());
QVERIFY(pointerChangedSpy.wait());
// create pointer and Surface
QScopedPointer<Pointer> pointer(m_seat->createPointer());
QVERIFY(!pointer.isNull());
// create the surface
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
QVERIFY(surfaceCreatedSpy.isValid());
QScopedPointer<Surface> s(m_compositor->createSurface());
QVERIFY(surfaceCreatedSpy.wait());
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWaylandServer::SurfaceInterface*>();
QVERIFY(serverSurface);
// unbind the surface again
QSignalSpy surfaceUnboundSpy(serverSurface, &SurfaceInterface::unbound);
QVERIFY(surfaceUnboundSpy.isValid());
s.reset();
QVERIFY(surfaceUnboundSpy.wait());
QSignalSpy clientErrorSpy(m_connection, &ConnectionThread::errorOccurred);
QVERIFY(clientErrorSpy.isValid());
m_seatInterface->setFocusedPointerSurface(serverSurface);
QVERIFY(!clientErrorSpy.wait(100));
}
void TestWaylandSeat::testKeymap()
{
using namespace KWayland::Client;
......
......@@ -238,11 +238,12 @@ void TestWaylandSurface::testStaticAccessor()
delete s1;
QVERIFY(KWayland::Client::Surface::all().isEmpty());
QVERIFY(!KWayland::Client::Surface::get(nullptr));
QSignalSpy unboundSpy(serverSurface1, &KWaylandServer::Resource::unbound);
QVERIFY(unboundSpy.isValid());
QVERIFY(unboundSpy.wait());
QSignalSpy destroyedSpy(serverSurface1, &KWaylandServer::SurfaceInterface::destroyed);
QVERIFY(destroyedSpy.isValid());
QVERIFY(destroyedSpy.wait());
QVERIFY(!KWaylandServer::SurfaceInterface::get(nullptr));
QVERIFY(!KWaylandServer::SurfaceInterface::get(1, nullptr));
QVERIFY(!KWaylandServer::SurfaceInterface::get(serverSurface1->id(), nullptr));
QVERIFY(!KWaylandServer::SurfaceInterface::get(serverSurface2->id(), nullptr));
}
void TestWaylandSurface::testDamage()
......@@ -255,7 +256,6 @@ void TestWaylandSurface::testDamage()
KWaylandServer::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface*>();
QVERIFY(serverSurface);
QCOMPARE(serverSurface->damage(), QRegion());
QVERIFY(serverSurface->parentResource());
QVERIFY(!serverSurface->isMapped());
QSignalSpy committedSpy(serverSurface, SIGNAL(committed()));
......
......@@ -64,7 +64,7 @@ private:
KWaylandServer::CompositorInterface *m_compositorInterface;
KWaylandServer::PlasmaWindowManagementInterface *m_windowManagementInterface;
KWaylandServer::PlasmaWindowInterface *m_windowInterface;
KWaylandServer::SurfaceInterface *m_surfaceInterface = nullptr;
QPointer<KWaylandServer::SurfaceInterface> m_surfaceInterface;
KWayland::Client::Surface *m_surface = nullptr;
KWayland::Client::ConnectionThread *m_connection;
......@@ -234,8 +234,7 @@ void TestWindowManagement::cleanup()
delete m_windowInterface;
m_windowInterface = nullptr;
delete m_surfaceInterface;
m_surfaceInterface = nullptr;
QVERIFY(m_surfaceInterface.isNull());
delete m_display;
m_display = nullptr;
......
......@@ -42,7 +42,7 @@ private:
void doExport();
KWaylandServer::Display *m_display;
KWaylandServer::CompositorInterface *m_compositorInterface;
QPointer<KWaylandServer::CompositorInterface> m_compositorInterface;
KWaylandServer::XdgForeignInterface *m_foreignInterface;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::Compositor *m_compositor;
......@@ -151,11 +151,6 @@ void TestForeign::cleanup()
variable = nullptr; \
}
CLEANUP(m_exportedSurfaceInterface)
CLEANUP(m_childSurfaceInterface)
CLEANUP(m_compositor)
CLEANUP(m_exporter)
CLEANUP(m_importer)
......@@ -170,7 +165,6 @@ void TestForeign::cleanup()
delete m_thread;
m_thread = nullptr;
}
CLEANUP(m_compositorInterface)
CLEANUP(m_foreignInterface)
//internally there are some deleteLaters on exported interfaces
......@@ -182,6 +176,8 @@ void TestForeign::cleanup()
destroyedSpy.wait();
}
QVERIFY(m_compositorInterface.isNull());
#undef CLEANUP
}
......@@ -259,10 +255,6 @@ void TestForeign::testDeleteChildSurface()
QVERIFY(transientSpy.wait());
//when the client surface dies, the server one will eventually die too
QSignalSpy surfaceDestroyedSpy(m_childSurfaceInterface, SIGNAL(destroyed()));
QVERIFY(surfaceDestroyedSpy.wait());
QVERIFY(!transientSpy.first().at(0).value<KWaylandServer::SurfaceInterface *>());
QCOMPARE(transientSpy.first().at(1).value<KWaylandServer::SurfaceInterface *>(), m_exportedSurfaceInterface.data());
}
......
......@@ -47,7 +47,8 @@ void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_unset(Resource *reso
if (!s) {
return;
}
s->d_func()->setBlur(QPointer<BlurInterface>());
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setBlur(QPointer<BlurInterface>());
}
......@@ -64,7 +65,8 @@ void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_create(Resource *res
return;
}
auto blur = new BlurInterface(blur_resource);
s->d_func()->setBlur(blur);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setBlur(blur);
}
BlurManagerInterface::BlurManagerInterface(Display *display, QObject *parent)
......
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "buffer_interface.h"
#include "compositor_interface.h"
#include "display.h"
#include "logging.h"
#include "surface_interface.h"
......@@ -155,7 +156,7 @@ BufferInterface::Private::Private(BufferInterface *q, wl_resource *resource, Sur
}
size = dmabufBuffer->size();
} else if (parent) {
EGLDisplay eglDisplay = parent->global()->display()->eglDisplay();
EGLDisplay eglDisplay = parent->compositor()->display()->eglDisplay();
static bool resolved = false;
using namespace EGL;
if (!resolved && eglDisplay != EGL_NO_DISPLAY) {
......
......@@ -49,7 +49,9 @@ class LinuxDmabufBuffer;
class KWAYLANDSERVER_EXPORT BufferInterface : public QObject
{
Q_OBJECT
public:
explicit BufferInterface(wl_resource *resource, SurfaceInterface *parent);
virtual ~BufferInterface();
/**
* Reference the BufferInterface.
......@@ -171,8 +173,6 @@ Q_SIGNALS:
void sizeChanged();
private:
friend class SurfaceInterface;
explicit BufferInterface(wl_resource *resource, SurfaceInterface *parent);
class Private;
QScopedPointer<Private> d;
};
......
......@@ -82,14 +82,13 @@ void CompositorInterface::Private::createSurfaceCallback(wl_client *client, wl_r
void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id)
{
SurfaceInterface *surface = new SurfaceInterface(q, resource);
surface->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!surface->resource()) {
wl_resource *surfaceResource = wl_resource_create(client, &wl_surface_interface,
wl_resource_get_version(resource), id);
if (!surfaceResource) {
wl_resource_post_no_memory(resource);
delete surface;
return;
}
emit q->surfaceCreated(surface);
emit q->surfaceCreated(new SurfaceInterface(q, surfaceResource));
}
void CompositorInterface::Private::createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id)
......
......@@ -51,7 +51,8 @@ void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_create(Resou
return;
}
auto contrast = new ContrastInterface(contrast_resource);
s->d_func()->setContrast(contrast);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setContrast(contrast);
}
void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_unset(Resource *resource, wl_resource *surface)
......@@ -61,7 +62,8 @@ void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_unset(Resour
wl_resource_post_error(resource->handle, 0, "Invalid surface");
return;
}
s->d_func()->setContrast(QPointer<ContrastInterface>());
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setContrast(QPointer<ContrastInterface>());
}
ContrastManagerInterface::ContrastManagerInterface(Display *display, QObject *parent)
......
......@@ -60,7 +60,8 @@ void IdleInhibitManagerUnstableV1Interface::Private::createInhibitorCallback(wl_
auto q = cast(resource);
auto inhibitor = new IdleInhibitorInterface(q->q, resource);
inhibitor->d_func()->create(q->display->getConnection(client), version, id);
s->d_func()->installIdleInhibitor(inhibitor);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->installIdleInhibitor(inhibitor);
}
void IdleInhibitManagerUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
......
......@@ -130,7 +130,7 @@ void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface, quint32 ser
if (!d->focusedSurface) {
return;
}
d->destroyConnection = connect(d->focusedSurface, &Resource::aboutToBeUnbound, this,
d->destroyConnection = connect(d->focusedSurface, &SurfaceInterface::aboutToBeUnbound, this,
[this] {
Q_D();
if (d->resource) {
......
......@@ -54,7 +54,7 @@ class PlasmaShellSurfaceInterface::Private : public Resource::Private
public:
Private(PlasmaShellSurfaceInterface *q, PlasmaShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource);
SurfaceInterface *surface;
QPointer<SurfaceInterface> surface;
QPoint m_globalPos;
Role m_role = Role::Normal;
bool m_positionSet = false;
......@@ -159,12 +159,6 @@ const struct org_kde_plasma_surface_interface PlasmaShellSurfaceInterface::Priva
PlasmaShellSurfaceInterface::PlasmaShellSurfaceInterface(PlasmaShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, shell, parent, parentResource))
{
auto unsetSurface = [this] {
Q_D();
d->surface = nullptr;
};
connect(parent, &Resource::unbound, this, unsetSurface);
connect(parent, &QObject::destroyed, this, unsetSurface);
}
PlasmaShellSurfaceInterface::~PlasmaShellSurfaceInterface() = default;
......
......@@ -264,7 +264,7 @@ void PointerInterface::setFocusedSurface(SurfaceInterface *surface, quint32 seri
return;
}
d->focusedSurface = surface;
d->destroyConnection = connect(d->focusedSurface, &Resource::aboutToBeUnbound, this,
d->destroyConnection = connect(d->focusedSurface, &SurfaceInterface::aboutToBeUnbound, this,
[this] {
Q_D();
d->sendLeave(d->focusedChildSurface.data(), d->global->display()->nextSerial());
......
......@@ -177,7 +177,7 @@ protected:
private:
Private *d_func() const;
friend class SurfaceInterface;
friend class SurfaceInterfacePrivate;
};
/**
......@@ -271,7 +271,7 @@ protected:
private:
Private *d_func() const;
friend class SurfaceInterface;
friend class SurfaceInterfacePrivate;
};
}
......
......@@ -84,7 +84,7 @@ void PointerConstraintsUnstableV1Interface::Private::createConstraint(wl_client
return;
}
if (!s->lockedPointer().isNull() || !s->confinedPointer().isNull()) {
wl_resource_post_error(s->resource(), ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, "Surface already constrained");
wl_resource_post_error(surface, ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, "Surface already constrained");
return;
}
auto constraint = new T(q, resource);
......@@ -100,7 +100,8 @@ void PointerConstraintsUnstableV1Interface::Private::createConstraint(wl_client
auto r = RegionInterface::get(region);
constraint->d_func()->region = r ? r->region() : QRegion();
constraint->d_func()->create(display->getConnection(client), version, id);
s->d_func()->installPointerConstraint(constraint);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->installPointerConstraint(constraint);
}
void PointerConstraintsUnstableV1Interface::Private::lockPointerCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *pointer, wl_resource *region, uint32_t lifetime)
......
......@@ -1616,7 +1616,7 @@ void SeatInterface::setFocusedTextInputSurface(SurfaceInterface *surface)
}
d->textInput.focus.textInput = t;
if (d->textInput.focus.surface) {
d->textInput.focus.destroyConnection = connect(surface, &Resource::aboutToBeUnbound, this,
d->textInput.focus.destroyConnection = connect(surface, &SurfaceInterface::aboutToBeUnbound, this,
[this] {
setFocusedTextInputSurface(nullptr);
}
......
......@@ -97,7 +97,8 @@ void ShadowManagerInterface::Private::createShadow(wl_client *client, wl_resourc
delete shadow;
return;
}
s->d_func()->setShadow(QPointer<ShadowInterface>(shadow));
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setShadow(QPointer<ShadowInterface>(shadow));
}
void ShadowManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface)
......@@ -108,7 +109,8 @@ void ShadowManagerInterface::Private::unsetCallback(wl_client *client, wl_resour
if (!s) {
return;
}
s->d_func()->setShadow(QPointer<ShadowInterface>());
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setShadow(QPointer<ShadowInterface>());
}
ShadowManagerInterface::ShadowManagerInterface(Display *display, QObject *parent)
......
......@@ -67,7 +67,8 @@ void SlideManagerInterface::Private::createSlide(wl_client *client, wl_resource
delete slide;
return;
}
s->d_func()->setSlide(QPointer<SlideInterface>(slide));
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setSlide(QPointer<SlideInterface>(slide));
}
void SlideManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource * surface)
......
......@@ -132,7 +132,8 @@ SubSurfaceInterface::Private::~Private()
// no need to notify the surface as it's tracking a QPointer which will be reset automatically
if (parent) {
Q_Q(SubSurfaceInterface);
reinterpret_cast<SurfaceInterface::Private*>(parent->d.data())->removeChild(QPointer<SubSurfaceInterface>(q));
SurfaceInterfacePrivate *parentPrivate = SurfaceInterfacePrivate::get(parent);
parentPrivate->removeChild(QPointer<SubSurfaceInterface>(q));
}
}
......@@ -145,21 +146,23 @@ void SubSurfaceInterface::Private::create(ClientConnection *client, quint32 vers
surface = s;
parent = p;
Q_Q(SubSurfaceInterface);
surface->d_func()->subSurface = QPointer<SubSurfaceInterface>(q);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
SurfaceInterfacePrivate *parentPrivate = SurfaceInterfacePrivate::get(parent);
surfacePrivate->subSurface = QPointer<SubSurfaceInterface>(q);
// copy current state to subSurfacePending state
// it's the reference for all new pending state which needs to be committed
surface->d_func()->subSurfacePending = surface->d_func()->current;
surface->d_func()->subSurfacePending.blurIsSet = false;
surface->d_func()->subSurfacePending.bufferIsSet = false;
surface->d_func()->subSurfacePending.childrenChanged = false;
surface->d_func()->subSurfacePending.contrastIsSet = false;
surface->d_func()->subSurfacePending.callbacks.clear();
surface->d_func()->subSurfacePending.inputIsSet = false;
surface->d_func()->subSurfacePending.inputIsInfinite = true;
surface->d_func()->subSurfacePending.opaqueIsSet = false;
surface->d_func()->subSurfacePending.shadowIsSet = false;
surface->d_func()->subSurfacePending.slideIsSet = false;
parent->d_func()->addChild(QPointer<SubSurfaceInterface>(q));
surfacePrivate->subSurfacePending = surfacePrivate->current;
surfacePrivate->subSurfacePending.blurIsSet = false;
surfacePrivate->subSurfacePending.bufferIsSet = false;
surfacePrivate->subSurfacePending.childrenChanged = false;
surfacePrivate->subSurfacePending.contrastIsSet = false;
surfacePrivate->subSurfacePending.frameCallbacks.clear();
surfacePrivate->subSurfacePending.inputIsSet = false;
surfacePrivate->subSurfacePending.inputIsInfinite = true;
surfacePrivate->subSurfacePending.opaqueIsSet = false;
surfacePrivate->subSurfacePending.shadowIsSet = false;
surfacePrivate->subSurfacePending.slideIsSet = false;
parentPrivate->addChild(QPointer<SubSurfaceInterface>(q));
QObject::connect(surface.data(), &QObject::destroyed, q,
[this] {
......@@ -168,7 +171,8 @@ void SubSurfaceInterface::Private::create(ClientConnection *client, quint32 vers
// takes effect immediately."
if (parent) {
Q_Q(SubSurfaceInterface);
reinterpret_cast<SurfaceInterface::Private*>(parent->d.data())->removeChild(QPointer<SubSurfaceInterface>(q));
SurfaceInterfacePrivate *parentPrivate = SurfaceInterfacePrivate::get(parent);
parentPrivate->removeChild(QPointer<SubSurfaceInterface>(q));
}
}
);
......@@ -184,7 +188,8 @@ void SubSurfaceInterface::Private::commit()
emit q->positionChanged(pos);
}
if (surface) {
surface->d_func()->commitSubSurface();
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->commitSubSurface();
}
}
......@@ -225,7 +230,8 @@ void SubSurfaceInterface::Private::placeAbove(SurfaceInterface *sibling)
return;
}
Q_Q(SubSurfaceInterface);
if (!parent->d_func()->raiseChild(QPointer<SubSurfaceInterface>(q), sibling)) {
SurfaceInterfacePrivate *parentPrivate = SurfaceInterfacePrivate::get(parent);
if (!parentPrivate->raiseChild(QPointer<SubSurfaceInterface>(q), sibling)) {
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Incorrect sibling");
}
}
......@@ -243,7 +249,8 @@ void SubSurfaceInterface::Private::placeBelow(SurfaceInterface *sibling)
return;
}
Q_Q(SubSurfaceInterface);
if (!parent->d_func()->lowerChild(QPointer<SubSurfaceInterface>(q), sibling)) {
SurfaceInterfacePrivate *parentPrivate = SurfaceInterfacePrivate::get(parent);
if (!parentPrivate->lowerChild(QPointer<SubSurfaceInterface>(q), sibling)) {
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Incorrect sibling");
}
}
......@@ -268,8 +275,9 @@ void SubSurfaceInterface::Private::setMode(Mode m)
if (m == Mode::Desynchronized && (!parent->subSurface() || !parent->subSurface()->isSynchronized())) {
// no longer synchronized, this is like calling commit
if (surface) {
surface->d_func()->commit();
surface->d_func()->commitSubSurface();
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->commit();
surfacePrivate->commitSubSurface();
}
}
mode = m;
......@@ -347,8 +355,9 @@ QPointer<SurfaceInterface> SubSurfaceInterface::mainSurface() const
if (!d->parent) {
return QPointer<SurfaceInterface>();
}
if (d->parent->d_func()->subSurface) {
return d->parent->d_func()->subSurface->mainSurface();
SurfaceInterfacePrivate *parentPrivate = SurfaceInterfacePrivate::get(d->parent);
if (parentPrivate->subSurface) {
return parentPrivate->subSurface->mainSurface();
}
return d->parent;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment