#include <stdlib.h>
#include <wayland-client.h>
#include <wayland-tbm-client.h>
+#include <tdm_client.h>
+#include <glib-unix.h>
+
#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;
GThread *twe_thread;
GMainLoop *twe_loop;
+
+ /*TDM*/
+ tdm_client *tdm_client;
+ int tdm_fd;
+ GSource *tdm_gsource;
};
struct _twe_thread {
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)
{
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();
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));
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;