From 0317b30345311063be3e46d8f0f7b3fcb82f45a9 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Fri, 29 Sep 2017 13:31:17 +0900 Subject: [PATCH] tpl_wayland_egl_thread: Added new internal APIs related with swapchain for vulkan. Change-Id: Ieceb7c1d6f08a684ba30de204818764e0c621754 Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ src/tpl_wayland_egl_thread.h | 7 ++++ 2 files changed, 102 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 9cb4735..6b66c2c 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -93,6 +93,11 @@ struct _twe_wl_surf_source { int rotation; void *cb_data; int format; + struct { + int width, height; + int buffer_count; + int present_mode; + } swapchain_properties; tpl_surface_cb_func_t rotate_cb; tpl_bool_t rotation_capability; tpl_object_t obj; /* for mutex lock */ @@ -2079,6 +2084,96 @@ twe_surface_del(twe_surface_h twe_surface) } tpl_result_t +twe_surface_create_swapchain(twe_surface_h twe_surface, + int width, int height, int format, + int buffer_count, int present_mode) +{ + twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; + twe_wl_disp_source *disp_source = NULL; + + if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { + TPL_ERR("twe_surface(%p) is invalid.", twe_surface); + return TPL_ERROR_INVALID_PARAMETER; + } + + disp_source = surf_source->disp_source; + + TPL_ASSERT(disp_source); + + if ((buffer_count < disp_source->surface_capabilities.min_buffer) + || (buffer_count > disp_source->surface_capabilities.max_buffer)) { + TPL_ERR("Invalid buffer_count(%d)! min_buffer(%d) max_buffer(%d)", + buffer_count, + disp_source->surface_capabilities.min_buffer, + disp_source->surface_capabilities.max_buffer); + return TPL_ERROR_INVALID_PARAMETER; + } + + if ((present_mode & disp_source->surface_capabilities.present_modes) == 0) { + /* server not supported current mode check client mode */ + switch (present_mode) { + case TPL_DISPLAY_PRESENT_MODE_FIFO: + case TPL_DISPLAY_PRESENT_MODE_FIFO_RELAXED: + case TPL_DISPLAY_PRESENT_MODE_MAILBOX: + case TPL_DISPLAY_PRESENT_MODE_IMMEDIATE: + break; + default: + TPL_ERR("Unsupported present mode: %d", present_mode); + return TPL_ERROR_INVALID_PARAMETER; + } + } + + /* FIXME: vblank has performance problem so replace all present mode to MAILBOX */ + present_mode = TPL_DISPLAY_PRESENT_MODE_MAILBOX; + + surf_source->tbm_queue = tbm_surface_queue_create(buffer_count, + width, + height, + TBM_FORMAT_ARGB8888, + 0); + if (!surf_source->tbm_queue) { + TPL_ERR("TBM surface queue creation failed!"); + return TPL_ERROR_OUT_OF_MEMORY; + } + + surf_source->format = format; + surf_source->swapchain_properties.width = width; + surf_source->swapchain_properties.height = height; + surf_source->swapchain_properties.present_mode = present_mode; + surf_source->swapchain_properties.buffer_count = buffer_count; + + TPL_LOG_T("WL_VK", "[SWAPCHAIN_CREATE][1/2] twe_surface(%p) tbm_queue(%p)", + twe_surface, surf_source->tbm_queue); + TPL_LOG_T("WL_VK", + "[SWAPCHAIN_CREATE][2/2] w(%d) h(%d) f(%d) p(%d) b_cnt(%d)", + width, height, present_mode, buffer_count); + + return TPL_ERROR_NONE; +} + +tpl_result_t +twe_surface_destroy_swapchain(twe_surface_h twe_surface) +{ + twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; + + if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { + TPL_ERR("twe_surface(%p) is invalid.", twe_surface); + return TPL_ERROR_INVALID_PARAMETER; + } + + TPL_LOG_T("WL_VK", "[SWAPCHAIN_DESTROY] twe_surface(%p) tbm_queue(%p)", + twe_surface, surf_source->tbm_queue); + + if (surf_source->tbm_queue) { + tbm_surface_queue_destroy(surf_source->tbm_queue); + surf_source->tbm_queue = NULL; + } + + return TPL_ERROR_NONE; +} + + +tpl_result_t twe_surface_set_rotate_callback(twe_surface_h twe_surface, void *data, tpl_surface_cb_func_t rotate_cb) { diff --git a/src/tpl_wayland_egl_thread.h b/src/tpl_wayland_egl_thread.h index 57dd497..c366b43 100644 --- a/src/tpl_wayland_egl_thread.h +++ b/src/tpl_wayland_egl_thread.h @@ -48,6 +48,13 @@ twe_surface_add(twe_thread* thread, tpl_result_t twe_surface_del(twe_surface_h twe_surface); +tpl_result_t +twe_surface_create_swapchain(twe_surface_h twe_surface, + int width, int height, int format, + int buffer_count, int present_mode); +tpl_result_t +twe_surface_destroy_swapchain(twe_surface_h twe_surface); + tbm_surface_queue_h twe_surface_get_tbm_queue(twe_surface_h twe_surface); -- 2.7.4