#include "tbm_bufmgr.h"
#include "tbm_bufmgr_int.h"
#include "tbm_bufmgr_backend.h"
-#include "tbm_bufmgr_tgl.h"
#include "list.h"
-#define DEBUG
+#include <sys/resource.h>
+
#ifdef DEBUG
-int bDebug = 0;
-#define DBG(...) if (bDebug&0x1) TBM_LOG(__VA_ARGS__)
-#define DBG_LOCK(...) if (bDebug&0x2) TBM_LOG(__VA_ARGS__)
-#else
-#define DBG(...)
-#define DBG_LOCK(...)
+int bDebug;
#endif
-#define PREFIX_LIB "libtbm_"
-#define SUFFIX_LIB ".so"
-#define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB
+#ifdef TRACE
+int bTrace;
+#endif
-#define BO_IS_CACHEABLE(bo) ((bo->flags & TBM_BO_NONCACHABLE) ? 0 : 1)
-#define DEVICE_IS_CACHE_AWARE(device) ((device == TBM_DEVICE_CPU) ? (1) : (0))
+#ifdef HAVE_DLOG
+int bDlog;
+#endif
+
+tbm_bufmgr gBufMgr;
+int b_dump_queue;
-/* tgl key values */
-#define GLOBAL_KEY ((unsigned int)(-1))
-#define INITIAL_KEY ((unsigned int)(-2))
+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);
-#define CACHE_OP_CREATE (-1)
-#define CACHE_OP_ATTACH (-2)
-#define CACHE_OP_IMPORT (-3)
+//#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 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_bufmgr_mutex_unlock();\
+ return;\
+ } \
+}
+
+#define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\
+ if (!(cond)) {\
+ TBM_LOG_E("'%s' failed.\n", #cond);\
+ _tbm_bufmgr_mutex_unlock();\
+ return val;\
+ } \
+}
+
enum {
LOCK_TRY_ONCE,
LOCK_TRY_ALWAYS,
LOCK_TRY_NEVER
};
-enum {
- DEVICE_NONE = 0,
- DEVICE_CA, /* cache aware device */
- DEVICE_CO /* cache oblivious device */
-};
+static void
+_tbm_set_last_result(tbm_error_e err)
+{
+ tbm_last_error = err;
+}
-typedef struct {
- unsigned long key;
- void *data;
- tbm_data_free free_func;
+/* LCOV_EXCL_START */
+static bool
+_tbm_bufmgr_mutex_init(void)
+{
+ static bool tbm_bufmgr_mutex_init = false;
- /* link of user_data */
- struct list_head item_link;
-} tbm_user_data;
+ if (tbm_bufmgr_mutex_init)
+ return true;
-pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
-tbm_bufmgr gBufMgr = NULL;
+ if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) {
+ TBM_LOG_E("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n");
+ return false;
+ }
-static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE;
+ tbm_bufmgr_mutex_init = true;
+
+ return true;
+}
-static void _tbm_set_last_result(tbm_error_e err)
+static void
+_tbm_bufmgr_mutex_lock(void)
{
- tbm_last_error = err;
+ if (!_tbm_bufmgr_mutex_init()) {
+ TBM_LOG_E("fail: _tbm_bufmgr_mutex_init()\n");
+ return;
+ }
+
+ pthread_mutex_lock(&tbm_bufmgr_lock);
+}
+
+static void
+_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-c, "SCANOUT");
+
+ if (f & TBM_BO_NONCACHABLE) {
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, ", ");
+
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, "NONCACHABLE,");
+ }
+
+ if (f & TBM_BO_WC) {
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, ", ");
+
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, "WC");
+ }
+ }
+
+ return str;
}
-static void _tbm_util_get_appname_brief(char *brief)
+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)
+{
+ tbm_surface_info_s info;
+ tbm_surface_h surface = NULL;
+ int count = 0;
+
+ *w = 0;
+ *h = 0;
+
+ if (gBufMgr == NULL || LIST_IS_EMPTY(&gBufMgr->surf_list))
+ return count;
+
+ LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link) {
+ if (tbm_surface_get_info(surface, &info) == TBM_SURFACE_ERROR_NONE) {
+ count++;
+ if (*w < info.width)
+ *w = info.width;
+ if (*h < info.height)
+ *h = info.height;
+ }
+ }
+
+ return count;
+}
+
+static void
+_tbm_util_get_appname_brief(char *brief)
{
char delim[] = "/";
char *token = NULL;
token = strtok_r(brief, delim, &saveptr);
while (token != NULL) {
- memset(temp, 0x00, 255*sizeof(char));
- strncpy(temp, token, 254*sizeof(char));
+ memset(temp, 0x00, 255 * sizeof(char));
+ strncpy(temp, token, 254 * sizeof(char));
token = strtok_r(NULL, delim, &saveptr);
}
snprintf(brief, sizeof(temp), "%s", temp);
}
-static void _tbm_util_get_appname_from_pid(long pid, char *str)
+static void
+_tbm_util_get_appname_from_pid(long pid, char *str)
{
- FILE* fp;
+ char fn_cmdline[255] = {0, }, cmdline[255];
+ FILE *fp;
int len;
- long app_pid = pid;
- char fn_cmdline[255] = {0,};
- char cmdline[255] = {0,};
- snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", app_pid);
+ snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", pid);
fp = fopen(fn_cmdline, "r");
if (fp == 0) {
- fprintf(stderr, "cannot file open /proc/%ld/cmdline", app_pid);
+ TBM_LOG_E("cannot file open %s\n", fn_cmdline);
return;
}
if (!fgets(cmdline, 255, fp)) {
- fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid);
+ TBM_LOG_E("fail to get appname for pid(%ld)\n", pid);
fclose(fp);
return;
}
+
fclose(fp);
len = strlen(cmdline);
snprintf(str, sizeof(cmdline), "%s", cmdline);
}
+/* LCOV_EXCL_STOP */
-static inline int _tgl_init(int fd, unsigned int key)
-{
- struct tgl_attribute attr;
- int err;
-
- attr.key = key;
- attr.timeout_ms = 1000;
-
- err = ioctl(fd, TGL_IOC_INIT_LOCK, &attr);
- if (err) {
- TBM_LOG("[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
-}
-
-static inline int _tgl_destroy(int fd, unsigned int key)
+tbm_user_data
+*user_data_lookup(struct list_head *user_data_list, unsigned long key)
{
- int err;
- err = ioctl(fd, TGL_IOC_DESTROY_LOCK, key);
- if (err) {
- TBM_LOG("[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
+ tbm_user_data *old_data = NULL;
- return 1;
-}
-
-static inline int _tgl_lock(int fd, unsigned int key)
-{
- int err;
- err = ioctl(fd, TGL_IOC_LOCK_LOCK, key);
- if (err) {
- TBM_LOG("[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
-}
-
-static inline int _tgl_unlock(int fd, unsigned int key)
-{
- int err;
- err = ioctl(fd, TGL_IOC_UNLOCK_LOCK, key);
- if (err) {
- TBM_LOG("[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
-}
-
-static inline int _tgl_set_data(int fd, unsigned int key, unsigned int val)
-{
- int err;
- struct tgl_user_data arg;
-
- arg.key = key;
- arg.data1 = val;
- err = ioctl(fd, TGL_IOC_SET_DATA, &arg);
- if (err) {
- TBM_LOG("[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
-}
-
-static inline unsigned int _tgl_get_data(int fd, unsigned int key, unsigned int *locked)
-{
- int err;
- struct tgl_user_data arg = { 0, };
-
- arg.key = key;
- err = ioctl(fd, TGL_IOC_GET_DATA, &arg);
- if (err) {
- TBM_LOG("[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- if (locked)
- *locked = arg.locked;
-
- return arg.data1;
-}
+ if (LIST_IS_EMPTY(user_data_list))
+ return NULL;
-static tbm_user_data *_user_data_lookup(struct list_head *user_data_list, unsigned long key)
-{
- tbm_user_data *user_data = NULL;
- tbm_user_data *old_data = NULL, *tmp = NULL;
-
- if (!LIST_IS_EMPTY(user_data_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, user_data_list, item_link) {
- if (old_data->key == key) {
- user_data = old_data;
- return user_data;
- }
- }
+ LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
+ if (old_data->key == key)
+ return old_data;
}
- return user_data;
+ return NULL;
}
-static tbm_user_data *_user_data_create(unsigned long key, tbm_data_free data_free_func)
+tbm_user_data
+*user_data_create(unsigned long key, tbm_data_free data_free_func)
{
- tbm_user_data *user_data = NULL;
+ tbm_user_data *user_data;
user_data = calloc(1, sizeof(tbm_user_data));
- if (!user_data)
+ if (!user_data) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("fail to allocate an user_date\n");
return NULL;
+ /* LCOV_EXCL_STOP */
+ }
user_data->key = key;
user_data->free_func = data_free_func;
- user_data->data = (void *)0;
return user_data;
}
-static void _user_data_delete(tbm_user_data * 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);
free(user_data);
}
-static int _bo_lock(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- int ret = 0;
-
- if (TBM_LOCK_CTRL_BACKEND_VALID(bufmgr->backend->flags)) {
- if (bufmgr->backend->bo_lock2) {
- /* use bo_lock2 backend lock */
- ret = bufmgr->backend->bo_lock2(bo, device, opt);
- } else if (bufmgr->backend->bo_lock) {
- /* use bo_lock backend lock */
- ret = bufmgr->backend->bo_lock(bo);
- } else {
- TBM_LOG("[libtbm:%d] "
- "error %s:%d no backend lock functions\n",
- getpid(), __FUNCTION__, __LINE__);
- }
- } else {
- /* use tizen global lock */
- ret = _tgl_lock(bufmgr->lock_fd, bo->tgl_key);
- }
-
- return ret;
-}
-
-static void _bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- if (TBM_LOCK_CTRL_BACKEND_VALID(bufmgr->backend->flags)) {
- if (bufmgr->backend->bo_unlock) {
- /* use backend unlock */
- bufmgr->backend->bo_unlock(bo);
- } else {
- TBM_LOG("[libtbm:%d] "
- "error %s:%d no backend unlock functions\n",
- getpid(), __FUNCTION__, __LINE__);
- }
- } else {
- /* use tizen global unlock */
- _tgl_unlock(bufmgr->lock_fd, bo->tgl_key);
- }
-}
-
-static int _tbm_bo_init_state(tbm_bo bo, int opt)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- tbm_bo_cache_state cache_state;
-
- if (bo->tgl_key == INITIAL_KEY)
- bo->tgl_key = bufmgr->backend->bo_get_global_key(bo);
-
- if (!bo->default_handle.u32)
- bo->default_handle = bufmgr->backend->bo_get_handle(bo, TBM_DEVICE_DEFAULT);
-
- RETURN_VAL_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
-
- cache_state.val = 0;
- switch (opt) {
- case CACHE_OP_CREATE: /*Create */
-
- _tgl_init(bufmgr->lock_fd, bo->tgl_key);
-
- cache_state.data.isCacheable = BO_IS_CACHEABLE(bo);
- cache_state.data.isDirtied = DEVICE_NONE;
- cache_state.data.isCached = 0;
- cache_state.data.cntFlush = 0;
-
- _tgl_set_data(bufmgr->lock_fd, bo->tgl_key, cache_state.val);
- break;
- case CACHE_OP_IMPORT: /*Import */
-
- _tgl_init(bufmgr->lock_fd, bo->tgl_key);
- break;
- default:
- break;
- }
-
- return 1;
-}
-
-static void _tbm_bo_destroy_state(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- RETURN_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags));
-
- _tgl_destroy(bufmgr->lock_fd, bo->tgl_key);
-}
-
-static int _tbm_bo_set_state(tbm_bo bo, int device, int opt)
+static int
+_bo_lock(tbm_bo bo, int device, int opt)
{
tbm_bufmgr bufmgr = bo->bufmgr;
- char need_flush = 0;
- unsigned short cntFlush = 0;
- unsigned int is_locked;
-
- RETURN_VAL_CHECK_FLAG(TBM_CACHE_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
-
- /* get cache state of a bo */
- bo->cache_state.val = _tgl_get_data(bufmgr->lock_fd, bo->tgl_key, &is_locked);
+ int ret = 1;
- if (!bo->cache_state.data.isCacheable)
- return 1;
-
- /* get global cache flush count */
- cntFlush = (unsigned short)_tgl_get_data(bufmgr->lock_fd, GLOBAL_KEY, NULL);
-
- if (DEVICE_IS_CACHE_AWARE(device)) {
- if (bo->cache_state.data.isDirtied == DEVICE_CO &&
- bo->cache_state.data.isCached)
- need_flush = TBM_CACHE_INV;
+ if (bufmgr->backend->bo_lock)
+ ret = bufmgr->backend->bo_lock(bo, device, opt);
- bo->cache_state.data.isCached = 1;
- if (opt & TBM_OPTION_WRITE)
- bo->cache_state.data.isDirtied = DEVICE_CA;
- else {
- if (bo->cache_state.data.isDirtied != DEVICE_CA)
- bo->cache_state.data.isDirtied = DEVICE_NONE;
- }
- } else {
- if (bo->cache_state.data.isDirtied == DEVICE_CA &&
- bo->cache_state.data.isCached &&
- bo->cache_state.data.cntFlush == cntFlush)
- need_flush = TBM_CACHE_CLN | TBM_CACHE_ALL;
-
- if (opt & TBM_OPTION_WRITE)
- bo->cache_state.data.isDirtied = DEVICE_CO;
- else {
- if (bo->cache_state.data.isDirtied != DEVICE_CO)
- bo->cache_state.data.isDirtied = DEVICE_NONE;
- }
- }
-
- if (need_flush) {
- /* set global cache flush count */
- if (need_flush & TBM_CACHE_ALL)
- _tgl_set_data(bufmgr->lock_fd, GLOBAL_KEY, (unsigned int)(++cntFlush));
-
- /* call backend cache flush */
- bufmgr->backend->bo_cache_flush(bo, need_flush);
-
- DBG("[libtbm:%d] \tcache(%d,%d,%d)....flush:0x%x, cntFlush(%d)\n",
- getpid(),
- bo->cache_state.data.isCacheable,
- bo->cache_state.data.isCached,
- bo->cache_state.data.isDirtied,
- need_flush,
- cntFlush);
- }
-
- return 1;
+ return ret;
}
-static void _tbm_bo_save_state(tbm_bo bo)
+static void
+_bo_unlock(tbm_bo bo)
{
tbm_bufmgr bufmgr = bo->bufmgr;
- unsigned short cntFlush = 0;
- RETURN_CHECK_FLAG(TBM_CACHE_CTRL_BACKEND_VALID(bufmgr->backend->flags));
-
- /* get global cache flush count */
- cntFlush = (unsigned short)_tgl_get_data(bufmgr->lock_fd, GLOBAL_KEY, NULL);
-
- /* save global cache flush count */
- bo->cache_state.data.cntFlush = cntFlush;
- _tgl_set_data(bufmgr->lock_fd, bo->tgl_key, bo->cache_state.val);
+ if (bufmgr->backend->bo_unlock)
+ bufmgr->backend->bo_unlock(bo);
}
-static int _tbm_bo_lock(tbm_bo bo, int device, int opt)
+static int
+_tbm_bo_lock(tbm_bo bo, int device, int opt)
{
- tbm_bufmgr bufmgr = NULL;
- int old;
- int ret = 0;
+ tbm_bufmgr bufmgr;
+ int old, ret;
if (!bo)
return 0;
return 1;
if (bo->lock_cnt < 0) {
- TBM_LOG("[libtbm:%d] "
- "error %s:%d bo:%p(%d) LOCK_CNT=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo, bo->tgl_key, bo->lock_cnt);
+ TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
+ bo, bo->lock_cnt);
+ return 0;
}
old = bo->lock_cnt;
- if (bufmgr->lock_type == LOCK_TRY_ONCE) {
+
+ switch (bufmgr->lock_type) {
+ case LOCK_TRY_ONCE:
if (bo->lock_cnt == 0) {
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
ret = _bo_lock(bo, device, opt);
- pthread_mutex_lock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_lock();
if (ret)
bo->lock_cnt++;
} else
ret = 1;
- } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) {
- pthread_mutex_unlock(&bufmgr->lock);
+ break;
+ case LOCK_TRY_ALWAYS:
+ _tbm_bufmgr_mutex_unlock();
ret = _bo_lock(bo, device, opt);
- pthread_mutex_lock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_lock();
if (ret)
bo->lock_cnt++;
- } else {
- TBM_LOG("[libtbm:%d] "
- "error %s:%d bo:%p lock_type is wrong.\n",
- getpid(), __FUNCTION__, __LINE__, bo);
+ break;
+ default:
+ TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
+ bo, bufmgr->lock_type);
+ ret = 0;
+ break;
}
- DBG_LOCK("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(),
- bo, bo->tgl_key, old, bo->lock_cnt);
+ TBM_DBG_LOCK(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
return ret;
}
-static void _tbm_bo_unlock(tbm_bo bo)
+static void
+_tbm_bo_unlock(tbm_bo bo)
{
- tbm_bufmgr bufmgr = NULL;
-
+ tbm_bufmgr bufmgr;
int old;
if (!bo)
return;
old = bo->lock_cnt;
- if (bufmgr->lock_type == LOCK_TRY_ONCE) {
+
+ switch (bufmgr->lock_type) {
+ case LOCK_TRY_ONCE:
if (bo->lock_cnt > 0) {
bo->lock_cnt--;
if (bo->lock_cnt == 0)
_bo_unlock(bo);
}
- } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) {
+ break;
+ case LOCK_TRY_ALWAYS:
if (bo->lock_cnt > 0) {
bo->lock_cnt--;
_bo_unlock(bo);
}
- } else {
- TBM_LOG("[libtbm:%d] "
- "error %s:%d bo:%p lock_type is wrong.\n",
- getpid(), __FUNCTION__, __LINE__, bo);
+ break;
+ default:
+ TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
+ bo, bufmgr->lock_type);
+ break;
}
if (bo->lock_cnt < 0)
bo->lock_cnt = 0;
- DBG_LOCK("[libtbm:%d] << unlock bo:%p(%d, %d->%d)\n", getpid(),
- bo, bo->tgl_key, old, bo->lock_cnt);
+ TBM_DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
}
-static int _tbm_bo_is_valid(tbm_bo bo)
+static int
+_tbm_bo_is_valid(tbm_bo bo)
{
- tbm_bo old_data = NULL, tmp = NULL;;
+ tbm_bo old_data = NULL;
- if (bo == NULL)
+ if (bo == NULL || gBufMgr == NULL) {
+ TBM_LOG_E("error: bo is NULL or tbm_bufmgr was deinited\n");
return 0;
-
- if (!LIST_IS_EMPTY(&gBufMgr->bo_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &gBufMgr->bo_list, item_link) {
- if (old_data == bo)
- return 1;
- }
-
}
- return 0;
-}
-
-static void _tbm_bo_ref(tbm_bo bo)
-{
- bo->ref_cnt++;
-}
-
-static void _tbm_bo_unref(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- tbm_user_data *old_data = NULL, *tmp = NULL;
-
- if (bo->ref_cnt <= 0)
- return;
-
- bo->ref_cnt--;
- if (bo->ref_cnt == 0) {
- /* destory the user_data_list */
- if (!LIST_IS_EMPTY(&bo->user_data_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &bo->user_data_list, item_link) {
- DBG("[libtbm:%d] free user_data \n",
- getpid());
- _user_data_delete(old_data);
- }
- }
- if (bo->lock_cnt > 0) {
- TBM_LOG("[libtbm:%d] "
- "error %s:%d lock_cnt:%d\n",
- getpid(), __FUNCTION__, __LINE__, bo->lock_cnt);
- _bo_unlock(bo);
- }
-
- /* Destroy Global Lock */
- _tbm_bo_destroy_state(bo);
-
- /* call the bo_free */
- bufmgr->backend->bo_free(bo);
- bo->priv = NULL;
+ if (LIST_IS_EMPTY(&gBufMgr->bo_list)) {
+ TBM_LOG_E("error: gBufMgr->bo_list is EMPTY.\n");
+ return 0;
+ }
- LIST_DEL(&bo->item_link);
- free(bo);
- bo = NULL;
+ LIST_FOR_EACH_ENTRY(old_data, &gBufMgr->bo_list, item_link) {
+ if (old_data == bo)
+ return 1;
}
+ TBM_LOG_E("error: No valid bo(%p).\n", bo);
+
+ return 0;
}
-static int _tbm_bufmgr_init_state(tbm_bufmgr bufmgr)
+static void
+_tbm_bo_free(tbm_bo bo)
{
- RETURN_VAL_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
-
- bufmgr->lock_fd = open(tgl_devfile, O_RDWR);
+ tbm_bufmgr bufmgr = bo->bufmgr;
- if (bufmgr->lock_fd < 0) {
- bufmgr->lock_fd = open(tgl_devfile1, O_RDWR);
- if (bufmgr->lock_fd < 0) {
+ /* destory the user_data_list */
+ if (!LIST_IS_EMPTY(&bo->user_data_list)) {
+ tbm_user_data *old_data = NULL, *tmp;
- TBM_LOG("[libtbm:%d] "
- "error: Fail to open global_lock:%s\n",
- getpid(), tgl_devfile);
- return 0;
+ 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);
}
}
- if (!_tgl_init(bufmgr->lock_fd, GLOBAL_KEY)) {
- TBM_LOG("[libtbm:%d] "
- "error: Fail to initialize the tgl\n",
- getpid());
- return 0;
+ while (bo->lock_cnt > 0) {
+ TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
+ _bo_unlock(bo);
+ bo->lock_cnt--;
}
- return 1;
-}
+ /* call the bo_free */
+ bufmgr->backend->bo_free(bo);
+ bo->priv = NULL;
-static void _tbm_bufmgr_destroy_state(tbm_bufmgr bufmgr)
-{
- RETURN_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags));
+ LIST_DEL(&bo->item_link);
+ free(bo);
- close(bufmgr->lock_fd);
+ bufmgr->bo_cnt--;
}
-static int _check_version(TBMModuleVersionInfo * data)
+/* LCOV_EXCL_START */
+static int
+_check_version(TBMModuleVersionInfo *data)
{
int abimaj, abimin;
int vermaj, vermin;
abimaj = GET_ABI_MAJOR(data->abiversion);
abimin = GET_ABI_MINOR(data->abiversion);
- DBG("[libtbm:%d] "
- "TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
- getpid(), data->modname ? data->modname : "UNKNOWN!",
- data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
+ TBM_DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
+ data->modname ? data->modname : "UNKNOWN!",
+ data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
vermaj = GET_ABI_MAJOR(TBM_ABI_VERSION);
vermin = GET_ABI_MINOR(TBM_ABI_VERSION);
- DBG("[libtbm:%d] "
- "TBM ABI version %d.%d\n",
- getpid(), vermaj, vermin);
+ TBM_DBG("TBM ABI version %d.%d\n",
+ vermaj, vermin);
if (abimaj != vermaj) {
- TBM_LOG("[libtbm:%d] "
- "TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
- getpid(), 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("[libtbm:%d] "
- "TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
- getpid(), abimin, vermin);
+ TBM_LOG_E("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
+ abimin, vermin);
return 0;
}
+
return 1;
}
-static int _tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
+static int
+_tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
{
- char path[PATH_MAX] = { 0, };
- TBMModuleData *initdata = NULL;
+ 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_LOG("[libtbm:%d] "
- "failed to load module: %s(%s)\n",
- getpid(), dlerror(), file);
+ TBM_LOG_E("failed to load module: %s(%s)\n", dlerror(), file);
return 0;
}
initdata = dlsym(module_data, "tbmModuleData");
- if (initdata) {
- ModuleInitProc init;
- TBMModuleVersionInfo *vers;
+ if (!initdata) {
+ TBM_LOG_E("Error: module does not have data object.\n");
+ goto err;
+ }
- vers = initdata->vers;
- init = initdata->init;
+ vers = initdata->vers;
+ if (!vers) {
+ TBM_LOG_E("Error: module does not supply version information.\n");
+ goto err;
+ }
- if (vers) {
- if (!_check_version(vers)) {
- dlclose(module_data);
- return 0;
- }
- } else {
- TBM_LOG("[libtbm:%d] "
- "Error: module does not supply version information.\n",
- getpid());
+ init = initdata->init;
+ if (!init) {
+ TBM_LOG_E("Error: module does not supply init symbol.\n");
+ goto err;
+ }
- dlclose(module_data);
- return 0;
- }
+ if (!_check_version(vers)) {
+ TBM_LOG_E("Fail to check version.\n");
+ goto err;
+ }
- if (init) {
- if (!init(bufmgr, fd)) {
- TBM_LOG("[libtbm:%d] "
- "Fail to init module(%s)\n",
- getpid(), file);
- dlclose(module_data);
- return 0;
- }
+ if (!init(bufmgr, fd)) {
+ TBM_LOG_E("Fail to init module(%s)\n", file);
+ goto err;
+ }
- if (!bufmgr->backend || !bufmgr->backend->priv) {
- TBM_LOG("[libtbm:%d] "
- "Error: module(%s) wrong operation. Check backend or backend's priv.\n",
- getpid(), file);
- dlclose(module_data);
- return 0;
- }
- } else {
- TBM_LOG("[libtbm:%d] "
- "Error: module does not supply init symbol.\n",
- getpid());
- dlclose(module_data);
- return 0;
- }
- } else {
- TBM_LOG("[libtbm:%d] "
- "Error: module does not have data object.\n",
- getpid());
- dlclose(module_data);
- return 0;
+ if (!bufmgr->backend || !bufmgr->backend->priv) {
+ TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file);
+ goto err;
}
bufmgr->module_data = module_data;
- DBG("[libtbm:%d] "
- "Success to load module(%s)\n",
- getpid(), file);
+ 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)
+static int
+_tbm_load_module(tbm_bufmgr bufmgr, int fd)
{
struct dirent **namelist;
- const char *p = NULL;
- int n;
- int ret = 0;
+ int ret = 0, n;
/* load bufmgr priv from default lib */
- ret = _tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB);
+ if (_tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB))
+ return 1;
/* load bufmgr priv from configured path */
- if (!ret) {
- n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
- if (n < 0) {
- TBM_LOG("[libtbm:%d] "
- "no files : %s\n",
- getpid(), BUFMGR_MODULE_DIR);
- } else {
- while (n--) {
- if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) {
- p = strstr(namelist[n]->d_name, SUFFIX_LIB);
- if (p != NULL) {
- if (!strcmp(p, SUFFIX_LIB))
- ret = _tbm_bufmgr_load_module(bufmgr, fd, namelist[n]->d_name);
- }
- }
- free(namelist[n]);
- }
- free(namelist);
+ n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
+ if (n < 0) {
+ TBM_LOG_E("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_bufmgr_load_module(bufmgr, fd,
+ namelist[n]->d_name);
}
+
+ free(namelist[n]);
}
+ free(namelist);
+
return ret;
}
+/* LCOV_EXCL_STOP */
-tbm_bufmgr tbm_bufmgr_init(int fd)
+tbm_bufmgr
+tbm_bufmgr_init(int fd)
{
+#ifdef TBM_BUFMGR_INIT_TIME
+ struct timeval start_tv, end_tv;
+#endif
char *env;
- int fd_flag = 0;
- int backend_flag = 0;
- pthread_mutex_lock(&gLock);
+#ifdef TBM_BUFMGR_INIT_TIME
+ /* get the start tv */
+ gettimeofday(&start_tv, NULL);
+#endif
+
+ /* LCOV_EXCL_START */
+#ifdef HAVE_DLOG
+ env = getenv("TBM_DLOG");
+ if (env) {
+ bDlog = atoi(env);
+ TBM_LOG_D("TBM_DLOG=%s\n", env);
+ } else
+ bDlog = 1;
+#endif
#ifdef DEBUG
- env = getenv("GEM_DEBUG");
+ env = getenv("TBM_DEBUG");
if (env) {
bDebug = atoi(env);
- TBM_LOG("GEM_DEBUG=%s\n", 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);
+ } else
+ bTrace = 0;
+#endif
+
+ pthread_mutex_lock(&gLock);
+
+ 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");
+ }
+
+
/* initialize buffer manager */
if (gBufMgr) {
- DBG("[libtbm:%d] use previous gBufMgr\n", getpid());
-
- if (fd >= 0) {
- if (dup2(gBufMgr->fd, fd) < 0) {
- _tbm_set_last_result(TBM_BO_ERROR_DUP_FD_FAILED);
- DBG("[libtbm:%d] Fail to duplicate(dup2) the drm fd\n",
- getpid());
- pthread_mutex_unlock(&gLock);
- return NULL;
- }
- DBG("[libtbm:%d] duplicate the drm_fd(%d), new drm_fd(%d).\n",
- getpid(), gBufMgr->fd, fd);
- }
gBufMgr->ref_count++;
-
- DBG("[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n",
- getpid(), gBufMgr->fd, gBufMgr->ref_count);
+ TBM_TRACE("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd);
pthread_mutex_unlock(&gLock);
return gBufMgr;
}
- if (fd < 0) {
-#ifdef HAVE_X11
- fd = tbm_bufmgr_get_drm_fd_x11();
-#elif HAVE_WAYLAND
- fd = tbm_bufmgr_get_drm_fd_wayland();
-#endif
- if (fd < 0) {
- _tbm_set_last_result(TBM_BO_ERROR_GET_FD_FAILED);
- TBM_LOG("[libtbm:%d] Fail get drm fd\n",
- getpid());
- pthread_mutex_unlock(&gLock);
- return NULL;
- }
- fd_flag = 1;
- }
-
- DBG("[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd);
+ TBM_DBG("bufmgr init\n");
/* allocate bufmgr */
gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
if (!gBufMgr) {
_tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
- if (fd_flag)
- close(fd);
-
+ TBM_TRACE("error: fail to alloc bufmgr fd(%d)\n", fd);
pthread_mutex_unlock(&gLock);
return NULL;
}
- gBufMgr->fd_flag = fd_flag;
-
- if (fd_flag) {
- gBufMgr->fd = fd;
- } else {
- gBufMgr->fd = dup(fd);
- if (gBufMgr->fd < 0) {
- _tbm_set_last_result(TBM_BO_ERROR_DUP_FD_FAILED);
- TBM_LOG("[libtbm:%d] Fail to duplicate(dup) the drm fd\n",
- getpid());
- free(gBufMgr);
- gBufMgr = NULL;
- pthread_mutex_unlock(&gLock);
- return NULL;
- }
- DBG("[libtbm:%d] duplicate the drm_fd(%d), bufmgr use fd(%d).\n",
- getpid(), fd, gBufMgr->fd);
- }
+ gBufMgr->fd = fd;
/* load bufmgr priv from env */
if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) {
_tbm_set_last_result(TBM_BO_ERROR_LOAD_MODULE_FAILED);
- TBM_LOG("[libtbm:%d] " "error : Fail to load bufmgr backend\n", getpid());
- close(gBufMgr->fd);
+ TBM_LOG_E("error : Fail to load bufmgr backend\n");
free(gBufMgr);
gBufMgr = NULL;
pthread_mutex_unlock(&gLock);
return NULL;
- } else {
- backend_flag = gBufMgr->backend->flags;
- /* log for tbm backend_flag */
- DBG("[libtbm:%d] ", getpid());
- DBG("cache_crtl:");
- if (backend_flag & TBM_CACHE_CTRL_BACKEND) {
- DBG("BACKEND ");
- } else {
- DBG("TBM ");
- }
-
- DBG("lock_crtl:");
- if (backend_flag & TBM_LOCK_CTRL_BACKEND) {
- DBG("BACKEND ");
- } else {
- DBG("TBM ");
- }
- DBG("\n");
}
+ /* LCOV_EXCL_STOP */
- gBufMgr->ref_count = 1;
-
- DBG("[libtbm:%d] create tizen bufmgr: ref_count:%d\n",
- getpid(), gBufMgr->ref_count);
-
- if (pthread_mutex_init(&gBufMgr->lock, NULL) != 0) {
- _tbm_set_last_result(TBM_BO_ERROR_THREAD_INIT_FAILED);
- gBufMgr->backend->bufmgr_deinit(gBufMgr->backend->priv);
- tbm_backend_free(gBufMgr->backend);
- dlclose(gBufMgr->module_data);
- close(gBufMgr->fd);
- free(gBufMgr);
- gBufMgr = NULL;
- pthread_mutex_unlock(&gLock);
- return NULL;
- }
+ /* log for tbm backend_flag */
+ TBM_DBG("backend flag:%x:", gBufMgr->backend->flags);
+ TBM_DBG("\n");
- /* intialize the tizen global status */
- if (!_tbm_bufmgr_init_state(gBufMgr)) {
- _tbm_set_last_result(TBM_BO_ERROR_INIT_STATE_FAILED);
- TBM_LOG("[libtbm:%d] " "error: Fail to init state\n", getpid());
- gBufMgr->backend->bufmgr_deinit(gBufMgr->backend->priv);
- tbm_backend_free(gBufMgr->backend);
- pthread_mutex_destroy(&gBufMgr->lock);
- dlclose(gBufMgr->module_data);
- close(gBufMgr->fd);
- free(gBufMgr);
- gBufMgr = NULL;
- pthread_mutex_unlock(&gLock);
- return NULL;
- }
+ gBufMgr->ref_count = 1;
+
+ TBM_DBG("create tizen bufmgr:%p ref_count:%d\n",
+ gBufMgr, gBufMgr->ref_count);
/* setup the lock_type */
env = getenv("BUFMGR_LOCK_TYPE");
else
gBufMgr->lock_type = LOCK_TRY_ALWAYS;
- DBG("[libtbm:%d] BUFMGR_LOCK_TYPE=%s\n",
- getpid(), env ? env : "default:once");
+ TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once");
- /* setup the map_cache */
- env = getenv("BUFMGR_MAP_CACHE");
- if (env && !strcmp(env, "false"))
- gBufMgr->use_map_cache = 0;
- else
- gBufMgr->use_map_cache = 1;
- DBG("[libtbm:%d] BUFMGR_MAP_CACHE=%s\n",
- getpid(), env ? env : "default:true");
+ 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);
/* intialize surf_list */
LIST_INITHEAD(&gBufMgr->surf_list);
+ /* intialize surf_queue_list */
+ LIST_INITHEAD(&gBufMgr->surf_queue_list);
+
+ /* intialize debug_key_list */
+ LIST_INITHEAD(&gBufMgr->debug_key_list);
+
+#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)));
+#endif
+
pthread_mutex_unlock(&gLock);
+
return gBufMgr;
}
-void tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
+void
+tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
{
TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
- tbm_bo bo = NULL;
- tbm_bo tmp = NULL;
-
- tbm_surface_h surf = NULL;
- tbm_surface_h tmp_surf = NULL;
-
+ _tbm_bufmgr_mutex_lock();
pthread_mutex_lock(&gLock);
+ if (!gBufMgr) {
+ TBM_LOG_E("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_LOG("[libtbm:%d] "
- "tizen bufmgr destroy: bufmgr:%p, ref_count:%d\n",
- getpid(), bufmgr, bufmgr->ref_count);
+ TBM_TRACE("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
pthread_mutex_unlock(&gLock);
+ _tbm_bufmgr_mutex_unlock();
return;
}
/* destroy bo_list */
if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
+ tbm_bo bo = NULL, tmp;
+
LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bo_list, item_link) {
- TBM_LOG("[libtbm:%d] "
- "Un-freed bo(%p, ref:%d) \n",
- getpid(), bo, bo->ref_cnt);
- bo->ref_cnt = 1;
- tbm_bo_unref(bo);
+ TBM_LOG_E("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt);
+ _tbm_bo_free(bo);
}
+ LIST_DELINIT(&bufmgr->bo_list);
}
/* destroy surf_list */
if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(surf, tmp_surf, &bufmgr->surf_list, item_link) {
- TBM_LOG("[libtbm:%d] "
- "Destroy surf(%p) \n",
- getpid(), surf);
+ 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_surface_destroy(surf);
}
+ LIST_DELINIT(&bufmgr->surf_list);
}
- /* destroy the tizen global status */
- _tbm_bufmgr_destroy_state(bufmgr);
-
/* destroy bufmgr priv */
bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
bufmgr->backend->priv = NULL;
tbm_backend_free(bufmgr->backend);
bufmgr->backend = NULL;
- pthread_mutex_destroy(&bufmgr->lock);
-
- DBG("[libtbm:%d] "
- "tizen bufmgr destroy: bufmgr:%p\n",
- getpid(), bufmgr);
+ TBM_TRACE("destroy tbm_bufmgr(%p)\n", bufmgr);
dlclose(bufmgr->module_data);
- close(bufmgr->fd);
+ if (bufmgr->fd > 0)
+ close(bufmgr->fd);
free(bufmgr);
- bufmgr = NULL;
gBufMgr = NULL;
pthread_mutex_unlock(&gLock);
+ _tbm_bufmgr_mutex_unlock();
}
-int tbm_bo_size(tbm_bo bo)
+int
+tbm_bo_size(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- tbm_bufmgr bufmgr = bo->bufmgr;
+ tbm_bufmgr bufmgr = gBufMgr;
int size;
- pthread_mutex_lock(&bufmgr->lock);
+ _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);
- pthread_mutex_unlock(&bufmgr->lock);
+ TBM_TRACE("bo(%p) size(%d)\n", bo, size);
+
+ _tbm_bufmgr_mutex_unlock();
return size;
}
-tbm_bo tbm_bo_ref(tbm_bo bo)
+tbm_bo
+tbm_bo_ref(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
+ _tbm_bufmgr_mutex_lock();
- tbm_bufmgr bufmgr = bo->bufmgr;
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
- pthread_mutex_lock(&bufmgr->lock);
+ bo->ref_cnt++;
- _tbm_bo_ref(bo);
+ TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return bo;
}
-void tbm_bo_unref(tbm_bo bo)
+void
+tbm_bo_unref(tbm_bo bo)
{
- TBM_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
+ _tbm_bufmgr_mutex_lock();
- tbm_bufmgr bufmgr = bo->bufmgr;
+ TBM_BUFMGR_RETURN_IF_FAIL(gBufMgr);
+ TBM_BUFMGR_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
- pthread_mutex_lock(&bufmgr->lock);
+ TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
+
+ if (bo->ref_cnt <= 0) {
+ _tbm_bufmgr_mutex_unlock();
+ return;
+ }
- _tbm_bo_unref(bo);
+ bo->ref_cnt--;
+ if (bo->ref_cnt == 0)
+ _tbm_bo_free(bo);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
}
-tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
+tbm_bo
+tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr) && (size > 0), NULL);
+ void *bo_priv;
+ tbm_bo bo;
- tbm_bo bo = NULL;
- void *bo_priv = NULL;
+ _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);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL);
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 */
}
- bo->bufmgr = bufmgr;
+ _tbm_util_check_bo_cnt(bufmgr);
- pthread_mutex_lock(&bufmgr->lock);
+ bo->bufmgr = bufmgr;
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);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return NULL;
+ /* LCOV_EXCL_STOP */
}
+ bufmgr->bo_cnt++;
+
bo->ref_cnt = 1;
bo->flags = flags;
- bo->tgl_key = INITIAL_KEY;
bo->priv = bo_priv;
- bo->default_handle.u32 = 0;
- /* init bo state */
- if (!_tbm_bo_init_state(bo, CACHE_OP_CREATE)) {
- _tbm_set_last_result(TBM_BO_ERROR_INIT_STATE_FAILED);
- _tbm_bo_unref(bo);
- pthread_mutex_unlock(&bufmgr->lock);
- return NULL;
- }
+ TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
+ _tbm_flag_to_str(bo->flags));
LIST_INITHEAD(&bo->user_data_list);
LIST_ADD(&bo->item_link, &bufmgr->bo_list);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return bo;
}
-tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
+tbm_bo
+tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+ void *bo_priv;
+ tbm_bo bo;
- tbm_bo bo = NULL;
- tbm_bo bo2 = NULL;
- tbm_bo tmp = NULL;
- void *bo_priv = NULL;
+ _tbm_bufmgr_mutex_lock();
- pthread_mutex_lock(&bufmgr->lock);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
- /* find bo in list */
- if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(bo2, tmp, &bufmgr->bo_list, item_link) {
- if (bo2->tgl_key == key) {
- DBG("[libtbm:%d] "
- "find bo(%p, ref:%d key:%d) in list \n",
- getpid(), bo2, bo2->ref_cnt, bo2->tgl_key);
-
- bo2->ref_cnt++;
- pthread_mutex_unlock(&bufmgr->lock);
- return bo2;
- }
- }
+ 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) {
- pthread_mutex_unlock(&bufmgr->lock);
+ /* 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);
- pthread_mutex_unlock(&bufmgr->lock);
+ _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->tgl_key = INITIAL_KEY;
bo->priv = bo_priv;
- bo->default_handle.u32 = 0;
if (bufmgr->backend->bo_get_flags)
bo->flags = bufmgr->backend->bo_get_flags(bo);
else
bo->flags = TBM_BO_DEFAULT;
- /* init bo state */
- if (!_tbm_bo_init_state(bo, CACHE_OP_IMPORT)) {
- _tbm_set_last_result(TBM_BO_ERROR_INIT_STATE_FAILED);
- _tbm_bo_unref(bo);
- pthread_mutex_unlock(&bufmgr->lock);
- return NULL;
- }
+ 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);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return bo;
}
-tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
+tbm_bo
+tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
-
- tbm_bo bo = NULL;
- tbm_bo bo2 = NULL;
- tbm_bo tmp = NULL;
- void *bo_priv = NULL;
- tbm_bo_handle default_handle;
+ void *bo_priv;
+ tbm_bo bo;
- pthread_mutex_lock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_lock();
- default_handle = bufmgr->backend->fd_to_handle(bufmgr, fd, TBM_DEVICE_DEFAULT);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
- /* find bo in list */
- if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(bo2, tmp, &bufmgr->bo_list, item_link) {
- if (bo2->default_handle.u32 == default_handle.u32) {
- DBG("[libtbm:%d] "
- "find bo(%p, ref:%d handle:%d) in list \n",
- getpid(), bo2, bo2->ref_cnt, bo2->default_handle.u32);
-
- bo2->ref_cnt++;
- pthread_mutex_unlock(&bufmgr->lock);
- return bo2;
- }
- }
+ 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) {
- pthread_mutex_unlock(&bufmgr->lock);
+ /* 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);
- pthread_mutex_unlock(&bufmgr->lock);
+ _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->tgl_key = INITIAL_KEY;
bo->priv = bo_priv;
- bo->default_handle.u32 = 0;
if (bufmgr->backend->bo_get_flags)
bo->flags = bufmgr->backend->bo_get_flags(bo);
else
bo->flags = TBM_BO_DEFAULT;
- /* init bo state */
- if (!_tbm_bo_init_state(bo, CACHE_OP_IMPORT)) {
- _tbm_set_last_result(TBM_BO_ERROR_INIT_STATE_FAILED);
- _tbm_bo_unref(bo);
- pthread_mutex_unlock(&bufmgr->lock);
- return NULL;
- }
+ 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);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return bo;
}
-unsigned int tbm_bo_export(tbm_bo bo)
+tbm_key
+tbm_bo_export(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+ tbm_bufmgr bufmgr = gBufMgr;
+ tbm_key ret;
- tbm_bufmgr bufmgr;
- int ret;
+ _tbm_bufmgr_mutex_lock();
- bufmgr = bo->bufmgr;
+ 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 */
+ }
- pthread_mutex_lock(&bufmgr->lock);
ret = bufmgr->backend->bo_export(bo);
if (!ret) {
+ /* LCOV_EXCL_START */
_tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED);
- pthread_mutex_unlock(&bufmgr->lock);
+ TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret);
+ _tbm_bufmgr_mutex_unlock();
return ret;
+ /* LCOV_EXCL_STOP */
}
- pthread_mutex_unlock(&bufmgr->lock);
+
+ 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_fd
+tbm_bo_export_fd(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
+ tbm_bufmgr bufmgr = gBufMgr;
+ tbm_fd ret;
- tbm_bufmgr bufmgr;
- int ret;
+ _tbm_bufmgr_mutex_lock();
- bufmgr = bo->bufmgr;
+ 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 */
+ }
- pthread_mutex_lock(&bufmgr->lock);
ret = bufmgr->backend->bo_export_fd(bo);
if (ret < 0) {
+ /* LCOV_EXCL_START */
_tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED);
- pthread_mutex_unlock(&bufmgr->lock);
+ TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret);
+ _tbm_bufmgr_mutex_unlock();
return ret;
+ /* LCOV_EXCL_STOP */
}
- pthread_mutex_unlock(&bufmgr->lock);
+
+ 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_bo_handle
+tbm_bo_get_handle(tbm_bo bo, int device)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) 0);
-
- tbm_bufmgr bufmgr;
+ tbm_bufmgr bufmgr = gBufMgr;
tbm_bo_handle bo_handle;
- bufmgr = bo->bufmgr;
+ _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);
- pthread_mutex_lock(&bufmgr->lock);
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);
- pthread_mutex_unlock(&bufmgr->lock);
+ 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 */
}
- pthread_mutex_unlock(&bufmgr->lock);
+
+ 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_bo_handle
+tbm_bo_map(tbm_bo bo, int device, int opt)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) 0);
-
- tbm_bufmgr bufmgr;
+ tbm_bufmgr bufmgr = gBufMgr;
tbm_bo_handle bo_handle;
- bufmgr = bo->bufmgr;
-
- pthread_mutex_lock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_lock();
- bo_handle = bufmgr->backend->bo_get_handle(bo, device);
+ 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("[libtbm:%d] "
- "error %s:%d fail to lock bo:%p)\n",
- getpid(), __FUNCTION__, __LINE__, bo);
- pthread_mutex_unlock(&bufmgr->lock);
+ 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("[libtbm:%d] "
- "error %s:%d fail to map bo:%p\n",
- getpid(), __FUNCTION__, __LINE__, bo);
-
+ TBM_LOG_E("error: fail to map bo:%p\n", bo);
_tbm_bo_unlock(bo);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return (tbm_bo_handle) NULL;
+ /* LCOV_EXCL_STOP */
}
- if (bufmgr->use_map_cache == 1 && bo->map_cnt == 0)
- _tbm_bo_set_state(bo, device, opt);
-
/* increase the map_count */
bo->map_cnt++;
- pthread_mutex_unlock(&bufmgr->lock);
+ 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)
+int
+tbm_bo_unmap(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- tbm_bufmgr bufmgr;
+ tbm_bufmgr bufmgr = gBufMgr;
int ret;
- bufmgr = bo->bufmgr;
+ _tbm_bufmgr_mutex_lock();
- pthread_mutex_lock(&bufmgr->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);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 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);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return ret;
+ /* LCOV_EXCL_STOP */
}
/* decrease the map_count */
bo->map_cnt--;
- if (bo->map_cnt == 0)
- _tbm_bo_save_state(bo);
+ TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
_tbm_bo_unlock(bo);
- pthread_mutex_unlock(&bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return ret;
}
-int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
+int
+tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
-
+ tbm_bufmgr bufmgr = gBufMgr;
void *temp;
- unsigned int tmp_key;
- tbm_bo_handle tmp_defualt_handle;
- pthread_mutex_lock(&bo1->bufmgr->lock);
+ _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);
- if (bo1->bufmgr->backend->bo_size(bo1) != bo2->bufmgr->backend->bo_size(bo2)) {
+ 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);
- pthread_mutex_unlock(&bo1->bufmgr->lock);
+ TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2);
+ _tbm_bufmgr_mutex_unlock();
return 0;
}
- tmp_key = bo1->tgl_key;
- bo1->tgl_key = bo2->tgl_key;
- bo2->tgl_key = tmp_key;
-
- tmp_defualt_handle = bo1->default_handle;
- bo1->default_handle = bo2->default_handle;
- bo2->default_handle = tmp_defualt_handle;
+ TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2);
temp = bo1->priv;
bo1->priv = bo2->priv;
bo2->priv = temp;
- pthread_mutex_unlock(&bo1->bufmgr->lock);
+ _tbm_bufmgr_mutex_unlock();
return 1;
}
-int tbm_bo_locked(tbm_bo bo)
+int
+tbm_bo_locked(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+ tbm_bufmgr bufmgr = gBufMgr;
- tbm_bufmgr bufmgr;
+ _tbm_bufmgr_mutex_lock();
- bufmgr = bo->bufmgr;
+ 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)
+ 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;
-
- pthread_mutex_lock(&bufmgr->lock);
+ }
if (bo->lock_cnt > 0) {
- pthread_mutex_unlock(&bufmgr->lock);
+ TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
+ _tbm_bufmgr_mutex_unlock();
return 1;
}
- pthread_mutex_unlock(&bufmgr->lock);
+ 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)
+int
+tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
+ tbm_data_free data_free_func)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
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);
+ data = user_data_lookup(&bo->user_data_list, key);
if (data) {
- TBM_LOG("[libtbm:%d] "
- "waring: %s:%d user data already exist. key:%ld\n",
- getpid(), __FUNCTION__, __LINE__, key);
+ 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)
+ 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)
+int
+tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
tbm_user_data *old_data;
- if (LIST_IS_EMPTY(&bo->user_data_list))
+ _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)
+ 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)
+int
+tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
tbm_user_data *old_data;
- if (!data || LIST_IS_EMPTY(&bo->user_data_list))
+ _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);
+ 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)
+int
+tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+ tbm_user_data *old_data;
+
+ _tbm_bufmgr_mutex_lock();
- tbm_user_data *old_data = (void *)0;
+ 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))
+ 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)
+ 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);
+ user_data_delete(old_data);
+
+ _tbm_bufmgr_mutex_unlock();
return 1;
}
-tbm_error_e tbm_get_last_error(void)
+unsigned int
+tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
{
- return tbm_last_error;
-}
+ unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE;
-unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
-{
- TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), 0);
+ _tbm_bufmgr_mutex_lock();
- unsigned int capability = TBM_BUFMGR_CAPABILITY_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);
- if (bufmgr->backend->bo_import && bufmgr->backend->bo_export)
- capability |= TBM_BUFMGR_CAPABILITY_SHARE_KEY;
+ TBM_TRACE("tbm_bufmgr(%p) capability(%u)\n", bufmgr, bufmgr->capabilities);
- if (bufmgr->backend->bo_import_fd && bufmgr->backend->bo_export_fd)
- capability |= TBM_BUFMGR_CAPABILITY_SHARE_FD;
+ capabilities = bufmgr->capabilities;
- return capability;
+ _tbm_bufmgr_mutex_unlock();
+
+ return capabilities;
}
-int tbm_bo_get_flags(tbm_bo bo)
+int
+tbm_bo_get_flags(tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+ 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;
- return bo->flags;
+ TBM_TRACE("bo(%p)\n", bo);
+
+ _tbm_bufmgr_mutex_unlock();
+
+ return flags;
}
-void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
+/* LCOV_EXCL_START */
+tbm_error_e
+tbm_get_last_error(void)
{
- TBM_RETURN_IF_FAIL(bufmgr != NULL);
- tbm_bo bo = NULL, tmp_bo = NULL;
- int bo_cnt = 0;
+ return tbm_last_error;
+}
- tbm_surface_h surf = NULL, tmp_surf = NULL;
- int surf_cnt = 0;
- int i;
- char app_name[255] = {0,};
- unsigned int pid = 0;
+char *
+tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr)
+{
+ 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;
pthread_mutex_lock(&gLock);
+ if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) {
+ TBM_LOG_E("invalid bufmgr\n");
+ pthread_mutex_unlock(&gLock);
+ return NULL;
+ }
+
+ str = malloc(len);
+ if (!str) {
+ TBM_LOG_E("Fail to allocate the string.\n");
+ pthread_mutex_unlock(&gLock);
+ return NULL;
+ }
+
+ TBM_SNRPRINTF(str, len, c, "\n");
_tbm_util_get_appname_from_pid(getpid(), app_name);
_tbm_util_get_appname_brief(app_name);
- TBM_DEBUG("============TBM DEBUG: %s(%d)===========================\n", app_name, getpid());
- memset(app_name, 0x0, 255*sizeof(char));
+ TBM_SNRPRINTF(str, len, c, "============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, " ", MAX_SIZE_N(title));
+ strncat(title, debug_old_data->key, MAX_SIZE_N(title));
+ }
+ }
+
+ TBM_SNRPRINTF(str, len, c, "[tbm_surface information]\n");
+ TBM_SNRPRINTF(str, len, c, "%s\n", title);
- TBM_DEBUG("[tbm_surface information]\n");
- TBM_DEBUG("no surface refcnt width height bpp size num_bos num_planes flags format app_name\n");
/* show the tbm_surface information in surf_list */
if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(surf, tmp_surf, &bufmgr->surf_list, item_link) {
+ 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();
+ /* 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);
- TBM_DEBUG("%-4d%-23p%-6d%-7d%-8d%-5d%-12d%-10d%-9d%-4d%-20s%s\n",
- ++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),
- 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, " ", MAX_SIZE_N(title));
+
+ 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);
for (i = 0; i < surf->num_bos; i++) {
- TBM_DEBUG(" bo:%-11p(key:%2d) %-26d%-10d\n",
- surf->bos[i],
- surf->bos[i]->tgl_key,
- surf->bos[i]->ref_cnt,
- tbm_bo_size(surf->bos[i])/1024);
+ 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);
}
-
- memset(app_name, 0x0, 255*sizeof(char));
}
- } else {
- TBM_DEBUG("no tbm_surfaces.\n");
- }
- TBM_DEBUG("\n");
+ } else
+ TBM_SNRPRINTF(str, len, c, " no tbm_surfaces.\n");
+ TBM_SNRPRINTF(str, len, c, "\n");
- TBM_DEBUG("[tbm_bo information]\n");
- TBM_DEBUG("no bo refcnt size lock_cnt map_cnt cache_state flags surface\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");
/* show the tbm_bo information in bo_list */
if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(bo, tmp_bo, &bufmgr->bo_list, item_link) {
- TBM_DEBUG("%-4d%-11p(key:%2d) %-6d%-12d%-9d%-9d%-10d%-4d%-11p\n",
- ++bo_cnt,
- bo,
- bo->tgl_key,
- bo->ref_cnt,
- tbm_bo_size(bo)/1024,
- bo->lock_cnt,
- bo->map_cnt,
- bo->cache_state.val,
- bo->flags,
- bo->surface);
+ int bo_cnt = 0;
+ tbm_bo bo = NULL;
+
+ LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
+ 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,
+ bo->lock_cnt,
+ bo->map_cnt,
+ bo->flags,
+ bo->surface,
+ bufmgr->backend->bo_export(bo));
}
- } else {
- TBM_DEBUG("no tbm_bos.\n");
+ } else
+ TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n");
+ TBM_SNRPRINTF(str, len, c, "\n");
+
+ TBM_SNRPRINTF(str, len, c, "===============================================================\n");
+
+ pthread_mutex_unlock(&gLock);
+
+ return str;
+}
+
+void
+tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
+{
+ char * str;
+ str = tbm_bufmgr_debug_tbm_info_get(bufmgr);
+ if (str) {
+ TBM_DEBUG(" %s", str);
+ free(str);
}
- TBM_DEBUG("\n");
+}
+
+void
+tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
+{
+ _tbm_bufmgr_mutex_lock();
+
+ TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
+ TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
+
+#ifdef TRACE
+ TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
+ bTrace = onoff;
+#endif
- TBM_DEBUG("===============================================================\n");
+ _tbm_bufmgr_mutex_unlock();
+}
+void
+tbm_bufmgr_debug_dump_set_scale(double scale)
+{
+ pthread_mutex_lock(&gLock);
+ scale_factor = scale;
pthread_mutex_unlock(&gLock);
+}
+
+int
+tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
+{
+ pthread_mutex_lock(&gLock);
+
+ if (onoff == 0) {
+ TBM_LOG_D("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");
+ pthread_mutex_unlock(&gLock);
+ return 0;
+ }
+ TBM_LOG_D("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");
+ pthread_mutex_unlock(&gLock);
+ return 0;
+ }
+
+ tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
+ scale_factor = 0;
+
+ b_dump_queue = 1;
+ }
+ pthread_mutex_unlock(&gLock);
+ return 1;
}
-void tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
+int
+tbm_bufmgr_debug_dump_all(char *path)
{
- TBM_LOG("bufmgr=%p onoff=%d\n", bufmgr, onoff);
- TBM_LOG("Not implemented yet.\n");
+ 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);
+
+ count = _tbm_util_get_max_surface_size(&w, &h);
+ if (count == 0) {
+ TBM_LOG_E("No tbm_surface.\n");
+ pthread_mutex_unlock(&gLock);
+ return 1;
+ }
+
+ tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
+ scale_factor = 0;
+
+ LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link)
+ tbm_surface_internal_dump_buffer(surface, "dump_all");
+
+ tbm_surface_internal_dump_end();
+
+ pthread_mutex_unlock(&gLock);
+
+ return 1;
}
/* internal function */
-int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
+tbm_bufmgr
+_tbm_bufmgr_get_bufmgr(void)
+{
+ return gBufMgr;
+}
+
+int
+_tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
{
- TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+ _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);
bo->surface = surface;
+ _tbm_bufmgr_mutex_unlock();
+
+ return 1;
+}
+
+int
+tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
+{
+ int ret;
+
+ _tbm_bufmgr_mutex_lock();
+
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(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;
+ }
+
+ TBM_TRACE("tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay);
+
+ _tbm_bufmgr_mutex_unlock();
+
return 1;
}
+int tbm_bufmgr_get_fd_limit(void)
+{
+ struct rlimit lim;
+
+ if (getrlimit(RLIMIT_NOFILE, &lim))
+ return 1024;
+
+ return (int)lim.rlim_cur;
+}
+/* LCOV_EXCL_STOP */