From c8a260b8427a9ae2032618be579cfe4d8d0e07d7 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 23 Jun 2021 11:52:30 +0900 Subject: [PATCH] tbm_bufmgr: add error as a parameter add an error parameter to tbm_bufmgr_internal_alloc_bo_with_bo_data to get the error. Change-Id: I4def2716f5e749b9a768dfec5f6416d527cb2144 --- src/tbm_bufmgr.c | 20 +++++++++++++++----- src/tbm_bufmgr_int.h | 2 +- src/tbm_surface_internal.c | 6 ++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 51a075b..a57980f 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -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 */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 9212f1e..b24a7d9 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -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); diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c index 18afbf8..053bf1a 100644 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -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; } -- 2.7.4