From: Sangjin Lee Date: Thu, 20 Apr 2017 05:30:37 +0000 (+0900) Subject: tpl_wayland_egl_thread: Add tdm to thread X-Git-Tag: accepted/tizen/unified/20170711.180707~70 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b96e48621802249a7a904da2b0679375d63e7b82;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git tpl_wayland_egl_thread: Add tdm to thread Change-Id: I1aac64996989ee528f5ef23eb9c2a87dcd8d3e06 --- diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 94d8d3d..86f5232 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -4,10 +4,14 @@ #include #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; @@ -16,6 +20,11 @@ struct _twe_thread_context { GThread *twe_thread; GMainLoop *twe_loop; + + /*TDM*/ + tdm_client *tdm_client; + int tdm_fd; + GSource *tdm_gsource; }; struct _twe_thread { @@ -50,6 +59,34 @@ _twe_thread_loop(gpointer data) return ctx; } +static gboolean +_twe_thread_tdm_source_dispatch(gpointer user_data) +{ + twe_thread_context* context = user_data; + tdm_error tdm_err; + + tdm_err = tdm_client_handle_events(context->tdm_client); + if (tdm_err) { + TPL_ERR("TDM_ERROR:%d context:%p, tdm_cleint:%p\n", context, context->tdm_client); + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +static void +_twe_thread_tdm_source_destroy(gpointer user_data) +{ + twe_thread_context* context = user_data; + + g_source_destroy(context->tdm_gsource); + g_source_unref(context->tdm_gsource); + context->tdm_gsource = NULL; + + tdm_client_destroy(context->tdm_client); + context->tdm_client = NULL; +} + twe_thread* twe_thread_create(void) { @@ -57,6 +94,7 @@ twe_thread_create(void) if (!_twe_ctx) { GMainContext *context; + tdm_error tdm_err = TDM_ERROR_NONE; _twe_ctx = calloc(1, sizeof(twe_thread_context)); context = g_main_context_new(); @@ -64,6 +102,28 @@ twe_thread_create(void) g_main_context_unref(context); _twe_ctx->twe_thread = g_thread_new("twe_thread", _twe_thread_loop, _twe_ctx); + + /*Connect to tdm server*/ + _twe_ctx->tdm_client = tdm_client_create(&tdm_err); + if (!_twe_ctx->tdm_client) { + TPL_ERR("Failed to create tdm_client\n"); + } + + _twe_ctx->tdm_fd = tdm_client_get_fd(_twe_ctx->tdm_client, &_twe_ctx->tdm_fd); + if (_twe_ctx->tdm_fd < 0) { + TPL_ERR("Failed to get tdm_client fd\n"); + } else { + _twe_ctx->tdm_gsource = g_unix_fd_source_new(_twe_ctx->tdm_fd, G_IO_IN); + if (!_twe_ctx->tdm_gsource) { + TPL_ERR("Failed to create tdm_gsource\n"); + } + + g_source_set_callback(_twe_ctx->tdm_gsource, + _twe_thread_tdm_source_dispatch, + _twe_ctx, + _twe_thread_tdm_source_destroy); + g_source_attach(_twe_ctx->tdm_gsource, g_main_loop_get_context(_twe_ctx->twe_loop)); + } } thread = calloc(1, sizeof(twe_thread)); @@ -79,11 +139,16 @@ twe_thread_destroy(twe_thread* thread) thread->ctx->ref_cnt--; if (thread->ctx->ref_cnt == 0) { + if (thread->ctx->tdm_gsource) { + _twe_thread_tdm_source_destroy(thread->ctx); + } + g_main_loop_quit(thread->ctx->twe_loop); g_thread_join(thread->ctx->twe_thread); g_main_loop_unref(thread->ctx->twe_loop); free(thread->ctx); + thread->ctx = NULL; } thread->ctx = NULL;