From 45faa5746254e01d283feaca7fcf981462916862 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 16 Jun 2021 12:14:02 +0900 Subject: [PATCH] tbm_bufmgr: add tbm_bufmgr_internal_find_bo The tbm_bufmgr_internal_find_bo find the bo which has the same bo_data in the bufmgr->bo_list. Change-Id: I6fe4cda6bac1714a8c9d69fb938a179f09cc701a --- src/tbm_bo.c | 40 ++++++++++++++++++---------------------- src/tbm_bufmgr.c | 22 ++++++++++++++++++++++ src/tbm_bufmgr_int.h | 1 + 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/tbm_bo.c b/src/tbm_bo.c index 0f4210f..58d832b 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -871,17 +871,15 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) /* LCOV_EXCL_STOP */ } - if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { - LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) { - if (bo2->bo_data == bo->bo_data) { - TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list", - bo2, bo2->ref_cnt, key, _tbm_flag_to_str(bo2->flags)); - bo2->ref_cnt++; - free(bo); - _tbm_bufmgr_mutex_unlock(); - return bo2; - } - } + // return the existed bo2 if bo->bo_data and bo2->bo_data is the same + bo2 = tbm_bufmgr_internal_find_bo(bufmgr, bo); + if (bo2) { + TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list", + bo2, bo2->ref_cnt, key, _tbm_flag_to_str(bo2->flags)); + bo2->ref_cnt++; + free(bo); + _tbm_bufmgr_mutex_unlock(); + return bo2; } if (bufmgr->use_hal_tbm) { @@ -949,17 +947,15 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) /* LCOV_EXCL_STOP */ } - if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { - LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) { - if (bo2->bo_data == bo->bo_data) { - TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n", - bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags)); - bo2->ref_cnt++; - free(bo); - _tbm_bufmgr_mutex_unlock(); - return bo2; - } - } + // return the existed bo2 if bo->bo_data and bo2->bo_data is the same + bo2 = tbm_bufmgr_internal_find_bo(bufmgr, bo); + if (bo2) { + TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list", + bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags)); + bo2->ref_cnt++; + free(bo); + _tbm_bufmgr_mutex_unlock(); + return bo2; } if (bufmgr->use_hal_tbm) { diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index ec7a7cf..43906f1 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -863,4 +863,26 @@ tbm_bufmgr tbm_bufmgr_get(void) { return gBufMgr; } + + +tbm_bo +tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo) +{ + tbm_bo bo2 = NULL; + + TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL); + TBM_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL); + + if (LIST_IS_EMPTY(&bufmgr->bo_list)) + return NULL; + + LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) { + if (bo2->bo_data == bo->bo_data) { + return bo2; + } + } + + return NULL; +} + /* LCOV_EXCL_STOP */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 1cf31d2..8a19f80 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -345,6 +345,7 @@ void _tbm_set_last_result(tbm_error_e err); /* functions for mutex */ 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_bo_alloc_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_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int flags); -- 2.34.1