Search for Xwayland surfaces differently

Currently, we store all surfaces in a single list and use linear search
to find the SurfaceInterface by its object id and client connection.

With this, we first search for the wl_resource object by its id. Once we
have a wl_resource, SurfaceInterface::get(wl_resource) can be used.

The main advantage of the proposed solution is that we don't need to
maintain a static list with all SurfaceInterface objects.
This commit is contained in:
Vlad Zahorodnii 2021-07-28 14:26:51 +03:00
parent ba3f587200
commit 43cfd25d27
5 changed files with 4 additions and 24 deletions

View file

@ -99,7 +99,7 @@ void ClientConnection::destroy()
wl_client_destroy(d->client);
}
wl_resource *ClientConnection::getResource(quint32 id)
wl_resource *ClientConnection::getResource(quint32 id) const
{
if (!d->client) {
return nullptr;

View file

@ -42,7 +42,7 @@ public:
/**
* Get the wl_resource associated with the given @p id.
*/
wl_resource *getResource(quint32 id);
wl_resource *getResource(quint32 id) const;
/**
* @returns the native wl_client this ClientConnection represents.

View file

@ -23,8 +23,6 @@
namespace KWaylandServer
{
QList<SurfaceInterface *> SurfaceInterfacePrivate::surfaces;
KWaylandFrameCallback::KWaylandFrameCallback(wl_resource *resource, SurfaceInterface *surface)
: QtWaylandServer::wl_callback(resource)
, surface(surface)
@ -50,7 +48,6 @@ void KWaylandFrameCallback::callback_destroy_resource(Resource *)
SurfaceInterfacePrivate::SurfaceInterfacePrivate(SurfaceInterface *q)
: q(q)
{
surfaces.append(q);
}
SurfaceInterfacePrivate::~SurfaceInterfacePrivate()
@ -74,7 +71,6 @@ SurfaceInterfacePrivate::~SurfaceInterfacePrivate()
if (current.buffer) {
current.buffer->unref();
}
surfaces.removeOne(q);
}
void SurfaceInterfacePrivate::addChild(SubSurfaceInterface *child)
@ -385,11 +381,6 @@ CompositorInterface *SurfaceInterface::compositor() const
return d->compositor;
}
QList<SurfaceInterface *> SurfaceInterface::surfaces()
{
return SurfaceInterfacePrivate::surfaces;
}
void SurfaceInterface::frameRendered(quint32 msec)
{
// notify all callbacks
@ -764,11 +755,8 @@ SurfaceInterface *SurfaceInterface::get(wl_resource *native)
SurfaceInterface *SurfaceInterface::get(quint32 id, const ClientConnection *client)
{
const QList<SurfaceInterface *> candidates = surfaces();
for (SurfaceInterface *surface : candidates) {
if (surface->client() == client && surface->id() == id) {
return surface;
}
if (client) {
return get(client->getResource(id));
}
return nullptr;
}

View file

@ -92,11 +92,6 @@ public:
*/
CompositorInterface *compositor() const;
/**
* Returns a list with all created Wayland surfaces.
*/
static QList<SurfaceInterface *> surfaces();
/**
* Maps the specified @a point from the surface-local coordinates to buffer pixel coordinates.
*

View file

@ -132,9 +132,6 @@ public:
QVector<IdleInhibitorV1Interface*> idleInhibitors;
ViewportInterface *viewportExtension = nullptr;
SurfaceInterface *dataProxy = nullptr;
static QList<SurfaceInterface *> surfaces;
ClientConnection *client = nullptr;
protected: