From: Changyeon Lee Date: Tue, 15 Dec 2015 02:49:37 +0000 (+0900) Subject: Apply tizen coding rule X-Git-Tag: accepted/tizen/mobile/20151216.105500~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F07%2F54407%2F5;p=platform%2Fcore%2Fuifw%2Flibtbm.git Apply tizen coding rule Change-Id: Ief16c55ec9e02418b5a8c4a49010f42716845d2c Signed-off-by: Changyeon Lee --- diff --git a/packaging/libtbm.spec b/packaging/libtbm.spec index c8476c7..0ee44a6 100644 --- a/packaging/libtbm.spec +++ b/packaging/libtbm.spec @@ -2,7 +2,7 @@ %bcond_with wayland Name: libtbm -Version: 1.2.0 +Version: 1.2.1 Release: 1 License: MIT Summary: The library for Tizen Buffer Manager diff --git a/src/list.h b/src/list.h index e967b93..aa2f5ed 100644 --- a/src/list.h +++ b/src/list.h @@ -40,46 +40,46 @@ static void list_inithead(struct list_head *item) { - item->prev = item; - item->next = item; + item->prev = item; + item->next = item; } static inline void list_add(struct list_head *item, struct list_head *list) { - item->prev = list; - item->next = list->next; - list->next->prev = item; - list->next = item; + item->prev = list; + item->next = list->next; + list->next->prev = item; + list->next = item; } static inline void list_addtail(struct list_head *item, struct list_head *list) { - item->next = list; - item->prev = list->prev; - list->prev->next = item; - list->prev = item; + item->next = list; + item->prev = list->prev; + list->prev->next = item; + list->prev = item; } static inline void list_replace(struct list_head *from, struct list_head *to) { - to->prev = from->prev; - to->next = from->next; - from->next->prev = to; - from->prev->next = to; + to->prev = from->prev; + to->next = from->next; + from->next->prev = to; + from->prev->next = to; } static inline void list_del(struct list_head *item) { - item->prev->next = item->next; - item->next->prev = item->prev; + item->prev->next = item->next; + item->next->prev = item->prev; } static inline void list_delinit(struct list_head *item) { - item->prev->next = item->next; - item->next->prev = item->prev; - item->next = item; - item->prev = item; + item->prev->next = item->next; + item->next->prev = item->prev; + item->next = item; + item->prev = item; } #define LIST_INITHEAD(__item) list_inithead(__item) @@ -90,42 +90,42 @@ static inline void list_delinit(struct list_head *item) #define LIST_DELINIT(__item) list_delinit(__item) #define LIST_ENTRY(__type, __item, __field) \ - ((__type *)(((char *)(__item)) - offsetof(__type, __field))) + ((__type *)(((char *)(__item)) - offsetof(__type, __field))) #define LIST_IS_EMPTY(__list) \ - ((__list)->next == (__list)) + ((__list)->next == (__list)) #ifndef container_of #define container_of(ptr, sample, member) \ - (void *)((char *)(ptr) \ - - ((char *)&(sample)->member - (char *)(sample))) + (void *)((char *)(ptr) \ + - ((char *)&(sample)->member - (char *)(sample))) #endif #define LIST_FOR_EACH_ENTRY(pos, head, member) \ - for (pos = container_of((head)->next, pos, member); \ - &pos->member != (head); \ - pos = container_of(pos->member.next, pos, member)) + for (pos = container_of((head)->next, pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.next, pos, member)) #define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member) \ - for (pos = container_of((head)->next, pos, member), \ - storage = container_of(pos->member.next, pos, member); \ - &pos->member != (head); \ - pos = storage, storage = container_of(storage->member.next, storage, member)) + for (pos = container_of((head)->next, pos, member), \ + storage = container_of(pos->member.next, pos, member); \ + &pos->member != (head); \ + pos = storage, storage = container_of(storage->member.next, storage, member)) #define LIST_FOR_EACH_ENTRY_SAFE_REV(pos, storage, head, member) \ - for (pos = container_of((head)->prev, pos, member), \ + for (pos = container_of((head)->prev, pos, member), \ storage = container_of(pos->member.prev, pos, member); \ - &pos->member != (head); \ - pos = storage, storage = container_of(storage->member.prev, storage, member)) + &pos->member != (head); \ + pos = storage, storage = container_of(storage->member.prev, storage, member)) #define LIST_FOR_EACH_ENTRY_FROM(pos, start, head, member) \ - for (pos = container_of((start), pos, member); \ + for (pos = container_of((start), pos, member); \ &pos->member != (head); \ - pos = container_of(pos->member.next, pos, member)) + pos = container_of(pos->member.next, pos, member)) #define LIST_FOR_EACH_ENTRY_FROM_REV(pos, start, head, member) \ - for (pos = container_of((start), pos, member); \ - &pos->member != (head); \ - pos = container_of(pos->member.prev, pos, member)) + for (pos = container_of((start), pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.prev, pos, member)) #endif /*_U_DOUBLE_LIST_H_*/ diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c old mode 100755 new mode 100644 index a2e79dc..1b7ce7b --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -40,8 +40,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define DEBUG #ifdef DEBUG int bDebug = 0; -#define DBG(...) if(bDebug&0x1) TBM_LOG (__VA_ARGS__) -#define DBG_LOCK(...) if(bDebug&0x2) TBM_LOG (__VA_ARGS__) +#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(...) @@ -51,8 +51,8 @@ int bDebug = 0; #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)) +#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)) @@ -69,31 +69,30 @@ int bDebug = 0; #define ABI_VERS_UNSPEC 0xFFFFFFFF #define MODULE_VERSION_NUMERIC(maj, min, patch) \ - ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF)) + ((((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 + LOCK_TRY_ONCE, + LOCK_TRY_ALWAYS, + LOCK_TRY_NEVER }; enum { - DEVICE_NONE = 0, - DEVICE_CA, /* cache aware device */ - DEVICE_CO /* cache oblivious device */ + 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 ; +typedef struct { + unsigned long key; + void *data; + tbm_data_free free_func; - /* link of user_data */ - struct list_head item_link; + /* link of user_data */ + struct list_head item_link; } tbm_user_data; pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; @@ -101,1669 +100,1507 @@ tbm_bufmgr gBufMgr = NULL; static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE; -static void -_tbm_set_last_result(tbm_error_e err) +static void _tbm_set_last_result(tbm_error_e err) { tbm_last_error = err; } -static void -_tbm_util_get_appname_brief(char *brief) +static void _tbm_util_get_appname_brief(char *brief) { - char delim[] = "/"; - char *token = NULL; - char temp[255] = {0,}; - char *saveptr = NULL; + char delim[] = "/"; + char *token = NULL; + char temp[255] = {0,}; + char *saveptr = NULL; - token = strtok_r(brief, delim, &saveptr); + token = strtok_r(brief, delim, &saveptr); - while (token != NULL) { - memset(temp, 0x00, 255*sizeof(char)); - strncpy(temp, token, 254*sizeof(char)); - token = strtok_r(NULL, delim, &saveptr); - } + while (token != NULL) { + memset(temp, 0x00, 255*sizeof(char)); + strncpy(temp, token, 254*sizeof(char)); + token = strtok_r(NULL, delim, &saveptr); + } - snprintf(brief, sizeof(temp), "%s", temp); + 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; - 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); - - fp = fopen(fn_cmdline, "r"); - if(fp == 0) { - fprintf(stderr,"cannot file open /proc/%ld/cmdline", app_pid); - return; - } - - if (!fgets(cmdline, 255, fp)) { - fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid); - fclose(fp); - return; - } - fclose(fp); - - len = strlen(cmdline); - if(len < 1) - memset(cmdline, 0x00,255); - else - cmdline[len] = 0; - - snprintf(str, sizeof(cmdline), "%s", cmdline); + 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); + + fp = fopen(fn_cmdline, "r"); + if (fp == 0) { + fprintf(stderr, "cannot file open /proc/%ld/cmdline", app_pid); + return; + } + + if (!fgets(cmdline, 255, fp)) { + fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid); + fclose(fp); + return; + } + fclose(fp); + + len = strlen(cmdline); + if (len < 1) + memset(cmdline, 0x00, 255); + else + cmdline[len] = 0; + + snprintf(str, sizeof(cmdline), "%s", cmdline); } -static inline int -_tgl_init (int fd, unsigned int key) +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; + 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) +static inline int _tgl_destroy(int fd, unsigned int 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; - } - - return 1; + 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; + } + + return 1; } -static inline int -_tgl_lock (int fd, unsigned int key) +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; + 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) +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; + 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) +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; + 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) +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; + 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; } -static tbm_user_data * -_user_data_lookup (struct list_head *user_data_list, unsigned long key) +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; + 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; } -static tbm_user_data * -_user_data_create (unsigned long key, tbm_data_free data_free_func) +static 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 = NULL; - user_data = calloc (1, sizeof (tbm_user_data)); - if (!user_data) - return NULL; + 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; + user_data->key = key; + user_data->free_func = data_free_func; + user_data->data = (void *)0; - return user_data; + return user_data; } -static void -_user_data_delete (tbm_user_data *user_data) +static void _user_data_delete(tbm_user_data * user_data) { - if (user_data->data && user_data->free_func) - user_data->free_func(user_data->data); + if (user_data->data && user_data->free_func) + user_data->free_func(user_data->data); - LIST_DEL (&user_data->item_link); + LIST_DEL(&user_data->item_link); - free(user_data); + free(user_data); } -static int -_bo_lock (tbm_bo bo, int device, int opt) +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; + 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) +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); - } + 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) +static int _tbm_bo_init_state(tbm_bo bo, int opt) { - tbm_bufmgr bufmgr = bo->bufmgr; - tbm_bo_cache_state cache_state; + 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->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); + 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); + RETURN_VAL_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); - cache_state.val = 0; - switch (opt) - { - case CACHE_OP_CREATE: /*Create*/ + cache_state.val = 0; + switch (opt) { + case CACHE_OP_CREATE: /*Create */ - _tgl_init (bufmgr->lock_fd, bo->tgl_key); + _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; + 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_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; - } + _tgl_init(bufmgr->lock_fd, bo->tgl_key); + break; + default: + break; + } - return 1; + return 1; } -static void -_tbm_bo_destroy_state (tbm_bo bo) +static void _tbm_bo_destroy_state(tbm_bo bo) { - tbm_bufmgr bufmgr = bo->bufmgr; + tbm_bufmgr bufmgr = bo->bufmgr; - RETURN_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags)); + RETURN_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags)); - _tgl_destroy (bufmgr->lock_fd, bo->tgl_key); + _tgl_destroy(bufmgr->lock_fd, bo->tgl_key); } -static int -_tbm_bo_set_state (tbm_bo bo, int device, int opt) +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 (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); - - 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 - { - 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; + 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); + + 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 { + 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; } -static void -_tbm_bo_save_state (tbm_bo bo) +static void _tbm_bo_save_state(tbm_bo bo) { - tbm_bufmgr bufmgr = bo->bufmgr; - unsigned short cntFlush = 0; + tbm_bufmgr bufmgr = bo->bufmgr; + unsigned short cntFlush = 0; - RETURN_CHECK_FLAG (TBM_CACHE_CTRL_BACKEND_VALID(bufmgr->backend->flags)); + 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); + /* 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); + /* save global cache flush count */ + bo->cache_state.data.cntFlush = cntFlush; + _tgl_set_data(bufmgr->lock_fd, bo->tgl_key, bo->cache_state.val); } - -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; - - if (!bo) - return 0; - - bufmgr = bo->bufmgr; - - /* do not try to lock the bo */ - if (bufmgr->lock_type == LOCK_TRY_NEVER) - 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); - } - - old = bo->lock_cnt; - if (bufmgr->lock_type == LOCK_TRY_ONCE) - { - if (bo->lock_cnt == 0) - { - pthread_mutex_unlock (&bufmgr->lock); - ret = _bo_lock (bo, device, opt); - pthread_mutex_lock (&bufmgr->lock); - if (ret) - bo->lock_cnt++; - } - else - ret = 1; - } - else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) - { - pthread_mutex_unlock (&bufmgr->lock); - ret = _bo_lock (bo, device, opt); - pthread_mutex_lock (&bufmgr->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); - - DBG_LOCK ("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(), - bo, bo->tgl_key, old, bo->lock_cnt); - - return ret; + tbm_bufmgr bufmgr = NULL; + int old; + int ret = 0; + + if (!bo) + return 0; + + bufmgr = bo->bufmgr; + + /* do not try to lock the bo */ + if (bufmgr->lock_type == LOCK_TRY_NEVER) + 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); + } + + old = bo->lock_cnt; + if (bufmgr->lock_type == LOCK_TRY_ONCE) { + if (bo->lock_cnt == 0) { + pthread_mutex_unlock(&bufmgr->lock); + ret = _bo_lock(bo, device, opt); + pthread_mutex_lock(&bufmgr->lock); + if (ret) + bo->lock_cnt++; + } else + ret = 1; + } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) { + pthread_mutex_unlock(&bufmgr->lock); + ret = _bo_lock(bo, device, opt); + pthread_mutex_lock(&bufmgr->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); + } + + DBG_LOCK("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(), + bo, bo->tgl_key, 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; - - int old; - - if (!bo) - return; - - bufmgr = bo->bufmgr; - - /* do not try to unlock the bo */ - if (bufmgr->lock_type == LOCK_TRY_NEVER) - return; - - old = bo->lock_cnt; - if (bufmgr->lock_type == 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) - { - 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); - - 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_bufmgr bufmgr = NULL; + + int old; + + if (!bo) + return; + + bufmgr = bo->bufmgr; + + /* do not try to unlock the bo */ + if (bufmgr->lock_type == LOCK_TRY_NEVER) + return; + + old = bo->lock_cnt; + if (bufmgr->lock_type == 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) { + 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); + } + + 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); } -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, tmp = NULL;; - if( bo == NULL ) - return 0; + if (bo == NULL) + 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) - { + 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; + } + return 0; } -static void -_tbm_bo_ref (tbm_bo bo) +static void _tbm_bo_ref(tbm_bo bo) { - bo->ref_cnt++; + bo->ref_cnt++; } -static void -_tbm_bo_unref (tbm_bo bo) +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; - - LIST_DEL (&bo->item_link); - free(bo); - bo = NULL; - } + 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; + + LIST_DEL(&bo->item_link); + free(bo); + bo = NULL; + } } -static int -_tbm_bufmgr_init_state (tbm_bufmgr bufmgr) +static int _tbm_bufmgr_init_state(tbm_bufmgr bufmgr) { - RETURN_VAL_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); - - bufmgr->lock_fd = open (tgl_devfile, O_RDWR); - - if(bufmgr->lock_fd < 0) - { - bufmgr->lock_fd = open (tgl_devfile1, O_RDWR); - if(bufmgr->lock_fd < 0) - { - - TBM_LOG ("[libtbm:%d] " - "error: Fail to open global_lock:%s\n", - getpid(), tgl_devfile); - return 0; - } - } - - if (!_tgl_init(bufmgr->lock_fd, GLOBAL_KEY)) - { - TBM_LOG ("[libtbm:%d] " - "error: Fail to initialize the tgl\n", - getpid()); - return 0; - } - - return 1; + RETURN_VAL_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); + + bufmgr->lock_fd = open(tgl_devfile, O_RDWR); + + if (bufmgr->lock_fd < 0) { + bufmgr->lock_fd = open(tgl_devfile1, O_RDWR); + if (bufmgr->lock_fd < 0) { + + TBM_LOG("[libtbm:%d] " + "error: Fail to open global_lock:%s\n", + getpid(), tgl_devfile); + return 0; + } + } + + if (!_tgl_init(bufmgr->lock_fd, GLOBAL_KEY)) { + TBM_LOG("[libtbm:%d] " + "error: Fail to initialize the tgl\n", + getpid()); + return 0; + } + + return 1; } -static void -_tbm_bufmgr_destroy_state (tbm_bufmgr bufmgr) +static void _tbm_bufmgr_destroy_state(tbm_bufmgr bufmgr) { - RETURN_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags)); + RETURN_CHECK_FLAG(TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags)); - close (bufmgr->lock_fd); + close(bufmgr->lock_fd); } -static int -_check_version (TBMModuleVersionInfo *data) +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); - - 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) - { - TBM_LOG ("[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) - { - TBM_LOG ("[libtbm:%d] " - "TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n", - getpid(), abimin, vermin); - return 0; - } - return 1; + 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); + + 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) { + TBM_LOG("[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) { + TBM_LOG("[libtbm:%d] " + "TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n", + getpid(), 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; - 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); - 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 - { - TBM_LOG ("[libtbm:%d] " - "Error: module does not supply version information.\n", - getpid()); - - dlclose (module_data); - return 0; - } - - if (init) - { - if(!init (bufmgr, fd)) - { - TBM_LOG ("[libtbm:%d] " - "Fail to init module(%s)\n", - getpid(), file); - dlclose (module_data); - return 0; - } - - 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; - } - - bufmgr->module_data = module_data; - - DBG ("[libtbm:%d] " - "Success to load module(%s)\n", getpid(), file); - - return 1; + 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) { + TBM_LOG("[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 { + TBM_LOG("[libtbm:%d] " + "Error: module does not supply version information.\n", + getpid()); + + dlclose(module_data); + return 0; + } + + if (init) { + if (!init(bufmgr, fd)) { + TBM_LOG("[libtbm:%d] " + "Fail to init module(%s)\n", + getpid(), file); + dlclose(module_data); + return 0; + } + + 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; + } + + bufmgr->module_data = module_data; + + DBG("[libtbm:%d] " + "Success to load module(%s)\n", + getpid(), file); + + return 1; } -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) - 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); - } - } - - return ret; + 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) { + 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); + } + } + + return ret; } -tbm_bufmgr -tbm_bufmgr_init (int fd) +tbm_bufmgr tbm_bufmgr_init(int fd) { - char *env; - int fd_flag = 0; - int backend_flag = 0; + char *env; + int fd_flag = 0; + int backend_flag = 0; - pthread_mutex_lock (&gLock); + pthread_mutex_lock(&gLock); #ifdef DEBUG - env = getenv("GEM_DEBUG"); - if(env) - { - bDebug = atoi(env); - TBM_LOG ("GEM_DEBUG=%s\n", env); - } - else - bDebug = 0; + env = getenv("GEM_DEBUG"); + if (env) { + bDebug = atoi(env); + TBM_LOG("GEM_DEBUG=%s\n", env); + } else + bDebug = 0; #endif - /* 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); - pthread_mutex_unlock (&gLock); - return gBufMgr; - } - - if (fd < 0) - { + /* 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); + pthread_mutex_unlock(&gLock); + return gBufMgr; + } + + if (fd < 0) { #ifdef HAVE_X11 - fd = tbm_bufmgr_get_drm_fd_x11(); + fd = tbm_bufmgr_get_drm_fd_x11(); #elif HAVE_WAYLAND - fd = tbm_bufmgr_get_drm_fd_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); - - /* 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); - - 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); - } - - /* 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); - 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"); - } - - 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; - } - - /* 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; - } - - /* setup the lock_type */ - env = getenv ("BUFMGR_LOCK_TYPE"); - if (env && !strcmp (env, "always")) - gBufMgr->lock_type = LOCK_TRY_ALWAYS; - else if(env && !strcmp(env, "none")) - gBufMgr->lock_type = LOCK_TRY_NEVER; - else if(env && !strcmp(env, "once")) - gBufMgr->lock_type = LOCK_TRY_ONCE; - else - gBufMgr->lock_type = LOCK_TRY_ALWAYS; - - 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")) - gBufMgr->use_map_cache = 0; - else - gBufMgr->use_map_cache = 1; - DBG ("[libtbm:%d] BUFMGR_MAP_CACHE=%s\n", getpid(), env?env:"default:true"); - - /* intialize bo_list */ - LIST_INITHEAD (&gBufMgr->bo_list); - - /* intialize surf_list */ - LIST_INITHEAD (&gBufMgr->surf_list); - - pthread_mutex_unlock (&gLock); - return gBufMgr; + 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); + + /* 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); + + 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); + } + + /* 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); + 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"); + } + + 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; + } + + /* 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; + } + + /* setup the lock_type */ + env = getenv("BUFMGR_LOCK_TYPE"); + if (env && !strcmp(env, "always")) + gBufMgr->lock_type = LOCK_TRY_ALWAYS; + else if (env && !strcmp(env, "none")) + gBufMgr->lock_type = LOCK_TRY_NEVER; + else if (env && !strcmp(env, "once")) + gBufMgr->lock_type = LOCK_TRY_ONCE; + else + gBufMgr->lock_type = LOCK_TRY_ALWAYS; + + 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")) + gBufMgr->use_map_cache = 0; + else + gBufMgr->use_map_cache = 1; + DBG("[libtbm:%d] BUFMGR_MAP_CACHE=%s\n", + getpid(), env ? env : "default:true"); + + /* intialize bo_list */ + LIST_INITHEAD(&gBufMgr->bo_list); + + /* intialize surf_list */ + LIST_INITHEAD(&gBufMgr->surf_list); + + 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; - - pthread_mutex_lock (&gLock); - - 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); - pthread_mutex_unlock (&gLock); - return; - } - - /* destroy bo_list */ - if(!LIST_IS_EMPTY (&bufmgr->bo_list)) - { - 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); - } - } - - /* 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_destroy(surf); - } - } - - /* 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); - - dlclose (bufmgr->module_data); - - close(bufmgr->fd); - - free (bufmgr); - bufmgr = NULL; - gBufMgr = NULL; - - pthread_mutex_unlock (&gLock); + 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; + + pthread_mutex_lock(&gLock); + + 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); + pthread_mutex_unlock(&gLock); + return; + } + + /* destroy bo_list */ + if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { + 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); + } + } + + /* 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_destroy(surf); + } + } + + /* 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); + + dlclose(bufmgr->module_data); + + close(bufmgr->fd); + + free(bufmgr); + bufmgr = NULL; + gBufMgr = NULL; + + pthread_mutex_unlock(&gLock); } -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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_bufmgr bufmgr = bo->bufmgr; - int size; + tbm_bufmgr bufmgr = bo->bufmgr; + int size; - pthread_mutex_lock(&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); - size = bufmgr->backend->bo_size(bo); + size = bufmgr->backend->bo_size(bo); - pthread_mutex_unlock(&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); - return size; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL); - tbm_bufmgr bufmgr = bo->bufmgr; + tbm_bufmgr bufmgr = bo->bufmgr; - pthread_mutex_lock(&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); - _tbm_bo_ref (bo); + _tbm_bo_ref(bo); - pthread_mutex_unlock(&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); - return bo; + 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_RETURN_IF_FAIL(_tbm_bo_is_valid(bo)); - tbm_bufmgr bufmgr = bo->bufmgr; + tbm_bufmgr bufmgr = bo->bufmgr; - pthread_mutex_lock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); - _tbm_bo_unref (bo); + _tbm_bo_unref(bo); - pthread_mutex_unlock(&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); } -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); - - tbm_bo bo = NULL; - void * bo_priv = NULL; + TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr) && (size > 0), NULL); - bo = calloc (1, sizeof(struct _tbm_bo)); - if(!bo) - { - _tbm_set_last_result (TBM_BO_ERROR_HEAP_ALLOC_FAILED); - return NULL; - } + tbm_bo bo = NULL; + void *bo_priv = NULL; - bo->bufmgr = bufmgr; + bo = calloc(1, sizeof(struct _tbm_bo)); + if (!bo) { + _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED); + return NULL; + } - pthread_mutex_lock (&bufmgr->lock); + bo->bufmgr = bufmgr; - bo_priv = bufmgr->backend->bo_alloc (bo, size, flags); - if (!bo_priv) - { - _tbm_set_last_result (TBM_BO_ERROR_BO_ALLOC_FAILED); - free (bo); - pthread_mutex_unlock (&bufmgr->lock); - return NULL; - } + pthread_mutex_lock(&bufmgr->lock); - bo->ref_cnt = 1; - bo->flags = flags; - bo->tgl_key = INITIAL_KEY; - bo->priv = bo_priv; - bo->default_handle.u32 = 0; + bo_priv = bufmgr->backend->bo_alloc(bo, size, flags); + if (!bo_priv) { + _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED); + free(bo); + pthread_mutex_unlock(&bufmgr->lock); + return NULL; + } - /* 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; - } + 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; + } - LIST_INITHEAD (&bo->user_data_list); + LIST_INITHEAD(&bo->user_data_list); - LIST_ADD (&bo->item_link, &bufmgr->bo_list); + LIST_ADD(&bo->item_link, &bufmgr->bo_list); - pthread_mutex_unlock(&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); - return bo; + 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); - - tbm_bo bo = NULL; - tbm_bo bo2 = NULL; - tbm_bo tmp = NULL; - void * bo_priv = NULL; - - pthread_mutex_lock (&bufmgr->lock); - - /* 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; - } - } - } - - bo = calloc (1, sizeof(struct _tbm_bo)); - if(!bo) - { - pthread_mutex_unlock (&bufmgr->lock); - return NULL; - } - - bo->bufmgr = bufmgr; - - bo_priv = bufmgr->backend->bo_import (bo, key); - if (!bo_priv) - { - _tbm_set_last_result (TBM_BO_ERROR_IMPORT_FAILED); - free (bo); - pthread_mutex_unlock (&bufmgr->lock); - return NULL; - } - - 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; - } - - LIST_INITHEAD (&bo->user_data_list); - - LIST_ADD (&bo->item_link, &bufmgr->bo_list); - - pthread_mutex_unlock (&bufmgr->lock); - - return bo; + 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; + + pthread_mutex_lock(&bufmgr->lock); + + /* 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; + } + } + } + + bo = calloc(1, sizeof(struct _tbm_bo)); + if (!bo) { + pthread_mutex_unlock(&bufmgr->lock); + return NULL; + } + + bo->bufmgr = bufmgr; + + bo_priv = bufmgr->backend->bo_import(bo, key); + if (!bo_priv) { + _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED); + free(bo); + pthread_mutex_unlock(&bufmgr->lock); + return NULL; + } + + 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; + } + + LIST_INITHEAD(&bo->user_data_list); + + LIST_ADD(&bo->item_link, &bufmgr->bo_list); + + pthread_mutex_unlock(&bufmgr->lock); + + 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; - - pthread_mutex_lock (&bufmgr->lock); - - default_handle = bufmgr->backend->fd_to_handle (bufmgr, fd, TBM_DEVICE_DEFAULT); - - /* 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; - } - } - } - - bo = calloc (1, sizeof(struct _tbm_bo)); - if(!bo) - { - pthread_mutex_unlock (&bufmgr->lock); - return NULL; - } - - bo->bufmgr = bufmgr; - - bo_priv = bufmgr->backend->bo_import_fd(bo, fd); - if (!bo_priv) - { - _tbm_set_last_result (TBM_BO_ERROR_IMPORT_FD_FAILED); - free (bo); - pthread_mutex_unlock (&bufmgr->lock); - return NULL; - } - - 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; - } - - LIST_INITHEAD (&bo->user_data_list); - - LIST_ADD (&bo->item_link, &bufmgr->bo_list); - - pthread_mutex_unlock (&bufmgr->lock); - - return bo; + 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; + + pthread_mutex_lock(&bufmgr->lock); + + default_handle = bufmgr->backend->fd_to_handle(bufmgr, fd, TBM_DEVICE_DEFAULT); + + /* 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; + } + } + } + + bo = calloc(1, sizeof(struct _tbm_bo)); + if (!bo) { + pthread_mutex_unlock(&bufmgr->lock); + return NULL; + } + + bo->bufmgr = bufmgr; + + bo_priv = bufmgr->backend->bo_import_fd(bo, fd); + if (!bo_priv) { + _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED); + free(bo); + pthread_mutex_unlock(&bufmgr->lock); + return NULL; + } + + 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; + } + + LIST_INITHEAD(&bo->user_data_list); + + LIST_ADD(&bo->item_link, &bufmgr->bo_list); + + pthread_mutex_unlock(&bufmgr->lock); + + return bo; } -unsigned int -tbm_bo_export (tbm_bo bo) +unsigned int tbm_bo_export(tbm_bo bo) { - TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0); + TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_bufmgr bufmgr; - int ret; + tbm_bufmgr bufmgr; + int ret; - bufmgr = bo->bufmgr; + bufmgr = bo->bufmgr; - pthread_mutex_lock (&bufmgr->lock); - ret = bufmgr->backend->bo_export (bo); - if (!ret) - { - _tbm_set_last_result (TBM_BO_ERROR_EXPORT_FAILED); - pthread_mutex_unlock (&bufmgr->lock); - return ret; - } - pthread_mutex_unlock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); + ret = bufmgr->backend->bo_export(bo); + if (!ret) { + _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED); + pthread_mutex_unlock(&bufmgr->lock); + return ret; + } + pthread_mutex_unlock(&bufmgr->lock); - return ret; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1); - tbm_bufmgr bufmgr; - int ret; + tbm_bufmgr bufmgr; + int ret; - bufmgr = bo->bufmgr; + bufmgr = bo->bufmgr; - pthread_mutex_lock (&bufmgr->lock); - ret = bufmgr->backend->bo_export_fd (bo); - if (ret < 0) - { - _tbm_set_last_result (TBM_BO_ERROR_EXPORT_FD_FAILED); - pthread_mutex_unlock (&bufmgr->lock); - return ret; - } - pthread_mutex_unlock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); + ret = bufmgr->backend->bo_export_fd(bo); + if (ret < 0) { + _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED); + pthread_mutex_unlock(&bufmgr->lock); + return ret; + } + pthread_mutex_unlock(&bufmgr->lock); - return ret; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) 0); - tbm_bufmgr bufmgr; - tbm_bo_handle bo_handle; + tbm_bufmgr bufmgr; + tbm_bo_handle bo_handle; - bufmgr = bo->bufmgr; + bufmgr = bo->bufmgr; - pthread_mutex_lock (&bufmgr->lock); - bo_handle = bufmgr->backend->bo_get_handle (bo, device); - if (bo_handle.ptr == NULL) - { - _tbm_set_last_result (TBM_BO_ERROR_GET_HANDLE_FAILED); - pthread_mutex_unlock (&bufmgr->lock); - return (tbm_bo_handle)NULL; - } - pthread_mutex_unlock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); + bo_handle = bufmgr->backend->bo_get_handle(bo, device); + if (bo_handle.ptr == NULL) { + _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED); + pthread_mutex_unlock(&bufmgr->lock); + return (tbm_bo_handle) NULL; + } + pthread_mutex_unlock(&bufmgr->lock); - return bo_handle; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) 0); - tbm_bufmgr bufmgr; - tbm_bo_handle bo_handle; + tbm_bufmgr bufmgr; + tbm_bo_handle bo_handle; - bufmgr = bo->bufmgr; + bufmgr = bo->bufmgr; - pthread_mutex_lock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); - bo_handle = bufmgr->backend->bo_get_handle (bo, device); + bo_handle = bufmgr->backend->bo_get_handle(bo, device); - 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); - return (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); + return (tbm_bo_handle) NULL; + } - bo_handle = bufmgr->backend->bo_map (bo, device, opt); - if (bo_handle.ptr == NULL) - { - _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); + bo_handle = bufmgr->backend->bo_map(bo, device, opt); + if (bo_handle.ptr == NULL) { + _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_bo_unlock(bo); - pthread_mutex_unlock (&bufmgr->lock); - return (tbm_bo_handle)NULL; - } + _tbm_bo_unlock(bo); + pthread_mutex_unlock(&bufmgr->lock); + return (tbm_bo_handle) NULL; + } - if (bufmgr->use_map_cache == 1 && bo->map_cnt == 0) - _tbm_bo_set_state (bo, device, opt); + if (bufmgr->use_map_cache == 1 && bo->map_cnt == 0) + _tbm_bo_set_state(bo, device, opt); - /* increase the map_count */ - bo->map_cnt++; + /* increase the map_count */ + bo->map_cnt++; - pthread_mutex_unlock (&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); - return bo_handle; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_bufmgr bufmgr; - int ret; + tbm_bufmgr bufmgr; + int ret; - bufmgr = bo->bufmgr; + bufmgr = bo->bufmgr; - pthread_mutex_lock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); - ret = bufmgr->backend->bo_unmap (bo); - if (!ret) - { + ret = bufmgr->backend->bo_unmap(bo); + if (!ret) { - _tbm_set_last_result (TBM_BO_ERROR_UNMAP_FAILED); - pthread_mutex_unlock (&bufmgr->lock); - return ret; - } + _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED); + pthread_mutex_unlock(&bufmgr->lock); + return ret; + } - /* decrease the map_count */ - bo->map_cnt--; + /* decrease the map_count */ + bo->map_cnt--; - if (bo->map_cnt == 0) - _tbm_bo_save_state (bo); + if (bo->map_cnt == 0) + _tbm_bo_save_state(bo); - _tbm_bo_unlock (bo); + _tbm_bo_unlock(bo); - pthread_mutex_unlock (&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); - return ret; + 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); - - void* temp; - unsigned int tmp_key; - tbm_bo_handle tmp_defualt_handle; + TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0); + TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0); - pthread_mutex_lock (&bo1->bufmgr->lock); + void *temp; + unsigned int tmp_key; + tbm_bo_handle tmp_defualt_handle; - if (bo1->bufmgr->backend->bo_size (bo1) != bo2->bufmgr->backend->bo_size (bo2)) - { - _tbm_set_last_result (TBM_BO_ERROR_SWAP_FAILED); - pthread_mutex_unlock (&bo1->bufmgr->lock); - return 0; - } + pthread_mutex_lock(&bo1->bufmgr->lock); + if (bo1->bufmgr->backend->bo_size(bo1) != bo2->bufmgr->backend->bo_size(bo2)) { + _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED); + pthread_mutex_unlock(&bo1->bufmgr->lock); + return 0; + } - tmp_key = bo1->tgl_key; - bo1->tgl_key = bo2->tgl_key; - bo2->tgl_key = tmp_key; + 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; + tmp_defualt_handle = bo1->default_handle; + bo1->default_handle = bo2->default_handle; + bo2->default_handle = tmp_defualt_handle; - temp = bo1->priv; - bo1->priv = bo2->priv; - bo2->priv = temp; + temp = bo1->priv; + bo1->priv = bo2->priv; + bo2->priv = temp; - pthread_mutex_unlock (&bo1->bufmgr->lock); + pthread_mutex_unlock(&bo1->bufmgr->lock); - return 1; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_bufmgr bufmgr; + tbm_bufmgr bufmgr; - bufmgr = bo->bufmgr; + bufmgr = bo->bufmgr; - if (bufmgr->lock_type == LOCK_TRY_NEVER) - return 0; + if (bufmgr->lock_type == LOCK_TRY_NEVER) + return 0; - pthread_mutex_lock (&bufmgr->lock); + pthread_mutex_lock(&bufmgr->lock); - if (bo->lock_cnt > 0) - { - pthread_mutex_unlock (&bufmgr->lock); - return 1; - } + if (bo->lock_cnt > 0) { + pthread_mutex_unlock(&bufmgr->lock); + return 1; + } - pthread_mutex_unlock (&bufmgr->lock); + pthread_mutex_unlock(&bufmgr->lock); - return 0; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_user_data *data; + tbm_user_data *data; - /* check if the data according to the key exist if so, return false.*/ - data = _user_data_lookup (&bo->user_data_list, key); - if (data) - { - TBM_LOG ("[libtbm:%d] " - "waring: %s:%d user data already exist. key:%ld\n", - getpid(), __FUNCTION__, __LINE__, key); - return 0; - } + /* check if the data according to the key exist if so, return false. */ + data = _user_data_lookup(&bo->user_data_list, key); + if (data) { + TBM_LOG("[libtbm:%d] " + "waring: %s:%d user data already exist. key:%ld\n", + getpid(), __FUNCTION__, __LINE__, key); + return 0; + } - data = _user_data_create (key, data_free_func); - if (!data) - return 0; + data = _user_data_create(key, data_free_func); + if (!data) + return 0; - LIST_ADD (&data->item_link, &bo->user_data_list); + LIST_ADD(&data->item_link, &bo->user_data_list); - return 1; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_user_data *old_data; + tbm_user_data *old_data; - if (LIST_IS_EMPTY (&bo->user_data_list)) - return 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; + old_data = _user_data_lookup(&bo->user_data_list, key); + if (!old_data) + return 0; - if (old_data->data && old_data->free_func) - old_data->free_func(old_data->data); + if (old_data->data && old_data->free_func) + old_data->free_func(old_data->data); - old_data->data = data; + old_data->data = data; - return 1; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_user_data* old_data; + tbm_user_data *old_data; - if (!data || LIST_IS_EMPTY (&bo->user_data_list)) - return 0; + if (!data || LIST_IS_EMPTY(&bo->user_data_list)) + return 0; - old_data = _user_data_lookup (&bo->user_data_list, key); - if (!old_data) - { - *data = NULL; - return 0; - } + old_data = _user_data_lookup(&bo->user_data_list, key); + if (!old_data) { + *data = NULL; + return 0; + } - *data = old_data->data; + *data = old_data->data; - return 1; + 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_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - tbm_user_data *old_data = (void *)0; + tbm_user_data *old_data = (void *)0; - if (LIST_IS_EMPTY (&bo->user_data_list)) - return 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; + old_data = _user_data_lookup(&bo->user_data_list, key); + if (!old_data) + return 0; - _user_data_delete (old_data); + _user_data_delete(old_data); - return 1; + return 1; } -tbm_error_e -tbm_get_last_error (void) +tbm_error_e tbm_get_last_error(void) { - return tbm_last_error; + return tbm_last_error; } -unsigned int -tbm_bufmgr_get_capability (tbm_bufmgr bufmgr) +unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr) { - TBM_RETURN_VAL_IF_FAIL (TBM_BUFMGR_IS_VALID(bufmgr), 0); + TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), 0); - unsigned int capability = TBM_BUFMGR_CAPABILITY_NONE; + unsigned int capability = TBM_BUFMGR_CAPABILITY_NONE; - if (bufmgr->backend->bo_import && bufmgr->backend->bo_export) - capability |= TBM_BUFMGR_CAPABILITY_SHARE_KEY; + if (bufmgr->backend->bo_import && bufmgr->backend->bo_export) + capability |= TBM_BUFMGR_CAPABILITY_SHARE_KEY; - if (bufmgr->backend->bo_import_fd && bufmgr->backend->bo_export_fd) - capability |= TBM_BUFMGR_CAPABILITY_SHARE_FD; + if (bufmgr->backend->bo_import_fd && bufmgr->backend->bo_export_fd) + capability |= TBM_BUFMGR_CAPABILITY_SHARE_FD; - return capability; + return capability; } -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); + TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); - return bo->flags; + return bo->flags; } -void -tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) +void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr) { TBM_RETURN_IF_FAIL(bufmgr != NULL); - tbm_bo bo = NULL, tmp_bo = NULL; + tbm_bo bo = NULL, tmp_bo = NULL; int bo_cnt = 0; - tbm_surface_h surf = NULL, tmp_surf = NULL; + tbm_surface_h surf = NULL, tmp_surf = NULL; int surf_cnt = 0; - int i; + int i; char app_name[255] = {0,}; unsigned int pid = 0; - pthread_mutex_lock (&gLock); + pthread_mutex_lock(&gLock); _tbm_util_get_appname_from_pid(getpid(), app_name); _tbm_util_get_appname_brief(app_name); @@ -1773,10 +1610,8 @@ tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) 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) - { + if (!LIST_IS_EMPTY(&bufmgr->surf_list)) { + LIST_FOR_EACH_ENTRY_SAFE(surf, tmp_surf, &bufmgr->surf_list, item_link) { pid = _tbm_surface_internal_get_debug_pid(surf); if (!pid) { /* if pid is null, set the self_pid */ @@ -1787,83 +1622,76 @@ tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) _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); - 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); - } + ++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); + + 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); + } memset(app_name, 0x0, 255*sizeof(char)); } - } - else - { + } else { TBM_DEBUG("no tbm_surfaces.\n"); } TBM_DEBUG("\n"); TBM_DEBUG("[tbm_bo information]\n"); TBM_DEBUG("no bo refcnt size lock_cnt map_cnt cache_state flags surface\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) - { + 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); + ++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); } - } - else - { + } else { TBM_DEBUG("no tbm_bos.\n"); } TBM_DEBUG("\n"); TBM_DEBUG("===============================================================\n"); - pthread_mutex_unlock (&gLock); + pthread_mutex_unlock(&gLock); } -void -tbm_bufmgr_debug_trace (tbm_bufmgr bufmgr, int onoff) +void tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff) { TBM_LOG("bufmgr=%p onoff=%d\n", bufmgr, onoff); TBM_LOG("Not implemented yet.\n"); } /* internal function */ -int -_tbm_bo_set_surface (tbm_bo bo, tbm_surface_h surface) +int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0); + TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0); bo->surface = surface; return 1; } - diff --git a/src/tbm_bufmgr.h b/src/tbm_bufmgr.h index 2d364f0..9a32481 100644 --- a/src/tbm_bufmgr.h +++ b/src/tbm_bufmgr.h @@ -49,7 +49,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * @brief Definition for the tizen buffer manager * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef struct _tbm_bufmgr * tbm_bufmgr; +typedef struct _tbm_bufmgr *tbm_bufmgr; /** * @brief Definition for the tizen buffer object @@ -67,7 +67,6 @@ typedef uint32_t tbm_key; */ typedef int32_t tbm_fd; - /* TBM_DEVICE_TYPE */ /** @@ -129,63 +128,58 @@ typedef int32_t tbm_fd; * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef union _tbm_bo_handle -{ - void *ptr; - int32_t s32; - uint32_t u32; - int64_t s64; - uint64_t u64; +typedef union _tbm_bo_handle { + void *ptr; + int32_t s32; + uint32_t u32; + int64_t s64; + uint64_t u64; } tbm_bo_handle; /** * @brief Enumeration of bo memory type * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -enum TBM_BO_FLAGS -{ - TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */ - TBM_BO_SCANOUT = (1<<0), /**< scanout memory */ - TBM_BO_NONCACHABLE = (1<<1), /**< non-cachable memory */ - TBM_BO_WC = (1<<2), /**< write-combine memory */ - TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */ +enum TBM_BO_FLAGS { + TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */ + TBM_BO_SCANOUT = (1 << 0), /**< scanout memory */ + TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory */ + TBM_BO_WC = (1 << 2), /**< write-combine memory */ + TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */ }; - /** * @brief Enumeration for tbm error type. * @since_tizen 2.4 */ -typedef enum -{ - TBM_ERROR_NONE = 0, /**< Successful */ - TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE|0x0101, /**< failed to get fd failed */ - TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE|0x0102, /**< failed to allocate the heap memory */ - TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE|0x0103, /**< failed to load module*/ - TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE|0x0104, /**< failed to initialize the pthread */ - TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE|0x0105, /**< failed to allocate tbm_bo */ - TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE|0x0106, /**< failed to initialize the state of tbm_bo */ - TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE|0x0107, /**< failed to import the handle of tbm_bo */ - TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE|0x0108, /**< failed to import fd of tbm_bo */ - TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE|0x0109, /**< failed to export the handle of the tbm_bo */ - TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE|0x01010, /**< failed to export fd of tbm_bo */ - TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE|0x0111, /**< failed to get the tbm_bo_handle */ - TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE|0x0112, /**< failed to lock the tbm_bo */ - TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE|0x0113, /**< failed to map the tbm_bo to get the tbm_bo_handle */ - TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE|0x0114, /**< failed to unmap the tbm_bo */ - TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE|0x0115, /**< failed to swap the tbm_bos */ - TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE|0x0116, /**< failed to duplicate fd */ +typedef enum { + TBM_ERROR_NONE = 0, /**< Successful */ + TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE | 0x0101, /**< failed to get fd failed */ + TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE | 0x0102, /**< failed to allocate the heap memory */ + TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE | 0x0103,/**< failed to load module*/ + TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE | 0x0104,/**< failed to initialize the pthread */ + TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE | 0x0105, /**< failed to allocate tbm_bo */ + TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE | 0x0106, /**< failed to initialize the state of tbm_bo */ + TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE | 0x0107, /**< failed to import the handle of tbm_bo */ + TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE | 0x0108, /**< failed to import fd of tbm_bo */ + TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE | 0x0109, /**< failed to export the handle of the tbm_bo */ + TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE | 0x01010, /**< failed to export fd of tbm_bo */ + TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE | 0x0111, /**< failed to get the tbm_bo_handle */ + TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE | 0x0112, /**< failed to lock the tbm_bo */ + TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE | 0x0113, /**< failed to map the tbm_bo to get the tbm_bo_handle */ + TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE | 0x0114, /**< failed to unmap the tbm_bo */ + TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE | 0x0115, /**< failed to swap the tbm_bos */ + TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE | 0x0116, /**< failed to duplicate fd */ } tbm_error_e; /** * @brief Enumeration of tbm buffer manager capability. * @since_tizen 2.4 */ -enum TBM_BUFMGR_CAPABILITY -{ - TBM_BUFMGR_CAPABILITY_NONE = 0, /**< Not Support capability*/ - TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1<<0), /**< Support sharing buffer by tbm key */ - TBM_BUFMGR_CAPABILITY_SHARE_FD = (1<<1), /**< Support sharing buffer by tbm fd */ +enum TBM_BUFMGR_CAPABILITY { + TBM_BUFMGR_CAPABILITY_NONE = 0, /**< Not Support capability*/ + TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0), /**< Support sharing buffer by tbm key */ + TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1), /**< Support sharing buffer by tbm fd */ }; #ifdef __cplusplus @@ -217,7 +211,6 @@ extern "C" { #include int bufmgr_fd; - setenv("BUFMGR_LOCK_TYPE", "once", 1); setenv("BUFMGR_MAP_CACHE", "true", 1); @@ -229,7 +222,7 @@ extern "C" { tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_bufmgr tbm_bufmgr_init (int fd); +tbm_bufmgr tbm_bufmgr_init(int fd); /** * @brief Deinitializes the buffer manager. @@ -255,7 +248,7 @@ tbm_bufmgr tbm_bufmgr_init (int fd); tbm_bufmgr_deinit (bufmgr); @endcode */ -void tbm_bufmgr_deinit (tbm_bufmgr bufmgr); +void tbm_bufmgr_deinit(tbm_bufmgr bufmgr); /* Functions for bo */ @@ -296,7 +289,7 @@ void tbm_bufmgr_deinit (tbm_bufmgr bufmgr); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_bo tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags); +tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags); /** * @brief Increases the reference count of bo. @@ -325,7 +318,7 @@ tbm_bo tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_bo tbm_bo_ref (tbm_bo bo); +tbm_bo tbm_bo_ref(tbm_bo bo); /** * @brief Decreases the reference count of bo @@ -350,7 +343,7 @@ tbm_bo tbm_bo_ref (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -void tbm_bo_unref (tbm_bo bo); +void tbm_bo_unref(tbm_bo bo); /** * @brief Maps the buffer object according to the device type and the option. @@ -406,7 +399,7 @@ void tbm_bo_unref (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -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); /** * @brief Unmaps the buffer object. @@ -437,7 +430,7 @@ tbm_bo_handle tbm_bo_map (tbm_bo bo, int device, int opt); tbm_bufmgr_deinit (bufmgr); @endcode */ -int tbm_bo_unmap (tbm_bo bo); +int tbm_bo_unmap(tbm_bo bo); /** * @brief Gets the tbm_bo_handle according to the device type. @@ -481,7 +474,7 @@ int tbm_bo_unmap (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device); +tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device); /** * @brief Exports the buffer object by key. @@ -516,7 +509,7 @@ tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_key tbm_bo_export (tbm_bo bo); +tbm_key tbm_bo_export(tbm_bo bo); /** * @brief Exports the buffer object by fd. @@ -552,7 +545,7 @@ tbm_key tbm_bo_export (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_fd tbm_bo_export_fd (tbm_bo bo); +tbm_fd tbm_bo_export_fd(tbm_bo bo); /** * @brief Imports the buffer object associated with the key. @@ -589,7 +582,7 @@ tbm_fd tbm_bo_export_fd (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_bo tbm_bo_import (tbm_bufmgr bufmgr, tbm_key key); +tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key); /** * @brief Imports the buffer object associated with the fd. @@ -627,7 +620,7 @@ tbm_bo tbm_bo_import (tbm_bufmgr bufmgr, tbm_key key); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_bo tbm_bo_import_fd (tbm_bufmgr bufmgr, tbm_fd fd); +tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd); /** * @brief Gets the size of a bo. @@ -654,7 +647,7 @@ tbm_bo tbm_bo_import_fd (tbm_bufmgr bufmgr, tbm_fd fd); tbm_bufmgr_deinit (bufmgr); @endcode */ -int tbm_bo_size (tbm_bo bo); +int tbm_bo_size(tbm_bo bo); /** * @brief Gets the state where the buffer object is locked. @@ -685,7 +678,7 @@ int tbm_bo_size (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -int tbm_bo_locked (tbm_bo bo); +int tbm_bo_locked(tbm_bo bo); /** * @brief Swaps the buffer object. @@ -724,8 +717,7 @@ int tbm_bo_locked (tbm_bo bo); tbm_bufmgr_deinit (bufmgr); @endcode */ -int tbm_bo_swap (tbm_bo bo1, tbm_bo bo2); - +int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2); /** * @brief Called when the user data is deleted in buffer object. @@ -736,7 +728,7 @@ int tbm_bo_swap (tbm_bo bo1, tbm_bo bo2); * @see tbm_bo_add_user_data() * @see tbm_bo_delete_user_data() */ -typedef void (*tbm_data_free)(void *user_data); +typedef void (*tbm_data_free) (void *user_data); /** * @brief Adds a user_data to the buffer object. @@ -791,7 +783,7 @@ typedef void (*tbm_data_free)(void *user_data); @endcode */ -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); /** * @brief Deletes the user_data in the buffer object. @@ -842,7 +834,7 @@ int tbm_bo_add_user_data (tbm_bo bo, unsigned long key, tbm_data_free data_fr } @endcode */ -int tbm_bo_delete_user_data (tbm_bo bo, unsigned long key); +int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key); /** * @brief Sets a user_date to the buffer object. @@ -894,7 +886,7 @@ int tbm_bo_delete_user_data (tbm_bo bo, unsigned long key); } @endcode */ -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); /** * @brief Gets a user_data from the buffer object with the key. @@ -946,7 +938,7 @@ int tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data); } @endcode */ -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); /** * @brief Gets the latest tbm_error. @@ -986,7 +978,7 @@ int tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data); tbm_bufmgr_deinit (bufmgr); @endcode */ -tbm_error_e tbm_get_last_error (void); +tbm_error_e tbm_get_last_error(void); /** * @brief Gets the tbm buffer capability. @@ -1008,7 +1000,7 @@ tbm_error_e tbm_get_last_error (void); tbm_bufmgr_deinit (bufmgr); @endcode */ -unsigned int tbm_bufmgr_get_capability (tbm_bufmgr bufmgr); +unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr); /** * @brief Gets the tbm bo flags. @@ -1036,7 +1028,7 @@ unsigned int tbm_bufmgr_get_capability (tbm_bufmgr bufmgr); @endcode */ -int tbm_bo_get_flags (tbm_bo bo); +int tbm_bo_get_flags(tbm_bo bo); /** * @brief Print out the information of tbm_bos. @@ -1058,6 +1050,4 @@ void tbm_bufmgr_debug_trace (tbm_bufmgr bufmgr, int onoff); #ifdef __cplusplus } #endif - -#endif /* _TBM_BUFMGR_H_ */ - +#endif /* _TBM_BUFMGR_H_ */ diff --git a/src/tbm_bufmgr_backend.c b/src/tbm_bufmgr_backend.c index 18fed8c..83c4078 100644 --- a/src/tbm_bufmgr_backend.c +++ b/src/tbm_bufmgr_backend.c @@ -37,94 +37,74 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include "tbm_bufmgr_int.h" -tbm_bufmgr_backend -tbm_backend_alloc (void) +tbm_bufmgr_backend tbm_backend_alloc(void) { - tbm_bufmgr_backend bufmgr_backend; + tbm_bufmgr_backend bufmgr_backend; - bufmgr_backend = calloc (1, sizeof(struct _tbm_bufmgr_backend)); - if (!bufmgr_backend) - return NULL; + bufmgr_backend = calloc(1, sizeof(struct _tbm_bufmgr_backend)); + if (!bufmgr_backend) + return NULL; - return bufmgr_backend; + return bufmgr_backend; } -void -tbm_backend_free (tbm_bufmgr_backend backend) +void tbm_backend_free(tbm_bufmgr_backend backend) { - if (!backend) - return; + if (!backend) + return; - free (backend); - backend = NULL; + free(backend); + backend = NULL; } -int -tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend) +int tbm_backend_init(tbm_bufmgr bufmgr, tbm_bufmgr_backend backend) { - int flags = 0; - - if (!bufmgr) - { - TBM_LOG ("[libtbm:%d] " - "error (%s): fail to init tbm backend... bufmgr is null\n", - getpid(), __FUNCTION__); - return 0; - } - - if (!backend) - { - TBM_LOG ("[libtbm:%d] " - "error (%s): fail to init tbm backend... backend is null\n", - getpid(), __FUNCTION__); - return 0; - } - - flags = backend->flags; - /* check the backend flags */ - if (!(flags&TBM_CACHE_CTRL_BACKEND)) - { - if (!backend->bo_cache_flush) - { - TBM_LOG ("[libtbm:%d] " - "error (%s): TBM_FLAG_CACHE_CTRL_TBM needs backend->bo_cache_flush\n", - getpid(), __FUNCTION__); - return 0; - } - } - - bufmgr->backend = backend; - - return 1; + int flags = 0; + + if (!bufmgr) { + TBM_LOG("[libtbm:%d] " "error (%s): fail to init tbm backend... bufmgr is null\n", getpid(), __FUNCTION__); + return 0; + } + + if (!backend) { + TBM_LOG("[libtbm:%d] " "error (%s): fail to init tbm backend... backend is null\n", getpid(), __FUNCTION__); + return 0; + } + + flags = backend->flags; + /* check the backend flags */ + if (!(flags & TBM_CACHE_CTRL_BACKEND)) { + if (!backend->bo_cache_flush) { + TBM_LOG("[libtbm:%d] " "error (%s): TBM_FLAG_CACHE_CTRL_TBM needs backend->bo_cache_flush\n", getpid(), __FUNCTION__); + return 0; + } + } + + bufmgr->backend = backend; + + return 1; } -void * -tbm_backend_get_bufmgr_priv (tbm_bo bo) +void *tbm_backend_get_bufmgr_priv(tbm_bo bo) { - tbm_bufmgr_backend backend = bo->bufmgr->backend; + tbm_bufmgr_backend backend = bo->bufmgr->backend; - return backend->priv; + return backend->priv; } -void * -tbm_backend_get_priv_from_bufmgr (tbm_bufmgr bufmgr) +void *tbm_backend_get_priv_from_bufmgr(tbm_bufmgr bufmgr) { - tbm_bufmgr_backend backend = bufmgr->backend; + tbm_bufmgr_backend backend = bufmgr->backend; - return backend->priv; + return backend->priv; } -void -tbm_backend_set_bo_priv (tbm_bo bo, void *bo_priv) +void tbm_backend_set_bo_priv(tbm_bo bo, void *bo_priv) { - bo->priv = bo_priv; + bo->priv = bo_priv; } -void * -tbm_backend_get_bo_priv (tbm_bo bo) +void *tbm_backend_get_bo_priv(tbm_bo bo) { - return bo->priv; + return bo->priv; } - - - diff --git a/src/tbm_bufmgr_backend.h b/src/tbm_bufmgr_backend.h index 43974ad..711dd4c 100644 --- a/src/tbm_bufmgr_backend.h +++ b/src/tbm_bufmgr_backend.h @@ -45,7 +45,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * This header is for the implementation of the TBM backend module. */ - #define ABI_MINOR_MASK 0x0000FFFF #define ABI_MAJOR_MASK 0xFFFF0000 #define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK) @@ -60,7 +59,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * mask is 0xFFFF0000. */ #define SET_ABI_VERSION(maj, min) \ - ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK)) + ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK)) #define TBM_ABI_VERSION SET_ABI_VERSION(1, 1) /**< current abi vertion */ @@ -69,7 +68,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define TBM_CACHE_CLN 0x02 /**< cache clean */ #define TBM_CACHE_ALL 0x10 /**< cache all */ #define TBM_CACHE_FLUSH (TBM_CACHE_INV|TBM_CACHE_CLN) /**< cache flush */ -#define TBM_CACHE_FLUSH_ALL (TBM_CACHE_FLUSH|TBM_CACHE_ALL) /**< cache flush all */ +#define TBM_CACHE_FLUSH_ALL (TBM_CACHE_FLUSH|TBM_CACHE_ALL) /**< cache flush all */ /* TBM flag for cache control and lock control */ /** @@ -88,116 +87,115 @@ typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend; * @brief TBM backend functions * the set of function pointers for the backend module of TBM. */ -struct _tbm_bufmgr_backend -{ - int flags; +struct _tbm_bufmgr_backend { + int flags; - void *priv; /**< bufmgr private */ + void *priv; /**< bufmgr private */ - /** + /** * @brief deinitialize the bufmgr private. * @param[in] bufmgr : the private of the bufmgr * @return 1 if this function succeeds, otherwise 0. */ - void (*bufmgr_deinit) (void *priv); + void (*bufmgr_deinit) (void *priv); - /** + /** * @brief get the size of a bo. * @param[in] bo : the buffer object * @return 1 if this function succeeds, otherwise 0. */ - int (*bo_size) (tbm_bo bo); + int (*bo_size) (tbm_bo bo); - /** + /** * @brief allocate the buffer object * @param[in] bo : the buffer object * @param[in] size : the size of buffer object * @param[in] flags : the flags of memory type * @return pointer of the bo private. */ - void * (*bo_alloc) (tbm_bo bo, int size, int flags); + void *(*bo_alloc) (tbm_bo bo, int size, int flags); - /** + /** * @brief free the buffer object. * @param[in] bo : the buffer object */ - void (*bo_free) (tbm_bo bo); + void (*bo_free) (tbm_bo bo); - /** + /** * @brief import the buffer object associated with the key. * @remarks If the backend doesn't support a buffer sharing by tbm key, - fucntion pointer must be set to NULL. + fucntion pointer must be set to NULL. * @param[in] bo : the buffer object * @param[in] key : the key associated with the buffer object * @return pointer of the bo private. */ - void * (*bo_import) (tbm_bo bo, unsigned int key); + void *(*bo_import) (tbm_bo bo, unsigned int key); - /** + /** * @brief export the buffer object * @remarks If the backend doesn't support a buffer sharing by tbm key, - fucntion pointer must be set to NULL. + fucntion pointer must be set to NULL. * @param[in] bo : the buffer object * @return key associated with the buffer object */ - unsigned int (*bo_export) (tbm_bo bo); + unsigned int (*bo_export) (tbm_bo bo); - /** + /** * @brief get the tbm_bo_handle according to the device type. * @param[in] bo : the buffer object * @param[in] device : the device type to get a handle * @return the handle of the buffer object */ - tbm_bo_handle (*bo_get_handle) (tbm_bo bo, int device); + tbm_bo_handle(*bo_get_handle) (tbm_bo bo, int device); - /** + /** * @brief map the buffer object according to the device type and the option. * @param[in] bo : the buffer object * @param[in] device : the device type to get a handle * @param[in] option : the option to access the buffer object * @return the handle of the buffer object */ - tbm_bo_handle (*bo_map) (tbm_bo bo, int device, int opt); + tbm_bo_handle(*bo_map) (tbm_bo bo, int device, int opt); - /** + /** * @brief unmap the buffer object. * @param[in] bo : the buffer object * @return 1 if this function succeeds, otherwise 0. */ - int (*bo_unmap) (tbm_bo bo); + int (*bo_unmap) (tbm_bo bo); - /** + /** * @brief flush the cache of the buffer object. * @param[in] bo : the buffer object * @param[in] flags : the flags of cache flush type * @return 1 if this function succeeds, otherwise 0. */ - int (*bo_cache_flush) (tbm_bo bo, int flags); + int (*bo_cache_flush) (tbm_bo bo, int flags); - /** + /** * @brief get the global key associated with the buffer object. * @param[in] bo : the buffer object * @return global key associated with the buffer object. */ - int (*bo_get_global_key) (tbm_bo bo); + int (*bo_get_global_key) (tbm_bo bo); - /** + /** * @brief lock the buffer object. * @param[in] bo : the buffer object * @return 1 if this function succeeds, otherwise 0. * @remark This function pointer could be null. (default: use the tizen global lock) */ - int (*bo_lock) (tbm_bo bo); + int (*bo_lock) (tbm_bo bo); - /** + /** * @brief unlock the buffer object. * @param[in] bo : the buffer object * @return 1 if this function succeeds, otherwise 0. * @remark This function pointer could be null. (default: use the tizen global lock) */ - int (*bo_unlock) (tbm_bo bo); + int (*bo_unlock) (tbm_bo bo); - /** + /** * @brief lock the buffer object with a device and an opt. * @param[in] bo : the buffer object * @param[in] device : the device type to get a handle @@ -205,17 +203,17 @@ struct _tbm_bufmgr_backend * @return 1 if this function succeeds, otherwise 0. * @remark This function pointer could be null. (default: use the tizen global lock) */ - int (*bo_lock2) (tbm_bo bo, int device, int opt); + int (*bo_lock2) (tbm_bo bo, int device, int opt); - /** + /** * @brief query the formats list and the num to be supported by backend. * @param[out] *formats : format array list. this array has to be allocated by backend funtion * @param[out] *num : the number of the formats to be supported by backend * @return 1 if this function succeeds, otherwise 0. */ - int (*surface_supported_format) (uint32_t **formats, uint32_t *num); + int (*surface_supported_format) (uint32_t ** formats, uint32_t * num); - /** + /** * @brief get the size of the surface with a format. * @param[in] surface : the surface * @param[in] width : the width of the surface @@ -223,9 +221,9 @@ struct _tbm_bufmgr_backend * @param[in] format : the format of the surface * @return size of the surface if this function succeeds, otherwise 0. */ - int (*surface_get_size) (tbm_surface_h surface, int width, int height, tbm_format format); + int (*surface_get_size) (tbm_surface_h surface, int width, int height, tbm_format format); - /** + /** * @brief get the plane data of the surface. * @param[in] surface : the surface * @param[in] width : the width of the surface @@ -238,71 +236,70 @@ struct _tbm_bufmgr_backend * @param[out] bo_idx : the bo index of the plane * @return 1 if this function succeeds, otherwise 0. */ - int (*surface_get_plane_data) (tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx); + int (*surface_get_plane_data) (tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch, int *bo_idx); - /** + /** * @brief import the buffer object associated with the prime fd. * @remarks tbm_fd must be free by user. * @remarks If the backend doesn't support a buffer sharing by tbm fd, - fucntion pointer must be set to NULL. + fucntion pointer must be set to NULL. * @param[in] bo : the buffer object * @param[in] fd : the prime fd associated with the buffer object * @return pointer of the bo private. */ - void * (*bo_import_fd) (tbm_bo bo, tbm_fd fd); + void *(*bo_import_fd) (tbm_bo bo, tbm_fd fd); - /** + /** * @brief export the buffer object * @remarks tbm_fd must be free by user. * @remarks If the backend doesn't support a buffer sharing by tbm fd, - fucntion pointer must be set to NULL. + fucntion pointer must be set to NULL. * @param[in] bo : the buffer object * @return tbm_fd associated with the buffer object */ - tbm_fd (*bo_export_fd) (tbm_bo bo); + tbm_fd(*bo_export_fd) (tbm_bo bo); - /** + /** * @brief get the tbm_bo_handle according to the device type and the prime fd. * @param[in] bufmgr : the tizen buffer manager * @param[in] fd : the prime fd associated with the buffer object * @param[in] device : the option to access the buffer object * @return the handle of the buffer object */ - tbm_bo_handle (*fd_to_handle) (tbm_bufmgr bufmgr, tbm_fd fd, int device); + tbm_bo_handle(*fd_to_handle) (tbm_bufmgr bufmgr, tbm_fd fd, int device); - /** + /** * @brief get the num of bos with a format. * @param[in] format : the format of the surface * @return num of the bos if this function succeeds, otherwise 0. */ - int (*surface_get_num_bos) (tbm_format format); + int (*surface_get_num_bos) (tbm_format format); - /** + /** * @brief get the tbm flags of memory type * @param[in] bo : the buffer object * @see #TBM_BO_FLAGS * @return tbm flags of memory type is this function succeeds, otherwise 0. */ - int (*bo_get_flags) (tbm_bo bo); - - /* Padding for future extension */ - void (*reserved1) (void); - void (*reserved2) (void); - void (*reserved3) (void); - void (*reserved4) (void); - void (*reserved5) (void); - void (*reserved6) (void); + int (*bo_get_flags) (tbm_bo bo); + + /* Padding for future extension */ + void (*reserved1) (void); + void (*reserved2) (void); + void (*reserved3) (void); + void (*reserved4) (void); + void (*reserved5) (void); + void (*reserved6) (void); }; /** * @brief tbm module information * data type for the module information */ -typedef struct -{ - const char *modname; /**< name of module, e.g. "foo" */ - const char *vendor; /**< vendor specific string */ - unsigned long abiversion; /**< ABI version */ +typedef struct { + const char *modname; /**< name of module, e.g. "foo" */ + const char *vendor; /**< vendor specific string */ + unsigned long abiversion; /**< ABI version */ } TBMModuleVersionInfo; typedef int (*ModuleInitProc) (tbm_bufmgr, int); @@ -313,18 +310,17 @@ typedef int (*ModuleInitProc) (tbm_bufmgr, int); * @brief tbm module data * data type for the entry point of the backend module */ -typedef struct -{ - TBMModuleVersionInfo *vers; /**< tbm module informtaion */ - ModuleInitProc init; /**< init function of a backend module */ +typedef struct { + TBMModuleVersionInfo *vers; /**< tbm module informtaion */ + ModuleInitProc init; /**< init function of a backend module */ } TBMModuleData; -tbm_bufmgr_backend tbm_backend_alloc (void); -void tbm_backend_free (tbm_bufmgr_backend backend); -int tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend); +tbm_bufmgr_backend tbm_backend_alloc(void); +void tbm_backend_free(tbm_bufmgr_backend backend); +int tbm_backend_init(tbm_bufmgr bufmgr, tbm_bufmgr_backend backend); -void *tbm_backend_get_bufmgr_priv (tbm_bo bo); -void *tbm_backend_get_priv_from_bufmgr (tbm_bufmgr bufmgr); -void *tbm_backend_get_bo_priv (tbm_bo bo); +void *tbm_backend_get_bufmgr_priv(tbm_bo bo); +void *tbm_backend_get_priv_from_bufmgr(tbm_bufmgr bufmgr); +void *tbm_backend_get_bo_priv(tbm_bo bo); -#endif /* _TBM_BUFMGR_BACKEND_H_ */ +#endif /* _TBM_BUFMGR_BACKEND_H_ */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h old mode 100755 new mode 100644 index e9647f8..816a18f --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -53,130 +53,124 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* check condition */ #define TBM_RETURN_IF_FAIL(cond) {\ - if (!(cond)) {\ - TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return;\ - }\ + if (!(cond)) {\ + TBM_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + return;\ + } \ } #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\ - if (!(cond)) {\ - TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return val;\ - }\ + if (!(cond)) {\ + TBM_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + return val;\ + } \ } /* check flags */ #define RETURN_CHECK_FLAG(cond) {\ - if ((cond)) {\ - return;\ - }\ + if ((cond)) {\ + return;\ + } \ } #define RETURN_VAL_CHECK_FLAG(cond, val) {\ - if ((cond)) {\ - return val;\ - }\ + if ((cond)) {\ + return val;\ + } \ } - /* check validation */ #define TBM_BUFMGR_IS_VALID(mgr) (mgr) #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) + TBM_BUFMGR_IS_VALID(bo->bufmgr) && \ + bo->item_link.next && \ + bo->item_link.next->prev == &bo->item_link) #define TBM_SURFACE_IS_VALID(surf) (surf && \ - TBM_BUFMGR_IS_VALID(surf->bufmgr) && \ - surf->item_link.next && \ - surf->item_link.next->prev == &surf->item_link) + TBM_BUFMGR_IS_VALID(surf->bufmgr) && \ + surf->item_link.next && \ + surf->item_link.next->prev == &surf->item_link) #define TBM_ALL_CTRL_BACKEND_VALID(flags) \ - ((flags&TBM_CACHE_CTRL_BACKEND) &&\ - (flags&TBM_LOCK_CTRL_BACKEND)) + ((flags&TBM_CACHE_CTRL_BACKEND) &&\ + (flags&TBM_LOCK_CTRL_BACKEND)) #define TBM_CACHE_CTRL_BACKEND_VALID(flags) \ - (flags&TBM_CACHE_CTRL_BACKEND) + (flags&TBM_CACHE_CTRL_BACKEND) #define TBM_LOCK_CTRL_BACKEND_VALID(flags) \ - (flags&TBM_LOCK_CTRL_BACKEND) + (flags&TBM_LOCK_CTRL_BACKEND) -#define TBM_DEBUG(fmt, ...) fprintf (stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__) -#define TBM_LOG(fmt, ...) fprintf (stderr, "[TBM(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__) +#define TBM_DEBUG(fmt, ...) fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__) +#define TBM_LOG(fmt, ...) fprintf(stderr, "[TBM(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__) typedef union _tbm_bo_cache_state tbm_bo_cache_state; -struct list_head -{ - struct list_head *prev; - struct list_head *next; +struct list_head { + struct list_head *prev; + struct list_head *next; }; -union _tbm_bo_cache_state -{ - unsigned int val; - struct { - unsigned int cntFlush:16; /*Flush all index for sync*/ - unsigned int isCacheable:1; - unsigned int isCached:1; - unsigned int isDirtied:2; - } data; +union _tbm_bo_cache_state { + unsigned int val; + struct { + unsigned int cntFlush:16; /*Flush all index for sync */ + unsigned int isCacheable:1; + unsigned int isCached:1; + unsigned int isDirtied:2; + } data; }; /** * @brief tbm_bo : buffer object of Tizen Buffer Manager */ -struct _tbm_bo -{ - tbm_bufmgr bufmgr; /* tbm buffer manager */ +struct _tbm_bo { + tbm_bufmgr bufmgr; /* tbm buffer manager */ - int ref_cnt; /* ref count of bo */ + int ref_cnt; /* ref count of bo */ - int flags; /* TBM_BO_FLAGS :bo memory type */ + int flags; /* TBM_BO_FLAGS :bo memory type */ - unsigned int tgl_key; /*global key for tizen global lock */ + unsigned int tgl_key; /*global key for tizen global lock */ - /* for cache control */ - unsigned int map_cnt; /* device map count */ - tbm_bo_cache_state cache_state; /*cache state */ + /* for cache control */ + unsigned int map_cnt; /* device map count */ + tbm_bo_cache_state cache_state; /*cache state */ - int lock_cnt; /* lock count of bo */ + int lock_cnt; /* lock count of bo */ - struct list_head user_data_list; /* list of the user_date in bo */ + struct list_head user_data_list; /* list of the user_date in bo */ - void *priv; /* bo private */ + void *priv; /* bo private */ - struct list_head item_link; /* link of bo */ + struct list_head item_link; /* link of bo */ - tbm_bo_handle default_handle; /*default handle */ + tbm_bo_handle default_handle; /*default handle */ tbm_surface_h surface; /* tbm_surface */ - }; /** * @brief tbm_bufmgr : structure for tizen buffer manager * */ -struct _tbm_bufmgr -{ - pthread_mutex_t lock; /* mutex lock */ +struct _tbm_bufmgr { + pthread_mutex_t lock; /* mutex lock */ - int ref_count; /*reference count */ + int ref_count; /*reference count */ - int fd; /* bufmgr fd */ + int fd; /* bufmgr fd */ - int fd_flag; /* flag set 1 when bufmgr fd open in tbm_bufmgr_init*/ + int fd_flag; /* flag set 1 when bufmgr fd open in tbm_bufmgr_init */ - int lock_fd; /* fd of tizen global lock */ + int lock_fd; /* fd of tizen global lock */ - int lock_type; /* lock_type of bufmgr */ + int lock_type; /* lock_type of bufmgr */ - int use_map_cache; /* flag to use the map_cahce */ + int use_map_cache; /* flag to use the map_cahce */ - struct list_head bo_list; /* list of bos belonging to bufmgr */ + struct list_head bo_list; /* list of bos belonging to bufmgr */ - struct list_head surf_list; /* list of surfaces belonging to bufmgr */ + struct list_head surf_list; /* list of surfaces belonging to bufmgr */ - void *module_data; + void *module_data; - tbm_bufmgr_backend backend; /* bufmgr backend */ + tbm_bufmgr_backend backend; /* bufmgr backend */ }; /** @@ -184,41 +178,40 @@ struct _tbm_bufmgr * */ struct _tbm_surface { - tbm_bufmgr bufmgr; /* tbm buffer manager */ + tbm_bufmgr bufmgr; /* tbm buffer manager */ - tbm_surface_info_s info; /* tbm surface information */ + tbm_surface_info_s info; /* tbm surface information */ - int flags; + int flags; - int num_bos; /* the number of buffer objects */ + int num_bos; /* the number of buffer objects */ - tbm_bo bos[4]; + tbm_bo bos[4]; - int num_planes; /* the number of buffer objects */ + int num_planes; /* the number of buffer objects */ - int planes_bo_idx[TBM_SURF_PLANE_MAX]; + int planes_bo_idx[TBM_SURF_PLANE_MAX]; - int refcnt; + int refcnt; unsigned int debug_pid; - struct list_head item_link; /* link of surface */ + struct list_head item_link; /* link of surface */ }; int tbm_bufmgr_get_drm_fd_x11(void); int tbm_bufmgr_get_drm_fd_wayland(void); -int _tbm_bo_set_surface (tbm_bo bo, tbm_surface_h surface); +int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface); /* functions for mutex */ -int tbm_surface_internal_get_info (tbm_surface_h surface, int opt, tbm_surface_info_s *info, int map); -void tbm_surface_internal_unmap (tbm_surface_h surface); -unsigned int tbm_surface_internal_get_width (tbm_surface_h surface); -unsigned int tbm_surface_internal_get_height (tbm_surface_h surface); -tbm_format tbm_surface_internal_get_format (tbm_surface_h surface); -char *_tbm_surface_internal_format_to_str(tbm_format format); +int tbm_surface_internal_get_info(tbm_surface_h surface, int opt, tbm_surface_info_s * info, int map); +void tbm_surface_internal_unmap(tbm_surface_h surface); +unsigned int tbm_surface_internal_get_width(tbm_surface_h surface); +unsigned int tbm_surface_internal_get_height(tbm_surface_h surface); +tbm_format tbm_surface_internal_get_format(tbm_surface_h surface); unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface); +char * _tbm_surface_internal_format_to_str(tbm_format format); - -#endif /* _TBM_BUFMGR_INT_H_ */ +#endif /* _TBM_BUFMGR_INT_H_ */ diff --git a/src/tbm_bufmgr_tgl.h b/src/tbm_bufmgr_tgl.h index e0f9865..2279cac 100644 --- a/src/tbm_bufmgr_tgl.h +++ b/src/tbm_bufmgr_tgl.h @@ -67,4 +67,4 @@ typedef enum { #define TGL_IOC_SET_DATA _IOW(TGL_IOC_BASE, _TGL_SET_DATA, struct tgl_user_data *) #define TGL_IOC_GET_DATA _IOW(TGL_IOC_BASE, _TGL_GET_DATA, struct tgl_user_data *) -#endif /* __TBM_BUFMGR_TGL_H__ */ +#endif /* __TBM_BUFMGR_TGL_H__ */ diff --git a/src/tbm_surface.c b/src/tbm_surface.c index db05c32..6c5f312 100644 --- a/src/tbm_surface.c +++ b/src/tbm_surface.c @@ -34,125 +34,109 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tbm_bufmgr_int.h" #include "tbm_surface_internal.h" -int -tbm_surface_query_formats (uint32_t **formats, uint32_t *num) +int tbm_surface_query_formats(uint32_t ** formats, uint32_t * num) { - if (!tbm_surface_internal_query_supported_formats (formats, num)) - return TBM_SURFACE_ERROR_INVALID_OPERATION; + if (!tbm_surface_internal_query_supported_formats(formats, num)) + return TBM_SURFACE_ERROR_INVALID_OPERATION; - return TBM_SURFACE_ERROR_NONE; + return TBM_SURFACE_ERROR_NONE; } -tbm_surface_h -tbm_surface_create (int width, int height, tbm_format format) +tbm_surface_h tbm_surface_create(int width, int height, tbm_format format) { - if (!(width > 0) || !(height > 0)) - { + if (!(width > 0) || !(height > 0)) { #ifdef HAVE_CAPI_0_1_1 - set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER); + set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER); #endif - return NULL; - } + return NULL; + } - struct _tbm_surface *surf = NULL; + struct _tbm_surface *surf = NULL; - surf = tbm_surface_internal_create_with_flags (width, height, format, TBM_BO_DEFAULT); - if (!surf) - { + surf = tbm_surface_internal_create_with_flags(width, height, format, TBM_BO_DEFAULT); + if (!surf) { #ifdef HAVE_CAPI_0_1_1 - set_last_result (TBM_SURFACE_ERROR_INVALID_OPERATION); + set_last_result(TBM_SURFACE_ERROR_INVALID_OPERATION); #endif - return NULL; - } - + return NULL; + } #ifdef HAVE_CAPI_0_1_1 - set_last_result (TBM_SURFACE_ERROR_NONE); + set_last_result(TBM_SURFACE_ERROR_NONE); #endif - return surf; + return surf; } - -int -tbm_surface_destroy (tbm_surface_h surface) +int tbm_surface_destroy(tbm_surface_h surface) { - if (!surface) - return TBM_SURFACE_ERROR_INVALID_PARAMETER; + if (!surface) + return TBM_SURFACE_ERROR_INVALID_PARAMETER; - tbm_surface_internal_destroy (surface); + tbm_surface_internal_destroy(surface); - return TBM_SURFACE_ERROR_NONE; + return TBM_SURFACE_ERROR_NONE; } -int -tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info) +int tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s * info) { - TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - int ret = 0; + int ret = 0; - ret = tbm_surface_internal_get_info (surface, opt, info, 1); - if (ret == 0) - return TBM_SURFACE_ERROR_INVALID_OPERATION; + ret = tbm_surface_internal_get_info(surface, opt, info, 1); + if (ret == 0) + return TBM_SURFACE_ERROR_INVALID_OPERATION; - return TBM_SURFACE_ERROR_NONE; + return TBM_SURFACE_ERROR_NONE; } -int -tbm_surface_unmap (tbm_surface_h surface) +int tbm_surface_unmap(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - tbm_surface_internal_unmap(surface); + tbm_surface_internal_unmap(surface); - return TBM_SURFACE_ERROR_NONE; + return TBM_SURFACE_ERROR_NONE; } -int -tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info) +int tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s * info) { - TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - int ret = 0; + int ret = 0; - ret = tbm_surface_internal_get_info (surface, 0, info, 0); - if (ret == 0) - return TBM_SURFACE_ERROR_INVALID_OPERATION; + ret = tbm_surface_internal_get_info(surface, 0, info, 0); + if (ret == 0) + return TBM_SURFACE_ERROR_INVALID_OPERATION; - return TBM_SURFACE_ERROR_NONE; + return TBM_SURFACE_ERROR_NONE; } -int -tbm_surface_get_width (tbm_surface_h surface) +int tbm_surface_get_width(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - return tbm_surface_internal_get_width(surface); + return tbm_surface_internal_get_width(surface); } -int -tbm_surface_get_height (tbm_surface_h surface) +int tbm_surface_get_height(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); - return tbm_surface_internal_get_height(surface); + return tbm_surface_internal_get_height(surface); } -tbm_format -tbm_surface_get_format (tbm_surface_h surface) +tbm_format tbm_surface_get_format(tbm_surface_h surface) { - if (!surface) - { + if (!surface) { #ifdef HAVE_CAPI_0_1_1 - set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER); + set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER); #endif - return 0; - } - + return 0; + } #ifdef HAVE_CAPI_0_1_1 - set_last_result (TBM_SURFACE_ERROR_NONE); + set_last_result(TBM_SURFACE_ERROR_NONE); #endif - return tbm_surface_internal_get_format(surface); + return tbm_surface_internal_get_format(surface); } - diff --git a/src/tbm_surface.h b/src/tbm_surface.h index 88f7d3f..be5e900 100644 --- a/src/tbm_surface.h +++ b/src/tbm_surface.h @@ -50,11 +50,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * @brief Enumeration for tbm_surface error type. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef enum -{ - TBM_SURFACE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - TBM_SURFACE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - TBM_SURFACE_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */ +typedef enum { + TBM_SURFACE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + TBM_SURFACE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + TBM_SURFACE_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */ } tbm_surface_error_e; /** @@ -79,40 +78,38 @@ typedef enum * @brief Definition for the TBM plane struct. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef struct _tbm_surface_plane -{ - unsigned char *ptr; /**< Plane pointer */ - uint32_t size; /**< Plane size */ - uint32_t offset; /**< Plane offset */ - uint32_t stride; /**< Plane stride */ +typedef struct _tbm_surface_plane { + unsigned char *ptr; /**< Plane pointer */ + uint32_t size; /**< Plane size */ + uint32_t offset; /**< Plane offset */ + uint32_t stride; /**< Plane stride */ - void *reserved1; /**< Reserved pointer1 */ - void *reserved2; /**< Reserved pointer2 */ - void *reserved3; /**< Reserved pointer3 */ + void *reserved1; /**< Reserved pointer1 */ + void *reserved2; /**< Reserved pointer2 */ + void *reserved3; /**< Reserved pointer3 */ } tbm_surface_plane_s; /** * @brief Definition for the TBM surface information struct. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef struct _tbm_surface_info -{ - uint32_t width; /**< TBM surface width */ - uint32_t height; /**< TBM surface height */ - tbm_format format; /**< TBM surface format*/ - uint32_t bpp; /**< TBM surface bbp */ - uint32_t size; /**< TBM surface size */ +typedef struct _tbm_surface_info { + uint32_t width; /**< TBM surface width */ + uint32_t height; /**< TBM surface height */ + tbm_format format; /**< TBM surface format*/ + uint32_t bpp; /**< TBM surface bbp */ + uint32_t size; /**< TBM surface size */ - uint32_t num_planes; /**< The number of planes */ - tbm_surface_plane_s planes[TBM_SURF_PLANE_MAX]; /**< Array of planes */ + uint32_t num_planes; /**< The number of planes */ + tbm_surface_plane_s planes[TBM_SURF_PLANE_MAX]; /**< Array of planes */ - void *reserved4; /**< Reserved pointer4 */ - void *reserved5; /**< Reserved pointer5 */ - void *reserved6; /**< Reserved pointer6 */ + void *reserved4; /**< Reserved pointer4 */ + void *reserved5; /**< Reserved pointer5 */ + void *reserved6; /**< Reserved pointer6 */ } tbm_surface_info_s; -#define __tbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ - ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) +#define __tbm_fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ + ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) /* color index */ /** @@ -324,7 +321,7 @@ typedef struct _tbm_surface_info * @brief Definition for the TBM surface format BGRA1010102 ([31:0] B:G:R:A 10:10:10:2 little endian). * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -#define TBM_FORMAT_BGRA1010102 __tbm_fourcc_code('B', 'A', '3', '0') /* */ +#define TBM_FORMAT_BGRA1010102 __tbm_fourcc_code('B', 'A', '3', '0') /* */ /* packed YCbCr */ /** @@ -336,7 +333,7 @@ typedef struct _tbm_surface_info * @brief Definition for the TBM surface format YVYU ([31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian). * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -#define TBM_FORMAT_YVYU __tbm_fourcc_code('Y', 'V', 'Y', 'U') /* */ +#define TBM_FORMAT_YVYU __tbm_fourcc_code('Y', 'V', 'Y', 'U') /* */ /** * @brief Definition for the TBM surface format UYVY ([31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian). * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -370,7 +367,7 @@ typedef struct _tbm_surface_info * @brief Definition for the TBM surface format NV21 (2x2 subsampled Cb:Cr plane). * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -#define TBM_FORMAT_NV21 __tbm_fourcc_code('N', 'V', '2', '1') /* */ +#define TBM_FORMAT_NV21 __tbm_fourcc_code('N', 'V', '2', '1') /* */ /** * @brief Definition for the TBM surface format NV16 (2x1 subsampled Cr:Cb plane). * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -488,7 +485,7 @@ extern "C" { free (formats); @endcode */ -int tbm_surface_query_formats (uint32_t **formats, uint32_t *num); +int tbm_surface_query_formats(uint32_t ** formats, uint32_t * num); /** * @brief Creates the tbm_surface. @@ -526,7 +523,7 @@ int tbm_surface_query_formats (uint32_t **formats, uint32_t *num); tbm_surface_destroy (surface); @endcode */ -tbm_surface_h tbm_surface_create (int width, int height, tbm_format format); +tbm_surface_h tbm_surface_create(int width, int height, tbm_format format); /** * @brief Destroys the tbm_surface. @@ -555,7 +552,7 @@ tbm_surface_h tbm_surface_create (int width, int height, tbm_format format); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_destroy (tbm_surface_h surface); +int tbm_surface_destroy(tbm_surface_h surface); /** * @brief Maps the tbm_surface according to the access option. @@ -597,7 +594,7 @@ int tbm_surface_destroy (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info); +int tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s * info); /** * @brief Unmaps the tbm_surface. @@ -630,7 +627,7 @@ int tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_unmap (tbm_surface_h surface); +int tbm_surface_unmap(tbm_surface_h surface); /** * @brief Gets the information of the tbm_surface. @@ -668,7 +665,7 @@ int tbm_surface_unmap (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info); +int tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s * info); /** * @brief Gets the width of the tbm_surface. @@ -699,7 +696,7 @@ int tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_get_width (tbm_surface_h surface); +int tbm_surface_get_width(tbm_surface_h surface); /** * @brief Gets the height of the tbm_surface. @@ -730,7 +727,7 @@ int tbm_surface_get_width (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_get_height (tbm_surface_h surface); +int tbm_surface_get_height(tbm_surface_h surface); /** * @brief Gets the format of the tbm_surface. @@ -766,15 +763,12 @@ int tbm_surface_get_height (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -tbm_format tbm_surface_get_format (tbm_surface_h surface); +tbm_format tbm_surface_get_format(tbm_surface_h surface); #ifdef __cplusplus } #endif - /** * @} */ - -#endif /* _TBM_SURFACE_H_ */ - +#endif /* _TBM_SURFACE_H_ */ diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c old mode 100755 new mode 100644 index a8cd287..ebba248 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -38,919 +38,906 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. static tbm_bufmgr g_surface_bufmgr = NULL; static pthread_mutex_t tbm_surface_lock; -char* _tbm_surface_internal_format_to_str(tbm_format format) +char *_tbm_surface_internal_format_to_str(tbm_format format) { - switch(format) - { - case TBM_FORMAT_C8 : return "TBM_FORMAT_C8"; - case TBM_FORMAT_RGB332 : return "TBM_FORMAT_RGB332"; - case TBM_FORMAT_BGR233 : return "TBM_FORMAT_BGR233"; - case TBM_FORMAT_XRGB4444 : return "TBM_FORMAT_XRGB4444"; - case TBM_FORMAT_XBGR4444 : return "TBM_FORMAT_XBGR4444"; - case TBM_FORMAT_RGBX4444 : return "TBM_FORMAT_RGBX4444"; - case TBM_FORMAT_BGRX4444 : return "TBM_FORMAT_BGRX4444"; - case TBM_FORMAT_ARGB4444 : return "TBM_FORMAT_ARGB4444"; - case TBM_FORMAT_ABGR4444 : return "TBM_FORMAT_ABGR4444"; - case TBM_FORMAT_RGBA4444 : return "TBM_FORMAT_RGBA4444"; - case TBM_FORMAT_BGRA4444 : return "TBM_FORMAT_BGRA4444"; - case TBM_FORMAT_XRGB1555 : return "TBM_FORMAT_XRGB1555"; - case TBM_FORMAT_XBGR1555 : return "TBM_FORMAT_XBGR1555"; - case TBM_FORMAT_RGBX5551 : return "TBM_FORMAT_RGBX5551"; - case TBM_FORMAT_BGRX5551 : return "TBM_FORMAT_BGRX5551"; - case TBM_FORMAT_ARGB1555 : return "TBM_FORMAT_ARGB1555"; - case TBM_FORMAT_ABGR1555 : return "TBM_FORMAT_ABGR1555"; - case TBM_FORMAT_RGBA5551 : return "TBM_FORMAT_RGBA5551"; - case TBM_FORMAT_BGRA5551 : return "TBM_FORMAT_BGRA5551"; - case TBM_FORMAT_RGB565 : return "TBM_FORMAT_RGB565"; - case TBM_FORMAT_BGR565 : return "TBM_FORMAT_BGR565"; - case TBM_FORMAT_RGB888 : return "TBM_FORMAT_RGB888"; - case TBM_FORMAT_BGR888 : return "TBM_FORMAT_BGR888"; - case TBM_FORMAT_XRGB8888 : return "TBM_FORMAT_XRGB8888"; - case TBM_FORMAT_XBGR8888 : return "TBM_FORMAT_XBGR8888"; - case TBM_FORMAT_RGBX8888 : return "TBM_FORMAT_RGBX8888"; - case TBM_FORMAT_BGRX8888 : return "TBM_FORMAT_BGRX8888"; - case TBM_FORMAT_ARGB8888 : return "TBM_FORMAT_ARGB8888"; - case TBM_FORMAT_ABGR8888 : return "TBM_FORMAT_ABGR8888"; - case TBM_FORMAT_RGBA8888 : return "TBM_FORMAT_RGBA8888"; - case TBM_FORMAT_BGRA8888 : return "TBM_FORMAT_BGRA8888"; - case TBM_FORMAT_XRGB2101010 : return "TBM_FORMAT_XRGB2101010"; - case TBM_FORMAT_XBGR2101010 : return "TBM_FORMAT_XBGR2101010"; - case TBM_FORMAT_RGBX1010102 : return "TBM_FORMAT_RGBX1010102"; - case TBM_FORMAT_BGRX1010102 : return "TBM_FORMAT_BGRX1010102"; - case TBM_FORMAT_ARGB2101010 : return "TBM_FORMAT_ARGB2101010"; - case TBM_FORMAT_ABGR2101010 : return "TBM_FORMAT_ABGR2101010"; - case TBM_FORMAT_RGBA1010102 : return "TBM_FORMAT_RGBA1010102"; - case TBM_FORMAT_BGRA1010102 : return "TBM_FORMAT_BGRA1010102"; - case TBM_FORMAT_YUYV : return "TBM_FORMAT_YUYV"; - case TBM_FORMAT_YVYU : return "TBM_FORMAT_YVYU"; - case TBM_FORMAT_UYVY : return "TBM_FORMAT_UYVY"; - case TBM_FORMAT_VYUY : return "TBM_FORMAT_VYUY"; - case TBM_FORMAT_AYUV : return "TBM_FORMAT_AYUV"; - case TBM_FORMAT_NV12 : return "TBM_FORMAT_NV12"; - case TBM_FORMAT_NV21 : return "TBM_FORMAT_NV21"; - case TBM_FORMAT_NV16 : return "TBM_FORMAT_NV16"; - case TBM_FORMAT_NV61 : return "TBM_FORMAT_NV61"; - case TBM_FORMAT_YUV410 : return "TBM_FORMAT_YUV410"; - case TBM_FORMAT_YVU410 : return "TBM_FORMAT_YVU410"; - case TBM_FORMAT_YUV411 : return "TBM_FORMAT_YUV411"; - case TBM_FORMAT_YVU411 : return "TBM_FORMAT_YVU411"; - case TBM_FORMAT_YUV420 : return "TBM_FORMAT_YUV420"; - case TBM_FORMAT_YVU420 : return "TBM_FORMAT_YVU420"; - case TBM_FORMAT_YUV422 : return "TBM_FORMAT_YUV422"; - case TBM_FORMAT_YVU422 : return "TBM_FORMAT_YVU422"; - case TBM_FORMAT_YUV444 : return "TBM_FORMAT_YUV444"; - case TBM_FORMAT_YVU444 : return "TBM_FORMAT_YVU444"; - case TBM_FORMAT_NV12MT : return "TBM_FORMAT_NV12MT"; - default : return "unknwon"; + switch (format) { + case TBM_FORMAT_C8: + return "TBM_FORMAT_C8"; + case TBM_FORMAT_RGB332: + return "TBM_FORMAT_RGB332"; + case TBM_FORMAT_BGR233: + return "TBM_FORMAT_BGR233"; + case TBM_FORMAT_XRGB4444: + return "TBM_FORMAT_XRGB4444"; + case TBM_FORMAT_XBGR4444: + return "TBM_FORMAT_XBGR4444"; + case TBM_FORMAT_RGBX4444: + return "TBM_FORMAT_RGBX4444"; + case TBM_FORMAT_BGRX4444: + return "TBM_FORMAT_BGRX4444"; + case TBM_FORMAT_ARGB4444: + return "TBM_FORMAT_ARGB4444"; + case TBM_FORMAT_ABGR4444: + return "TBM_FORMAT_ABGR4444"; + case TBM_FORMAT_RGBA4444: + return "TBM_FORMAT_RGBA4444"; + case TBM_FORMAT_BGRA4444: + return "TBM_FORMAT_BGRA4444"; + case TBM_FORMAT_XRGB1555: + return "TBM_FORMAT_XRGB1555"; + case TBM_FORMAT_XBGR1555: + return "TBM_FORMAT_XBGR1555"; + case TBM_FORMAT_RGBX5551: + return "TBM_FORMAT_RGBX5551"; + case TBM_FORMAT_BGRX5551: + return "TBM_FORMAT_BGRX5551"; + case TBM_FORMAT_ARGB1555: + return "TBM_FORMAT_ARGB1555"; + case TBM_FORMAT_ABGR1555: + return "TBM_FORMAT_ABGR1555"; + case TBM_FORMAT_RGBA5551: + return "TBM_FORMAT_RGBA5551"; + case TBM_FORMAT_BGRA5551: + return "TBM_FORMAT_BGRA5551"; + case TBM_FORMAT_RGB565: + return "TBM_FORMAT_RGB565"; + case TBM_FORMAT_BGR565: + return "TBM_FORMAT_BGR565"; + case TBM_FORMAT_RGB888: + return "TBM_FORMAT_RGB888"; + case TBM_FORMAT_BGR888: + return "TBM_FORMAT_BGR888"; + case TBM_FORMAT_XRGB8888: + return "TBM_FORMAT_XRGB8888"; + case TBM_FORMAT_XBGR8888: + return "TBM_FORMAT_XBGR8888"; + case TBM_FORMAT_RGBX8888: + return "TBM_FORMAT_RGBX8888"; + case TBM_FORMAT_BGRX8888: + return "TBM_FORMAT_BGRX8888"; + case TBM_FORMAT_ARGB8888: + return "TBM_FORMAT_ARGB8888"; + case TBM_FORMAT_ABGR8888: + return "TBM_FORMAT_ABGR8888"; + case TBM_FORMAT_RGBA8888: + return "TBM_FORMAT_RGBA8888"; + case TBM_FORMAT_BGRA8888: + return "TBM_FORMAT_BGRA8888"; + case TBM_FORMAT_XRGB2101010: + return "TBM_FORMAT_XRGB2101010"; + case TBM_FORMAT_XBGR2101010: + return "TBM_FORMAT_XBGR2101010"; + case TBM_FORMAT_RGBX1010102: + return "TBM_FORMAT_RGBX1010102"; + case TBM_FORMAT_BGRX1010102: + return "TBM_FORMAT_BGRX1010102"; + case TBM_FORMAT_ARGB2101010: + return "TBM_FORMAT_ARGB2101010"; + case TBM_FORMAT_ABGR2101010: + return "TBM_FORMAT_ABGR2101010"; + case TBM_FORMAT_RGBA1010102: + return "TBM_FORMAT_RGBA1010102"; + case TBM_FORMAT_BGRA1010102: + return "TBM_FORMAT_BGRA1010102"; + case TBM_FORMAT_YUYV: + return "TBM_FORMAT_YUYV"; + case TBM_FORMAT_YVYU: + return "TBM_FORMAT_YVYU"; + case TBM_FORMAT_UYVY: + return "TBM_FORMAT_UYVY"; + case TBM_FORMAT_VYUY: + return "TBM_FORMAT_VYUY"; + case TBM_FORMAT_AYUV: + return "TBM_FORMAT_AYUV"; + case TBM_FORMAT_NV12: + return "TBM_FORMAT_NV12"; + case TBM_FORMAT_NV21: + return "TBM_FORMAT_NV21"; + case TBM_FORMAT_NV16: + return "TBM_FORMAT_NV16"; + case TBM_FORMAT_NV61: + return "TBM_FORMAT_NV61"; + case TBM_FORMAT_YUV410: + return "TBM_FORMAT_YUV410"; + case TBM_FORMAT_YVU410: + return "TBM_FORMAT_YVU410"; + case TBM_FORMAT_YUV411: + return "TBM_FORMAT_YUV411"; + case TBM_FORMAT_YVU411: + return "TBM_FORMAT_YVU411"; + case TBM_FORMAT_YUV420: + return "TBM_FORMAT_YUV420"; + case TBM_FORMAT_YVU420: + return "TBM_FORMAT_YVU420"; + case TBM_FORMAT_YUV422: + return "TBM_FORMAT_YUV422"; + case TBM_FORMAT_YVU422: + return "TBM_FORMAT_YVU422"; + case TBM_FORMAT_YUV444: + return "TBM_FORMAT_YUV444"; + case TBM_FORMAT_YVU444: + return "TBM_FORMAT_YVU444"; + case TBM_FORMAT_NV12MT: + return "TBM_FORMAT_NV12MT"; + default: + return "unknwon"; } } - -static bool -_tbm_surface_mutex_init (void) +static bool _tbm_surface_mutex_init(void) { - static bool tbm_surface_mutex_init = false; + static bool tbm_surface_mutex_init = false; - if (tbm_surface_mutex_init) - return true; + if (tbm_surface_mutex_init) + return true; - if (pthread_mutex_init (&tbm_surface_lock, NULL)) - { - TBM_LOG ("[libtbm] fail: tbm_surface mutex init\n"); - return false; - } + if (pthread_mutex_init(&tbm_surface_lock, NULL)) { + TBM_LOG("[libtbm] fail: tbm_surface mutex init\n"); + return false; + } - tbm_surface_mutex_init = true; + tbm_surface_mutex_init = true; - return true; + return true; } -void -_tbm_surface_mutex_lock (void) +void _tbm_surface_mutex_lock(void) { - if (!_tbm_surface_mutex_init ()) - return; + if (!_tbm_surface_mutex_init()) + return; - pthread_mutex_lock (&tbm_surface_lock); + pthread_mutex_lock(&tbm_surface_lock); } -void -_tbm_surface_mutex_unlock (void) +void _tbm_surface_mutex_unlock(void) { - pthread_mutex_unlock (&tbm_surface_lock); + pthread_mutex_unlock(&tbm_surface_lock); } -static void -_init_surface_bufmgr() +static void _init_surface_bufmgr() { - g_surface_bufmgr = tbm_bufmgr_init (-1); + g_surface_bufmgr = tbm_bufmgr_init(-1); } -static void -_deinit_surface_bufmgr() +static void _deinit_surface_bufmgr() { - if (!g_surface_bufmgr) - return; + if (!g_surface_bufmgr) + return; - tbm_bufmgr_deinit (g_surface_bufmgr); - g_surface_bufmgr = NULL; + tbm_bufmgr_deinit(g_surface_bufmgr); + g_surface_bufmgr = NULL; } -static int -_tbm_surface_internal_query_size (tbm_surface_h surface) +static int _tbm_surface_internal_query_size(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); + TBM_RETURN_VAL_IF_FAIL(surface, 0); - struct _tbm_surface *surf = (struct _tbm_surface *) surface; - struct _tbm_bufmgr *mgr = surf->bufmgr; - int size = 0; + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + struct _tbm_bufmgr *mgr = surf->bufmgr; + int size = 0; - TBM_RETURN_VAL_IF_FAIL (mgr != NULL, 0); - TBM_RETURN_VAL_IF_FAIL (surf->info.width > 0, 0); - TBM_RETURN_VAL_IF_FAIL (surf->info.height > 0, 0); - TBM_RETURN_VAL_IF_FAIL (surf->info.format > 0, 0); + TBM_RETURN_VAL_IF_FAIL(mgr != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(surf->info.width > 0, 0); + TBM_RETURN_VAL_IF_FAIL(surf->info.height > 0, 0); + TBM_RETURN_VAL_IF_FAIL(surf->info.format > 0, 0); - if (!mgr->backend->surface_get_size) - return 0; + if (!mgr->backend->surface_get_size) + return 0; - size = mgr->backend->surface_get_size (surf, surf->info.width, surf->info.height, surf->info.format); + size = mgr->backend->surface_get_size(surf, surf->info.width, surf->info.height, surf->info.format); - return size; + return size; } -static int -_tbm_surface_internal_query_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx) +static int _tbm_surface_internal_query_plane_data(tbm_surface_h surface, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch, int *bo_idx) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); - TBM_RETURN_VAL_IF_FAIL (plane_idx > -1, 0); + TBM_RETURN_VAL_IF_FAIL(surface, 0); + TBM_RETURN_VAL_IF_FAIL(plane_idx > -1, 0); - struct _tbm_surface *surf = (struct _tbm_surface *) surface; - struct _tbm_bufmgr *mgr = surf->bufmgr; - int ret = 0; + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + struct _tbm_bufmgr *mgr = surf->bufmgr; + int ret = 0; - TBM_RETURN_VAL_IF_FAIL (mgr != NULL, 0); - TBM_RETURN_VAL_IF_FAIL (surf->info.width > 0, 0); - TBM_RETURN_VAL_IF_FAIL (surf->info.height > 0, 0); - TBM_RETURN_VAL_IF_FAIL (surf->info.format > 0, 0); + TBM_RETURN_VAL_IF_FAIL(mgr != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(surf->info.width > 0, 0); + TBM_RETURN_VAL_IF_FAIL(surf->info.height > 0, 0); + TBM_RETURN_VAL_IF_FAIL(surf->info.format > 0, 0); - if (!mgr->backend->surface_get_plane_data) - return 0; + if (!mgr->backend->surface_get_plane_data) + return 0; - ret = mgr->backend->surface_get_plane_data (surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch, bo_idx); - if (!ret) - return 0; + ret = mgr->backend->surface_get_plane_data(surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch, bo_idx); + if (!ret) + return 0; - return 1; + return 1; } -static int -_tbm_surface_internal_query_num_bos (tbm_format format) +static int _tbm_surface_internal_query_num_bos(tbm_format format) { - TBM_RETURN_VAL_IF_FAIL (format > 0, 0); - struct _tbm_bufmgr *mgr; - int ret = 0; + TBM_RETURN_VAL_IF_FAIL(format > 0, 0); + struct _tbm_bufmgr *mgr; + int ret = 0; - mgr = g_surface_bufmgr; + mgr = g_surface_bufmgr; - if (!mgr->backend->surface_get_num_bos) - return 0; + if (!mgr->backend->surface_get_num_bos) + return 0; - ret = mgr->backend->surface_get_num_bos (format); - if (!ret) - return 0; + ret = mgr->backend->surface_get_num_bos(format); + if (!ret) + return 0; - return ret; + return ret; } -static void -_tbm_surface_internal_destroy (tbm_surface_h surface) +static void _tbm_surface_internal_destroy(tbm_surface_h surface) { - int i; + int i; tbm_bufmgr bufmgr = surface->bufmgr; - for (i = 0; i < surface->num_bos; i++) - { + for (i = 0; i < surface->num_bos; i++) { surface->bos[i]->surface = NULL; - tbm_bo_unref (surface->bos[i]); - surface->bos[i] = NULL; - } - - LIST_DEL (&surface->item_link); - - free (surface); - surface = NULL; + tbm_bo_unref(surface->bos[i]); + surface->bos[i] = NULL; + } - if(LIST_IS_EMPTY (&bufmgr->surf_list)) - { - LIST_DELINIT (&bufmgr->surf_list); - _deinit_surface_bufmgr (); - } + free(surface); + surface = NULL; + if (LIST_IS_EMPTY(&bufmgr->surf_list)) { + LIST_DELINIT(&bufmgr->surf_list); + _deinit_surface_bufmgr(); + } } - -int -tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *num) +int tbm_surface_internal_query_supported_formats(uint32_t ** formats, uint32_t * num) { - struct _tbm_bufmgr *mgr; - int ret = 0; + struct _tbm_bufmgr *mgr; + int ret = 0; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - if (!g_surface_bufmgr) - { - _init_surface_bufmgr(); - LIST_INITHEAD (&g_surface_bufmgr->surf_list); - } + if (!g_surface_bufmgr) { + _init_surface_bufmgr(); + LIST_INITHEAD(&g_surface_bufmgr->surf_list); + } - mgr = g_surface_bufmgr; + mgr = g_surface_bufmgr; - if (!mgr->backend->surface_supported_format) - { - _tbm_surface_mutex_unlock(); - return 0; - } + if (!mgr->backend->surface_supported_format) { + _tbm_surface_mutex_unlock(); + return 0; + } - ret = mgr->backend->surface_supported_format (formats, num); + ret = mgr->backend->surface_supported_format(formats, num); - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return ret; + return ret; } - -int tbm_surface_internal_get_num_planes (tbm_format format) +int tbm_surface_internal_get_num_planes(tbm_format format) { - int num_planes = 0; - - switch (format) - { - case TBM_FORMAT_C8: - case TBM_FORMAT_RGB332: - case TBM_FORMAT_BGR233: - case TBM_FORMAT_XRGB4444: - case TBM_FORMAT_XBGR4444: - case TBM_FORMAT_RGBX4444: - case TBM_FORMAT_BGRX4444: - case TBM_FORMAT_ARGB4444: - case TBM_FORMAT_ABGR4444: - case TBM_FORMAT_RGBA4444: - case TBM_FORMAT_BGRA4444: - case TBM_FORMAT_XRGB1555: - case TBM_FORMAT_XBGR1555: - case TBM_FORMAT_RGBX5551: - case TBM_FORMAT_BGRX5551: - case TBM_FORMAT_ARGB1555: - case TBM_FORMAT_ABGR1555: - case TBM_FORMAT_RGBA5551: - case TBM_FORMAT_BGRA5551: - case TBM_FORMAT_RGB565: - case TBM_FORMAT_BGR565: - case TBM_FORMAT_RGB888: - case TBM_FORMAT_BGR888: - case TBM_FORMAT_XRGB8888: - case TBM_FORMAT_XBGR8888: - case TBM_FORMAT_RGBX8888: - case TBM_FORMAT_BGRX8888: - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_ABGR8888: - case TBM_FORMAT_RGBA8888: - case TBM_FORMAT_BGRA8888: - case TBM_FORMAT_XRGB2101010: - case TBM_FORMAT_XBGR2101010: - case TBM_FORMAT_RGBX1010102: - case TBM_FORMAT_BGRX1010102: - case TBM_FORMAT_ARGB2101010: - case TBM_FORMAT_ABGR2101010: - case TBM_FORMAT_RGBA1010102: - case TBM_FORMAT_BGRA1010102: - case TBM_FORMAT_YUYV: - case TBM_FORMAT_YVYU: - case TBM_FORMAT_UYVY: - case TBM_FORMAT_VYUY: - case TBM_FORMAT_AYUV: - num_planes = 1; - break; - case TBM_FORMAT_NV12: - case TBM_FORMAT_NV21: - case TBM_FORMAT_NV16: - case TBM_FORMAT_NV61: - num_planes = 2; - break; - case TBM_FORMAT_YUV410: - case TBM_FORMAT_YVU410: - case TBM_FORMAT_YUV411: - case TBM_FORMAT_YVU411: - case TBM_FORMAT_YUV420: - case TBM_FORMAT_YVU420: - case TBM_FORMAT_YUV422: - case TBM_FORMAT_YVU422: - case TBM_FORMAT_YUV444: - case TBM_FORMAT_YVU444: - num_planes = 3; - break; - - default : - break; - } - - return num_planes; + int num_planes = 0; + + switch (format) { + case TBM_FORMAT_C8: + case TBM_FORMAT_RGB332: + case TBM_FORMAT_BGR233: + case TBM_FORMAT_XRGB4444: + case TBM_FORMAT_XBGR4444: + case TBM_FORMAT_RGBX4444: + case TBM_FORMAT_BGRX4444: + case TBM_FORMAT_ARGB4444: + case TBM_FORMAT_ABGR4444: + case TBM_FORMAT_RGBA4444: + case TBM_FORMAT_BGRA4444: + case TBM_FORMAT_XRGB1555: + case TBM_FORMAT_XBGR1555: + case TBM_FORMAT_RGBX5551: + case TBM_FORMAT_BGRX5551: + case TBM_FORMAT_ARGB1555: + case TBM_FORMAT_ABGR1555: + case TBM_FORMAT_RGBA5551: + case TBM_FORMAT_BGRA5551: + case TBM_FORMAT_RGB565: + case TBM_FORMAT_BGR565: + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + case TBM_FORMAT_XRGB8888: + case TBM_FORMAT_XBGR8888: + case TBM_FORMAT_RGBX8888: + case TBM_FORMAT_BGRX8888: + case TBM_FORMAT_ARGB8888: + case TBM_FORMAT_ABGR8888: + case TBM_FORMAT_RGBA8888: + case TBM_FORMAT_BGRA8888: + case TBM_FORMAT_XRGB2101010: + case TBM_FORMAT_XBGR2101010: + case TBM_FORMAT_RGBX1010102: + case TBM_FORMAT_BGRX1010102: + case TBM_FORMAT_ARGB2101010: + case TBM_FORMAT_ABGR2101010: + case TBM_FORMAT_RGBA1010102: + case TBM_FORMAT_BGRA1010102: + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + num_planes = 1; + break; + case TBM_FORMAT_NV12: + case TBM_FORMAT_NV21: + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + num_planes = 2; + break; + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + num_planes = 3; + break; + + default: + break; + } + + return num_planes; } -int tbm_surface_internal_get_bpp (tbm_format format) +int tbm_surface_internal_get_bpp(tbm_format format) { - int bpp = 0; - - switch (format) - { - case TBM_FORMAT_C8: - case TBM_FORMAT_RGB332: - case TBM_FORMAT_BGR233: - bpp = 8; - break; - case TBM_FORMAT_XRGB4444: - case TBM_FORMAT_XBGR4444: - case TBM_FORMAT_RGBX4444: - case TBM_FORMAT_BGRX4444: - case TBM_FORMAT_ARGB4444: - case TBM_FORMAT_ABGR4444: - case TBM_FORMAT_RGBA4444: - case TBM_FORMAT_BGRA4444: - case TBM_FORMAT_XRGB1555: - case TBM_FORMAT_XBGR1555: - case TBM_FORMAT_RGBX5551: - case TBM_FORMAT_BGRX5551: - case TBM_FORMAT_ARGB1555: - case TBM_FORMAT_ABGR1555: - case TBM_FORMAT_RGBA5551: - case TBM_FORMAT_BGRA5551: - case TBM_FORMAT_RGB565: - case TBM_FORMAT_BGR565: - bpp = 16; - break; - case TBM_FORMAT_RGB888: - case TBM_FORMAT_BGR888: - bpp = 24; - break; - case TBM_FORMAT_XRGB8888: - case TBM_FORMAT_XBGR8888: - case TBM_FORMAT_RGBX8888: - case TBM_FORMAT_BGRX8888: - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_ABGR8888: - case TBM_FORMAT_RGBA8888: - case TBM_FORMAT_BGRA8888: - case TBM_FORMAT_XRGB2101010: - case TBM_FORMAT_XBGR2101010: - case TBM_FORMAT_RGBX1010102: - case TBM_FORMAT_BGRX1010102: - case TBM_FORMAT_ARGB2101010: - case TBM_FORMAT_ABGR2101010: - case TBM_FORMAT_RGBA1010102: - case TBM_FORMAT_BGRA1010102: - case TBM_FORMAT_YUYV: - case TBM_FORMAT_YVYU: - case TBM_FORMAT_UYVY: - case TBM_FORMAT_VYUY: - case TBM_FORMAT_AYUV: - bpp = 32; - break; - case TBM_FORMAT_NV12: - case TBM_FORMAT_NV21: - bpp = 12; - break; - case TBM_FORMAT_NV16: - case TBM_FORMAT_NV61: - bpp = 16; - break; - case TBM_FORMAT_YUV410: - case TBM_FORMAT_YVU410: - bpp = 9; - break; - case TBM_FORMAT_YUV411: - case TBM_FORMAT_YVU411: - case TBM_FORMAT_YUV420: - case TBM_FORMAT_YVU420: - bpp = 12; - break; - case TBM_FORMAT_YUV422: - case TBM_FORMAT_YVU422: - bpp = 16; - break; - case TBM_FORMAT_YUV444: - case TBM_FORMAT_YVU444: - bpp = 24; - break; - default : - break; - } - - return bpp; + int bpp = 0; + + switch (format) { + case TBM_FORMAT_C8: + case TBM_FORMAT_RGB332: + case TBM_FORMAT_BGR233: + bpp = 8; + break; + case TBM_FORMAT_XRGB4444: + case TBM_FORMAT_XBGR4444: + case TBM_FORMAT_RGBX4444: + case TBM_FORMAT_BGRX4444: + case TBM_FORMAT_ARGB4444: + case TBM_FORMAT_ABGR4444: + case TBM_FORMAT_RGBA4444: + case TBM_FORMAT_BGRA4444: + case TBM_FORMAT_XRGB1555: + case TBM_FORMAT_XBGR1555: + case TBM_FORMAT_RGBX5551: + case TBM_FORMAT_BGRX5551: + case TBM_FORMAT_ARGB1555: + case TBM_FORMAT_ABGR1555: + case TBM_FORMAT_RGBA5551: + case TBM_FORMAT_BGRA5551: + case TBM_FORMAT_RGB565: + case TBM_FORMAT_BGR565: + bpp = 16; + break; + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + bpp = 24; + break; + case TBM_FORMAT_XRGB8888: + case TBM_FORMAT_XBGR8888: + case TBM_FORMAT_RGBX8888: + case TBM_FORMAT_BGRX8888: + case TBM_FORMAT_ARGB8888: + case TBM_FORMAT_ABGR8888: + case TBM_FORMAT_RGBA8888: + case TBM_FORMAT_BGRA8888: + case TBM_FORMAT_XRGB2101010: + case TBM_FORMAT_XBGR2101010: + case TBM_FORMAT_RGBX1010102: + case TBM_FORMAT_BGRX1010102: + case TBM_FORMAT_ARGB2101010: + case TBM_FORMAT_ABGR2101010: + case TBM_FORMAT_RGBA1010102: + case TBM_FORMAT_BGRA1010102: + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + bpp = 32; + break; + case TBM_FORMAT_NV12: + case TBM_FORMAT_NV21: + bpp = 12; + break; + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + bpp = 16; + break; + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + bpp = 9; + break; + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + bpp = 12; + break; + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + bpp = 16; + break; + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + bpp = 24; + break; + default: + break; + } + + return bpp; } -tbm_surface_h -tbm_surface_internal_create_with_flags (int width, int height, int format, int flags) +tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags) { - TBM_RETURN_VAL_IF_FAIL (width > 0, NULL); - TBM_RETURN_VAL_IF_FAIL (height > 0, NULL); - - struct _tbm_bufmgr *mgr; - struct _tbm_surface *surf = NULL; - uint32_t size = 0; - uint32_t offset = 0; - uint32_t stride = 0; - uint32_t bo_size = 0; - int bo_idx; - int i, j; - - _tbm_surface_mutex_lock(); - - if (!g_surface_bufmgr) - { - _init_surface_bufmgr(); - LIST_INITHEAD (&g_surface_bufmgr->surf_list); - } - - mgr = g_surface_bufmgr; - if (!TBM_BUFMGR_IS_VALID(mgr)) - { - _tbm_surface_mutex_unlock(); - return NULL; - } - surf = calloc (1, sizeof(struct _tbm_surface)); - if (!surf) - { - _tbm_surface_mutex_unlock(); - return NULL; - } - - surf->bufmgr = mgr; - surf->info.width = width; - surf->info.height = height; - surf->info.format = format; - surf->info.bpp = tbm_surface_internal_get_bpp (format); - surf->info.size = _tbm_surface_internal_query_size (surf); - surf->info.num_planes = tbm_surface_internal_get_num_planes(format); - surf->num_bos = _tbm_surface_internal_query_num_bos(format); - surf->refcnt = 1; - - /* get size, stride and offset bo_idx*/ - for (i = 0; i < surf->info.num_planes; i++) - { - _tbm_surface_internal_query_plane_data (surf, i, &size, &offset, &stride, &bo_idx); - surf->info.planes[i].size = size; - surf->info.planes[i].offset = offset; - surf->info.planes[i].stride = stride; - surf->planes_bo_idx[i] = bo_idx; - } - - surf->flags = flags; - - for (i = 0; i < surf->num_bos; i++) - { - bo_size = 0; - for (j = 0; j < surf->info.num_planes; j++) - { - if (surf->planes_bo_idx[j] == i) - bo_size += surf->info.planes[j].size; - } - surf->bos[i] = tbm_bo_alloc (mgr, bo_size, flags); - if (!surf->bos[i]) { - for (j = 0; j < i; j++) - tbm_bo_unref (surf->bos[j]); - - free (surf); - surf = NULL; - - if(LIST_IS_EMPTY (&mgr->surf_list)) - { - LIST_DELINIT (&mgr->surf_list); - _deinit_surface_bufmgr (); - } - - _tbm_surface_mutex_unlock(); - return NULL; - } + TBM_RETURN_VAL_IF_FAIL(width > 0, NULL); + TBM_RETURN_VAL_IF_FAIL(height > 0, NULL); + + struct _tbm_bufmgr *mgr; + struct _tbm_surface *surf = NULL; + uint32_t size = 0; + uint32_t offset = 0; + uint32_t stride = 0; + uint32_t bo_size = 0; + int bo_idx; + int i, j; + + _tbm_surface_mutex_lock(); + + if (!g_surface_bufmgr) { + _init_surface_bufmgr(); + LIST_INITHEAD(&g_surface_bufmgr->surf_list); + } + + mgr = g_surface_bufmgr; + if (!TBM_BUFMGR_IS_VALID(mgr)) { + _tbm_surface_mutex_unlock(); + return NULL; + } + surf = calloc(1, sizeof(struct _tbm_surface)); + if (!surf) { + _tbm_surface_mutex_unlock(); + return NULL; + } + + surf->bufmgr = mgr; + surf->info.width = width; + surf->info.height = height; + surf->info.format = format; + surf->info.bpp = tbm_surface_internal_get_bpp(format); + surf->info.size = _tbm_surface_internal_query_size(surf); + surf->info.num_planes = tbm_surface_internal_get_num_planes(format); + surf->num_bos = _tbm_surface_internal_query_num_bos(format); + surf->refcnt = 1; + + /* get size, stride and offset bo_idx */ + for (i = 0; i < surf->info.num_planes; i++) { + _tbm_surface_internal_query_plane_data(surf, i, &size, &offset, &stride, &bo_idx); + surf->info.planes[i].size = size; + surf->info.planes[i].offset = offset; + surf->info.planes[i].stride = stride; + surf->planes_bo_idx[i] = bo_idx; + } + + surf->flags = flags; + + for (i = 0; i < surf->num_bos; i++) { + bo_size = 0; + for (j = 0; j < surf->info.num_planes; j++) { + if (surf->planes_bo_idx[j] == i) + bo_size += surf->info.planes[j].size; + } + surf->bos[i] = tbm_bo_alloc(mgr, bo_size, flags); + if (!surf->bos[i]) { + for (j = 0; j < i; j++) + tbm_bo_unref(surf->bos[j]); + + free(surf); + surf = NULL; + + if (LIST_IS_EMPTY(&mgr->surf_list)) { + LIST_DELINIT(&mgr->surf_list); + _deinit_surface_bufmgr(); + } + + _tbm_surface_mutex_unlock(); + return NULL; + } _tbm_bo_set_surface(surf->bos[i], surf); - } + } - LIST_ADD (&surf->item_link, &mgr->surf_list); + LIST_ADD(&surf->item_link, &mgr->surf_list); - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return surf; + return surf; } -tbm_surface_h -tbm_surface_internal_create_with_bos (tbm_surface_info_s *info, tbm_bo *bos, int num) +tbm_surface_h tbm_surface_internal_create_with_bos(tbm_surface_info_s * info, tbm_bo * bos, int num) { - TBM_RETURN_VAL_IF_FAIL (bos, NULL); - TBM_RETURN_VAL_IF_FAIL (info, NULL); - TBM_RETURN_VAL_IF_FAIL (num == 1 || info->num_planes == num, NULL); - - struct _tbm_bufmgr *mgr; - struct _tbm_surface *surf = NULL; - int i; - - _tbm_surface_mutex_lock(); - - if (!g_surface_bufmgr) - { - _init_surface_bufmgr(); - LIST_INITHEAD (&g_surface_bufmgr->surf_list); - } - - mgr = g_surface_bufmgr; - if (!TBM_BUFMGR_IS_VALID(mgr)) - { - _tbm_surface_mutex_unlock(); - return NULL; - } - - surf = calloc (1, sizeof(struct _tbm_surface)); - if (!surf) - { - _tbm_surface_mutex_unlock(); - return NULL; - } - - surf->bufmgr = mgr; - surf->info.width = info->width; - surf->info.height = info->height; - surf->info.format = info->format; - surf->info.bpp = info->bpp; - surf->info.num_planes = info->num_planes; - surf->refcnt = 1; - - /* get size, stride and offset */ - for (i = 0; i < info->num_planes; i++) - { - surf->info.planes[i].offset = info->planes[i].offset; - surf->info.planes[i].stride = info->planes[i].stride; - - if (info->planes[i].size > 0) - surf->info.planes[i].size = info->planes[i].size; - else - surf->info.planes[i].size += surf->info.planes[i].stride * info->height; - - if (num == 1) - surf->planes_bo_idx[i] = 0; - else - surf->planes_bo_idx[i] = i; - } - - if (info->size > 0) - { - surf->info.size = info->size; - } - else - { - surf->info.size = 0; - for (i = 0; i < info->num_planes; i++) - { - surf->info.size += surf->info.planes[i].size; - } - } - - surf->flags = TBM_BO_DEFAULT; - - /* create only one bo */ - surf->num_bos = num; - for (i = 0; i < num; i++) - { - if (bos[i] == NULL) - goto bail1; - - surf->bos[i] = tbm_bo_ref(bos[i]); + TBM_RETURN_VAL_IF_FAIL(bos, NULL); + TBM_RETURN_VAL_IF_FAIL(info, NULL); + TBM_RETURN_VAL_IF_FAIL(num == 1 || info->num_planes == num, NULL); + + struct _tbm_bufmgr *mgr; + struct _tbm_surface *surf = NULL; + int i; + + _tbm_surface_mutex_lock(); + + if (!g_surface_bufmgr) { + _init_surface_bufmgr(); + LIST_INITHEAD(&g_surface_bufmgr->surf_list); + } + + mgr = g_surface_bufmgr; + if (!TBM_BUFMGR_IS_VALID(mgr)) { + _tbm_surface_mutex_unlock(); + return NULL; + } + + surf = calloc(1, sizeof(struct _tbm_surface)); + if (!surf) { + _tbm_surface_mutex_unlock(); + return NULL; + } + + surf->bufmgr = mgr; + surf->info.width = info->width; + surf->info.height = info->height; + surf->info.format = info->format; + surf->info.bpp = info->bpp; + surf->info.num_planes = info->num_planes; + surf->refcnt = 1; + + /* get size, stride and offset */ + for (i = 0; i < info->num_planes; i++) { + surf->info.planes[i].offset = info->planes[i].offset; + surf->info.planes[i].stride = info->planes[i].stride; + + if (info->planes[i].size > 0) + surf->info.planes[i].size = info->planes[i].size; + else + surf->info.planes[i].size += surf->info.planes[i].stride * info->height; + + if (num == 1) + surf->planes_bo_idx[i] = 0; + else + surf->planes_bo_idx[i] = i; + } + + if (info->size > 0) { + surf->info.size = info->size; + } else { + surf->info.size = 0; + for (i = 0; i < info->num_planes; i++) + surf->info.size += surf->info.planes[i].size; + } + + surf->flags = TBM_BO_DEFAULT; + + /* create only one bo */ + surf->num_bos = num; + for (i = 0; i < num; i++) { + if (bos[i] == NULL) + goto bail1; + + surf->bos[i] = tbm_bo_ref(bos[i]); _tbm_bo_set_surface(bos[i], surf); - } + } - LIST_ADD (&surf->item_link, &mgr->surf_list); + LIST_ADD(&surf->item_link, &mgr->surf_list); - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return surf; -bail1: - for (i = 0; i < num; i++) - { - if (surf->bos[i]) - { - tbm_bo_unref (surf->bos[i]); - surf->bos[i] = NULL; - } - } + return surf; + bail1: + for (i = 0; i < num; i++) { + if (surf->bos[i]) { + tbm_bo_unref(surf->bos[i]); + surf->bos[i] = NULL; + } + } - free (surf); - surf = NULL; + free(surf); + surf = NULL; - if(LIST_IS_EMPTY (&g_surface_bufmgr->surf_list)) - { - LIST_DELINIT (&g_surface_bufmgr->surf_list); - _deinit_surface_bufmgr (); - } + if (LIST_IS_EMPTY(&g_surface_bufmgr->surf_list)) { + LIST_DELINIT(&g_surface_bufmgr->surf_list); + _deinit_surface_bufmgr(); + } - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return NULL; + return NULL; } - -void -tbm_surface_internal_destroy (tbm_surface_h surface) +void tbm_surface_internal_destroy(tbm_surface_h surface) { - if (!surface) - return; + if (!surface) + return; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surface->refcnt--; + surface->refcnt--; - if (surface->refcnt > 0) { - _tbm_surface_mutex_unlock(); - return; - } + if (surface->refcnt > 0) { + _tbm_surface_mutex_unlock(); + return; + } - if (surface->refcnt == 0) - _tbm_surface_internal_destroy(surface); + if (surface->refcnt == 0) + _tbm_surface_internal_destroy(surface); - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); } - -void -tbm_surface_internal_ref (tbm_surface_h surface) +void tbm_surface_internal_ref(tbm_surface_h surface) { - TBM_RETURN_IF_FAIL (surface); + TBM_RETURN_IF_FAIL(surface); - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surface->refcnt++; + surface->refcnt++; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); } -void -tbm_surface_internal_unref (tbm_surface_h surface) +void tbm_surface_internal_unref(tbm_surface_h surface) { - TBM_RETURN_IF_FAIL (surface); + TBM_RETURN_IF_FAIL(surface); - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surface->refcnt--; + surface->refcnt--; - if (surface->refcnt > 0) { - _tbm_surface_mutex_unlock(); - return; - } + if (surface->refcnt > 0) { + _tbm_surface_mutex_unlock(); + return; + } - if (surface->refcnt == 0) - _tbm_surface_internal_destroy(surface); + if (surface->refcnt == 0) + _tbm_surface_internal_destroy(surface); - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); } -int -tbm_surface_internal_get_num_bos (tbm_surface_h surface) +int tbm_surface_internal_get_num_bos(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); + TBM_RETURN_VAL_IF_FAIL(surface, 0); - struct _tbm_surface *surf; - int num; + struct _tbm_surface *surf; + int num; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *) surface; - num = surf->num_bos; + surf = (struct _tbm_surface *)surface; + num = surf->num_bos; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return num; + return num; } -tbm_bo -tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx) +tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx) { - TBM_RETURN_VAL_IF_FAIL (surface, NULL); - TBM_RETURN_VAL_IF_FAIL (bo_idx > -1, NULL); + TBM_RETURN_VAL_IF_FAIL(surface, NULL); + TBM_RETURN_VAL_IF_FAIL(bo_idx > -1, NULL); - struct _tbm_surface *surf; - tbm_bo bo; + struct _tbm_surface *surf; + tbm_bo bo; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *) surface; - bo = surf->bos[bo_idx]; + surf = (struct _tbm_surface *)surface; + bo = surf->bos[bo_idx]; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return bo; + return bo; } -int -tbm_surface_internal_get_size (tbm_surface_h surface) +int tbm_surface_internal_get_size(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); + TBM_RETURN_VAL_IF_FAIL(surface, 0); - struct _tbm_surface *surf; - unsigned int size; + struct _tbm_surface *surf; + unsigned int size; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *) surface; - size = surf->info.size; + surf = (struct _tbm_surface *)surface; + size = surf->info.size; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return size; + return size; } -int -tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch) +int tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); - TBM_RETURN_VAL_IF_FAIL (plane_idx > -1, 0); + TBM_RETURN_VAL_IF_FAIL(surface, 0); + TBM_RETURN_VAL_IF_FAIL(plane_idx > -1, 0); - struct _tbm_surface *surf; + struct _tbm_surface *surf; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *) surface; + surf = (struct _tbm_surface *)surface; - if (plane_idx >= surf->info.num_planes) - { - _tbm_surface_mutex_unlock(); - return 0; - } + if (plane_idx >= surf->info.num_planes) { + _tbm_surface_mutex_unlock(); + return 0; + } - *size = surf->info.planes[plane_idx].size; - *offset = surf->info.planes[plane_idx].offset; - *pitch = surf->info.planes[plane_idx].stride; + *size = surf->info.planes[plane_idx].size; + *offset = surf->info.planes[plane_idx].offset; + *pitch = surf->info.planes[plane_idx].stride; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return 1; + return 1; } -int -tbm_surface_internal_get_info (tbm_surface_h surface, int opt, tbm_surface_info_s *info, int map) +int tbm_surface_internal_get_info(tbm_surface_h surface, int opt, tbm_surface_info_s * info, int map) { - struct _tbm_surface *surf; - tbm_bo_handle bo_handles[4]; - int i, j; - - _tbm_surface_mutex_lock(); - - memset (bo_handles, 0, sizeof(tbm_bo_handle) * 4); - - surf = (struct _tbm_surface *)surface; - - info->width = surf->info.width; - info->height = surf->info.height; - info->format = surf->info.format; - info->bpp = surf->info.bpp; - info->size = surf->info.size; - info->num_planes = surf->info.num_planes; - - if (map == 1) - { - for (i = 0; i < surf->num_bos; i++) - { - bo_handles[i] = tbm_bo_map (surf->bos[i], TBM_DEVICE_CPU, opt); - if (bo_handles[i].ptr == NULL) - { - for (j = 0; j < i; j++) - tbm_bo_unmap (surf->bos[j]); - - _tbm_surface_mutex_unlock(); - return 0; - } - } - } - else - { - for (i = 0; i < surf->num_bos; i++) - { - bo_handles[i] = tbm_bo_get_handle (surf->bos[i], TBM_DEVICE_CPU); - if (bo_handles[i].ptr == NULL) - { - _tbm_surface_mutex_unlock(); - return 0; - } - } - } - - for (i = 0; i < surf->info.num_planes; i++) - { - info->planes[i].size = surf->info.planes[i].size; - info->planes[i].offset = surf->info.planes[i].offset; - info->planes[i].stride = surf->info.planes[i].stride; - info->planes[i].ptr = bo_handles[surf->planes_bo_idx[i]].ptr + surf->info.planes[i].offset; - } - - _tbm_surface_mutex_unlock(); - - return 1; + struct _tbm_surface *surf; + tbm_bo_handle bo_handles[4]; + int i, j; + + _tbm_surface_mutex_lock(); + + memset(bo_handles, 0, sizeof(tbm_bo_handle) * 4); + + surf = (struct _tbm_surface *)surface; + + info->width = surf->info.width; + info->height = surf->info.height; + info->format = surf->info.format; + info->bpp = surf->info.bpp; + info->size = surf->info.size; + info->num_planes = surf->info.num_planes; + + if (map == 1) { + for (i = 0; i < surf->num_bos; i++) { + bo_handles[i] = tbm_bo_map(surf->bos[i], TBM_DEVICE_CPU, opt); + if (bo_handles[i].ptr == NULL) { + for (j = 0; j < i; j++) + tbm_bo_unmap(surf->bos[j]); + + _tbm_surface_mutex_unlock(); + return 0; + } + } + } else { + for (i = 0; i < surf->num_bos; i++) { + bo_handles[i] = tbm_bo_get_handle(surf->bos[i], TBM_DEVICE_CPU); + if (bo_handles[i].ptr == NULL) { + _tbm_surface_mutex_unlock(); + return 0; + } + } + } + + for (i = 0; i < surf->info.num_planes; i++) { + info->planes[i].size = surf->info.planes[i].size; + info->planes[i].offset = surf->info.planes[i].offset; + info->planes[i].stride = surf->info.planes[i].stride; + info->planes[i].ptr = bo_handles[surf->planes_bo_idx[i]].ptr + surf->info.planes[i].offset; + } + + _tbm_surface_mutex_unlock(); + + return 1; } -void -tbm_surface_internal_unmap (tbm_surface_h surface) +void tbm_surface_internal_unmap(tbm_surface_h surface) { - struct _tbm_surface *surf; - int i; + struct _tbm_surface *surf; + int i; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *)surface; + surf = (struct _tbm_surface *)surface; - for (i = 0; i < surf->num_bos; i++) - tbm_bo_unmap (surf->bos[i]); + for (i = 0; i < surf->num_bos; i++) + tbm_bo_unmap(surf->bos[i]); - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); } -unsigned int -tbm_surface_internal_get_width (tbm_surface_h surface) +unsigned int tbm_surface_internal_get_width(tbm_surface_h surface) { - struct _tbm_surface *surf; - unsigned int width; + struct _tbm_surface *surf; + unsigned int width; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *)surface; - width = surf->info.width; + surf = (struct _tbm_surface *)surface; + width = surf->info.width; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return width; + return width; } -unsigned int -tbm_surface_internal_get_height (tbm_surface_h surface) +unsigned int tbm_surface_internal_get_height(tbm_surface_h surface) { - struct _tbm_surface *surf; - unsigned int height; + struct _tbm_surface *surf; + unsigned int height; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *)surface; - height = surf->info.height; + surf = (struct _tbm_surface *)surface; + height = surf->info.height; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return height; + return height; } -tbm_format -tbm_surface_internal_get_format (tbm_surface_h surface) +tbm_format tbm_surface_internal_get_format(tbm_surface_h surface) { - struct _tbm_surface *surf; - tbm_format format; + struct _tbm_surface *surf; + tbm_format format; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *)surface; - format = surf->info.format; + surf = (struct _tbm_surface *)surface; + format = surf->info.format; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return format; + return format; } -int -tbm_surface_internal_get_plane_bo_idx (tbm_surface_h surface, int plane_idx) +int tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); - TBM_RETURN_VAL_IF_FAIL (plane_idx > -1, 0); - struct _tbm_surface *surf; - int bo_idx; + TBM_RETURN_VAL_IF_FAIL(surface, 0); + TBM_RETURN_VAL_IF_FAIL(plane_idx > -1, 0); + struct _tbm_surface *surf; + int bo_idx; - _tbm_surface_mutex_lock(); + _tbm_surface_mutex_lock(); - surf = (struct _tbm_surface *)surface; - bo_idx = surf->planes_bo_idx[plane_idx]; + surf = (struct _tbm_surface *)surface; + bo_idx = surf->planes_bo_idx[plane_idx]; - _tbm_surface_mutex_unlock(); + _tbm_surface_mutex_unlock(); - return bo_idx; + return bo_idx; } -unsigned int -_tbm_surface_internal_get_debug_pid(tbm_surface_h surface) +unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface, 0); + TBM_RETURN_VAL_IF_FAIL(surface, 0); return surface->debug_pid; } -void -tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid) +void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid) { - TBM_RETURN_IF_FAIL (surface); + TBM_RETURN_IF_FAIL(surface); surface->debug_pid = pid; } - diff --git a/src/tbm_surface_internal.h b/src/tbm_surface_internal.h old mode 100755 new mode 100644 index 6e9ae20..41d4996 --- a/src/tbm_surface_internal.h +++ b/src/tbm_surface_internal.h @@ -65,7 +65,7 @@ extern "C" { tbm_surface_bufmgr_deinit (bufmgr); @endcode */ -int tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *num); +int tbm_surface_internal_query_supported_formats(uint32_t ** formats, uint32_t * num); /** * @brief Creates the tbm_surface with memory type. @@ -103,7 +103,7 @@ int tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t * tbm_surface_bufmgr_deinit (bufmgr); @endcode */ -tbm_surface_h tbm_surface_internal_create_with_flags (int width, int height, int format, int flags); +tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags); /** * @brief Creates the tbm_surface with buffer objects. @@ -151,26 +151,25 @@ tbm_surface_h tbm_surface_internal_create_with_flags (int width, int height, int tbm_surface_bufmgr_deinit (bufmgr); @endcode */ -tbm_surface_h tbm_surface_internal_create_with_bos (tbm_surface_info_s *info, tbm_bo *bos, int num); - +tbm_surface_h tbm_surface_internal_create_with_bos(tbm_surface_info_s * info, tbm_bo * bos, int num); /** * @brief Destroy the tbm surface TODO: */ -void tbm_surface_internal_destroy (tbm_surface_h surface); +void tbm_surface_internal_destroy(tbm_surface_h surface); /** * @brief reference the tbm surface TODO: */ -void tbm_surface_internal_ref (tbm_surface_h surface); +void tbm_surface_internal_ref(tbm_surface_h surface); /** * @brief unreference the tbm surface TODO: */ -void tbm_surface_internal_unref (tbm_surface_h surface); +void tbm_surface_internal_unref(tbm_surface_h surface); /** * @brief Gets the number of buffer objects associated with the tbm_surface. @@ -193,7 +192,7 @@ void tbm_surface_internal_unref (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_internal_get_num_bos (tbm_surface_h surface); +int tbm_surface_internal_get_num_bos(tbm_surface_h surface); /** * @brief Gets the buffor object by the bo_index. @@ -223,7 +222,7 @@ int tbm_surface_internal_get_num_bos (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -tbm_bo tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx); +tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx); /** * @brief Gets the size of the surface. @@ -244,7 +243,7 @@ tbm_bo tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_internal_get_size (tbm_surface_h surface); +int tbm_surface_internal_get_size(tbm_surface_h surface); /** * @brief Gets size, offset and pitch data of plane by the plane_index. @@ -272,7 +271,7 @@ int tbm_surface_internal_get_size (tbm_surface_h surface); tbm_surface_destroy (surface); @endcode */ -int tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch); +int tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch); /** * @brief Gets number of planes by the format. @@ -292,7 +291,7 @@ int tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, u @endcode */ -int tbm_surface_internal_get_num_planes (tbm_format format); +int tbm_surface_internal_get_num_planes(tbm_format format); /** * @brief Gets bpp by the format. @@ -312,7 +311,7 @@ int tbm_surface_internal_get_num_planes (tbm_format format); @endcode */ -int tbm_surface_internal_get_bpp (tbm_format format); +int tbm_surface_internal_get_bpp(tbm_format format); /** * @brief Gets bo index of plane. @@ -335,7 +334,7 @@ int tbm_surface_internal_get_bpp (tbm_format format); @endcode */ -int tbm_surface_internal_get_plane_bo_idx (tbm_surface_h surface, int plane_idx); +int tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx); /** * @brief Set the pid to the tbm_surface for debugging. @@ -348,6 +347,4 @@ void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid) #ifdef __cplusplus } #endif - -#endif /* _TBM_SURFACE_INTERNAL_H_ */ - +#endif /* _TBM_SURFACE_INTERNAL_H_ */ diff --git a/src/tbm_surface_queue.c b/src/tbm_surface_queue.c index 1ee649a..ffc09d3 100644 --- a/src/tbm_surface_queue.c +++ b/src/tbm_surface_queue.c @@ -32,547 +32,494 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tbm_bufmgr_int.h" #include "list.h" -typedef struct -{ - struct list_head head; +typedef struct { + struct list_head head; - struct list_head tail; + struct list_head tail; - int count; + int count; } queue; -typedef struct -{ - tbm_surface_h surface; +typedef struct { + tbm_surface_h surface; - struct list_head item_link; + struct list_head item_link; } queue_node; -struct _tbm_surface_queue -{ - int width; - int height; - int format; - int size; - int flags; +struct _tbm_surface_queue { + int width; + int height; + int format; + int size; + int flags; - queue free_queue; - queue duty_queue; - queue_node **node_list; + queue free_queue; + queue duty_queue; + queue_node **node_list; - tbm_surface_queue_notify_cb destroy_cb; - void *destroy_cb_data; + tbm_surface_queue_notify_cb destroy_cb; + void *destroy_cb_data; - tbm_surface_queue_notify_cb dequeuable_cb; - void *dequeuable_cb_data; + tbm_surface_queue_notify_cb dequeuable_cb; + void *dequeuable_cb_data; - tbm_surface_queue_notify_cb acquirable_cb; - void *acquirable_cb_data; + tbm_surface_queue_notify_cb acquirable_cb; + void *acquirable_cb_data; - tbm_surface_queue_notify_cb reset_cb; - void *reset_cb_data; + tbm_surface_queue_notify_cb reset_cb; + void *reset_cb_data; - pthread_mutex_t lock; - pthread_cond_t free_cond; - pthread_cond_t duty_cond; + pthread_mutex_t lock; + pthread_cond_t free_cond; + pthread_cond_t duty_cond; }; -static queue_node * -_queue_node_create (void) +static queue_node *_queue_node_create(void) { - queue_node *node = (queue_node *) calloc (1, sizeof(queue_node)); - TBM_RETURN_VAL_IF_FAIL (node != NULL, NULL); + queue_node *node = (queue_node *) calloc(1, sizeof(queue_node)); + TBM_RETURN_VAL_IF_FAIL(node != NULL, NULL); - return node; + return node; } -static void -_queue_node_delete (queue_node *node) +static void _queue_node_delete(queue_node * node) { - if (node->surface) - tbm_surface_destroy (node->surface); - LIST_DEL (&node->item_link); - free (node); + if (node->surface) + tbm_surface_destroy(node->surface); + LIST_DEL(&node->item_link); + free(node); } -static int -_queue_is_empty (queue *queue) +static int _queue_is_empty(queue * queue) { - if (queue->head.next == &queue->tail) - return 1; + if (queue->head.next == &queue->tail) + return 1; - return 0; + return 0; } -static void -_queue_node_push_back (queue *queue, queue_node *node) +static void _queue_node_push_back(queue * queue, queue_node * node) { - LIST_ADDTAIL (&node->item_link, &queue->tail); - queue->count++; - return; + LIST_ADDTAIL(&node->item_link, &queue->tail); + queue->count++; + return; } -static void -_queue_node_push_front (queue *queue, queue_node *node) +static void _queue_node_push_front(queue * queue, queue_node * node) { - LIST_ADD (&node->item_link, &queue->head); - queue->count++; - return; + LIST_ADD(&node->item_link, &queue->head); + queue->count++; + return; } -static queue_node * -_queue_node_pop_front (queue *queue) +static queue_node *_queue_node_pop_front(queue * queue) { - queue_node *node = NULL; + queue_node *node = NULL; - node = LIST_ENTRY (queue_node, queue->head.next, item_link); + node = LIST_ENTRY(queue_node, queue->head.next, item_link); - LIST_DEL (&node->item_link); - queue->count--; + LIST_DEL(&node->item_link); + queue->count--; - return node; + return node; } -static int -_queue_node_exist_in_queue (queue *queue, queue_node *node) +static int _queue_node_exist_in_queue(queue * queue, queue_node * node) { - queue_node *search_node = NULL; - queue_node *temp = NULL; - - if (!_queue_is_empty(queue)) - { - LIST_FOR_EACH_ENTRY_SAFE (search_node, temp, &queue->head, item_link) - { - if (search_node == node) - return 1; - } - } - - return 0; + queue_node *search_node = NULL; + queue_node *temp = NULL; + + if (!_queue_is_empty(queue)) { + LIST_FOR_EACH_ENTRY_SAFE(search_node, temp, &queue->head, item_link) { + if (search_node == node) + return 1; + } + } + + return 0; } -static void -_queue_init (queue *queue) +static void _queue_init(queue * queue) { - LIST_INITHEAD (&queue->head); - LIST_INITHEAD (&queue->tail); - LIST_ADDTAIL (&queue->head, &queue->tail); - queue->count = 0; + LIST_INITHEAD(&queue->head); + LIST_INITHEAD(&queue->tail); + LIST_ADDTAIL(&queue->head, &queue->tail); + queue->count = 0; } -tbm_surface_queue_error_e -tbm_surface_queue_enqueue (tbm_surface_queue_h surface_queue, tbm_surface_h surface) +tbm_surface_queue_error_e tbm_surface_queue_enqueue(tbm_surface_queue_h surface_queue, tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE); - int i; + int i; - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - for (i = 0 ; i < surface_queue->size ; i++) - { - if (surface_queue->node_list[i]->surface == surface) - break; - } + for (i = 0; i < surface_queue->size; i++) { + if (surface_queue->node_list[i]->surface == surface) + break; + } - if (i == surface_queue->size) - { - TBM_LOG ("Can't find the surface in queue\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; - } + if (i == surface_queue->size) { + TBM_LOG("Can't find the surface in queue\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; + } - if (_queue_node_exist_in_queue (&surface_queue->duty_queue, surface_queue->node_list[i])) - { - TBM_LOG ("Surface exist in queue\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; - } + if (_queue_node_exist_in_queue(&surface_queue->duty_queue, surface_queue->node_list[i])) { + TBM_LOG("Surface exist in queue\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; + } - _queue_node_push_back(&surface_queue->duty_queue, surface_queue->node_list[i]); + _queue_node_push_back(&surface_queue->duty_queue, surface_queue->node_list[i]); - pthread_mutex_unlock (&surface_queue->lock); - pthread_cond_signal(&surface_queue->duty_cond); + pthread_mutex_unlock(&surface_queue->lock); + pthread_cond_signal(&surface_queue->duty_cond); - if (surface_queue->acquirable_cb) - surface_queue->acquirable_cb(surface_queue, surface_queue->acquirable_cb_data); + if (surface_queue->acquirable_cb) + surface_queue->acquirable_cb(surface_queue, surface_queue->acquirable_cb_data); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } -tbm_surface_queue_error_e -tbm_surface_queue_dequeue (tbm_surface_queue_h surface_queue, tbm_surface_h *surface) +tbm_surface_queue_error_e tbm_surface_queue_dequeue(tbm_surface_queue_h surface_queue, tbm_surface_h * surface) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - TBM_RETURN_VAL_IF_FAIL (surface_queue->free_queue.count > 0, TBM_SURFACE_QUEUE_ERROR_EMPTY); - - pthread_mutex_lock (&surface_queue->lock); - - if (_queue_is_empty (&surface_queue->free_queue)) - { - TBM_LOG ("Surface queue is empty\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_EMPTY; - } - - queue_node *node = NULL; - - node = _queue_node_pop_front (&surface_queue->free_queue); - if (node == NULL) - { - TBM_LOG ("_queue_node_pop_front is failed\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE; - } - - if (!node->surface) - { - tbm_surface_h surface = tbm_surface_internal_create_with_flags (surface_queue->width, - surface_queue->height, - surface_queue->format, - surface_queue->flags); - if (surface == NULL) - { - TBM_LOG ("tbm surface create failed"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED; - } - node->surface = surface; - } - - *surface = node->surface; - - pthread_mutex_unlock (&surface_queue->lock); - - return TBM_SURFACE_QUEUE_ERROR_NONE; + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue->free_queue.count > 0, TBM_SURFACE_QUEUE_ERROR_EMPTY); + + pthread_mutex_lock(&surface_queue->lock); + + if (_queue_is_empty(&surface_queue->free_queue)) { + TBM_LOG("Surface queue is empty\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_EMPTY; + } + + queue_node *node = NULL; + + node = _queue_node_pop_front(&surface_queue->free_queue); + if (node == NULL) { + TBM_LOG("_queue_node_pop_front is failed\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE; + } + + if (!node->surface) { + tbm_surface_h surface = tbm_surface_internal_create_with_flags(surface_queue->width, + surface_queue->height, + surface_queue->format, + surface_queue->flags); + if (surface == NULL) { + TBM_LOG("tbm surface create failed"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED; + } + node->surface = surface; + } + + *surface = node->surface; + + pthread_mutex_unlock(&surface_queue->lock); + + return TBM_SURFACE_QUEUE_ERROR_NONE; } -tbm_surface_queue_error_e -tbm_surface_queue_release (tbm_surface_queue_h surface_queue, tbm_surface_h surface) +tbm_surface_queue_error_e tbm_surface_queue_release(tbm_surface_queue_h surface_queue, tbm_surface_h surface) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE); - - pthread_mutex_lock (&surface_queue->lock); - - int i; - for (i = 0 ; i < surface_queue->size ; i++) - { - if (surface_queue->node_list[i]->surface == surface) - break; - } - if (i == surface_queue->size) - { - TBM_LOG ("Can't find the surface in queue\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; - } - - if (_queue_node_exist_in_queue (&surface_queue->free_queue, surface_queue->node_list[i])) - { - TBM_LOG ("Surface exist in queue\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; - } - - _queue_node_push_front(&surface_queue->free_queue, surface_queue->node_list[i]); - - pthread_mutex_unlock (&surface_queue->lock); - pthread_cond_signal(&surface_queue->free_cond); - - if (surface_queue->dequeuable_cb) - surface_queue->dequeuable_cb (surface_queue, surface_queue->dequeuable_cb_data); - - return TBM_SURFACE_QUEUE_ERROR_NONE; + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE); + + pthread_mutex_lock(&surface_queue->lock); + + int i; + for (i = 0; i < surface_queue->size; i++) { + if (surface_queue->node_list[i]->surface == surface) + break; + } + if (i == surface_queue->size) { + TBM_LOG("Can't find the surface in queue\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; + } + + if (_queue_node_exist_in_queue(&surface_queue->free_queue, surface_queue->node_list[i])) { + TBM_LOG("Surface exist in queue\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; + } + + _queue_node_push_front(&surface_queue->free_queue, surface_queue->node_list[i]); + + pthread_mutex_unlock(&surface_queue->lock); + pthread_cond_signal(&surface_queue->free_cond); + + if (surface_queue->dequeuable_cb) + surface_queue->dequeuable_cb(surface_queue, surface_queue->dequeuable_cb_data); + + return TBM_SURFACE_QUEUE_ERROR_NONE; } -tbm_surface_queue_error_e -tbm_surface_queue_acquire (tbm_surface_queue_h surface_queue, tbm_surface_h *surface) +tbm_surface_queue_error_e tbm_surface_queue_acquire(tbm_surface_queue_h surface_queue, tbm_surface_h * surface) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - TBM_RETURN_VAL_IF_FAIL (surface_queue->duty_queue.count > 0, TBM_SURFACE_QUEUE_ERROR_EMPTY); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue->duty_queue.count > 0, TBM_SURFACE_QUEUE_ERROR_EMPTY); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - if (_queue_is_empty (&surface_queue->duty_queue)) - { - TBM_LOG ("Surface queue is empty\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_EMPTY; - } + if (_queue_is_empty(&surface_queue->duty_queue)) { + TBM_LOG("Surface queue is empty\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_EMPTY; + } - queue_node *node = NULL; + queue_node *node = NULL; - node = _queue_node_pop_front (&surface_queue->duty_queue); - if (node == NULL) - { - TBM_LOG ("_queue_node_pop_front failed\n"); - pthread_mutex_unlock (&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE; - } + node = _queue_node_pop_front(&surface_queue->duty_queue); + if (node == NULL) { + TBM_LOG("_queue_node_pop_front failed\n"); + pthread_mutex_unlock(&surface_queue->lock); + return TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE; + } - *surface = node->surface; + *surface = node->surface; - pthread_mutex_unlock (&surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } -int -tbm_surface_queue_can_dequeue (tbm_surface_queue_h surface_queue, int wait) +int tbm_surface_queue_can_dequeue(tbm_surface_queue_h surface_queue, int wait) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, 0); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - if (_queue_is_empty (&surface_queue->free_queue)) - { - if (wait) - { - pthread_cond_wait (&surface_queue->free_cond, &surface_queue->lock); - pthread_mutex_unlock (&surface_queue->lock); - return 1; - } + if (_queue_is_empty(&surface_queue->free_queue)) { + if (wait) { + pthread_cond_wait(&surface_queue->free_cond, &surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); + return 1; + } - pthread_mutex_unlock (&surface_queue->lock); - return 0; - } + pthread_mutex_unlock(&surface_queue->lock); + return 0; + } - pthread_mutex_unlock (&surface_queue->lock); - return 1; + pthread_mutex_unlock(&surface_queue->lock); + return 1; } -int -tbm_surface_queue_can_acquire (tbm_surface_queue_h surface_queue, int wait) +int tbm_surface_queue_can_acquire(tbm_surface_queue_h surface_queue, int wait) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, 0); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - if (_queue_is_empty (&surface_queue->duty_queue)) - { - if (wait) - { - pthread_cond_wait (&surface_queue->duty_cond, &surface_queue->lock); - pthread_mutex_unlock (&surface_queue->lock); - return 1; - } + if (_queue_is_empty(&surface_queue->duty_queue)) { + if (wait) { + pthread_cond_wait(&surface_queue->duty_cond, &surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); + return 1; + } - pthread_mutex_unlock (&surface_queue->lock); - return 0; - } + pthread_mutex_unlock(&surface_queue->lock); + return 0; + } - pthread_mutex_unlock (&surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); - return 1; + return 1; } -tbm_surface_queue_h -tbm_surface_queue_create(int queue_size, int width, int height, int format, int flags) +tbm_surface_queue_h tbm_surface_queue_create(int queue_size, int width, int height, int format, int flags) { - TBM_RETURN_VAL_IF_FAIL (queue_size > 0, NULL); - TBM_RETURN_VAL_IF_FAIL (width > 0, NULL); - TBM_RETURN_VAL_IF_FAIL (height > 0, NULL); - TBM_RETURN_VAL_IF_FAIL (format > 0, NULL); - - int i, j; - tbm_surface_queue_h surface_queue = (tbm_surface_queue_h)calloc(1, sizeof(struct _tbm_surface_queue)); - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, NULL); - - pthread_mutex_init (&surface_queue->lock, NULL); - pthread_cond_init (&surface_queue->free_cond, NULL); - pthread_cond_init (&surface_queue->duty_cond, NULL); - - surface_queue->width = width; - surface_queue->height = height; - surface_queue->format = format; - surface_queue->flags = flags; - surface_queue->size = queue_size; - surface_queue->node_list = (queue_node **)calloc(queue_size, sizeof(queue_node *)); - if (!surface_queue->node_list) - { - TBM_LOG ("surface node list alloc failed"); - free (surface_queue); - pthread_mutex_destroy (&surface_queue->lock); - return NULL; - } - - _queue_init (&surface_queue->free_queue); - _queue_init (&surface_queue->duty_queue); - - for (i = 0 ; i < queue_size; i++) - { - queue_node *node = _queue_node_create(); - if (node == NULL) - { - TBM_LOG ("surface node create failed"); - goto fail; - } - - surface_queue->node_list[i] = node; - _queue_node_push_back (&surface_queue->free_queue, node); - } - - return surface_queue; - -fail: - for (j = 0 ; j < i ; j++) - _queue_node_delete (surface_queue->node_list[j]); - - free (surface_queue->node_list); - free (surface_queue); - pthread_mutex_destroy (&surface_queue->lock); - - return NULL; + TBM_RETURN_VAL_IF_FAIL(queue_size > 0, NULL); + TBM_RETURN_VAL_IF_FAIL(width > 0, NULL); + TBM_RETURN_VAL_IF_FAIL(height > 0, NULL); + TBM_RETURN_VAL_IF_FAIL(format > 0, NULL); + + int i, j; + tbm_surface_queue_h surface_queue = (tbm_surface_queue_h) calloc(1, sizeof(struct _tbm_surface_queue)); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, NULL); + + pthread_mutex_init(&surface_queue->lock, NULL); + pthread_cond_init(&surface_queue->free_cond, NULL); + pthread_cond_init(&surface_queue->duty_cond, NULL); + + surface_queue->width = width; + surface_queue->height = height; + surface_queue->format = format; + surface_queue->flags = flags; + surface_queue->size = queue_size; + surface_queue->node_list = (queue_node **) calloc(queue_size, sizeof(queue_node *)); + if (!surface_queue->node_list) { + TBM_LOG("surface node list alloc failed"); + free(surface_queue); + pthread_mutex_destroy(&surface_queue->lock); + return NULL; + } + + _queue_init(&surface_queue->free_queue); + _queue_init(&surface_queue->duty_queue); + + for (i = 0; i < queue_size; i++) { + queue_node *node = _queue_node_create(); + if (node == NULL) { + TBM_LOG("surface node create failed"); + goto fail; + } + + surface_queue->node_list[i] = node; + _queue_node_push_back(&surface_queue->free_queue, node); + } + + return surface_queue; + + fail: + for (j = 0; j < i; j++) + _queue_node_delete(surface_queue->node_list[j]); + + free(surface_queue->node_list); + free(surface_queue); + pthread_mutex_destroy(&surface_queue->lock); + + return NULL; } -void -tbm_surface_queue_destroy (tbm_surface_queue_h surface_queue) +void tbm_surface_queue_destroy(tbm_surface_queue_h surface_queue) { - TBM_RETURN_IF_FAIL (surface_queue != NULL); + TBM_RETURN_IF_FAIL(surface_queue != NULL); - if (surface_queue->destroy_cb) - surface_queue->destroy_cb (surface_queue, surface_queue->destroy_cb_data); + if (surface_queue->destroy_cb) + surface_queue->destroy_cb(surface_queue, surface_queue->destroy_cb_data); - int i; + int i; - for (i = 0 ; i < surface_queue->size ; i++) - _queue_node_delete (surface_queue->node_list[i]); + for (i = 0; i < surface_queue->size; i++) + _queue_node_delete(surface_queue->node_list[i]); - free (surface_queue->node_list); - free (surface_queue); + free(surface_queue->node_list); + free(surface_queue); } -tbm_surface_queue_error_e -tbm_surface_queue_set_destroy_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, void *data) +tbm_surface_queue_error_e tbm_surface_queue_set_destroy_cb(tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, void *data) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - surface_queue->destroy_cb = destroy_cb; - surface_queue->destroy_cb_data = data; + surface_queue->destroy_cb = destroy_cb; + surface_queue->destroy_cb_data = data; - pthread_mutex_unlock (&surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } -tbm_surface_queue_error_e -tbm_surface_queue_set_dequeuable_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb dequeuable_cb, void *data) +tbm_surface_queue_error_e tbm_surface_queue_set_dequeuable_cb(tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb dequeuable_cb, void *data) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - surface_queue->dequeuable_cb = dequeuable_cb; - surface_queue->dequeuable_cb_data = data; + surface_queue->dequeuable_cb = dequeuable_cb; + surface_queue->dequeuable_cb_data = data; - pthread_mutex_unlock (&surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } -tbm_surface_queue_error_e -tbm_surface_queue_set_acquirable_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, void *data) +tbm_surface_queue_error_e tbm_surface_queue_set_acquirable_cb(tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, void *data) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - surface_queue->acquirable_cb = acquirable_cb; - surface_queue->acquirable_cb_data = data; + surface_queue->acquirable_cb = acquirable_cb; + surface_queue->acquirable_cb_data = data; - pthread_mutex_unlock (&surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } -int -tbm_surface_queue_get_queue_size (tbm_surface_queue_h surface_queue) +int tbm_surface_queue_get_queue_size(tbm_surface_queue_h surface_queue) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, 0); - return surface_queue->size; + return surface_queue->size; } -int -tbm_surface_queue_get_width(tbm_surface_queue_h surface_queue) +int tbm_surface_queue_get_width(tbm_surface_queue_h surface_queue) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, 0); - return surface_queue->width; + return surface_queue->width; } -int -tbm_surface_queue_get_height(tbm_surface_queue_h surface_queue) +int tbm_surface_queue_get_height(tbm_surface_queue_h surface_queue) { - return surface_queue->height; + return surface_queue->height; } -int -tbm_surface_queue_get_format(tbm_surface_queue_h surface_queue) +int tbm_surface_queue_get_format(tbm_surface_queue_h surface_queue) { - return surface_queue->format; + return surface_queue->format; } -tbm_surface_queue_error_e -tbm_surface_queue_reset(tbm_surface_queue_h surface_queue, int width, int height, int format) +tbm_surface_queue_error_e tbm_surface_queue_reset(tbm_surface_queue_h surface_queue, int width, int height, int format) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - int i; - queue_node *node = NULL; + int i; + queue_node *node = NULL; - if (width == surface_queue->width && - height == surface_queue->height && - format == surface_queue->format) - return TBM_SURFACE_QUEUE_ERROR_NONE; + if (width == surface_queue->width && height == surface_queue->height && format == surface_queue->format) + return TBM_SURFACE_QUEUE_ERROR_NONE; - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - surface_queue->width = width; - surface_queue->height = height; - surface_queue->format = format; + surface_queue->width = width; + surface_queue->height = height; + surface_queue->format = format; - //Reset queue - _queue_init(&surface_queue->free_queue); - _queue_init(&surface_queue->duty_queue); + /* Reset queue */ + _queue_init(&surface_queue->free_queue); + _queue_init(&surface_queue->duty_queue); - //Destory surface and Push to free_queue - for (i = 0 ; i < surface_queue->size; i++) - { - node = surface_queue->node_list[i]; - if (node->surface) - { - tbm_surface_destroy(node->surface); - node->surface = NULL; - } + /* Destory surface and Push to free_queue */ + for (i = 0; i < surface_queue->size; i++) { + node = surface_queue->node_list[i]; + if (node->surface) { + tbm_surface_destroy(node->surface); + node->surface = NULL; + } - _queue_node_push_back(&surface_queue->free_queue, node); - } + _queue_node_push_back(&surface_queue->free_queue, node); + } - pthread_mutex_unlock (&surface_queue->lock); - pthread_cond_signal(&surface_queue->free_cond); + pthread_mutex_unlock(&surface_queue->lock); + pthread_cond_signal(&surface_queue->free_cond); - if (surface_queue->reset_cb) - surface_queue->reset_cb (surface_queue, surface_queue->reset_cb_data); + if (surface_queue->reset_cb) + surface_queue->reset_cb(surface_queue, surface_queue->reset_cb_data); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } -tbm_surface_queue_error_e -tbm_surface_queue_set_reset_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, void *data) +tbm_surface_queue_error_e tbm_surface_queue_set_reset_cb(tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, void *data) { - TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_RETURN_VAL_IF_FAIL(surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); - pthread_mutex_lock (&surface_queue->lock); + pthread_mutex_lock(&surface_queue->lock); - surface_queue->reset_cb = reset_cb; - surface_queue->reset_cb_data = data; + surface_queue->reset_cb = reset_cb; + surface_queue->reset_cb_data = data; - pthread_mutex_unlock (&surface_queue->lock); + pthread_mutex_unlock(&surface_queue->lock); - return TBM_SURFACE_QUEUE_ERROR_NONE; + return TBM_SURFACE_QUEUE_ERROR_NONE; } diff --git a/src/tbm_surface_queue.h b/src/tbm_surface_queue.h index 28824ef..d61b759 100644 --- a/src/tbm_surface_queue.h +++ b/src/tbm_surface_queue.h @@ -34,19 +34,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -typedef enum -{ - TBM_SURFACE_QUEUE_ERROR_NONE = 0, /**< Successful */ - TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE = -1, - TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE = -2, - TBM_SURFACE_QUEUE_ERROR_EMPTY = -3, - TBM_SURFACE_QUEUE_ERROR_INVALID_PARAMETER = -4, - TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED = -5, +typedef enum { + TBM_SURFACE_QUEUE_ERROR_NONE = 0, /**< Successful */ + TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE = -1, + TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE = -2, + TBM_SURFACE_QUEUE_ERROR_EMPTY = -3, + TBM_SURFACE_QUEUE_ERROR_INVALID_PARAMETER = -4, + TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED = -5, } tbm_surface_queue_error_e; typedef struct _tbm_surface_queue *tbm_surface_queue_h; -typedef void (* tbm_surface_queue_notify_cb) (tbm_surface_queue_h surface_queue, void* data); +typedef void (*tbm_surface_queue_notify_cb) (tbm_surface_queue_h surface_queue, void *data); #ifdef __cplusplus extern "C" { @@ -54,11 +53,11 @@ extern "C" { tbm_surface_queue_error_e tbm_surface_queue_enqueue(tbm_surface_queue_h surface_queue, tbm_surface_h surface); -tbm_surface_queue_error_e tbm_surface_queue_dequeue(tbm_surface_queue_h surface_queue, tbm_surface_h *surface); +tbm_surface_queue_error_e tbm_surface_queue_dequeue(tbm_surface_queue_h surface_queue, tbm_surface_h * surface); tbm_surface_queue_error_e tbm_surface_queue_release(tbm_surface_queue_h surface_queue, tbm_surface_h surface); -tbm_surface_queue_error_e tbm_surface_queue_acquire(tbm_surface_queue_h surface_queue, tbm_surface_h *surface); +tbm_surface_queue_error_e tbm_surface_queue_acquire(tbm_surface_queue_h surface_queue, tbm_surface_h * surface); int tbm_surface_queue_can_dequeue(tbm_surface_queue_h surface_queue, int wait); @@ -84,12 +83,9 @@ int tbm_surface_queue_get_format(tbm_surface_queue_h surface_queue); tbm_surface_queue_error_e tbm_surface_queue_reset(tbm_surface_queue_h surface_queue, int width, int height, int format); -tbm_surface_queue_error_e tbm_surface_queue_set_reset_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, void *data); - +tbm_surface_queue_error_e tbm_surface_queue_set_reset_cb(tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, void *data); #ifdef __cplusplus } #endif - -#endif /* _TBM_SURFACE_H_ */ - +#endif /* _TBM_SURFACE_H_ */ diff --git a/src/tbm_type.h b/src/tbm_type.h index 51794c8..360675e 100644 --- a/src/tbm_type.h +++ b/src/tbm_type.h @@ -44,7 +44,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * @brief Definition for the Tizen buffer surface. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef struct _tbm_surface * tbm_surface_h; +typedef struct _tbm_surface *tbm_surface_h; /** * @brief Definition for the Tizen buffer surface format. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -55,5 +55,4 @@ typedef uint32_t tbm_format; * @} */ -#endif /* _TBM_TYPE_H_ */ - +#endif /* _TBM_TYPE_H_ */ diff --git a/src/tbm_wayland.c b/src/tbm_wayland.c index a2f6a57..40c0685 100644 --- a/src/tbm_wayland.c +++ b/src/tbm_wayland.c @@ -43,63 +43,63 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. extern const struct wl_interface wl_buffer_interface; static const struct wl_interface *types[] = { - NULL, - NULL, - NULL, - &wl_buffer_interface, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - &wl_buffer_interface, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, + NULL, + NULL, + NULL, + &wl_buffer_interface, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &wl_buffer_interface, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, }; static const struct wl_message wl_tbm_requests[] = { - { "create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3 }, - { "create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22 }, - { "get_authentication_info", "", types + 0 }, + {"create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3}, + {"create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22}, + {"get_authentication_info", "", types + 0}, }; static const struct wl_message wl_tbm_events[] = { - { "authentication_info", "suh", types + 0 }, + {"authentication_info", "suh", types + 0}, }; WL_EXPORT const struct wl_interface wl_tbm_interface = { - "wl_tbm", 1, - 3, wl_tbm_requests, - 1, wl_tbm_events, + "wl_tbm", 1, + 3, wl_tbm_requests, + 1, wl_tbm_events, }; struct wl_buffer; @@ -110,193 +110,168 @@ extern const struct wl_interface wl_tbm_interface; #ifndef WL_TBM_ERROR_ENUM #define WL_TBM_ERROR_ENUM enum wl_tbm_error { - WL_TBM_ERROR_AUTHENTICATE_FAIL = 0, - WL_TBM_ERROR_INVALID_FORMAT = 1, - WL_TBM_ERROR_INVALID_NAME = 2, + WL_TBM_ERROR_AUTHENTICATE_FAIL = 0, + WL_TBM_ERROR_INVALID_FORMAT = 1, + WL_TBM_ERROR_INVALID_NAME = 2, }; -#endif /* WL_TBM_ERROR_ENUM */ +#endif /* WL_TBM_ERROR_ENUM */ struct wl_tbm_listener { - /** + /** * authentication_info - (none) * @device_name: (none) * @capabilities: (none) * @auth_fd: (none) */ - void (*authentication_info)(void *data, - struct wl_tbm *wl_tbm, - const char *device_name, - uint32_t capabilities, - int32_t auth_fd); + void (*authentication_info) (void *data, struct wl_tbm * wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd); }; -static inline int -wl_tbm_add_listener(struct wl_tbm *wl_tbm, - const struct wl_tbm_listener *listener, void *data) +static inline int wl_tbm_add_listener(struct wl_tbm *wl_tbm, const struct wl_tbm_listener *listener, void *data) { - return wl_proxy_add_listener((struct wl_proxy *) wl_tbm, - (void (**)(void)) listener, data); + return wl_proxy_add_listener((struct wl_proxy *)wl_tbm, (void (**)(void))listener, data); } #define WL_TBM_CREATE_BUFFER 0 #define WL_TBM_CREATE_BUFFER_WITH_FD 1 #define WL_TBM_GET_AUTHENTICATION_INFO 2 -static inline void -wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data) +static inline void wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data) { - wl_proxy_set_user_data((struct wl_proxy *) wl_tbm, user_data); + wl_proxy_set_user_data((struct wl_proxy *)wl_tbm, user_data); } -static inline void * -wl_tbm_get_user_data(struct wl_tbm *wl_tbm) +static inline void *wl_tbm_get_user_data(struct wl_tbm *wl_tbm) { - return wl_proxy_get_user_data((struct wl_proxy *) wl_tbm); + return wl_proxy_get_user_data((struct wl_proxy *)wl_tbm); } -static inline void -wl_tbm_destroy(struct wl_tbm *wl_tbm) +static inline void wl_tbm_destroy(struct wl_tbm *wl_tbm) { - wl_proxy_destroy((struct wl_proxy *) wl_tbm); + wl_proxy_destroy((struct wl_proxy *)wl_tbm); } -static inline void -wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm) +static inline void wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm) { - wl_proxy_marshal((struct wl_proxy *) wl_tbm, - WL_TBM_GET_AUTHENTICATION_INFO); + wl_proxy_marshal((struct wl_proxy *)wl_tbm, WL_TBM_GET_AUTHENTICATION_INFO); } -struct wl_tbm_info -{ - struct wl_display* dpy; - struct wl_event_queue *wl_queue; - struct wl_tbm* wl_tbm; +struct wl_tbm_info { + struct wl_display *dpy; + struct wl_event_queue *wl_queue; + struct wl_tbm *wl_tbm; - uint32_t capabilities; - char *device; - int32_t fd; + uint32_t capabilities; + char *device; + int32_t fd; }; -static void -handle_tbm_authentication_info(void *data, - struct wl_tbm *wl_tbm, - const char *device_name, - uint32_t capabilities, - int32_t auth_fd) +static void handle_tbm_authentication_info(void *data, struct wl_tbm *wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd) { - struct wl_tbm_info *info = (struct wl_tbm_info *)data; + struct wl_tbm_info *info = (struct wl_tbm_info *)data; - info->fd = auth_fd; - info->capabilities = capabilities; - if (device_name) - info->device = strndup(device_name, 256); + info->fd = auth_fd; + info->capabilities = capabilities; + if (device_name) + info->device = strndup(device_name, 256); } static const struct wl_tbm_listener wl_tbm_client_listener = { - handle_tbm_authentication_info + handle_tbm_authentication_info }; static void wl_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - struct wl_tbm_info *info = (struct wl_tbm_info *)data; - - if (!strcmp(interface, "wl_tbm")) - { - info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version); - if (!info->wl_tbm) - { - printf("Failed to bind wl_tbm\n"); - return; - } - - wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info); - wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue); - } + struct wl_tbm_info *info = (struct wl_tbm_info *)data; + + if (!strcmp(interface, "wl_tbm")) { + info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version); + if (!info->wl_tbm) { + printf("Failed to bind wl_tbm\n"); + return; + } + + wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info); + wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue); + } } static int tbm_util_get_drm_fd(void *dpy, int *fd) { - struct wl_display *disp = NULL; - struct wl_registry *wl_registry; - struct wl_tbm_info info = { - .dpy = NULL, - .wl_queue = NULL, - .wl_tbm = NULL, - .capabilities = 0, - .device = NULL, - .fd = 0, - }; - - static const struct wl_registry_listener registry_listener = { - wl_client_registry_handle_global, - NULL - }; - - if (!fd) { - return -1; - } - - if (!dpy) { - disp = wl_display_connect(NULL); - if (!disp) { - printf("Failed to create a new display connection\n"); - return -1; - } - dpy = disp; - } - - info.dpy = dpy; - info.wl_queue = wl_display_create_queue(dpy); - if (!info.wl_queue) { - printf("Failed to create a WL Queue\n"); - if (disp == dpy) { - wl_display_disconnect(disp); - } - return -1; - } - - wl_registry = wl_display_get_registry(dpy); - if (!wl_registry) { - printf("Failed to get registry\n"); - wl_event_queue_destroy(info.wl_queue); - if (disp == dpy) { - wl_display_disconnect(disp); - } - return -1; - } - wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue); - wl_registry_add_listener(wl_registry, ®istry_listener, &info); - wl_display_roundtrip_queue(dpy, info.wl_queue); - - wl_tbm_get_authentication_info(info.wl_tbm); - wl_display_roundtrip_queue(dpy, info.wl_queue); - - *fd = info.fd; - - wl_event_queue_destroy(info.wl_queue); - wl_registry_destroy(wl_registry); - - free(info.device); - wl_tbm_set_user_data (info.wl_tbm, NULL); - wl_tbm_destroy(info.wl_tbm); - - if (disp == dpy) { - wl_display_disconnect(disp); - } - - return *fd >= 0 ? 0 : -1; + struct wl_display *disp = NULL; + struct wl_registry *wl_registry; + struct wl_tbm_info info = { + .dpy = NULL, + .wl_queue = NULL, + .wl_tbm = NULL, + .capabilities = 0, + .device = NULL, + .fd = 0, + }; + + static const struct wl_registry_listener registry_listener = { + wl_client_registry_handle_global, + NULL + }; + + if (!fd) + return -1; + + if (!dpy) { + disp = wl_display_connect(NULL); + if (!disp) { + printf("Failed to create a new display connection\n"); + return -1; + } + dpy = disp; + } + + info.dpy = dpy; + info.wl_queue = wl_display_create_queue(dpy); + if (!info.wl_queue) { + printf("Failed to create a WL Queue\n"); + if (disp == dpy) + wl_display_disconnect(disp); + + return -1; + } + + wl_registry = wl_display_get_registry(dpy); + if (!wl_registry) { + printf("Failed to get registry\n"); + wl_event_queue_destroy(info.wl_queue); + if (disp == dpy) + wl_display_disconnect(disp); + + return -1; + } + wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue); + wl_registry_add_listener(wl_registry, ®istry_listener, &info); + wl_display_roundtrip_queue(dpy, info.wl_queue); + + wl_tbm_get_authentication_info(info.wl_tbm); + wl_display_roundtrip_queue(dpy, info.wl_queue); + + *fd = info.fd; + + wl_event_queue_destroy(info.wl_queue); + wl_registry_destroy(wl_registry); + + free(info.device); + wl_tbm_set_user_data(info.wl_tbm, NULL); + wl_tbm_destroy(info.wl_tbm); + + if (disp == dpy) + wl_display_disconnect(disp); + + return *fd >= 0 ? 0 : -1; } -int -tbm_bufmgr_get_drm_fd_wayland() +int tbm_bufmgr_get_drm_fd_wayland() { - int fd = -1; + int fd = -1; - if(tbm_util_get_drm_fd(NULL, &fd)) - { - printf("Failed to get drm_fd\n"); - } + if (tbm_util_get_drm_fd(NULL, &fd)) + printf("Failed to get drm_fd\n"); - return fd; + return fd; } diff --git a/src/tbm_x11.c b/src/tbm_x11.c index f4e8a87..ce09c9e 100644 --- a/src/tbm_x11.c +++ b/src/tbm_x11.c @@ -37,91 +37,81 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -int -tbm_bufmgr_get_drm_fd_x11() +int tbm_bufmgr_get_drm_fd_x11() { - int screen; - Display *display; - int dri2Major, dri2Minor; - int eventBase, errorBase; - drm_magic_t magic; - char *driver_name, *device_name; - int fd; - - display = XOpenDisplay(NULL); - if (!display) - { - TBM_LOG ("[libtbm:%d] Fail XOpenDisplay\n", getpid()); - return -1; - } - - screen = DefaultScreen(display); - - if (!DRI2QueryExtension (display, &eventBase, &errorBase)) - { - TBM_LOG ("[libtbm:%d] Fail DRI2QueryExtention\n", getpid()); - XCloseDisplay(display); - return -1; - } - - if (!DRI2QueryVersion (display, &dri2Major, &dri2Minor)) - { - TBM_LOG ("[libtbm:%d] Fail DRI2QueryVersion\n", getpid()); - XCloseDisplay(display); - return -1; - } - - if (!DRI2Connect (display, RootWindow(display, screen), &driver_name, &device_name)) - { - TBM_LOG ("[libtbm:%d] Fail DRI2Connect\n", getpid()); - XCloseDisplay(display); - return -1; - } - - fd = open (device_name, O_RDWR); - if (fd < 0) - { - TBM_LOG ("[libtbm:%d] cannot open drm device (%s)\n", getpid(), device_name); - free (driver_name); - free (device_name); - XCloseDisplay(display); - return -1; - } - - if (drmGetMagic (fd, &magic)) - { - TBM_LOG ("[libtbm:%d] Fail drmGetMagic\n", getpid()); - free (driver_name); - free (device_name); - close(fd); - XCloseDisplay(display); - return -1; - } - - if (!DRI2Authenticate(display, RootWindow(display, screen), magic)) - { - TBM_LOG ("[libtbm:%d] Fail DRI2Authenticate\n", getpid()); - free (driver_name); - free (device_name); - close(fd); - XCloseDisplay(display); - return -1; - } - - if(!drmAuthMagic(fd, magic)) - { - TBM_LOG ("[libtbm:%d] Fail drmAuthMagic\n", getpid()); - free (driver_name); - free (device_name); - close(fd); - XCloseDisplay(display); - return -1; - } - - free (driver_name); - free (device_name); - XCloseDisplay(display); - - return fd; + int screen; + Display *display; + int dri2Major, dri2Minor; + int eventBase, errorBase; + drm_magic_t magic; + char *driver_name, *device_name; + int fd; + + display = XOpenDisplay(NULL); + if (!display) { + TBM_LOG("[libtbm:%d] Fail XOpenDisplay\n", getpid()); + return -1; + } + + screen = DefaultScreen(display); + + if (!DRI2QueryExtension(display, &eventBase, &errorBase)) { + TBM_LOG("[libtbm:%d] Fail DRI2QueryExtention\n", getpid()); + XCloseDisplay(display); + return -1; + } + + if (!DRI2QueryVersion(display, &dri2Major, &dri2Minor)) { + TBM_LOG("[libtbm:%d] Fail DRI2QueryVersion\n", getpid()); + XCloseDisplay(display); + return -1; + } + + if (!DRI2Connect(display, RootWindow(display, screen), &driver_name, &device_name)) { + TBM_LOG("[libtbm:%d] Fail DRI2Connect\n", getpid()); + XCloseDisplay(display); + return -1; + } + + fd = open(device_name, O_RDWR); + if (fd < 0) { + TBM_LOG("[libtbm:%d] cannot open drm device (%s)\n", getpid(), device_name); + free(driver_name); + free(device_name); + XCloseDisplay(display); + return -1; + } + + if (drmGetMagic(fd, &magic)) { + TBM_LOG("[libtbm:%d] Fail drmGetMagic\n", getpid()); + free(driver_name); + free(device_name); + close(fd); + XCloseDisplay(display); + return -1; + } + + if (!DRI2Authenticate(display, RootWindow(display, screen), magic)) { + TBM_LOG("[libtbm:%d] Fail DRI2Authenticate\n", getpid()); + free(driver_name); + free(device_name); + close(fd); + XCloseDisplay(display); + return -1; + } + + if (!drmAuthMagic(fd, magic)) { + TBM_LOG("[libtbm:%d] Fail drmAuthMagic\n", getpid()); + free(driver_name); + free(device_name); + close(fd); + XCloseDisplay(display); + return -1; + } + + free(driver_name); + free(device_name); + XCloseDisplay(display); + + return fd; } -