From c4c46519cabddd39243c6792d7a5d3de505f5bd3 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Wed, 19 Apr 2017 19:00:46 +0900 Subject: [PATCH] tpl_wayland_egl_thread: Added init/deinit routine for wayland_tbm_client. Change-Id: Ic1b5c3341bd36b26e86acd81f9d03345db9d85ff Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 63 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index e2d5e04..94d8d3d 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -3,8 +3,10 @@ #include #include #include +#include #include "wayland-egl/wayland-egl-priv.h" #include "tpl_wayland_egl_thread.h" +#include "tpl_utils.h" typedef struct _twe_wl_disp_source twe_wl_disp_source; typedef struct _twe_wl_surf_source twe_wl_surf_source; @@ -18,6 +20,7 @@ struct _twe_thread_context { struct _twe_thread { twe_thread_context *ctx; + struct wayland_tbm_client *wl_tbm_client; }; struct _twe_wl_disp_source { @@ -148,17 +151,72 @@ static GSourceFuncs _twe_wl_disp_funcs = { .finalize = _twe_thread_wl_disp_finalize, }; +static struct wayland_tbm_client* +_twe_thread_init_wl_tbm_client(struct wl_display *display, + struct wl_event_queue *ev_queue) +{ + struct wl_proxy *wl_tbm = NULL; + struct wayland_tbm_client *wl_tbm_client = NULL; + + wl_tbm_client = wayland_tbm_client_init(display); + if (!wl_tbm_client) { + TPL_ERR("Failed to initialize wl_tbm_client."); + return NULL; + } + + wl_tbm = (struct wl_proxy *)wayland_tbm_client_get_wl_tbm(wl_tbm_client); + if (!wl_tbm) { + TPL_ERR("Failed to get wl_tbm from wl_tbm_client(%p)", wl_tbm_client); + wayland_tbm_client_deinit(wl_tbm_client); + return NULL; + } + + wl_proxy_set_queue(wl_tbm, ev_queue); + + return wl_tbm_client; +} + +static void +_twe_thread_fini_wl_tbm_client(struct wayland_tbm_client *wl_tbm_client) +{ + struct wl_proxy *wl_tbm = NULL; + + wl_tbm = (struct wl_proxy *)wayland_tbm_client_get_wl_tbm(wl_tbm_client); + if (wl_tbm) { + wl_proxy_set_queue(wl_tbm, NULL); + } + + wayland_tbm_client_deinit(wl_tbm_client); +} + + void twe_thread_add_wl_display(twe_thread* thread, struct wl_display *display) { twe_thread_context *ctx = thread->ctx; twe_wl_disp_source *source; + struct wayland_tbm_client *wl_tbm_client = NULL; + struct wl_event_queue *ev_queue = NULL; + + ev_queue = wl_display_create_queue(display); + if (!ev_queue) { + TPL_ERR("Failed to create wl_event_queue."); + return; + } + + wl_tbm_client = _twe_thread_init_wl_tbm_client(display, ev_queue); + if (!wl_tbm_client) { + TPL_ERR("Failed to create wl_tbm_client."); + return; + } + + thread->wl_tbm_client = wl_tbm_client; source = (twe_wl_disp_source *)g_source_new(&_twe_wl_disp_funcs, sizeof(twe_wl_disp_source)); source->disp = display; - source->ev_queue = wl_display_create_queue(display); + source->ev_queue = ev_queue; source->gfd.fd = wl_display_get_fd(display); source->gfd.events = G_IO_IN | G_IO_ERR; source->gfd.revents = 0; @@ -181,6 +239,9 @@ twe_thread_del_wl_display(twe_thread* thread, struct wl_display *display) return; } + _twe_thread_fini_wl_tbm_client(thread->wl_tbm_client); + thread->wl_tbm_client = NULL; + g_source_remove_poll(&source->gsource, &source->gfd); g_source_destroy(&source->gsource); g_source_unref(&source->gsource); -- 2.7.4