X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftbm_bufmgr.c;h=8f39d721bd3e3bafe9d35e828c27bc934112d8eb;hb=e5c10c6c0868e37c78ba5cd2bcf0fb9d05daf733;hp=f101e735d91f7e3d68957f1d1e1bc745846bc4e6;hpb=04a7544ed0fc29da57828a30057e28cf50020c37;p=platform%2Fcore%2Fuifw%2Flibtbm.git diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index f101e73..8f39d72 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -38,13 +38,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -#ifdef DEBUG -int bDebug; -#endif - -#ifdef TRACE -int bTrace; -#endif +int trace_mask = 0; #ifdef HAVE_DLOG int bDlog; @@ -55,7 +49,6 @@ int b_dump_queue; static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER; -static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE; static double scale_factor = 0; static void _tbm_bufmgr_mutex_unlock(void); @@ -66,9 +59,9 @@ static void _tbm_bufmgr_mutex_unlock(void); #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 MAJOR_UNSPEC 0xFF +#define MINOR_UNSPEC 0xFF +#define PATCH_UNSPEC 0xFFFF #define ABI_VERS_UNSPEC 0xFFFFFFFF #define MODULE_VERSION_NUMERIC(maj, min, patch) \ @@ -77,10 +70,13 @@ static void _tbm_bufmgr_mutex_unlock(void); #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 */ #define TBM_BUFMGR_RETURN_IF_FAIL(cond) {\ if (!(cond)) {\ - TBM_LOG_E("'%s' failed.\n", #cond);\ + TBM_ERR("'%s' failed.\n", #cond);\ + _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\ _tbm_bufmgr_mutex_unlock();\ return;\ } \ @@ -88,24 +84,13 @@ static void _tbm_bufmgr_mutex_unlock(void); #define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\ if (!(cond)) {\ - TBM_LOG_E("'%s' failed.\n", #cond);\ + TBM_ERR("'%s' failed.\n", #cond);\ + _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\ _tbm_bufmgr_mutex_unlock();\ return val;\ } \ } -enum { - LOCK_TRY_ONCE, - LOCK_TRY_ALWAYS, - LOCK_TRY_NEVER -}; - -static void -_tbm_set_last_result(tbm_error_e err) -{ - tbm_last_error = err; -} - /* LCOV_EXCL_START */ static bool _tbm_bufmgr_mutex_init(void) @@ -116,7 +101,7 @@ _tbm_bufmgr_mutex_init(void) return true; if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) { - TBM_LOG_E("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n"); + TBM_ERR("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n"); return false; } @@ -129,7 +114,7 @@ static void _tbm_bufmgr_mutex_lock(void) { if (!_tbm_bufmgr_mutex_init()) { - TBM_LOG_E("fail: _tbm_bufmgr_mutex_init()\n"); + TBM_ERR("fail: _tbm_bufmgr_mutex_init()\n"); return; } @@ -142,51 +127,6 @@ _tbm_bufmgr_mutex_unlock(void) pthread_mutex_unlock(&tbm_bufmgr_lock); } -static char * -_tbm_flag_to_str(int f) -{ - static char str[255]; - - if (f == TBM_BO_DEFAULT) - snprintf(str, 255, "DEFAULT"); - else { - int c = 0; - - if (f & TBM_BO_SCANOUT) - c = snprintf(&str[c], 255, "SCANOUT"); - - if (f & TBM_BO_NONCACHABLE) { - if (c) - c = snprintf(&str[c], 255, ", "); - c = snprintf(&str[c], 255, "NONCACHABLE,"); - } - - if (f & TBM_BO_WC) { - if (c) - c = snprintf(&str[c], 255, ", "); - c = snprintf(&str[c], 255, "WC"); - } - } - - return str; -} - -static void -_tbm_util_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_DEBUG("============TBM BO CNT DEBUG: bo_cnt=%d\n", - bufmgr->bo_cnt); - - tbm_bufmgr_debug_show(bufmgr); - - last_chk_bo_cnt = bufmgr->bo_cnt; - } -} - static int _tbm_util_get_max_surface_size(int *w, int *h) { @@ -243,12 +183,12 @@ _tbm_util_get_appname_from_pid(long pid, char *str) fp = fopen(fn_cmdline, "r"); if (fp == 0) { - TBM_LOG_E("cannot file open %s\n", fn_cmdline); + TBM_ERR("cannot file open %s\n", fn_cmdline); return; } if (!fgets(cmdline, 255, fp)) { - TBM_LOG_E("fail to get appname for pid(%ld)\n", pid); + TBM_ERR("fail to get appname for pid(%ld)\n", pid); fclose(fp); return; } @@ -263,227 +203,181 @@ _tbm_util_get_appname_from_pid(long pid, char *str) snprintf(str, sizeof(cmdline), "%s", cmdline); } -/* LCOV_EXCL_STOP */ -tbm_user_data -*user_data_lookup(struct list_head *user_data_list, unsigned long key) +static int +_check_version(TBMModuleVersionInfo *data) { - tbm_user_data *old_data = NULL; + int backend_module_major, backend_module_minor; + int tbm_backend_major, tbm_backend_minor; - if (LIST_IS_EMPTY(user_data_list)) - return NULL; + backend_module_major = GET_ABI_MAJOR(data->abiversion); + backend_module_minor = GET_ABI_MINOR(data->abiversion); - LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) { - if (old_data->key == key) - return old_data; - } + 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); - return NULL; -} + tbm_backend_major = GET_ABI_MAJOR(TBM_ABI_VERSION); + tbm_backend_minor = GET_ABI_MINOR(TBM_ABI_VERSION); -tbm_user_data -*user_data_create(unsigned long key, tbm_data_free data_free_func) -{ - tbm_user_data *user_data; + TBM_DBG("TBM ABI version %d.%d\n", + tbm_backend_major, tbm_backend_minor); - user_data = calloc(1, sizeof(tbm_user_data)); - if (!user_data) { - /* LCOV_EXCL_START */ - TBM_LOG_E("fail to allocate an user_date\n"); - return NULL; - /* LCOV_EXCL_STOP */ + 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; } - user_data->key = key; - user_data->free_func = data_free_func; - - return user_data; -} - -void -user_data_delete(tbm_user_data *user_data) -{ - if (user_data->data && user_data->free_func) - user_data->free_func(user_data->data); - - LIST_DEL(&user_data->item_link); - - free(user_data); + return 1; } static int -_bo_lock(tbm_bo bo, int device, int opt) +_tbm_backend_check_bufmgr_func(tbm_backend_bufmgr_func *bufmgr_func) { - tbm_bufmgr bufmgr = bo->bufmgr; - int ret = 1; - - if (bufmgr->backend->bo_lock) - ret = bufmgr->backend->bo_lock(bo, device, opt); + 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 ret; + return 1; } -static void -_bo_unlock(tbm_bo bo) +static int +_tbm_backend_check_bufmgr_bo(tbm_backend_bo_func *bo_func) { - tbm_bufmgr bufmgr = bo->bufmgr; + 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."); - if (bufmgr->backend->bo_unlock) - bufmgr->backend->bo_unlock(bo); + return 1; } static int -_tbm_bo_lock(tbm_bo bo, int device, int opt) +_tbm_backend_load_module(tbm_bufmgr bufmgr, const char *file) { - tbm_bufmgr bufmgr; - int old, ret; - - if (!bo) - return 0; - - bufmgr = bo->bufmgr; + 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; - /* do not try to lock the bo */ - if (bufmgr->lock_type == LOCK_TRY_NEVER) - return 1; + snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file); - if (bo->lock_cnt < 0) { - TBM_LOG_E("error bo:%p LOCK_CNT=%d\n", - bo, bo->lock_cnt); + module_data = dlopen(path, RTLD_LAZY); + if (!module_data) { + TBM_ERR("failed to load module: %s(%s)\n", dlerror(), file); return 0; } - old = bo->lock_cnt; - - switch (bufmgr->lock_type) { - case LOCK_TRY_ONCE: - if (bo->lock_cnt == 0) { - _tbm_bufmgr_mutex_unlock(); - ret = _bo_lock(bo, device, opt); - _tbm_bufmgr_mutex_lock(); - if (ret) - bo->lock_cnt++; - } else - ret = 1; - break; - case LOCK_TRY_ALWAYS: - _tbm_bufmgr_mutex_unlock(); - ret = _bo_lock(bo, device, opt); - _tbm_bufmgr_mutex_lock(); - if (ret) - bo->lock_cnt++; - break; - default: - TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n", - bo, bufmgr->lock_type); - ret = 0; - break; + 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_DBG_LOCK(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt); - - return ret; -} - -static void -_tbm_bo_unlock(tbm_bo bo) -{ - tbm_bufmgr bufmgr; - int old; - - if (!bo) - return; - - bufmgr = bo->bufmgr; + 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); - /* do not try to unlock the bo */ - if (bufmgr->lock_type == LOCK_TRY_NEVER) - return; + backend_module_major = GET_ABI_MAJOR(backend_module_data->abi_version); + backend_module_minor = GET_ABI_MINOR(backend_module_data->abi_version); - old = bo->lock_cnt; + 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); - switch (bufmgr->lock_type) { - case LOCK_TRY_ONCE: - if (bo->lock_cnt > 0) { - bo->lock_cnt--; - if (bo->lock_cnt == 0) - _bo_unlock(bo); - } - break; - case LOCK_TRY_ALWAYS: - if (bo->lock_cnt > 0) { - bo->lock_cnt--; - _bo_unlock(bo); - } - break; - default: - TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n", - bo, bufmgr->lock_type); - break; + 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 (bo->lock_cnt < 0) - bo->lock_cnt = 0; - - TBM_DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt); -} - -static int -_tbm_bo_is_valid(tbm_bo bo) -{ - tbm_bo old_data = NULL; - - if (bo == NULL || gBufMgr == NULL) { - TBM_LOG_E("error: bo is NULL or tbm_bufmgr was deinited\n"); - return 0; + if (!backend_module_data->init) { + TBM_ERR("Error: module does not supply init symbol.\n"); + goto err; } - if (LIST_IS_EMPTY(&gBufMgr->bo_list)) { - TBM_LOG_E("error: gBufMgr->bo_list is EMPTY.\n"); - return 0; + if (!backend_module_data->deinit) { + TBM_ERR("Error: module does not supply deinit symbol.\n"); + goto err; } - LIST_FOR_EACH_ENTRY(old_data, &gBufMgr->bo_list, item_link) { - if (old_data == bo) - return 1; + bufmgr_data = backend_module_data->init(bufmgr, &error); + if (!bufmgr_data) { + TBM_ERR("Fail to init module(%s)\n", file); + goto err; } - TBM_LOG_E("error: No valid bo(%p).\n", bo); + /* 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; + } - return 0; -} + if (!_tbm_backend_check_bufmgr_bo(bufmgr->bo_func)) { + TBM_ERR("Fail to check the bufmgr_bo symboles."); + goto err; + } -/* LCOV_EXCL_START */ -static int -_check_version(TBMModuleVersionInfo *data) -{ - int abimaj, abimin; - int vermaj, vermin; + /* 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; + } - abimaj = GET_ABI_MAJOR(data->abiversion); - abimin = GET_ABI_MINOR(data->abiversion); + 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; + } - TBM_DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n", - data->modname ? data->modname : "UNKNOWN!", - data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin); + bufmgr->module_data = module_data; + bufmgr->backend_module_data = backend_module_data; + bufmgr->bufmgr_data = bufmgr_data; - vermaj = GET_ABI_MAJOR(TBM_ABI_VERSION); - vermin = GET_ABI_MINOR(TBM_ABI_VERSION); + TBM_DBG("Success to load module(%s)\n", file); - TBM_DBG("TBM ABI version %d.%d\n", - vermaj, vermin); + return 1; - if (abimaj != vermaj) { - TBM_LOG_E("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n", - abimaj, vermaj); - return 0; - } else if (abimin > vermin) { - TBM_LOG_E("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n", - abimin, vermin); - return 0; - } +err: + if (bufmgr_data) + bufmgr->backend_module_data->deinit(bufmgr_data); + if (module_data) + dlclose(module_data); - return 1; + return 0; } static int @@ -499,40 +393,40 @@ _tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file) module_data = dlopen(path, RTLD_LAZY); if (!module_data) { - TBM_LOG_E("failed to load module: %s(%s)\n", dlerror(), file); + TBM_ERR("failed to load module: %s(%s)\n", dlerror(), file); return 0; } initdata = dlsym(module_data, "tbmModuleData"); if (!initdata) { - TBM_LOG_E("Error: module does not have data object.\n"); + TBM_ERR("Error: module does not have data object.\n"); goto err; } vers = initdata->vers; if (!vers) { - TBM_LOG_E("Error: module does not supply version information.\n"); + TBM_ERR("Error: module does not supply version information.\n"); goto err; } init = initdata->init; if (!init) { - TBM_LOG_E("Error: module does not supply init symbol.\n"); + TBM_ERR("Error: module does not supply init symbol.\n"); goto err; } if (!_check_version(vers)) { - TBM_LOG_E("Fail to check version.\n"); + TBM_ERR("Fail to check version.\n"); goto err; } if (!init(bufmgr, fd)) { - TBM_LOG_E("Fail to init module(%s)\n", file); + TBM_ERR("Fail to init module(%s)\n", file); goto err; } if (!bufmgr->backend || !bufmgr->backend->priv) { - TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file); + TBM_ERR("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file); goto err; } @@ -553,14 +447,20 @@ _tbm_load_module(tbm_bufmgr bufmgr, int fd) struct dirent **namelist; int ret = 0, n; - /* load bufmgr priv from default lib */ - if (_tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB)) + /* 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_LOG_E("no files : %s\n", BUFMGR_MODULE_DIR); + TBM_ERR("no files : %s\n", BUFMGR_MODULE_DIR); return 0; } @@ -568,9 +468,12 @@ _tbm_load_module(tbm_bufmgr bufmgr, int fd) 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_bufmgr_load_module(bufmgr, fd, - namelist[n]->d_name); + 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]); @@ -582,8 +485,8 @@ _tbm_load_module(tbm_bufmgr bufmgr, int fd) } /* LCOV_EXCL_STOP */ -tbm_bufmgr -tbm_bufmgr_init(int fd) +static tbm_bufmgr +_tbm_bufmgr_init(int fd, int server) { #ifdef TBM_BUFMGR_INIT_TIME struct timeval start_tv, end_tv; @@ -600,41 +503,34 @@ tbm_bufmgr_init(int fd) env = getenv("TBM_DLOG"); if (env) { bDlog = atoi(env); - TBM_LOG_D("TBM_DLOG=%s\n", env); + TBM_DBG("TBM_DLOG=%s\n", env); } else bDlog = 1; #endif -#ifdef DEBUG - env = getenv("TBM_DEBUG"); - if (env) { - bDebug = atoi(env); - TBM_LOG_D("TBM_DEBUG=%s\n", env); - } else - bDebug = 0; -#endif - #ifdef TRACE env = getenv("TBM_TRACE"); if (env) { - bTrace = atoi(env); - TBM_LOG_D("TBM_TRACE=%s\n", env); + trace_mask = atoi(env); + TBM_DBG("TBM_TRACE=%s\n", env); } else - bTrace = 0; + trace_mask = 0; #endif pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); + if (fd >= 0) { - TBM_LOG_W("!!!!!WARNING:: The tbm_bufmgr_init DOSE NOT use argument fd ANYMORE.\n"); - TBM_LOG_W("!!!!!WARNING:: IT WILL BE CHANGED like tbm_bufmgr_init(int fd) --> tbm_bufmgr_init(void).\n"); + TBM_WRN("!!!!!WARNING:: The tbm_bufmgr_init DOSE NOT use argument fd ANYMORE.\n"); + TBM_WRN("!!!!!WARNING:: IT WILL BE CHANGED like tbm_bufmgr_init(int fd) --> tbm_bufmgr_init(void).\n"); } /* initialize buffer manager */ if (gBufMgr) { gBufMgr->ref_count++; - TBM_TRACE("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd); + TBM_DBG("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd); pthread_mutex_unlock(&gLock); return gBufMgr; } @@ -644,18 +540,24 @@ tbm_bufmgr_init(int fd) /* allocate bufmgr */ gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr)); if (!gBufMgr) { - _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED); - TBM_TRACE("error: fail to alloc bufmgr fd(%d)\n", fd); + TBM_ERR("error: fail to alloc bufmgr fd(%d)\n", fd); + _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY); pthread_mutex_unlock(&gLock); return NULL; } gBufMgr->fd = fd; + /* set the display_server flag before loading the backend module */ + if (server) { + TBM_INFO("The tbm_bufmgr(%p) is used by display server. Need to bind the native_display.\n", gBufMgr); + gBufMgr->display_server = 1; + } + /* load bufmgr priv from env */ if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) { - _tbm_set_last_result(TBM_BO_ERROR_LOAD_MODULE_FAILED); - TBM_LOG_E("error : Fail to load bufmgr backend\n"); + TBM_ERR("error : Fail to load bufmgr backend\n"); + _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); free(gBufMgr); gBufMgr = NULL; pthread_mutex_unlock(&gLock); @@ -664,30 +566,24 @@ tbm_bufmgr_init(int fd) } /* LCOV_EXCL_STOP */ - /* log for tbm backend_flag */ - TBM_DBG("backend flag:%x:", gBufMgr->backend->flags); - TBM_DBG("\n"); - gBufMgr->ref_count = 1; - TBM_DBG("create tizen bufmgr:%p ref_count:%d\n", + TBM_INFO("create tizen bufmgr:%p ref_count:%d\n", gBufMgr, gBufMgr->ref_count); - /* setup the lock_type */ + /* setup the bo_lock_type */ env = getenv("BUFMGR_LOCK_TYPE"); if (env && !strcmp(env, "always")) - gBufMgr->lock_type = LOCK_TRY_ALWAYS; + gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS; else if (env && !strcmp(env, "none")) - gBufMgr->lock_type = LOCK_TRY_NEVER; + gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_NEVER; else if (env && !strcmp(env, "once")) - gBufMgr->lock_type = LOCK_TRY_ONCE; + gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ONCE; else - gBufMgr->lock_type = LOCK_TRY_ALWAYS; + gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS; TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once"); - TBM_TRACE("create tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, fd); - /* intialize bo_list */ LIST_INITHEAD(&gBufMgr->bo_list); @@ -703,7 +599,7 @@ tbm_bufmgr_init(int fd) #ifdef TBM_BUFMGR_INIT_TIME /* get the end tv */ gettimeofday(&end_tv, NULL); - TBM_LOG_I("tbm_bufmgr_init time: %ld ms", ((end_tv.tv_sec * 1000 + end_tv.tv_usec / 1000) - (start_tv.tv_sec * 1000 + start_tv.tv_usec / 1000))); + TBM_INFO("tbm_bufmgr_init time: %ld ms", ((end_tv.tv_sec * 1000 + end_tv.tv_usec / 1000) - (start_tv.tv_sec * 1000 + start_tv.tv_usec / 1000))); #endif pthread_mutex_unlock(&gLock); @@ -711,23 +607,37 @@ tbm_bufmgr_init(int fd) return gBufMgr; } +tbm_bufmgr +tbm_bufmgr_init(int fd) +{ + tbm_bufmgr bufmgr; + + bufmgr = _tbm_bufmgr_init(fd, 0); + + return bufmgr; +} + void tbm_bufmgr_deinit(tbm_bufmgr bufmgr) { TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr)); + _tbm_bufmgr_mutex_lock(); pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); if (!gBufMgr) { - TBM_LOG_E("gBufmgr already destroy: bufmgr:%p\n", bufmgr); + TBM_ERR("gBufmgr already destroy: bufmgr:%p\n", bufmgr); pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return; } bufmgr->ref_count--; if (bufmgr->ref_count > 0) { - TBM_TRACE("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr); + TBM_DBG("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr); pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return; } @@ -736,10 +646,10 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) tbm_bo bo = NULL, tmp; LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bo_list, item_link) { - TBM_LOG_E("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt); - bo->ref_cnt = 1; - tbm_bo_unref(bo); + TBM_ERR("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt); + _tbm_bo_free(bo); } + LIST_DELINIT(&bufmgr->bo_list); } /* destroy surf_list */ @@ -747,18 +657,28 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) tbm_surface_h surf = NULL, tmp; LIST_FOR_EACH_ENTRY_SAFE(surf, tmp, &bufmgr->surf_list, item_link) { - TBM_LOG_E("Un-freed surf(%p, ref:%d)\n", surf, surf->refcnt); + TBM_ERR("Un-freed surf(%p, ref:%d)\n", surf, surf->refcnt); tbm_surface_destroy(surf); } + LIST_DELINIT(&bufmgr->surf_list); } - /* destroy bufmgr priv */ - bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv); - bufmgr->backend->priv = NULL; - tbm_backend_free(bufmgr->backend); - bufmgr->backend = NULL; + 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_TRACE("destroy tbm_bufmgr(%p)\n", bufmgr); + TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr); dlclose(bufmgr->module_data); @@ -769,853 +689,200 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) gBufMgr = NULL; pthread_mutex_unlock(&gLock); -} - -int -tbm_bo_size(tbm_bo bo) -{ - tbm_bufmgr bufmgr = gBufMgr; - int size; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - size = bufmgr->backend->bo_size(bo); - - TBM_TRACE("bo(%p) size(%d)\n", bo, size); - _tbm_bufmgr_mutex_unlock(); - - return size; } -tbm_bo -tbm_bo_ref(tbm_bo bo) +unsigned int +tbm_bufmgr_get_capability(tbm_bufmgr bufmgr) { - _tbm_bufmgr_mutex_lock(); + unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE; - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL); + _tbm_bufmgr_mutex_lock(); + _tbm_set_last_result(TBM_ERROR_NONE); - bo->ref_cnt++; + TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), TBM_BUFMGR_CAPABILITY_NONE); + TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, TBM_BUFMGR_CAPABILITY_NONE); - TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt); + capabilities = bufmgr->capabilities; _tbm_bufmgr_mutex_unlock(); - return bo; + return capabilities; } -void -tbm_bo_unref(tbm_bo bo) +/* LCOV_EXCL_START */ +char * +tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) { - tbm_bufmgr bufmgr = gBufMgr; - - _tbm_bufmgr_mutex_lock(); + char app_name[255] = {0,}, title[512] = {0,}; + tbm_surface_debug_data *debug_old_data = NULL; + char *str; + int len = 1024*4; + int c = 0; + int size; + tbm_error_e error; - TBM_BUFMGR_RETURN_IF_FAIL(gBufMgr); - TBM_BUFMGR_RETURN_IF_FAIL(_tbm_bo_is_valid(bo)); + pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); - TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1); + if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) { + TBM_ERR("invalid bufmgr\n"); + _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER); + pthread_mutex_unlock(&gLock); + return NULL; + } - if (bo->ref_cnt <= 0) { - _tbm_bufmgr_mutex_unlock(); - return; + str = malloc(len); + if (!str) { + TBM_ERR("Fail to allocate the string.\n"); + _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY); + pthread_mutex_unlock(&gLock); + return NULL; } - bo->ref_cnt--; - if (bo->ref_cnt == 0) { - /* destory the user_data_list */ - if (!LIST_IS_EMPTY(&bo->user_data_list)) { - tbm_user_data *old_data = NULL, *tmp; + TBM_SNRPRINTF(str, len, c, "\n"); + _tbm_util_get_appname_from_pid(getpid(), app_name); + _tbm_util_get_appname_brief(app_name); + TBM_SNRPRINTF(str, len, c, "============TBM DEBUG: %s(%d)===========================\n", + app_name, getpid()); - LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, - &bo->user_data_list, item_link) { - TBM_DBG("free user_data\n"); - user_data_delete(old_data); - } - } + snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name "); - while (bo->lock_cnt > 0) { - TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt); - _bo_unlock(bo); - bo->lock_cnt--; + if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) { + LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) { + strncat(title, " ", MAX_SIZE_N(title)); + strncat(title, debug_old_data->key, MAX_SIZE_N(title)); } - - /* call the bo_free */ - bufmgr->backend->bo_free(bo); - bo->priv = NULL; - - LIST_DEL(&bo->item_link); - free(bo); - - bufmgr->bo_cnt--; } - _tbm_bufmgr_mutex_unlock(); -} + TBM_SNRPRINTF(str, len, c, "[tbm_surface information]\n"); + TBM_SNRPRINTF(str, len, c, "%s\n", title); -tbm_bo -tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) -{ - void *bo_priv; - tbm_bo bo; + /* show the tbm_surface information in surf_list */ + if (!LIST_IS_EMPTY(&bufmgr->surf_list)) { + tbm_surface_h surf = NULL; + int surf_cnt = 0; - _tbm_bufmgr_mutex_lock(); + LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) { + char data[512] = {0,}; + unsigned int pid; + int i; - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL); + pid = _tbm_surface_internal_get_debug_pid(surf); + if (!pid) { + /* if pid is null, set the self_pid */ + pid = getpid(); + } - bo = calloc(1, sizeof(struct _tbm_bo)); - if (!bo) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n", - size, _tbm_flag_to_str(flags)); - _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } + memset(app_name, 0x0, 255 * sizeof(char)); + _tbm_util_get_appname_from_pid(pid, app_name); + _tbm_util_get_appname_brief(app_name); - _tbm_util_check_bo_cnt(bufmgr); + snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s", + ++surf_cnt, + surf, + surf->refcnt, + surf->info.width, + surf->info.height, + surf->info.bpp, + surf->info.size / 1024, + surf->num_bos, + surf->num_planes, + surf->flags, + _tbm_surface_internal_format_to_str(surf->info.format) + 11, + app_name); - bo->bufmgr = bufmgr; + if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) { + LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) { + char *value; - bo_priv = bufmgr->backend->bo_alloc(bo, size, flags); - if (!bo_priv) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n", - size, _tbm_flag_to_str(flags)); - _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED); - free(bo); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } + strncat(data, " ", MAX_SIZE_N(title)); - bufmgr->bo_cnt++; + value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key); + if (value) + strncat(data, value, MAX_SIZE_N(title)); + else + strncat(data, "none", MAX_SIZE_N(title)); + } + } + TBM_SNRPRINTF(str, len, c, "%s\n", data); - bo->ref_cnt = 1; - bo->flags = flags; - bo->priv = bo_priv; + 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]); + TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n", + surf->bos[i], + surf->bos[i]->ref_cnt, + size / 1024); + } + } + } else + TBM_SNRPRINTF(str, len, c, " no tbm_surfaces.\n"); + TBM_SNRPRINTF(str, len, c, "\n"); - TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt, - _tbm_flag_to_str(bo->flags)); + 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"); - LIST_INITHEAD(&bo->user_data_list); - - LIST_ADD(&bo->item_link, &bufmgr->bo_list); - - _tbm_bufmgr_mutex_unlock(); - - return bo; -} - -tbm_bo -tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) -{ - void *bo_priv; - 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(bufmgr == gBufMgr, NULL); - - if (!bufmgr->backend->bo_import) { - /* LCOV_EXCL_START */ - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - _tbm_util_check_bo_cnt(bufmgr); - - bo = calloc(1, sizeof(struct _tbm_bo)); - if (!bo) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - bo->bufmgr = bufmgr; - - bo_priv = bufmgr->backend->bo_import(bo, key); - if (!bo_priv) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key); - _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED); - free(bo); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { - tbm_bo bo2 = NULL; - - LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) { - if (bo2->priv == bo_priv) { - TBM_TRACE("find bo(%p) ref(%d) key(%d) flag(%s) in list\n", - bo2, bo2->ref_cnt, key, - _tbm_flag_to_str(bo2->flags)); - bo2->ref_cnt++; - free(bo); - _tbm_bufmgr_mutex_unlock(); - return bo2; - } - } - } - - bufmgr->bo_cnt++; - - bo->ref_cnt = 1; - bo->priv = bo_priv; - - if (bufmgr->backend->bo_get_flags) - bo->flags = bufmgr->backend->bo_get_flags(bo); - else - bo->flags = TBM_BO_DEFAULT; - - TBM_TRACE("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n", - bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags)); - - LIST_INITHEAD(&bo->user_data_list); - - LIST_ADD(&bo->item_link, &bufmgr->bo_list); - - _tbm_bufmgr_mutex_unlock(); - - return bo; -} - -tbm_bo -tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) -{ - void *bo_priv; - 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(bufmgr == gBufMgr, NULL); - - if (!bufmgr->backend->bo_import_fd) { - /* LCOV_EXCL_START */ - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - _tbm_util_check_bo_cnt(bufmgr); - - bo = calloc(1, sizeof(struct _tbm_bo)); - if (!bo) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - bo->bufmgr = bufmgr; - - bo_priv = bufmgr->backend->bo_import_fd(bo, fd); - if (!bo_priv) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd); - _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED); - free(bo); - _tbm_bufmgr_mutex_unlock(); - return NULL; - /* LCOV_EXCL_STOP */ - } - - if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { - tbm_bo bo2 = NULL; - - LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) { - if (bo2->priv == bo_priv) { - TBM_TRACE("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; - } - } - } - - bufmgr->bo_cnt++; - - bo->ref_cnt = 1; - bo->priv = bo_priv; - - if (bufmgr->backend->bo_get_flags) - bo->flags = bufmgr->backend->bo_get_flags(bo); - else - bo->flags = TBM_BO_DEFAULT; - - TBM_TRACE("import bo(%p) ref(%d) fd(%d) flag(%s)\n", - bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags)); - - LIST_INITHEAD(&bo->user_data_list); - - LIST_ADD(&bo->item_link, &bufmgr->bo_list); - - _tbm_bufmgr_mutex_unlock(); - - return bo; -} - -tbm_key -tbm_bo_export(tbm_bo bo) -{ - tbm_bufmgr bufmgr = gBufMgr; - tbm_key ret; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - if (!bufmgr->backend->bo_export) { - /* LCOV_EXCL_START */ - _tbm_bufmgr_mutex_unlock(); - return 0; - /* LCOV_EXCL_STOP */ - } - - ret = bufmgr->backend->bo_export(bo); - if (!ret) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED); - TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret); - _tbm_bufmgr_mutex_unlock(); - return ret; - /* LCOV_EXCL_STOP */ - } - - TBM_TRACE("bo(%p) tbm_key(%u)\n", bo, ret); - - _tbm_bufmgr_mutex_unlock(); - - return ret; -} - -tbm_fd -tbm_bo_export_fd(tbm_bo bo) -{ - tbm_bufmgr bufmgr = gBufMgr; - tbm_fd ret; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), -1); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1); - - if (!bufmgr->backend->bo_export_fd) { - /* LCOV_EXCL_START */ - _tbm_bufmgr_mutex_unlock(); - return -1; - /* LCOV_EXCL_STOP */ - } - - ret = bufmgr->backend->bo_export_fd(bo); - if (ret < 0) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED); - TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret); - _tbm_bufmgr_mutex_unlock(); - return ret; - /* LCOV_EXCL_STOP */ - } - - TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret); - - _tbm_bufmgr_mutex_unlock(); - - return ret; -} - -tbm_bo_handle -tbm_bo_get_handle(tbm_bo bo, int device) -{ - tbm_bufmgr bufmgr = gBufMgr; - tbm_bo_handle bo_handle; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL); - - bo_handle = bufmgr->backend->bo_get_handle(bo, device); - if (bo_handle.ptr == NULL) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED); - TBM_LOG_E("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr); - _tbm_bufmgr_mutex_unlock(); - return (tbm_bo_handle) NULL; - /* LCOV_EXCL_STOP */ - } - - TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr); - - _tbm_bufmgr_mutex_unlock(); - - return bo_handle; -} - -tbm_bo_handle -tbm_bo_map(tbm_bo bo, int device, int opt) -{ - tbm_bufmgr bufmgr = gBufMgr; - tbm_bo_handle bo_handle; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL); - - if (!_tbm_bo_lock(bo, device, opt)) { - _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED); - TBM_LOG_E("error: fail to lock bo:%p)\n", bo); - _tbm_bufmgr_mutex_unlock(); - return (tbm_bo_handle) NULL; - } - - bo_handle = bufmgr->backend->bo_map(bo, device, opt); - if (bo_handle.ptr == NULL) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED); - TBM_LOG_E("error: fail to map bo:%p\n", bo); - _tbm_bo_unlock(bo); - _tbm_bufmgr_mutex_unlock(); - return (tbm_bo_handle) NULL; - /* LCOV_EXCL_STOP */ - } - - /* increase the map_count */ - bo->map_cnt++; - - TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt); - - _tbm_bufmgr_mutex_unlock(); - - return bo_handle; -} - -int -tbm_bo_unmap(tbm_bo bo) -{ - tbm_bufmgr bufmgr = gBufMgr; - int ret; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - ret = bufmgr->backend->bo_unmap(bo); - if (!ret) { - /* LCOV_EXCL_START */ - TBM_LOG_E("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt); - _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED); - _tbm_bufmgr_mutex_unlock(); - return ret; - /* LCOV_EXCL_STOP */ - } - - /* decrease the map_count */ - bo->map_cnt--; - - TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt); - - _tbm_bo_unlock(bo); - - _tbm_bufmgr_mutex_unlock(); - - return ret; -} - -int -tbm_bo_swap(tbm_bo bo1, tbm_bo bo2) -{ - tbm_bufmgr bufmgr = gBufMgr; - void *temp; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0); - - TBM_TRACE("before: bo1(%p) bo2(%p)\n", bo1, bo2); - - if (bufmgr->backend->bo_size(bo1) != bufmgr->backend->bo_size(bo2)) { - _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED); - TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2); - - temp = bo1->priv; - bo1->priv = bo2->priv; - bo2->priv = temp; - - _tbm_bufmgr_mutex_unlock(); - - return 1; -} - -int -tbm_bo_locked(tbm_bo bo) -{ - tbm_bufmgr bufmgr = gBufMgr; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - if (bufmgr->lock_type == LOCK_TRY_NEVER) { - TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - if (bo->lock_cnt > 0) { - TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt); - _tbm_bufmgr_mutex_unlock(); - return 1; - } - - TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt); - _tbm_bufmgr_mutex_unlock(); - - return 0; -} - -int -tbm_bo_add_user_data(tbm_bo bo, unsigned long key, - tbm_data_free data_free_func) -{ - tbm_user_data *data; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - /* check if the data according to the key exist if so, return false. */ - data = user_data_lookup(&bo->user_data_list, key); - if (data) { - TBM_TRACE("warning: user data already exist key(%ld)\n", key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - data = user_data_create(key, data_free_func); - if (!data) { - TBM_LOG_E("error: bo(%p) key(%lu)\n", bo, key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, data->data); - - LIST_ADD(&data->item_link, &bo->user_data_list); - - _tbm_bufmgr_mutex_unlock(); - - return 1; -} - -int -tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data) -{ - tbm_user_data *old_data; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - if (LIST_IS_EMPTY(&bo->user_data_list)) { - TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - old_data = user_data_lookup(&bo->user_data_list, key); - if (!old_data) { - TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - if (old_data->data && old_data->free_func) - old_data->free_func(old_data->data); - old_data->data = data; - - TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data); - - _tbm_bufmgr_mutex_unlock(); - - return 1; -} - -int -tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data) -{ - tbm_user_data *old_data; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - if (!data || LIST_IS_EMPTY(&bo->user_data_list)) { - TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - old_data = user_data_lookup(&bo->user_data_list, key); - if (!old_data) { - TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - *data = NULL; - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - *data = old_data->data; - - TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data); - - _tbm_bufmgr_mutex_unlock(); - - return 1; -} - -int -tbm_bo_delete_user_data(tbm_bo bo, unsigned long key) -{ - tbm_user_data *old_data; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - if (LIST_IS_EMPTY(&bo->user_data_list)) { - TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - old_data = user_data_lookup(&bo->user_data_list, key); - if (!old_data) { - TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - _tbm_bufmgr_mutex_unlock(); - return 0; - } - - TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data); - - user_data_delete(old_data); - - _tbm_bufmgr_mutex_unlock(); - - return 1; -} - -unsigned int -tbm_bufmgr_get_capability(tbm_bufmgr bufmgr) -{ - unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), TBM_BUFMGR_CAPABILITY_NONE); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, TBM_BUFMGR_CAPABILITY_NONE); - - TBM_TRACE("tbm_bufmgr(%p) capability(%u)\n", bufmgr, bufmgr->capabilities); - - capabilities = bufmgr->capabilities; - - _tbm_bufmgr_mutex_unlock(); - - return capabilities; -} - -int -tbm_bo_get_flags(tbm_bo bo) -{ - int flags; - - _tbm_bufmgr_mutex_lock(); - - TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - - flags = bo->flags; - - TBM_TRACE("bo(%p)\n", bo); - - _tbm_bufmgr_mutex_unlock(); - - return flags; -} - -/* LCOV_EXCL_START */ -tbm_error_e -tbm_get_last_error(void) -{ - return tbm_last_error; -} - -void -tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len) -{ - char app_name[255] = {0,}, title[512] = {0,}; - tbm_surface_debug_data *debug_old_data = NULL; - - pthread_mutex_lock(&gLock); - - if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) { - TBM_LOG_E("invalid bufmgr\n"); - pthread_mutex_unlock(&gLock); - return; - } - - TBM_SNPRINTF(str, len, "\n"); - _tbm_util_get_appname_from_pid(getpid(), app_name); - _tbm_util_get_appname_brief(app_name); - TBM_SNPRINTF(str, len, "============TBM DEBUG: %s(%d)===========================\n", - app_name, getpid()); - - 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) { - strncat(title, " ", 3); - strncat(title, debug_old_data->key, strlen(debug_old_data->key) + 1); - } - } - - TBM_SNPRINTF(str, len, "[tbm_surface information]\n"); - TBM_SNPRINTF(str, len, "%s\n", title); - - /* show the tbm_surface information in surf_list */ - if (!LIST_IS_EMPTY(&bufmgr->surf_list)) { - tbm_surface_h surf = NULL; - int surf_cnt = 0; - - LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) { - char data[512] = {0,}; - unsigned int pid; - int i; - - pid = _tbm_surface_internal_get_debug_pid(surf); - if (!pid) { - /* if pid is null, set the self_pid */ - pid = getpid(); - } - - memset(app_name, 0x0, 255 * sizeof(char)); - _tbm_util_get_appname_from_pid(pid, app_name); - _tbm_util_get_appname_brief(app_name); - - snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s", - ++surf_cnt, - surf, - surf->refcnt, - surf->info.width, - surf->info.height, - surf->info.bpp, - surf->info.size / 1024, - surf->num_bos, - surf->num_planes, - surf->flags, - _tbm_surface_internal_format_to_str(surf->info.format) + 11, - app_name); - - if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) { - LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) { - char *value; - - strncat(data, " ", 3); - - value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key); - if (value) - strncat(data, value, strlen(value) + 1); - else - strncat(data, "none", 5); - } - } - TBM_SNPRINTF(str, len, "%s\n", data); - - for (i = 0; i < surf->num_bos; i++) { - TBM_SNPRINTF(str, len, " bo:%-12p %-26d%-10d\n", - surf->bos[i], - surf->bos[i]->ref_cnt, - bufmgr->backend->bo_size(surf->bos[i]) / 1024); - } - } - } else - TBM_SNPRINTF(str, len, " no tbm_surfaces.\n"); - TBM_SNPRINTF(str, len, "\n"); - - TBM_SNPRINTF(str, len, "[tbm_bo information]\n"); - TBM_SNPRINTF(str, len, "no bo refcnt size lock_cnt map_cnt flags surface\n"); - - /* show the tbm_bo information in bo_list */ - if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { - int bo_cnt = 0; - tbm_bo bo = NULL; + /* show the tbm_bo information in bo_list */ + if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { + int bo_cnt = 0; + tbm_bo bo = NULL; + tbm_key key = 0; LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) { - TBM_SNPRINTF(str, len, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p\n", + 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", ++bo_cnt, bo, bo->ref_cnt, - bufmgr->backend->bo_size(bo) / 1024, + size / 1024, bo->lock_cnt, bo->map_cnt, bo->flags, - bo->surface); + bo->surface, + key); } } else - TBM_SNPRINTF(str, len, "no tbm_bos.\n"); - TBM_SNPRINTF(str, len, "\n"); + TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n"); + TBM_SNRPRINTF(str, len, c, "\n"); - TBM_SNPRINTF(str, len, "===============================================================\n"); + TBM_SNRPRINTF(str, len, c, "===============================================================\n"); pthread_mutex_unlock(&gLock); + + return str; } void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr) { - char str[1024*4]; - int len = sizeof(str); - tbm_bufmgr_debug_tbm_info_get(bufmgr, str, &len); - TBM_DEBUG(" %s", str); + char * str; + str = tbm_bufmgr_debug_tbm_info_get(bufmgr); + if (str) { + TBM_DBG(" %s", str); + free(str); + } } void tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff) { _tbm_bufmgr_mutex_lock(); + _tbm_set_last_result(TBM_ERROR_NONE); TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr)); TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr); @@ -1629,34 +896,92 @@ tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff) } void +tbm_bufmgr_debug_set_trace_mask(tbm_bufmgr bufmgr, tbm_bufmgr_debug_trace_mask mask, int set) +{ + _tbm_bufmgr_mutex_lock(); + _tbm_set_last_result(TBM_ERROR_NONE); + + TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr)); + TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr); + + if (set == 1) { + trace_mask |= mask; + + TBM_INFO("bufmgr=%p sets the trace_mask=%d\n", bufmgr, mask); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_BO"); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL"); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE"); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE"); + } else if (set == 0) { + trace_mask &= ~mask; + + TBM_INFO("bufmgr=%p unsets the trace_mask=%d\n", bufmgr, mask); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_BO"); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL"); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE"); + if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE) + TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE"); + } else { + TBM_WRN("set value is wrong.(set=%d)", set); + } + + _tbm_bufmgr_mutex_unlock(); +} + +void tbm_bufmgr_debug_dump_set_scale(double scale) { pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); scale_factor = scale; pthread_mutex_unlock(&gLock); } int +tbm_bufmgr_debug_get_ref_count(void) +{ + int refcnt; + + pthread_mutex_lock(&gLock); + + _tbm_set_last_result(TBM_ERROR_NONE); + + refcnt = (gBufMgr) ? gBufMgr->ref_count : 0; + + pthread_mutex_unlock(&gLock); + + return refcnt; +} + +int tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff) { pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); if (onoff == 0) { - TBM_LOG_D("count=%d onoff=%d\n", count, onoff); + TBM_DBG("count=%d onoff=%d\n", count, onoff); b_dump_queue = 0; tbm_surface_internal_dump_end(); } else { int w, h; if (path == NULL) { - TBM_LOG_E("path is null"); + TBM_ERR("path is null"); pthread_mutex_unlock(&gLock); return 0; } - TBM_LOG_D("path=%s count=%d onoff=%d\n", path, count, onoff); + TBM_DBG("path=%s count=%d onoff=%d\n", path, count, onoff); if (_tbm_util_get_max_surface_size(&w, &h) == 0) { - TBM_LOG_E("Fail to get tbm_surface size.\n"); + TBM_ERR("Fail to get tbm_surface size.\n"); pthread_mutex_unlock(&gLock); return 0; } @@ -1668,6 +993,7 @@ tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff) } pthread_mutex_unlock(&gLock); + return 1; } @@ -1677,16 +1003,22 @@ tbm_bufmgr_debug_dump_all(char *path) int w, h, count = 0; tbm_surface_h surface = NULL; - TBM_RETURN_VAL_IF_FAIL(path != NULL, 0); - TBM_LOG_D("path=%s\n", path); - pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); + + if (!path) { + TBM_ERR("path is null.\n"); + pthread_mutex_unlock(&gLock); + return 0; + } + + TBM_DBG("path=%s\n", path); count = _tbm_util_get_max_surface_size(&w, &h); if (count == 0) { - TBM_LOG_E("No tbm_surface.\n"); + TBM_ERR("No tbm_surface.\n"); pthread_mutex_unlock(&gLock); - return 1; + return 0; } tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor); @@ -1710,51 +1042,91 @@ _tbm_bufmgr_get_bufmgr(void) } int -_tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface) +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_bo_is_valid(bo), 0); - bo->surface = surface; + 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 = 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(); + 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; + } + } + + TBM_INFO("tbm_bufmgr(%p) native_display(%p)\n", bufmgr, native_display); _tbm_bufmgr_mutex_unlock(); return 1; } -int -tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay) +tbm_bufmgr +tbm_bufmgr_server_init(void) { - int ret; + tbm_bufmgr bufmgr; + + bufmgr = _tbm_bufmgr_init(-1, 1); + return bufmgr; +} + +int +tbm_bufmgr_set_bo_lock_type(tbm_bufmgr bufmgr, tbm_bufmgr_bo_lock_type bo_lock_type) +{ _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(bufmgr == gBufMgr, 0); - if (!bufmgr->backend->bufmgr_bind_native_display) { - TBM_TRACE("skip: tbm_bufmgr(%p) NativeDisplay(%p)\n", - bufmgr, NativeDisplay); - _tbm_bufmgr_mutex_unlock(); - return 1; - } - - ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, NativeDisplay); - if (!ret) { - TBM_LOG_E("error: tbm_bufmgr(%p) NativeDisplay(%p)\n", - bufmgr, NativeDisplay); - _tbm_bufmgr_mutex_unlock(); - return 0; - } + pthread_mutex_lock(&gLock); + gBufMgr->bo_lock_type = bo_lock_type; + pthread_mutex_unlock(&gLock); - TBM_TRACE("tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay); + TBM_INFO("The bo_lock_type of the bo is %d\n", bo_lock_type); _tbm_bufmgr_mutex_unlock(); return 1; } + int tbm_bufmgr_get_fd_limit(void) { struct rlimit lim; @@ -1764,4 +1136,9 @@ int tbm_bufmgr_get_fd_limit(void) return (int)lim.rlim_cur; } + +tbm_bufmgr tbm_bufmgr_get(void) +{ + return gBufMgr; +} /* LCOV_EXCL_STOP */