Introduced WaylandClient API to keep track of clients.
authorSamuel Rødal <samuel.rodal@nokia.com>
Thu, 29 Mar 2012 11:56:38 +0000 (13:56 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Thu, 29 Mar 2012 15:45:46 +0000 (17:45 +0200)
Makes it easier to keep track of which surfaces belong to a given
client, and the client associated with a given surface. WaylandClient is
an opaque type, representing an underlying wl_client *.

Change-Id: If21a2e02eb13a860e6ac641875bdcca67a53fdf5
Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
src/compositor/compositor_api/waylandcompositor.cpp
src/compositor/compositor_api/waylandcompositor.h
src/compositor/compositor_api/waylandsurface.cpp
src/compositor/compositor_api/waylandsurface.h
src/compositor/global/waylandexport.h
src/compositor/wayland_wrapper/wlcompositor.cpp
src/compositor/wayland_wrapper/wlcompositor.h
tests/auto/compositor/tst_compositor.cpp

index 95a7bb5..cd4dce7 100644 (file)
@@ -90,7 +90,29 @@ void WaylandCompositor::frameFinished(WaylandSurface *surface)
 
 void WaylandCompositor::destroyClientForSurface(WaylandSurface *surface)
 {
-    m_compositor->destroyClientForSurface(surface->handle());
+    destroyClient(surface->client());
+}
+
+void WaylandCompositor::destroyClient(WaylandClient *client)
+{
+    m_compositor->destroyClient(client);
+}
+
+QList<WaylandSurface *> WaylandCompositor::surfacesForClient(WaylandClient* c) const
+{
+    wl_client *client = static_cast<wl_client *>(c);
+
+    QList<Wayland::Surface *> surfaces = m_compositor->surfaces();
+
+    QList<WaylandSurface *> result;
+
+    for (int i = 0; i < surfaces.count(); ++i) {
+        if (surfaces.at(i)->base()->resource.client == client) {
+            result.append(surfaces.at(i)->waylandSurface());
+        }
+    }
+
+    return result;
 }
 
 void WaylandCompositor::setDirectRenderSurface(WaylandSurface *surface)
index c68cd6c..df56b9b 100644 (file)
@@ -65,6 +65,9 @@ public:
     void frameFinished(WaylandSurface *surface = 0);
 
     void destroyClientForSurface(WaylandSurface *surface);
+    void destroyClient(WaylandClient *client);
+
+    QList<WaylandSurface *> surfacesForClient(WaylandClient* client) const;
 
     void setDirectRenderSurface(WaylandSurface *surface);
     WaylandSurface *directRenderSurface() const;
index f846aec..995c81a 100644 (file)
@@ -87,6 +87,12 @@ WaylandSurface::WaylandSurface(Wayland::Surface *surface)
     connect(this, SIGNAL(windowOrientationChanged()), this, SIGNAL(windowRotationChanged()));
 }
 
+WaylandClient *WaylandSurface::client() const
+{
+    Q_D(const WaylandSurface);
+    return d->surface->base()->resource.client;
+}
+
 WaylandSurface *WaylandSurface::parentSurface() const
 {
     Q_D(const WaylandSurface);
index 1910052..d9fbc39 100644 (file)
@@ -95,6 +95,8 @@ public:
 
     WaylandSurface(Wayland::Surface *surface = 0);
 
+    WaylandClient *client() const;
+
     WaylandSurface *parentSurface() const;
     QLinkedList<WaylandSurface *> subSurfaces() const;
 
index e5c5af0..4ddcaef 100644 (file)
@@ -51,4 +51,6 @@
 #  endif
 #endif
 
+typedef void WaylandClient;
+
 #endif //WAYLANDEXPORT_H
index d539e2d..f12c89b 100644 (file)
@@ -283,10 +283,9 @@ void Compositor::markSurfaceAsDirty(Wayland::Surface *surface)
     m_dirty_surfaces.insert(surface);
 }
 
-void Compositor::destroyClientForSurface(Surface *surface)
+void Compositor::destroyClient(WaylandClient *c)
 {
-    wl_client *client = surface->base()->resource.client;
-
+    wl_client *client = static_cast<wl_client *>(c);
     if (client) {
         m_windowManagerIntegration->removeClient(client);
         wl_client_destroy(client);
index 2ed4a1b..1d3e358 100644 (file)
@@ -93,7 +93,7 @@ public:
     void surfaceDestroyed(Surface *surface);
     void markSurfaceAsDirty(Surface *surface);
 
-    void destroyClientForSurface(Surface *surface);
+    void destroyClient(WaylandClient *client);
 
     static uint currentTimeMsecs();
 
@@ -108,8 +108,8 @@ public:
     Surface *directRenderSurface() const {return m_directRenderSurface;}
     QPlatformScreenPageFlipper *pageFlipper() const { return m_pageFlipper; }
 
+    QList<Surface*> surfaces() const { return m_surfaces; }
     QList<Surface*> surfacesForClient(wl_client* client);
-
     WaylandCompositor *waylandCompositor() const { return m_qt_compositor; }
 
     struct wl_display *wl_display() const { return m_display->handle(); }
index 0e632c4..3f35dd5 100644 (file)
@@ -73,6 +73,16 @@ void tst_WaylandCompositor::singleClient()
     wl_surface *sb = client.createSurface();
     QTRY_COMPARE(compositor.surfaces.size(), 2);
 
+    WaylandClient *ca = compositor.surfaces.at(0)->client();
+    WaylandClient *cb = compositor.surfaces.at(1)->client();
+
+    QCOMPARE(ca, cb);
+
+    QList<WaylandSurface *> surfaces = compositor.surfacesForClient(ca);
+    QCOMPARE(surfaces.size(), 2);
+    QVERIFY((surfaces.at(0) == compositor.surfaces.at(0) && surfaces.at(1) == compositor.surfaces.at(1))
+            || (surfaces.at(0) == compositor.surfaces.at(1) && surfaces.at(1) == compositor.surfaces.at(0)));
+
     wl_surface_destroy(sa);
     QTRY_COMPARE(compositor.surfaces.size(), 1);
 
@@ -94,6 +104,23 @@ void tst_WaylandCompositor::multipleClients()
 
     QTRY_COMPARE(compositor.surfaces.size(), 3);
 
+    WaylandClient *ca = compositor.surfaces.at(0)->client();
+    WaylandClient *cb = compositor.surfaces.at(1)->client();
+    WaylandClient *cc = compositor.surfaces.at(2)->client();
+
+    QVERIFY(ca != cb);
+    QVERIFY(ca != cc);
+    QVERIFY(cb != cc);
+
+    QCOMPARE(compositor.surfacesForClient(ca).size(), 1);
+    QCOMPARE(compositor.surfacesForClient(ca).at(0), compositor.surfaces.at(0));
+
+    QCOMPARE(compositor.surfacesForClient(cb).size(), 1);
+    QCOMPARE(compositor.surfacesForClient(cb).at(0), compositor.surfaces.at(1));
+
+    QCOMPARE(compositor.surfacesForClient(cc).size(), 1);
+    QCOMPARE(compositor.surfacesForClient(cc).at(0), compositor.surfaces.at(2));
+
     wl_surface_destroy(sa);
     wl_surface_destroy(sb);
     wl_surface_destroy(sc);