X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftbm_bufmgr.c;h=a056c03205fd2ff30487953128675a4e5337d198;hb=e565c41f907df4ed8a2b85d304bf11cc3ba0724d;hp=48dca8ea71eef431b7c236cf1e2a0214e398051d;hpb=78ddca445ba8da350a0a828a79fb1ba8511627b8;p=platform%2Fcore%2Fuifw%2Flibtbm.git diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 48dca8e..a056c03 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -1035,4 +1035,126 @@ tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data return bo; } +tbm_bo +tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, unsigned int key, tbm_error_e *error) +{ + tbm_bo bo, bo2; + int flags; + + _tbm_bufmgr_check_bo_cnt(bufmgr); + + bo = calloc(1, sizeof(struct _tbm_bo)); + if (!bo) { + /* LCOV_EXCL_START */ + TBM_ERR("memory allocationc failed."); + *error = TBM_ERROR_OUT_OF_MEMORY; + 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); + free(bo); + 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); + return bo2; + } + + // TODO: refactoring tbm_module_bo + 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)"); + 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)"); + flags = TBM_BO_DEFAULT; + } + } else { + if (bufmgr->backend->bo_get_flags) + flags = bufmgr->backend->bo_get_flags(bo); + else + flags = TBM_BO_DEFAULT; + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + return bo; +} + +tbm_bo +tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e *error) +{ + tbm_bo bo, bo2; + int flags; + + _tbm_bufmgr_check_bo_cnt(bufmgr); + + bo = calloc(1, sizeof(struct _tbm_bo)); + if (!bo) { + /* LCOV_EXCL_START */ + TBM_ERR("memory allocationc failed."); + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; + /* LCOV_EXCL_STOP */ + } + + bo->bo_data = tbm_module_bufmgr_bo_import_fd(bufmgr->module, bo, fd, error); + if (!bo->bo_data) { + /* LCOV_EXCL_START */ + TBM_ERR("tbm_module_bufmgr_bo_import_fd failed. tbm_fd:%d", fd); + free(bo); + 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) fd(%d) flag(%s) in list", + bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags)); + bo2->ref_cnt++; + free(bo); + return bo2; + } + + // TODO: refactoring tbm_module_bo + 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)"); + 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)"); + flags = TBM_BO_DEFAULT; + } + } else { + if (bufmgr->backend->bo_get_flags) + flags = bufmgr->backend->bo_get_flags(bo); + else + flags = TBM_BO_DEFAULT; + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + return bo; +} + /* LCOV_EXCL_STOP */