WLChromakeyExample: update for wayland version 1.0.0
authorNobuhiko Tanibata <ntanibata@jp.adit-jv.com>
Wed, 21 Nov 2012 14:21:05 +0000 (23:21 +0900)
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Thu, 22 Nov 2012 10:03:26 +0000 (02:03 -0800)
Signed-off-by: Nobuhiko Tanibata <ntanibata@jp.adit-jv.com>
LayerManagerExamples/WLChromakeyExample/src/chromakey.c
LayerManagerExamples/WLChromakeyExample/src/serverinfo-protocol.c

index 695a7ad..f65d9c7 100644 (file)
  ****************************************************************************/
 typedef struct t_wlContextStruct {
     struct wl_display*    wlDisplay;
+    struct wl_registry*   wlRegistry;
     struct wl_compositor* wlCompositor;
     struct wl_surface*    wlSurface;
     struct wl_shm*        wlShm;
     uint32_t              formats;
-    uint32_t              mask;
     struct serverinfo*    wlExtServerinfo;
     uint32_t              connect_id;
     ctx_bmpaccessor*      ctx_bmp;
@@ -90,7 +90,7 @@ struct wl_shm_listener shm_listenter = {
     shm_format
 };
 
-static void display_handle_global(struct wl_display* display, uint32_t id, const char* interface, uint32_t version, void* data)
+static void registry_handle_global(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
 {
     WLContextStruct* p_wlCtx = (WLContextStruct*)data;
     int ans_strcmp = 0;
@@ -100,14 +100,14 @@ static void display_handle_global(struct wl_display* display, uint32_t id, const
         ans_strcmp = strcmp(interface, "wl_compositor");
         if (0 == ans_strcmp)
         {
-            p_wlCtx->wlCompositor = (struct wl_compositor*)wl_display_bind(display, id, &wl_compositor_interface);
+            p_wlCtx->wlCompositor = (struct wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 1);
             break;
         }
 
         ans_strcmp = strcmp(interface, "wl_shm");
         if (0 == ans_strcmp)
         {
-            p_wlCtx->wlShm = wl_display_bind(display, id, &wl_shm_interface);
+            p_wlCtx->wlShm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
             wl_shm_add_listener(p_wlCtx->wlShm, &shm_listenter, p_wlCtx);
             break;
         }
@@ -115,20 +115,17 @@ static void display_handle_global(struct wl_display* display, uint32_t id, const
         ans_strcmp = strcmp(interface, "serverinfo");
         if (0 == ans_strcmp)
         {
-            p_wlCtx->wlExtServerinfo = (struct serverinfo*)wl_display_bind(display, id, &serverinfo_interface);
+            p_wlCtx->wlExtServerinfo = (struct serverinfo*)wl_registry_bind(registry, name, &serverinfo_interface, 1);
             serverinfo_add_listener(p_wlCtx->wlExtServerinfo, &serverinfo_listener_list, data);
             serverinfo_get_connection_id(p_wlCtx->wlExtServerinfo);
         }
     } while(0);
 }
 
-static int
-event_mask_update(uint32_t mask, void* data)
-{
-    WLContextStruct* p_wlCtx = (WLContextStruct*)data;
-    p_wlCtx->mask = mask;
-    return 0;
-}
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    NULL
+};
 
 /*****************************************************************************
  *  local functions
@@ -203,9 +200,9 @@ static int createWLContext()
         printf("Error: wl_display_connect() failed.\n");
     }
 
-    wl_display_add_global_listener(g_wlContextStruct.wlDisplay, display_handle_global, &g_wlContextStruct);
-    wl_display_get_fd(g_wlContextStruct.wlDisplay, event_mask_update, &g_wlContextStruct);
-    wl_display_iterate(g_wlContextStruct.wlDisplay, WL_DISPLAY_READABLE);
+    g_wlContextStruct.wlRegistry = wl_display_get_registry(g_wlContextStruct.wlDisplay);
+    wl_registry_add_listener(g_wlContextStruct.wlRegistry, &registry_listener, &g_wlContextStruct);
+    wl_display_dispatch(g_wlContextStruct.wlDisplay);
     wl_display_roundtrip(g_wlContextStruct.wlDisplay);
 
     g_wlContextStruct.wlSurface = wl_compositor_create_surface(g_wlContextStruct.wlCompositor);
@@ -247,6 +244,7 @@ static void drawImage(void)
                       g_wlContextStruct.ctx_bmp->height);
     struct wl_callback* callback = wl_surface_frame(g_wlContextStruct.wlSurface);
     wl_callback_add_listener(callback, &frame_listener, NULL);
+    wl_surface_commit(g_wlContextStruct.wlSurface);
     //wl_display_flush(g_wlContextStruct.wlDisplay);
     wl_display_roundtrip(g_wlContextStruct.wlDisplay);
 }
index 98974d6..7526fe7 100644 (file)
@@ -21,6 +21,8 @@
 #include <stdint.h>
 #include "wayland-util.h"
 
+#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
+
 static const struct wl_interface *types[] = {
        NULL,
 };