tbm_bufmgr: add tbm_bufmgr_internal_find_bo 98/259898/1
authorSooChan Lim <sc1.lim@samsung.com>
Wed, 16 Jun 2021 03:14:02 +0000 (12:14 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 16 Jun 2021 03:14:02 +0000 (12:14 +0900)
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
src/tbm_bufmgr.c
src/tbm_bufmgr_int.h

index 0f4210f..58d832b 100644 (file)
@@ -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) {
index ec7a7cf..43906f1 100644 (file)
@@ -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 */
index 1cf31d2..8a19f80 100644 (file)
@@ -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);