From 8a847d97de5109a4a3a698d9c4c7743310c2d83a Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 31 Jul 2018 16:18:46 +0900 Subject: [PATCH 01/16] Package version up to 1.5.13 Change-Id: I5b929878b1097e9dfe771cbab76099bea732f4d6 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 3347626..3375711 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 5 -%define TPL_VERSION_PATCH 12 +%define TPL_VERSION_PATCH 13 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 43ee41c57a3efe623cc1d8aff7f9adcf46080913 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 9 Aug 2018 14:03:08 +0900 Subject: [PATCH 02/16] tpl_display: Added a new API to get existed display with backend type. - Added API below. Get TPL display object for the given native display. If there's already existing TPL display for the given native display and backend type, then return the existed TPL display object. If the given backend type is TPL_BACKEND_UNKNWON, it behaves the same as tpl_display_get(). Otherwise, it searches for the tpl_display created with the given type. @param type backend type of the given native display. @param native_dpy handle to the native display. @return pointer to the display on success, NULL on failure. tpl_display_t * tpl_display_get_with_backend_type(tpl_backend_type_t type, tpl_handle_t native_dpy); Change-Id: I82f65da4f168f47b2669e5e82f92aae4e77968a0 Signed-off-by: Joonbum Ko --- src/tpl.h | 18 ++++++++++++++++++ src/tpl_display.c | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/tpl.h b/src/tpl.h index 3c6b70b..aaf6998 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -318,6 +318,24 @@ tpl_display_t * tpl_display_get(tpl_handle_t native_dpy); /** + * Get TPL display object for the given native display. + * + * If there's already existing TPL display for the given native display and backend type, + * then return the existed TPL display object. + * + * If the given backend type is TPL_BACKEND_UNKNWON, + * it behaves the same as tpl_display_get(). + * Otherwise, it searches for the tpl_display created with the given type. + * + * @param type backend type of the given native display. + * @param native_dpy handle to the native display. + * @return pointer to the display on success, NULL on failure. + */ +tpl_display_t * +tpl_display_get_with_backend_type(tpl_backend_type_t type, + tpl_handle_t native_dpy); + +/** * Get the native display handle which the given TPL display is created for. * * @param display display to get native handle. diff --git a/src/tpl_display.c b/src/tpl_display.c index f62fcfe..a125a3f 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -89,12 +89,25 @@ tpl_display_get(tpl_handle_t native_dpy) { tpl_display_t *display; - /* Search for an already connected display for the given native display. */ + /* Search for an already created tpl_display for the given native display. */ display = __tpl_runtime_find_display(TPL_BACKEND_UNKNOWN, native_dpy); return display; } +tpl_display_t * +tpl_display_get_with_backend_type(tpl_backend_type_t type, + tpl_handle_t native_dpy) +{ + tpl_display_t *display; + + /* Search for an already created tpl_display + * for the given native display and type. */ + display = __tpl_runtime_find_display(type, native_dpy); + + return display; +} + tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display) { -- 2.7.4 From f15688c950ee6528077fcdd55f9e504416e473df Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 9 Aug 2018 17:43:31 +0900 Subject: [PATCH 03/16] Package version up to 1.5.14 Change-Id: Iad63a60908ac832f806b004984f34b4e53e6be5e 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 3375711..0c092de 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 5 -%define TPL_VERSION_PATCH 13 +%define TPL_VERSION_PATCH 14 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 5669f756b3e43fa3ce7b6d86ccf051b0072df311 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 30 Aug 2018 16:17:02 +0900 Subject: [PATCH 04/16] tpl_wayland_egl_thread: Fixed a bug to prevent tearing. - In the case of vulkan, the meaning of enqueue is not render_done state. Therefore, vulkan surface should check the can_acquire count in the dirty_queue of tbm_queue as well as the draw_done_count of surf_source. Change-Id: Ibdd3e2438ac158fa78d2f897ae83f1cceb289efb Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 7a091aa..7a4764f 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1857,6 +1857,11 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) * to commit or pending, depending on whether vblank_done * after acquire as much as possible. */ while (tbm_surface_queue_can_acquire(surf_source->tbm_queue, 0)) { + /* If its backend is vulkan, it should be checked with draw_done_count. + * Because vulkan surface's [enqueue] doesn't mean render done state */ + if (disp_source->is_vulkan_dpy && surf_source->draw_done_count <= 0) + return; + tsq_err = tbm_surface_queue_acquire(surf_source->tbm_queue, &tbm_surface); if (!tbm_surface || tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("Failed to acquire from tbm_queue(%p)", @@ -1897,6 +1902,9 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) TPL_LOG_T(BACKEND, "[ACQ] tbm_surface(%p) bo(%d)", tbm_surface, tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); + + surf_source->draw_done_count--; + switch (surf_source->swapchain_properties.present_mode) { case TPL_DISPLAY_PRESENT_MODE_IMMEDIATE: _twe_thread_wl_vk_surface_commit(surf_source, tbm_surface); @@ -1980,10 +1988,7 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) if (surf_source->disp_source->is_vulkan_dpy && surf_source->use_sync_fence) { g_mutex_lock(&surf_source->sub_thread_mutex); - while (surf_source->draw_done_count > 0) { - _twe_thread_wl_surface_acquire_and_commit(surf_source); - surf_source->draw_done_count--; - } + _twe_thread_wl_surface_acquire_and_commit(surf_source); g_mutex_unlock(&surf_source->sub_thread_mutex); } else { _twe_thread_wl_surface_acquire_and_commit(surf_source); @@ -2895,7 +2900,6 @@ _twe_thread_sync_draw_source_dispatch(GSource *source, GSourceFunc cb, gpointer if (ret == -1) { TPL_ERR("failed to send acquirable event. tbm_surface(%p)", tbm_surface); - return G_SOURCE_REMOVE; } TRACE_END(); -- 2.7.4 From efcdbcdb59d0fcfedec4d42209be9851e8fcbfc9 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 30 Aug 2018 18:07:25 +0900 Subject: [PATCH 05/16] tpl_wayland_egl_thread: Added enqueue trace callback to tbm_queue. - Tracking dequeued buffers in the in_use_buffers is only from dequeue to enqueue. Change-Id: I0ba57d16fc181898f9ccd7e2c76767f082b83472 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 7a4764f..e399e6b 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1471,6 +1471,24 @@ _twe_surface_cancel_dequeued_buffer(twe_wl_surf_source *surf_source, } static void +_twe_surface_trace_enqueue_buffer(twe_wl_surf_source *surf_source, + tbm_surface_h tbm_surface) +{ + if (!surf_source) { + TPL_ERR("Invalid parameter. twe_surface(%p)", surf_source); + return; + } + + if (surf_source->in_use_buffers) { + g_mutex_lock(&surf_source->surf_mutex); + /* Stop tracking of this canceled tbm_surface */ + __tpl_list_remove_data(surf_source->in_use_buffers, + (void *)tbm_surface, TPL_FIRST, NULL); + g_mutex_unlock(&surf_source->surf_mutex); + } +} + +static void __cb_tbm_queue_reset_callback(tbm_surface_queue_h tbm_queue, void *data) { @@ -1529,6 +1547,9 @@ static void __cb_tbm_queue_trace_callback(tbm_surface_queue_h tbm_queue, case TBM_SURFACE_QUEUE_TRACE_CANCEL_DEQUEUE: _twe_surface_cancel_dequeued_buffer(surf_source, tbm_surface); break; + case TBM_SURFACE_QUEUE_TRACE_ENQUEUE: + _twe_surface_trace_enqueue_buffer(surf_source, tbm_surface); + break; default: break; } @@ -1716,8 +1737,6 @@ _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, } if (surf_source->committed_buffers) { - __tpl_list_remove_data(surf_source->in_use_buffers, - (void *)tbm_surface, TPL_FIRST, NULL); __tpl_list_push_back(surf_source->committed_buffers, tbm_surface); } @@ -1825,9 +1844,6 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, if (surf_source->committed_buffers) { __tpl_list_push_back(surf_source->committed_buffers, tbm_surface); - /* Stop tracking of this released tbm_surface. */ - __tpl_list_remove_data(surf_source->in_use_buffers, - (void *)tbm_surface, TPL_FIRST, NULL); } } -- 2.7.4 From 7abd921b796854447ccd31baa78ccd0d97891359 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 30 Aug 2018 18:10:13 +0900 Subject: [PATCH 06/16] tpl_wayland_egl_thread: Deleted meaningless lines. Change-Id: I51e14837e6daa4fdbab04bda2f80ffab2210906a Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index e399e6b..8a00580 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1442,21 +1442,11 @@ static void _twe_surface_cancel_dequeued_buffer(twe_wl_surf_source *surf_source, tbm_surface_h tbm_surface) { - twe_wl_buffer_info *buf_info = NULL; - if (!surf_source) { TPL_ERR("Invalid parameter. twe_surface(%p)", surf_source); return; } - tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, - (void **)&buf_info); - if (!buf_info) { - TPL_ERR("Failed to get twe_wl_buffer_info from tbm_surface(%p)", - tbm_surface); - return; - } - TPL_LOG_T(BACKEND, "[CANCEL_BUFFER] Stop tracking of canceled tbm_surface(%p)", tbm_surface); -- 2.7.4 From ba7256c4b357984d3e541baeabd756a7ef680880 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 3 Sep 2018 12:01:35 +0900 Subject: [PATCH 07/16] tpl_wayland_egl: Fixed bug related with deadlock. - Using wl_event_mutex in the shm_flush_callback can cause deadlock problem with polling in the wait_dequeuable(). Change-Id: I624bf18e120492cda6825fc84a061e9d27f6a02d Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl.c | 86 +++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index 7bc48bb..e2d8924 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -1459,7 +1459,6 @@ __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) return; } } - pthread_mutex_unlock(&g_list_mutex); } tbm_surface = (tbm_surface_h) data; @@ -1499,12 +1498,9 @@ __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) tbm_surface_internal_unref(tbm_surface); - if (pthread_mutex_lock(&g_list_mutex) == 0) { - /* This wl_buffer should be removed from committed_wl_buffers list. */ - __tpl_list_remove_data(committed_wl_buffers, (void *)proxy, - TPL_FIRST, NULL); - pthread_mutex_unlock(&g_list_mutex); - } + /* This wl_buffer should be removed from committed_wl_buffers list. */ + __tpl_list_remove_data(committed_wl_buffers, (void *)proxy, + TPL_FIRST, NULL); } else { TPL_WARN("No need to release buffer | wl_buffer(%p) tbm_surface(%p) bo(%d)", @@ -1515,6 +1511,8 @@ __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) } else { TPL_ERR("Failed to process release_event. Invalid tbm_surface(%p)", tbm_surface); } + + pthread_mutex_unlock(&g_list_mutex); } static const struct wl_buffer_listener buffer_release_listener = { @@ -1699,22 +1697,12 @@ static void __cb_tizen_surface_shm_flusher_flush_callback(void *data, { tpl_surface_t *surface = data; tpl_wayland_egl_surface_t *wayland_egl_surface; - tpl_wayland_egl_display_t *wayland_egl_display; - int lock_res = 0; TPL_CHECK_ON_NULL_RETURN(surface); wayland_egl_surface = surface->backend.data; TPL_CHECK_ON_NULL_RETURN(wayland_egl_surface); - TPL_CHECK_ON_NULL_RETURN(surface->display); - wayland_egl_display = surface->display->backend.data; - TPL_CHECK_ON_NULL_RETURN(wayland_egl_display); - - TPL_CHECK_ON_NULL_RETURN(wayland_egl_display->wl_dpy); - TPL_CHECK_ON_NULL_RETURN(wayland_egl_display->wl_tbm_event_queue); TPL_CHECK_ON_NULL_RETURN(wayland_egl_surface->tbm_queue); - lock_res = pthread_mutex_lock(&wayland_egl_display->wl_event_mutex); - TPL_LOG_B("WL_EGL", "[FLUSH_CB] tpl_wayland_egl_surface_t(%p)", wayland_egl_surface); @@ -1728,35 +1716,35 @@ static void __cb_tizen_surface_shm_flusher_flush_callback(void *data, * attached buffer. */ - TPL_OBJECT_LOCK(&wayland_egl_surface->base); - if (wayland_egl_surface->attached_buffers) { - while (!__tpl_list_is_empty(wayland_egl_surface->attached_buffers)) { - tbm_surface_queue_error_e tsq_err; - tbm_surface_h tbm_surface = - __tpl_list_pop_front(wayland_egl_surface->attached_buffers, NULL); - tpl_wayland_egl_buffer_t *wayland_egl_buffer = - __tpl_wayland_egl_get_wayland_buffer_from_tbm_surface(tbm_surface); - - TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ RELEASE_CB] BO_NAME:%d", - tbm_bo_export(tbm_surface_internal_get_bo( - tbm_surface, 0))); - - if (wayland_egl_buffer && pthread_mutex_lock(&g_list_mutex) == 0) { - __tpl_list_remove_data(committed_wl_buffers, (void *)wayland_egl_buffer->wl_proxy, - TPL_FIRST, NULL); - pthread_mutex_unlock(&g_list_mutex); - } + if (pthread_mutex_lock(&g_list_mutex) == 0) { + TPL_OBJECT_LOCK(&wayland_egl_surface->base); + if (wayland_egl_surface->attached_buffers) { + while (!__tpl_list_is_empty(wayland_egl_surface->attached_buffers)) { + tbm_surface_queue_error_e tsq_err; + tbm_surface_h tbm_surface = + __tpl_list_pop_front(wayland_egl_surface->attached_buffers, NULL); + tpl_wayland_egl_buffer_t *wayland_egl_buffer = + __tpl_wayland_egl_get_wayland_buffer_from_tbm_surface(tbm_surface); + + TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ RELEASE_CB] BO_NAME:%d", + tbm_bo_export(tbm_surface_internal_get_bo( + tbm_surface, 0))); + + if (wayland_egl_buffer) { + __tpl_list_remove_data(committed_wl_buffers, (void *)wayland_egl_buffer->wl_proxy, + TPL_FIRST, NULL); + } - tbm_surface_internal_unref(tbm_surface); - tsq_err = tbm_surface_queue_release(wayland_egl_surface->tbm_queue, tbm_surface); - if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) - TPL_ERR("Failed to release. tbm_surface(%p) tsq_err(%d)", - tbm_surface, tsq_err); + tbm_surface_internal_unref(tbm_surface); + tsq_err = tbm_surface_queue_release(wayland_egl_surface->tbm_queue, tbm_surface); + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) + TPL_ERR("Failed to release. tbm_surface(%p) tsq_err(%d)", + tbm_surface, tsq_err); + } } + TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); + pthread_mutex_unlock(&g_list_mutex); } - TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); - - if (lock_res == 0) pthread_mutex_unlock(&wayland_egl_display->wl_event_mutex); } static void __cb_tizen_surface_shm_flusher_free_flush_callback(void *data, @@ -1764,28 +1752,16 @@ static void __cb_tizen_surface_shm_flusher_free_flush_callback(void *data, { tpl_surface_t *surface = data; tpl_wayland_egl_surface_t *wayland_egl_surface; - tpl_wayland_egl_display_t *wayland_egl_display; - int lock_res; TPL_CHECK_ON_NULL_RETURN(surface); wayland_egl_surface = surface->backend.data; TPL_CHECK_ON_NULL_RETURN(wayland_egl_surface); - TPL_CHECK_ON_NULL_RETURN(surface->display); - wayland_egl_display = surface->display->backend.data; - TPL_CHECK_ON_NULL_RETURN(wayland_egl_display); - - TPL_CHECK_ON_NULL_RETURN(wayland_egl_display->wl_dpy); - TPL_CHECK_ON_NULL_RETURN(wayland_egl_display->wl_tbm_event_queue); TPL_CHECK_ON_NULL_RETURN(wayland_egl_surface->tbm_queue); - lock_res = pthread_mutex_lock(&wayland_egl_display->wl_event_mutex); - TPL_LOG_B("WL_EGL", "[FLUSH_CB] tpl_wayland_egl_surface_t(%p)", wayland_egl_surface); tbm_surface_queue_free_flush(wayland_egl_surface->tbm_queue); - - if (lock_res == 0) pthread_mutex_unlock(&wayland_egl_display->wl_event_mutex); } static const struct tizen_surface_shm_flusher_listener -- 2.7.4 From 49037db87e7f8e9fac6b84ade0ae8d01abb6a21a Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 3 Sep 2018 14:53:17 +0900 Subject: [PATCH 08/16] Package version up to 1.5.15 Change-Id: I28db1a95f4f2f6043b8e0dd9e0660236ee8d4f7b 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 0c092de..32d62e8 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 5 -%define TPL_VERSION_PATCH 14 +%define TPL_VERSION_PATCH 15 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 85d33705bcbeeb3b7c631cdef3ddfd3cf82c06be Mon Sep 17 00:00:00 2001 From: Harsh Aggarwal Date: Tue, 31 Jul 2018 16:33:53 +0530 Subject: [PATCH 09/16] Add support for VK_KHR_incremental_present: pass wl_surface_damage rects to compositor + added based on wl_surface protocol version + for vulkan the coordindate system is top left (so no inverted y) Change-Id: I00d47db5044ce00c855f898b55a1d15d443be9ae --- src/tpl_wayland_egl_thread.c | 29 ++++++++++++++++++++++++++++- src/tpl_wl_vk_thread.c | 10 ++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 8a00580..24b74c3 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1692,6 +1692,7 @@ _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, twe_wl_buffer_info *buf_info = NULL; struct wl_surface *wl_surface = surf_source->surf; tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; + uint32_t version; tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, (void **)&buf_info); @@ -1701,12 +1702,38 @@ _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, return; } + version = wl_proxy_get_version((struct wl_proxy *)wl_surface); wl_surface_attach(wl_surface, (void *)buf_info->wl_buffer, 0, 0); - wl_surface_damage(wl_surface, 0, 0, + if (buf_info->num_rects < 1 || buf_info->rects == NULL) { + if (version < 4) { + wl_surface_damage(wl_surface, 0, 0, + surf_source->swapchain_properties.width, + surf_source->swapchain_properties.height); + } else { + wl_surface_damage_buffer(wl_surface, 0, 0, surf_source->swapchain_properties.width, surf_source->swapchain_properties.height); + } + } else { + int i; + for (i = 0; i < buf_info->num_rects; i++) { + if (version < 4) { + wl_surface_damage(wl_surface, + buf_info->rects[i * 4 + 0], + buf_info->rects[i * 4 + 1], + buf_info->rects[i * 4 + 2], + buf_info->rects[i * 4 + 3]); + } else { + wl_surface_damage_buffer(wl_surface, + buf_info->rects[i * 4 + 0], + buf_info->rects[i * 4 + 1], + buf_info->rects[i * 4 + 2], + buf_info->rects[i * 4 + 3]); + } + } + } wl_surface_commit(wl_surface); TRACE_MARK("[COMMIT] BO(%d)", diff --git a/src/tpl_wl_vk_thread.c b/src/tpl_wl_vk_thread.c index 09716c6..17ffa5c 100644 --- a/src/tpl_wl_vk_thread.c +++ b/src/tpl_wl_vk_thread.c @@ -354,6 +354,16 @@ __tpl_wl_vk_wsi_surface_enqueue_buffer(tpl_surface_t *surface, return TPL_ERROR_INVALID_PARAMETER; } + /* If there are received region information, + * save it to buf_info in tbm_surface user_data using below API. */ + if (num_rects && rects) { + tpl_result_t ret = TPL_ERROR_NONE; + ret = twe_surface_set_damage_region(tbm_surface, num_rects, rects); + if (ret != TPL_ERROR_NONE) { + TPL_WARN("Failed to set damage region. num_rects(%d) rects(%p)", + num_rects, rects); + } + } tsq_err = tbm_surface_queue_enqueue(wayland_vk_wsi_surface->tbm_queue, tbm_surface); if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE) { -- 2.7.4 From eb989d5d811180d6fda32f1f7a1e333a10516cc7 Mon Sep 17 00:00:00 2001 From: Juyeon Lee Date: Fri, 17 Aug 2018 14:11:23 +0900 Subject: [PATCH 10/16] wayland_egl: Added new APIs related with serial - once dequeue, increase serial number and assign it both on wl_egl_window and twe_wl_buffer_info. - at the same time of wl_surface_commit, deliver the serial to wayland-tbm server by using wayland_tbm_client_set_buffer_serial - New wayland_egl API: unsigned int wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window) egl_window cannot be NULL Change-Id: I8a607be8c44b2a37e8ba90cceae3e3962a128ec9 --- src/tpl_wayland_egl.c | 7 +++++++ src/tpl_wayland_egl_thread.c | 12 +++++++++++- src/wayland-egl/wayland-egl-priv.h | 1 + src/wayland-egl/wayland-egl-tizen.c | 11 +++++++++++ src/wayland-egl/wayland-egl-tizen.h | 3 +++ src/wayland-egl/wayland-egl.c | 2 +- 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index e2d8924..01be90d 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -64,6 +64,7 @@ struct _tpl_wayland_egl_buffer { tpl_bool_t is_new; /* for frontbuffer mode */ tpl_bool_t need_to_release; /* for checking need release */ struct wl_proxy *wl_proxy; /* wl_buffer proxy */ + unsigned int serial; /* increase while dequeue */ }; static tpl_list_t *committed_wl_buffers = NULL; @@ -851,6 +852,9 @@ __tpl_wayland_egl_surface_commit(tpl_surface_t *surface, } } + wayland_tbm_client_set_buffer_serial(wayland_egl_display->wl_tbm_client, + (void *)wayland_egl_buffer->wl_proxy, + wayland_egl_buffer->serial); wl_surface_commit(wl_egl_window->surface); wayland_egl_buffer->need_to_release = TPL_TRUE; @@ -1310,6 +1314,9 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeou wl_display_flush(wayland_egl_display->wl_dpy); + ++wl_egl_window->serial; + wayland_egl_buffer->serial = wl_egl_window->serial; + wayland_egl_buffer->dx = wl_egl_window->dx; wayland_egl_buffer->dy = wl_egl_window->dy; wayland_egl_buffer->width = wl_egl_window->width; diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 24b74c3..7f5808b 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -165,6 +165,9 @@ struct _twe_wl_buffer_info { tbm_surface_h tbm_surface; twe_wl_surf_source *surf_source; + + /* for wayland_tbm_client_set_buffer_serial */ + unsigned int serial; }; struct _vk_sync_draw_source { @@ -1314,6 +1317,8 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->transform = wl_egl_window->transform; buf_info->dx = wl_egl_window->dx; buf_info->dy = wl_egl_window->dy; + ++wl_egl_window->serial; + buf_info->serial = wl_egl_window->serial; } if (buf_info->rects) { @@ -1378,6 +1383,8 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, } buf_info->transform = wl_egl_window->transform; + ++wl_egl_window->serial; + buf_info->serial = wl_egl_window->serial; } else { buf_info->dx = 0; buf_info->dy = 0; @@ -1386,6 +1393,7 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->w_transform = 0; buf_info->w_rotated = TPL_FALSE; buf_info->rotated = TPL_FALSE; + buf_info->serial = 0; } buf_info->sync_timestamp = 0; @@ -1842,7 +1850,9 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, } } } - + wayland_tbm_client_set_buffer_serial(disp_source->wl_tbm_client, + (void *)buf_info->wl_buffer, + buf_info->serial); wl_surface_commit(wl_surface); TRACE_ASYNC_BEGIN((int)tbm_surface, "[COMMIT ~ RELEASE] BO(%d)", diff --git a/src/wayland-egl/wayland-egl-priv.h b/src/wayland-egl/wayland-egl-priv.h index 3e1f08a..0f87713 100644 --- a/src/wayland-egl/wayland-egl-priv.h +++ b/src/wayland-egl/wayland-egl-priv.h @@ -30,6 +30,7 @@ struct wl_egl_window { int frontbuffer_mode; int transform; int window_transform; + unsigned int serial; void *private; void (*destroy_window_callback)(void *); diff --git a/src/wayland-egl/wayland-egl-tizen.c b/src/wayland-egl/wayland-egl-tizen.c index a342cca..d3af986 100644 --- a/src/wayland-egl/wayland-egl-tizen.c +++ b/src/wayland-egl/wayland-egl-tizen.c @@ -139,3 +139,14 @@ wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, egl_window->window_transform = window_transform; } + +unsigned int +wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window) +{ + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return 0; + } + + return egl_window->serial; +} \ No newline at end of file diff --git a/src/wayland-egl/wayland-egl-tizen.h b/src/wayland-egl/wayland-egl-tizen.h index cbc03f6..6c76177 100644 --- a/src/wayland-egl/wayland-egl-tizen.h +++ b/src/wayland-egl/wayland-egl-tizen.h @@ -66,6 +66,9 @@ void wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, int window_transform); +unsigned int +wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window); + #ifdef __cplusplus } #endif diff --git a/src/wayland-egl/wayland-egl.c b/src/wayland-egl/wayland-egl.c index 5c16bcf..cdb8b6a 100644 --- a/src/wayland-egl/wayland-egl.c +++ b/src/wayland-egl/wayland-egl.c @@ -106,6 +106,7 @@ wl_egl_window_create(struct wl_surface *surface, egl_window->frontbuffer_mode = 0; egl_window->transform = 0; egl_window->window_transform = 0; + egl_window->serial = 0; egl_window->private = NULL; egl_window->rotate_callback = NULL; @@ -240,4 +241,3 @@ wl_egl_window_set_window_transform(struct wl_egl_window *egl_window, egl_window->window_transform = window_transform; } - -- 2.7.4 From 2da318d55d4bb6ad95ea66c8fcc8cb7db25c44f9 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 6 Sep 2018 13:27:07 +0900 Subject: [PATCH 11/16] tpl_wayland_egl_thread: Modified some bugs in in_use_buffers list. - For vulkan, get_buffers causes set_wl_buffer_info to be called once for all buffers. Therefore, vulkan does not have to push in_use_buffers when set_wl_buffer_info is called for each buffer first. Change-Id: Ic6fe472d675449906f3033f64807adc2821cec18 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 7f5808b..405648b 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1385,6 +1385,13 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->transform = wl_egl_window->transform; ++wl_egl_window->serial; buf_info->serial = wl_egl_window->serial; + + if (surf_source->in_use_buffers) { + g_mutex_lock(&surf_source->surf_mutex); + __tpl_list_push_back(surf_source->in_use_buffers, + (void *)tbm_surface); + g_mutex_unlock(&surf_source->surf_mutex); + } } else { buf_info->dx = 0; buf_info->dy = 0; @@ -1430,13 +1437,6 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, tbm_surface_internal_set_user_data(tbm_surface, KEY_BUFFER_INFO, buf_info); - if (surf_source->in_use_buffers) { - g_mutex_lock(&surf_source->surf_mutex); - __tpl_list_push_back(surf_source->in_use_buffers, - (void *)tbm_surface); - g_mutex_unlock(&surf_source->surf_mutex); - } - TRACE_MARK("[SET_BUFFER_INFO] BO(%d)", tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); TPL_LOG_T(BACKEND, -- 2.7.4 From 98827f085d65defeda0431bf3ee47edcd516193c Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 6 Sep 2018 13:53:16 +0900 Subject: [PATCH 12/16] tpl_wayland_egl_thread: Inserted the missing code to use sync fd. Change-Id: I4a8434e3c040b4abc9749d027fbcc4691f96d040 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 405648b..0e86b8c 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -3092,6 +3092,8 @@ twe_surface_create_sync_fd(tbm_surface_h tbm_surface) strerror_r(errno, buf, sizeof(buf)); TPL_ERR("Failed to create TBM sync fence: %d(%s)", errno, buf); } + + buf_info->sync_fd = sync_fd; } return sync_fd; -- 2.7.4 From 0df026578f27fdc24ebc3d6df9ede9a11d7f7a45 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 6 Sep 2018 14:16:31 +0900 Subject: [PATCH 13/16] tpl_wayland_egl_thread: Added log and trace mark Change-Id: I32a175d2c6e36c1ad9c068337c32a0db9e201f40 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 0e86b8c..37e222e 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1767,6 +1767,11 @@ _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, /* Presented buffer's sync operating dependent on tdm timeline fence. */ if (buf_info->sync_fd != -1) { + TPL_LOG_T(BACKEND, "[RELEASE_IMMEDIATELY] tbm_surface(%p) bo(%d) sync_fd(%d)", + tbm_surface, tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)), + buf_info->sync_fd); + TRACE_MARK("[RELEASE_IMMEDIATELY] BO(%d)", + tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); tsq_err = tbm_surface_queue_release(surf_source->tbm_queue, tbm_surface); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) TPL_ERR("Failed to release tbm_surface(%p) when vk_surface_commit.", -- 2.7.4 From 61adb6b18ae7f7a1e77d7f4d4ed34a49898758b1 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 12 Sep 2018 09:12:54 +0900 Subject: [PATCH 14/16] tpl_wayland_egl_thread: Enhanced thread safety for get_swapchain_buffers - If wayland events handled in the event thread during get_swapchain_buffers, unexpected problem can occur. Change-Id: I6c6955fd7bb5f9b03372de0c396c1b6e157b92c0 Signed-off-by: Joonbum Ko --- src/tpl_wl_vk_thread.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/tpl_wl_vk_thread.c b/src/tpl_wl_vk_thread.c index 17ffa5c..2242975 100644 --- a/src/tpl_wl_vk_thread.c +++ b/src/tpl_wl_vk_thread.c @@ -522,12 +522,14 @@ __tpl_wl_vk_wsi_surface_get_swapchain_buffers(tpl_surface_t *surface, { tbm_surface_h *swapchain_buffers = NULL; tpl_wayland_vk_wsi_surface_t *wayland_vk_wsi_surface = NULL; + tpl_wayland_vk_wsi_display_t *wayland_vk_wsi_display = NULL; int i; tpl_result_t ret = TPL_ERROR_NONE; TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); TPL_ASSERT(surface->display); + TPL_ASSERT(surface->display->backend.data); TPL_ASSERT(buffers); TPL_ASSERT(buffer_count); @@ -539,23 +541,29 @@ __tpl_wl_vk_wsi_surface_get_swapchain_buffers(tpl_surface_t *surface, return TPL_ERROR_OUT_OF_MEMORY; } - ret = twe_surface_get_swapchain_buffers(wayland_vk_wsi_surface->twe_surface, - swapchain_buffers, buffer_count); - if (ret != TPL_ERROR_NONE) { - TPL_ERR("Failed to get swapchain_buffers. wayland_vk_wsi_surface(%p) twe_surface(%p)", - wayland_vk_wsi_surface, wayland_vk_wsi_surface->twe_surface); - free(swapchain_buffers); - swapchain_buffers = NULL; - return ret; - } + wayland_vk_wsi_display = (tpl_wayland_vk_wsi_display_t *)surface->display->backend.data; - for (i = 0; i < *buffer_count; i++) { - TPL_DEBUG("swapchain_buffers[%d] = tbm_surface(%p) bo(%d)", - i, swapchain_buffers[i], - tbm_bo_export(tbm_surface_internal_get_bo(swapchain_buffers[i], 0))); - } + if (twe_display_lock(wayland_vk_wsi_display->twe_display) == TPL_ERROR_NONE) { + ret = twe_surface_get_swapchain_buffers(wayland_vk_wsi_surface->twe_surface, + swapchain_buffers, buffer_count); + if (ret != TPL_ERROR_NONE) { + TPL_ERR("Failed to get swapchain_buffers. wayland_vk_wsi_surface(%p) twe_surface(%p)", + wayland_vk_wsi_surface, wayland_vk_wsi_surface->twe_surface); + free(swapchain_buffers); + swapchain_buffers = NULL; + return ret; + } - *buffers = swapchain_buffers; + for (i = 0; i < *buffer_count; i++) { + TPL_DEBUG("swapchain_buffers[%d] = tbm_surface(%p) bo(%d)", + i, swapchain_buffers[i], + tbm_bo_export(tbm_surface_internal_get_bo(swapchain_buffers[i], 0))); + } + + *buffers = swapchain_buffers; + + twe_display_unlock(wayland_vk_wsi_display->twe_display); + } return TPL_ERROR_NONE; } -- 2.7.4 From 5e1cf71d1e954c496bfda1293f30f70e2cfca1e7 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 12 Sep 2018 09:17:31 +0900 Subject: [PATCH 15/16] tpl_tbm: Modified to mutex_unlock during waiting for can_dequeue. Change-Id: I4279bc245e391a66cb80285b12ab6efd92df9965 Signed-off-by: Joonbum Ko --- src/tpl_tbm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index aeb8f14..df39918 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -655,8 +655,10 @@ __tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, tbm_queue = (tbm_surface_queue_h)surface->native_handle; + TPL_OBJECT_UNLOCK(surface); if (tbm_surface_queue_can_dequeue(tbm_queue, 1) == 1) tsq_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surface); + TPL_OBJECT_LOCK(surface); if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d", -- 2.7.4 From a4d54e761710fa7e5c3270d8ef7de3ac9a8f3e4f Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 12 Sep 2018 11:44:40 +0900 Subject: [PATCH 16/16] wayland-egl: Added new API to set window serial. - New wayland-egl-tizen API : void wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window, unsigned int serial) - If client use this new API, increaing wl_egl_window->serial will not work at dequeue, and buffer's serial value will be set to the serial that the client passed to this API. '- The serial value client want to set must be incremented whenever there is a change related to the window. - This API should be called before the gl first draw call to ensure the correct one frame in the desired serial. Change-Id: I66266fc58867b331ab253ce5682df10d70176851 Signed-off-by: Joonbum Ko --- src/wayland-egl/wayland-egl-priv.h | 1 + src/wayland-egl/wayland-egl-tizen.c | 14 ++++++++++++++ src/wayland-egl/wayland-egl-tizen.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/wayland-egl/wayland-egl-priv.h b/src/wayland-egl/wayland-egl-priv.h index 0f87713..e729417 100644 --- a/src/wayland-egl/wayland-egl-priv.h +++ b/src/wayland-egl/wayland-egl-priv.h @@ -38,6 +38,7 @@ struct wl_egl_window { void (*rotate_callback)(struct wl_egl_window *, void *); int (*get_rotation_capability)(struct wl_egl_window *, void *); void (*set_frontbuffer_callback)(struct wl_egl_window *, void *, int); + void (*set_window_serial_callback)(struct wl_egl_window *, void *, unsigned int); }; #ifdef __cplusplus diff --git a/src/wayland-egl/wayland-egl-tizen.c b/src/wayland-egl/wayland-egl-tizen.c index d3af986..d697efd 100644 --- a/src/wayland-egl/wayland-egl-tizen.c +++ b/src/wayland-egl/wayland-egl-tizen.c @@ -149,4 +149,18 @@ wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window) } return egl_window->serial; +} + +void +wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window, + unsigned int serial) +{ + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return; + } + + if (egl_window->set_window_serial_callback) + egl_window->set_window_serial_callback(egl_window, egl_window->private, + serial); } \ No newline at end of file diff --git a/src/wayland-egl/wayland-egl-tizen.h b/src/wayland-egl/wayland-egl-tizen.h index 6c76177..a1d0ee6 100644 --- a/src/wayland-egl/wayland-egl-tizen.h +++ b/src/wayland-egl/wayland-egl-tizen.h @@ -69,6 +69,10 @@ wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, unsigned int wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window); +void +wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window, + unsigned int serial); + #ifdef __cplusplus } #endif -- 2.7.4