commit e3e448f
Michael Forney
·
2013-07-19 02:49:34 +0000 UTC
parent a61f447
Use a central queue
6 files changed,
+43,
-45
+16,
-27
1@@ -40,7 +40,6 @@ struct wld_drm_context
2 {
3 struct wl_drm * wl;
4 struct wl_registry * registry;
5- struct wl_event_queue * queue;
6 struct wl_array formats;
7 int fd;
8 bool authenticated;
9@@ -117,59 +116,55 @@ static const struct wld_drm_interface * find_drm_interface(int fd)
10 return NULL;
11 }
12
13-struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
14+struct wld_drm_context * wld_drm_create_context(struct wl_display * display,
15+ struct wl_event_queue * queue)
16 {
17 struct wld_drm_context * drm;
18
19 drm = malloc(sizeof *drm);
20
21 if (!drm)
22- return 0;
23+ goto error0;
24
25 drm->wl = NULL;
26 drm->fd = -1;
27 wl_array_init(&drm->formats);
28
29- drm->queue = wl_display_create_queue(display);
30-
31- if (!drm->queue)
32- goto error2;
33-
34 drm->registry = wl_display_get_registry(display);
35
36 if (!drm->registry)
37- goto error3;
38+ goto error1;
39
40 wl_registry_add_listener(drm->registry, ®istry_listener, drm);
41- wl_proxy_set_queue((struct wl_proxy *) drm->registry, drm->queue);
42+ wl_proxy_set_queue((struct wl_proxy *) drm->registry, queue);
43
44 /* Wait for wl_drm global. */
45- wayland_roundtrip(display, drm->queue);
46+ wayland_roundtrip(display, queue);
47
48 if (!drm->wl)
49 {
50 DEBUG("No wl_drm global\n");
51- goto error3;
52+ goto error2;
53 }
54
55 wl_drm_add_listener(drm->wl, &drm_listener, drm);
56
57 /* Wait for DRM device. */
58- wayland_roundtrip(display, drm->queue);
59+ wayland_roundtrip(display, queue);
60
61 if (drm->fd == -1)
62 {
63 DEBUG("No DRM device\n");
64- goto error4;
65+ goto error3;
66 }
67
68 /* Wait for DRM authentication. */
69- wayland_roundtrip(display, drm->queue);
70+ wayland_roundtrip(display, queue);
71
72 if (!drm->authenticated)
73 {
74 DEBUG("DRM authentication failed\n");
75- goto error5;
76+ goto error4;
77 }
78
79 drm->interface = find_drm_interface(drm->fd);
80@@ -177,7 +172,7 @@ struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
81 if (!drm->interface)
82 {
83 DEBUG("Couldn't find drawable implementation for DRM device\n");
84- goto error5;
85+ goto error4;
86 }
87
88 drm->context = drm->interface->create_context(drm->fd);
89@@ -185,19 +180,17 @@ struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
90 if (!drm->context)
91 {
92 DEBUG("Couldn't create context for DRM drawable implementation\n");
93- goto error5;
94+ goto error4;
95 }
96
97 return drm;
98
99- error5:
100- close(drm->fd);
101 error4:
102- wl_drm_destroy(drm->wl);
103+ close(drm->fd);
104 error3:
105- wl_registry_destroy(drm->registry);
106+ wl_drm_destroy(drm->wl);
107 error2:
108- wl_event_queue_destroy(drm->queue);
109+ wl_registry_destroy(drm->registry);
110 error1:
111 wl_array_release(&drm->formats);
112 free(drm);
113@@ -211,7 +204,6 @@ void wld_drm_destroy_context(struct wld_drm_context * drm)
114 close(drm->fd);
115 wl_drm_destroy(drm->wl);
116 wl_registry_destroy(drm->registry);
117- wl_event_queue_destroy(drm->queue);
118 wl_array_release(&drm->formats);
119
120 free(drm);
121@@ -271,10 +263,7 @@ void registry_global(void * data, struct wl_registry * registry, uint32_t name,
122 struct wld_drm_context * drm = data;
123
124 if (strcmp(interface, "wl_drm") == 0)
125- {
126 drm->wl = wl_registry_bind(registry, name, &wl_drm_interface, 1);
127- wl_proxy_set_queue((struct wl_proxy *) drm->wl, drm->queue);
128- }
129 }
130
131 void drm_device(void * data, struct wl_drm * wl, const char * name)
+3,
-1
1@@ -32,13 +32,15 @@ struct wld_drawable;
2 enum wld_format;
3
4 struct wl_display;
5+struct wl_event_queue;
6 struct wl_surface;
7
8 /**
9 * Create a new drawable context which creates Wayland buffers through the
10 * wl_drm interface, backed by hardware specific drawable implementations.
11 */
12-struct wld_drm_context * wld_drm_create_context(struct wl_display * display);
13+struct wld_drm_context * wld_drm_create_context(struct wl_display * display,
14+ struct wl_event_queue * queue);
15
16 /**
17 * Destroy a DRM context.
+2,
-1
1@@ -32,7 +32,8 @@ enum wld_format format;
2 struct wl_display;
3 struct wl_event_queue;
4
5-typedef void * (* wayland_create_context_func_t)(struct wl_display * display);
6+typedef void * (* wayland_create_context_func_t)(struct wl_display * display,
7+ struct wl_event_queue * queue);
8 typedef void (* wayland_destroy_context_func_t)(void * context);
9 typedef struct wld_drawable * (* wayland_create_drawable_func_t)
10 (void * context, struct wl_surface * surface,
+5,
-11
1@@ -37,7 +37,6 @@
2 struct wld_shm_context
3 {
4 struct wl_registry * registry;
5- struct wl_event_queue * queue;
6 struct wl_shm * wl;
7 struct wl_array formats;
8
9@@ -78,7 +77,8 @@ static inline uint32_t wayland_format(enum wld_format format)
10 }
11 }
12
13-struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
14+struct wld_shm_context * wld_shm_create_context(struct wl_display * display,
15+ struct wl_event_queue * queue)
16 {
17 struct wld_shm_context * shm;
18
19@@ -90,15 +90,14 @@ struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
20 shm->wl = NULL;
21 wl_array_init(&shm->formats);
22
23- shm->queue = wl_display_create_queue(display);
24 shm->registry = wl_display_get_registry(display);
25 wl_registry_add_listener(shm->registry, ®istry_listener, shm);
26- wl_proxy_set_queue((struct wl_proxy *) shm->registry, shm->queue);
27+ wl_proxy_set_queue((struct wl_proxy *) shm->registry, queue);
28
29 shm->pixman_context = wld_pixman_create_context();
30
31 /* Wait for wl_shm global. */
32- wayland_roundtrip(display, shm->queue);
33+ wayland_roundtrip(display, queue);
34
35 if (!shm->wl)
36 {
37@@ -109,13 +108,12 @@ struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
38 wl_shm_add_listener(shm->wl, &shm_listener, shm);
39
40 /* Wait for SHM formats. */
41- wayland_roundtrip(display, shm->queue);
42+ wayland_roundtrip(display, queue);
43
44 return shm;
45
46 error2:
47 wl_registry_destroy(shm->registry);
48- wl_event_queue_destroy(shm->queue);
49 error1:
50 wl_array_release(&shm->formats);
51 free(shm);
52@@ -128,7 +126,6 @@ void wld_shm_destroy_context(struct wld_shm_context * shm)
53 wld_pixman_destroy_context(shm->pixman_context);
54 wl_shm_destroy(shm->wl);
55 wl_registry_destroy(shm->registry);
56- wl_event_queue_destroy(shm->queue);
57 wl_array_release(&shm->formats);
58
59 free(shm);
60@@ -206,10 +203,7 @@ void registry_global(void * data, struct wl_registry * registry, uint32_t name,
61 struct wld_shm_context * shm = data;
62
63 if (strcmp(interface, "wl_shm") == 0)
64- {
65 shm->wl = wl_registry_bind(registry, name, &wl_shm_interface, 1);
66- wl_proxy_set_queue((struct wl_proxy *) shm->wl, shm->queue);
67- }
68 }
69
70 void shm_format(void * data, struct wl_shm * wl, uint32_t format)
+3,
-1
1@@ -32,13 +32,15 @@ struct wld_drawable;
2 enum wld_format;
3
4 struct wl_display;
5+struct wl_event_queue;
6 struct wl_surface;
7
8 /**
9 * Create a new drawable context which creates Wayland buffers through the
10 * wl_shm interface, back by Pixman drawables.
11 */
12-struct wld_shm_context * wld_shm_create_context(struct wl_display * display);
13+struct wld_shm_context * wld_shm_create_context(struct wl_display * display,
14+ struct wl_event_queue * queue);
15
16 /**
17 * Destroy an SHM context.
+14,
-4
1@@ -33,6 +33,7 @@
2
3 struct wld_wayland_context
4 {
5+ struct wl_event_queue * queue;
6 const struct wld_wayland_interface * interface;
7 void * context;
8 };
9@@ -100,6 +101,7 @@ struct wld_wayland_context * wld_wayland_create_context
10 if (!wayland)
11 goto error0;
12
13+ wayland->queue = wl_display_create_queue(display);
14 wayland->context = NULL;
15 wayland->interface = NULL;
16
17@@ -110,7 +112,10 @@ struct wld_wayland_context * wld_wayland_create_context
18 if (interfaces_tried[id] || !interfaces[id])
19 continue;
20
21- if ((wayland->context = interfaces[id]->create_context(display)))
22+ wayland->context
23+ = interfaces[id]->create_context(display, wayland->queue);
24+
25+ if (wayland->context)
26 {
27 wayland->interface = interfaces[id];
28 break;
29@@ -130,7 +135,10 @@ struct wld_wayland_context * wld_wayland_create_context
30 if (interfaces_tried[id] || !interfaces[id])
31 continue;
32
33- if ((wayland->context = interfaces[id]->create_context(display)))
34+ wayland->context
35+ = interfaces[id]->create_context(display, wayland->queue);
36+
37+ if (wayland->context)
38 {
39 wayland->interface = interfaces[id];
40 break;
41@@ -140,12 +148,14 @@ struct wld_wayland_context * wld_wayland_create_context
42
43 if (!wayland->context)
44 {
45- DEBUG("Could not initialize any of the specified interfaces");
46- goto error1;
47+ DEBUG("Could not initialize any of the specified interfaces\n");
48+ goto error2;
49 }
50
51 return wayland;
52
53+ error2:
54+ wl_event_queue_destroy(wayland->queue);
55 error1:
56 free(wayland);
57 error0: