ecore/wayland: Use sync callback to report end of ecore_wl_init().

At the end of the ecore_wl_init() function, send a sync request to the
server, and add a callback listener to the "done" event. When this event
is received, we are sure that all the registry bind requests done so
far were processed already, and that the registry and globals are
available and can be used.

Now, on the functions that request interfaces or registry, we call
_ecore_wl_init_wait(), which will check if the callback was received
already (that means that all requests inside the init were processed).
If it was not yet, then we wait until receiving that callback, before
returning the requested data.
This commit is contained in:
Rafael Antognolli 2013-10-28 14:07:25 -02:00
parent 3aca95bb22
commit ccdeae7ce4
4 changed files with 45 additions and 6 deletions

View File

@ -120,6 +120,8 @@ struct _Ecore_Wl_Display
struct wl_list outputs; struct wl_list outputs;
struct wl_list globals; /** @since 1.7.6 */ struct wl_list globals; /** @since 1.7.6 */
Eina_Bool init_done;
struct struct
{ {
struct xkb_context *context; struct xkb_context *context;
@ -558,6 +560,15 @@ EAPI struct wl_list *ecore_wl_outputs_get(void);
/** /**
* Retrieves the Wayland Globals Interface list used for the current Wayland connection. * Retrieves the Wayland Globals Interface list used for the current Wayland connection.
* *
* This call, if done after the ECORE_WL_EVENT_INTERFACES_BOUND event was
* received already, won't block the mainloop or trigger a dispatch. It will
* return the current globals immediately. However, if done before this event,
* it will probably block the mainloop waiting for the sync "done" event to be
* received (by using one or more wl_display_dispatch call), and then finally
* return the wl globals list.
*
* There's no need to call dispatch manually, since this call will do it if necessary.
*
* @return The current wayland globals interface list * @return The current wayland globals interface list
* *
* @ingroup Ecore_Wl_Display_Group * @ingroup Ecore_Wl_Display_Group

View File

@ -22,6 +22,7 @@ static void _ecore_wl_animator_callback(void *data, struct wl_callback *callback
static Eina_Bool _ecore_wl_animator_window_add(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED); static Eina_Bool _ecore_wl_animator_window_add(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED);
static void _ecore_wl_signal_exit(void); static void _ecore_wl_signal_exit(void);
static void _ecore_wl_signal_exit_free(void *data EINA_UNUSED, void *event); static void _ecore_wl_signal_exit_free(void *data EINA_UNUSED, void *event);
static void _ecore_wl_init_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED);
/* local variables */ /* local variables */
static int _ecore_wl_init_count = 0; static int _ecore_wl_init_count = 0;
@ -40,6 +41,11 @@ static const struct wl_callback_listener _ecore_wl_sync_listener =
_ecore_wl_sync_callback _ecore_wl_sync_callback
}; };
static const struct wl_callback_listener _ecore_wl_init_sync_listener =
{
_ecore_wl_init_callback
};
static const struct wl_callback_listener _ecore_wl_anim_listener = static const struct wl_callback_listener _ecore_wl_anim_listener =
{ {
_ecore_wl_animator_callback _ecore_wl_animator_callback
@ -66,9 +72,26 @@ EAPI int ECORE_WL_EVENT_SELECTION_DATA_READY = 0;
EAPI int ECORE_WL_EVENT_DATA_SOURCE_CANCELLED = 0; EAPI int ECORE_WL_EVENT_DATA_SOURCE_CANCELLED = 0;
EAPI int ECORE_WL_EVENT_INTERFACES_BOUND = 0; EAPI int ECORE_WL_EVENT_INTERFACES_BOUND = 0;
static void
_ecore_wl_init_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED)
{
Ecore_Wl_Display *ewd = data;
wl_callback_destroy(callback);
ewd->init_done = EINA_TRUE;
}
static void
_ecore_wl_init_wait(void)
{
while (!_ecore_wl_disp->init_done)
wl_display_dispatch(_ecore_wl_disp->wl.display);
}
EAPI int EAPI int
ecore_wl_init(const char *name) ecore_wl_init(const char *name)
{ {
struct wl_callback *callback;
LOGFN(__FILE__, __LINE__, __FUNCTION__); LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (++_ecore_wl_init_count != 1) return _ecore_wl_init_count; if (++_ecore_wl_init_count != 1) return _ecore_wl_init_count;
@ -181,6 +204,10 @@ ecore_wl_init(const char *name)
_ecore_wl_window_init(); _ecore_wl_window_init();
_ecore_wl_events_init(); _ecore_wl_events_init();
callback = wl_display_sync(_ecore_wl_disp->wl.display);
wl_callback_add_listener(callback, &_ecore_wl_init_sync_listener,
_ecore_wl_disp);
return _ecore_wl_init_count; return _ecore_wl_init_count;
} }
@ -212,6 +239,9 @@ EAPI struct wl_shm *
ecore_wl_shm_get(void) ecore_wl_shm_get(void)
{ {
if (!_ecore_wl_disp) return NULL; if (!_ecore_wl_disp) return NULL;
_ecore_wl_init_wait();
return _ecore_wl_disp->wl.shm; return _ecore_wl_disp->wl.shm;
} }
@ -228,6 +258,9 @@ ecore_wl_globals_get(void)
{ {
if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display)) if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display))
return NULL; return NULL;
_ecore_wl_init_wait();
return &(_ecore_wl_disp->globals); return &(_ecore_wl_disp->globals);
} }
@ -249,8 +282,7 @@ ecore_wl_screen_size_get(int *w, int *h)
if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display)) return; if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display)) return;
if (!_ecore_wl_disp->output) _ecore_wl_init_wait();
ecore_wl_sync();
if (!_ecore_wl_disp->output) return; if (!_ecore_wl_disp->output) return;

View File

@ -112,8 +112,6 @@ ecore_evas_wayland_egl_new_internal(const char *disp_name, unsigned int parent,
ERR("Failed to initialize Ecore_Wayland"); ERR("Failed to initialize Ecore_Wayland");
return NULL; return NULL;
} }
else if (count >= 1)
ecore_wl_display_iterate();
if (!(ee = calloc(1, sizeof(Ecore_Evas)))) if (!(ee = calloc(1, sizeof(Ecore_Evas))))
{ {

View File

@ -111,8 +111,6 @@ ecore_evas_wayland_shm_new_internal(const char *disp_name, unsigned int parent,
ERR("Failed to initialize Ecore_Wayland"); ERR("Failed to initialize Ecore_Wayland");
return NULL; return NULL;
} }
else if (count >= 1)
ecore_wl_display_iterate();
if (!(ee = calloc(1, sizeof(Ecore_Evas)))) if (!(ee = calloc(1, sizeof(Ecore_Evas))))
{ {