Implement display backend at tpl_wl_egl.c 67/254767/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Mon, 9 Nov 2020 05:20:05 +0000 (14:20 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 9 Mar 2021 08:44:31 +0000 (17:44 +0900)
Change-Id: I1a25d1d09eb7c3baf308e085d8dd690588f487f2
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wl_egl.c

index 7b41f7ee584813f18e612d41ff8459c166269561..99285b84766893d0121b56ed49f3e9d75408407b 100644 (file)
@@ -45,6 +45,9 @@ struct _tpl_wl_egl_display {
        struct wayland_tbm_client    *wl_tbm_client;
        int                           last_error; /* errno of the last wl_display error*/
 
+       tpl_bool_t                   wl_initialized;
+       tpl_bool_t                   tdm_initialized;
+
        tdm_client                   *tdm_client;
        tpl_gsource                  *tdm_source;
 
@@ -242,13 +245,15 @@ __thread_func_tdm_finalize(tpl_gsource *gsource)
 
        wl_egl_display = (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
 
-       TPL_LOG_T(BACKEND, "tdm_destroy| tdm_source(%p) tdm_client(%p)",
+       TPL_LOG_T("WL_EGL", "tdm_destroy| tdm_source(%p) tdm_client(%p)",
                          gsource, wl_egl_display->tdm_client);
 
        if (wl_egl_display->tdm_client) {
                tdm_client_destroy(wl_egl_display->tdm_client);
                wl_egl_display->tdm_client = NULL;
        }
+
+       wl_egl_display->tdm_initialized = TPL_FALSE;
 }
 
 static tpl_gsource_functions tdm_funcs = {
@@ -262,7 +267,7 @@ tpl_result_t
 _thread_tdm_init(tpl_wl_egl_display_t *wl_egl_display)
 {
        tpl_gsource      *tdm_source = NULL;
-       tdm_client       *client = NULL;
+       tdm_client       *tdm_client = NULL;
        int               tdm_display_fd = -1;
        tdm_error         tdm_err = TDM_ERROR_NONE;
 
@@ -271,33 +276,35 @@ _thread_tdm_init(tpl_wl_egl_display_t *wl_egl_display)
                return TPL_ERROR_INVALID_OPERATION;
        }
 
-       client = tdm_client_create(&tdm_err);
-       if (!client || tdm_err != TDM_ERROR_NONE) {
+       tdm_client = tdm_client_create(&tdm_err);
+       if (!tdm_client || tdm_err != TDM_ERROR_NONE) {
                TPL_ERR("TDM_ERROR:%d Failed to create tdm_client\n", tdm_err);
                return TPL_ERROR_INVALID_OPERATION;
        }
 
-       tdm_err = tdm_client_get_fd(client, &tdm_fd);
-       if (tdm_fd < 0 || tdm_err != TDM_ERROR_NONE) {
+       tdm_err = tdm_client_get_fd(tdm_client, &tdm_display_fd);
+       if (tdm_display_fd < 0 || tdm_err != TDM_ERROR_NONE) {
                TPL_ERR("TDM_ERROR:%d Failed to get tdm_client fd\n", tdm_err);
-               tdm_client_destroy(client);
+               tdm_client_destroy(tdm_client);
                return TPL_ERROR_INVALID_OPERATION;
        }
 
        tdm_source = tpl_gsource_create(wl_egl_display->thread,
-                                                                       (void *)wl_egl_display,
+                                                                       (void *)wl_egl_display, tdm_display_fd,
                                                                        &tdm_funcs, TPL_FALSE);
        if (!tdm_source) {
                TPL_ERR("Failed to create tdm_gsource\n");
-               tdm_client_destroy(client);
+               tdm_client_destroy(tdm_client);
                return TPL_ERROR_INVALID_OPERATION;
        }
 
-       wl_egl_display->tdm_client = client;
+       wl_egl_display->tdm_client = tdm_client;
        wl_egl_display->tdm_source = tdm_source;
 
-       TPL_LOG_T(BACKEND, "TPL_WAIT_VBLANK:DEFAULT_ENABLED");
-       TPL_LOG_T(BACKEND, "wl_egl_display(%p) tdm_source(%p) tdm_client(%p)",
+       wl_egl_display->tdm_initialized = TPL_TRUE;
+
+       TPL_LOG_T("WL_EGL", "TPL_WAIT_VBLANK:DEFAULT_ENABLED");
+       TPL_LOG_T("WL_EGL", "wl_egl_display(%p) tdm_source(%p) tdm_client(%p)",
                          wl_egl_display, tdm_source, client);
 
        return TPL_ERROR_NONE;
@@ -376,121 +383,22 @@ _wl_display_print_err(tpl_wl_egl_display_t *wl_egl_display,
        wl_egl_display->last_error = errno;
 }
 
-tpl_result_t
-_thread_wl_display_init(tpl_wl_egl_display_t *wl_egl_display)
-{
-       struct wl_registry *registry = NULL;
-       struct wl_event_queue *queue = NULL;
-       struct wl_display *display_wrapper = NULL;
-       int ret;
-       tpl_result_t result = TPL_ERROR_NONE;
-
-       queue = wl_display_create_queue(wl_egl_display->wl_display);
-       if (!queue) {
-               TPL_ERR("Failed to create wl_queue wl_display(%p)",
-                               wl_egl_display->wl_display);
-               result = TPL_ERROR_INVALID_OPERATION;
-               goto fini;
-       }
-
-       display_wrapper = wl_proxy_create_wrapper(wl_egl_display->wl_display);
-       if (!display_wrapper) {
-               TPL_ERR("Failed to create a proxy wrapper of wl_display(%p)",
-                               wl_egl_display->wl_display);
-               result = TPL_ERROR_INVALID_OPERATION;
-               goto fini;
-       }
-
-       wl_proxy_set_queue((struct wl_proxy *)display_wrapper, queue);
-
-       registry = wl_display_get_registry(display_wrapper);
-       if (!registry) {
-               TPL_ERR("Failed to create wl_registry");
-               result = TPL_ERROR_INVALID_OPERATION;
-               goto fini;
-       }
-
-       wl_proxy_wrapper_destroy(display_wrapper);
-       display_wrapper = NULL;
-
-       if (wl_registry_add_listener(registry, &registry_listener,
-                                                                wl_egl_display)) {
-               TPL_ERR("Failed to wl_registry_add_listener");
-               result = TPL_ERROR_INVALID_OPERATION;
-               goto fini;
-       }
-
-       ret = wl_display_roundtrip_queue(wl_egl_display->wl_display, queue);
-       if (ret == -1) {
-               _twe_display_print_err(wl_egl_display, "roundtrip_queue");
-               result = TPL_ERROR_INVALID_OPERATION;
-               goto fini;
-       }
-
-       /* set tizen_surface_shm's queue as client's private queue */
-       if (wl_egl_display->tss) {
-               wl_proxy_set_queue((struct wl_proxy *)wl_egl_display->tss,
-                                                  wl_egl_display->ev_queue);
-               TPL_LOG_T("WL_EGL", "tizen_surface_shm(%p) init.", wl_egl_display->tss);
-       }
-
-       if (wl_egl_display->presentation) {
-               wl_proxy_set_queue((struct wl_proxy *)wl_egl_display->presentation,
-                                                  wl_egl_display->ev_queue);
-               TPL_LOG_T("WL_EGL", "wp_presentation(%p) init.",
-                                 wl_egl_display->presentation);
-       }
-
-       if (wl_egl_display->explicit_sync) {
-               wl_proxy_set_queue((struct wl_proxy *)wl_egl_display->explicit_sync,
-                                                  wl_egl_display->ev_queue);
-               TPL_LOG_T("WL_EGL", "zwp_linux_explicit_synchronization_v1(%p) init.",
-                                 wl_egl_display->explicit_sync);
-       }
-
-fini:
-       if (display_wrapper)
-               wl_proxy_wrapper_destroy(display_wrapper);
-       if (registry)
-               wl_registry_destroy(registry);
-       if (queue)
-               wl_event_queue_destroy(queue);
-
-       return result;
-}
-
-static void*
-_thread_init(void *data)
-{
-       tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)data;
-
-       if (_thread_wl_display_init(wl_egl_display) != TPL_ERROR_NONE) {
-               TPL_ERR("Failed to initialize wl_egl_display(%p) with wl_display(%p)",
-                               wl_egl_display, wl_egl_display->wl_display);
-       }
-
-       if (_thread_tdm_init(wl_egl_display) != TPL_ERROR_NONE) {
-               TPL_WARN("Failed to initialize tdm-client. TPL_WAIT_VLANK:DISABLED");
-       }
-
-       return wl_egl_display;
-}
-
-static gboolean
+static tpl_bool_t
 __thread_func_disp_prepare(tpl_gsource *gsource)
 {
-       tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)gsource->data;
+       tpl_wl_egl_display_t *wl_egl_display =
+               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
 
        /* If this wl_egl_display is already prepared,
         * do nothing in this function. */
        if (wl_egl_display->prepared)
-               return FALSE;
+               return TPL_FALSE;
 
        /* If there is a last_error, there is no need to poll,
         * so skip directly to dispatch.
         * prepare -> dispatch */
        if (wl_egl_display->last_error)
-               return TRUE;
+               return TPL_TRUE;
 
        while (wl_display_prepare_read_queue(wl_egl_display->wl_display,
                                                                                 wl_egl_display->ev_queue) != 0) {
@@ -504,16 +412,17 @@ __thread_func_disp_prepare(tpl_gsource *gsource)
 
        wl_display_flush(wl_egl_display->wl_display);
 
-       return FALSE;
+       return TPL_FALSE;
 }
 
-static gboolean
-_twe_thread_wl_disp_check(GSource *source)
+static tpl_bool_t
+__thread_func_disp_check(tpl_gsource *gsource)
 {
-       twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source;
-       gboolean ret = FALSE;
+       tpl_wl_egl_display_t *wl_egl_display =
+               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+       tpl_bool_t ret = TPL_FALSE;
 
-       if (!disp_source->prepared)
+       if (!wl_egl_display->prepared)
                return ret;
 
        /* If prepared, but last_error is set,
@@ -521,55 +430,63 @@ _twe_thread_wl_disp_check(GSource *source)
         * That can lead to G_SOURCE_REMOVE by calling disp_prepare again
         * and skipping disp_check from prepare to disp_dispatch.
         * check -> prepare -> dispatch -> G_SOURCE_REMOVE */
-       if (disp_source->prepared && disp_source->last_error) {
-               wl_display_cancel_read(disp_source->disp);
+       if (wl_egl_display->prepared && wl_egl_display->last_error) {
+               wl_display_cancel_read(wl_egl_display->wl_display);
                return ret;
        }
 
-       if (disp_source->gfd.revents & G_IO_IN) {
-               if (wl_display_read_events(disp_source->disp) == -1)
-                       _wl_display_print_err(disp_source, "read_event.");
-               ret = TRUE;
+       if (tpl_gsource_check_io_condition(gsource)) {
+               if (wl_display_read_events(wl_egl_display->wl_display) == -1)
+                       _wl_display_print_err(wl_egl_display, "read_event");
+               ret = TPL_TRUE;
        } else {
-               wl_display_cancel_read(disp_source->disp);
-               ret = FALSE;
+               wl_display_cancel_read(wl_egl_display->wl_display);
+               ret = TPL_FALSE;
        }
 
-       disp_source->prepared = TPL_FALSE;
+       wl_egl_display->prepared = TPL_FALSE;
 
        return ret;
 }
 
-static gboolean
-_twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data)
+static tpl_bool_t
+__thread_func_disp_dispatch(tpl_gsource *gsource)
 {
-       twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source;
+       tpl_wl_egl_display_t *wl_egl_display =
+               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
 
-       /* If there is last_error, G_SOURCE_REMOVE should be returned
+       /* If there is last_error, SOURCE_REMOVE should be returned
         * to remove the gsource from the main loop.
-        * This is because disp_source is not valid since last_error was set.*/
-       if (disp_source->last_error) {
-               return G_SOURCE_REMOVE;
+        * This is because wl_egl_display is not valid since last_error was set.*/
+       if (wl_egl_display->last_error) {
+               return TPL_GSOURCE_REMOVE;
        }
 
-       g_mutex_lock(&disp_source->wl_event_mutex);
-       if (disp_source->gfd.revents & G_IO_IN) {
-               if (wl_display_dispatch_queue_pending(disp_source->disp,
-                                                                                         disp_source->ev_queue) == -1) {
-                       _wl_display_print_err(disp_source, "dispatch_queue_pending");
+       g_mutex_lock(&wl_egl_display->wl_event_mutex);
+       if (tpl_gsource_check_io_condition(gsource)) {
+               if (wl_display_dispatch_queue_pending(wl_egl_display->wl_display,
+                                                                                         wl_egl_display->ev_queue) == -1) {
+                       _wl_display_print_err(wl_egl_display, "dispatch_queue_pending");
                }
        }
 
-       wl_display_flush(disp_source->disp);
-       g_mutex_unlock(&disp_source->wl_event_mutex);
+       wl_display_flush(wl_egl_display->wl_display);
+       g_mutex_unlock(&wl_egl_display->wl_event_mutex);
 
-       return G_SOURCE_CONTINUE;
+       return TPL_GSOURCE_CONTINUE;
 }
 
 static void
-_twe_thread_wl_disp_finalize(GSource *source)
+__thread_func_disp_finalize(tpl_gsource *source)
 {
-       TPL_LOG_T(BACKEND, "finalize| disp_source(%p)", source);
+       tpl_wl_egl_display_t *wl_egl_display =
+               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+
+       if (wl_egl_display->wl_initialized)
+               _thread_wl_display_fini(wl_egl_display);
+
+       TPL_LOG_T("WL_EGL", "finalize| wl_egl_display(%p) tpl_gsource(%p)",
+                         wl_egl_display, source);
 
        return;
 }
@@ -581,6 +498,34 @@ static tpl_gsource_functions disp_funcs = {
        .finalize = __thread_func_disp_finalize,
 };
 
+static void*
+_thread_init(void *data)
+{
+       tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)data;
+
+       if (_thread_wl_display_init(wl_egl_display) != TPL_ERROR_NONE) {
+               TPL_ERR("Failed to initialize wl_egl_display(%p) with wl_display(%p)",
+                               wl_egl_display, wl_egl_display->wl_display);
+       }
+
+       if (_thread_tdm_init(wl_egl_display) != TPL_ERROR_NONE) {
+               TPL_WARN("Failed to initialize tdm-client. TPL_WAIT_VLANK:DISABLED");
+       }
+
+       return wl_egl_display;
+}
+
+static void
+_thread_fini(void *data)
+{
+       tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)data;
+
+       if (wl_egl_display->tdm_initialized)
+               tpl_gsource_destroy(wl_egl_display->tdm_source);
+       if (wl_egl_display->wl_initialized)
+               _thread_wl_display_fini(wl_egl_display);
+}
+
 static tpl_result_t
 __tpl_wl_egl_display_init(tpl_display_t *display)
 {
@@ -599,6 +544,12 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
                return TPL_ERROR_INVALID_PARAMETER;
        }
 
+       ev_queue = wl_display_create_queue(display->native_handle);
+       if (!ev_queue) {
+               TPL_ERR("Failed to create wl_event_queue.");
+               return TPL_ERROR_OUT_OF_MEMORY;
+       }
+
        wl_egl_display = (tpl_wl_egl_display_t *) calloc(1,
                                                  sizeof(tpl_wl_egl_display_t));
        if (!wl_egl_display) {
@@ -609,6 +560,10 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
        display->backend.data             = wl_egl_display;
        display->bufmgr_fd                = -1;
 
+       wl_egl_display->tdm_initialized   = TPL_FALSE;
+       wl_egl_display->wl_initialized    = TPL_FALSE;
+
+       wl_egl_display->ev_queue          = ev_queue;
        wl_egl_display->wl_display        = (struct wl_display *)display->native_handle;
        wl_egl_display->last_error        = 0;
        wl_egl_display->use_explicit_sync = TPL_FALSE;   // default disabled
@@ -625,6 +580,8 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
                wl_egl_display->use_wait_vblank = TPL_FALSE;
        }
 
+       tpl_gmutex_init(&wl_egl_display->wl_event_mutex);
+
        /* Create gthread */
        wl_egl_display->thread = tpl_gthread_create("wl_egl_thread",
                                                                                                _thread_init, (void *)wl_egl_display);
@@ -636,12 +593,11 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
        wl_egl_display->disp_source = tpl_gsource_create(wl_egl_display->thread,
                                                                                                         (void *)wl_egl_display,
                                                                                                         wl_display_get_fd(wl_egl_display->wl_display),
-                                                                                                        &
-                                                                                                        )
-       if (!wl_egl_display->twe_display) {
+                                                                                                        &disp_funcs, TPL_FALSE);
+       if (!wl_egl_display->disp_source) {
                TPL_ERR("Failed to add native_display(%p) to thread(%p)",
                                display->native_handle,
-                               wl_egl_display->wl_egl_thread);
+                               wl_egl_display->thread);
                goto free_display;
        }
 
@@ -661,7 +617,7 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
 
 free_display:
        if (wl_egl_display->thread)
-               tpl_gthread_destroy(wl_egl_display->thread);
+               tpl_gthread_destroy(wl_egl_display->thread, _thread_fini);
 
        wl_egl_display->thread = NULL;
        free(wl_egl_display);
@@ -679,41 +635,171 @@ __tpl_wl_egl_display_fini(tpl_display_t *display)
 
        wl_egl_display = (tpl_wl_egl_display_t *)display->backend.data;
        if (wl_egl_display) {
-
                TPL_LOG_T("WL_EGL",
                                  "[FINI] wl_egl_display(%p) tpl_gthread(%p) wl_display(%p)",
                                  wl_egl_display,
                                  wl_egl_display->thread,
                                  wl_egl_display->wl_display);
 
-               if (wl_egl_display->twe_display) {
-                       tpl_result_t ret = TPL_ERROR_NONE;
-                       ret = twe_display_del(wl_egl_display->twe_display);
-                       if (ret != TPL_ERROR_NONE)
-                               TPL_ERR("Failed to delete twe_display(%p) from twe_thread(%p)",
-                                               wl_egl_display->twe_display,
-                                               wl_egl_display->wl_egl_thread);
-                       wl_egl_display->twe_display = NULL;
+               if (wl_egl_display->gsource) {
+                       tpl_gsource_destroy(wl_egl_display->gsource);
+                       wl_egl_display->gsource = NULL;
                }
 
-               if (wl_egl_display->wl_egl_thread) {
-                       twe_thread_destroy(wl_egl_display->wl_egl_thread);
+               if (wl_egl_display->thread) {
+                       tpl_gthread_destroy(wl_egl_display->thread, NULL);
                        wl_egl_display->wl_egl_thread = NULL;
                }
 
+               tpl_gmutex_clear(&wl_egl_display->wl_event_mutex);
+
                free(wl_egl_display);
        }
 
        display->backend.data = NULL;
 }
 
+static tpl_result_t
+_thread_wl_display_init(tpl_wl_egl_display_t *wl_egl_display)
+{
+       struct wl_registry *registry = NULL;
+       struct wl_event_queue *queue = NULL;
+       struct wl_display *display_wrapper = NULL;
+       int ret;
+       tpl_result_t result = TPL_ERROR_NONE;
+
+       queue = wl_display_create_queue(wl_egl_display->wl_display);
+       if (!queue) {
+               TPL_ERR("Failed to create wl_queue wl_display(%p)",
+                               wl_egl_display->wl_display);
+               result = TPL_ERROR_INVALID_OPERATION;
+               goto fini;
+       }
+
+       wl_egl_display->ev_queue = wl_display_create_queue(wl_egl_display->wl_display);
+       if (wl_egl_display->ev_queue) {
+               TPL_ERR("Failed to create wl_queue wl_display(%p)",
+                               wl_egl_display->wl_display);
+               result = TPL_ERROR_INVALID_OPERATION;
+               goto fini;
+       }
+
+       display_wrapper = wl_proxy_create_wrapper(wl_egl_display->wl_display);
+       if (!display_wrapper) {
+               TPL_ERR("Failed to create a proxy wrapper of wl_display(%p)",
+                               wl_egl_display->wl_display);
+               result = TPL_ERROR_INVALID_OPERATION;
+               goto fini;
+       }
+
+       wl_proxy_set_queue((struct wl_proxy *)display_wrapper, queue);
+
+       registry = wl_display_get_registry(display_wrapper);
+       if (!registry) {
+               TPL_ERR("Failed to create wl_registry");
+               result = TPL_ERROR_INVALID_OPERATION;
+               goto fini;
+       }
+
+       wl_proxy_wrapper_destroy(display_wrapper);
+       display_wrapper = NULL;
+
+       if (wl_registry_add_listener(registry, &registry_listener,
+                                                                wl_egl_display)) {
+               TPL_ERR("Failed to wl_registry_add_listener");
+               result = TPL_ERROR_INVALID_OPERATION;
+               goto fini;
+       }
+
+       ret = wl_display_roundtrip_queue(wl_egl_display->wl_display, queue);
+       if (ret == -1) {
+               _twe_display_print_err(wl_egl_display, "roundtrip_queue");
+               result = TPL_ERROR_INVALID_OPERATION;
+               goto fini;
+       }
+
+       /* set tizen_surface_shm's queue as client's private queue */
+       if (wl_egl_display->tss) {
+               wl_proxy_set_queue((struct wl_proxy *)wl_egl_display->tss,
+                                                  wl_egl_display->ev_queue);
+               TPL_LOG_T("WL_EGL", "tizen_surface_shm(%p) init.", wl_egl_display->tss);
+       }
+
+       if (wl_egl_display->presentation) {
+               wl_proxy_set_queue((struct wl_proxy *)wl_egl_display->presentation,
+                                                  wl_egl_display->ev_queue);
+               TPL_LOG_T("WL_EGL", "wp_presentation(%p) init.",
+                                 wl_egl_display->presentation);
+       }
+
+       if (wl_egl_display->explicit_sync) {
+               wl_proxy_set_queue((struct wl_proxy *)wl_egl_display->explicit_sync,
+                                                  wl_egl_display->ev_queue);
+               TPL_LOG_T("WL_EGL", "zwp_linux_explicit_synchronization_v1(%p) init.",
+                                 wl_egl_display->explicit_sync);
+       }
+
+       wl_egl_display->wl_initialized = TPL_TRUE;
+
+fini:
+       if (display_wrapper)
+               wl_proxy_wrapper_destroy(display_wrapper);
+       if (registry)
+               wl_registry_destroy(registry);
+       if (queue)
+               wl_event_queue_destroy(queue);
+
+       return result;
+}
+
+static void
+_thread_wl_display_fini(tpl_wl_egl_display_t *wl_egl_display)
+{
+       /* If wl_egl_display is in prepared state, cancel it */
+       if (wl_egl_display->prepared) {
+               wl_display_cancel_read(wl_egl_display->wl_display);
+               wl_egl_display->prepared = TPL_FALSE;
+       }
+
+       if (wl_display_dispatch_queue_pending(wl_egl_display->wl_display,
+                                                                                 wl_egl_display->ev_queue) == -1) {
+               _wl_display_print_err(wl_egl_display, "dispatch_queue_pending");
+       }
+
+       if (wl_egl_display->tss) {
+               TPL_LOG_T("WL_EGL", "tizen_surface_shm(%p) fini.", wl_egl_display->tss);
+               tizen_surface_shm_destroy(wl_egl_display->tss);
+               wl_egl_display->tss = NULL;
+       }
+
+       if (wl_egl_display->presentation) {
+               TPL_LOG_T("WL_EGL", "wp_presentation(%p) fini.", wl_egl_display->presentation);
+               wp_presentation_destroy(wl_egl_display->presentation);
+               wl_egl_display->presentation = NULL;
+       }
+
+       if (wl_egl_display->explicit_sync) {
+               TPL_LOG_T("WL_EGL", "zwp_linux_explicit_synchronization_v1(%p) fini.",
+                                 wl_egl_display->explicit_sync);
+               zwp_linux_explicit_synchronization_v1_destroy(wl_egl_display->explicit_sync);
+               wl_egl_display->explicit_sync = NULL;
+       }
+
+       wl_event_queue_destroy(wl_egl_display->ev_queue);
+
+       wl_egl_display->wl_initialized = TPL_FALSE;
+
+       TPL_LOG_T("WL_EGL", "[FINI] wl_display(%p)",
+                         wl_egl_display->wl_display);
+}
+
 static tpl_result_t
 __tpl_wl_egl_display_query_config(tpl_display_t *display,
-                                                                          tpl_surface_type_t surface_type,
-                                                                          int red_size, int green_size,
-                                                                          int blue_size, int alpha_size,
-                                                                          int color_depth, int *native_visual_id,
-                                                                          tpl_bool_t *is_slow)
+                                                                 tpl_surface_type_t surface_type,
+                                                                 int red_size, int green_size,
+                                                                 int blue_size, int alpha_size,
+                                                                 int color_depth, int *native_visual_id,
+                                                                 tpl_bool_t *is_slow)
 {
        TPL_ASSERT(display);
 
@@ -738,7 +824,7 @@ __tpl_wl_egl_display_query_config(tpl_display_t *display,
 
 static tpl_result_t
 __tpl_wl_egl_display_filter_config(tpl_display_t *display, int *visual_id,
-                                                                               int alpha_size)
+                                                                  int alpha_size)
 {
        TPL_IGNORE(display);
        TPL_IGNORE(visual_id);
@@ -748,18 +834,34 @@ __tpl_wl_egl_display_filter_config(tpl_display_t *display, int *visual_id,
 
 static tpl_result_t
 __tpl_wl_egl_display_get_window_info(tpl_display_t *display,
-               tpl_handle_t window, int *width,
-               int *height, tbm_format *format,
-               int depth, int a_size)
+                                                                        tpl_handle_t window, int *width,
+                                                                        int *height, tbm_format *format,
+                                                                        int depth, int a_size)
 {
        tpl_result_t ret = TPL_ERROR_NONE;
+       struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)window;
 
        TPL_ASSERT(display);
        TPL_ASSERT(window);
 
-       if ((ret = twe_get_native_window_info(window, width, height, format, a_size))
-                       != TPL_ERROR_NONE) {
-               TPL_ERR("Failed to get size info of native_window(%p)", window);
+       if (!wl_egl_window) {
+               TPL_ERR("Invalid parameter. tpl_handle_t(%p)", window);
+               return TPL_ERROR_INVALID_PARAMETER;
+       }
+
+       if (width) *width = wl_egl_window->width;
+       if (height) *height = wl_egl_window->height;
+       if (format) {
+               struct tizen_private *tizen_private = _get_tizen_private(wl_egl_window);
+               if (tizen_private && tizen_private->data) {
+                       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+                       *format = wl_egl_surface->format;
+               } else {
+                       if (a_size == 8)
+                               *format = TBM_FORMAT_ARGB8888;
+                       else
+                               *format = TBM_FORMAT_XRGB8888;
+               }
        }
 
        return ret;
@@ -767,15 +869,21 @@ __tpl_wl_egl_display_get_window_info(tpl_display_t *display,
 
 static tpl_result_t
 __tpl_wl_egl_display_get_pixmap_info(tpl_display_t *display,
-               tpl_handle_t pixmap, int *width,
-               int *height, tbm_format *format)
+                                                                        tpl_handle_t pixmap, int *width,
+                                                                        int *height, tbm_format *format)
 {
        tbm_surface_h   tbm_surface = NULL;
 
-       tbm_surface = twe_get_native_buffer_from_pixmap(pixmap);
+       if (!pixmap) {
+               TPL_ERR("Invalid parameter. tpl_handle_t(%p)", pixmap);
+               return TPL_ERROR_INVALID_PARAMETER;
+       }
+
+       tbm_surface = wayland_tbm_server_get_surface(NULL,
+                                                                                                (struct wl_resource *)pixmap);
        if (!tbm_surface) {
-               TPL_ERR("Failed to get tbm_surface_h from native pixmap.");
-               return TPL_ERROR_INVALID_OPERATION;
+               TPL_ERR("Failed to get tbm_surface from wayland_tbm.");
+               return TPL_ERROR_INVALID_PARAMETER;
        }
 
        if (width) *width = tbm_surface_get_width(tbm_surface);
@@ -792,7 +900,8 @@ __tpl_wl_egl_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap)
 
        TPL_ASSERT(pixmap);
 
-       tbm_surface = twe_get_native_buffer_from_pixmap(pixmap);
+       tbm_surface = wayland_tbm_server_get_surface(NULL,
+                                                                                                (struct wl_resource *)pixmap);
        if (!tbm_surface) {
                TPL_ERR("Failed to get tbm_surface_h from wayland_tbm.");
                return NULL;
@@ -801,6 +910,10 @@ __tpl_wl_egl_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap)
        return tbm_surface;
 }
 
+
+
+
+
 static void
 __cb_tbm_surface_queue_reset_callback(tbm_surface_queue_h surface_queue,
                                                                          void *data)