X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftbm_bufmgr.c;h=55f9243bb17357433d0d0c61c2f9c78cb382a46f;hb=238437409d604e27c1dd8162578e4c4a9fa5acae;hp=8f39d721bd3e3bafe9d35e828c27bc934112d8eb;hpb=dd61cb4e10221cd9e5ccda8affea05d4a07d49d9;p=platform%2Fcore%2Fuifw%2Flibtbm.git diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 8f39d72..55f9243 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -33,7 +33,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tbm_bufmgr.h" #include "tbm_bufmgr_int.h" -#include "tbm_bufmgr_backend.h" +#include "tbm_drm_helper.h" #include "list.h" #include @@ -50,26 +50,10 @@ int b_dump_queue; static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER; static double scale_factor = 0; -static void _tbm_bufmgr_mutex_unlock(void); +void _tbm_bufmgr_mutex_unlock(void); //#define TBM_BUFMGR_INIT_TIME -#define PREFIX_LIB "libtbm_" -#define SUFFIX_LIB ".so" -#define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB - -/* values to indicate unspecified fields in XF86ModReqInfo. */ -#define MAJOR_UNSPEC 0xFF -#define MINOR_UNSPEC 0xFF -#define PATCH_UNSPEC 0xFFFF -#define ABI_VERS_UNSPEC 0xFFFFFFFF - -#define MODULE_VERSION_NUMERIC(maj, min, patch) \ - ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF)) -#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF) -#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) -#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) - #define MAX_SIZE_N(dest) (sizeof(dest) - strlen(dest) - 1) /* check condition */ @@ -91,37 +75,51 @@ static void _tbm_bufmgr_mutex_unlock(void); } \ } +#define TBM_BUFMGR_RETURN_VAL_SET_ERR_IF_FAIL(cond, val, error, error_type) {\ + if (!(cond)) {\ + TBM_ERR("'%s' failed.\n", #cond);\ + error = error_type;\ + _tbm_bufmgr_mutex_unlock();\ + return val;\ + } \ +} + /* LCOV_EXCL_START */ -static bool -_tbm_bufmgr_mutex_init(void) -{ - static bool tbm_bufmgr_mutex_init = false; - if (tbm_bufmgr_mutex_init) - return true; +static void +_tbm_bufmgr_check_bo_cnt(tbm_bufmgr bufmgr) +{ + static int last_chk_bo_cnt = 0; - if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) { - TBM_ERR("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n"); - return false; + 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; - tbm_bufmgr_mutex_init = true; + LIST_INITHEAD(&bo->user_data_list); - return true; + bufmgr->bo_cnt++; + LIST_ADD(&bo->item_link, &bufmgr->bo_list); } -static void +void _tbm_bufmgr_mutex_lock(void) { - if (!_tbm_bufmgr_mutex_init()) { - TBM_ERR("fail: _tbm_bufmgr_mutex_init()\n"); - return; - } - pthread_mutex_lock(&tbm_bufmgr_lock); } -static void +void _tbm_bufmgr_mutex_unlock(void) { pthread_mutex_unlock(&tbm_bufmgr_lock); @@ -179,6 +177,8 @@ _tbm_util_get_appname_from_pid(long pid, char *str) FILE *fp; int len; + if (pid <= 0) return; + snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", pid); fp = fopen(fn_cmdline, "r"); @@ -204,290 +204,13 @@ _tbm_util_get_appname_from_pid(long pid, char *str) snprintf(str, sizeof(cmdline), "%s", cmdline); } -static int -_check_version(TBMModuleVersionInfo *data) -{ - int backend_module_major, backend_module_minor; - int tbm_backend_major, tbm_backend_minor; - - backend_module_major = GET_ABI_MAJOR(data->abiversion); - backend_module_minor = GET_ABI_MINOR(data->abiversion); - - TBM_DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n", - data->modname ? data->modname : "UNKNOWN!", - data->vendor ? data->vendor : "UNKNOWN!", backend_module_major, backend_module_minor); - - tbm_backend_major = GET_ABI_MAJOR(TBM_ABI_VERSION); - tbm_backend_minor = GET_ABI_MINOR(TBM_ABI_VERSION); - - TBM_DBG("TBM ABI version %d.%d\n", - tbm_backend_major, tbm_backend_minor); - - if (backend_module_major != tbm_backend_major) { - TBM_ERR("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n", - backend_module_major, tbm_backend_major); - return 0; - } else if (backend_module_minor > tbm_backend_minor) { - TBM_ERR("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n", - backend_module_minor, tbm_backend_minor); - return 0; - } - - return 1; -} - -static int -_tbm_backend_check_bufmgr_func(tbm_backend_bufmgr_func *bufmgr_func) -{ - TBM_RETURN_VAL_IF_FAIL(bufmgr_func, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bufmgr_func->bufmgr_get_capabilities, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bufmgr_func->bufmgr_bind_native_display, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bufmgr_func->bufmgr_get_supported_formats, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bufmgr_func->bufmgr_get_plane_data, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bufmgr_func->bufmgr_alloc_bo, 0); /* mandatory symbol */ - if (!bufmgr_func->bufmgr_alloc_bo_with_format) - TBM_DBG("No bufmgr_func->bufmgr_alloc_bo_with_format."); - TBM_RETURN_VAL_IF_FAIL(bufmgr_func->bufmgr_import_fd, 0); /* mandatory symbol */ - if (!bufmgr_func->bufmgr_import_key) - TBM_DBG("No bufmgr_func->bo_export_key."); - - return 1; -} - -static int -_tbm_backend_check_bufmgr_bo(tbm_backend_bo_func *bo_func) -{ - TBM_RETURN_VAL_IF_FAIL(bo_func, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_free, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_get_size, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_get_memory_types, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_get_handle, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_map, 0); /* mandatory symbol */ - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_unmap, 0); /* mandatory symbol */ - if (!bo_func->bo_lock) - TBM_DBG("No bo_func->bo_lock."); - if (!bo_func->bo_unlock) - TBM_DBG("No bo_func->bo_unlock."); - TBM_RETURN_VAL_IF_FAIL(bo_func->bo_export_fd, 0); /* mandatory symbol */ - if (!bo_func->bo_export_key) - TBM_INFO("No bo_func->bo_export_key."); - - return 1; -} - -static int -_tbm_backend_load_module(tbm_bufmgr bufmgr, const char *file) -{ - char path[PATH_MAX] = {0, }; - void *module_data = NULL; - tbm_backend_module *backend_module_data = NULL; - tbm_backend_bufmgr_data *bufmgr_data = NULL; - int backend_module_major, backend_module_minor; - int tbm_backend_major, tbm_backend_minor; - tbm_error_e error; - - snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file); - - module_data = dlopen(path, RTLD_LAZY); - if (!module_data) { - TBM_ERR("failed to load module: %s(%s)\n", dlerror(), file); - return 0; - } - - backend_module_data = dlsym(module_data, "tbm_backend_module_data"); - if (!backend_module_data) { - TBM_ERR("Error: module does not have data object.\n"); - goto err; - } - - tbm_backend_major = GET_ABI_MAJOR(TBM_BACKEND_ABI_LATEST_VERSION); - tbm_backend_minor = GET_ABI_MINOR(TBM_BACKEND_ABI_LATEST_VERSION); - TBM_INFO("TBM Backend ABI version %d.%d\n", tbm_backend_major, tbm_backend_minor); - - backend_module_major = GET_ABI_MAJOR(backend_module_data->abi_version); - backend_module_minor = GET_ABI_MINOR(backend_module_data->abi_version); - - TBM_INFO("TBM module %s: vendor=\"%s\" Backend ABI version=%d.%d\n", - backend_module_data->name ? backend_module_data->name : "UNKNOWN!", - backend_module_data->vendor ? backend_module_data->vendor : "UNKNOWN!", - backend_module_major, backend_module_minor); - - if (backend_module_major > tbm_backend_major) { - TBM_ERR("TBM module ABI major ver(%d) is newer than the TBM's ver(%d)\n", - backend_module_major, tbm_backend_major); - goto err; - } else if (backend_module_minor > tbm_backend_minor) { - TBM_ERR("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n", - backend_module_minor, tbm_backend_minor); - goto err; - } - - if (!backend_module_data->init) { - TBM_ERR("Error: module does not supply init symbol.\n"); - goto err; - } - - if (!backend_module_data->deinit) { - TBM_ERR("Error: module does not supply deinit symbol.\n"); - goto err; - } - - bufmgr_data = backend_module_data->init(bufmgr, &error); - if (!bufmgr_data) { - TBM_ERR("Fail to init module(%s)\n", file); - goto err; - } - - /* check the mandatory symbols of the backend module */ - if (!_tbm_backend_check_bufmgr_func(bufmgr->bufmgr_func)) { - TBM_ERR("Fail to check the bufmgr_func symboles."); - goto err; - } - - if (!_tbm_backend_check_bufmgr_bo(bufmgr->bo_func)) { - TBM_ERR("Fail to check the bufmgr_bo symboles."); - goto err; - } - - /* get the capability */ - bufmgr->capabilities = bufmgr->bufmgr_func->bufmgr_get_capabilities(bufmgr_data, &error); - if (bufmgr->capabilities == TBM_BUFMGR_CAPABILITY_NONE) { - TBM_ERR("The capabilities of the backend module is TBM_BUFMGR_CAPABILITY_NONE."); - TBM_ERR("TBM_BUFMGR_CAPABILITY_SHARE_FD is the essential capability."); - goto err; - } - - if (!(bufmgr->capabilities & TBM_BUFMGR_CAPABILITY_SHARE_FD)) { - TBM_ERR("The capabilities of the backend module had no TBM_BUFMGR_CAPABILITY_SHARE_FD."); - TBM_ERR("The tbm backend has to get TBM_BUFMGR_CAPABILITY_SHARE_FD. "); - goto err; - } - - bufmgr->module_data = module_data; - bufmgr->backend_module_data = backend_module_data; - bufmgr->bufmgr_data = bufmgr_data; - - TBM_DBG("Success to load module(%s)\n", file); - - return 1; - -err: - if (bufmgr_data) - bufmgr->backend_module_data->deinit(bufmgr_data); - if (module_data) - dlclose(module_data); - - return 0; -} - -static int -_tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file) -{ - char path[PATH_MAX] = {0, }; - TBMModuleVersionInfo *vers; - TBMModuleData *initdata; - ModuleInitProc init; - void *module_data; - - snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file); - - module_data = dlopen(path, RTLD_LAZY); - if (!module_data) { - TBM_ERR("failed to load module: %s(%s)\n", dlerror(), file); - return 0; - } - - initdata = dlsym(module_data, "tbmModuleData"); - if (!initdata) { - TBM_ERR("Error: module does not have data object.\n"); - goto err; - } - - vers = initdata->vers; - if (!vers) { - TBM_ERR("Error: module does not supply version information.\n"); - goto err; - } - - init = initdata->init; - if (!init) { - TBM_ERR("Error: module does not supply init symbol.\n"); - goto err; - } - - if (!_check_version(vers)) { - TBM_ERR("Fail to check version.\n"); - goto err; - } - - if (!init(bufmgr, fd)) { - TBM_ERR("Fail to init module(%s)\n", file); - goto err; - } - - if (!bufmgr->backend || !bufmgr->backend->priv) { - TBM_ERR("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file); - goto err; - } - - bufmgr->module_data = module_data; - - TBM_DBG("Success to load module(%s)\n", file); - - return 1; - -err: - dlclose(module_data); - return 0; -} - -static int -_tbm_load_module(tbm_bufmgr bufmgr, int fd) -{ - struct dirent **namelist; - int ret = 0, n; - - /* try to load the new backend module */ - ret = _tbm_backend_load_module(bufmgr, DEFAULT_LIB); - if (ret) - return 1; - - /* try to load the old(deprecated) backend mdoule */ - ret = _tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB); - if (ret) - return 1; - - /* load bufmgr priv from configured path */ - n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort); - if (n < 0) { - TBM_ERR("no files : %s\n", BUFMGR_MODULE_DIR); - return 0; - } - - while (n--) { - if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) { - const char *p = strstr(namelist[n]->d_name, SUFFIX_LIB); - - if (p && !strcmp(p, SUFFIX_LIB)) { - ret = _tbm_backend_load_module(bufmgr, namelist[n]->d_name); - if (!ret) - ret = _tbm_bufmgr_load_module(bufmgr, fd, - namelist[n]->d_name); - } - } - - free(namelist[n]); - } - - free(namelist); - - return ret; -} /* LCOV_EXCL_STOP */ static tbm_bufmgr _tbm_bufmgr_init(int fd, int server) { + tbm_error_e error = TBM_ERROR_NONE; + #ifdef TBM_BUFMGR_INIT_TIME struct timeval start_tv, end_tv; #endif @@ -498,16 +221,9 @@ _tbm_bufmgr_init(int fd, int server) gettimeofday(&start_tv, NULL); #endif - /* LCOV_EXCL_START */ -#ifdef HAVE_DLOG - env = getenv("TBM_DLOG"); - if (env) { - bDlog = atoi(env); - TBM_DBG("TBM_DLOG=%s\n", env); - } else - bDlog = 1; -#endif + bDlog = 1; + /* LCOV_EXCL_START */ #ifdef TRACE env = getenv("TBM_TRACE"); if (env) { @@ -555,7 +271,8 @@ _tbm_bufmgr_init(int fd, int server) } /* load bufmgr priv from env */ - if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) { + gBufMgr->module = tbm_module_load(gBufMgr->fd); + if (!gBufMgr->module) { TBM_ERR("error : Fail to load bufmgr backend\n"); _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); free(gBufMgr); @@ -564,6 +281,31 @@ _tbm_bufmgr_init(int fd, int server) return NULL; } + + /* check the essential capabilities of tbm_module */ + gBufMgr->capabilities = tbm_module_get_capabilities(gBufMgr->module, &error); + if (gBufMgr->capabilities == TBM_BUFMGR_CAPABILITY_NONE) { + TBM_ERR("The capabilities of the backend module is TBM_BUFMGR_CAPABILITY_NONE."); + TBM_ERR("TBM_BUFMGR_CAPABILITY_SHARE_FD is the essential capability."); + tbm_module_unload(gBufMgr->module); + _tbm_set_last_result(error); + free(gBufMgr); + gBufMgr = NULL; + pthread_mutex_unlock(&gLock); + return NULL; + } + + if (!(gBufMgr->capabilities & TBM_BUFMGR_CAPABILITY_SHARE_FD)) { + TBM_ERR("The capabilities of the backend module had no TBM_BUFMGR_CAPABILITY_SHARE_FD."); + TBM_ERR("The tbm backend has to get TBM_BUFMGR_CAPABILITY_SHARE_FD. "); + tbm_module_unload(gBufMgr->module); + _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); + free(gBufMgr); + gBufMgr = NULL; + pthread_mutex_unlock(&gLock); + return NULL; + } + /* LCOV_EXCL_STOP */ gBufMgr->ref_count = 1; @@ -622,22 +364,22 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) { TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr)); - _tbm_bufmgr_mutex_lock(); pthread_mutex_lock(&gLock); + _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); if (!gBufMgr) { TBM_ERR("gBufmgr already destroy: bufmgr:%p\n", bufmgr); - pthread_mutex_unlock(&gLock); _tbm_bufmgr_mutex_unlock(); + pthread_mutex_unlock(&gLock); return; } bufmgr->ref_count--; if (bufmgr->ref_count > 0) { TBM_DBG("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr); - pthread_mutex_unlock(&gLock); _tbm_bufmgr_mutex_unlock(); + pthread_mutex_unlock(&gLock); return; } @@ -663,33 +405,18 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) LIST_DELINIT(&bufmgr->surf_list); } - if (bufmgr->backend_module_data) { - /* deinit and backend destroys the backend func and data */ - bufmgr->backend_module_data->deinit(bufmgr->bufmgr_data); - bufmgr->bo_func = NULL; - bufmgr->bufmgr_func = NULL; - bufmgr->bufmgr_data = NULL; - bufmgr->backend_module_data = NULL; - } else { - /* destroy bufmgr priv */ - bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv); - bufmgr->backend->priv = NULL; - tbm_backend_free(bufmgr->backend); - bufmgr->backend = NULL; - } - - TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr); - - dlclose(bufmgr->module_data); + tbm_module_unload(bufmgr->module); if (bufmgr->fd > 0) close(bufmgr->fd); + TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr); + free(bufmgr); gBufMgr = NULL; - pthread_mutex_unlock(&gLock); _tbm_bufmgr_mutex_unlock(); + pthread_mutex_unlock(&gLock); } unsigned int @@ -721,6 +448,7 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) int c = 0; int size; tbm_error_e error; + long pid = 0; pthread_mutex_lock(&gLock); _tbm_set_last_result(TBM_ERROR_NONE); @@ -741,12 +469,13 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) } TBM_SNRPRINTF(str, len, c, "\n"); - _tbm_util_get_appname_from_pid(getpid(), app_name); + pid = syscall(SYS_getpid); + _tbm_util_get_appname_from_pid(pid, app_name); _tbm_util_get_appname_brief(app_name); - TBM_SNRPRINTF(str, len, c, "============TBM DEBUG: %s(%d)===========================\n", - app_name, getpid()); + TBM_SNRPRINTF(str, len, c, "===========================================TBM DEBUG: %s(%ld)===========================================\n", + app_name, pid); - snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name "); + snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name "); if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) { LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) { @@ -765,20 +494,24 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) { char data[512] = {0,}; - unsigned int pid; + unsigned int surf_pid = 0; int i; - pid = _tbm_surface_internal_get_debug_pid(surf); - if (!pid) { + surf_pid = _tbm_surface_internal_get_debug_pid(surf); + if (!surf_pid) { /* if pid is null, set the self_pid */ - pid = getpid(); + surf_pid = syscall(SYS_getpid);; } memset(app_name, 0x0, 255 * sizeof(char)); - _tbm_util_get_appname_from_pid(pid, app_name); - _tbm_util_get_appname_brief(app_name); + if (geteuid() == 0) { + _tbm_util_get_appname_from_pid(surf_pid, app_name); + _tbm_util_get_appname_brief(app_name); + } else { + snprintf(app_name, sizeof(app_name), "%d", surf_pid); + } - snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s", + snprintf(data, 255, "%-3d %-11p %-5d %-6u %-7u %-4u %-7u %-3d %-3d %-8d %-9s %-22s", ++surf_cnt, surf, surf->refcnt, @@ -808,12 +541,9 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) TBM_SNRPRINTF(str, len, c, "%s\n", data); for (i = 0; i < surf->num_bos; i++) { - if (bufmgr->backend_module_data) { - size = bufmgr->bo_func->bo_get_size(surf->bos[i]->bo_data, &error); - if (error != TBM_ERROR_NONE) - TBM_WRN("fail to get the size of bo."); - } else - size = bufmgr->backend->bo_size(surf->bos[i]); + size = tbm_bo_data_get_size(surf->bos[i]->bo_data, &error); + if (error != TBM_ERROR_NONE) + TBM_WRN("fail to get the size of bo."); TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n", surf->bos[i], surf->bos[i]->ref_cnt, @@ -825,7 +555,7 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) TBM_SNRPRINTF(str, len, c, "\n"); TBM_SNRPRINTF(str, len, c, "[tbm_bo information]\n"); - TBM_SNRPRINTF(str, len, c, "no bo refcnt size lock_cnt map_cnt flags surface name\n"); + TBM_SNRPRINTF(str, len, c, "no bo refcnt size lock_cnt map_cnt flags surface name\n"); /* show the tbm_bo information in bo_list */ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { @@ -834,18 +564,13 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) tbm_key key = 0; LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) { - if (bufmgr->backend_module_data) { - size = bufmgr->bo_func->bo_get_size(bo->bo_data, &error); - if (error != TBM_ERROR_NONE) - TBM_WRN("fail to get the size of bo."); - key = bufmgr->bo_func->bo_export_key(bo->bo_data, &error); - if (error != TBM_ERROR_NONE) - TBM_WRN("fail to get the tdm_key of bo."); - } else { - size = bufmgr->backend->bo_size(bo); - key = bufmgr->backend->bo_export(bo); - } - TBM_SNRPRINTF(str, len, c, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p %-4d\n", + size = tbm_bo_data_get_size(bo->bo_data, &error); + if (error != TBM_ERROR_NONE) + TBM_WRN("fail to get the size of bo."); + key = tbm_bo_data_export_key(bo->bo_data, &error); + if (error != TBM_ERROR_NONE) + TBM_WRN("fail to get the tdm_key of bo."); + TBM_SNRPRINTF(str, len, c, "%-3d %-11p %-5d %-7d %-6d %-5u %-7d %-11p %-4d\n", ++bo_cnt, bo, bo->ref_cnt, @@ -860,7 +585,7 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n"); TBM_SNRPRINTF(str, len, c, "\n"); - TBM_SNRPRINTF(str, len, c, "===============================================================\n"); + TBM_SNRPRINTF(str, len, c, "========================================================================================================\n"); pthread_mutex_unlock(&gLock); @@ -1044,49 +769,24 @@ _tbm_bufmgr_get_bufmgr(void) int tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display) { - int ret; tbm_error_e error; _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); + TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), 0); - if (bufmgr->backend_module_data) { - if (!bufmgr->bufmgr_func->bufmgr_bind_native_display) { - TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n", - bufmgr, native_display); - _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED); - _tbm_bufmgr_mutex_unlock(); - return 1; - } + error = tbm_module_bind_native_display(bufmgr->module, native_display); + if (error != TBM_ERROR_NONE) { + _tbm_set_last_result(error); + _tbm_bufmgr_mutex_unlock(); - error = bufmgr->bufmgr_func->bufmgr_bind_native_display(bufmgr->bufmgr_data, (tbm_native_display *)native_display); - if (error != TBM_ERROR_NONE) { - TBM_ERR("error: tbm_bufmgr(%p) native_display(%p) error(%d)\n", - bufmgr, native_display, error); - _tbm_set_last_result(error); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - ret = 1; - } else { - if (!bufmgr->backend->bufmgr_bind_native_display) { - TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n", - bufmgr, native_display); - _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED); - _tbm_bufmgr_mutex_unlock(); + if (error == TBM_ERROR_NOT_SUPPORTED) { + TBM_WRN("Not supported, so skip: tbm_bufmgr(%p) native_display(%p)", bufmgr, native_display); return 1; } - ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, native_display); - if (!ret) { - TBM_ERR("error: tbm_bufmgr(%p) native_display(%p)\n", - bufmgr, native_display); - _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); - _tbm_bufmgr_mutex_unlock(); - return 0; - } + return 0; } TBM_INFO("tbm_bufmgr(%p) native_display(%p)\n", bufmgr, native_display); @@ -1141,4 +841,298 @@ 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 (tbm_module_compare_bo_data(bufmgr->module, bo2->bo_data, bo->bo_data)) + return bo2; + } + + return NULL; +} + +tbm_bo +tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags) +{ + tbm_error_e error = TBM_ERROR_NONE; + tbm_bo bo; + + _tbm_bufmgr_mutex_lock(); + + TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL); + TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL); + + _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; + goto failed; + /* LCOV_EXCL_STOP */ + } + + bo->bo_data = tbm_module_alloc_bo_data(bufmgr->module, bo, size, flags, &error); + if (!bo->bo_data) { + /* LCOV_EXCL_START */ + TBM_ERR("tbm_module_alloc_bo_data failed. size:%d flags:%s error:%d", size, _tbm_flag_to_str(flags), error); + free(bo); + _tbm_set_last_result(error); + _tbm_bufmgr_mutex_unlock(); + goto failed; + /* LCOV_EXCL_STOP */ + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)", bo, size, bo->ref_cnt, _tbm_flag_to_str(bo->flags)); + + _tbm_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); + + return bo; + +/* LCOV_EXCL_START */ +failed: + _tbm_set_last_result(error); + _tbm_bufmgr_mutex_unlock(); + + return NULL; +/* LCOV_EXCL_STOP */ +} + + +/* 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_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."); + *error = TBM_ERROR_OUT_OF_MEMORY; + goto failed; + /* LCOV_EXCL_STOP */ + } + + bo->bo_data = tbm_module_alloc_bo_data_with_format(bufmgr->module, format, bo_idx, width, height, bpp, flags, error); + if (!bo->bo_data) { + /* LCOV_EXCL_START */ + free(bo); + goto failed; + /* LCOV_EXCL_STOP */ + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + _tbm_bufmgr_mutex_unlock(); + + return bo; + +/* LCOV_EXCL_START */ +failed: + _tbm_bufmgr_mutex_unlock(); + + return NULL; +/* LCOV_EXCL_STOP */ +} + +tbm_bo +tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_data, int flags, tbm_error_e *error) +{ + tbm_bo bo, bo2 = NULL; + + _tbm_bufmgr_mutex_lock(); + + *error = TBM_ERROR_NONE; + + TBM_BUFMGR_RETURN_VAL_SET_ERR_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL, *error, TBM_ERROR_INVALID_PARAMETER); + TBM_BUFMGR_RETURN_VAL_SET_ERR_IF_FAIL(bo_data, NULL, *error, TBM_ERROR_INVALID_PARAMETER); + + _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; + _tbm_bufmgr_mutex_unlock(); + return NULL; + /* LCOV_EXCL_STOP */ + } + bo->bo_data = bo_data; + bo->get_from_surface_data = 1; + + // return an existed bo if the bo is already created with the same bo_data. + bo2 = tbm_bufmgr_internal_find_bo(bufmgr, bo); + if (bo2) { + bo2->ref_cnt++; + free(bo); + _tbm_bufmgr_mutex_unlock(); + return bo2; + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + TBM_TRACE_BO("bo(%p) refcnt(%d), flag(%s)", bo, bo->ref_cnt, _tbm_flag_to_str(bo->flags)); + + _tbm_bufmgr_mutex_unlock(); + + return bo; +} + +tbm_bo +tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, unsigned int key) +{ + tbm_error_e error = TBM_ERROR_NONE; + tbm_bo bo, bo2; + int flags; + + _tbm_bufmgr_mutex_lock(); + + 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."); + goto failed; + /* LCOV_EXCL_STOP */ + } + + bo->bo_data = tbm_module_import_bo_data_with_key(bufmgr->module, bo, key, &error); + if (!bo->bo_data) { + /* LCOV_EXCL_START */ + TBM_ERR("tbm_module_import_bo_data_with_key failed. tbm_key:%d", key); + free(bo); + goto failed; + /* 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_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); + return bo2; + } + + flags = tbm_bo_data_get_memory_types(bo->bo_data, &error); + if (error != TBM_ERROR_NONE) { + TBM_WRN("tbm_bo_data_get_memory_types filed. use the default flags:TBM_BO_DEFAULT."); + flags = TBM_BO_DEFAULT; + error = TBM_ERROR_NONE; + } + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list", + bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags)); + + _tbm_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); + + return bo; + +failed: + _tbm_set_last_result(error); + _tbm_bufmgr_mutex_unlock(); + + return NULL; +} + +tbm_bo +tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd) +{ + tbm_error_e error = TBM_ERROR_NONE; + tbm_bo bo, bo2; + int flags; + + _tbm_bufmgr_mutex_lock(); + + 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."); + goto failed; + /* LCOV_EXCL_STOP */ + } + + bo->bo_data = tbm_module_import_bo_data_with_fd(bufmgr->module, bo, fd, &error); + if (!bo->bo_data) { + /* LCOV_EXCL_START */ + TBM_ERR("tbm_module_import_bo_data_with_fd failed. tbm_fd:%d", fd); + free(bo); + goto failed; + /* 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); + _tbm_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); + return bo2; + } + + flags = tbm_bo_data_get_memory_types(bo->bo_data, &error); + if (error != TBM_ERROR_NONE) { + TBM_WRN("tbm_bo_data_get_memory_types filed. use the default flags:TBM_BO_DEFAULT."); + flags = TBM_BO_DEFAULT; + error = TBM_ERROR_NONE; + } + + TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)", + bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags)); + + _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + + _tbm_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); + + return bo; + +failed: + _tbm_set_last_result(error); + _tbm_bufmgr_mutex_unlock(); + + return NULL; +} + /* LCOV_EXCL_STOP */