[Libva] [PATCH 2/2] Wayland: Port to 1.0 protocol

Rob Bradford robert.bradford at intel.com
Mon Nov 12 06:52:22 PST 2012


From: Rob Bradford <rob at linux.intel.com>

With the change in protocol the hash of globals maintained by the client was
dropped. Instead we must setup a listener on the registry and get the globals
in a stream from that.
---
 test/common/va_display_wayland.c     | 38 ++++++++++++++---------------
 test/putsurface/putsurface_wayland.c | 46 ++++++++++++++++--------------------
 va/wayland/va_wayland_drm.c          | 41 ++++++++++++++++++++++++--------
 va/wayland/va_wayland_emgd.c         | 41 ++++++++++++++++++++++++--------
 4 files changed, 101 insertions(+), 65 deletions(-)

diff --git a/test/common/va_display_wayland.c b/test/common/va_display_wayland.c
index 332d16d..e31efbb 100644
--- a/test/common/va_display_wayland.c
+++ b/test/common/va_display_wayland.c
@@ -33,42 +33,39 @@
 
 struct display {
     struct wl_display          *display;
+    struct wl_registry         *registry;
     struct wl_compositor       *compositor;
     struct wl_shell            *shell;
     struct wl_shell_surface    *shell_surface;
     struct wl_surface          *surface;
     unsigned int                ref_count;
     int                         event_fd;
-    unsigned int                event_mask;
 };
 
 static struct display *g_display;
 
 static void
-display_handle_global(
-    struct wl_display *display,
-    uint32_t           id,
-    const char        *interface,
-    uint32_t           version,
-    void              *data
+registry_handle_global(
+    void               *data,
+    struct wl_registry *registry,
+    uint32_t            id,
+    const char         *interface,
+    uint32_t            version
 )
 {
     struct display * const d = data;
 
     if (strcmp(interface, "wl_compositor") == 0)
-        d->compositor = wl_display_bind(display, id, &wl_compositor_interface);
+        d->compositor =
+            wl_registry_bind(registry, id, &wl_compositor_interface, 1);
     else if (strcmp(interface, "wl_shell") == 0)
-        d->shell = wl_display_bind(display, id, &wl_shell_interface);
+        d->shell = wl_registry_bind(registry, id, &wl_shell_interface, 1);
 }
 
-static int
-event_mask_update(uint32_t mask, void *data)
-{
-    struct display * const d = data;
-
-    d->event_mask = mask;
-    return 0;
-}
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    NULL,
+};
 
 static VADisplay
 va_open_display_wayland(void)
@@ -91,9 +88,10 @@ va_open_display_wayland(void)
             return NULL;
         }
         wl_display_set_user_data(d->display, d);
-        wl_display_add_global_listener(d->display, display_handle_global, d);
-        d->event_fd = wl_display_get_fd(d->display, event_mask_update, d);
-        wl_display_iterate(d->display, d->event_mask);
+        d->registry = wl_display_get_registry(d->display);
+        wl_registry_add_listener(d->registry, &registry_listener, d);
+        d->event_fd = wl_display_get_fd(d->display);
+        wl_display_dispatch(d->display);
 
         d->ref_count = 1;
         g_display = d;
diff --git a/test/putsurface/putsurface_wayland.c b/test/putsurface/putsurface_wayland.c
index 3e1d495..b93334d 100644
--- a/test/putsurface/putsurface_wayland.c
+++ b/test/putsurface/putsurface_wayland.c
@@ -102,7 +102,7 @@ struct display {
     struct wl_display  *display;
     struct wl_compositor *compositor;
     struct wl_shell    *shell;
-    uint32_t            mask;
+    struct wl_registry *registry;
     int                 event_fd;
 };
 
@@ -153,7 +153,7 @@ va_put_surface(
     if (wl_drawable->redraw_pending) {
         wl_display_flush(d->display);
         while (wl_drawable->redraw_pending)
-            wl_display_iterate(wl_drawable->display, WL_DISPLAY_READABLE);
+            wl_display_dispatch(wl_drawable->display);
     }
 
     va_status = vaGetSurfaceBufferWl(va_dpy, va_surface, VA_FRAME_PICTURE, &buffer);
@@ -169,35 +169,33 @@ va_put_surface(
     wl_display_flush(d->display);
     wl_drawable->redraw_pending = 1;
     callback = wl_surface_frame(wl_drawable->surface);
+    wl_surface_commit(wl_drawable->surface);
     wl_callback_add_listener(callback, &frame_callback_listener, wl_drawable);
     return VA_STATUS_SUCCESS;
 }
 
 static void
-display_handle_global(
-    struct wl_display *display,
-    uint32_t           id,
-    const char        *interface,
-    uint32_t           version,
-    void              *data
+registry_handle_global(
+    void               *data,
+    struct wl_registry *registry,
+    uint32_t            id,
+    const char         *interface,
+    uint32_t            version
 )
 {
     struct display * const d = data;
 
     if (strcmp(interface, "wl_compositor") == 0)
-        d->compositor = wl_display_bind(display, id, &wl_compositor_interface);
+        d->compositor =
+            wl_registry_bind(registry, id, &wl_compositor_interface, 1);
     else if (strcmp(interface, "wl_shell") == 0)
-        d->shell = wl_display_bind(display, id, &wl_shell_interface);
+        d->shell = wl_registry_bind(registry, id, &wl_shell_interface, 1);
 }
 
-static int
-event_mask_update(uint32_t mask, void *data)
-{
-    struct display * const d = data;
-
-    d->mask = mask;
-    return 0;
-}
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    NULL,
+};
 
 static void *
 open_display(void)
@@ -213,9 +211,10 @@ open_display(void)
         return NULL;
 
     wl_display_set_user_data(d->display, d);
-    wl_display_add_global_listener(d->display, display_handle_global, d);
-    d->event_fd = wl_display_get_fd(d->display, event_mask_update, d);
-    wl_display_iterate(d->display, d->mask);
+    d->registry = wl_display_get_registry(d->display);
+    wl_registry_add_listener(d->registry, &registry_listener, d);
+    d->event_fd = wl_display_get_fd(d->display);
+    wl_display_dispatch(d->display);
     return d->display;
 }
 
@@ -298,9 +297,6 @@ check_window_event(
     if (check_event == 0)
         return 0;
 
-    if (!(d->mask & WL_DISPLAY_READABLE))
-        return 0;
-
     tv.tv_sec  = 0;
     tv.tv_usec = 0;
     do {
@@ -313,7 +309,7 @@ check_window_event(
             break;
         }
         if (retval == 1)
-            wl_display_iterate(d->display, WL_DISPLAY_READABLE);
+            wl_display_dispatch(d->display);
     } while (retval > 0);
 
 #if 0
diff --git a/va/wayland/va_wayland_drm.c b/va/wayland/va_wayland_drm.c
index 30c3953..d292316 100644
--- a/va/wayland/va_wayland_drm.c
+++ b/va/wayland/va_wayland_drm.c
@@ -44,6 +44,7 @@ typedef struct va_wayland_drm_context {
     struct va_wayland_context   base;
     void                       *handle;
     struct wl_drm              *drm;
+    struct wl_registry         *registry;
     void                       *drm_interface;
     unsigned int                is_authenticated        : 1;
 } VADisplayContextWaylandDRM;
@@ -142,6 +143,28 @@ va_wayland_drm_destroy(VADisplayContextP pDisplayContext)
     }
 }
 
+static void
+registry_handle_global(
+    void               *data,
+    struct wl_registry *registry,
+    uint32_t            id,
+    const char         *interface,
+    uint32_t            version
+)
+{
+    struct va_wayland_drm_context *wl_drm_ctx = data;
+
+    if (strcmp(interface, "wl_drm") == 0) {
+        wl_drm_ctx->drm =
+            wl_registry_bind(wl_drm_ctx->registry, id, wl_drm_ctx->drm_interface, 1);
+    }
+}
+
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    NULL,
+};
+
 bool
 va_wayland_drm_create(VADisplayContextP pDisplayContext)
 {
@@ -168,14 +191,6 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
     drm_state->auth_type = 0;
     ctx->drm_state       = drm_state;
 
-    id = wl_display_get_global(ctx->native_dpy, "wl_drm", 1);
-    if (!id) {
-        wl_display_roundtrip(ctx->native_dpy);
-        id = wl_display_get_global(ctx->native_dpy, "wl_drm", 1);
-        if (!id)
-            return false;
-    }
-
     wl_drm_ctx->handle = dlopen(LIBWAYLAND_DRM_NAME, RTLD_LAZY|RTLD_LOCAL);
     if (!wl_drm_ctx->handle)
         return false;
@@ -185,8 +200,14 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
     if (!wl_drm_ctx->drm_interface)
         return false;
 
-    wl_drm_ctx->drm =
-        wl_display_bind(ctx->native_dpy, id, wl_drm_ctx->drm_interface);
+    wl_drm_ctx->registry = wl_display_get_registry(ctx->native_dpy);
+    wl_registry_add_listener(wl_drm_ctx->registry, &registry_listener, wl_drm_ctx);
+    wl_display_roundtrip(ctx->native_dpy);
+
+    /* registry_handle_global should have been called by the
+     * wl_display_roundtrip above
+     */
+
     if (!wl_drm_ctx->drm)
         return false;
 
diff --git a/va/wayland/va_wayland_emgd.c b/va/wayland/va_wayland_emgd.c
index 73e6802..8d87c55 100644
--- a/va/wayland/va_wayland_emgd.c
+++ b/va/wayland/va_wayland_emgd.c
@@ -40,6 +40,7 @@ typedef struct va_wayland_emgd_context {
     struct wl_emgd             *emgd;
     void                       *emgd_interface;
     unsigned int                is_created      : 1;
+    struct wl_registry         *registry;
 } VADisplayContextWaylandEMGD;
 
 static inline void
@@ -86,6 +87,29 @@ va_wayland_emgd_destroy(VADisplayContextP pDisplayContext)
     }
 }
 
+
+static void
+registry_handle_global(
+    void               *data,
+    struct wl_registry *registry,
+    uint32_t            id,
+    const char         *interface,
+    uint32_t            version
+)
+{
+    VADisplayContextWaylandEMGD *wl_emgd_ctx = data;
+
+    if (strcmp(interface, "wl_emgd") == 0) {
+        wl_emgd_ctx->emgd =
+            wl_registry_bind(registry, id, wl_emgd_ctx->emgd_interface, 1);
+    }
+}
+
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    NULL,
+};
+
 bool
 va_wayland_emgd_create(VADisplayContextP pDisplayContext)
 {
@@ -112,14 +136,6 @@ va_wayland_emgd_create(VADisplayContextP pDisplayContext)
     drm_state->auth_type = 0;
     ctx->drm_state       = drm_state;
 
-    id = wl_display_get_global(ctx->native_dpy, "wl_emgd", 1);
-    if (!id) {
-        wl_display_roundtrip(ctx->native_dpy);
-        id = wl_display_get_global(ctx->native_dpy, "wl_emgd", 1);
-        if (!id)
-            return false;
-    }
-
     wl_emgd_ctx->handle = dlopen(LIBWAYLAND_EMGD_NAME, RTLD_LAZY|RTLD_LOCAL);
     if (!wl_emgd_ctx->handle)
         return false;
@@ -129,8 +145,13 @@ va_wayland_emgd_create(VADisplayContextP pDisplayContext)
     if (!wl_emgd_ctx->emgd_interface)
         return false;
 
-    wl_emgd_ctx->emgd =
-        wl_display_bind(ctx->native_dpy, id, wl_emgd_ctx->emgd_interface);
+    wl_emgd_ctx->registry = wl_display_get_registry(ctx->native_dpy);
+    wl_registry_add_listener(wl_emgd_ctx->registry, &registry_listener, wl_emgd_ctx);
+    wl_display_roundtrip(ctx->native_dpy);
+
+    /* registry_handle_global should have been called by the
+     * wl_display_roundtrip above
+     */
     if (!wl_emgd_ctx->emgd)
         return false;
     return true;
-- 
1.7.11.2



More information about the Libva mailing list