From fe2179cfdf7dd9df4be753e1442197313bf066a5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 19 Mar 2020 19:38:52 +0900 Subject: [PATCH 01/16] Added ttrace point to trace fence waiting time. Change-Id: I79764f225b785d12cbb43d90d9e46f38b9dc4744 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 71aa8fd..1aab901 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -3220,6 +3220,8 @@ _twe_thread_fence_wait_source_dispatch(GSource *source, GSourceFunc cb, gpointer surf_source->render_done_cnt++; + TRACE_ASYNC_END((int)wait_source, "FENCE WAIT fd(%d)", wait_source->fence_fd); + /* Since this source is going to be removed, acquire_and_commit must be * executed even in a situation other than G_IO_IN. * Nevertheless, there may be room for improvement. */ @@ -3271,6 +3273,8 @@ _twe_thread_fence_wait_source_attach(twe_wl_surf_source *surf_source, return TPL_ERROR_OUT_OF_MEMORY; } + TRACE_ASYNC_BEGIN((int)wait_source, "FENCE WAIT fd(%d)", sync_fd); + tbm_surface_internal_ref(tbm_surface); wait_source->fence_fd = sync_fd; -- 2.7.4 From 549eda9fc1b1a3d244db0d5cd3cfea1560b8f2bc Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 24 Mar 2020 18:38:07 +0900 Subject: [PATCH 02/16] Added some comments about the lists. Change-Id: I9fb0f70281704a13237aee7c921908a997ab7140 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 1aab901..3837417 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -109,8 +109,8 @@ struct _twe_wl_surf_source { } swapchain_properties; tpl_surface_cb_func_t rotate_cb; tpl_bool_t rotation_capability; - tpl_list_t *committed_buffers; - tpl_list_t *in_use_buffers; + tpl_list_t *committed_buffers; /* Trace tbm_surface from wl_surface_commit() to RELEASE */ + tpl_list_t *in_use_buffers; /* Trace tbm_surface from DEQUEUE to ENQUEUE */ tpl_list_t *vblank_waiting_buffers; /* for FIFO/FIFO_RELAXED modes */ tbm_surface_h draw_done_buffer; /* for MAILBOX mode */ int render_done_cnt; -- 2.7.4 From f8fe6dd8f502c29c4372ef2e99cf46f0e2b066a0 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 25 Mar 2020 16:35:30 +0900 Subject: [PATCH 03/16] Added fence_waiting_sources list to trace fence_wait_sources. Change-Id: Ib70a80a94be9f507adea71e13957adca87e41f9e Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 3837417..ce46b07 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -111,6 +111,7 @@ struct _twe_wl_surf_source { tpl_bool_t rotation_capability; tpl_list_t *committed_buffers; /* Trace tbm_surface from wl_surface_commit() to RELEASE */ tpl_list_t *in_use_buffers; /* Trace tbm_surface from DEQUEUE to ENQUEUE */ + tpl_list_t *fence_waiting_sources; /* Trace fence_wait_source from ENQUEUE to fence signaled */ tpl_list_t *vblank_waiting_buffers; /* for FIFO/FIFO_RELAXED modes */ tbm_surface_h draw_done_buffer; /* for MAILBOX mode */ int render_done_cnt; @@ -2595,6 +2596,25 @@ _twe_thread_wl_surf_source_destroy(void *source) surf_source->vblank_waiting_buffers = NULL; } + if (surf_source->use_sync_fence && surf_source->fence_waiting_sources) { + while (!__tpl_list_is_empty(surf_source->fence_waiting_sources)) { + twe_fence_wait_source *wait_source = + __tpl_list_pop_front(surf_source->fence_waiting_sources, + NULL); + if (!g_source_is_destroyed(&wait_source->gsource)) { + tbm_surface_internal_unref(wait_source->tbm_surface); + wait_source->tbm_surface = NULL; + + close(wait_source->fence_fd); + wait_source->fence_fd = -1; + + g_source_remove_unix_fd(&wait_source->gsource, wait_source->tag); + g_source_destroy(&wait_source->gsource); + g_source_unref(&wait_source->gsource); + } + } + } + _twe_surface_buffer_flusher_fini(surf_source); if (surf_source->tbm_queue) { @@ -2700,6 +2720,7 @@ twe_surface_add(twe_thread* thread, source->is_destroying = TPL_FALSE; source->committed_buffers = __tpl_list_alloc(); source->in_use_buffers = __tpl_list_alloc(); + source->fence_waiting_sources = __tpl_list_alloc(); source->render_done_cnt = 0; source->cb_data = NULL; @@ -3228,6 +3249,11 @@ _twe_thread_fence_wait_source_dispatch(GSource *source, GSourceFunc cb, gpointer _twe_thread_wl_surface_acquire_and_commit(surf_source); tbm_surface_internal_unref(tbm_surface); + g_mutex_lock(&surf_source->surf_mutex); + __tpl_list_remove_data(surf_source->fence_waiting_sources, + (void *)wait_source, TPL_FIRST, NULL); + g_mutex_unlock(&surf_source->surf_mutex); + /* This source is used only once and does not allow reuse. * So finalize will be executed immediately. */ g_source_remove_unix_fd(&wait_source->gsource, wait_source->tag); @@ -3284,6 +3310,12 @@ _twe_thread_fence_wait_source_attach(twe_wl_surf_source *surf_source, wait_source->tag = g_source_add_unix_fd(&wait_source->gsource, wait_source->fence_fd, G_IO_IN); + + /* When waiting is over, it will be removed from the list. */ + g_mutex_lock(&surf_source->surf_mutex); + __tpl_list_push_back(surf_source->fence_waiting_sources, (void *)wait_source); + g_mutex_unlock(&surf_source->surf_mutex); + g_source_attach(&wait_source->gsource, g_main_loop_get_context(_twe_ctx->twe_loop)); return TPL_ERROR_NONE; -- 2.7.4 From b963d7b5fb1a71e886606cf3b0e7b813f51c44ee Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 25 Mar 2020 16:37:11 +0900 Subject: [PATCH 04/16] Package version up to 1.7.4 Change-Id: I3f0c29f36603646865fba76d4f4f7e363fc53ced Signed-off-by: Joonbum Ko --- packaging/libtpl-egl.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 542be2b..36cbfca 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -4,7 +4,7 @@ #TPL VERSION MACROS %define TPL_VERSION_MAJOR 1 %define TPL_VERSION_MINOR 7 -%define TPL_VERSION_PATCH 3 +%define TPL_VERSION_PATCH 4 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 1946f1ce6ed71ce3ca9a180651439d38c38413e5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 26 Mar 2020 15:57:29 +0900 Subject: [PATCH 05/16] Fixed tdm_source to destroy when error occurs in tdm. - If an error occurs in tdm_client_handle_events, it cannot be recovered. When tdm_source is no longer available due to an unexpected situation, twe_thread must remove it from the thread and destroy it. - In that case, tdm_vblank can no longer be used for surfaces and display that used the tdm_source. Change-Id: I1e19e12847a03ef03e5ce7562a4e992952c4fdbb Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index ce46b07..47ba4c1 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -378,7 +378,7 @@ static gboolean _twe_thread_tdm_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) { twe_tdm_source *tdm_source = (twe_tdm_source *)source; - tdm_error tdm_err; + tdm_error tdm_err = TDM_ERROR_NONE; GIOCondition cond; if (!source || g_source_is_destroyed(source)) { @@ -390,7 +390,30 @@ _twe_thread_tdm_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) if (cond & G_IO_IN) { tdm_err = tdm_client_handle_events(tdm_source->tdm_client); - TPL_ASSERT(tdm_err == TDM_ERROR_NONE); + } + + /* If an error occurs in tdm_client_handle_events, it cannot be recovered. + * When tdm_source is no longer available due to an unexpected situation, + * twe_thread must remove it from the thread and destroy it. + * In that case, tdm_vblank can no longer be used for surfaces and displays + * that used this tdm_source. */ + if (tdm_err != TDM_ERROR_NONE) { + TPL_ERR("Error occured in tdm_client_handle_events. tdm_err(%d)", + tdm_err); + TPL_WARN("tdm_source(%p) will be removed from thread.", tdm_source); + + g_source_remove_unix_fd(&tdm_source->gsource, tdm_source->tag); + g_source_destroy(&tdm_source->gsource); + g_source_unref(&tdm_source->gsource); + + _twe_ctx->tdm_source = NULL; + + if (_twe_ctx->tdm_del_source) { + _twe_del_source_fini(_twe_ctx->tdm_del_source); + _twe_ctx->tdm_del_source = NULL; + } + + return G_SOURCE_REMOVE; } return G_SOURCE_CONTINUE; @@ -545,9 +568,10 @@ twe_thread_destroy(twe_thread* thread) if (_twe_ctx->tdm_source) { g_mutex_lock(&_twe_ctx->thread_mutex); - if (tdm_del_source) + if (tdm_del_source) { _twe_thread_del_source_trigger(tdm_del_source); - g_cond_wait(&_twe_ctx->thread_cond, &_twe_ctx->thread_mutex); + g_cond_wait(&_twe_ctx->thread_cond, &_twe_ctx->thread_mutex); + } g_mutex_unlock(&_twe_ctx->thread_mutex); } -- 2.7.4 From b0ef631b94e8447603fbb02cce65de9768f6c895 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 26 Mar 2020 16:06:05 +0900 Subject: [PATCH 06/16] Renamed vblank callback function to be more clearly. Change-Id: I9700162590997a584bf69413142928324fb2cf89 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 47ba4c1..ceef070 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1794,7 +1794,7 @@ static void _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, tbm_surface_h tbm_surface); static void -__cb_tdm_client_wait_vblank(tdm_client_vblank *vblank, tdm_error error, +__cb_tdm_client_vblank(tdm_client_vblank *vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data) { @@ -1883,7 +1883,7 @@ _twe_surface_wait_vblank(twe_wl_surf_source *surf_source) tdm_err = tdm_client_vblank_wait(surf_source->vblank, surf_source->post_interval, /* TODO: interval */ - __cb_tdm_client_wait_vblank, + __cb_tdm_client_vblank, (void *)surf_source); if (tdm_err == TDM_ERROR_NONE) { @@ -2210,7 +2210,7 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, /* The following function _twe_thread_wl_surface_acquire_and_commit can be * called in both situations. * One is when acquirable event is received from the main thread, - * and the other is when __cb_tdm_client_wait_vblank callback is called. + * and the other is when __cb_tdm_client_vblank callback is called. * The reason for calling the next function in the two situations described * above is to make only one commit for one vblank. */ -- 2.7.4 From 3cb906ff21a420f70aa9805327c23132a2b224e2 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 26 Mar 2020 18:08:15 +0900 Subject: [PATCH 07/16] Make to operate normally even when tdm_source was unexpectedly destroyed. Change-Id: If3a39100b1922a840a16b1860ff427c532883102 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index ceef070..b1c1f4e 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1868,6 +1868,13 @@ _twe_surface_wait_vblank(twe_wl_surf_source *surf_source) if (!_twe_ctx->tdm_source) { TPL_WARN("tdm_vblank feature is disabled."); + + if (surf_source->vblank) { + tdm_client_vblank_destroy(surf_source->vblank); + surf_source->vblank = NULL; + surf_source->vblank_done = TPL_TRUE; + } + return TPL_ERROR_INVALID_OPERATION; } @@ -1967,7 +1974,8 @@ _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, == TPL_DISPLAY_PRESENT_MODE_FIFO_RELAXED || surf_source->swapchain_properties.present_mode == TPL_DISPLAY_PRESENT_MODE_FIFO) { - if (_twe_surface_wait_vblank(surf_source) != TPL_ERROR_NONE) + if ((_twe_ctx->tdm_source || surf_source->vblank) && + _twe_surface_wait_vblank(surf_source) != TPL_ERROR_NONE) TPL_ERR("Failed to set wait vblank"); } @@ -2187,7 +2195,8 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, buf_info->wl_buffer, tbm_surface, tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); - if (_twe_surface_wait_vblank(surf_source) != TPL_ERROR_NONE) + if ((_twe_ctx->tdm_source || surf_source->vblank) && + _twe_surface_wait_vblank(surf_source) != TPL_ERROR_NONE) TPL_ERR("Failed to set wait vblank."); @@ -2303,7 +2312,8 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) surf_source->draw_done_buffer = tbm_surface; if (surf_source->vblank_done) { - if (_twe_surface_wait_vblank(surf_source) != TPL_ERROR_NONE) + if ((_twe_ctx->tdm_source || surf_source->vblank) && + _twe_surface_wait_vblank(surf_source) != TPL_ERROR_NONE) TPL_ERR("Failed to set wait vblank"); } break; @@ -2650,6 +2660,7 @@ _twe_thread_wl_surf_source_destroy(void *source) TPL_LOG_T(BACKEND, "[VBLANK FINI] twe_wl_surf_source(%p) vblank(%p)", surf_source, surf_source->vblank); tdm_client_vblank_destroy(surf_source->vblank); + surf_source->vblank = NULL; } surf_source->cb_data = NULL; -- 2.7.4 From 838d2950e4b755a548e80b73fc7c56009cbbfd8b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 31 Mar 2020 18:11:10 +0900 Subject: [PATCH 08/16] tpl_tbm: Added reset callback for tbm_queue. Change-Id: Ic9c331d82525ad05fae9818970f60ed6853907d5 Signed-off-by: Joonbum Ko --- src/tpl_tbm.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index b38c7c5..cabdf9d 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -21,6 +21,7 @@ struct _tpl_tbm_display { struct _tpl_tbm_surface { tbm_surface_queue_h tbm_queue; + tpl_bool_t need_reset; }; static tpl_result_t @@ -165,6 +166,22 @@ __tpl_tbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) return (tbm_surface_h)pixmap; } +static void +__cb_tbm_queue_reset_callback(tbm_surface_queue_h tbm_queue, + void *data) +{ + tpl_tbm_surface_t *tpl_tbm_surface = (tpl_tbm_surface_t *)data; + + if (!tpl_tbm_surface) { + TPL_ERR("Invalid parameter. tpl_tbm_surface(%p)", tpl_tbm_surface); + return; + } + + TPL_LOG_B("TBM", "tbm_queue(%p) has been reset!", tbm_queue); + + tpl_tbm_surface->need_reset = TPL_TRUE; +} + static tpl_result_t __tpl_tbm_surface_init(tpl_surface_t *surface) { @@ -179,8 +196,15 @@ __tpl_tbm_surface_init(tpl_surface_t *surface) surface->backend.data = (void *)tpl_tbm_surface; + tpl_tbm_surface->need_reset = TPL_FALSE; + tpl_tbm_surface->tbm_queue = (tbm_surface_queue_h)surface->native_handle; + /* Set reset_callback to tbm_queue */ + tbm_surface_queue_add_reset_cb(tpl_tbm_surface->tbm_queue, + __cb_tbm_queue_reset_callback, + (void *)tpl_tbm_surface); + TPL_LOG_B("TBM", "[INIT] tpl_surface(%p) tpl_tbm_surface_t(%p) tbm_surface_queue(%p)", surface, tpl_tbm_surface, surface->native_handle); @@ -252,7 +276,12 @@ __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, static tpl_bool_t __tpl_tbm_surface_validate(tpl_surface_t *surface) { - return TPL_TRUE; + tpl_tbm_surface_t *tpl_tbm_surface = (tpl_tbm_surface_t *)surface->backend.data; + tpl_bool_t ret = TPL_TRUE; + + ret = !tpl_tbm_surface->need_reset; + + return ret; } static tbm_surface_h @@ -286,6 +315,8 @@ __tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, /* It will be dec when before tbm_surface_queue_enqueue called */ tbm_surface_internal_ref(tbm_surface); + tpl_tbm_surface->need_reset = TPL_FALSE; + TPL_LOG_B("TBM", "[DEQ] tpl_surface(%p) tbm_queue(%p) tbm_surface(%p) bo(%d)", surface, tpl_tbm_surface->tbm_queue, tbm_surface, tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); -- 2.7.4 From 830b7e8b7157a9cb57f76d39012c20501b4ab1e4 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 8 Apr 2020 15:38:56 +0900 Subject: [PATCH 09/16] Package version up to 1.7.5 Change-Id: I2800f5fdebb3a2278344774599ba53f69a2b09f1 Signed-off-by: Joonbum Ko --- packaging/libtpl-egl.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 36cbfca..98712ac 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -4,7 +4,7 @@ #TPL VERSION MACROS %define TPL_VERSION_MAJOR 1 %define TPL_VERSION_MINOR 7 -%define TPL_VERSION_PATCH 4 +%define TPL_VERSION_PATCH 5 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 79a72b5fc4544c977a36e587f0abcef3356d8be5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 9 Apr 2020 13:15:52 +0900 Subject: [PATCH 10/16] Added missing destroy of bound presentation interface. Change-Id: I61344fb95eba06ec5b3a281bf09a3756edc6e460 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index b1c1f4e..4f6acf1 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -924,6 +924,13 @@ _twe_display_wayland_fini(twe_wl_disp_source *disp_source) if (disp_source->wl_vk_client) { TPL_LOG_T(BACKEND, "wl_vk_client(%p) fini.", disp_source->wl_vk_client); wayland_vulkan_destroy(disp_source->wl_vk_client); + disp_source->wl_vk_client = NULL; + } + + if (disp_source->presentation) { + TPL_LOG_T(BACKEND, "wp_presentation(%p) fini.", disp_source->presentation); + wp_presentation_destroy(disp_source->presentation); + disp_source->presentation = NULL; } } -- 2.7.4 From 0f9bdedeaac4bcd2f7f537a707decfce2ab2f4fd Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 9 Apr 2020 18:13:15 +0900 Subject: [PATCH 11/16] Changed to do not print error logs when last_error is already set. Change-Id: Ib5b4ec852930a55089864eeaf28e7b095295bc50 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 4f6acf1..48c9507 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -81,6 +81,7 @@ struct _twe_wl_disp_source { twe_thread *thread; GMutex wl_event_mutex; + int last_error; /* errno of the last wl_display error*/ /* TODO : surface list */ }; @@ -606,6 +607,9 @@ _twe_display_print_err(twe_wl_disp_source *disp_source, char buf[1024]; strerror_r(errno, buf, sizeof(buf)); + if (disp_source->last_error == errno) + return; + TPL_ERR("falied to %s. error:%d(%s)", func_name, errno, buf); dpy_err = wl_display_get_error(disp_source->disp); @@ -618,6 +622,8 @@ _twe_display_print_err(twe_wl_disp_source *disp_source, TPL_ERR("[Protocol Error] interface: %s, error_code: %d, proxy_id: %d", err_interface->name, err_code, err_proxy_id); } + + disp_source->last_error = errno; } static gboolean @@ -1000,6 +1006,7 @@ twe_display_add(twe_thread* thread, } source->disp = display; + source->last_error = 0; source->ev_queue = ev_queue; source->wl_tbm_client = wl_tbm_client; source->prepared = TPL_FALSE; -- 2.7.4 From 155d98f2a79866bce7b3ebf307e3e6c959d50c1a Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 17 Apr 2020 15:56:10 +0900 Subject: [PATCH 12/16] Added an error type to tpl_result_t to indicate display error. - new error type TPL_ERROR_INVALID_CONNECTION /* Invalid display connection */ - When some error occurs in the wayland display, it will be used to distinguish the error. Change-Id: I9f0813d64d10b522dae1224a0bf699328d479f27 Signed-off-by: Joonbum Ko --- src/tpl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tpl.h b/src/tpl.h index aaf6998..7250315 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -209,7 +209,8 @@ typedef enum { TPL_ERROR_INVALID_PARAMETER, /* Invalid parmeter */ TPL_ERROR_INVALID_OPERATION, /* Invalid operation */ TPL_ERROR_OUT_OF_MEMORY, /* Out of memory */ - TPL_ERROR_TIME_OUT /* Time out error */ + TPL_ERROR_TIME_OUT, /* Time out error */ + TPL_ERROR_INVALID_CONNECTION /* Invalid display connection */ } tpl_result_t; /** -- 2.7.4 From 2bb448c9e99fc22b38c3e96a8a1a9df1bf22f02b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 14:57:42 +0900 Subject: [PATCH 13/16] Deleted unnecessary checks for gsource is destroyed. Change-Id: I03d527cfd0b1986a32f14e8b106e5f83bddefa16 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 64 -------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 48c9507..29af684 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -252,13 +252,6 @@ _twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) g_mutex_lock(&_twe_ctx->thread_mutex); - if (g_source_is_destroyed(source)) { - TPL_ERR("del_source(%p) already destroyed.", source); - g_cond_signal(&_twe_ctx->thread_cond); - g_mutex_unlock(&_twe_ctx->thread_mutex); - return G_SOURCE_REMOVE; - } - cond = g_source_query_unix_fd(source, del_source->tag); if (cond & G_IO_IN) { @@ -315,11 +308,6 @@ _twe_thread_del_source_trigger(twe_del_source *del_source) uint64_t value = 1; int ret; - if (!del_source || g_source_is_destroyed(&del_source->gsource)) { - TPL_ERR("del_source(%p) is already destroyed.", del_source); - return; - } - ret = write(del_source->event_fd, &value, sizeof(uint64_t)); if (ret == -1) { TPL_ERR("failed to send delete event. twe_del_source(%p)", @@ -382,11 +370,6 @@ _twe_thread_tdm_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) tdm_error tdm_err = TDM_ERROR_NONE; GIOCondition cond; - if (!source || g_source_is_destroyed(source)) { - TPL_ERR("TDM source(%p) already destroyed.", source); - return G_SOURCE_REMOVE; - } - cond = g_source_query_unix_fd(source, tdm_source->tag); if (cond & G_IO_IN) { @@ -490,11 +473,6 @@ _twe_thread_tdm_source_destroy(void *source) { twe_tdm_source *tdm_source = (twe_tdm_source *)source; - if (!tdm_source || g_source_is_destroyed(&tdm_source->gsource)) { - TPL_ERR("TDM source(%p) already destroyed.", tdm_source); - return; - } - _twe_ctx->tdm_source = NULL; g_source_remove_unix_fd(&tdm_source->gsource, tdm_source->tag); @@ -657,13 +635,6 @@ _twe_thread_wl_disp_check(GSource *source) twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source; gboolean ret = FALSE; - if (g_source_is_destroyed(source)) { - if (disp_source && disp_source->disp && disp_source->prepared) - wl_display_cancel_read(disp_source->disp); - TPL_ERR("display source(%p) already destroyed.", source); - return ret; - } - if (!disp_source->prepared) return ret; @@ -686,11 +657,6 @@ _twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data) { twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source; - if (g_source_is_destroyed(source)) { - TPL_ERR("display source(%p) already destroyed.", source); - return G_SOURCE_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, @@ -2357,11 +2323,6 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; GIOCondition cond; - if (g_source_is_destroyed(source)) { - TPL_ERR("surface source(%p) already destroyed.", source); - return G_SOURCE_REMOVE; - } - cond = g_source_query_unix_fd(source, surf_source->tag); if (cond & G_IO_IN) { @@ -2907,11 +2868,6 @@ twe_surface_create_swapchain(twe_surface_h twe_surface, tbm_bufmgr bufmgr = NULL; unsigned int capability; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("twe_surface(%p) is invalid.", twe_surface); - return TPL_ERROR_INVALID_PARAMETER; - } - if (surf_source->tbm_queue) { TPL_LOG_B(BACKEND, "[REUSE SWAPCHAIN] surf_source(%p) tbm_queue(%p)", surf_source, surf_source->tbm_queue); @@ -3040,11 +2996,6 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("twe_surface(%p) is invalid.", twe_surface); - return TPL_ERROR_INVALID_PARAMETER; - } - TPL_LOG_T(BACKEND, "[SWAPCHAIN_DESTROY] twe_surface(%p) tbm_queue(%p)", twe_surface, surf_source->tbm_queue); @@ -3090,11 +3041,6 @@ twe_surface_get_swapchain_buffers(twe_surface_h twe_surface, twe_wl_disp_source *disp_source = NULL; int ret = 1; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("twe_surface(%p) is invalid.", twe_surface); - return TPL_ERROR_INVALID_PARAMETER; - } - if (!buffer_count) { TPL_ERR("Invalid parameter. buffer_count is NULL."); return TPL_ERROR_INVALID_PARAMETER; @@ -3435,11 +3381,6 @@ twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) twe_wl_disp_source *disp_source = NULL; gint64 end_time; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("Invalid parameter. surf_source(%p)", surf_source); - return TPL_ERROR_INVALID_PARAMETER; - } - disp_source = surf_source->disp_source; if (timeout_ns != UINT64_MAX) @@ -3588,11 +3529,6 @@ twe_surface_set_post_interval(twe_surface_h twe_surface, int post_interval) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("Invalid parameter. surf_source(%p)", surf_source); - return TPL_ERROR_INVALID_PARAMETER; - } - surf_source->post_interval = post_interval; TPL_LOG_T(BACKEND, "surf_source(%p) post_interval(%d)", -- 2.7.4 From 5b1e179267322b2bca0457e53fbf563b5512b0bd Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:37:29 +0900 Subject: [PATCH 14/16] Deleted unused function commit_without_enqueue. Change-Id: I35f8b16c4acb98153277f3613e0c2e106f11465d Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 25 ------------------------- src/tpl_wayland_egl_thread.h | 4 ---- 2 files changed, 29 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 29af684..ea58f4c 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -3191,31 +3191,6 @@ twe_surface_check_commit_needed(twe_surface_h twe_surface, return buf_info->need_to_commit; } -void -twe_surface_commit_without_enqueue(twe_surface_h twe_surface, - tbm_surface_h tbm_surface) -{ - twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; - - if (!surf_source) { - TPL_ERR("Invalid parameter. twe_surface(%p)", twe_surface); - return; - } - - if (!tbm_surface || !tbm_surface_internal_is_valid(tbm_surface)) { - TPL_ERR("Invalid parameter. tbm_surface(%p)", tbm_surface); - return; - } - - g_mutex_lock(&surf_source->surf_mutex); - if (!surf_source->is_destroying) - _twe_thread_wl_surface_commit(surf_source, tbm_surface); - else - TPL_WARN("surf_source(%p) native window is already destroyed.", - surf_source); - g_mutex_unlock(&surf_source->surf_mutex); -} - static gboolean _twe_thread_fence_wait_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) { diff --git a/src/tpl_wayland_egl_thread.h b/src/tpl_wayland_egl_thread.h index 3a17305..9252fa9 100755 --- a/src/tpl_wayland_egl_thread.h +++ b/src/tpl_wayland_egl_thread.h @@ -80,10 +80,6 @@ tpl_bool_t twe_surface_check_commit_needed(twe_surface_h twe_surface, tbm_surface_h tbm_surface); -void -twe_surface_commit_without_enqueue(twe_surface_h twe_surface, - tbm_surface_h tbm_surface); - tpl_result_t twe_surface_set_damage_region(tbm_surface_h tbm_surface, int num_rects, const int *rects); -- 2.7.4 From 2dedc1fe5d55dafe9254e104b58bac1ab342003b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:41:59 +0900 Subject: [PATCH 15/16] Protected the access of surf_source's event_fd with surf_mutex. Change-Id: Icd081e7adf27c047e64b3f6bfabb06c1b85e6906 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index ea58f4c..121a1da 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1719,14 +1719,19 @@ __cb_tbm_queue_acquirable_callback(tbm_surface_queue_h surface_queue, uint64_t value = 1; int ret; + g_mutex_lock(&surf_source->surf_mutex); + if (!surf_source->use_sync_fence) { ret = write(surf_source->event_fd, &value, sizeof(uint64_t)); if (ret == -1) { TPL_ERR("failed to send acquirable event. twe_wl_surf_source(%p)", surf_source); + g_mutex_unlock(&surf_source->surf_mutex); return; } } + + g_mutex_unlock(&surf_source->surf_mutex); } static void __cb_tbm_queue_trace_callback(tbm_surface_queue_h tbm_queue, @@ -2323,6 +2328,8 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; GIOCondition cond; + g_mutex_lock(&surf_source->surf_mutex); + cond = g_source_query_unix_fd(source, surf_source->tag); if (cond & G_IO_IN) { @@ -2342,6 +2349,8 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) TPL_ASSERT((cond & G_IO_IN)); } + g_mutex_unlock(&surf_source->surf_mutex); + return G_SOURCE_CONTINUE; } -- 2.7.4 From a2e1ab6fe7e2a4463c452579f2a6522945a7bc25 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:52:07 +0900 Subject: [PATCH 16/16] Excluded the case of abort due to eventfd problem. - Remove poll fd(event_fd) of main loop, but keep gsource. Change-Id: I3759d24672895b355e3541e7b8b6d2a2de7dab6d Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 121a1da..2742986 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -268,9 +268,11 @@ _twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) } else { TPL_ERR("eventfd(%d) cannot wake up with other condition. cond(%d)", del_source->event_fd, cond); - g_cond_signal(&_twe_ctx->thread_cond); - g_mutex_unlock(&_twe_ctx->thread_mutex); - TPL_ASSERT((cond & G_IO_IN)); + + g_source_remove_unix_fd(del_source->event_fd, del_source->tag); + close(del_source->event_fd); + del_source->tag = NULL; + del_source->event_fd = -1; } g_cond_signal(&_twe_ctx->thread_cond); @@ -2346,7 +2348,10 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) } else { TPL_ERR("eventfd(%d) cannot wake up with other condition. cond(%d)", surf_source->event_fd, cond); - TPL_ASSERT((cond & G_IO_IN)); + g_source_remove_unix_fd(source, surf_source->tag); + close(surf_source->event_fd); + surf_source->tag = NULL; + surf_source->event_fd = -1; } g_mutex_unlock(&surf_source->surf_mutex); -- 2.7.4