clients: Add an optional roundtrip for visual lookup
authorBenjamin Franzke <benjaminfranzke@googlemail.com>
Tue, 31 May 2011 09:36:31 +0000 (11:36 +0200)
committerBenjamin Franzke <benjaminfranzke@googlemail.com>
Tue, 31 May 2011 13:05:32 +0000 (15:05 +0200)
clients/simple-client.c
clients/window.c

index f2252ea..0a97be0 100644 (file)
@@ -189,11 +189,30 @@ init_gl(struct window *window)
 }
 
 static void
+sync_callback(void *data)
+{
+       int *done = data;
+
+       *done = 1;
+}
+
+static void
 create_surface(struct window *window)
 {
        struct display *display = window->display;
        struct wl_visual *visual;
        EGLBoolean ret;
+       int done = 0;
+       
+       if (!display->premultiplied_argb_visual) {
+               wl_display_sync_callback(display->display, sync_callback, &done);
+               while (!done)
+                       wl_display_iterate(display->display, display->mask);
+               if (!display->premultiplied_argb_visual) {
+                       fprintf(stderr, "premultiplied argb visual missing\n");
+                       exit(1);
+               }
+       }
 
        window->surface = wl_compositor_create_surface(display->compositor);
        visual = display->premultiplied_argb_visual;
@@ -333,6 +352,8 @@ main(int argc, char **argv)
        wl_display_add_global_listener(display.display,
                                       display_handle_global, &display);
 
+       wl_display_get_fd(display.display, event_mask_update, &display);
+
        init_egl(&display);
        create_surface(&window);
        init_gl(&window);
@@ -340,7 +361,6 @@ main(int argc, char **argv)
        wl_display_frame_callback(display.display, window.surface,
                                  redraw, &window);
 
-       wl_display_get_fd(display.display, event_mask_update, &display);
        while (true)
                wl_display_iterate(display.display, display.mask);
 
index 758a536..944981c 100644 (file)
@@ -1849,6 +1849,25 @@ init_egl(struct display *d)
        return 0;
 }
 
+static void
+sync_callback(void *data)
+{
+       int *done = data;
+
+       *done = 1;
+}
+
+static void
+force_roundtrip(struct display *d)
+{
+       int done = 0;
+
+       wl_display_sync_callback(d->display, sync_callback, &done);
+       wl_display_iterate(d->display, WL_DISPLAY_WRITABLE);
+       while (!done)
+               wl_display_iterate(d->display, WL_DISPLAY_READABLE);
+}
+
 struct display *
 display_create(int *argc, char **argv[], const GOptionEntry *option_entries,
               display_global_handler_t handler)
@@ -1900,7 +1919,6 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries,
 
        /* Process connection events. */
        wl_display_iterate(d->display, WL_DISPLAY_READABLE);
-
        if (init_egl(d) < 0)
                return NULL;
 
@@ -1909,6 +1927,14 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries,
        d->create_image = (void *) eglGetProcAddress("eglCreateImageKHR");
        d->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR");
 
+       if (!d->premultiplied_argb_visual || !d->rgb_visual) {
+               force_roundtrip(d);
+               if (!d->premultiplied_argb_visual || !d->rgb_visual) {
+                       fprintf(stderr, "failed to retreive visuals\n");
+                       return NULL;
+               }
+       }
+
        create_pointer_surfaces(d);
 
        display_render_frame(d);