#define TBM_BUFMGR_RETURN_IF_FAIL(cond) {\
if (!(cond)) {\
TBM_ERR("'%s' failed.\n", #cond);\
+ _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
_tbm_bufmgr_mutex_unlock();\
return;\
} \
#define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\
if (!(cond)) {\
TBM_ERR("'%s' failed.\n", #cond);\
+ _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
_tbm_bufmgr_mutex_unlock();\
return val;\
} \
}
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 abimaj, abimin;
+ int vermaj, vermin;
+ 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;
+ }
+
+ abimaj = GET_ABI_MAJOR(backend_module_data->abi_version);
+ abimin = GET_ABI_MINOR(backend_module_data->abi_version);
+
+ TBM_DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
+ backend_module_data->name ? backend_module_data->name : "UNKNOWN!",
+ backend_module_data->vendor ? backend_module_data->vendor : "UNKNOWN!",
+ abimaj, abimin);
+
+ vermaj = GET_ABI_MAJOR(TBM_BACKEND_ABI_LATEST_VERSION);
+ vermin = GET_ABI_MINOR(TBM_BACKEND_ABI_LATEST_VERSION);
+ TBM_DBG("TBM ABI version %d.%d\n", vermaj, vermin);
+
+ if (abimaj > vermaj) {
+ TBM_ERR("TBM module ABI major ver(%d) is newer than the TBM's ver(%d)\n",
+ abimaj, vermaj);
+ goto err;
+ } else if (abimin > vermin) {
+ TBM_ERR("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
+ abimin, vermin);
+ 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, };
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 */
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]);
pthread_mutex_lock(&gLock);
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
if (fd >= 0) {
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");
gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
if (!gBufMgr) {
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;
}
/* load bufmgr priv from env */
if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) {
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);
_tbm_bufmgr_mutex_lock();
pthread_mutex_lock(&gLock);
+ _tbm_set_last_result(TBM_ERROR_NONE);
if (!gBufMgr) {
TBM_ERR("gBufmgr already destroy: bufmgr:%p\n", bufmgr);
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_INFO("destroy tbm_bufmgr(%p)\n", bufmgr);
unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE;
_tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
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);
char *str;
int len = 1024*4;
int c = 0;
+ int size;
+ tbm_error_e error;
pthread_mutex_lock(&gLock);
+ _tbm_set_last_result(TBM_ERROR_NONE);
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;
}
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;
}
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]);
TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n",
surf->bos[i],
surf->bos[i]->ref_cnt,
- bufmgr->backend->bo_size(surf->bos[i]) / 1024);
+ size / 1024);
}
}
} else
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) {
+ 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,
- bufmgr->backend->bo_export(bo));
+ key);
}
} else
TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n");
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);
}
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)
{
- return (gBufMgr) ? gBufMgr->ref_count : 0;
+ 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_DBG("count=%d onoff=%d\n", count, onoff);
}
pthread_mutex_unlock(&gLock);
+
return 1;
}
int w, h, count = 0;
tbm_surface_h surface = NULL;
+ pthread_mutex_lock(&gLock);
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
TBM_DBG("path=%s\n", path);
- pthread_mutex_lock(&gLock);
-
count = _tbm_util_get_max_surface_size(&w, &h);
if (count == 0) {
TBM_ERR("No tbm_surface.\n");
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);
- if (!bufmgr->backend->bufmgr_bind_native_display) {
- TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n",
- bufmgr, native_display);
- _tbm_bufmgr_mutex_unlock();
- return 1;
- }
+ 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;
+ }
- 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_bufmgr_mutex_unlock();
- return 0;
+ 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);
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);
+ pthread_mutex_lock(&gLock);
gBufMgr->bo_lock_type = bo_lock_type;
+ pthread_mutex_unlock(&gLock);
TBM_INFO("The bo_lock_type of the bo is %d\n", bo_lock_type);
+ _tbm_bufmgr_mutex_unlock();
+
return 1;
}