From 69bf06cf122dd70915ec673f16bdb467c4a6d3ba Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 11 Mar 2021 16:09:32 +0900 Subject: [PATCH 01/16] Make shorten the name of backend function. - __tpl_wl_egl_surface_cancel_dequeued_buffer() is too long name. - it will be changed to below. __tpl_wl_egl_surface_cancel_buffer() Change-Id: I05d6520097b965e316bbf8b9b9b2c1e78c62ecbb Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 17cc5cf..e5d875e 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2357,8 +2357,8 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, } static tpl_result_t -__tpl_wl_egl_surface_cancel_dequeued_buffer(tpl_surface_t *surface, - tbm_surface_h tbm_surface) +__tpl_wl_egl_surface_cancel_buffer(tpl_surface_t *surface, + tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); @@ -3212,7 +3212,7 @@ __tpl_surface_init_backend_wl_egl_thread(tpl_surface_backend_t *backend) backend->fini = __tpl_wl_egl_surface_fini; backend->validate = __tpl_wl_egl_surface_validate; backend->cancel_dequeued_buffer = - __tpl_wl_egl_surface_cancel_dequeued_buffer; + __tpl_wl_egl_surface_cancel_buffer; backend->dequeue_buffer = __tpl_wl_egl_surface_dequeue_buffer; backend->enqueue_buffer = __tpl_wl_egl_surface_enqueue_buffer; backend->set_rotation_capability = -- 2.7.4 From 41ca2a8219d134cb3c41cd6471fe4305cfb95d79 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 11 Mar 2021 17:56:37 +0900 Subject: [PATCH 02/16] Destroy buffer_release when wl_egl_buffer destroy. Change-Id: Iad683fc89b9d9a5e23a948f564a64ad572715140 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index e5d875e..68cdbef 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -3243,9 +3243,16 @@ __cb_wl_egl_buffer_free(tpl_wl_egl_buffer_t *wl_egl_buffer) wl_display_flush(wl_egl_display->wl_display); - if (wl_egl_buffer->wl_buffer) + if (wl_egl_buffer->wl_buffer) { wayland_tbm_client_destroy_buffer(wl_egl_display->wl_tbm_client, (void *)wl_egl_buffer->wl_buffer); + wl_egl_buffer->wl_buffer = NULL; + } + + if (wl_egl_buffer->buffer_release) { + zwp_linux_buffer_release_v1_destroy(wl_egl_buffer->buffer_release); + wl_egl_buffer->buffer_release = NULL; + } if (wl_egl_buffer->waiting_source) { tpl_gsource_destroy(wl_egl_buffer->waiting_source, TPL_FALSE); -- 2.7.4 From 90ce1840e07d9a89fd2e5704849157e4416db6c9 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 12 Mar 2021 10:42:33 +0900 Subject: [PATCH 03/16] Fix buffer_clear logic for explicit fence sync. Change-Id: Idb76fa9179605c03b29c8dd36d9276f121d7753d Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 57 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 68cdbef..cc609a0 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -1875,17 +1875,28 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface) * so cancel_dequeue must be performed. */ need_to_cancel = wl_egl_buffer->status == DEQUEUED; - if (wl_egl_buffer->status >= ENQUEUED && - wl_egl_buffer->status < WAITING_VBLANK) { + if (wl_egl_buffer->status >= ENQUEUED) { + tpl_bool_t need_to_wait = TPL_FALSE; tpl_result_t wait_result = TPL_ERROR_NONE; - tpl_gmutex_unlock(&wl_egl_display->wl_event_mutex); - wait_result = tpl_cond_timed_wait(&wl_egl_buffer->cond, - &wl_egl_buffer->mutex, - 16); /* 16ms */ - tpl_gmutex_lock(&wl_egl_display->wl_event_mutex); - if (wait_result == TPL_ERROR_TIME_OUT) - TPL_WARN("timeout occured waiting signaled. wl_egl_buffer(%p)", - wl_egl_buffer); + + if (!wl_egl_display->use_explicit_sync && + wl_egl_buffer->status < WAITING_VBLANK) + need_to_wait = TPL_TRUE; + + if (wl_egl_display->use_explicit_sync && + wl_egl_buffer->status < COMMITTED) + need_to_wait = TPL_TRUE; + + if (need_to_wait) { + tpl_gmutex_unlock(&wl_egl_display->wl_event_mutex); + wait_result = tpl_cond_timed_wait(&wl_egl_buffer->cond, + &wl_egl_buffer->mutex, + 16); /* 16ms */ + tpl_gmutex_lock(&wl_egl_display->wl_event_mutex); + if (wait_result == TPL_ERROR_TIME_OUT) + TPL_WARN("timeout occured waiting signaled. wl_egl_buffer(%p)", + wl_egl_buffer); + } } if (need_to_release) { @@ -1904,6 +1915,8 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface) wl_egl_buffer->tbm_surface, tsq_err); } + wl_egl_buffer->status = RELEASED; + tpl_gmutex_unlock(&wl_egl_buffer->mutex); if (need_to_release || need_to_cancel) @@ -2702,12 +2715,12 @@ __cb_buffer_fenced_release(void *data, tbm_surface = wl_egl_buffer->tbm_surface; if (tbm_surface_internal_is_valid(tbm_surface)) { + + tpl_gmutex_lock(&wl_egl_buffer->mutex); if (wl_egl_buffer->status == COMMITTED) { tpl_wl_egl_surface_t *wl_egl_surface = wl_egl_buffer->wl_egl_surface; tbm_surface_queue_error_e tsq_err; - tpl_gmutex_lock(&wl_egl_buffer->mutex); - zwp_linux_buffer_release_v1_destroy(wl_egl_buffer->buffer_release); wl_egl_buffer->buffer_release = NULL; @@ -2726,8 +2739,6 @@ __cb_buffer_fenced_release(void *data, _get_tbm_surface_bo_name(tbm_surface), fence); - tpl_gmutex_unlock(&wl_egl_buffer->mutex); - tsq_err = tbm_surface_queue_release(wl_egl_surface->tbm_queue, tbm_surface); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) @@ -2735,6 +2746,9 @@ __cb_buffer_fenced_release(void *data, tbm_surface_internal_unref(tbm_surface); } + + tpl_gmutex_unlock(&wl_egl_buffer->mutex); + } else { TPL_ERR("Invalid parameter | tbm_surface(%p)", tbm_surface); } @@ -2752,12 +2766,12 @@ __cb_buffer_immediate_release(void *data, tbm_surface = wl_egl_buffer->tbm_surface; if (tbm_surface_internal_is_valid(tbm_surface)) { + + tpl_gmutex_lock(&wl_egl_buffer->mutex); if (wl_egl_buffer->status == COMMITTED) { tpl_wl_egl_surface_t *wl_egl_surface = wl_egl_buffer->wl_egl_surface; tbm_surface_queue_error_e tsq_err; - tpl_gmutex_lock(&wl_egl_buffer->mutex); - zwp_linux_buffer_release_v1_destroy(wl_egl_buffer->buffer_release); wl_egl_buffer->buffer_release = NULL; @@ -2774,8 +2788,6 @@ __cb_buffer_immediate_release(void *data, wl_egl_buffer->wl_buffer, tbm_surface, _get_tbm_surface_bo_name(tbm_surface)); - tpl_gmutex_unlock(&wl_egl_buffer->mutex); - tsq_err = tbm_surface_queue_release(wl_egl_surface->tbm_queue, tbm_surface); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) @@ -2783,6 +2795,9 @@ __cb_buffer_immediate_release(void *data, tbm_surface_internal_unref(tbm_surface); } + + tpl_gmutex_unlock(&wl_egl_buffer->mutex); + } else { TPL_ERR("Invalid parameter | tbm_surface(%p)", tbm_surface); } @@ -3130,9 +3145,15 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface, TRACE_ASYNC_BEGIN((int)wl_egl_buffer->tbm_surface, "[COMMIT ~ RELEASE] BO(%d)", wl_egl_buffer->bo_name); + tpl_gmutex_lock(&wl_egl_buffer->mutex); + wl_egl_buffer->need_to_commit = TPL_FALSE; wl_egl_buffer->status = COMMITTED; + tpl_gcond_signal(&wl_egl_buffer->cond); + + tpl_gmutex_unlock(&wl_egl_buffer->mutex); + TPL_LOG_T("WL_EGL", "[COMMIT] wl_egl_buffer(%p) wl_buffer(%p) tbm_surface(%p) bo(%d)", wl_egl_buffer, wl_egl_buffer->wl_buffer, wl_egl_buffer->tbm_surface, -- 2.7.4 From a2d736370add8cb09aac892e023a21530e99e61b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 12 Mar 2021 11:17:25 +0900 Subject: [PATCH 04/16] Fix a problem with overwriting fence fd with -1. Change-Id: Iab7191b1ddd50a822b768529f577b1612f80e259 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index cc609a0..8618311 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2132,14 +2132,7 @@ _wl_egl_buffer_init(tpl_wl_egl_buffer_t *wl_egl_buffer, wl_egl_buffer->draw_done = TPL_FALSE; wl_egl_buffer->need_to_commit = TPL_TRUE; - - wl_egl_buffer->acquire_fence_fd = -1; - wl_egl_buffer->release_fence_fd = -1; - wl_egl_buffer->commit_sync_fd = -1; - wl_egl_buffer->presentation_sync_fd = -1; - wl_egl_buffer->buffer_release = NULL; - wl_egl_buffer->transform = tizen_private->transform; if (wl_egl_buffer->w_transform != tizen_private->window_transform) { @@ -2194,6 +2187,11 @@ _wl_egl_buffer_create(tpl_wl_egl_surface_t *wl_egl_surface, wl_egl_buffer->status = RELEASED; + wl_egl_buffer->acquire_fence_fd = -1; + wl_egl_buffer->commit_sync_fd = -1; + wl_egl_buffer->presentation_sync_fd = -1; + wl_egl_buffer->release_fence_fd = -1; + wl_egl_buffer->dx = wl_egl_window->dx; wl_egl_buffer->dy = wl_egl_window->dy; wl_egl_buffer->width = tbm_surface_get_width(tbm_surface); -- 2.7.4 From 9887da5c823e1b7d8e31cff39793e4ebccaf83b1 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 12 Mar 2021 13:22:16 +0900 Subject: [PATCH 05/16] Enable explicit_fence_sync feature defaultly. Change-Id: I44a63dc2df55d54372a8ddfe2392f618489ca1da Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 8618311..bd4ba82 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -372,14 +372,14 @@ __cb_wl_resistry_global_callback(void *data, struct wl_registry *wl_registry, TPL_DEBUG("bind wp_presentation_interface"); } else if (strcmp(interface, "zwp_linux_explicit_synchronization_v1") == 0) { char *env = tpl_getenv("TPL_EFS"); - if (env && atoi(env)) { + if (env && !atoi(env)) { + wl_egl_display->use_explicit_sync = TPL_FALSE; + } else { wl_egl_display->explicit_sync = wl_registry_bind(wl_registry, name, &zwp_linux_explicit_synchronization_v1_interface, 1); wl_egl_display->use_explicit_sync = TPL_TRUE; TPL_DEBUG("bind zwp_linux_explicit_synchronization_v1_interface"); - } else { - wl_egl_display->use_explicit_sync = TPL_FALSE; } } } -- 2.7.4 From f2c1739f2064c11d9a69bec58f51263d3bb0893d Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 12 Mar 2021 15:52:53 +0900 Subject: [PATCH 06/16] Package version up to 1.8.1 Change-Id: I2560ac5a621f19981742bb46965f155913e27b99 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 a0e2e65..6511342 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 8 -%define TPL_VERSION_PATCH 0 +%define TPL_VERSION_PATCH 1 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 2c166ed0510b598d164f8f421934d13fce4d83b5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 23 Mar 2021 13:44:38 +0900 Subject: [PATCH 07/16] Fix gem memory leak issue when client destroyed. - When surface_fini, the ENQUEUED state, the wl_egl_buffer was not properly processed. - As a result, the APP was terminated without tbm_surface_destroy, resulting in GEM Memory leak. Change-Id: I5b9da2f256265c9f986ecc6ff4dcd963e096e30b Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index bd4ba82..a07ba40 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -1838,6 +1838,7 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface) tpl_wl_egl_buffer_t *wl_egl_buffer = NULL; tpl_bool_t need_to_release = TPL_FALSE; tpl_bool_t need_to_cancel = TPL_FALSE; + buffer_status_t status = RELEASED; int idx = 0; while (wl_egl_surface->buffer_cnt) { @@ -1859,32 +1860,23 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface) tpl_gmutex_lock(&wl_egl_buffer->mutex); + status = wl_egl_buffer->status; + TPL_DEBUG("[idx:%d] wl_egl_buffer(%p) tbm_surface(%p) status(%s)", idx, wl_egl_buffer, wl_egl_buffer->tbm_surface, - status_to_string[wl_egl_buffer->status]); + status_to_string[status]); - /* ACQUIRED, WAITING_SIGNALED, WAITING_VBLANK, COMMITTED */ - /* It has been acquired but has not yet been released, so this - * buffer must be released. */ - need_to_release = (wl_egl_buffer->status == ACQUIRED || - wl_egl_buffer->status == WAITING_SIGNALED || - wl_egl_buffer->status == WAITING_VBLANK || - wl_egl_buffer->status == COMMITTED); - /* After dequeue, it has not been enqueued yet - * so cancel_dequeue must be performed. */ - need_to_cancel = wl_egl_buffer->status == DEQUEUED; - - if (wl_egl_buffer->status >= ENQUEUED) { + if (status >= ENQUEUED) { tpl_bool_t need_to_wait = TPL_FALSE; tpl_result_t wait_result = TPL_ERROR_NONE; if (!wl_egl_display->use_explicit_sync && - wl_egl_buffer->status < WAITING_VBLANK) + status < WAITING_VBLANK) need_to_wait = TPL_TRUE; if (wl_egl_display->use_explicit_sync && - wl_egl_buffer->status < COMMITTED) + status < COMMITTED) need_to_wait = TPL_TRUE; if (need_to_wait) { @@ -1893,12 +1885,24 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface) &wl_egl_buffer->mutex, 16); /* 16ms */ tpl_gmutex_lock(&wl_egl_display->wl_event_mutex); + + status = wl_egl_buffer->status; + if (wait_result == TPL_ERROR_TIME_OUT) TPL_WARN("timeout occured waiting signaled. wl_egl_buffer(%p)", wl_egl_buffer); } } + /* ACQUIRED, WAITING_SIGNALED, WAITING_VBLANK, COMMITTED */ + /* It has been acquired but has not yet been released, so this + * buffer must be released. */ + need_to_release = (status >= ACQUIRED && status <= COMMITTED); + + /* After dequeue, it has not been enqueued yet + * so cancel_dequeue must be performed. */ + need_to_cancel = (status == DEQUEUED); + if (need_to_release) { tsq_err = tbm_surface_queue_release(wl_egl_surface->tbm_queue, wl_egl_buffer->tbm_surface); @@ -2549,8 +2553,8 @@ __thread_func_waiting_source_dispatch(tpl_gsource *gsource, uint64_t message) wl_egl_buffer, tbm_surface); tpl_gmutex_lock(&wl_egl_buffer->mutex); - tpl_gcond_signal(&wl_egl_buffer->cond); wl_egl_buffer->status = WAITING_VBLANK; + tpl_gcond_signal(&wl_egl_buffer->cond); tpl_gmutex_unlock(&wl_egl_buffer->mutex); tpl_gmutex_lock(&wl_egl_surface->surf_mutex); -- 2.7.4 From a75b0883587faa6a9edd39fb6ead326eb8d2b95c Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 23 Mar 2021 13:50:08 +0900 Subject: [PATCH 08/16] Package version up to 1.8.2 Change-Id: I26be40e9102731927b0b0134745a18d050f39f7d 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 6511342..e3f399c 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 8 -%define TPL_VERSION_PATCH 1 +%define TPL_VERSION_PATCH 2 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 14c3f4b8c3435798703aec311ab68136611042fc Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 24 Mar 2021 16:31:52 +0900 Subject: [PATCH 09/16] Add some logs to trace buffers. Change-Id: I508922c4007f4ce7429f846bae7270ad54bfa364 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index a07ba40..4b29924 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -1283,6 +1283,8 @@ static void __cb_tss_flusher_flush_callback(void *data, TPL_INFO("[BUFFER_FLUSH]", "wl_egl_surface(%p) tbm_queue(%p)", wl_egl_surface, wl_egl_surface->tbm_queue); + _print_buffer_lists(wl_egl_surface); + tsq_err = tbm_surface_queue_flush(wl_egl_surface->tbm_queue); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("Failed to flush tbm_queue(%p)", wl_egl_surface->tbm_queue); @@ -1296,8 +1298,10 @@ static void __cb_tss_flusher_free_flush_callback(void *data, tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)data; tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; - TPL_INFO("[FREE_BUFFER_FLUSH]", "wl_egl_surface(%p) tbm_queue(%p)", - wl_egl_surface, wl_egl_surface->tbm_queue); + TPL_INFO("[FREE_BUFFER_FLUSH]", "wl_egl_surface(%p) tbm_queue(%p)", + wl_egl_surface, wl_egl_surface->tbm_queue); + + _print_buffer_lists(wl_egl_surface); tsq_err = tbm_surface_queue_free_flush(wl_egl_surface->tbm_queue); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { @@ -2633,6 +2637,10 @@ _thread_surface_queue_acquire(tpl_wl_egl_surface_t *wl_egl_surface) if (!wl_egl_buffer->wl_buffer) { TPL_WARN("Failed to create wl_buffer. wl_tbm_client(%p) tbm_surface(%p)", wl_egl_display->wl_tbm_client, tbm_surface); + } else { + TPL_LOG_T("WL_EGL", + "[WL_BUFFER_CREATE] wl_egl_buffer(%p) wl_buffer(%p) tbm_surface(%p)", + wl_egl_buffer, wl_egl_buffer->wl_buffer, tbm_surface); } } @@ -2736,8 +2744,8 @@ __cb_buffer_fenced_release(void *data, _get_tbm_surface_bo_name(tbm_surface)); TPL_LOG_T("WL_EGL", - "[FENCED_RELEASE] wl_buffer(%p) tbm_surface(%p) bo(%d) fence(%d)", - wl_egl_buffer->wl_buffer, tbm_surface, + "[FENCED_RELEASE] wl_egl_buffer(%p) tbm_surface(%p) bo(%d) fence(%d)", + wl_egl_buffer, tbm_surface, _get_tbm_surface_bo_name(tbm_surface), fence); @@ -2786,8 +2794,8 @@ __cb_buffer_immediate_release(void *data, _get_tbm_surface_bo_name(tbm_surface)); TPL_LOG_T("WL_EGL", - "[IMMEDIATE_RELEASE] wl_buffer(%p) tbm_surface(%p) bo(%d)", - wl_egl_buffer->wl_buffer, tbm_surface, + "[IMMEDIATE_RELEASE] wl_egl_buffer(%p) tbm_surface(%p) bo(%d)", + wl_egl_buffer, tbm_surface, _get_tbm_surface_bo_name(tbm_surface)); tsq_err = tbm_surface_queue_release(wl_egl_surface->tbm_queue, @@ -3024,9 +3032,6 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface, TPL_CHECK_ON_FALSE_ASSERT_FAIL(wl_egl_buffer->wl_buffer != NULL, "[FATAL] Failed to create wl_buffer"); - wl_buffer_add_listener((void *)wl_egl_buffer->wl_buffer, - &wl_buffer_release_listener, wl_egl_buffer); - version = wl_proxy_get_version((struct wl_proxy *)wl_surface); /* create presentation feedback and add listener */ @@ -3138,6 +3143,9 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface, wl_egl_buffer->buffer_release, &zwp_release_listner, wl_egl_buffer); TPL_DEBUG("add explicit_sync_release_listener."); } + } else { + wl_buffer_add_listener((void *)wl_egl_buffer->wl_buffer, + &wl_buffer_release_listener, wl_egl_buffer); } wl_surface_commit(wl_surface); -- 2.7.4 From 44623de646cd885ff3bed81426d374549d556cbc Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 24 Mar 2021 17:06:35 +0900 Subject: [PATCH 10/16] Add IO exception checking to reduce warning logs. - When a problem occurs, there are cases where the result of g_source_query_unix_fd is (cond == 0). - Since too many warning logs may be output, exception handling was added to simply ignore it in this case. Change-Id: I694c5916c82d0969a86db8207ad8a64224e2fb25 Signed-off-by: Joonbum Ko --- src/tpl_utils_gthread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tpl_utils_gthread.c b/src/tpl_utils_gthread.c index 65a1db2..b024088 100644 --- a/src/tpl_utils_gthread.c +++ b/src/tpl_utils_gthread.c @@ -189,7 +189,9 @@ _thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) g_mutex_unlock(&thread->thread_mutex); } } - } else { + } + + if (cond && !(cond & G_IO_IN)) { /* When some io errors occur, it is not considered as a critical error. * There may be problems with the screen, but it does not affect the operation. */ TPL_WARN("Invalid GIOCondition occured. tpl_gsource(%p) fd(%d) cond(%d)", -- 2.7.4 From 98e734005b6b0548fc00773f89237d9a27dd4e92 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 24 Mar 2021 19:48:31 +0900 Subject: [PATCH 11/16] Add intended_destroy flag to destroy only when intended. - G_IO_IN may occur in eventfd of finalizer source due to some unexpected errors. In this case, if gsource destroyed in unintended, a fatal problem may occur in thread. - The intended_destroy flag of the newly added to tpl_gsource will help the finalizer source to operate normally only if it is intended G_IO_IN. Change-Id: I6dd6a2de7e3c4ff667f8d639e30783584e6e8cec Signed-off-by: Joonbum Ko --- src/tpl_utils_gthread.c | 55 ++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/tpl_utils_gthread.c b/src/tpl_utils_gthread.c index b024088..47a7041 100644 --- a/src/tpl_utils_gthread.c +++ b/src/tpl_utils_gthread.c @@ -23,10 +23,13 @@ struct _tpl_gsource { tpl_gsource_type_t type; tpl_gsource *finalizer; + tpl_bool_t intended_destroy; void *data; }; +static void +__gsource_remove_and_destroy(tpl_gsource *source); static gpointer _tpl_gthread_init(gpointer data) @@ -175,15 +178,14 @@ _thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) if (gsource->gsource_funcs && gsource->gsource_funcs->dispatch) ret = gsource->gsource_funcs->dispatch(gsource, message); - if (gsource->type == SOURCE_TYPE_FINALIZER) { + if (gsource->type == SOURCE_TYPE_FINALIZER && + gsource->intended_destroy == TPL_TRUE) { tpl_gsource *del_source = (tpl_gsource *)gsource->data; if (!g_source_is_destroyed(&del_source->gsource)) { tpl_gthread *thread = del_source->thread; g_mutex_lock(&thread->thread_mutex); - g_source_remove_unix_fd(&del_source->gsource, del_source->tag); - g_source_destroy(&del_source->gsource); - g_source_unref(&del_source->gsource); + __gsource_remove_and_destroy(del_source); g_cond_signal(&thread->thread_cond); g_mutex_unlock(&thread->thread_mutex); @@ -200,9 +202,7 @@ _thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) if (gsource->type == SOURCE_TYPE_DISPOSABLE || gsource->type == SOURCE_TYPE_FINALIZER) { - g_source_remove_unix_fd(&gsource->gsource, gsource->tag); - g_source_destroy(&gsource->gsource); - g_source_unref(&gsource->gsource); + __gsource_remove_and_destroy(gsource); ret = G_SOURCE_REMOVE; } @@ -265,6 +265,7 @@ tpl_gsource_create(tpl_gthread *thread, void *data, int fd, new_gsource->gsource_funcs = funcs; new_gsource->data = data; new_gsource->type = type; + new_gsource->intended_destroy = TPL_FALSE; if (new_gsource->type == SOURCE_TYPE_NORMAL) { tpl_gsource *finalizer = tpl_gsource_create(thread, new_gsource, -1, @@ -285,6 +286,17 @@ tpl_gsource_create(tpl_gthread *thread, void *data, int fd, return new_gsource; } +static void +__gsource_remove_and_destroy(tpl_gsource *source) +{ + TPL_DEBUG("[GSOURCE_DESTROY] tpl_gsource(%p) type(%d)", + source, source->type); + + g_source_remove_unix_fd(&source->gsource, source->tag); + g_source_destroy(&source->gsource); + g_source_unref(&source->gsource); +} + void tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread) { @@ -294,32 +306,27 @@ tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread) return; } - TPL_DEBUG("[GSOURCE_DESTROY] tpl_gsource(%p) type(%d)", - source, source->type); + if (source->type == SOURCE_TYPE_NORMAL && + source->finalizer) { + tpl_gsource *finalizer = source->finalizer; - if (destroy_in_thread) { - tpl_gthread *thread = source->thread; - if (source->type == SOURCE_TYPE_NORMAL) { + if (destroy_in_thread) { + tpl_gthread *thread = source->thread; g_mutex_lock(&thread->thread_mutex); - tpl_gsource_send_message(source->finalizer, 1); + finalizer->intended_destroy = TPL_TRUE; + tpl_gsource_send_message(finalizer, 1); g_cond_wait(&thread->thread_cond, &thread->thread_mutex); g_mutex_unlock(&thread->thread_mutex); - } - } else { - if (source->type == SOURCE_TYPE_NORMAL && - source->finalizer) { - tpl_gsource *finalize = source->finalizer; - g_source_remove_unix_fd(&finalize->gsource, finalize->tag); - g_source_destroy(&finalize->gsource); - g_source_unref(&finalize->gsource); + } else { + __gsource_remove_and_destroy(finalizer); source->finalizer = NULL; } + } - g_source_remove_unix_fd(&source->gsource, source->tag); - g_source_destroy(&source->gsource); - g_source_unref(&source->gsource); + if (!destroy_in_thread) { + __gsource_remove_and_destroy(source); } } -- 2.7.4 From ab602cc8bceed075aebacd1a344bb03fa68b219c Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 25 Mar 2021 10:36:18 +0900 Subject: [PATCH 12/16] Modified the log output from gsource_finalize. Change-Id: I491f012afb0aba638cb40b3f4f47840dfe36dac4 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 4b29924..6147716 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -298,8 +298,9 @@ __thread_func_tdm_finalize(tpl_gsource *gsource) wl_egl_display = (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource); - TPL_LOG_T("WL_EGL", "tdm_destroy| wl_egl_display(%p) tdm_client(%p)", - wl_egl_display, wl_egl_display->tdm_client); + TPL_LOG_T("WL_EGL", + "tdm_destroy| wl_egl_display(%p) tdm_client(%p) tpl_gsource(%p)", + wl_egl_display, wl_egl_display->tdm_client, gsource); if (wl_egl_display->tdm_client) { tdm_client_destroy(wl_egl_display->tdm_client); @@ -1508,8 +1509,8 @@ __thread_func_surf_finalize(tpl_gsource *gsource) _thread_wl_egl_surface_fini(wl_egl_surface); - TPL_DEBUG("[FINALIZE] gsource(%p) wl_egl_surface(%p)", - gsource, wl_egl_surface); + TPL_DEBUG("[FINALIZE] wl_egl_surface(%p) tpl_gsource(%p)", + wl_egl_surface, gsource); } static tpl_gsource_functions surf_funcs = { -- 2.7.4 From 6f4c654f11ec32009cdef1adac07c4b1b7cf43cb Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 25 Mar 2021 12:46:10 +0900 Subject: [PATCH 13/16] Close release_fence_fd when wl_egl_buffer freed. - The fenced_release event can be dispatched just before the wl_egl_buffer is freed. At this time, release_fence_fd delivered to fenced_release event may leak if it is not closed because wl_egl_buffer cannot be used and is freed. Change-Id: I7584c518b955c83f632b2d5ea281272f8dd2b166 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 6147716..41bc081 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2353,6 +2353,8 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, *release_fence = wl_egl_buffer->release_fence_fd; TPL_DEBUG("wl_egl_surface(%p) wl_egl_buffer(%p) release_fence_fd(%d)", wl_egl_surface, wl_egl_buffer, *release_fence); + + wl_egl_buffer->release_fence_fd = -1; } else { *release_fence = -1; } @@ -3286,6 +3288,11 @@ __cb_wl_egl_buffer_free(tpl_wl_egl_buffer_t *wl_egl_buffer) wl_egl_buffer->buffer_release = NULL; } + if (wl_egl_buffer->release_fence_fd != -1) { + close(wl_egl_buffer->release_fence_fd); + wl_egl_buffer->release_fence_fd = -1; + } + if (wl_egl_buffer->waiting_source) { tpl_gsource_destroy(wl_egl_buffer->waiting_source, TPL_FALSE); wl_egl_buffer->waiting_source = NULL; -- 2.7.4 From acba9102f810718c37af4f7fc0d3e91c385b4e1c Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 25 Mar 2021 12:51:06 +0900 Subject: [PATCH 14/16] Fixed wrong use of NULL checking macro. Change-Id: I9d1d11823a15395dac38360aff25d9c991351f53 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 41bc081..d79e3af 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2028,7 +2028,7 @@ __tpl_wl_egl_surface_set_rotation_capability(tpl_surface_t *surface, wl_egl_surface = (tpl_wl_egl_surface_t *)surface->backend.data; - TPL_CHECK_ON_TRUE_RETURN_VAL(wl_egl_surface, TPL_ERROR_INVALID_PARAMETER); + TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_surface, TPL_ERROR_INVALID_PARAMETER); TPL_INFO("[SET_PREROTATION_CAPABILITY]", "wl_egl_surface(%p) prerotation capability set to [%s]", @@ -2048,7 +2048,7 @@ __tpl_wl_egl_surface_set_post_interval(tpl_surface_t *surface, wl_egl_surface = (tpl_wl_egl_surface_t *)surface->backend.data; - TPL_CHECK_ON_TRUE_RETURN_VAL(wl_egl_surface, TPL_ERROR_INVALID_PARAMETER); + TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_surface, TPL_ERROR_INVALID_PARAMETER); TPL_INFO("[SET_POST_INTERVAL]", "wl_egl_surface(%p) post_interval(%d -> %d)", -- 2.7.4 From 328520a250d372dea039ffa6c5c8a2eef6b44a95 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 25 Mar 2021 13:13:51 +0900 Subject: [PATCH 15/16] Make ready_to_commit to TRUE when acquire_fence_fd is not used. - Missig this line caused a serious problem where wl_surface_commit would not work if acquire_fence_fd was not used. Change-Id: I22b610ad187d90b2d51cb73fa7e4913095997009 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index d79e3af..041f163 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2667,6 +2667,8 @@ _thread_surface_queue_acquire(tpl_wl_egl_surface_t *wl_egl_surface) ready_to_commit = TPL_FALSE; } + } else { + ready_to_commit = TPL_TRUE; } if (ready_to_commit) { -- 2.7.4 From 5c34f864f73625738ae6bad939cf59fac4883ca7 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 25 Mar 2021 13:15:53 +0900 Subject: [PATCH 16/16] Package version up to 1.8.3 Change-Id: Ibf44a2061e89f5b0c9841ebe3a2b9c81b424bd07 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 e3f399c..41e011c 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 8 -%define TPL_VERSION_PATCH 2 +%define TPL_VERSION_PATCH 3 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4