tbm_bufmgr: change tbm_bo_alloc_with_format name
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr.c
index 43906f1..b235029 100644 (file)
@@ -77,6 +77,33 @@ void _tbm_bufmgr_mutex_unlock(void);
 
 /* LCOV_EXCL_START */
 
+static void
+_tbm_bufmgr_check_bo_cnt(tbm_bufmgr bufmgr)
+{
+       static int last_chk_bo_cnt = 0;
+
+       if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
+               (bufmgr->bo_cnt > last_chk_bo_cnt)) {
+               TBM_DBG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt);
+               tbm_bufmgr_debug_show(bufmgr);
+               last_chk_bo_cnt = bufmgr->bo_cnt;
+       }
+}
+
+static void
+_tbm_bufmgr_initialize_bo(tbm_bufmgr bufmgr, tbm_bo bo, int flags)
+{
+       bo->bufmgr = bufmgr;
+       bo->flags = flags;
+       bo->magic = TBM_BO_MAGIC;
+       bo->ref_cnt = 1;
+
+       LIST_INITHEAD(&bo->user_data_list);
+
+       bufmgr->bo_cnt++;
+       LIST_ADD(&bo->item_link, &bufmgr->bo_list);
+}
+
 void
 _tbm_bufmgr_mutex_lock(void)
 {
@@ -885,4 +912,50 @@ tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo)
        return NULL;
 }
 
+/* LCOV_EXCL_START */
+
+tbm_bo
+tbm_bufmgr_internal_alloc_bo_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
+                                               int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
+{
+       tbm_bo bo = 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_check_bo_cnt(bufmgr);
+
+       bo = calloc(1, sizeof(struct _tbm_bo));
+       if (!bo) {
+               /* LCOV_EXCL_START */
+               TBM_ERR("memory allocationc failed.");
+               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+               /* LCOV_EXCL_STOP */
+               goto fail;
+       }
+
+       bo->bo_data = tbm_module_bufmgr_bo_alloc_with_format(bufmgr->module, format, bo_idx, width, height, bpp, flags, error);
+       if (!bo->bo_data) {
+               /* LCOV_EXCL_START */
+               _tbm_set_last_result(*error);
+               /* LCOV_EXCL_STOP */
+               goto fail;
+       }
+
+       _tbm_bufmgr_initialize_bo(bufmgr, bo, flags);
+
+       _tbm_bufmgr_mutex_unlock();
+
+       return bo;
+
+fail:
+       if (bo)
+               free(bo);
+       _tbm_bufmgr_mutex_unlock();
+
+       return NULL;
+}
+
 /* LCOV_EXCL_STOP */