tbm_bo
tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
{
- tbm_bo bo, bo2 = NULL;
+ tbm_bo bo;
tbm_error_e error;
- int flags;
_tbm_bufmgr_mutex_lock();
_tbm_set_last_result(TBM_ERROR_NONE);
TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
- _tbm_util_check_bo_cnt(bufmgr);
-
- bo = calloc(1, sizeof(struct _tbm_bo));
+ bo = tbm_bufmgr_internal_import_bo_with_key(bufmgr, key, &error);
if (!bo) {
/* LCOV_EXCL_START */
- TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
- _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- bo->bo_data = tbm_module_bufmgr_bo_import_key(bufmgr->module, bo, key, &error);
- if (!bo->bo_data) {
- /* LCOV_EXCL_START */
- TBM_ERR("tbm_module_bufmgr_bo_import_key failed. tbm_key:%d", key);
+ TBM_ERR("tbm_bufmgr_internal_import_key failed. error:%d", error);
_tbm_set_last_result(error);
_tbm_bufmgr_mutex_unlock();
return NULL;
/* LCOV_EXCL_STOP */
}
- // 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) {
- flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
- if (error != TBM_ERROR_NONE) {
- TBM_ERR("fail to get the bo flags(memory_types)");
- _tbm_set_last_result(error);
- flags = TBM_BO_DEFAULT;
- }
- } else if (bufmgr->backend_module_data) {
- flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
- if (error != TBM_ERROR_NONE) {
- TBM_ERR("fail to get the bo flags(memory_types)");
- _tbm_set_last_result(error);
- flags = TBM_BO_DEFAULT;
- }
- } else {
- if (bufmgr->backend->bo_get_flags)
- flags = bufmgr->backend->bo_get_flags(bo);
- else
- flags = TBM_BO_DEFAULT;
- }
-
- _tbm_bo_init(bufmgr, bo, flags);
-
TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));