tpl_wayland_egl_thread: Simplified APIs and modify design between the data structures. 17/134817/5
authorjoonbum.ko <joonbum.ko@samsung.com>
Fri, 21 Apr 2017 07:32:42 +0000 (16:32 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 21 Jun 2017 07:04:25 +0000 (16:04 +0900)
 - Added handle for sources.
  twe_display_h, twe_surface_h

Change-Id: I1d8e806aed89f33c24dc627128109f733a589872
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c
src/tpl_wayland_egl_thread.h

index 88f4922..37ec5b2 100644 (file)
        ((int)getpid() == (int)syscall(SYS_gettid)) ? tpl_log_d("[MAIN]", f, ##x) : tpl_log_t("[THREAD]", f, ##x)
 typedef struct _twe_thread                     twe_thread;
 typedef struct _twe_thread_context     twe_thread_context;
+typedef void*  twe_display_h;
+typedef void*  twe_surface_h;
+
+typedef enum {
+       TPL_ERROR_NONE = 0, /* Successfull */
+       TPL_ERROR_INVALID_PARAMETER, /* Invalid parmeter */
+       TPL_ERROR_INVALID_OPERATION, /* Invalid operation */
+       TPL_ERROR_OUT_OF_MEMORY /* Out of memory */
+} tpl_result_t;
+
 #else
 #include "wayland-egl/wayland-egl-priv.h"
 #include "tpl_wayland_egl_thread.h"
@@ -58,7 +68,7 @@ struct _twe_thread_context {
 
 struct _twe_thread {
        twe_thread_context *ctx;
-       struct wayland_tbm_client *wl_tbm_client;
+       /* TODO : display list */
 };
 
 struct _twe_wl_disp_source {
@@ -66,6 +76,9 @@ struct _twe_wl_disp_source {
        GPollFD gfd;
        struct wl_display *disp;
        struct wl_event_queue *ev_queue;
+       struct wayland_tbm_client *wl_tbm_client;
+       twe_thread *thread;
+       /* TODO : surface list */
 };
 
 struct _twe_wl_surf_source {
@@ -74,6 +87,7 @@ struct _twe_wl_surf_source {
        int event_fd;
        struct wl_surface *surf;
        tbm_surface_queue_h tbm_surface_queue;
+       twe_wl_disp_source *disp_source;
 };
 
 static twe_thread_context *_twe_ctx;
@@ -304,7 +318,7 @@ _twe_thread_fini_wl_tbm_client(struct wayland_tbm_client *wl_tbm_client)
 }
 
 
-void
+twe_display_h
 twe_thread_add_wl_display(twe_thread* thread,
                                                  struct wl_display *display)
 {
@@ -316,21 +330,21 @@ twe_thread_add_wl_display(twe_thread* thread,
        ev_queue = wl_display_create_queue(display);
        if (!ev_queue) {
                TPL_ERR("Failed to create wl_event_queue.");
-               return;
+               return NULL;
        }
 
        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;
+               wl_event_queue_destroy(ev_queue);
+               return NULL;
        }
 
-       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 = ev_queue;
+       source->wl_tbm_client = wl_tbm_client;
        source->gfd.fd = wl_display_get_fd(display);
        source->gfd.events = G_IO_IN | G_IO_ERR;
        source->gfd.revents = 0;
@@ -342,28 +356,36 @@ twe_thread_add_wl_display(twe_thread* thread,
 
        TPL_DEBUG("add| gsource(%p) ev_queue(%p) wl_display(%p)",
                          source, source->ev_queue, display);
+
+       return (twe_display_h)source;
 }
 
-void
-twe_thread_del_wl_display(twe_thread* thread, struct wl_display *display)
+tpl_result_t
+twe_thread_del_wl_display(twe_display_h twe_display)
 {
-       twe_wl_disp_source *source;
-
-       source = (twe_wl_disp_source *)g_main_context_find_source_by_user_data(
-                       g_main_loop_get_context(thread->ctx->twe_loop), display);
-       if (!source) {
-               TPL_ERR("Failed to get source from context.");
-               return;
+       gboolean is_destroyed = FALSE;
+       twe_thread *thread = NULL;
+       twe_wl_disp_source *source = (twe_wl_disp_source *)twe_display;
+       if (!source ||
+                       (is_destroyed = g_source_is_destroyed(&source->gsource))) {
+               TPL_ERR("twe_display(%p) is invalid. | is_destroyed(%s)",
+                               twe_display, (is_destroyed ? "TRUE" : "FALSE"));
+               return TPL_ERROR_INVALID_PARAMETER;
        }
 
-       _twe_thread_fini_wl_tbm_client(thread->wl_tbm_client);
-       thread->wl_tbm_client = NULL;
+       thread = source->thread;
+       /* TODO : disp_source will be removed from displays list in thread */
+
+       _twe_thread_fini_wl_tbm_client(source->wl_tbm_client);
+       source->wl_tbm_client = NULL;
 
        g_source_remove_poll(&source->gsource, &source->gfd);
        g_source_destroy(&source->gsource);
        g_source_unref(&source->gsource);
 
-       TPL_DEBUG("del| gsource(%p) wl_display(%p)", source, display);
+       TPL_DEBUG("del| twe_display(%p) wl_display(%p)", source, source->disp);
+
+       return TPL_ERROR_NONE;
 }
 
 static gboolean
@@ -411,33 +433,54 @@ static GSourceFuncs _twe_wl_surface_funcs = {
        .finalize = _twe_thread_wl_surface_finalize,
 };
 
-int
+tbm_surface_queue_h
+twe_thread_get_tbm_queue(twe_surface_h twe_surface)
+{
+       /* TODO */
+       return NULL;
+}
+
+
+twe_surface_h
 twe_thread_add_wl_surface(twe_thread* thread,
+                                                 twe_display_h twe_display,
                                                  struct wl_surface *surface)
 {
        twe_thread_context *ctx = thread->ctx;
        twe_wl_surf_source *source = NULL;
+       twe_wl_disp_source *disp_source = (twe_wl_disp_source *)twe_display;
        GIOChannel *event_channel = NULL;
+       gboolean is_destroyed = FALSE;
+
+       if (!twe_display ||
+                       (is_destroyed = g_source_is_destroyed(&disp_source->gsource))) {
+               TPL_ERR("twe_display(%p) is invalid. | is_destroyed(%s)",
+                               twe_display, (is_destroyed ? "TRUE" : "FALSE"));
+               return NULL;
+       }
 
        source = (twe_wl_surf_source *)g_source_new(&_twe_wl_surface_funcs,
                                                                                                sizeof(twe_wl_surf_source));
        if (!source) {
                TPL_ERR("[THREAD] Failed to create GSource from event_channel(%p)",
                                event_channel);
-               return -1;
+               return NULL;
        }
 
        source->event_fd = eventfd(0, EFD_CLOEXEC);
        if (source->event_fd < 0) {
                TPL_ERR("[THREAD] Failed to create eventfd. errno(%d)", errno);
                g_source_unref(&source->gsource);
-               return -1;
+               return NULL;
        }
 
+    /* TODO : surface source will be listed in twe_wl_disp_source */
+
        source->tag = g_source_add_unix_fd(&source->gsource,
                                                                           source->event_fd,
                                                                           G_IO_IN);
        source->surf = surface;
+       source->disp_source = (twe_wl_disp_source *)twe_display;
 
        g_source_set_callback(&source->gsource, NULL, surface, NULL);
        g_source_attach(&source->gsource, g_main_loop_get_context(ctx->twe_loop));
@@ -445,27 +488,40 @@ twe_thread_add_wl_surface(twe_thread* thread,
 
        TPL_DEBUG("gsource(%p) wl_surface(%p) event_fd(%d)",
                          source, surface, source->event_fd);
-       return source->event_fd;
+
+       return (twe_surface_h)source;
 }
 
-void
-twe_thread_del_wl_surface(twe_thread* thread, struct wl_surface *surface)
+tpl_result_t
+twe_thread_del_wl_surface(twe_surface_h twe_surface)
 {
-       twe_thread_context *ctx = thread->ctx;
-       twe_wl_surf_source *source = NULL;
+       twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface;
+       twe_wl_disp_source *disp_source = NULL;
+       gboolean is_destroyed = FALSE;
+
+       if (!surf_source ||
+                       (is_destroyed = g_source_is_destroyed(&surf_source->gsource))) {
+               TPL_ERR("twe_surface(%p) is invalid. | is_destroyed(%s)",
+                               twe_surface, (is_destroyed ? "TRUE" : "FALSE"));
+               return TPL_ERROR_INVALID_PARAMETER;
+       }
 
-       source = (twe_wl_surf_source *) g_main_context_find_source_by_user_data(
-                                       g_main_loop_get_context(ctx->twe_loop), surface);
-       if (!source) {
-               TPL_ERR("[THREAD] Failed to get source from context.");
-               return;
+       disp_source = surf_source->disp_source;
+       if (!disp_source ||
+                       (is_destroyed = g_source_is_destroyed(&disp_source->gsource))) {
+               TPL_ERR("twe_display(%p) is invalid. | is_destroyed(%s)",
+                               disp_source, (is_destroyed ? "TRUE" : "FALSE"));
+               return TPL_ERROR_INVALID_PARAMETER;
        }
 
-       g_source_destroy(&source->gsource);
-       g_source_unref(&source->gsource);
+       /* TODO : surf_source will be removed from surfaces list in disp_source */
+
+       g_source_destroy(&surf_source->gsource);
+       g_source_unref(&surf_source->gsource);
+
+       TPL_DEBUG("twe_surface(%p) wl_surface(%p)", surf_source, surf_source->surf);
 
-       TPL_DEBUG("gsource(%p) wl_surface(%p)",
-                         source, surface);
+       return TPL_ERROR_NONE;
 }
 
 #ifdef WORKER_TEST_ONLY
@@ -526,6 +582,7 @@ main(void)
        struct wl_event_queue *ev_queue;
        int count = 0;
        GSource *timeout;
+       twe_display_h twe_display = NULL;
 
        twe_thread *t_thread = NULL;
 
@@ -543,15 +600,15 @@ main(void)
        registry = wl_display_get_registry(display);
        wl_registry_add_listener(registry, &registry_listener, NULL);
 
-       twe_thread_add_wl_display(t_thread, display);
+       twe_display = twe_thread_add_wl_display(t_thread, display);
 
        while (1) {
                sleep(1);
                count++;
 
                if (count == 3) {
-                       TPL_DEBUG_M("#### PRE_DEL");
-                       twe_thread_del_wl_display(t_thread, display);
+                       TPL_DEBUG("#### PRE_DEL");
+                       twe_thread_del_wl_display(twe_display);
                        TPL_DEBUG("#### DEL");
                }
        }
index c5ab0c5..f07d10f 100644 (file)
@@ -6,25 +6,30 @@
 typedef struct _twe_thread                     twe_thread;
 typedef struct _twe_thread_context     twe_thread_context;
 
+typedef void*  twe_display_h;
+typedef void*  twe_surface_h;
+
 twe_thread*
 twe_thread_create(void);
 
 void
 twe_thread_destroy(twe_thread* thread);
 
-void
+twe_display_h
 twe_thread_add_wl_display(twe_thread* thread,
                                                  struct wl_display *display);
 
-void
-twe_thread_del_wl_display(twe_thread* thread,
-                                                 struct wl_display *display);
+tpl_result_t
+twe_thread_del_wl_display(twe_display_h display);
 
-int
+twe_surface_h
 twe_thread_add_wl_surface(twe_thread* thread,
+                                                 twe_display_h twe_display,
                                                  struct wl_surface *surface);
 
-void
-twe_thread_del_wl_surface(twe_thread* thread,
-                                                 struct wl_surface *surface);
+tpl_result_t
+twe_thread_del_wl_surface(twe_surface_h twe_surface);
+
+tbm_surface_queue_h
+twe_thread_get_tbm_queue(twe_surface_h twe_surface);