From e565c41f907df4ed8a2b85d304bf11cc3ba0724d Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 16 Jun 2021 17:20:54 +0900 Subject: [PATCH] tbm_bufmgr: add tbm_bufmgr_internal_import_bo_with_fd and use it The tbm_bufmgr generates tbm_bo and manages them Change-Id: Ie292badda463f17a7e0eba0b4320c9ea537ab7c1 --- src/tbm_bo.c | 79 +++------------------------------------------------- src/tbm_bufmgr.c | 61 ++++++++++++++++++++++++++++++++++++++++ src/tbm_bufmgr_int.h | 1 + 3 files changed, 66 insertions(+), 75 deletions(-) diff --git a/src/tbm_bo.c b/src/tbm_bo.c index bb2193e..39aac76 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -86,18 +86,6 @@ _tbm_flag_to_str(int f) return str; } -static void -_tbm_util_check_bo_cnt(tbm_bufmgr bufmgr) -{ - static int last_chk_bo_cnt = 0; - - if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) && - (bufmgr->bo_cnt > last_chk_bo_cnt)) { - TBM_DBG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt); - tbm_bufmgr_debug_show(bufmgr); - last_chk_bo_cnt = bufmgr->bo_cnt; - } -} /* LCOV_EXCL_STOP */ tbm_user_data * @@ -326,20 +314,6 @@ _tbm_bo_is_valid(tbm_bo bo) } static void -_tbm_bo_init(tbm_bufmgr bufmgr, tbm_bo bo, int flags) -{ - bo->bufmgr = bufmgr; - bo->flags = flags; - bo->magic = TBM_BO_MAGIC; - bo->ref_cnt = 1; - - LIST_INITHEAD(&bo->user_data_list); - - bufmgr->bo_cnt++; - LIST_ADD(&bo->item_link, &bufmgr->bo_list); -} - -static void _tbm_bo_deinit(tbm_bo bo) { bo->magic = 0; @@ -749,70 +723,25 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) { - tbm_bo bo, bo2 = NULL; + tbm_bo bo; tbm_error_e error; - int flags; _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL); - _tbm_util_check_bo_cnt(bufmgr); - - bo = calloc(1, sizeof(struct _tbm_bo)); + bo = tbm_bufmgr_internal_import_bo_with_fd(bufmgr, fd, &error); if (!bo) { /* LCOV_EXCL_START */ - TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd); - _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - bo->bo_data = tbm_module_bufmgr_bo_import_fd(bufmgr->module, bo, fd, &error); - if (!bo->bo_data) { - /* LCOV_EXCL_START */ - TBM_ERR("tbm_module_bufmgr_bo_import_fd failed. tbm_fd:%d", fd); + TBM_ERR("tbm_bufmgr_internal_import_fd failed. error:%d", error); _tbm_set_last_result(error); _tbm_bufmgr_mutex_unlock(); return NULL; /* LCOV_EXCL_STOP */ } - // return the existed bo2 if bo->bo_data and bo2->bo_data is the same - bo2 = tbm_bufmgr_internal_find_bo(bufmgr, bo); - if (bo2) { - TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list", - bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags)); - bo2->ref_cnt++; - free(bo); - _tbm_bufmgr_mutex_unlock(); - return bo2; - } - - if (bufmgr->use_hal_tbm) { - flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error); - if (error != TBM_ERROR_NONE) { - TBM_ERR("fail to get the bo flags(memory_types)"); - _tbm_set_last_result(error); - flags = TBM_BO_DEFAULT; - } - } else if (bufmgr->backend_module_data) { - flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error); - if (error != TBM_ERROR_NONE) { - TBM_ERR("fail to get the bo flags(memory_types)"); - _tbm_set_last_result(error); - flags = TBM_BO_DEFAULT; - } - } else { - if (bufmgr->backend->bo_get_flags) - flags = bufmgr->backend->bo_get_flags(bo); - else - flags = TBM_BO_DEFAULT; - } - - _tbm_bo_init(bufmgr, bo, flags); + LIST_INITHEAD(&bo->user_data_list); // TODO: remove this. build-break when it is removed. TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n", bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags)); diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index d4a15bb..a056c03 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -1096,4 +1096,65 @@ tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, unsigned int key, tbm_ return bo; } +tbm_bo +tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e *error) +{ + tbm_bo bo, bo2; + int flags; + + _tbm_bufmgr_check_bo_cnt(bufmgr); + + bo = calloc(1, sizeof(struct _tbm_bo)); + if (!bo) { + /* LCOV_EXCL_START */ + TBM_ERR("memory allocationc failed."); + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; + /* LCOV_EXCL_STOP */ + } + + bo->bo_data = tbm_module_bufmgr_bo_import_fd(bufmgr->module, bo, fd, error); + if (!bo->bo_data) { + /* LCOV_EXCL_START */ + TBM_ERR("tbm_module_bufmgr_bo_import_fd failed. tbm_fd:%d", fd); + free(bo); + return NULL; + /* LCOV_EXCL_STOP */ + } + + // return the existed bo2 if bo->bo_data and bo2->bo_data is the same + bo2 = tbm_bufmgr_internal_find_bo(bufmgr, bo); + if (bo2) { + TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list", + bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags)); + bo2->ref_cnt++; + free(bo); + return bo2; + } + + // TODO: refactoring tbm_module_bo + if (bufmgr->use_hal_tbm) { + flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)error); + if (error != TBM_ERROR_NONE) { + TBM_ERR("fail to get the bo flags(memory_types)"); + flags = TBM_BO_DEFAULT; + } + } else if (bufmgr->backend_module_data) { + flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, error); + if (error != TBM_ERROR_NONE) { + TBM_ERR("fail to get the bo flags(memory_types)"); + flags = TBM_BO_DEFAULT; + } + } else { + if (bufmgr->backend->bo_get_flags) + flags = bufmgr->backend->bo_get_flags(bo); + else + flags = TBM_BO_DEFAULT; + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + return bo; +} + /* LCOV_EXCL_STOP */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index efdf68c..7776b3c 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -355,6 +355,7 @@ tbm_bo tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_ tbm_bo tbm_bufmgr_internal_alloc_bo_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width, int bpp, int height, tbm_bo_memory_type flags, tbm_error_e *error); tbm_bo tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int flags); tbm_bo tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, tbm_key key, tbm_error_e *error); +tbm_bo tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e *error); /* tbm_module functions */ tbm_module *tbm_module_load(int fd); -- 2.7.4