commit e3e448fdd7429644ec5893350bccf7baab2e1ff6
parent a61f44712e38a67823bcde5f999509d90b8d3ed2
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 18 Jul 2013 19:49:34 -0700
Use a central queue
Diffstat:
6 files changed, 43 insertions(+), 45 deletions(-)
diff --git a/wayland-drm.c b/wayland-drm.c
@@ -40,7 +40,6 @@ struct wld_drm_context
{
struct wl_drm * wl;
struct wl_registry * registry;
- struct wl_event_queue * queue;
struct wl_array formats;
int fd;
bool authenticated;
@@ -117,59 +116,55 @@ static const struct wld_drm_interface * find_drm_interface(int fd)
return NULL;
}
-struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
+struct wld_drm_context * wld_drm_create_context(struct wl_display * display,
+ struct wl_event_queue * queue)
{
struct wld_drm_context * drm;
drm = malloc(sizeof *drm);
if (!drm)
- return 0;
+ goto error0;
drm->wl = NULL;
drm->fd = -1;
wl_array_init(&drm->formats);
- drm->queue = wl_display_create_queue(display);
-
- if (!drm->queue)
- goto error2;
-
drm->registry = wl_display_get_registry(display);
if (!drm->registry)
- goto error3;
+ goto error1;
wl_registry_add_listener(drm->registry, ®istry_listener, drm);
- wl_proxy_set_queue((struct wl_proxy *) drm->registry, drm->queue);
+ wl_proxy_set_queue((struct wl_proxy *) drm->registry, queue);
/* Wait for wl_drm global. */
- wayland_roundtrip(display, drm->queue);
+ wayland_roundtrip(display, queue);
if (!drm->wl)
{
DEBUG("No wl_drm global\n");
- goto error3;
+ goto error2;
}
wl_drm_add_listener(drm->wl, &drm_listener, drm);
/* Wait for DRM device. */
- wayland_roundtrip(display, drm->queue);
+ wayland_roundtrip(display, queue);
if (drm->fd == -1)
{
DEBUG("No DRM device\n");
- goto error4;
+ goto error3;
}
/* Wait for DRM authentication. */
- wayland_roundtrip(display, drm->queue);
+ wayland_roundtrip(display, queue);
if (!drm->authenticated)
{
DEBUG("DRM authentication failed\n");
- goto error5;
+ goto error4;
}
drm->interface = find_drm_interface(drm->fd);
@@ -177,7 +172,7 @@ struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
if (!drm->interface)
{
DEBUG("Couldn't find drawable implementation for DRM device\n");
- goto error5;
+ goto error4;
}
drm->context = drm->interface->create_context(drm->fd);
@@ -185,19 +180,17 @@ struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
if (!drm->context)
{
DEBUG("Couldn't create context for DRM drawable implementation\n");
- goto error5;
+ goto error4;
}
return drm;
- error5:
- close(drm->fd);
error4:
- wl_drm_destroy(drm->wl);
+ close(drm->fd);
error3:
- wl_registry_destroy(drm->registry);
+ wl_drm_destroy(drm->wl);
error2:
- wl_event_queue_destroy(drm->queue);
+ wl_registry_destroy(drm->registry);
error1:
wl_array_release(&drm->formats);
free(drm);
@@ -211,7 +204,6 @@ void wld_drm_destroy_context(struct wld_drm_context * drm)
close(drm->fd);
wl_drm_destroy(drm->wl);
wl_registry_destroy(drm->registry);
- wl_event_queue_destroy(drm->queue);
wl_array_release(&drm->formats);
free(drm);
@@ -271,10 +263,7 @@ void registry_global(void * data, struct wl_registry * registry, uint32_t name,
struct wld_drm_context * drm = data;
if (strcmp(interface, "wl_drm") == 0)
- {
drm->wl = wl_registry_bind(registry, name, &wl_drm_interface, 1);
- wl_proxy_set_queue((struct wl_proxy *) drm->wl, drm->queue);
- }
}
void drm_device(void * data, struct wl_drm * wl, const char * name)
diff --git a/wayland-drm.h b/wayland-drm.h
@@ -32,13 +32,15 @@ struct wld_drawable;
enum wld_format;
struct wl_display;
+struct wl_event_queue;
struct wl_surface;
/**
* Create a new drawable context which creates Wayland buffers through the
* wl_drm interface, backed by hardware specific drawable implementations.
*/
-struct wld_drm_context * wld_drm_create_context(struct wl_display * display);
+struct wld_drm_context * wld_drm_create_context(struct wl_display * display,
+ struct wl_event_queue * queue);
/**
* Destroy a DRM context.
diff --git a/wayland-private.h b/wayland-private.h
@@ -32,7 +32,8 @@ enum wld_format format;
struct wl_display;
struct wl_event_queue;
-typedef void * (* wayland_create_context_func_t)(struct wl_display * display);
+typedef void * (* wayland_create_context_func_t)(struct wl_display * display,
+ struct wl_event_queue * queue);
typedef void (* wayland_destroy_context_func_t)(void * context);
typedef struct wld_drawable * (* wayland_create_drawable_func_t)
(void * context, struct wl_surface * surface,
diff --git a/wayland-shm.c b/wayland-shm.c
@@ -37,7 +37,6 @@
struct wld_shm_context
{
struct wl_registry * registry;
- struct wl_event_queue * queue;
struct wl_shm * wl;
struct wl_array formats;
@@ -78,7 +77,8 @@ static inline uint32_t wayland_format(enum wld_format format)
}
}
-struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
+struct wld_shm_context * wld_shm_create_context(struct wl_display * display,
+ struct wl_event_queue * queue)
{
struct wld_shm_context * shm;
@@ -90,15 +90,14 @@ struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
shm->wl = NULL;
wl_array_init(&shm->formats);
- shm->queue = wl_display_create_queue(display);
shm->registry = wl_display_get_registry(display);
wl_registry_add_listener(shm->registry, ®istry_listener, shm);
- wl_proxy_set_queue((struct wl_proxy *) shm->registry, shm->queue);
+ wl_proxy_set_queue((struct wl_proxy *) shm->registry, queue);
shm->pixman_context = wld_pixman_create_context();
/* Wait for wl_shm global. */
- wayland_roundtrip(display, shm->queue);
+ wayland_roundtrip(display, queue);
if (!shm->wl)
{
@@ -109,13 +108,12 @@ struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
wl_shm_add_listener(shm->wl, &shm_listener, shm);
/* Wait for SHM formats. */
- wayland_roundtrip(display, shm->queue);
+ wayland_roundtrip(display, queue);
return shm;
error2:
wl_registry_destroy(shm->registry);
- wl_event_queue_destroy(shm->queue);
error1:
wl_array_release(&shm->formats);
free(shm);
@@ -128,7 +126,6 @@ void wld_shm_destroy_context(struct wld_shm_context * shm)
wld_pixman_destroy_context(shm->pixman_context);
wl_shm_destroy(shm->wl);
wl_registry_destroy(shm->registry);
- wl_event_queue_destroy(shm->queue);
wl_array_release(&shm->formats);
free(shm);
@@ -206,10 +203,7 @@ void registry_global(void * data, struct wl_registry * registry, uint32_t name,
struct wld_shm_context * shm = data;
if (strcmp(interface, "wl_shm") == 0)
- {
shm->wl = wl_registry_bind(registry, name, &wl_shm_interface, 1);
- wl_proxy_set_queue((struct wl_proxy *) shm->wl, shm->queue);
- }
}
void shm_format(void * data, struct wl_shm * wl, uint32_t format)
diff --git a/wayland-shm.h b/wayland-shm.h
@@ -32,13 +32,15 @@ struct wld_drawable;
enum wld_format;
struct wl_display;
+struct wl_event_queue;
struct wl_surface;
/**
* Create a new drawable context which creates Wayland buffers through the
* wl_shm interface, back by Pixman drawables.
*/
-struct wld_shm_context * wld_shm_create_context(struct wl_display * display);
+struct wld_shm_context * wld_shm_create_context(struct wl_display * display,
+ struct wl_event_queue * queue);
/**
* Destroy an SHM context.
diff --git a/wayland.c b/wayland.c
@@ -33,6 +33,7 @@
struct wld_wayland_context
{
+ struct wl_event_queue * queue;
const struct wld_wayland_interface * interface;
void * context;
};
@@ -100,6 +101,7 @@ struct wld_wayland_context * wld_wayland_create_context
if (!wayland)
goto error0;
+ wayland->queue = wl_display_create_queue(display);
wayland->context = NULL;
wayland->interface = NULL;
@@ -110,7 +112,10 @@ struct wld_wayland_context * wld_wayland_create_context
if (interfaces_tried[id] || !interfaces[id])
continue;
- if ((wayland->context = interfaces[id]->create_context(display)))
+ wayland->context
+ = interfaces[id]->create_context(display, wayland->queue);
+
+ if (wayland->context)
{
wayland->interface = interfaces[id];
break;
@@ -130,7 +135,10 @@ struct wld_wayland_context * wld_wayland_create_context
if (interfaces_tried[id] || !interfaces[id])
continue;
- if ((wayland->context = interfaces[id]->create_context(display)))
+ wayland->context
+ = interfaces[id]->create_context(display, wayland->queue);
+
+ if (wayland->context)
{
wayland->interface = interfaces[id];
break;
@@ -140,12 +148,14 @@ struct wld_wayland_context * wld_wayland_create_context
if (!wayland->context)
{
- DEBUG("Could not initialize any of the specified interfaces");
- goto error1;
+ DEBUG("Could not initialize any of the specified interfaces\n");
+ goto error2;
}
return wayland;
+ error2:
+ wl_event_queue_destroy(wayland->queue);
error1:
free(wayland);
error0: