From 1062858e7241fd77b05305bcdd600c6e84f9ceab Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 11 Jun 2021 16:53:55 +0900 Subject: [PATCH] tbm_module: make tbm_module_bufmgr_bo_alloc function encapsulate the bufmgr_bo_allocation with this function. Change-Id: I28f3d6196950ca3a7e41757b63f8da64fc45a237 --- src/tbm_bo.c | 33 +++++++-------------------------- src/tbm_bufmgr_int.h | 3 ++- src/tbm_module.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/tbm_bo.c b/src/tbm_bo.c index cf1dda0..570690b 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -354,7 +354,6 @@ tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) { tbm_bo bo; - void *bo_priv; tbm_backend_bo_data *bo_data; tbm_error_e error; @@ -375,34 +374,16 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) _tbm_util_check_bo_cnt(bufmgr); - if (bufmgr->use_hal_tbm) { - bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo(bufmgr->hal_bufmgr, size, flags, (hal_tbm_error *)&error); + bo_data = tbm_module_bufmgr_bo_alloc(bufmgr->module, bo, size, flags, &error); + if (!bo_data || error != TBM_ERROR_NONE) { /* LCOV_EXCL_START */ - if (!bo_data) { - _tbm_set_last_result(error); - goto alloc_fail; - } + TBM_ERR("tbm_module_bufmgr_bo_alloc failed. error:%d", error); + _tbm_set_last_result(error); + goto alloc_fail; /* LCOV_EXCL_STOP */ - bo->bo_data = bo_data; - } else if (bufmgr->backend_module_data) { - bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error); - if (!bo_data) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(error); - goto alloc_fail; - /* LCOV_EXCL_STOP */ - } - bo->bo_data = bo_data; - } else { - bo_priv = bufmgr->backend->bo_alloc(bo, size, flags); - if (!bo_priv) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); - goto alloc_fail; - /* LCOV_EXCL_STOP */ - } - bo->priv = bo_priv; } + bo->bo_data = bo_data; + bo->priv = (void *)bo_data; // TODO: this will be DEPRECATED. _tbm_bo_init(bufmgr, bo, flags); diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 70957f8..c7e7d69 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -357,6 +357,7 @@ tbm_bo tbm_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data tbm_module *tbm_module_load(int fd); void tbm_module_unload(tbm_module *module); -int tbm_module_bufmgr_get_capabilities(tbm_module *module); +int tbm_module_bufmgr_get_capabilities(tbm_module *module); +tbm_backend_bo_data *tbm_module_bufmgr_bo_alloc(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error); #endif /* _TBM_BUFMGR_INT_H_ */ diff --git a/src/tbm_module.c b/src/tbm_module.c index ae8e848..e0d8daf 100644 --- a/src/tbm_module.c +++ b/src/tbm_module.c @@ -485,3 +485,41 @@ tbm_module_bufmgr_get_capabilities(tbm_module *module) return capabilities; } + +tbm_backend_bo_data * +tbm_module_bufmgr_bo_alloc(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error) +{ + tbm_backend_bo_data *bo_data = NULL; + tbm_backend_bufmgr_func *bufmgr_func = NULL; + tbm_bufmgr_backend backend = NULL; + + TBM_RETURN_VAL_SET_ERR_IF_FAIL(module, NULL, *error, TBM_ERROR_INVALID_PARAMETER); + + switch (module->type) { + case TBM_MODULE_TYPE_HAL_TBM: + bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo(module->hal_bufmgr, size, flags, (hal_tbm_error *)error); + break; + case TBM_MODULE_TYPE_TBM_BACKEND: + bufmgr_func = module->bufmgr_func; + TBM_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr_func, NULL, *error, TBM_ERROR_INVALID_OPERATION); + TBM_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr_func->bufmgr_alloc_bo, NULL, *error, TBM_ERROR_NOT_SUPPORTED); + + bo_data = module->bufmgr_func->bufmgr_alloc_bo(module->bufmgr_data, (unsigned int)size, flags, error); + break; + case TBM_MODULE_TYPE_BUFMGR_BACKEND: + TBM_WRN("!!WARNING: This backend interface will be DEPRECATED after Tizen 7.0."); + backend = module->backend; + TBM_RETURN_VAL_SET_ERR_IF_FAIL(backend, NULL, *error, TBM_ERROR_INVALID_OPERATION); + TBM_RETURN_VAL_SET_ERR_IF_FAIL(backend->bo_alloc, NULL, *error, TBM_ERROR_NOT_SUPPORTED); + + bo_data = (void *)module->backend->bo_alloc(bo, size, flags); + *error = TBM_ERROR_NONE; + break; + default: + TBM_ERR("Wrong module type:%d", module->type); + *error = TBM_ERROR_INVALID_OPERATION; + break; + } + + return bo_data; +} -- 2.7.4