tbm_bufmgr: add tbm_bufmgr_internal_alloc_bo and use it 02/259902/1
authorSooChan Lim <sc1.lim@samsung.com>
Wed, 16 Jun 2021 07:42:24 +0000 (16:42 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 16 Jun 2021 07:42:24 +0000 (16:42 +0900)
The tbm_bufmgr generates tbm_bo and manages them.

Change-Id: I2dae9758aba658c28c26ba595a049edc45f914c8

src/tbm_bo.c
src/tbm_bufmgr.c
src/tbm_bufmgr_int.h

index 1faccdc..dd75031 100644 (file)
@@ -352,7 +352,6 @@ tbm_bo
 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
 {
        tbm_bo bo;
-       tbm_backend_bo_data *bo_data;
        tbm_error_e error;
 
        _tbm_bufmgr_mutex_lock();
@@ -361,42 +360,22 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
        TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
        TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
 
-       bo = calloc(1, sizeof(struct _tbm_bo));
+       bo = tbm_bufmgr_internal_alloc_bo(bufmgr, size, flags, &error);
        if (!bo) {
                /* LCOV_EXCL_START */
-               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+               TBM_ERR("tbm_bufmgr_internal_alloc_bo failed. error:%d", error);
+               _tbm_set_last_result(error);
                _tbm_bufmgr_mutex_unlock();
                return NULL;
                /* LCOV_EXCL_STOP */
        }
 
-       _tbm_util_check_bo_cnt(bufmgr);
-
-       bo_data = tbm_module_bufmgr_bo_alloc(bufmgr->module, bo, size, flags, &error);
-       if (!bo_data || error != TBM_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               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;
-       bo->priv = (void *)bo_data; // TODO: this will be DEPRECATED.
-
-       _tbm_bo_init(bufmgr, bo, flags);
-
        TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
                        _tbm_flag_to_str(bo->flags));
 
        _tbm_bufmgr_mutex_unlock();
 
        return bo;
-
-alloc_fail:
-       TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
-       free(bo);
-       _tbm_bufmgr_mutex_unlock();
-       return NULL;
 }
 
 tbm_bo
index b20523a..48dca8e 100644 (file)
@@ -912,6 +912,40 @@ tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo)
        return NULL;
 }
 
+tbm_bo
+tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_error_e *error)
+{
+       tbm_bo bo;
+       tbm_backend_bo_data *bo_data;
+
+       _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_data = tbm_module_bufmgr_bo_alloc(bufmgr->module, bo, size, flags, error);
+       if (!bo_data) {
+               /* LCOV_EXCL_START */
+               TBM_ERR("tbm_module_bufmgr_bo_alloc failed. size:%d flags:%s error:%d", size, _tbm_flag_to_str(flags), *error);
+               free(bo);
+               return NULL;
+               /* LCOV_EXCL_STOP */
+       }
+       bo->bo_data = bo_data;
+       bo->priv = (void *)bo_data; // TODO: this will be DEPRECATED.
+
+       _tbm_bufmgr_initialize_bo(bufmgr, bo, flags);
+
+       return bo;
+}
+
+
 /* LCOV_EXCL_START */
 
 tbm_bo
index 230e36c..8365cfa 100644 (file)
@@ -351,6 +351,7 @@ void _tbm_bufmgr_mutex_lock(void);
 void _tbm_bufmgr_mutex_unlock(void);
 tbm_bo tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo);
 
+tbm_bo tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_error_e *error);
 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);