From c34883b51af32f6756daf09e8daea5412ec0a24e Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 9 Jan 2018 20:10:09 +0900 Subject: [PATCH 01/16] Fixed some build warnings. Change-Id: Ia3b45e382cafe02e25f9aaf777338dbd4f9e191e Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 5 +++-- src/tpl_wl_egl_thread.c | 2 +- src/tpl_wl_vk_thread.c | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index d800c4c..4ae5313 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -2608,7 +2608,7 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) } if (surf_source->vk_sub_thread) { - TPL_DEBUG("vk_sub_thread(%d) exit.", surf_source->vk_sub_thread); + TPL_DEBUG("vk_sub_thread(%p) exit.", surf_source->vk_sub_thread); g_mutex_lock(&surf_source->sub_thread_mutex); g_main_loop_quit(surf_source->vk_sub_loop); @@ -2837,7 +2837,8 @@ twe_surface_commit_without_enqueue(twe_surface_h twe_surface, 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."); + TPL_WARN("surf_source(%p) native window is already destroyed.", + surf_source); TPL_OBJECT_UNLOCK(&surf_source->obj); } diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index b7e2128..e4fa659 100644 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -698,7 +698,7 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, surface->frontbuffer, tbm_bo_export(tbm_surface_internal_get_bo( surface->frontbuffer, 0))); - TRACE_ASYNC_BEGIN(surface->frontbuffer, + TRACE_ASYNC_BEGIN((int)surface->frontbuffer, "[DEQ]~[ENQ] BO_NAME:%d", tbm_bo_export(tbm_surface_internal_get_bo( surface->frontbuffer, 0))); diff --git a/src/tpl_wl_vk_thread.c b/src/tpl_wl_vk_thread.c index f670382..6f96b2f 100644 --- a/src/tpl_wl_vk_thread.c +++ b/src/tpl_wl_vk_thread.c @@ -433,12 +433,13 @@ __tpl_wl_vk_wsi_surface_dequeue_buffer(tpl_surface_t *surface, lock_ret = twe_display_lock(wayland_vk_wsi_display->twe_display); if (res == TPL_ERROR_TIME_OUT) { - TPL_ERR("Failed to get buffer during timeout_ns(%u)", timeout_ns); + TPL_ERR("Failed to get buffer during timeout_ns(%" PRIu64 ")", + timeout_ns); if (lock_ret == TPL_ERROR_NONE) twe_display_unlock(wayland_vk_wsi_display->twe_display); return NULL; } else if (res != TPL_ERROR_NONE) { - TPL_ERR("Invalid parameter. twe_surface(%p) timeout_ns(%u)", + TPL_ERR("Invalid parameter. twe_surface(%p) timeout_ns(%" PRIu64 ")", wayland_vk_wsi_surface->twe_surface, timeout_ns); if (lock_ret == TPL_ERROR_NONE) twe_display_unlock(wayland_vk_wsi_display->twe_display); -- 2.7.4 From 0459ee298e0e1941b08c7d6e7563f228c5e57e7b Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 16 Jan 2018 13:58:03 +0900 Subject: [PATCH 02/16] tpl_wayland_egl_thread: Registered dequeueable callback to tbm_queue. - Signal to free_queue_cond when dequeuable callback is called. - wl_buffer release callback does not signal to free_queue_cond, and if dequeuable callback is called when tbm_surface_queue_release() is called, signal to free_queue_cond. Change-Id: I52d898f37ef6dc5074e98690399a04116869d177 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 58 +++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 4ae5313..6c4f1ef 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1273,8 +1273,6 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer) twe_wl_surf_source *surf_source = buf_info->surf_source; tbm_surface_queue_error_e tsq_err; - g_mutex_lock(&surf_source->free_queue_mutex); - tsq_err = tbm_surface_queue_release(surf_source->tbm_queue, tbm_surface); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) @@ -1301,9 +1299,6 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer) tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); tbm_surface_internal_unref(tbm_surface); - g_cond_signal(&surf_source->free_queue_cond); - g_mutex_unlock(&surf_source->free_queue_mutex); - return; } @@ -1543,16 +1538,23 @@ __cb_tbm_queue_reset_callback(tbm_surface_queue_h tbm_queue, { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)data; - if (surf_source && !g_source_is_destroyed(&surf_source->gsource)) { - surf_source->swapchain_properties.width = - tbm_surface_queue_get_width(tbm_queue); - surf_source->swapchain_properties.height = - tbm_surface_queue_get_height(tbm_queue); - surf_source->swapchain_properties.buffer_count = - tbm_surface_queue_get_size(tbm_queue); - surf_source->format = tbm_surface_queue_get_format(tbm_queue); + if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { + TPL_ERR("Invalid parameter. surf_source(%p)", surf_source); + return; } + surf_source->swapchain_properties.width = + tbm_surface_queue_get_width(tbm_queue); + surf_source->swapchain_properties.height = + tbm_surface_queue_get_height(tbm_queue); + surf_source->swapchain_properties.buffer_count = + tbm_surface_queue_get_size(tbm_queue); + surf_source->format = tbm_surface_queue_get_format(tbm_queue); + + g_mutex_lock(&surf_source->free_queue_mutex); + g_cond_signal(&surf_source->free_queue_cond); + g_mutex_unlock(&surf_source->free_queue_mutex); + TPL_LOG_T(BACKEND, "tbm_queue(%p) has been reset!", tbm_queue); } @@ -1594,6 +1596,25 @@ static void __cb_tbm_queue_trace_callback(tbm_surface_queue_h tbm_queue, } } +static void __cb_tbm_queue_dequeueable_callback(tbm_surface_queue_h tbm_queue, + void *data) +{ + twe_wl_surf_source *surf_source = (twe_wl_surf_source *)data; + + if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { + TPL_ERR("Invalid parameter. surf_source(%p)", surf_source); + return; + } + + g_mutex_lock(&surf_source->free_queue_mutex); + + TPL_LOG_T(BACKEND, "[DEQUEUEABLE_CB] surf_source(%p) tbm_queue(%p)", + surf_source, surf_source->tbm_queue); + + g_cond_signal(&surf_source->free_queue_cond); + g_mutex_unlock(&surf_source->free_queue_mutex); +} + static void _twe_thread_wl_vk_surface_commit(twe_wl_surf_source *surf_source, tbm_surface_h tbm_surface); @@ -2141,7 +2162,7 @@ _twe_surface_create_tbm_queue(twe_wl_surf_source *source, if (tbm_surface_queue_add_reset_cb(tbm_queue, __cb_tbm_queue_reset_callback, - NULL) != TBM_SURFACE_QUEUE_ERROR_NONE) { + (void *)source) != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("Failed to register reset callback to tbm_surface_queue(%p)", tbm_queue); tbm_surface_queue_destroy(tbm_queue); @@ -2553,6 +2574,15 @@ twe_surface_create_swapchain(twe_surface_h twe_surface, return TPL_ERROR_INVALID_OPERATION; } + if (tbm_surface_queue_add_dequeuable_cb(surf_source->tbm_queue, + __cb_tbm_queue_dequeueable_callback, + (void *)surf_source) != TBM_SURFACE_QUEUE_ERROR_NONE) { + TPL_ERR("Failed to register dequeueable callback to tbm_surface_queue(%p)", + surf_source->tbm_queue); + tbm_surface_queue_destroy(surf_source->tbm_queue); + return TPL_ERROR_INVALID_OPERATION; + } + if (present_mode == TPL_DISPLAY_PRESENT_MODE_FIFO || present_mode == TPL_DISPLAY_PRESENT_MODE_FIFO_RELAXED) { surf_source->vblank_waiting_buffers = __tpl_list_alloc(); -- 2.7.4 From b7c050ba63dc9f6940a65798211e4d6742b27b31 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 16 Jan 2018 15:36:58 +0900 Subject: [PATCH 03/16] tpl_wayland_egl_thread: Changed to use GMutex instead of tpl_object of the disp_source. Change-Id: Ieec00366d2084cfb9b77ed518bac7c3fb8c7d1b2 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 6c4f1ef..1a69167 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -75,7 +75,7 @@ struct _twe_wl_disp_source { tpl_bool_t prepared; twe_del_source *disp_del_source; twe_thread *thread; - tpl_object_t obj; + GMutex wl_event_mutex; /* TODO : surface list */ }; @@ -634,7 +634,7 @@ _twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data) return G_SOURCE_REMOVE; } - TPL_OBJECT_LOCK(&disp_source->obj); + 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, disp_source->ev_queue) == -1) { @@ -643,7 +643,7 @@ _twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data) } wl_display_flush(disp_source->disp); - TPL_OBJECT_UNLOCK(&disp_source->obj); + g_mutex_unlock(&disp_source->wl_event_mutex); return G_SOURCE_CONTINUE; } @@ -651,11 +651,7 @@ _twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data) static void _twe_thread_wl_disp_finalize(GSource *source) { - twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source; - - TPL_LOG_T(BACKEND, "finalize| disp_source(%p)", disp_source); - - __tpl_object_fini(&disp_source->obj); + TPL_LOG_T(BACKEND, "finalize| disp_source(%p)", source); return; } @@ -917,7 +913,7 @@ _twe_thread_wl_disp_source_destroy(void *source) } g_mutex_lock(&_twe_ctx->thread_mutex); - TPL_OBJECT_LOCK(&disp_source->obj); + g_mutex_lock(&disp_source->wl_event_mutex); /* If disp_source is in prepared state, cancel it */ if (disp_source->prepared) { @@ -931,11 +927,13 @@ _twe_thread_wl_disp_source_destroy(void *source) } wl_event_queue_destroy(disp_source->ev_queue); - TPL_OBJECT_UNLOCK(&disp_source->obj); + g_mutex_unlock(&disp_source->wl_event_mutex); TPL_LOG_T(BACKEND, "[DEL] twe_display(%p) wl_display(%p)", disp_source, disp_source->disp); + g_mutex_clear(&disp_source->wl_event_mutex); + g_source_remove_poll(&disp_source->gsource, &disp_source->gfd); g_source_destroy(&disp_source->gsource); g_source_unref(&disp_source->gsource); @@ -981,7 +979,7 @@ twe_display_add(twe_thread* thread, source->gfd.fd = wl_display_get_fd(display); source->gfd.events = G_IO_IN | G_IO_ERR; source->gfd.revents = 0; - __tpl_object_init(&source->obj, TPL_OBJECT_DISPLAY, NULL); + g_mutex_init(&source->wl_event_mutex); if (backend == TPL_BACKEND_WAYLAND_VULKAN_WSI || backend == TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD) { @@ -1062,7 +1060,9 @@ twe_display_lock(twe_display_h display) return TPL_ERROR_INVALID_PARAMETER; } - return TPL_OBJECT_LOCK(&disp_source->obj); + g_mutex_lock(&disp_source->wl_event_mutex); + + return TPL_ERROR_NONE; } void @@ -1074,7 +1074,7 @@ twe_display_unlock(twe_display_h display) return; } - TPL_OBJECT_UNLOCK(&disp_source->obj); + g_mutex_unlock(&disp_source->wl_event_mutex); } tpl_result_t @@ -2240,7 +2240,7 @@ _twe_thread_wl_surf_source_destroy(void *source) g_mutex_lock(&_twe_ctx->thread_mutex); - TPL_OBJECT_LOCK(&disp_source->obj); + g_mutex_lock(&disp_source->wl_event_mutex); if (surf_source->in_use_buffers) { __tpl_list_free(surf_source->in_use_buffers, @@ -2298,7 +2298,7 @@ _twe_thread_wl_surf_source_destroy(void *source) surf_source->surf = NULL; } - TPL_OBJECT_UNLOCK(&disp_source->obj); + g_mutex_unlock(&disp_source->wl_event_mutex); g_cond_clear(&surf_source->free_queue_cond); g_mutex_clear(&surf_source->free_queue_mutex); -- 2.7.4 From 169c9152399e169cc74005c8c14ed9a52e126467 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Wed, 17 Jan 2018 11:40:16 +0900 Subject: [PATCH 04/16] tpl_wayland_egl_thread: Changed to use GMutex instead of tpl_object of the surf_source. Change-Id: I05bdca4011f142fd39db939de49a9d83db55259c Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 54 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 1a69167..cc3e2e8 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -104,7 +104,6 @@ struct _twe_wl_surf_source { } swapchain_properties; tpl_surface_cb_func_t rotate_cb; tpl_bool_t rotation_capability; - tpl_object_t obj; /* for mutex lock */ tpl_list_t *committed_buffers; tpl_list_t *in_use_buffers; tpl_list_t *vblank_waiting_buffers; /* for FIFO/FIFO_RELAXED modes */ @@ -117,6 +116,8 @@ struct _twe_wl_surf_source { twe_wl_disp_source *disp_source; twe_del_source *surf_del_source; + GMutex surf_mutex; + GMutex free_queue_mutex; GCond free_queue_cond; @@ -1123,12 +1124,12 @@ __cb_destroy_callback(void *private) if (surf_source) { TPL_LOG_T(BACKEND, "[DESTROY_CB] wl_egl_window(%p) surf_source(%p)", surf_source->wl_egl_window, surf_source); - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); surf_source->wl_egl_window->private = NULL; surf_source->wl_egl_window = NULL; surf_source->surf = NULL; surf_source->is_destroying = TPL_TRUE; - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -1279,11 +1280,11 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer) TPL_ERR("tbm_surface(%p) tsq_err(%d)", tbm_surface, tsq_err); if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_remove_data(surf_source->committed_buffers, (void *)tbm_surface, TPL_FIRST, NULL); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } buf_info->need_to_release = TPL_FALSE; @@ -1308,11 +1309,11 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer) g_mutex_lock(&surf_source->free_queue_mutex); if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_remove_data(surf_source->committed_buffers, (void *)tbm_surface, TPL_FIRST, NULL); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } TRACE_MARK("[RELEASE] BO(%d)", @@ -1389,10 +1390,10 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->sync_fd = -1; if (surf_source->in_use_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_push_back(surf_source->in_use_buffers, (void *)tbm_surface); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } TRACE_MARK("[SET_BUFFER_INFO] BO(%d)", @@ -1485,10 +1486,10 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info); if (surf_source->in_use_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_push_back(surf_source->in_use_buffers, (void *)tbm_surface); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } TRACE_MARK("[SET_BUFFER_INFO] BO(%d)", @@ -1524,11 +1525,11 @@ _twe_surface_cancel_dequeued_buffer(twe_wl_surf_source *surf_source, tbm_surface); if (surf_source->in_use_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + 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); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -1645,7 +1646,7 @@ __cb_tdm_client_wait_vblank(tdm_client_vblank *vblank, tdm_error error, if (!disp_source->is_vulkan_dpy) _twe_thread_wl_surface_acquire_and_commit(surf_source); else { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); switch (surf_source->swapchain_properties.present_mode) { case TPL_DISPLAY_PRESENT_MODE_MAILBOX: if (surf_source->draw_done_buffer) { @@ -1686,7 +1687,7 @@ __cb_tdm_client_wait_vblank(tdm_client_vblank *vblank, tdm_error error, break; } - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -1928,7 +1929,7 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, (void **)&buf_info); - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); if (!disp_source->is_vulkan_dpy) { /* wayland_egl */ TPL_LOG_T(BACKEND, "[ACQ] tbm_surface(%p) bo(%d)", tbm_surface, @@ -1996,7 +1997,7 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) break; } } - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -2048,8 +2049,6 @@ _twe_thread_wl_surface_finalize(GSource *source) close(surf_source->event_fd); surf_source->event_fd = -1; - __tpl_object_fini(&surf_source->obj); - return; } @@ -2242,6 +2241,8 @@ _twe_thread_wl_surf_source_destroy(void *source) g_mutex_lock(&disp_source->wl_event_mutex); + g_mutex_lock(&surf_source->surf_mutex); + if (surf_source->in_use_buffers) { __tpl_list_free(surf_source->in_use_buffers, (tpl_free_func_t)__cb_buffer_remove_from_list); @@ -2298,6 +2299,9 @@ _twe_thread_wl_surf_source_destroy(void *source) surf_source->surf = NULL; } + g_mutex_unlock(&surf_source->surf_mutex); + g_mutex_clear(&surf_source->surf_mutex); + g_mutex_unlock(&disp_source->wl_event_mutex); g_cond_clear(&surf_source->free_queue_cond); @@ -2397,8 +2401,6 @@ twe_surface_add(twe_thread* thread, source->vk_sub_thread = NULL; source->draw_done_count = 0; - __tpl_object_init(&source->obj, TPL_OBJECT_SURFACE, NULL); - if (!disp_source->is_vulkan_dpy) { struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)native_handle; @@ -2430,6 +2432,8 @@ twe_surface_add(twe_thread* thread, g_source_attach(&source->gsource, g_main_loop_get_context(ctx->twe_loop)); + g_mutex_init(&source->surf_mutex); + g_mutex_init(&source->free_queue_mutex); g_cond_init(&source->free_queue_cond); @@ -2662,7 +2666,7 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) } if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); while (!__tpl_list_is_empty(surf_source->committed_buffers)) { tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; tbm_surface_h tbm_surface = @@ -2677,7 +2681,7 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) TPL_ERR("Failed to release. tbm_surface(%p) tsq_err(%d)", tbm_surface, tsq_err); } - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } if (surf_source->tbm_queue) { @@ -2863,13 +2867,13 @@ twe_surface_commit_without_enqueue(twe_surface_h twe_surface, return; } - TPL_OBJECT_LOCK(&surf_source->obj); + 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); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } static gboolean -- 2.7.4 From ce6410059a19cdf3ad442d767ae1dee2a3665d6c Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Wed, 17 Jan 2018 13:40:56 +0900 Subject: [PATCH 05/16] tpl_wl_vk_thread: Fixed the locking mechanism in dequeueable. Change-Id: Id63e92a3990a7f286d415760ed60aed93512ae0b Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 14 +++++++--- src/tpl_wl_vk_thread.c | 66 ++++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index cc3e2e8..03e6324 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -3086,6 +3086,7 @@ tpl_result_t twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; + twe_wl_disp_source *disp_source = NULL; gint64 end_time; if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { @@ -3093,8 +3094,7 @@ twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) return TPL_ERROR_INVALID_PARAMETER; } - /* wait until dequeueable */ - g_mutex_lock(&surf_source->free_queue_mutex); + disp_source = surf_source->disp_source; if (timeout_ns != UINT64_MAX) end_time = g_get_monotonic_time() + (timeout_ns / 1000); @@ -3102,12 +3102,18 @@ twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) while (!tbm_surface_queue_can_dequeue(surf_source->tbm_queue, 0)) { gboolean ret = FALSE; + g_mutex_unlock(&disp_source->wl_event_mutex); + + /* wait until dequeueable */ + g_mutex_lock(&surf_source->free_queue_mutex); + if (timeout_ns != UINT64_MAX) { ret = g_cond_wait_until(&surf_source->free_queue_cond, &surf_source->free_queue_mutex, end_time); if (ret == FALSE) { TPL_WARN("time out to wait dequeueable."); + g_mutex_lock(&disp_source->wl_event_mutex); g_mutex_unlock(&surf_source->free_queue_mutex); return TPL_ERROR_TIME_OUT; } @@ -3115,10 +3121,10 @@ twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) g_cond_wait(&surf_source->free_queue_cond, &surf_source->free_queue_mutex); } + g_mutex_unlock(&surf_source->free_queue_mutex); + g_mutex_lock(&disp_source->wl_event_mutex); } - g_mutex_unlock(&surf_source->free_queue_mutex); - return TPL_ERROR_NONE; } diff --git a/src/tpl_wl_vk_thread.c b/src/tpl_wl_vk_thread.c index 6f96b2f..9c7a8c1 100644 --- a/src/tpl_wl_vk_thread.c +++ b/src/tpl_wl_vk_thread.c @@ -408,50 +408,38 @@ __tpl_wl_vk_wsi_surface_dequeue_buffer(tpl_surface_t *surface, tpl_wayland_vk_wsi_display_t *wayland_vk_wsi_display = (tpl_wayland_vk_wsi_display_t *)surface->display->backend.data; tbm_surface_queue_error_e tsq_err = 0; - tpl_result_t lock_ret = TPL_ERROR_NONE; + tpl_result_t lock_res = TPL_ERROR_NONE; + tpl_result_t res = TPL_ERROR_NONE; if (sync_fence) *sync_fence = -1; - /* After the can dequeue state, call twe_display_lock to prevent other - * events from being processed in wayland_egl_thread - * during below dequeue procedure. */ - lock_ret = twe_display_lock(wayland_vk_wsi_display->twe_display); - - if (!tbm_surface_queue_can_dequeue(wayland_vk_wsi_surface->tbm_queue, 0)) { - if (timeout_ns == 0) return NULL; - else { - tpl_result_t res = TPL_ERROR_NONE; - if (lock_ret == TPL_ERROR_NONE) - twe_display_unlock(wayland_vk_wsi_display->twe_display); - TPL_OBJECT_UNLOCK(surface); - TRACE_BEGIN("WAIT_DEQUEUEABLE"); - res = twe_surface_wait_dequeueable(wayland_vk_wsi_surface->twe_surface, - timeout_ns); - TRACE_END(); - TPL_OBJECT_LOCK(surface); - lock_ret = twe_display_lock(wayland_vk_wsi_display->twe_display); - - if (res == TPL_ERROR_TIME_OUT) { - TPL_ERR("Failed to get buffer during timeout_ns(%" PRIu64 ")", - timeout_ns); - if (lock_ret == TPL_ERROR_NONE) - twe_display_unlock(wayland_vk_wsi_display->twe_display); - return NULL; - } else if (res != TPL_ERROR_NONE) { - TPL_ERR("Invalid parameter. twe_surface(%p) timeout_ns(%" PRIu64 ")", - wayland_vk_wsi_surface->twe_surface, timeout_ns); - if (lock_ret == TPL_ERROR_NONE) - twe_display_unlock(wayland_vk_wsi_display->twe_display); - return NULL; - } - } + TPL_OBJECT_UNLOCK(surface); + TRACE_BEGIN("WAIT_DEQUEUEABLE"); + lock_res = twe_display_lock(wayland_vk_wsi_display->twe_display); + res = twe_surface_wait_dequeueable(wayland_vk_wsi_surface->twe_surface, + timeout_ns); + TRACE_END(); + TPL_OBJECT_LOCK(surface); + + if (res == TPL_ERROR_TIME_OUT) { + TPL_ERR("Failed to get buffer during timeout_ns(%" PRIu64 ")", + timeout_ns); + if (lock_res == TPL_ERROR_NONE) + twe_display_unlock(wayland_vk_wsi_display->twe_display); + return NULL; + } else if (res != TPL_ERROR_NONE) { + TPL_ERR("Invalid operation. twe_surface(%p) timeout_ns(%" PRIu64 ")", + wayland_vk_wsi_surface->twe_surface, timeout_ns); + if (lock_res == TPL_ERROR_NONE) + twe_display_unlock(wayland_vk_wsi_display->twe_display); + return NULL; } if (wayland_vk_wsi_surface->reset) { TPL_LOG_T("WL_VK", "tbm_queue(%p) has been reset. Do not process dequeue.", wayland_vk_wsi_surface->tbm_queue); - if (lock_ret == TPL_ERROR_NONE) + if (lock_res == TPL_ERROR_NONE) twe_display_unlock(wayland_vk_wsi_display->twe_display); return NULL; } @@ -462,7 +450,7 @@ __tpl_wl_vk_wsi_surface_dequeue_buffer(tpl_surface_t *surface, if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface from tbm_surface_queue(%p) | tsq_err = %d", wayland_vk_wsi_surface->tbm_queue, tsq_err); - if (lock_ret == TPL_ERROR_NONE) + if (lock_res == TPL_ERROR_NONE) twe_display_unlock(wayland_vk_wsi_display->twe_display); return NULL; } @@ -473,11 +461,11 @@ __tpl_wl_vk_wsi_surface_dequeue_buffer(tpl_surface_t *surface, *sync_fence = twe_surface_create_sync_fd(tbm_surface); } - TPL_LOG_T("WL_VK", "[DEQ] tbm_surface(%p) bo(%d)", - tbm_surface, + TPL_LOG_T("WL_VK", "[DEQ] tbm_queue(%p) tbm_surface(%p) bo(%d)", + wayland_vk_wsi_surface->tbm_queue, tbm_surface, tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); - if (lock_ret == TPL_ERROR_NONE) + if (lock_res == TPL_ERROR_NONE) twe_display_unlock(wayland_vk_wsi_display->twe_display); return tbm_surface; -- 2.7.4 From 09121cc41b1b124c4fc978ff9710bd5b3ede1e8a Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 8 Feb 2018 13:15:09 +0900 Subject: [PATCH 06/16] tpl_wayland_egl_thread: Deleted unnecessary locking that can occur deadlock. - To signal to free_queue_cond has been changed into dequeueable_callback() Change-Id: Ib4028f0d7561b7ebf8161054ef23ec1ee5e20f7b Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 03e6324..82d37ff 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1779,13 +1779,10 @@ _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) { - g_mutex_lock(&surf_source->free_queue_mutex); 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.", tbm_surface); - g_cond_signal(&surf_source->free_queue_cond); - g_mutex_unlock(&surf_source->free_queue_mutex); buf_info->need_to_release = TPL_FALSE; } else { /* Dependent on wl_buffer release event. */ @@ -1947,7 +1944,6 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) case TPL_DISPLAY_PRESENT_MODE_MAILBOX: if (surf_source->draw_done_buffer) { - g_mutex_lock(&surf_source->free_queue_mutex); TPL_LOG_T(BACKEND, "[SKIP] tbm_surface(%p) bo(%d)", tbm_surface, tbm_bo_export(tbm_surface_internal_get_bo( @@ -1955,8 +1951,6 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) tbm_surface_internal_unref(surf_source->draw_done_buffer); tbm_surface_queue_release(surf_source->tbm_queue, surf_source->draw_done_buffer); - g_cond_signal(&surf_source->free_queue_cond); - g_mutex_unlock(&surf_source->free_queue_mutex); } surf_source->draw_done_buffer = tbm_surface; -- 2.7.4 From 4d1f1392d93689e8da879bd4c43d54e28f05297f Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 8 Feb 2018 14:35:51 +0900 Subject: [PATCH 07/16] Package version up to 1.5.4 Change-Id: Ied81baf78938d7200526d5126de5d907f70dabf7 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 4b1e945..4efe9e2 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 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 d9822dae06672b889d78939b48b9e394d5b2f423 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 22 Feb 2018 11:05:31 +0900 Subject: [PATCH 08/16] tpl: Fixed an issue runtime_fini was not thread safe. Change-Id: Iea2ae18e9b2dd6042fa1e86eda54fa8ef7b5fdb6 Signed-off-by: joonbum.ko --- src/tpl.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index d29e9de..7c834ce 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -38,19 +38,21 @@ __tpl_init(void) static void __attribute__((destructor)) __tpl_runtime_fini(void) { - if (runtime != NULL) { - int i; - - if (!pthread_mutex_lock(&runtime_mutex)) { + if (!pthread_mutex_lock(&runtime_mutex)) { + if (runtime != NULL) { + int i; for (i = 0; i < TPL_BACKEND_COUNT; i++) { if (runtime->displays[i] != NULL) __tpl_hashlist_destroy(&(runtime->displays[i])); + if (runtime->surfaces[i] != NULL) + __tpl_hashlist_destroy(&(runtime->surfaces[i])); } - pthread_mutex_unlock(&runtime_mutex); + + free(runtime); + runtime = NULL; } - free(runtime); - runtime = NULL; + pthread_mutex_unlock(&runtime_mutex); } #ifdef OBJECT_HASH_CHECK -- 2.7.4 From 4ec9e72e9434ab299767024406c39f1d0651c995 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 15 Mar 2018 14:07:48 +0900 Subject: [PATCH 09/16] wayland-egl-tizen: Added a new packaging for wayland-egl-tizen. - wayland-egl-tizen provides below RPMs libwayland-egl-tizen.rpm - libwayland-egl-tizen.so* libwayland-egl-tizen-devel.rpm - wayland-egl-tizen.pc - wayland-egl-tizen.h - wayland-egl-tizen is a separate package from the existing wayland-egl to provide tizen-specific extension APIs. - If wayland-client wants to use tizen-only wl_egl_window API, client should add wayland-egl-tizen.pc to their BuildRequires and include wayland-egl-tizen.h in their source code. - This change to the wayland-egl-tizen package is the first step in upgrading wayland in TIZEN, and the wayland-egl in libtpl-egl will be deprecated. Change-Id: Icb07de25890edc8c8eb228fbdf4a8e3e6673aa99 Signed-off-by: joonbum.ko --- configure.ac | 14 +++- packaging/libtpl-egl.spec | 41 ++++++++++ packaging/libwayland-egl-tizen.manifest | 5 ++ pkgconfig/Makefile.am | 2 +- pkgconfig/wayland-egl-tizen.pc.in | 10 +++ src/wayland-egl/Makefile.am | 15 ++++ src/wayland-egl/wayland-egl-tizen.c | 141 ++++++++++++++++++++++++++++++++ src/wayland-egl/wayland-egl-tizen.h | 22 ++++- src/wayland-egl/wayland-egl.c | 34 -------- 9 files changed, 242 insertions(+), 42 deletions(-) create mode 100644 packaging/libwayland-egl-tizen.manifest create mode 100644 pkgconfig/wayland-egl-tizen.pc.in create mode 100644 src/wayland-egl/wayland-egl-tizen.c diff --git a/configure.ac b/configure.ac index 5379baa..fbdb729 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,9 @@ AC_SUBST(TPL_VERSION_PATCH) AC_SUBST(WL_EGL_VERSION_MAJOR) AC_SUBST(WL_EGL_VERSION_MINOR) AC_SUBST(WL_EGL_VERSION_PATCH) - +AC_SUBST(WL_EGL_TIZEN_VERSION_MAJOR) +AC_SUBST(WL_EGL_TIZEN_VERSION_MINOR) +AC_SUBST(WL_EGL_TIZEN_VERSION_PATCH) # Checks for programs. AC_PROG_CXX AC_PROG_CC @@ -172,8 +174,10 @@ AS_IF([test "${enable_gcov}" = "yes" || test "${enable_gcov}" = "1"], [TPL_CFLAGS+=" -fprofile-arcs -ftest-coverage" TPL_LIBS+=" -lgcov " WL_EGL_CFLAGS+=" -fprofile-arcs -ftest-coverage" - WL_EGL_LIBS+=" -lgcov "], - []) + WL_EGL_LIBS+=" -lgcov " + WL_EGL_TIZEN_CFLAGS+=" -fprofile-arcs -ftest-coverage" + WL_EGL_TIZENLIBS+=" -lgcov ", + ]) AM_CONDITIONAL([ENABLE_GCOV], [test "${enable_gcov}" = "yes" || test "${enable_gcov}" = "1"]) @@ -186,6 +190,9 @@ AC_SUBST([TPL_LIBS]) AC_SUBST([WL_EGL_CFLAGS]) AC_SUBST([WL_EGL_LIBS]) +AC_SUBST([WL_EGL_TIZEN_CFLAGS]) +AC_SUBST([WL_EGL_TIZEN_LIBS]) + # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE AC_TYPE_INT32_T @@ -209,6 +216,7 @@ AC_CONFIG_FILES([ pkgconfig/Makefile pkgconfig/tpl-egl.pc pkgconfig/wayland-egl.pc + pkgconfig/wayland-egl-tizen.pc ]) AM_COND_IF([WITH_UTEST], diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 4efe9e2..33b6159 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -29,6 +29,12 @@ %define WL_EGL_VERSION_PATCH 3 %define WL_EGL_VERSION %{WL_EGL_VERSION_MAJOR}.%{WL_EGL_VERSION_MINOR}.%{WL_EGL_VERSION_PATCH} +#WAYLAND-EGL-TIZEN VERSION MACROS +%define WL_EGL_TIZEN_VERSION_MAJOR 1 +%define WL_EGL_TIZEN_VERSION_MINOR 0 +%define WL_EGL_TIZEN_VERSION_PATCH 0 +%define WL_EGL_TIZEN_VERSION %{WL_EGL_TIZEN_VERSION_MAJOR}.%{WL_EGL_TIZEN_VERSION_MINOR}.%{WL_EGL_TIZEN_VERSION_PATCH} + #TPL WINDOW SYSTEM CHECK %if "%{TPL_WINSYS}" != "DRI2" && "%{TPL_WINSYS}" != "DRI3" && "%{TPL_WINSYS}" != "WL" BuildRequires: ERROR(No_window_system_designated) @@ -123,6 +129,23 @@ Requires: libwayland-egl %description -n libwayland-egl-devel Development header files for use with Wayland protocol + +%package -n libwayland-egl-tizen +Version: %{WL_EGL_TIZEN_VERSION} +Release: 0 +Summary: Wayland EGL TIZEN backend + +%description -n libwayland-egl-tizen +This package provides tizen specific extension fo wayland-egl. + +%package -n libwayland-egl-tizen-devel +Version: %{WL_EGL_TIZEN_VERSION} +Release: 0 +Summary: Development header files for wayland-egl tizen extensions. +Requires: libwayland-egl libwayland-egl-tizen + +%description -n libwayland-egl-tizen-devel +Development header files for wayland-egl tizen extensions. %endif %if %{with utest} || "%{ENABLE_TPL_TEST}" == "1" @@ -146,6 +169,10 @@ export WL_EGL_VERSION_MAJOR=%{WL_EGL_VERSION_MAJOR} export WL_EGL_VERSION_MINOR=%{WL_EGL_VERSION_MINOR} export WL_EGL_VERSION_PATCH=%{WL_EGL_VERSION_PATCH} +export WL_EGL_TIZEN_VERSION_MAJOR=%{WL_EGL_TIZEN_VERSION_MAJOR} +export WL_EGL_TIZEN_VERSION_MINOR=%{WL_EGL_TIZEN_VERSION_MINOR} +export WL_EGL_TIZEN_VERSION_PATCH=%{WL_EGL_TIZEN_VERSION_PATCH} + %reconfigure \ %ifarch aarch64 --with-arch=aarch64 \ @@ -181,6 +208,8 @@ rm -rf %{buildroot} %if "%{TPL_WINSYS}" == "WL" %post -n libwayland-egl -p /sbin/ldconfig %postun -n libwayland-egl -p /sbin/ldconfig +%post -n libwayland-egl-tizen -p /sbin/ldconfig +%postun -n libwayland-egl-tizen -p /sbin/ldconfig %endif %files @@ -208,6 +237,18 @@ rm -rf %{buildroot} %{_includedir}/wayland-egl-tizen.h %{_libdir}/libwayland-egl.so %{_libdir}/pkgconfig/wayland-egl.pc + +%files -n libwayland-egl-tizen +%manifest packaging/libwayland-egl-tizen.manifest +%license COPYING +%defattr(-,root,root,-) +%{_libdir}/libwayland-egl-tizen.so* + +%files -n libwayland-egl-tizen-devel +%defattr(-,root,root,-) +%{_includedir}/wayland-egl-tizen.h +%{_libdir}/libwayland-egl-tizen.so +%{_libdir}/pkgconfig/wayland-egl-tizen.pc %endif %if %{with utest} || "%{ENABLE_TPL_TEST}" == "1" diff --git a/packaging/libwayland-egl-tizen.manifest b/packaging/libwayland-egl-tizen.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/libwayland-egl-tizen.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/pkgconfig/Makefile.am b/pkgconfig/Makefile.am index 9f4a13e..ac2f380 100644 --- a/pkgconfig/Makefile.am +++ b/pkgconfig/Makefile.am @@ -1,3 +1,3 @@ pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = tpl-egl.pc wayland-egl.pc +pkgconfig_DATA = tpl-egl.pc wayland-egl.pc wayland-egl-tizen.pc diff --git a/pkgconfig/wayland-egl-tizen.pc.in b/pkgconfig/wayland-egl-tizen.pc.in new file mode 100644 index 0000000..b474ee6 --- /dev/null +++ b/pkgconfig/wayland-egl-tizen.pc.in @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/@LIB@ +includedir=${prefix}/include + +Name: wayland-egl-tizen +Description: Wayland EGL Extension APIs for TIZEN +Version: 1.0.0 +Libs: -L${libdir} -lwayland-egl-tizen +Cflags: -I${includedir} diff --git a/src/wayland-egl/Makefile.am b/src/wayland-egl/Makefile.am index cf0a9e6..626fa7e 100644 --- a/src/wayland-egl/Makefile.am +++ b/src/wayland-egl/Makefile.am @@ -15,3 +15,18 @@ libwayland_egl_la_LIBADD = @WL_EGL_LIBS@ libwayland_egl_la_LDFLAGS = -version-number @WL_EGL_VERSION_MAJOR@:@WL_EGL_VERSION_MINOR@:@WL_EGL_VERSION_PATCH@ libwayland_egl_la_SOURCES = wayland-egl.c +libwayland_egl_tizen_la_LTLIBRARIES = libwayland-egl-tizen.la +libwayland_egl_tizen_ladir = $(libdir) + +libwayland_egl_tizen_lainclude_HEADERS = wayland-egl-tizen.h +libwayland_egl_tizen_laincludedir = $(includedir) + +libwayland_egl_tizen_la_CFLAGS = -I$(srcdir) \ + @WL_EGL_TIZEN_CFLAGS@ +if ENABLE_GCOV +libwayland_egl_la_CFLAGS += -DTIZEN_TEST_GCOV +endif + +libwayland_egl_tizen_la_LIBADD = @WL_EGL_TIZEN_LIBS@ +libwayland_egl_tizen_la_LDFLAGS = -version-number @WL_EGL_TIZEN_VERSION_MAJOR@:@WL_EGL_TIZEN_VERSION_MINOR@:@WL_EGL_TIZEN_VERSION_PATCH@ +libwayland_egl_tizen_la_SOURCES = wayland-egl-tizen.c diff --git a/src/wayland-egl/wayland-egl-tizen.c b/src/wayland-egl/wayland-egl-tizen.c new file mode 100644 index 0000000..a342cca --- /dev/null +++ b/src/wayland-egl/wayland-egl-tizen.c @@ -0,0 +1,141 @@ +#include +#include "wayland-egl-tizen.h" +#include "wayland-egl-priv.h" + +#define WL_EGL_DEBUG 1 +#if WL_EGL_DEBUG + +#include +#include +#include +#include +#include +#include + +unsigned int wl_egl_log_level; + +/* WL-EGL Log Level - 0:unintialized, 1:initialized(no logging), 2:min log, 3:more log */ +#define WL_EGL_LOG(lvl, f, x...) { \ + if (wl_egl_log_level == 1) { \ + } \ + else if (wl_egl_log_level > 1) { \ + if (wl_egl_log_level <= lvl) \ + WL_EGL_LOG_PRINT(f, ##x) \ + } \ + else { \ + char *env = getenv("WL_EGL_LOG_LEVEL"); \ + if (env == NULL) \ + wl_egl_log_level = 1; \ + else \ + wl_egl_log_level = atoi(env); \ + \ + if (wl_egl_log_level > 1 && wl_egl_log_level <= lvl)\ + WL_EGL_LOG_PRINT(f, ##x) \ + } \ + } + +#define WL_EGL_LOG_PRINT(fmt, args...) { \ + printf("[\x1b[32mWL-EGL\x1b[0m %d:%d|\x1b[32m%s\x1b[0m|%d] " fmt "\n", \ + getpid(), (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \ + } + +#define WL_EGL_ERR(f, x...) { \ + printf("[\x1b[31mWL-EGL_ERR\x1b[0m %d:%d|\x1b[31m%s\x1b[0m|%d] " f "\n",\ + getpid(), (int)syscall(SYS_gettid), __func__, __LINE__, ##x); \ + } + +#else +#define WL_EGL_LOG(lvl, f, x...) +#endif + +void +wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window, + wl_egl_window_tizen_rotation rotation) +{ + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return; + } + + if (egl_window->rotation == rotation) { + WL_EGL_LOG(2, "rotation(%d) egl_window->rotation(%d) already rotated", + rotation, egl_window->rotation); + return; + } + + egl_window->rotation = rotation; + + if (egl_window->rotate_callback) + egl_window->rotate_callback(egl_window, egl_window->private); +} + +int +wl_egl_window_tizen_get_capabilities(struct wl_egl_window *egl_window) +{ + int capabilities = WL_EGL_WINDOW_CAPABILITY_NONE; + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return capabilities; + } + + if (egl_window->get_rotation_capability) + capabilities = egl_window->get_rotation_capability(egl_window, egl_window->private); + else + capabilities = WL_EGL_WINDOW_CAPABILITY_ROTATION_UNKNOWN; + + return capabilities; +} + +void +wl_egl_window_tizen_set_buffer_transform(struct wl_egl_window *egl_window, + int wl_output_transform) +{ + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return; + } + + if (egl_window->transform == wl_output_transform) { + WL_EGL_LOG(2, + "wl_output_transform(%d) egl_window->transform(%d) already rotated", + wl_output_transform, egl_window->transform); + return; + } + + egl_window->transform = wl_output_transform; +} + +void +wl_egl_window_tizen_set_frontbuffer_mode(struct wl_egl_window *egl_window, + int set) +{ + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return; + } + + egl_window->frontbuffer_mode = set; + + if (egl_window->set_frontbuffer_callback) + egl_window->set_frontbuffer_callback(egl_window, egl_window->private, + set); +} + +void +wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, + int window_transform) +{ + if (egl_window == NULL) { + WL_EGL_ERR("egl_window is NULL"); + return; + } + + if (egl_window->window_transform == window_transform) { + WL_EGL_LOG(2, + "window_transform(%d) already rotated", + window_transform); + return; + } + + egl_window->window_transform = window_transform; +} diff --git a/src/wayland-egl/wayland-egl-tizen.h b/src/wayland-egl/wayland-egl-tizen.h index ba2b6cf..cbc03f6 100644 --- a/src/wayland-egl/wayland-egl-tizen.h +++ b/src/wayland-egl/wayland-egl-tizen.h @@ -33,24 +33,38 @@ extern "C" { #include +typedef enum { + WL_EGL_WINDOW_TIZEN_CAPABILITY_NONE = 0, + WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED = (1 << 0), + WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_UNSUPPORTED = (1 << 1), + WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_UNKNOWN = (1 << 2), +} wl_egl_window_tizen_capability; + +typedef enum { + WL_EGL_WINDOW_TIZEN_ROTATION_0 = 0, + WL_EGL_WINDOW_TIZEN_ROTATION_90 = 90, + WL_EGL_WINDOW_TIZEN_ROTATION_180 = 180, + WL_EGL_WINDOW_TIZEN_ROTATION_270 = 270 +} wl_egl_window_tizen_rotation; + void wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window, - wl_egl_window_rotation rotation); + wl_egl_window_tizen_rotation rotation); int wl_egl_window_tizen_get_capabilities(struct wl_egl_window *egl_window); void wl_egl_window_tizen_set_buffer_transform(struct wl_egl_window *egl_window, - int wl_output_transform); + int wl_output_transform); void wl_egl_window_tizen_set_frontbuffer_mode(struct wl_egl_window *egl_window, - int set); + int set); void wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, - int window_transform); + int window_transform); #ifdef __cplusplus } diff --git a/src/wayland-egl/wayland-egl.c b/src/wayland-egl/wayland-egl.c index 08a5fc4..5c16bcf 100644 --- a/src/wayland-egl/wayland-egl.c +++ b/src/wayland-egl/wayland-egl.c @@ -241,37 +241,3 @@ wl_egl_window_set_window_transform(struct wl_egl_window *egl_window, egl_window->window_transform = window_transform; } -void -wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window, - wl_egl_window_rotation rotation) -{ - return wl_egl_window_set_rotation(egl_window, rotation); -} - -int -wl_egl_window_tizen_get_capabilities(struct wl_egl_window *egl_window) -{ - return wl_egl_window_get_capabilities(egl_window); -} - -void -wl_egl_window_tizen_set_buffer_transform(struct wl_egl_window *egl_window, - int wl_output_transform) -{ - return wl_egl_window_set_buffer_transform(egl_window, wl_output_transform); -} - -void -wl_egl_window_tizen_set_frontbuffer_mode(struct wl_egl_window *egl_window, - int set) -{ - return wl_egl_window_set_frontbuffer_mode(egl_window, set); -} - -void -wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, - int window_transform) -{ - return wl_egl_window_set_window_transform(egl_window, window_transform); -} - -- 2.7.4 From e4d15eb330f8339ffab19ede5cd20b5591d2a4b5 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Mon, 19 Mar 2018 13:04:29 +0900 Subject: [PATCH 10/16] wayland-egl: Package version up to 1.2.4 Change-Id: I9a39fc0a31e79b14e6034cb4daddaed2556eeb49 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 33b6159..7797b04 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -26,7 +26,7 @@ #WAYLAND-EGL VERSION MACROS %define WL_EGL_VERSION_MAJOR 1 %define WL_EGL_VERSION_MINOR 2 -%define WL_EGL_VERSION_PATCH 3 +%define WL_EGL_VERSION_PATCH 4 %define WL_EGL_VERSION %{WL_EGL_VERSION_MAJOR}.%{WL_EGL_VERSION_MINOR}.%{WL_EGL_VERSION_PATCH} #WAYLAND-EGL-TIZEN VERSION MACROS -- 2.7.4 From 885457565cf9abebd8f477841d86b7fe74a081e1 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 10 Apr 2018 13:53:14 +0900 Subject: [PATCH 11/16] tpl_wayland_egl: Added exception handling to prevent abnormal conditions. Change-Id: I5663cec875a8b3252aedbc46f9932731d02034f1 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index 4565402..3fa70a4 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -1006,6 +1006,11 @@ __tpl_wayland_egl_surface_enqueue_buffer(tpl_surface_t *surface, return TPL_ERROR_INVALID_OPERATION; } + if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE && + wayland_egl_buffer->reset == TPL_TRUE) { + wayland_egl_buffer->reset = TPL_FALSE; + } + tsq_err = tbm_surface_queue_acquire(wayland_egl_surface->tbm_queue, &tbm_surface); if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE) { -- 2.7.4 From 72d7bfbfa1b1850662fcdd380dc68b0c0bc1f3be Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 10 Apr 2018 13:55:50 +0900 Subject: [PATCH 12/16] tpl_wayland_egl: Used new API of tdm_clint to check whether request is exist or not. Change-Id: I45ce8e043a55a3f2222e5119b7662746cf433b95 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index 3fa70a4..539be9e 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -730,7 +730,9 @@ __tpl_wayland_egl_surface_wait_vblank(tpl_surface_t *surface) TPL_OBJECT_UNLOCK(surface); tdm_lock_res = pthread_mutex_lock(&wayland_egl_display->tdm_mutex); - while (wayland_egl_surface->vblank_done == TPL_FALSE) { + while (wayland_egl_surface->vblank_done == TPL_FALSE && + wayland_egl_surface->tdm_vblank != NULL && + tdm_client_vblank_is_waiting(wayland_egl_surface->tdm_vblank)) { tdm_err = tdm_client_handle_events(wayland_egl_display->tdm_client); if (tdm_err != TDM_ERROR_NONE) { -- 2.7.4 From a91705b417f5b2c409af5777722fbce2bfeb6caa Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 10 Apr 2018 14:20:57 +0900 Subject: [PATCH 13/16] tpl_wayland_egl: Used tdm_client_handle_events_timeout() to prevent deadlock. Change-Id: Idf5f0e33b72364e0dd4646b0d9790c4a6e05f04d Signed-off-by: joonbum.ko --- src/tpl_wayland_egl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index 539be9e..9182de0 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -733,7 +733,13 @@ __tpl_wayland_egl_surface_wait_vblank(tpl_surface_t *surface) while (wayland_egl_surface->vblank_done == TPL_FALSE && wayland_egl_surface->tdm_vblank != NULL && tdm_client_vblank_is_waiting(wayland_egl_surface->tdm_vblank)) { - tdm_err = tdm_client_handle_events(wayland_egl_display->tdm_client); + tdm_err = tdm_client_handle_events_timeout(wayland_egl_display->tdm_client, + 1000); + if (tdm_err == TDM_ERROR_TIMEOUT) { + TPL_ERR("Failed to tdm_client_handle_events. timeour (>1000)"); + wayland_egl_surface->vblank_done = TPL_TRUE; + break; + } if (tdm_err != TDM_ERROR_NONE) { TPL_ERR("Failed to tdm_client_handle_events."); -- 2.7.4 From 15c89742889a905bc26dd1a5e510adcb21be06c8 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 10 Apr 2018 14:35:55 +0900 Subject: [PATCH 14/16] tpl_wayland_egl: Removed reset checking in release_callback. Change-Id: I2038fefa218e85f512153af3ae68fa6a210885c0 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index 9182de0..2a42fda 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -1471,6 +1471,7 @@ static void __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) { tbm_surface_h tbm_surface = NULL; + tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; TPL_ASSERT(data); @@ -1500,11 +1501,12 @@ __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) (void *)tbm_surface, TPL_FIRST, NULL); TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); } - /* If tbm_surface_queue was reset before release_cb called out, - * tbm_surface_queue_release doesn't have to be done. */ - if (wayland_egl_buffer->reset == TPL_FALSE) - tbm_surface_queue_release(wayland_egl_surface->tbm_queue, - 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) to tbm_queue(%p) tsq_err(%d)", + tbm_surface, wayland_egl_surface->tbm_queue, tsq_err); wayland_egl_buffer->need_to_release = TPL_FALSE; -- 2.7.4 From d5976c414108e3e73ee92c519d2041b8379d52ec Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 10 Apr 2018 15:39:36 +0900 Subject: [PATCH 15/16] tpl_wayland_egl: Modified to use tbm_surface_queue with GUARANTEE_CYCLE mode. - the reset flag of wayland_egl_buffer will be not used more. Change-Id: I6d40cce03bd15db043560d57bc1892863b8bc6a5 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl.c | 169 ++++++++++++++++++-------------------------------- 1 file changed, 59 insertions(+), 110 deletions(-) diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index 2a42fda..f7b77b0 100644 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -64,7 +64,6 @@ struct _tpl_wayland_egl_buffer { tbm_bo bo; tpl_bool_t w_rotated; /* TRUE if need to call wayland_tbm_client_set_buffer_transform */ tpl_bool_t rotated; /* TRUE if need to call wl_surface_set_buffer_transform */ - tpl_bool_t reset; /* TRUE if queue reseted by external */ 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 */ @@ -413,27 +412,6 @@ static void __cb_client_window_set_frontbuffer_mode(struct wl_egl_window *wl_egl_window, void *private, int set); -static TPL_INLINE void -__tpl_wayland_egl_buffer_set_reset_flag(tpl_list_t *tracking_list) -{ - tpl_list_node_t *node = __tpl_list_get_front_node(tracking_list); - - while (node) { - tbm_surface_h tbm_surface = - (tbm_surface_h)__tpl_list_node_get_data(node); - - if (tbm_surface) { - tpl_wayland_egl_buffer_t *wayland_egl_buffer = - __tpl_wayland_egl_get_wayland_buffer_from_tbm_surface(tbm_surface); - - if (wayland_egl_buffer) - wayland_egl_buffer->reset = TPL_TRUE; - } - - node = __tpl_list_node_next(node); - } -} - static void __cb_tbm_surface_queue_reset_callback(tbm_surface_queue_h surface_queue, void *data) @@ -455,12 +433,6 @@ __cb_tbm_surface_queue_reset_callback(tbm_surface_queue_h surface_queue, wayland_egl_surface->reset = TPL_TRUE; - /* Set the reset flag of the buffers which attached but not released to TPL_TRUE. */ - __tpl_wayland_egl_buffer_set_reset_flag(wayland_egl_surface->attached_buffers); - - /* Set the reset flag of the buffers which dequeued but not enqueued to TPL_TRUE. */ - __tpl_wayland_egl_buffer_set_reset_flag(wayland_egl_surface->dequeued_buffers); - TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); if (surface->reset_cb) @@ -573,6 +545,14 @@ __tpl_wayland_egl_surface_init(tpl_surface_t *surface) goto queue_create_fail; } + if (tbm_surface_queue_set_modes(wayland_egl_surface->tbm_queue, + TBM_SURFACE_QUEUE_MODE_GUARANTEE_CYCLE) != + TBM_SURFACE_QUEUE_ERROR_NONE) { + TPL_ERR("Failed to set queue mode to tbm_surface_queue(%p)", + wayland_egl_surface->tbm_queue); + goto guarantee_mode_set_fail; + } + /* Set reset_callback to tbm_queue */ if (tbm_surface_queue_add_reset_cb(wayland_egl_surface->tbm_queue, __cb_tbm_surface_queue_reset_callback, @@ -624,8 +604,10 @@ create_vblank_fail: tbm_surface_queue_remove_reset_cb(wayland_egl_surface->tbm_queue, __cb_tbm_surface_queue_reset_callback, (void *)surface); +guarantee_mode_set_fail: add_reset_cb_fail: tbm_surface_queue_destroy(wayland_egl_surface->tbm_queue); + wayland_egl_surface->tbm_queue = NULL; queue_create_fail: __tpl_list_free(wayland_egl_surface->attached_buffers, NULL); alloc_dequeue_buffers_fail: @@ -680,6 +662,30 @@ __tpl_wayland_egl_surface_fini(tpl_surface_t *surface) lock_res = pthread_mutex_lock(&wayland_egl_display->wl_event_mutex); wl_display_dispatch_queue_pending(wayland_egl_display->wl_dpy, wayland_egl_display->wl_tbm_event_queue); + /* When surface is destroyed, unreference tbm_surface which tracked by + * the list of attached_buffers in order to free the created resources. + * (tpl_wayland_egl_buffer_t or wl_buffer) */ + if (wayland_egl_surface->attached_buffers) { + TPL_OBJECT_LOCK(&wayland_egl_surface->base); + 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); + TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ RELEASE_CB] BO_NAME:%d", + tbm_bo_export(tbm_surface_internal_get_bo( + tbm_surface, 0))); + 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_list_free(wayland_egl_surface->attached_buffers, NULL); + wayland_egl_surface->attached_buffers = NULL; + TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); + } + if (lock_res == 0) pthread_mutex_unlock(&wayland_egl_display->wl_event_mutex); TPL_LOG_B("WL_EGL", @@ -689,22 +695,6 @@ __tpl_wayland_egl_surface_fini(tpl_surface_t *surface) wayland_egl_surface->tbm_queue = NULL; } - /* When surface is destroyed, unreference tbm_surface which tracked by - * the list of attached_buffers in order to free the created resources. - * (tpl_wayland_egl_buffer_t or wl_buffer) */ - if (wayland_egl_surface->attached_buffers) { - TPL_OBJECT_LOCK(&wayland_egl_surface->base); - while (!__tpl_list_is_empty(wayland_egl_surface->attached_buffers)) { - tbm_surface_h tbm_surface = - __tpl_list_pop_front(wayland_egl_surface->attached_buffers, NULL); - tbm_surface_internal_unref(tbm_surface); - } - - __tpl_list_free(wayland_egl_surface->attached_buffers, NULL); - wayland_egl_surface->attached_buffers = NULL; - TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); - } - /* the list of dequeued_buffers just does deletion */ if (wayland_egl_surface->dequeued_buffers) { TPL_OBJECT_LOCK(&wayland_egl_surface->base); @@ -959,73 +949,19 @@ __tpl_wayland_egl_surface_enqueue_buffer(tpl_surface_t *surface, TPL_OBJECT_UNLOCK(&wayland_egl_surface->base); } - if (wayland_egl_buffer->reset) { - /* - * When tbm_surface_queue being reset for receiving - * scan-out buffer or resized buffer - * tbm_surface_queue_enqueue will return error. - * This error condition leads to skip frame. - * - * tbm_surface received from argument this function, - * may be rendered done. So this tbm_surface is better to do - * commit forcibly without handling queue in order to prevent - * frame skipping. - */ - __tpl_wayland_egl_surface_commit(surface, tbm_surface, - num_rects, rects); - return TPL_ERROR_NONE; - } - tsq_err = tbm_surface_queue_enqueue(wayland_egl_surface->tbm_queue, tbm_surface); - if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE) { - /* - * If tbm_surface_queue has not been reset, tbm_surface_queue_enqueue - * will return ERROR_NONE. Otherwise, queue has been reset - * this tbm_surface may have only one ref_count. So we need to - * unreference this tbm_surface after getting ERROR_NONE result from - * tbm_surface_queue_enqueue in order to prevent destruction. - */ - tbm_surface_internal_unref(tbm_surface); - } else { - /* - * If tbm_surface is valid but it is not tracked by tbm_surface_queue, - * tbm_surface_queue_enqueue will return below value. - * TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE - * It means tbm_surface_queue has been reset before client try - * to enqueue this tbm_surface. - * We should commit this buffer to display to assure the latest frame. - * - * In enlightenment(E20) of TIZEN platform, depending on - * some situation(Activate, Deactivate), the compositor may or may not - * display the last forcibly commited buffer in this way. - * - * In this situation, the compositor's display policy may vary from - * server to server. - */ - if (tsq_err == TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE) { - __tpl_wayland_egl_surface_commit(surface, tbm_surface, - num_rects, rects); - return TPL_ERROR_NONE; - } - - TPL_ERR("Failed to enqeueue tbm_surface(%p). | tsq_err = %d", - tbm_surface, tsq_err); + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { + TPL_ERR("Failed to enqueue tbm_surface(%p) to tbm_queue(%p) | tsq_err = %d", + tbm_surface, wayland_egl_surface->tbm_queue, tsq_err); return TPL_ERROR_INVALID_OPERATION; } - if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE && - wayland_egl_buffer->reset == TPL_TRUE) { - wayland_egl_buffer->reset = TPL_FALSE; - } - tsq_err = tbm_surface_queue_acquire(wayland_egl_surface->tbm_queue, &tbm_surface); - if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE) { - tbm_surface_internal_ref(tbm_surface); - } else { - TPL_ERR("Failed to acquire tbm_surface(%p). | tsq_err = %d", - tbm_surface, tsq_err); + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { + TPL_ERR("Failed to acquire tbm_surface(%p) from tbm_queue(%p). | tsq_err = %d", + tbm_surface, wayland_egl_surface->tbm_queue, tsq_err); return TPL_ERROR_INVALID_OPERATION; } @@ -1123,6 +1059,7 @@ __tpl_wayland_egl_surface_cancel_dequeued_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { tpl_wayland_egl_surface_t *wayland_egl_surface = NULL; + tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; wayland_egl_surface = (tpl_wayland_egl_surface_t *)surface->backend.data; if (!wayland_egl_surface) { @@ -1146,6 +1083,14 @@ __tpl_wayland_egl_surface_cancel_dequeued_buffer(tpl_surface_t *surface, tbm_surface_internal_unref(tbm_surface); + tsq_err = tbm_surface_queue_cancel_dequeue(wayland_egl_surface->tbm_queue, + tbm_surface); + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { + TPL_ERR("Failed to cancel dequeue tbm_surface(%p) to tbm_queue(%p)", + tbm_surface, wayland_egl_surface->tbm_queue); + return TPL_ERROR_INVALID_OPERATION; + } + TPL_LOG_B("WL_EGL", "[CANCEL BUFFER] tpl_surface(%p) tbm_surface(%p)", surface, tbm_surface); @@ -1282,8 +1227,6 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeou wayland_egl_buffer->rotated = TPL_FALSE; } - wayland_egl_buffer->reset = TPL_FALSE; - if (wayland_egl_surface->is_activated != is_activated) wayland_egl_buffer->is_new = TPL_TRUE; @@ -1318,6 +1261,7 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeou if (!wayland_egl_buffer) { TPL_ERR("Mem alloc for wayland_egl_buffer failed!"); tbm_surface_internal_unref(tbm_surface); + tbm_surface_queue_cancel_dequeue(wayland_egl_surface->tbm_queue, tbm_surface); if (lock_res == 0) pthread_mutex_unlock(&wayland_egl_display->wl_event_mutex); return NULL; } @@ -1328,6 +1272,7 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeou if (!wl_proxy) { TPL_ERR("Failed to create TBM client buffer!"); tbm_surface_internal_unref(tbm_surface); + tbm_surface_queue_cancel_dequeue(wayland_egl_surface->tbm_queue, tbm_surface); free(wayland_egl_buffer); if (lock_res == 0) pthread_mutex_unlock(&wayland_egl_display->wl_event_mutex); return NULL; @@ -1362,10 +1307,6 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeou wayland_egl_buffer->rotated = TPL_FALSE; } - /* reset flag is to check whether it is the buffer before - * tbm_surface_queue is reset or not. */ - wayland_egl_buffer->reset = TPL_FALSE; - /* 'is_new' flag is to check wheter it is a new buffer need to commit * in frontbuffer mode. */ wayland_egl_buffer->is_new = TPL_TRUE; @@ -1747,9 +1688,17 @@ static void __cb_tizen_surface_shm_flusher_flush_callback(void *data, if (wayland_egl_surface->attached_buffers) { TPL_OBJECT_LOCK(&wayland_egl_surface->base); 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); + TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ RELEASE_CB] BO_NAME:%d", + tbm_bo_export(tbm_surface_internal_get_bo( + tbm_surface, 0))); 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); } -- 2.7.4 From 42e501f96c88f57602a29e118b127ecda4bbe0db Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Mon, 16 Apr 2018 13:37:36 +0900 Subject: [PATCH 16/16] tpl_wayland_egl_thread: Fixed bug that commit can't be done when sync_fence is not used in vulkan. Change-Id: I58b51b87bed46b34e445792199fb09c6f38d36c5 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 82d37ff..4138e98 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -2017,7 +2017,8 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) TPL_ERR("Failed to read from event_fd(%d)", surf_source->event_fd); - if (surf_source->disp_source->is_vulkan_dpy) { + 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); -- 2.7.4