tpl_wayland_egl_thread: Added init/deinit routine for wayland_tbm_client. 61/134761/3
authorjoonbum.ko <joonbum.ko@samsung.com>
Wed, 19 Apr 2017 10:00:46 +0000 (19:00 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 21 Jun 2017 07:04:25 +0000 (16:04 +0900)
Change-Id: Ic1b5c3341bd36b26e86acd81f9d03345db9d85ff
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index e2d5e04..94d8d3d 100644 (file)
@@ -3,8 +3,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <wayland-client.h>
+#include <wayland-tbm-client.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;
@@ -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);