tbm_bufmgr: add error as a parameter 14/260314/1
authorSooChan Lim <sc1.lim@samsung.com>
Wed, 23 Jun 2021 02:52:30 +0000 (11:52 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 23 Jun 2021 07:13:53 +0000 (16:13 +0900)
add an error parameter to tbm_bufmgr_internal_alloc_bo_with_bo_data
to get the error.

Change-Id: I4def2716f5e749b9a768dfec5f6416d527cb2144

src/tbm_bufmgr.c
src/tbm_bufmgr_int.h
src/tbm_surface_internal.c

index 51a075b..a57980f 100644 (file)
@@ -75,6 +75,15 @@ void _tbm_bufmgr_mutex_unlock(void);
        } \
 }
 
+#define TBM_BUFMGR_RETURN_VAL_SET_ERR_IF_FAIL(cond, val, error, error_type) {\
+       if (!(cond)) {\
+               TBM_ERR("'%s' failed.\n", #cond);\
+               error = error_type;\
+               _tbm_bufmgr_mutex_unlock();\
+               return val;\
+       } \
+}
+
 /* LCOV_EXCL_START */
 
 static void
@@ -933,15 +942,16 @@ fail:
 }
 
 tbm_bo
-tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_data, int flags)
+tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_data, int flags, tbm_error_e *error)
 {
        tbm_bo bo, bo2 = NULL;
 
        _tbm_bufmgr_mutex_lock();
-       _tbm_set_last_result(TBM_ERROR_NONE);
 
-       TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
-       TBM_BUFMGR_RETURN_VAL_IF_FAIL(bo_data, NULL);
+       *error = TBM_ERROR_NONE;
+
+       TBM_BUFMGR_RETURN_VAL_SET_ERR_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_BUFMGR_RETURN_VAL_SET_ERR_IF_FAIL(bo_data, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
 
        _tbm_bufmgr_check_bo_cnt(bufmgr);
 
@@ -949,7 +959,7 @@ tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_dat
        if (!bo) {
                /* LCOV_EXCL_START */
                TBM_ERR("memory allocationc failed.");
-               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+               *error = TBM_ERROR_OUT_OF_MEMORY;
                _tbm_bufmgr_mutex_unlock();
                return NULL;
                /* LCOV_EXCL_STOP */
index 9212f1e..b24a7d9 100644 (file)
@@ -309,7 +309,7 @@ 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_bo_data *bo_data, int flags);
+tbm_bo tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_data, int flags, tbm_error_e *error);
 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);
 
index 18afbf8..053bf1a 100644 (file)
@@ -767,10 +767,9 @@ _tbm_surface_internal_create_surface_data(tbm_bufmgr bufmgr, int width, int heig
        }
 
        for (i = 0; i < num_bos; i++) {
-               surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_bo_data(bufmgr, bo_data_array[i], flags);
+               surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_bo_data(bufmgr, bo_data_array[i], flags, error);
                if (!surf->bos[i]) {
                        TBM_ERR("fail to alloc bo idx:%d", i);
-                       *error = tbm_get_last_error();
                        goto get_bo_fail;
                }
 
@@ -884,10 +883,9 @@ _tbm_surface_internal_import_surface_data(tbm_bufmgr bufmgr, int width, int heig
        surf->flags = flags;
 
        for (i = 0; i < num_bos; i++) {
-               surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_bo_data(bufmgr, bo_data_array[i], flags);
+               surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_bo_data(bufmgr, bo_data_array[i], flags, error);
                if (!surf->bos[i]) {
                        TBM_ERR("fail to alloc bo idx:%d", i);
-                       *error = tbm_get_last_error();
                        goto get_bo_fail;
                }