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).
This commit is contained in:
Rafael Antognolli 2013-04-05 16:31:43 -03:00
parent f5b01e32ac
commit e38c985cd0
2 changed files with 30 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}