From: joonbum.ko Date: Fri, 22 Sep 2017 05:58:39 +0000 (+0900) Subject: tpl_wayland_egl_thread: modified the wl_surf_source to be destroyed in the thread. X-Git-Tag: accepted/tizen/4.0/unified/20170925.150846~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F151896%2F5;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git tpl_wayland_egl_thread: modified the wl_surf_source to be destroyed in the thread. - It is destroyed in thread through del_source like tdm_source and wl_disp_source. Change-Id: Ic65e5521d4fafb9734de87f114ae292195b008a1 Signed-off-by: joonbum.ko --- diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 4102e23..511ce56 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -95,6 +95,7 @@ struct _twe_wl_surf_source { struct tizen_surface_shm_flusher *tss_flusher; tbm_surface_queue_h tbm_queue; twe_wl_disp_source *disp_source; + twe_del_source *surf_del_source; }; struct _twe_wl_buffer_info { @@ -1497,14 +1498,16 @@ _twe_thread_wl_surface_finalize(GSource *source) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; - __tpl_object_fini(&surf_source->obj); + TPL_LOG_T("WL_EGL", "gsource(%p) event_fd(%d)", + source, surf_source->event_fd); g_source_remove_unix_fd(source, surf_source->tag); close(surf_source->event_fd); + surf_source->event_fd = -1; + + __tpl_object_fini(&surf_source->obj); - TPL_LOG_T("WL_EGL", "gsource(%p) event_fd(%d)", - source, surf_source->event_fd); return; } @@ -1663,6 +1666,88 @@ twe_surface_get_tbm_queue(twe_surface_h twe_surface) return source->tbm_queue; } +static void +_twe_thread_wl_surf_source_destroy(void *source) +{ + twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; + twe_wl_disp_source *disp_source = NULL; + gboolean is_destroyed = FALSE; + + if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { + TPL_ERR("twe_surface(%p) is already destroyed.", surf_source); + 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; + } + + g_mutex_lock(&_twe_ctx->thread_mutex); + + TPL_OBJECT_LOCK(&disp_source->obj); + + while (!__tpl_list_is_empty(surf_source->in_use_buffers)) { + tbm_surface_h tbm_surface = (tbm_surface_h)__tpl_list_pop_front( + surf_source->in_use_buffers, + NULL); + tbm_surface_internal_unref(tbm_surface); + } + + __tpl_list_free(surf_source->in_use_buffers, NULL); + + surf_source->in_use_buffers = NULL; + + if (surf_source->committed_buffers) { + while (!__tpl_list_is_empty(surf_source->committed_buffers)) { + tbm_surface_h tbm_surface = + (tbm_surface_h)__tpl_list_pop_front( + surf_source->committed_buffers, + NULL); + tbm_surface_internal_unref(tbm_surface); + } + + __tpl_list_free(surf_source->committed_buffers, NULL); + surf_source->committed_buffers = NULL; + } + + _twe_surface_buffer_flusher_fini(surf_source); + + if (surf_source->tbm_queue) { + tbm_surface_queue_destroy(surf_source->tbm_queue); + surf_source->tbm_queue = NULL; + } + + if (surf_source->vblank) { + TPL_LOG_T("WL_EGL", "[VBLANK FINI] twe_wl_surf_source(%p) vblank(%p)", + surf_source, surf_source->vblank); + tdm_client_vblank_destroy(surf_source->vblank); + } + + surf_source->cb_data = NULL; + surf_source->rotate_cb = NULL; + + if (surf_source->wl_egl_window) { + TPL_LOG_T("WL_EGL", "twe_surface(%p) wl_egl_window(%p) wl_surface(%p)", + surf_source, surf_source->wl_egl_window, surf_source->surf); + surf_source->wl_egl_window->private = NULL; + surf_source->wl_egl_window = NULL; + surf_source->surf = NULL; + } else { + TPL_LOG_T("WL_EGL", "twe_surface(%p) native window is already destroyed"); + } + + TPL_OBJECT_UNLOCK(&disp_source->obj); + + g_source_destroy(&surf_source->gsource); + g_source_unref(&surf_source->gsource); + + g_cond_signal(&_twe_ctx->thread_cond); + g_mutex_unlock(&_twe_ctx->thread_mutex); +} twe_surface_h twe_surface_add(twe_thread* thread, @@ -1740,6 +1825,12 @@ twe_surface_add(twe_thread* thread, wl_egl_window->get_rotation_capability = (void *) __cb_get_rotation_capability; + source->surf_del_source = _twe_del_source_init(ctx, source); + if (source->surf_del_source) { + source->surf_del_source->destroy_target_source_func + = _twe_thread_wl_surf_source_destroy; + } + g_source_set_callback(&source->gsource, NULL, surface, NULL); g_source_attach(&source->gsource, g_main_loop_get_context(ctx->twe_loop)); @@ -1755,6 +1846,7 @@ twe_surface_del(twe_surface_h twe_surface) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; twe_wl_disp_source *disp_source = NULL; + twe_del_source *surf_del_source = NULL; gboolean is_destroyed = FALSE; if (!surf_source || @@ -1772,67 +1864,17 @@ twe_surface_del(twe_surface_h twe_surface) return TPL_ERROR_INVALID_PARAMETER; } - TPL_OBJECT_LOCK(&surf_source->obj); - while (!__tpl_list_is_empty(surf_source->in_use_buffers)) { - tbm_surface_h tbm_surface = (tbm_surface_h)__tpl_list_pop_front( - surf_source->in_use_buffers, - NULL); - tbm_surface_internal_unref(tbm_surface); - } - - __tpl_list_free(surf_source->in_use_buffers, NULL); - TPL_OBJECT_UNLOCK(&surf_source->obj); - - surf_source->in_use_buffers = NULL; - - TPL_OBJECT_LOCK(&disp_source->obj); - if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); - while (!__tpl_list_is_empty(surf_source->committed_buffers)) { - tbm_surface_h tbm_surface = - (tbm_surface_h)__tpl_list_pop_front( - surf_source->committed_buffers, - NULL); - tbm_surface_internal_unref(tbm_surface); - } + TPL_LOG_T("WL_EGL", "twe_surface(%p) will be destroyed in thread", + twe_surface); + surf_del_source = surf_source->surf_del_source; - __tpl_list_free(surf_source->committed_buffers, NULL); - surf_source->committed_buffers = NULL; - TPL_OBJECT_UNLOCK(&surf_source->obj); - } - - _twe_surface_buffer_flusher_fini(surf_source); - - if (surf_source->tbm_queue) { - tbm_surface_queue_destroy(surf_source->tbm_queue); - surf_source->tbm_queue = NULL; - } - - if (surf_source->vblank) { - TPL_LOG_T("WL_EGL", "[VBLANK FINI] twe_wl_surf_source(%p) vblank(%p)", - surf_source, surf_source->vblank); - tdm_client_vblank_destroy(surf_source->vblank); - } - - /* TODO : surf_source will be removed from surfaces list in disp_source */ - - surf_source->cb_data = NULL; - surf_source->rotate_cb = NULL; - - if (surf_source->wl_egl_window) { - TPL_LOG_T("WL_EGL", "twe_surface(%p) wl_egl_window(%p) wl_surface(%p)", - surf_source, surf_source->wl_egl_window, surf_source->surf); - surf_source->wl_egl_window->private = NULL; - surf_source->wl_egl_window = NULL; - surf_source->surf = NULL; - } else { - TPL_LOG_T("WL_EGL", "twe_surface(%p) native window is already destroyed"); - } - - TPL_OBJECT_UNLOCK(&disp_source->obj); + g_mutex_lock(&_twe_ctx->thread_mutex); + _twe_thread_del_source_trigger(surf_del_source); + g_cond_wait(&_twe_ctx->thread_cond, + &_twe_ctx->thread_mutex); + g_mutex_unlock(&_twe_ctx->thread_mutex); - g_source_destroy(&surf_source->gsource); - g_source_unref(&surf_source->gsource); + _twe_del_source_fini(surf_del_source); return TPL_ERROR_NONE; }