tbm_module: make tbm_module_bufmgr_bo_alloc function 84/259884/1
authorSooChan Lim <sc1.lim@samsung.com>
Fri, 11 Jun 2021 07:53:55 +0000 (16:53 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 15 Jun 2021 12:01:53 +0000 (21:01 +0900)
encapsulate the bufmgr_bo_allocation with this function.

Change-Id: I28f3d6196950ca3a7e41757b63f8da64fc45a237

src/tbm_bo.c
src/tbm_bufmgr_int.h
src/tbm_module.c

index cf1dda0..570690b 100644 (file)
@@ -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);
 
index 70957f8..c7e7d69 100644 (file)
@@ -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_ */
index ae8e848..e0d8daf 100644 (file)
@@ -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;
+}