From 80dd92be4a4af352449a0a13870fcd61ff4537c5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 27 May 2021 20:14:47 +0900 Subject: [PATCH] Clarified thread message and corrected some bugs. Change-Id: I63fec57eb66104c87757cf5f665e8160859bddc8 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 36 +++++++++++++++++++--------- src/tpl_wl_vk_thread.c | 64 +++++++++++++++++++++++++++++++------------------ 2 files changed, 66 insertions(+), 34 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index d6f37f2..c564ae1 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -68,6 +68,12 @@ struct _tpl_wl_egl_display { struct zwp_linux_explicit_synchronization_v1 *explicit_sync; /* for explicit fence sync */ }; +typedef enum surf_message { + NONE_MESSAGE = 0, + INIT_SURFACE, + ACQUIRABLE, +} surf_message; + struct _tpl_wl_egl_surface { tpl_gsource *surf_source; @@ -114,6 +120,8 @@ struct _tpl_wl_egl_surface { tpl_gmutex surf_mutex; tpl_gcond surf_cond; + surf_message sent_message; + /* for waiting draw done */ tpl_bool_t use_render_done_fence; tpl_bool_t is_activated; @@ -1415,9 +1423,11 @@ __cb_tbm_queue_acquirable_callback(tbm_surface_queue_h tbm_queue, TPL_CHECK_ON_NULL_RETURN(wl_egl_surface); tpl_gmutex_lock(&wl_egl_surface->surf_mutex); - - tpl_gsource_send_message(wl_egl_surface->surf_source, 2); - + if (wl_egl_surface->sent_message == NONE_MESSAGE) { + wl_egl_surface->sent_message = ACQUIRABLE; + tpl_gsource_send_message(wl_egl_surface->surf_source, + wl_egl_surface->sent_message); + } tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); } /* -- END -- tbm_surface_queue callback funstions */ @@ -1512,22 +1522,22 @@ __thread_func_surf_dispatch(tpl_gsource *gsource, uint64_t message) wl_egl_surface = (tpl_wl_egl_surface_t *)tpl_gsource_get_data(gsource); - /* Initialize surface */ - if (message == 1) { - tpl_gmutex_lock(&wl_egl_surface->surf_mutex); + tpl_gmutex_lock(&wl_egl_surface->surf_mutex); + if (message == INIT_SURFACE) { /* Initialize surface */ TPL_DEBUG("wl_egl_surface(%p) initialize message received!", wl_egl_surface); _thread_wl_egl_surface_init(wl_egl_surface); tpl_gcond_signal(&wl_egl_surface->surf_cond); - tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); - } else if (message == 2) { - tpl_gmutex_lock(&wl_egl_surface->surf_mutex); + } else if (message == ACQUIRABLE) { /* Acquirable */ TPL_DEBUG("wl_egl_surface(%p) acquirable message received!", wl_egl_surface); _thread_surface_queue_acquire(wl_egl_surface); - tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); } + wl_egl_surface->sent_message = NONE_MESSAGE; + + tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); + return TPL_TRUE; } @@ -1627,6 +1637,8 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface) wl_egl_surface->commit_sync.fd = -1; wl_egl_surface->presentation_sync.fd = -1; + wl_egl_surface->sent_message = NONE_MESSAGE; + { int i = 0; for (i = 0; i < BUFFER_ARRAY_SIZE; i++) @@ -1669,7 +1681,9 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface) /* Initialize in thread */ tpl_gmutex_lock(&wl_egl_surface->surf_mutex); - tpl_gsource_send_message(wl_egl_surface->surf_source, 1); + wl_egl_surface->sent_message = INIT_SURFACE; + tpl_gsource_send_message(wl_egl_surface->surf_source, + wl_egl_surface->sent_message); tpl_gcond_wait(&wl_egl_surface->surf_cond, &wl_egl_surface->surf_mutex); tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); diff --git a/src/tpl_wl_vk_thread.c b/src/tpl_wl_vk_thread.c index 20baea3..4ae5b55 100644 --- a/src/tpl_wl_vk_thread.c +++ b/src/tpl_wl_vk_thread.c @@ -82,6 +82,14 @@ struct _tpl_wl_vk_swapchain { tpl_util_atomic_uint ref_cnt; }; +typedef enum surf_message { + NONE_MESSAGE = 0, + INIT_SURFACE, + CREATE_QUEUE, + DESTROY_QUEUE, + ACQUIRABLE, +} surf_message; + struct _tpl_wl_vk_surface { tpl_gsource *surf_source; @@ -113,6 +121,8 @@ struct _tpl_wl_vk_surface { tpl_bool_t reset; /* TRUE if queue reseted by external */ tpl_bool_t vblank_done; + surf_message sent_message; + int post_interval; }; @@ -1101,15 +1111,13 @@ __thread_func_surf_dispatch(tpl_gsource *gsource, uint64_t message) wl_vk_surface = (tpl_wl_vk_surface_t *)tpl_gsource_get_data(gsource); - if (message == 1) { /* Initialize surface */ - tpl_gmutex_lock(&wl_vk_surface->surf_mutex); + tpl_gmutex_lock(&wl_vk_surface->surf_mutex); + if (message == INIT_SURFACE) { /* Initialize surface */ TPL_DEBUG("wl_vk_surface(%p) initialize message received!", wl_vk_surface); _thread_wl_vk_surface_init(wl_vk_surface); - tpl_gcond_signal(&wl_vk_surface->surf_cond); - tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); - } else if (message == 2) { /* Create tbm_surface_queue */ - tpl_gmutex_lock(&wl_vk_surface->surf_mutex); + tpl_gcond_signal(&wl_vk_surface->surf_cond); + } else if (message == CREATE_QUEUE) { /* Create tbm_surface_queue */ TPL_DEBUG("wl_vk_surface(%p) queue creation message received!", wl_vk_surface); if (_thread_swapchain_create_tbm_queue(wl_vk_surface) @@ -1118,9 +1126,12 @@ __thread_func_surf_dispatch(tpl_gsource *gsource, uint64_t message) wl_vk_surface); } tpl_gcond_signal(&wl_vk_surface->surf_cond); - tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); - } else if (message == 3) { /* Acquirable message */ - tpl_gmutex_lock(&wl_vk_surface->surf_mutex); + } else if (message == DESTROY_QUEUE) { /* swapchain destroy */ + TPL_DEBUG("wl_vk_surface(%p) swapchain destroy message received!", + wl_vk_surface); + _thread_swapchain_destroy_tbm_queue(wl_vk_surface); + tpl_gcond_signal(&wl_vk_surface->surf_cond); + } else if (message == ACQUIRABLE) { /* Acquirable message */ TPL_DEBUG("wl_vk_surface(%p) acquirable message received!", wl_vk_surface); if (_thread_surface_queue_acquire(wl_vk_surface) @@ -1128,16 +1139,13 @@ __thread_func_surf_dispatch(tpl_gsource *gsource, uint64_t message) TPL_ERR("Failed to acquire from tbm_queue. wl_vk_surface(%p)", wl_vk_surface); } - tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); - } else if (message == 4) { /* swapchain destroy */ - tpl_gmutex_lock(&wl_vk_surface->surf_mutex); - TPL_DEBUG("wl_vk_surface(%p) swapchain destroy message received!", - wl_vk_surface); - _thread_swapchain_destroy_tbm_queue(wl_vk_surface); - tpl_gcond_signal(&wl_vk_surface->surf_cond); - tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); } + /* init to NONE_MESSAGE */ + wl_vk_surface->sent_message = NONE_MESSAGE; + + tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); + return TPL_TRUE; } @@ -1214,6 +1222,8 @@ __tpl_wl_vk_surface_init(tpl_surface_t *surface) wl_vk_surface->vblank = NULL; wl_vk_surface->surface_sync = NULL; + wl_vk_surface->sent_message = NONE_MESSAGE; + wl_vk_surface->post_interval = surface->post_interval; { @@ -1230,7 +1240,9 @@ __tpl_wl_vk_surface_init(tpl_surface_t *surface) /* Initialize in thread */ tpl_gmutex_lock(&wl_vk_surface->surf_mutex); - tpl_gsource_send_message(wl_vk_surface->surf_source, 1); + wl_vk_surface->sent_message = INIT_SURFACE; + tpl_gsource_send_message(wl_vk_surface->surf_source, + wl_vk_surface->sent_message); tpl_gcond_wait(&wl_vk_surface->surf_cond, &wl_vk_surface->surf_mutex); tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); @@ -1389,9 +1401,11 @@ __cb_tbm_queue_acquirable_callback(tbm_surface_queue_h tbm_queue, TPL_CHECK_ON_NULL_RETURN(wl_vk_surface); tpl_gmutex_lock(&wl_vk_surface->surf_mutex); - - tpl_gsource_send_message(wl_vk_surface->surf_source, 3); - + if (wl_vk_surface->sent_message == NONE_MESSAGE) { + wl_vk_surface->sent_message = ACQUIRABLE; + tpl_gsource_send_message(wl_vk_surface->surf_source, + wl_vk_surface->sent_message); + } tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); } @@ -1580,7 +1594,9 @@ __tpl_wl_vk_surface_create_swapchain(tpl_surface_t *surface, tpl_gmutex_lock(&wl_vk_surface->surf_mutex); /* send swapchain create tbm_queue message */ - tpl_gsource_send_message(wl_vk_surface->surf_source, 2); + wl_vk_surface->sent_message = CREATE_QUEUE; + tpl_gsource_send_message(wl_vk_surface->surf_source, + wl_vk_surface->sent_message); tpl_gcond_wait(&wl_vk_surface->surf_cond, &wl_vk_surface->surf_mutex); tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); @@ -1664,7 +1680,9 @@ __tpl_wl_vk_surface_destroy_swapchain(tpl_surface_t *surface) _tpl_wl_vk_surface_buffer_clear(wl_vk_surface); tpl_gmutex_lock(&wl_vk_surface->surf_mutex); - tpl_gsource_send_message(wl_vk_surface->surf_source, 4); + wl_vk_surface->sent_message = DESTROY_QUEUE; + tpl_gsource_send_message(wl_vk_surface->surf_source, + wl_vk_surface->sent_message); tpl_gcond_wait(&wl_vk_surface->surf_cond, &wl_vk_surface->surf_mutex); tpl_gmutex_unlock(&wl_vk_surface->surf_mutex); -- 2.7.4