Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
#include "config.h"
-#include <unistd.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dlfcn.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <pthread.h>
#include "tbm_bufmgr.h"
-#include "tbm_bufmgr_glock.h"
-#include "tbm_bufmgr_backend.h"
#include "tbm_bufmgr_int.h"
+#include "tbm_bufmgr_backend.h"
#include "list.h"
-#define DEBUG
-#ifdef DEBUG
-static int bDebug = 0;
-#define DBG(...) if(bDebug&0x1) fprintf(stderr, __VA_ARGS__)
-#define DBG_LOCK(...) if(bDebug&0x2) fprintf(stderr, __VA_ARGS__)
-#else
-#define DBG(...)
-#define DBG_LOCK(...)
-#endif
+#include <sys/resource.h>
-/* check condition */
-#define TBM_RETURN_IF_FAIL(cond) {\
- if (!(cond)) {\
- fprintf (stderr, "[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
- return;\
- }\
-}
-#define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
- if (!(cond)) {\
- fprintf (stderr, "[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
- return val;\
- }\
-}
+int trace_mask = 0;
-/* check flags */
-#define RETURN_CHECK_FLAG(cond) {\
- if ((cond)) {\
- return;\
- }\
-}
-#define RETURN_VAL_CHECK_FLAG(cond, val) {\
- if ((cond)) {\
- return val;\
- }\
-}
+#ifdef HAVE_DLOG
+int bDlog;
+#endif
+tbm_bufmgr gBufMgr;
+int b_dump_queue;
-/* check validation */
-#define TBM_BUFMGR_IS_VALID(mgr) (mgr && \
- mgr->link.next &&\
- mgr->link.next->prev == &mgr->link)
-#define TBM_BO_IS_VALID(bo) (bo && \
- TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
- bo->item_link.next && \
- bo->item_link.next->prev == &bo->item_link)
+static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER;
+static double scale_factor = 0;
+static void _tbm_bufmgr_mutex_unlock(void);
-#define CTRL_BACKEND_VALID(flags) ((flags&TBM_CACHE_CTRL_BACKEND) && \
- (flags&TBM_LOCK_CTRL_BACKEND))
+//#define TBM_BUFMGR_INIT_TIME
#define PREFIX_LIB "libtbm_"
#define SUFFIX_LIB ".so"
#define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB
-#define BO_IS_CACHEABLE(bo) ((bo->flags & TBM_BO_NONCACHABLE)?0:1)
-#define DEVICE_IS_CACHE_AWARE(device) ((device == TBM_DEVICE_CPU)?(1):(0))
-
-/* tgl key values */
-#define GLOBAL_KEY ((unsigned int)(-1))
-#define INITIAL_KEY ((unsigned int)(-2))
-
-#define CACHE_OP_CREATE (-1)
-#define CACHE_OP_ATTACH (-2)
-#define CACHE_OP_IMPORT (-3)
-
/* 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) \
- ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF))
-#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF)
-#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF)
-#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF)
-
-enum {
- LOCK_TRY_ONCE,
- LOCK_TRY_ALWAYS,
- LOCK_TRY_NEVER
-};
-
-enum {
- DEVICE_NONE = 0,
- DEVICE_CA, /* cache aware device */
- DEVICE_CO /* cache oblivious device */
-};
-
-typedef struct
-{
- unsigned long key;
- void *data;
- tbm_data_free free_func ;
-
- /* link of user_data */
- struct list_head item_link;
-} tbm_user_data;
-
-/* list of bufmgr */
-static struct list_head *gBufMgrs = NULL;
+ ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF))
+#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF)
+#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF)
+#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF)
+#define MAX_SIZE_N(dest) (sizeof(dest) - strlen(dest) - 1)
-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)
- {
- fprintf (stderr, "[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)
-{
- int err;
- err = ioctl (fd, TGL_IOC_DESTROY_LOCK, key);
- if (err)
- {
- fprintf (stderr, "[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
-}
-
-static inline int
-_tgl_lock (int fd, unsigned int key)
-{
- int err;
- err = ioctl (fd, TGL_IOC_LOCK_LOCK, key);
- if (err)
- {
- fprintf (stderr, "[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
+/* check condition */
+#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;\
+ } \
}
-static inline int
-_tgl_unlock (int fd, unsigned int key)
-{
- int err;
- err = ioctl (fd, TGL_IOC_UNLOCK_LOCK, key);
- if (err)
- {
- fprintf (stderr, "[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
+#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 inline int
-_tgl_set_data (int fd, unsigned int key, unsigned int val)
+/* LCOV_EXCL_START */
+static bool
+_tbm_bufmgr_mutex_init(void)
{
- int err;
- struct tgl_user_data arg;
-
- arg.key = key;
- arg.data1 = val;
- err = ioctl (fd, TGL_IOC_SET_DATA, &arg);
- if (err)
- {
- fprintf (stderr, "[libtbm:%d] "
- "error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
- return 0;
- }
-
- return 1;
-}
+ static bool tbm_bufmgr_mutex_init = false;
-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)
- {
- fprintf (stderr, "[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 (tbm_bufmgr_mutex_init)
+ return true;
-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;
- }
- }
- }
-
- return user_data;
-}
+ if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) {
+ TBM_ERR("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n");
+ return false;
+ }
-static tbm_user_data *
-_user_data_create (unsigned long key, tbm_data_free data_free_func)
-{
- tbm_user_data * user_data = NULL;
+ tbm_bufmgr_mutex_init = true;
- user_data = calloc (1, sizeof (tbm_user_data));
- if (!user_data)
- return NULL;
-
- user_data->key = key;
- user_data->free_func = data_free_func;
- user_data->data = (void *)0;
-
- return user_data;
+ return true;
}
static void
-_user_data_delete (tbm_user_data *user_data)
+_tbm_bufmgr_mutex_lock(void)
{
- if (user_data->data && user_data->free_func)
- user_data->free_func(user_data->data);
-
- LIST_DEL (&user_data->item_link);
+ if (!_tbm_bufmgr_mutex_init()) {
+ TBM_ERR("fail: _tbm_bufmgr_mutex_init()\n");
+ return;
+ }
- free(user_data);
-}
-
-static int
-_bo_lock (tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- int ret = 0;
-
- if (bufmgr->backend->flags&TBM_LOCK_CTRL_BACKEND &&
- bufmgr->backend->bo_lock)
- {
- /* use backend lock */
- ret = bufmgr->backend->bo_lock (bo);
- }
- else
- {
- /* use tizen global lock */
- ret = _tgl_lock (bufmgr->lock_fd, bo->tgl_key);
- }
-
- return ret;
+ pthread_mutex_lock(&tbm_bufmgr_lock);
}
static void
-_bo_unlock (tbm_bo bo)
+_tbm_bufmgr_mutex_unlock(void)
{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- if (bufmgr->backend->flags&TBM_LOCK_CTRL_BACKEND &&
- bufmgr->backend->bo_unlock)
- {
- /* use backend unlock */
- bufmgr->backend->bo_unlock (bo);
- }
- else
- {
- /* use tizen global unlock */
- _tgl_unlock (bufmgr->lock_fd, bo->tgl_key);
- }
+ pthread_mutex_unlock(&tbm_bufmgr_lock);
}
static int
-_tbm_bo_lock (tbm_bo bo)
+_tbm_util_get_max_surface_size(int *w, int *h)
{
- tbm_bufmgr bufmgr = NULL;
- int old;
- int ret = 0;
-
- if (!bo)
- return 0;
-
- bufmgr = bo->bufmgr;
-
- RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
-
- if (bo->lock_cnt < 0)
- {
- fprintf (stderr, "[libtbm:%d] "
- "error %s:%d bo:%p(%d) LOCK_CNT=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo, bo->tgl_key, bo->lock_cnt);
- }
-
- old = bo->lock_cnt;
- switch (bufmgr->lock_type)
- {
- case LOCK_TRY_ALWAYS: /* LOCK_TRY_ALWAYS */
- pthread_mutex_unlock (&bufmgr->lock);
- ret = _bo_lock (bo);
- pthread_mutex_lock (&bufmgr->lock);
- if(ret)
- bo->lock_cnt++;
- break;
- case LOCK_TRY_NEVER: /* LOCK_TRY_NEVER */
- return 1;
- break;
- default:
- if (bo->lock_cnt == 0)
- {
- pthread_mutex_unlock (&bufmgr->lock);
- ret = _bo_lock (bo);
- pthread_mutex_lock (&bufmgr->lock);
- if (ret)
- bo->lock_cnt++;
- }
-
- break;
- }
-
- DBG_LOCK ("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(),
- bo, bo->tgl_key, old, bo->lock_cnt);
-
- return 1;
+ 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_bo_unlock (tbm_bo bo)
+_tbm_util_get_appname_brief(char *brief)
{
- tbm_bufmgr bufmgr = NULL;
+ char delim[] = "/";
+ char *token = NULL;
+ char temp[255] = {0,};
+ char *saveptr = NULL;
- int old;
+ token = strtok_r(brief, delim, &saveptr);
- if (!bo)
- return;
+ while (token != NULL) {
+ memset(temp, 0x00, 255 * sizeof(char));
+ strncpy(temp, token, 254 * sizeof(char));
+ token = strtok_r(NULL, delim, &saveptr);
+ }
- bufmgr = bo->bufmgr;
-
- RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags));
+ snprintf(brief, sizeof(temp), "%s", temp);
+}
- old = bo->lock_cnt;
- if (bo->lock_cnt > 0)
- {
- bo->lock_cnt--;
- if (bo->lock_cnt == 0)
- _bo_unlock (bo);
- }
- else if (bo->lock_cnt < 0)
- {
- bo->lock_cnt = 0;
- }
+static void
+_tbm_util_get_appname_from_pid(long pid, char *str)
+{
+ char fn_cmdline[255] = {0, }, cmdline[255];
+ FILE *fp;
+ int len;
- DBG_LOCK ("[libtbm:%d] << unlock bo:%p(%d, %d->%d)\n", getpid(),
- bo, bo->tgl_key, old, bo->lock_cnt);
-}
+ if (pid <= 0) return;
+ snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", pid);
-static int
-_tbm_bo_set_state (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 (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);
-
- 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;
- }
-
- bo->cache_state.data.isCached = 1;
- if (opt & TBM_OPTION_WRITE)
- bo->cache_state.data.isDirtied = DEVICE_CA;
- else
- 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
- bo->cache_state.data.isDirtied = DEVICE_NONE;
- }
-
- if (need_flush)
- {
- /* call backend cache flush */
- bufmgr->backend->bo_cache_flush (bo, need_flush);
-
- /* set global cache flush count */
- if (need_flush & TBM_CACHE_ALL)
- _tgl_set_data (bufmgr->lock_fd, GLOBAL_KEY, (unsigned int)(++cntFlush));
-
- 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;
-}
+ fp = fopen(fn_cmdline, "r");
+ if (fp == 0) {
+ TBM_ERR("cannot file open %s\n", fn_cmdline);
+ return;
+ }
-static void
-_tbm_bo_save_state (tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- unsigned short cntFlush = 0;
+ if (!fgets(cmdline, 255, fp)) {
+ TBM_ERR("fail to get appname for pid(%ld)\n", pid);
+ fclose(fp);
+ return;
+ }
- RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags));
+ fclose(fp);
- /* get global cache flush count */
- cntFlush = (unsigned short)_tgl_get_data (bufmgr->lock_fd, GLOBAL_KEY, NULL);
+ len = strlen(cmdline);
+ if (len < 1)
+ memset(cmdline, 0x00, 255);
+ else
+ cmdline[len] = 0;
- /* save global cache flush count */
- bo->cache_state.data.cntFlush = cntFlush;
- _tgl_set_data(bufmgr->lock_fd, bo->tgl_key, bo->cache_state.val);
+ snprintf(str, sizeof(cmdline), "%s", cmdline);
}
static int
-_tbm_bo_init_state (tbm_bo bo, int opt)
+_check_version(TBMModuleVersionInfo *data)
{
- tbm_bufmgr bufmgr = bo->bufmgr;
- tbm_bo_cache_state cache_state;
-
- RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
-
- cache_state.val = 0;
- switch (opt)
- {
- case CACHE_OP_CREATE: /*Create*/
- if (bo->tgl_key == INITIAL_KEY)
- bo->tgl_key = bufmgr->backend->bo_get_global_key (bo);
-
- _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*/
- if (bo->tgl_key == INITIAL_KEY)
- bo->tgl_key = bufmgr->backend->bo_get_global_key (bo);
-
- _tgl_init (bufmgr->lock_fd, bo->tgl_key);
- break;
- default:
- break;
- }
-
- return 1;
-}
+ int backend_module_major, backend_module_minor;
+ int tbm_backend_major, tbm_backend_minor;
-static void
-_tbm_bo_destroy_state (tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
+ backend_module_major = GET_ABI_MAJOR(data->abiversion);
+ backend_module_minor = GET_ABI_MINOR(data->abiversion);
- RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags));
+ 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);
- _tgl_destroy (bufmgr->lock_fd, bo->tgl_key);
-}
+ tbm_backend_major = GET_ABI_MAJOR(TBM_ABI_VERSION);
+ tbm_backend_minor = GET_ABI_MINOR(TBM_ABI_VERSION);
-static void
-_tbm_bo_ref (tbm_bo bo)
-{
- bo->ref_cnt++;
-}
+ TBM_DBG("TBM ABI version %d.%d\n",
+ tbm_backend_major, tbm_backend_minor);
-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)
- {
- fprintf (stderr, "[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;
-
- LIST_DEL (&bo->item_link);
- free(bo);
- bo = NULL;
- }
+ if (backend_module_major != tbm_backend_major) {
+ TBM_ERR("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
+ backend_module_major, tbm_backend_major);
+ return 0;
+ } else if (backend_module_minor > tbm_backend_minor) {
+ TBM_ERR("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
+ backend_module_minor, tbm_backend_minor);
+ return 0;
+ }
+ return 1;
}
static int
-_tbm_bufmgr_init_state (tbm_bufmgr bufmgr)
+_tbm_backend_check_bufmgr_func(tbm_backend_bufmgr_func *bufmgr_func)
{
- RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
-
- bufmgr->lock_fd = open(tgl_devfile, O_RDWR);
-
- if(bufmgr->lock_fd < 0)
- {
- fprintf (stderr, "[libtbm:%d] "
- "error: Fail to open global_lock:%s\n",
- getpid(), tgl_devfile);
- return 0;
- }
-
- if (!_tgl_init(bufmgr->lock_fd, GLOBAL_KEY))
- {
- fprintf (stderr, "[libtbm:%d] "
- "error: Fail to initialize the tgl\n",
- getpid());
- return 0;
- }
-
- return 1;
+ 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 void
-_tbm_bufmgr_destroy_state (tbm_bufmgr bufmgr)
+static int
+_tbm_backend_check_bufmgr_bo(tbm_backend_bo_func *bo_func)
{
- RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags));
-
- close (bufmgr->lock_fd);
+ 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
-_check_version (TBMModuleVersionInfo *data)
+_tbm_backend_load_module(tbm_bufmgr bufmgr, const char *file)
{
- int abimaj, abimin;
- int vermaj, vermin;
-
- abimaj = GET_ABI_MAJOR (data->abiversion);
- abimin = GET_ABI_MINOR (data->abiversion);
-
- fprintf (stderr, "[libtbm:%d] "
- "TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
- getpid(), 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);
-
- if (abimaj != vermaj)
- {
- fprintf (stderr, "[libtbm:%d] "
- "TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
- getpid(), abimaj, vermaj);
- return 0;
- }
- else if (abimin > vermin)
- {
- fprintf (stderr, "[libtbm:%d] "
- "TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
- getpid(), abimin, vermin);
- return 0;
- }
- return 1;
+ char path[PATH_MAX] = {0, };
+ void *module_data = NULL;
+ tbm_backend_module *backend_module_data = NULL;
+ tbm_backend_bufmgr_data *bufmgr_data = NULL;
+ int backend_module_major, backend_module_minor;
+ int tbm_backend_major, tbm_backend_minor;
+ tbm_error_e error;
+
+ snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file);
+
+ module_data = dlopen(path, RTLD_LAZY);
+ if (!module_data) {
+ TBM_ERR("failed to load module: %s(%s)\n", dlerror(), file);
+ return 0;
+ }
+
+ backend_module_data = dlsym(module_data, "tbm_backend_module_data");
+ if (!backend_module_data) {
+ TBM_ERR("Error: module does not have data object.\n");
+ goto err;
+ }
+
+ tbm_backend_major = GET_ABI_MAJOR(TBM_BACKEND_ABI_LATEST_VERSION);
+ tbm_backend_minor = GET_ABI_MINOR(TBM_BACKEND_ABI_LATEST_VERSION);
+ TBM_INFO("TBM Backend ABI version %d.%d\n", tbm_backend_major, tbm_backend_minor);
+
+ backend_module_major = GET_ABI_MAJOR(backend_module_data->abi_version);
+ backend_module_minor = GET_ABI_MINOR(backend_module_data->abi_version);
+
+ TBM_INFO("TBM module %s: vendor=\"%s\" Backend ABI version=%d.%d\n",
+ backend_module_data->name ? backend_module_data->name : "UNKNOWN!",
+ backend_module_data->vendor ? backend_module_data->vendor : "UNKNOWN!",
+ backend_module_major, backend_module_minor);
+
+ if (backend_module_major > tbm_backend_major) {
+ TBM_ERR("TBM module ABI major ver(%d) is newer than the TBM's ver(%d)\n",
+ backend_module_major, tbm_backend_major);
+ goto err;
+ } else if (backend_module_minor > tbm_backend_minor) {
+ TBM_ERR("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
+ backend_module_minor, tbm_backend_minor);
+ goto err;
+ }
+
+ if (!backend_module_data->init) {
+ TBM_ERR("Error: module does not supply init symbol.\n");
+ goto err;
+ }
+
+ if (!backend_module_data->deinit) {
+ TBM_ERR("Error: module does not supply deinit symbol.\n");
+ goto err;
+ }
+
+ bufmgr_data = backend_module_data->init(bufmgr, &error);
+ if (!bufmgr_data) {
+ TBM_ERR("Fail to init module(%s)\n", file);
+ goto err;
+ }
+
+ /* check the mandatory symbols of the backend module */
+ if (!_tbm_backend_check_bufmgr_func(bufmgr->bufmgr_func)) {
+ TBM_ERR("Fail to check the bufmgr_func symboles.");
+ goto err;
+ }
+
+ if (!_tbm_backend_check_bufmgr_bo(bufmgr->bo_func)) {
+ TBM_ERR("Fail to check the bufmgr_bo symboles.");
+ goto err;
+ }
+
+ /* get the capability */
+ bufmgr->capabilities = bufmgr->bufmgr_func->bufmgr_get_capabilities(bufmgr_data, &error);
+ if (bufmgr->capabilities == TBM_BUFMGR_CAPABILITY_NONE) {
+ TBM_ERR("The capabilities of the backend module is TBM_BUFMGR_CAPABILITY_NONE.");
+ TBM_ERR("TBM_BUFMGR_CAPABILITY_SHARE_FD is the essential capability.");
+ goto err;
+ }
+
+ if (!(bufmgr->capabilities & TBM_BUFMGR_CAPABILITY_SHARE_FD)) {
+ TBM_ERR("The capabilities of the backend module had no TBM_BUFMGR_CAPABILITY_SHARE_FD.");
+ TBM_ERR("The tbm backend has to get TBM_BUFMGR_CAPABILITY_SHARE_FD. ");
+ goto err;
+ }
+
+ bufmgr->module_data = module_data;
+ bufmgr->backend_module_data = backend_module_data;
+ bufmgr->bufmgr_data = bufmgr_data;
+
+ TBM_DBG("Success to load module(%s)\n", file);
+
+ return 1;
+
+err:
+ if (bufmgr_data)
+ bufmgr->backend_module_data->deinit(bufmgr_data);
+ if (module_data)
+ dlclose(module_data);
+
+ return 0;
}
static int
-_tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file)
+_tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
{
- char path[PATH_MAX] = {0,};
- TBMModuleData *initdata = NULL;
- void * module_data;
-
- snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file);
-
- module_data = dlopen (path, RTLD_LAZY);
- if (!module_data)
- {
- fprintf (stderr, "[libtbm:%d] "
- "failed to load module: %s(%s)\n",
- getpid(), dlerror(), file);
- return 0;
- }
-
- initdata = dlsym (module_data, "tbmModuleData");
- if (initdata)
- {
- ModuleInitProc init;
- TBMModuleVersionInfo *vers;
-
- vers = initdata->vers;
- init = initdata->init;
-
- if (vers)
- {
- if (!_check_version (vers))
- {
- dlclose (module_data);
- return 0;
- }
- }
- else
- {
- fprintf (stderr, "[libtbm:%d] "
- "Error: module does not supply version information.\n",
- getpid());
-
- dlclose (module_data);
- return 0;
- }
-
- if (init)
- {
- if(!init (bufmgr, fd))
- {
- fprintf (stderr, "[libtbm:%d] "
- "Fail to init module(%s)\n",
- getpid(), file);
- dlclose (module_data);
- return 0;
- }
- }
- else
- {
- fprintf (stderr, "[libtbm:%d] "
- "Error: module does not supply init symbol.\n", getpid());
- dlclose (module_data);
- return 0;
- }
- }
- else
- {
- fprintf (stderr, "[libtbm:%d] "
- "Error: module does not have data object.\n", getpid());
- dlclose (module_data);
- return 0;
- }
-
- bufmgr->module_data = module_data;
-
- fprintf (stderr,"[libtbm:%d] "
- "Success to load module(%s)\n", getpid(), file);
-
- return 1;
+ char path[PATH_MAX] = {0, };
+ TBMModuleVersionInfo *vers;
+ TBMModuleData *initdata;
+ ModuleInitProc init;
+ void *module_data;
+
+ snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file);
+
+ module_data = dlopen(path, RTLD_LAZY);
+ if (!module_data) {
+ TBM_ERR("failed to load module: %s(%s)\n", dlerror(), file);
+ return 0;
+ }
+
+ initdata = dlsym(module_data, "tbmModuleData");
+ if (!initdata) {
+ TBM_ERR("Error: module does not have data object.\n");
+ goto err;
+ }
+
+ vers = initdata->vers;
+ if (!vers) {
+ TBM_ERR("Error: module does not supply version information.\n");
+ goto err;
+ }
+
+ init = initdata->init;
+ if (!init) {
+ TBM_ERR("Error: module does not supply init symbol.\n");
+ goto err;
+ }
+
+ if (!_check_version(vers)) {
+ TBM_ERR("Fail to check version.\n");
+ goto err;
+ }
+
+ if (!init(bufmgr, fd)) {
+ TBM_ERR("Fail to init module(%s)\n", file);
+ goto err;
+ }
+
+ if (!bufmgr->backend || !bufmgr->backend->priv) {
+ TBM_ERR("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file);
+ goto err;
+ }
+
+ bufmgr->module_data = module_data;
+
+ TBM_DBG("Success to load module(%s)\n", file);
+
+ return 1;
+
+err:
+ dlclose(module_data);
+ return 0;
}
-static int _tbm_load_module (tbm_bufmgr bufmgr, int fd)
+static int
+_tbm_load_module(tbm_bufmgr bufmgr, int fd)
{
- struct dirent **namelist;
- const char *p = NULL;
- int n;
- int ret = 0;
-
- /* load bufmgr priv from default lib */
- ret = _tbm_bufmgr_load_module (bufmgr, fd, DEFAULT_LIB);
-
- /* load bufmgr priv from configured path */
- if (!ret)
- {
- n = scandir (BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
- if (n < 0)
- fprintf (stderr,"[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 (!strcmp (p, SUFFIX_LIB))
- {
- ret = _tbm_bufmgr_load_module (bufmgr, fd, namelist[n]->d_name);
- }
- }
- free(namelist[n]);
- }
- free(namelist);
- }
- }
-
- return ret;
+ struct dirent **namelist;
+ int ret = 0, n;
+
+ /* try to load the new backend module */
+ ret = _tbm_backend_load_module(bufmgr, DEFAULT_LIB);
+ if (ret)
+ return 1;
+
+ /* try to load the old(deprecated) backend mdoule */
+ ret = _tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB);
+ if (ret)
+ return 1;
+
+ /* load bufmgr priv from configured path */
+ n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
+ if (n < 0) {
+ TBM_ERR("no files : %s\n", BUFMGR_MODULE_DIR);
+ return 0;
+ }
+
+ while (n--) {
+ if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) {
+ const char *p = strstr(namelist[n]->d_name, SUFFIX_LIB);
+
+ if (p && !strcmp(p, SUFFIX_LIB)) {
+ ret = _tbm_backend_load_module(bufmgr, namelist[n]->d_name);
+ if (!ret)
+ ret = _tbm_bufmgr_load_module(bufmgr, fd,
+ namelist[n]->d_name);
+ }
+ }
+
+ free(namelist[n]);
+ }
+
+ free(namelist);
+
+ return ret;
}
+/* LCOV_EXCL_STOP */
-tbm_bufmgr
-tbm_bufmgr_init (int fd)
+static tbm_bufmgr
+_tbm_bufmgr_init(int fd, int server)
{
- char *env;
- tbm_bufmgr bufmgr = NULL;
-
-#ifdef DEBUG
- env = getenv("GEM_DEBUG");
- if(env)
- {
- bDebug = atoi(env);
- fprintf(stderr, "GEM_DEBUG=%s\n", env);
- }
- else
- bDebug = 0;
+#ifdef TBM_BUFMGR_INIT_TIME
+ struct timeval start_tv, end_tv;
#endif
+ char *env;
- /* initialize buffer manager */
- if (fd < 0)
- return NULL;
-
- if(gBufMgrs == NULL)
- {
- gBufMgrs = malloc(sizeof(struct list_head));
- LIST_INITHEAD(gBufMgrs);
- }
- else
- {
- LIST_FOR_EACH_ENTRY(bufmgr, gBufMgrs, link)
- {
- if(bufmgr->fd == fd)
- {
- bufmgr->ref_count++;
- fprintf (stderr, "[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n",
- getpid(), fd, bufmgr->ref_count);
- return bufmgr;
- }
- }
- bufmgr = NULL;
- }
- fprintf(stderr, "[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd);
-
- /* allocate bufmgr */
- bufmgr = calloc (1, sizeof(struct _tbm_bufmgr));
- if (!bufmgr)
- return NULL;
-
- /* load bufmgr priv from env */
- if (!_tbm_load_module(bufmgr, fd))
- {
- fprintf (stderr,"[libtbm:%d] "
- "error : Fail to load bufmgr backend\n",
- getpid());
- free (bufmgr);
- bufmgr = NULL;
- return NULL;
- }
-
- bufmgr->ref_count = 1;
- bufmgr->fd = fd;
-
- fprintf(stderr, "[libtbm:%d] create tizen bufmgr: ref_count:%d\n",
- getpid(), bufmgr->ref_count);
-
- if (pthread_mutex_init (&bufmgr->lock, NULL) != 0)
- {
- bufmgr->backend->bufmgr_deinit (bufmgr);
- free (bufmgr);
- bufmgr = NULL;
- return NULL;
- }
-
- /* intialize the tizen global status */
- if (!_tbm_bufmgr_init_state (bufmgr))
- {
- fprintf (stderr, "[libtbm:%d] "
- "error: Fail to init state\n",
- getpid());
- bufmgr->backend->bufmgr_deinit (bufmgr);
- free (bufmgr);
- bufmgr = NULL;
- return NULL;
- }
-
- /* setup the lock_type */
- env = getenv ("BUFMGR_LOCK_TYPE");
- if (env && !strcmp (env, "always"))
- bufmgr->lock_type = LOCK_TRY_ALWAYS;
- else if(env && !strcmp(env, "none"))
- bufmgr->lock_type = LOCK_TRY_NEVER;
- else
- bufmgr->lock_type = LOCK_TRY_ONCE;
- DBG ("[libtbm:%d] BUFMGR_LOCK_TYPE=%s\n", getpid(), env?env:"default:once");
-
- /* setup the map_cache */
- env = getenv ("BUFMGR_MAP_CACHE");
- if (env && !strcmp (env, "false"))
- bufmgr->use_map_cache = 0;
- else
- bufmgr->use_map_cache = 1;
- DBG ("[libtbm:%d] BUFMGR_MAP_CACHE=%s\n", getpid(), env?env:"default:true");
-
- /* intialize bo_list */
- LIST_INITHEAD (&bufmgr->bo_list);
-
- /* add bufmgr to the gBufMgrs */
- LIST_ADD(&bufmgr->link, gBufMgrs);
-
- return 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;
-
- bufmgr->ref_count--;
- if (bufmgr->ref_count > 0)
- {
- fprintf (stderr, "[libtbm:%d] "
- "tizen bufmgr destroy: bufmgr:%p, ref_cnt:%d\n",
- getpid(), bufmgr, bufmgr->ref_count);
- return;
- }
-
- /* destroy bo_list */
- if(!LIST_IS_EMPTY (&bufmgr->bo_list))
- {
- LIST_FOR_EACH_ENTRY_SAFE (bo, tmp, &bufmgr->bo_list, item_link)
- {
- fprintf (stderr, "[libtbm:%d] "
- "Un-freed bo(%p, ref:%d) \n",
- getpid(), bo, bo->ref_cnt);
- bo->ref_cnt = 1;
- tbm_bo_unref(bo);
- }
- }
-
- /* 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);
-
- fprintf (stderr, "[libtbm:%d] "
- "tizen bufmgr destroy: bufmgr:%p, ref_cnt:%d\n",
- getpid(), bufmgr, bufmgr->ref_count);
-
- dlclose (bufmgr->module_data);
-
- LIST_DEL (&bufmgr->link);
-
- free (bufmgr);
- bufmgr = NULL;
-}
+#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_DBG("TBM_DLOG=%s\n", env);
+ } else
+ bDlog = 1;
+#endif
-int
-tbm_bo_size (tbm_bo bo)
-{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
+#ifdef TRACE
+ env = getenv("TBM_TRACE");
+ if (env) {
+ trace_mask = atoi(env);
+ TBM_DBG("TBM_TRACE=%s\n", env);
+ } else
+ trace_mask = 0;
+#endif
- tbm_bufmgr bufmgr = bo->bufmgr;
- int size;
+ 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");
+ }
+
+
+ /* initialize buffer manager */
+ if (gBufMgr) {
+ gBufMgr->ref_count++;
+ TBM_DBG("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd);
+ pthread_mutex_unlock(&gLock);
+ return gBufMgr;
+ }
+
+ TBM_DBG("bufmgr init\n");
+
+ /* allocate bufmgr */
+ 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;
+ }
+
+ 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_ERR("error : Fail to load bufmgr backend\n");
+ _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
+ free(gBufMgr);
+ gBufMgr = NULL;
+ pthread_mutex_unlock(&gLock);
+ return NULL;
+
+ }
+ /* LCOV_EXCL_STOP */
+
+ gBufMgr->ref_count = 1;
+
+ TBM_INFO("create tizen bufmgr:%p ref_count:%d\n",
+ gBufMgr, gBufMgr->ref_count);
+
+ /* setup the bo_lock_type */
+ env = getenv("BUFMGR_LOCK_TYPE");
+ if (env && !strcmp(env, "always"))
+ gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS;
+ else if (env && !strcmp(env, "none"))
+ gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_NEVER;
+ else if (env && !strcmp(env, "once"))
+ gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ONCE;
+ else
+ gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS;
+
+ TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once");
+
+ /* 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_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_lock(&bufmgr->lock);
- size = bufmgr->backend->bo_size(bo);
- pthread_mutex_unlock(&bufmgr->lock);
+ pthread_mutex_unlock(&gLock);
- return size;
+ return gBufMgr;
}
-tbm_bo
-tbm_bo_ref (tbm_bo bo)
+tbm_bufmgr
+tbm_bufmgr_init(int fd)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), NULL);
-
- tbm_bufmgr bufmgr = bo->bufmgr;
+ tbm_bufmgr bufmgr;
- pthread_mutex_lock(&bufmgr->lock);
+ bufmgr = _tbm_bufmgr_init(fd, 0);
- _tbm_bo_ref (bo);
-
- pthread_mutex_unlock(&bufmgr->lock);
-
- return bo;
+ return bufmgr;
}
void
-tbm_bo_unref (tbm_bo bo)
+tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
{
- TBM_RETURN_IF_FAIL(TBM_BO_IS_VALID(bo));
-
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- pthread_mutex_lock (&bufmgr->lock);
-
- _tbm_bo_unref (bo);
-
- pthread_mutex_unlock(&bufmgr->lock);
+ 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_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_DBG("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_ERR("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)) {
+ tbm_surface_h surf = NULL, tmp;
+
+ LIST_FOR_EACH_ENTRY_SAFE(surf, tmp, &bufmgr->surf_list, item_link) {
+ TBM_ERR("Un-freed surf(%p, ref:%d)\n", surf, surf->refcnt);
+ tbm_surface_destroy(surf);
+ }
+ LIST_DELINIT(&bufmgr->surf_list);
+ }
+
+ if (bufmgr->backend_module_data) {
+ /* deinit and backend destroys the backend func and data */
+ bufmgr->backend_module_data->deinit(bufmgr->bufmgr_data);
+ bufmgr->bo_func = NULL;
+ bufmgr->bufmgr_func = NULL;
+ bufmgr->bufmgr_data = NULL;
+ bufmgr->backend_module_data = NULL;
+ } else {
+ /* destroy bufmgr priv */
+ bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
+ bufmgr->backend->priv = NULL;
+ tbm_backend_free(bufmgr->backend);
+ bufmgr->backend = NULL;
+ }
+
+ TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr);
+
+ dlclose(bufmgr->module_data);
+
+ if (bufmgr->fd > 0)
+ close(bufmgr->fd);
+
+ free(bufmgr);
+ gBufMgr = NULL;
+
+ pthread_mutex_unlock(&gLock);
+ _tbm_bufmgr_mutex_unlock();
}
-tbm_bo
-tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags)
+unsigned int
+tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BUFMGR_IS_VALID(bufmgr) && (size > 0), NULL);
-
- tbm_bo bo = NULL;
- void * bo_priv = NULL;
-
- bo = calloc (1, sizeof(struct _tbm_bo));
- if(!bo)
- return NULL;
+ unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE;
- bo->bufmgr = bufmgr;
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
- pthread_mutex_lock (&bufmgr->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);
- bo_priv = bufmgr->backend->bo_alloc (bo, size, flags);
- if (!bo_priv)
- {
- free (bo);
- pthread_mutex_unlock (&bufmgr->lock);
- return NULL;
- }
+ capabilities = bufmgr->capabilities;
- bo->ref_cnt = 1;
- bo->flags = flags;
- bo->tgl_key = INITIAL_KEY;
- bo->priv = bo_priv;
+ _tbm_bufmgr_mutex_unlock();
- /* init bo state */
- if (!_tbm_bo_init_state (bo, CACHE_OP_CREATE))
- {
- _tbm_bo_unref (bo);
- pthread_mutex_unlock (&bufmgr->lock);
- return NULL;
- }
-
- LIST_INITHEAD (&bo->user_data_list);
-
- LIST_ADD (&bo->item_link, &bufmgr->bo_list);
-
- pthread_mutex_unlock(&bufmgr->lock);
-
- return bo;
+ return capabilities;
}
-tbm_bo
-tbm_bo_import (tbm_bufmgr bufmgr, unsigned int key)
+/* LCOV_EXCL_START */
+char *
+tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
-
- tbm_bo bo = NULL;
- void * bo_priv = NULL;
-
- bo = calloc (1, sizeof(struct _tbm_bo));
- if(!bo)
- return NULL;
-
- bo->bufmgr = bufmgr;
-
- pthread_mutex_lock (&bufmgr->lock);
-
- bo_priv = bufmgr->backend->bo_import (bo, key);
- if (!bo_priv)
- {
- free (bo);
- pthread_mutex_unlock (&bufmgr->lock);
- return NULL;
- }
-
- bo->ref_cnt = 1;
- bo->tgl_key = INITIAL_KEY;
- bo->priv = bo_priv;
-
- /* init bo state */
- if (!_tbm_bo_init_state (bo, CACHE_OP_IMPORT))
- {
- _tbm_bo_unref (bo);
- pthread_mutex_unlock (&bufmgr->lock);
- return NULL;
- }
-
- LIST_INITHEAD (&bo->user_data_list);
-
- LIST_ADD (&bo->item_link, &bufmgr->bo_list);
-
- pthread_mutex_unlock (&bufmgr->lock);
-
- return bo;
+ 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;
+ long pid = 0;
+
+ 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, "\n");
+ pid = syscall(SYS_getpid);
+ _tbm_util_get_appname_from_pid(pid, app_name);
+ _tbm_util_get_appname_brief(app_name);
+ TBM_SNRPRINTF(str, len, c, "============TBM DEBUG: %s(%ld)===========================\n",
+ app_name, pid);
+
+ 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);
+
+ /* 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 surf_pid = 0;
+ int i;
+
+ surf_pid = _tbm_surface_internal_get_debug_pid(surf);
+ if (!surf_pid) {
+ /* if pid is null, set the self_pid */
+ surf_pid = syscall(SYS_getpid);;
+ }
+
+ memset(app_name, 0x0, 255 * sizeof(char));
+ if (geteuid() == 0) {
+ _tbm_util_get_appname_from_pid(surf_pid, app_name);
+ _tbm_util_get_appname_brief(app_name);
+ } else {
+ snprintf(app_name, sizeof(app_name), "%d", surf_pid);
+ }
+
+ snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s",
+ ++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++) {
+ 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_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)) {
+ 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,
+ size / 1024,
+ bo->lock_cnt,
+ bo->map_cnt,
+ bo->flags,
+ bo->surface,
+ key);
+ }
+ } 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;
}
-unsigned int
-tbm_bo_export (tbm_bo bo)
+void
+tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
-
- tbm_bufmgr bufmgr;
- int ret;
-
- bufmgr = bo->bufmgr;
-
- pthread_mutex_lock (&bufmgr->lock);
- ret = bufmgr->backend->bo_export (bo);
- pthread_mutex_unlock (&bufmgr->lock);
-
- return ret;
+ char * str;
+ str = tbm_bufmgr_debug_tbm_info_get(bufmgr);
+ if (str) {
+ TBM_DBG(" %s", str);
+ free(str);
+ }
}
-tbm_bo_handle
-tbm_bo_get_handle (tbm_bo bo, int device)
+void
+tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), (tbm_bo_handle)0);
-
- tbm_bufmgr bufmgr;
- tbm_bo_handle bo_handle;
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
- bufmgr = bo->bufmgr;
+ TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
+ TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
- pthread_mutex_lock (&bufmgr->lock);
- bo_handle = bufmgr->backend->bo_get_handle (bo, device);
- pthread_mutex_unlock (&bufmgr->lock);
+#ifdef TRACE
+ TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
+ bTrace = onoff;
+#endif
- return bo_handle;
+ _tbm_bufmgr_mutex_unlock();
}
-tbm_bo_handle
-tbm_bo_map (tbm_bo bo, int device, int opt)
+void
+tbm_bufmgr_debug_set_trace_mask(tbm_bufmgr bufmgr, tbm_bufmgr_debug_trace_mask mask, int set)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), (tbm_bo_handle)0);
-
- tbm_bufmgr bufmgr;
- tbm_bo_handle bo_handle;
-
- bufmgr = bo->bufmgr;
-
- pthread_mutex_lock (&bufmgr->lock);
-
- _tbm_bo_lock (bo);
- bo_handle = bufmgr->backend->bo_map (bo, device, opt);
-
- /* increase the ref_count */
-// _tbm_bo_ref (bo);
-
- 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_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();
+}
- return bo_handle;
+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_bo_unmap (tbm_bo bo)
+tbm_bufmgr_debug_get_ref_count(void)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
-
- tbm_bufmgr bufmgr;
- int ret;
-
- bufmgr = bo->bufmgr;
-
- pthread_mutex_lock (&bufmgr->lock);
+ int refcnt;
- ret = bufmgr->backend->bo_unmap (bo);
+ pthread_mutex_lock(&gLock);
- /* decrease the map_count */
- bo->map_cnt--;
+ _tbm_set_last_result(TBM_ERROR_NONE);
- if (bo->map_cnt == 0)
- _tbm_bo_save_state (bo);
+ refcnt = (gBufMgr) ? gBufMgr->ref_count : 0;
- _tbm_bo_unlock (bo);
+ pthread_mutex_unlock(&gLock);
- /* decrease the ref_count */
-// _tbm_bo_unref (bo);
-
- pthread_mutex_unlock (&bufmgr->lock);
-
- return ret;
+ return refcnt;
}
int
-tbm_bo_swap (tbm_bo bo1, tbm_bo bo2)
+tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo1), 0);
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo2), 0);
-
- void* temp;
- unsigned int tmp_key;
-
- if (bo1->bufmgr->backend->bo_size (bo1) != bo2->bufmgr->backend->bo_size (bo2))
- return 0;
-
- pthread_mutex_lock (&bo1->bufmgr->lock);
-
- tmp_key = bo1->tgl_key;
- bo1->tgl_key = bo2->tgl_key;
- bo2->tgl_key = tmp_key;
-
- temp = bo1->priv;
- bo1->priv = bo2->priv;
- bo2->priv = temp;
-
- pthread_mutex_unlock (&bo1->bufmgr->lock);
-
- return 1;
+ pthread_mutex_lock(&gLock);
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ if (onoff == 0) {
+ 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_ERR("path is null");
+ pthread_mutex_unlock(&gLock);
+ return 0;
+ }
+ TBM_DBG("path=%s count=%d onoff=%d\n", path, count, onoff);
+
+ if (_tbm_util_get_max_surface_size(&w, &h) == 0) {
+ TBM_ERR("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;
}
int
-tbm_bo_locked (tbm_bo bo)
+tbm_bufmgr_debug_dump_all(char *path)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
-
- tbm_bufmgr bufmgr;
+ int w, h, count = 0;
+ tbm_surface_h surface = NULL;
- bufmgr = bo->bufmgr;
+ pthread_mutex_lock(&gLock);
+ _tbm_set_last_result(TBM_ERROR_NONE);
- if (bufmgr->lock_type == LOCK_TRY_NEVER)
- return 0;
+ if (!path) {
+ TBM_ERR("path is null.\n");
+ pthread_mutex_unlock(&gLock);
+ return 0;
+ }
- pthread_mutex_lock (&bufmgr->lock);
-
- if (bo->lock_cnt > 0)
- {
- pthread_mutex_unlock (&bufmgr->lock);
- return 1;
- }
-
- pthread_mutex_unlock (&bufmgr->lock);
-
- return 0;
-}
+ TBM_DBG("path=%s\n", path);
+ count = _tbm_util_get_max_surface_size(&w, &h);
+ if (count == 0) {
+ TBM_ERR("No tbm_surface.\n");
+ pthread_mutex_unlock(&gLock);
+ return 0;
+ }
-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_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
+ scale_factor = 0;
- tbm_user_data *data;
+ LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link)
+ tbm_surface_internal_dump_buffer(surface, "dump_all");
- /* check if the data according to the key exist if so, return false.*/
- data = _user_data_lookup (&bo->user_data_list, key);
- if (data)
- {
- fprintf (stderr, "[libtbm:%d] "
- "waring: %s:%d user data already exist. key:%ld\n",
- getpid(), __FUNCTION__, __LINE__, key);
- return 0;
- }
+ tbm_surface_internal_dump_end();
- data = _user_data_create (key, data_free_func);
- if (!data)
- return 0;
+ pthread_mutex_unlock(&gLock);
- LIST_ADD (&data->item_link, &bo->user_data_list);
+ return 1;
+}
- return 1;
+/* internal function */
+tbm_bufmgr
+_tbm_bufmgr_get_bufmgr(void)
+{
+ return gBufMgr;
}
int
-tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data)
+tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), 0);
-
- tbm_user_data *old_data;
-
- if (LIST_IS_EMPTY (&bo->user_data_list))
- return 0;
-
- old_data = _user_data_lookup (&bo->user_data_list, key);
- if (!old_data)
- return 0;
+ 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_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;
+}
- if (old_data->data && old_data->free_func)
- old_data->free_func(old_data->data);
+tbm_bufmgr
+tbm_bufmgr_server_init(void)
+{
+ tbm_bufmgr bufmgr;
- old_data->data = data;
+ bufmgr = _tbm_bufmgr_init(-1, 1);
- return 1;
+ return bufmgr;
}
int
-tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data)
+tbm_bufmgr_set_bo_lock_type(tbm_bufmgr bufmgr, tbm_bufmgr_bo_lock_type bo_lock_type)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), 0);
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
- tbm_user_data* old_data;
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, 0);
- if (!data || LIST_IS_EMPTY (&bo->user_data_list))
- return 0;
+ pthread_mutex_lock(&gLock);
+ gBufMgr->bo_lock_type = bo_lock_type;
+ pthread_mutex_unlock(&gLock);
- old_data = _user_data_lookup (&bo->user_data_list, key);
- if (!old_data)
- {
- *data = NULL;
- return 0;
- }
+ TBM_INFO("The bo_lock_type of the bo is %d\n", bo_lock_type);
- *data = old_data->data;
+ _tbm_bufmgr_mutex_unlock();
- return 1;
+ return 1;
}
-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 = (void *)0;
-
- if (LIST_IS_EMPTY (&bo->user_data_list))
- return 0;
- old_data = _user_data_lookup (&bo->user_data_list, key);
- if (!old_data)
- return 0;
+int tbm_bufmgr_get_fd_limit(void)
+{
+ struct rlimit lim;
- _user_data_delete (old_data);
+ if (getrlimit(RLIMIT_NOFILE, &lim))
+ return 1024;
- return 1;
+ return (int)lim.rlim_cur;
}
-
+tbm_bufmgr tbm_bufmgr_get(void)
+{
+ return gBufMgr;
+}
+/* LCOV_EXCL_STOP */