From e38c985cd0250814d2b222ce8ab9a599e81aeee4 Mon Sep 17 00:00:00 2001 From: Rafael Antognolli Date: Fri, 5 Apr 2013 16:31:43 -0300 Subject: [PATCH] ecore/wayland: Actually wait for the sync callback on ecore_wl_sync(). The wl_display_sync() request doesn't really wait for all the requests to be processed, but instead sends a request for the "done" event. Wayland relies on the fact that the requests are processed in order, so when the "done" event is received, it means that all the other requests requested prior to the respective "sync" have been processed already. This commit makes the ecore_wl_sync() call actually wait for its "done" event (thus blocking the ecore mainloop). --- src/lib/ecore_wayland/Ecore_Wayland.h | 1 + src/lib/ecore_wayland/ecore_wl.c | 30 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lib/ecore_wayland/Ecore_Wayland.h b/src/lib/ecore_wayland/Ecore_Wayland.h index 372c9840fc..42d836fcb2 100644 --- a/src/lib/ecore_wayland/Ecore_Wayland.h +++ b/src/lib/ecore_wayland/Ecore_Wayland.h @@ -102,6 +102,7 @@ struct _Ecore_Wl_Display int fd; unsigned int mask; unsigned int serial; + int sync_ref_count; Ecore_Fd_Handler *fd_hdl; Ecore_Idle_Enterer *idle_enterer; diff --git a/src/lib/ecore_wayland/ecore_wl.c b/src/lib/ecore_wayland/ecore_wl.c index 5ebe3fa2c6..97dfb6b9ee 100644 --- a/src/lib/ecore_wayland/ecore_wl.c +++ b/src/lib/ecore_wayland/ecore_wl.c @@ -12,6 +12,8 @@ static Eina_Bool _ecore_wl_cb_handle_data(void *data, Ecore_Fd_Handler *hdl); static void _ecore_wl_cb_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version EINA_UNUSED); static Eina_Bool _ecore_wl_xkb_init(Ecore_Wl_Display *ewd); static Eina_Bool _ecore_wl_xkb_shutdown(Ecore_Wl_Display *ewd); +static void _ecore_wl_sync_wait(Ecore_Wl_Display *ewd); +static void _ecore_wl_sync_callback(void *data, struct wl_callback *callback, uint32_t serial); /* local variables */ static int _ecore_wl_init_count = 0; @@ -21,6 +23,11 @@ static const struct wl_registry_listener _ecore_wl_registry_listener = NULL // handle_global_remove }; +static const struct wl_callback_listener _ecore_wl_sync_listener = +{ + _ecore_wl_sync_callback +}; + /* external variables */ int _ecore_wl_log_dom = -1; Ecore_Wl_Display *_ecore_wl_disp = NULL; @@ -176,7 +183,9 @@ ecore_wl_sync(void) { // LOGFN(__FILE__, __LINE__, __FUNCTION__); - wl_display_sync(_ecore_wl_disp->wl.display); + _ecore_wl_sync_wait(_ecore_wl_disp); + while (_ecore_wl_disp->sync_ref_count > 0) + wl_display_dispatch(_ecore_wl_disp->wl.display); } EAPI struct wl_shm * @@ -473,3 +482,22 @@ _ecore_wl_create_data_source(Ecore_Wl_Display *ewd) { return wl_data_device_manager_create_data_source(ewd->wl.data_device_manager); } + +static void +_ecore_wl_sync_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED) +{ + Ecore_Wl_Display *ewd = data; + + ewd->sync_ref_count--; + wl_callback_destroy(callback); +} + +static void +_ecore_wl_sync_wait(Ecore_Wl_Display *ewd) +{ + struct wl_callback *callback; + + ewd->sync_ref_count++; + callback = wl_display_sync(ewd->wl.display); + wl_callback_add_listener(callback, &_ecore_wl_sync_listener, ewd); +}