mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-03 09:01:42 -05:00
client: Add wl_event_queue for multi-thread dispatching
This introduces wl_event_queue, which is what will make multi-threaded wayland clients possible and useful. The driving use case is that of a GL rendering thread that renders and calls eglSwapBuffer independently of a "main thread" that owns the wl_display and handles input events and everything else. In general, the EGL and GL APIs have a threading model that requires the wayland client library to be usable from several threads. Finally, the current callback model gets into trouble even in a single threaded scenario: if we have to block in eglSwapBuffers, we may end up doing unrelated callbacks from within EGL. The wl_event_queue mechanism lets the application (or middleware such as EGL or toolkits) assign a proxy to an event queue. Only events from objects associated with the queue will be put in the queue, and conversely, events from objects associated with the queue will not be queue up anywhere else. The wl_display struct has a built-in event queue, which is considered the main and default event queue. New proxies are associated with the same queue as the object that created them (either the object that a request with a new-id argument was sent to or the object that sent an event with a new-id argument). A proxy can be moved to a different event queue by calling wl_proxy_set_queue(). A subsystem, such as EGL, will then create its own event queue and associate the objects it expects to receive events from with that queue. If EGL needs to block and wait for a certain event, it can keep dispatching event from its queue until that events comes in. This wont call out to unrelated code with an EGL lock held. Similarly, we don't risk the main thread handling an event from an EGL object and then calling into EGL from a different thread without the lock held.
This commit is contained in:
parent
de961dc1f3
commit
385fe30e8b
2 changed files with 123 additions and 35 deletions
|
|
@ -32,6 +32,9 @@ extern "C" {
|
|||
|
||||
struct wl_proxy;
|
||||
struct wl_display;
|
||||
struct wl_event_queue;
|
||||
|
||||
void wl_event_queue_destroy(struct wl_event_queue *queue);
|
||||
|
||||
void wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
|
||||
struct wl_proxy *wl_proxy_create(struct wl_proxy *factory,
|
||||
|
|
@ -46,6 +49,7 @@ int wl_proxy_add_listener(struct wl_proxy *proxy,
|
|||
void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
|
||||
void *wl_proxy_get_user_data(struct wl_proxy *proxy);
|
||||
uint32_t wl_proxy_get_id(struct wl_proxy *proxy);
|
||||
void wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue);
|
||||
|
||||
void *wl_display_bind(struct wl_display *display,
|
||||
uint32_t name, const struct wl_interface *interface);
|
||||
|
|
@ -74,8 +78,12 @@ struct wl_display *wl_display_connect_to_fd(int fd);
|
|||
void wl_display_disconnect(struct wl_display *display);
|
||||
int wl_display_get_fd(struct wl_display *display);
|
||||
int wl_display_dispatch(struct wl_display *display);
|
||||
int wl_display_dispatch_queue(struct wl_display *display,
|
||||
struct wl_event_queue *queue);
|
||||
|
||||
int wl_display_flush(struct wl_display *display);
|
||||
void wl_display_roundtrip(struct wl_display *display);
|
||||
struct wl_event_queue *wl_display_create_queue(struct wl_display *display);
|
||||
|
||||
struct wl_global_listener;
|
||||
typedef void (*wl_display_global_func_t)(struct wl_display *display,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue