%{_includedir}/tbm_surface_queue.h
%{_includedir}/tbm_bufmgr_backend.h
%{_includedir}/tbm_type.h
+%{_includedir}/tbm_type_int.h
%{_includedir}/tbm_drm_helper.h
%{_includedir}/tbm_sync.h
+%{_includedir}/tbm_bo.h
%{_libdir}/libtbm.so
%{_libdir}/pkgconfig/libtbm.pc
tbm_surface_queue.c \
tbm_bufmgr_backend.c \
tbm_bufmgr.c \
+ tbm_bo.c \
tbm_drm_helper_server.c \
tbm_drm_helper_client.c \
tbm_sync.c
libtbmincludedir=$(includedir)
libtbminclude_HEADERS = tbm_bufmgr.h \
+ tbm_bo.h \
tbm_surface.h \
tbm_bufmgr_backend.h \
tbm_type.h \
+ tbm_type_int.h \
tbm_surface_internal.h \
tbm_surface_queue.h \
tbm_drm_helper.h \
--- /dev/null
+/**************************************************************************
+
+libtbm
+
+Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include "config.h"
+#include "tbm_bufmgr.h"
+#include "tbm_bufmgr_int.h"
+#include "list.h"
+
+static pthread_mutex_t tbm_bo_lock = PTHREAD_MUTEX_INITIALIZER;
+static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE;
+static void _tbm_bo_mutex_unlock(void);
+
+/* check condition */
+#define TBM_BO_RETURN_IF_FAIL(cond) {\
+ if (!(cond)) {\
+ TBM_LOG_E("'%s' failed.\n", #cond);\
+ _tbm_bo_mutex_unlock();\
+ return;\
+ } \
+}
+
+#define TBM_BO_RETURN_VAL_IF_FAIL(cond, val) {\
+ if (!(cond)) {\
+ TBM_LOG_E("'%s' failed.\n", #cond);\
+ _tbm_bo_mutex_unlock();\
+ return val;\
+ } \
+}
+
+static void
+_tbm_set_last_result(tbm_error_e err)
+{
+ tbm_last_error = err;
+}
+
+/* LCOV_EXCL_START */
+static bool
+_tbm_bo_mutex_init(void)
+{
+ static bool tbm_bo_mutex_init = false;
+
+ if (tbm_bo_mutex_init)
+ return true;
+
+ if (pthread_mutex_init(&tbm_bo_lock, NULL)) {
+ TBM_LOG_E("fail: Cannot pthread_mutex_init for tbm_bo_lock.\n");
+ return false;
+ }
+
+ tbm_bo_mutex_init = true;
+
+ return true;
+}
+
+static void
+_tbm_bo_mutex_lock(void)
+{
+ if (!_tbm_bo_mutex_init()) {
+ TBM_LOG_E("fail: _tbm_bo_mutex_init()\n");
+ return;
+ }
+
+ pthread_mutex_lock(&tbm_bo_lock);
+}
+
+static void
+_tbm_bo_mutex_unlock(void)
+{
+ pthread_mutex_unlock(&tbm_bo_lock);
+}
+
+static char *
+_tbm_flag_to_str(int f)
+{
+ static char str[255];
+
+ if (f == TBM_BO_DEFAULT)
+ snprintf(str, 255, "DEFAULT");
+ else {
+ int c = 0;
+
+ if (f & TBM_BO_SCANOUT)
+ c += snprintf(&str[c], 255-c, "SCANOUT");
+
+ if (f & TBM_BO_NONCACHABLE) {
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, ", ");
+
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, "NONCACHABLE,");
+ }
+
+ if (f & TBM_BO_WC) {
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, ", ");
+
+ if (c >= 0 && c < 255)
+ c += snprintf(&str[c], 255-c, "WC");
+ }
+ }
+
+ return str;
+}
+
+static void
+_tbm_util_check_bo_cnt(tbm_bufmgr bufmgr)
+{
+ static int last_chk_bo_cnt = 0;
+
+ if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
+ (bufmgr->bo_cnt > last_chk_bo_cnt)) {
+ TBM_DEBUG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt);
+ tbm_bufmgr_debug_show(bufmgr);
+ last_chk_bo_cnt = bufmgr->bo_cnt;
+ }
+}
+/* LCOV_EXCL_STOP */
+
+tbm_user_data
+*user_data_lookup(struct list_head *user_data_list, unsigned long key)
+{
+ tbm_user_data *old_data = NULL;
+
+ if (LIST_IS_EMPTY(user_data_list))
+ return NULL;
+
+ LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
+ if (old_data->key == key)
+ return old_data;
+ }
+
+ return NULL;
+}
+
+tbm_user_data
+*user_data_create(unsigned long key, tbm_data_free data_free_func)
+{
+ tbm_user_data *user_data;
+
+ user_data = calloc(1, sizeof(tbm_user_data));
+ if (!user_data) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("fail to allocate an user_date\n");
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ user_data->key = key;
+ user_data->free_func = data_free_func;
+
+ return user_data;
+}
+
+void
+user_data_delete(tbm_user_data *user_data)
+{
+ if (user_data->data && user_data->free_func)
+ user_data->free_func(user_data->data);
+
+ LIST_DEL(&user_data->item_link);
+
+ free(user_data);
+}
+
+static int
+_bo_lock(tbm_bo bo, int device, int opt)
+{
+ int ret = 1;
+
+ if (bo->bufmgr->backend->bo_lock)
+ ret = bo->bufmgr->backend->bo_lock(bo, device, opt);
+
+ return ret;
+}
+
+static void
+_bo_unlock(tbm_bo bo)
+{
+ if (bo->bufmgr->backend->bo_unlock)
+ bo->bufmgr->backend->bo_unlock(bo);
+}
+
+static int
+_tbm_bo_lock(tbm_bo bo, int device, int opt)
+{
+ int old, ret;
+
+ if (!bo)
+ return 0;
+
+ /* do not try to lock the bo */
+ if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
+ return 1;
+
+ if (bo->lock_cnt < 0) {
+ TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
+ bo, bo->lock_cnt);
+ return 0;
+ }
+
+ old = bo->lock_cnt;
+
+ switch (bo->bufmgr->bo_lock_type) {
+ case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
+ if (bo->lock_cnt == 0) {
+ _tbm_bo_mutex_unlock();
+ ret = _bo_lock(bo, device, opt);
+ _tbm_bo_mutex_lock();
+ if (ret)
+ bo->lock_cnt++;
+ } else
+ ret = 1;
+ break;
+ case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
+ _tbm_bo_mutex_unlock();
+ ret = _bo_lock(bo, device, opt);
+ _tbm_bo_mutex_lock();
+ if (ret)
+ bo->lock_cnt++;
+ break;
+ default:
+ TBM_LOG_E("error bo:%p bo_lock_type[%d] is wrong.\n",
+ bo, bo->bufmgr->bo_lock_type);
+ ret = 0;
+ break;
+ }
+
+ TBM_DBG_LOCK(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
+
+ return ret;
+}
+
+static void
+_tbm_bo_unlock(tbm_bo bo)
+{
+ int old;
+
+ /* do not try to unlock the bo */
+ if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
+ return;
+
+ old = bo->lock_cnt;
+
+ switch (bo->bufmgr->bo_lock_type) {
+ case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
+ if (bo->lock_cnt > 0) {
+ bo->lock_cnt--;
+ if (bo->lock_cnt == 0)
+ _bo_unlock(bo);
+ }
+ break;
+ case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
+ if (bo->lock_cnt > 0) {
+ bo->lock_cnt--;
+ _bo_unlock(bo);
+ }
+ break;
+ default:
+ TBM_LOG_E("error bo:%p bo_lock_type[%d] is wrong.\n",
+ bo, bo->bufmgr->bo_lock_type);
+ break;
+ }
+
+ if (bo->lock_cnt < 0)
+ bo->lock_cnt = 0;
+
+ TBM_DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
+}
+
+static int
+_tbm_bo_is_valid(tbm_bo bo)
+{
+ tbm_bufmgr bufmgr = NULL;
+ tbm_bo old_data = NULL;
+
+ if (bo == NULL) {
+ TBM_LOG_E("error: bo is NULL.\n");
+ return 0;
+ }
+
+ bufmgr = bo->bufmgr;
+
+ if (!TBM_BUFMGR_IS_VALID(bufmgr)) {
+ TBM_LOG_E("error: bo->bufmgr is not valid.\n");
+ return 0;
+ }
+
+ if (LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
+ TBM_LOG_E("error: bo->bo->bufmgr->bo_list is EMPTY.\n");
+ return 0;
+ }
+
+ LIST_FOR_EACH_ENTRY(old_data, &bo->bufmgr->bo_list, item_link) {
+ if (old_data == bo)
+ return 1;
+ }
+
+ TBM_LOG_E("error: No valid bo(%p).\n", bo);
+
+ return 0;
+}
+
+tbm_bo
+tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
+{
+ void *bo_priv;
+ tbm_bo bo;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+ TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
+ size, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _tbm_util_check_bo_cnt(bufmgr);
+
+ bo->bufmgr = bufmgr;
+
+ bo_priv = bo->bufmgr->backend->bo_alloc(bo, size, flags);
+ if (!bo_priv) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
+ size, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED);
+ free(bo);
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ bo->bufmgr->bo_cnt++;
+
+ bo->ref_cnt = 1;
+ bo->flags = flags;
+ bo->priv = bo_priv;
+
+ TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
+ _tbm_flag_to_str(bo->flags));
+
+ LIST_INITHEAD(&bo->user_data_list);
+
+ LIST_ADD(&bo->item_link, &bo->bufmgr->bo_list);
+
+ _tbm_bo_mutex_unlock();
+
+ return bo;
+}
+
+tbm_bo
+tbm_bo_ref(tbm_bo bo)
+{
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
+
+ bo->ref_cnt++;
+
+ TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
+
+ _tbm_bo_mutex_unlock();
+
+ return bo;
+}
+
+void
+tbm_bo_unref(tbm_bo bo)
+{
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
+
+ TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
+
+ if (bo->ref_cnt <= 0) {
+ _tbm_bo_mutex_unlock();
+ return;
+ }
+
+ bo->ref_cnt--;
+ if (bo->ref_cnt == 0)
+ _tbm_bo_free(bo);
+
+ _tbm_bo_mutex_unlock();
+}
+
+tbm_bo_handle
+tbm_bo_map(tbm_bo bo, int device, int opt)
+{
+ tbm_bo_handle bo_handle;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
+
+ if (!_tbm_bo_lock(bo, device, opt)) {
+ _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED);
+ TBM_LOG_E("error: fail to lock bo:%p)\n", bo);
+ _tbm_bo_mutex_unlock();
+ return (tbm_bo_handle) NULL;
+ }
+
+ bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
+ if (bo_handle.ptr == NULL) {
+ /* LCOV_EXCL_START */
+ _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED);
+ TBM_LOG_E("error: fail to map bo:%p\n", bo);
+ _tbm_bo_unlock(bo);
+ _tbm_bo_mutex_unlock();
+ return (tbm_bo_handle) NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ /* increase the map_count */
+ bo->map_cnt++;
+
+ TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
+
+ _tbm_bo_mutex_unlock();
+
+ return bo_handle;
+}
+
+int
+tbm_bo_unmap(tbm_bo bo)
+{
+ int ret;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+ TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
+
+ ret = bo->bufmgr->backend->bo_unmap(bo);
+ if (!ret) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
+ _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED);
+ _tbm_bo_mutex_unlock();
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ /* decrease the map_count */
+ bo->map_cnt--;
+
+ TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
+
+ _tbm_bo_unlock(bo);
+
+ _tbm_bo_mutex_unlock();
+
+ return ret;
+}
+
+tbm_bo_handle
+tbm_bo_get_handle(tbm_bo bo, int device)
+{
+ tbm_bo_handle bo_handle;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
+
+ bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
+ if (bo_handle.ptr == NULL) {
+ /* LCOV_EXCL_START */
+ _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED);
+ TBM_LOG_E("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
+ _tbm_bo_mutex_unlock();
+ return (tbm_bo_handle) NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
+
+ _tbm_bo_mutex_unlock();
+
+ return bo_handle;
+}
+
+tbm_key
+tbm_bo_export(tbm_bo bo)
+{
+ tbm_key ret;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ if (!bo->bufmgr->backend->bo_export) {
+ /* LCOV_EXCL_START */
+ _tbm_bo_mutex_unlock();
+ return 0;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = bo->bufmgr->backend->bo_export(bo);
+ if (!ret) {
+ /* LCOV_EXCL_START */
+ _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED);
+ TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret);
+ _tbm_bo_mutex_unlock();
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ TBM_TRACE("bo(%p) tbm_key(%u)\n", bo, ret);
+
+ _tbm_bo_mutex_unlock();
+
+ return ret;
+}
+
+tbm_fd
+tbm_bo_export_fd(tbm_bo bo)
+{
+ tbm_fd ret;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
+
+ if (!bo->bufmgr->backend->bo_export_fd) {
+ /* LCOV_EXCL_START */
+ _tbm_bo_mutex_unlock();
+ return -1;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = bo->bufmgr->backend->bo_export_fd(bo);
+ if (ret < 0) {
+ /* LCOV_EXCL_START */
+ _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED);
+ TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret);
+ _tbm_bo_mutex_unlock();
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret);
+
+ _tbm_bo_mutex_unlock();
+
+ return ret;
+}
+
+tbm_bo
+tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
+{
+ tbm_bo bo;
+ tbm_bo bo2 = NULL;
+ void *bo_priv;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
+ if (!bufmgr->backend->bo_import) {
+ /* LCOV_EXCL_START */
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _tbm_util_check_bo_cnt(bufmgr);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ bo->bufmgr = bufmgr;
+
+ bo_priv = bo->bufmgr->backend->bo_import(bo, key);
+ if (!bo_priv) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
+ _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED);
+ free(bo);
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (!LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
+ LIST_FOR_EACH_ENTRY(bo2, &bo->bufmgr->bo_list, item_link) {
+ if (bo2->priv == bo_priv) {
+ TBM_TRACE("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
+ bo2, bo2->ref_cnt, key,
+ _tbm_flag_to_str(bo2->flags));
+ bo2->ref_cnt++;
+ free(bo);
+ _tbm_bo_mutex_unlock();
+ return bo2;
+ }
+ }
+ }
+
+ bo->bufmgr->bo_cnt++;
+
+ bo->ref_cnt = 1;
+ bo->priv = bo_priv;
+
+ if (bo->bufmgr->backend->bo_get_flags)
+ bo->flags = bo->bufmgr->backend->bo_get_flags(bo);
+ else
+ bo->flags = TBM_BO_DEFAULT;
+
+ TBM_TRACE("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
+ bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
+
+ LIST_INITHEAD(&bo->user_data_list);
+
+ LIST_ADD(&bo->item_link, &bo->bufmgr->bo_list);
+
+ _tbm_bo_mutex_unlock();
+
+ return bo;
+}
+
+tbm_bo
+tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
+{
+ tbm_bo bo;
+ tbm_bo bo2 = NULL;
+ void *bo_priv;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
+ if (!bufmgr->backend->bo_import_fd) {
+ /* LCOV_EXCL_START */
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _tbm_util_check_bo_cnt(bufmgr);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ bo->bufmgr = bufmgr;
+
+ bo_priv = bo->bufmgr->backend->bo_import_fd(bo, fd);
+ if (!bo_priv) {
+ /* LCOV_EXCL_START */
+ TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
+ _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED);
+ free(bo);
+ _tbm_bo_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (!LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
+
+ LIST_FOR_EACH_ENTRY(bo2, &bo->bufmgr->bo_list, item_link) {
+ if (bo2->priv == bo_priv) {
+ TBM_TRACE("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
+ bo2, bo2->ref_cnt, fd,
+ _tbm_flag_to_str(bo2->flags));
+ bo2->ref_cnt++;
+ free(bo);
+ _tbm_bo_mutex_unlock();
+ return bo2;
+ }
+ }
+ }
+
+ bo->bufmgr->bo_cnt++;
+
+ bo->ref_cnt = 1;
+ bo->priv = bo_priv;
+
+ if (bo->bufmgr->backend->bo_get_flags)
+ bo->flags = bo->bufmgr->backend->bo_get_flags(bo);
+ else
+ bo->flags = TBM_BO_DEFAULT;
+
+ TBM_TRACE("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
+ bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
+
+ LIST_INITHEAD(&bo->user_data_list);
+
+ LIST_ADD(&bo->item_link, &bo->bufmgr->bo_list);
+
+ _tbm_bo_mutex_unlock();
+
+ return bo;
+}
+
+int
+tbm_bo_size(tbm_bo bo)
+{
+ int size;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ size = bo->bufmgr->backend->bo_size(bo);
+
+ TBM_TRACE("bo(%p) size(%d)\n", bo, size);
+
+ _tbm_bo_mutex_unlock();
+
+ return size;
+}
+
+int
+tbm_bo_locked(tbm_bo bo)
+{
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
+ TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ if (bo->lock_cnt > 0) {
+ TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
+ _tbm_bo_mutex_unlock();
+ return 1;
+ }
+
+ TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
+ _tbm_bo_mutex_unlock();
+
+ return 0;
+}
+
+int
+tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
+{
+ void *temp;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
+
+ TBM_TRACE("before: bo1(%p) bo2(%p)\n", bo1, bo2);
+
+ if (bo1->bufmgr->backend->bo_size(bo1) != bo2->bufmgr->backend->bo_size(bo2)) {
+ _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED);
+ TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2);
+
+ temp = bo1->priv;
+ bo1->priv = bo2->priv;
+ bo2->priv = temp;
+
+ _tbm_bo_mutex_unlock();
+
+ return 1;
+}
+
+int
+tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
+ tbm_data_free data_free_func)
+{
+ tbm_user_data *data;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ /* check if the data according to the key exist if so, return false. */
+ data = user_data_lookup(&bo->user_data_list, key);
+ if (data) {
+ TBM_TRACE("warning: user data already exist key(%ld)\n", key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ data = user_data_create(key, data_free_func);
+ if (!data) {
+ TBM_LOG_E("error: bo(%p) key(%lu)\n", bo, key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
+
+ LIST_ADD(&data->item_link, &bo->user_data_list);
+
+ _tbm_bo_mutex_unlock();
+
+ return 1;
+}
+
+int
+tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
+{
+ tbm_user_data *old_data;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ if (LIST_IS_EMPTY(&bo->user_data_list)) {
+ TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ old_data = user_data_lookup(&bo->user_data_list, key);
+ if (!old_data) {
+ TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
+
+ user_data_delete(old_data);
+
+ _tbm_bo_mutex_unlock();
+
+ return 1;
+}
+
+int
+tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
+{
+ tbm_user_data *old_data;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ if (LIST_IS_EMPTY(&bo->user_data_list)) {
+ TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ old_data = user_data_lookup(&bo->user_data_list, key);
+ if (!old_data) {
+ TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ if (old_data->data && old_data->free_func)
+ old_data->free_func(old_data->data);
+ old_data->data = data;
+
+ TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
+
+ _tbm_bo_mutex_unlock();
+
+ return 1;
+}
+
+int
+tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
+{
+ tbm_user_data *old_data;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
+ TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ old_data = user_data_lookup(&bo->user_data_list, key);
+ if (!old_data) {
+ TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+ *data = NULL;
+ _tbm_bo_mutex_unlock();
+ return 0;
+ }
+
+ *data = old_data->data;
+
+ TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
+
+ _tbm_bo_mutex_unlock();
+
+ return 1;
+}
+
+/* LCOV_EXCL_START */
+tbm_error_e
+tbm_get_last_error(void)
+{
+ return tbm_last_error;
+}
+/* LCOV_EXCL_STOP */
+
+int
+tbm_bo_get_flags(tbm_bo bo)
+{
+ int flags;
+
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ flags = bo->flags;
+
+ TBM_TRACE("bo(%p)\n", bo);
+
+ _tbm_bo_mutex_unlock();
+
+ return flags;
+}
+
+/* LCOV_EXCL_START */
+/* internal function */
+int
+_tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
+{
+ _tbm_bo_mutex_lock();
+
+ TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
+
+ bo->surface = surface;
+
+ _tbm_bo_mutex_unlock();
+
+ return 1;
+}
+
+void
+_tbm_bo_free(tbm_bo bo)
+{
+ /* destory the user_data_list */
+ if (!LIST_IS_EMPTY(&bo->user_data_list)) {
+ tbm_user_data *old_data = NULL, *tmp;
+
+ LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
+ &bo->user_data_list, item_link) {
+ TBM_DBG("free user_data\n");
+ user_data_delete(old_data);
+ }
+ }
+
+ while (bo->lock_cnt > 0) {
+ TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
+ _bo_unlock(bo);
+ bo->lock_cnt--;
+ }
+
+ /* call the bo_free */
+ bo->bufmgr->backend->bo_free(bo);
+ bo->priv = NULL;
+
+ bo->bufmgr->bo_cnt--;
+
+ LIST_DEL(&bo->item_link);
+ free(bo);
+}
+/* LCOV_EXCL_STOP */
--- /dev/null
+/**************************************************************************
+
+libtbm
+
+Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _TBM_BO_H_
+#define _TBM_BO_H_
+
+#include <tbm_type.h>
+#include <tbm_type_int.h>
+
+/**
+ * \file tbm_bo.h
+ * \brief Tizen Buffer Object
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Functions for buffer object */
+
+/**
+ * @brief Allocates the buffer object.
+ * @details This function create tbm_bo and set reference count to 1.\n
+ * The user can craete tbm_bo with memory type flag #TBM_BO_FLAGS\n\n
+ * #TBM_BO_DEFAULT indecates default memory: it depends on the backend\n
+ * #TBM_BO_SCANOUT indecates scanout memory\n
+ * #TBM_BO_NONCACHABLE indecates non-cachable memory\n
+ * #TBM_BO_WC indecates write-combine memory\n
+ * #TBM_BO_VENDOR indecates vendor specific memory: it depends on the tbm backend
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bufmgr : the buffer manager
+ * @param[in] size : the size of buffer object
+ * @param[in] flags : the flags of memory type
+ * @return a buffer object
+ * @retval #tbm_bo
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ if (!bo)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ....
+
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags);
+
+/**
+ * @brief Increases the reference count of bo.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @return a buffer object
+ * @retval #tbm_bo
+ * @see tbm_bo_unref()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ...
+
+ bo = tbm_bo_ref (bo);
+
+ ....
+
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_bo tbm_bo_ref(tbm_bo bo);
+
+/**
+ * @brief Decreases the reference count of bo
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @see tbm_bo_ref()
+ * @see tbm_bo_alloc()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+void tbm_bo_unref(tbm_bo bo);
+
+/**
+ * @brief Maps the buffer object according to the device type and the option.
+ * @details Cache flushing and Locking is executed, while tbm_bo is mapping in the proper condition according to the device type and the access option.\n
+ * If the cache flush type of bufmgr set true, the map cache flushing is executed
+ * If the lock type of bufmgr set once, the previous bo which is locked is unlock when the new bo is trying to be locked.\n
+ * If the lock type of bufmgr set always, the new bo is locked until the previous bo which is locked is unlocked.\n
+ * If the lock type of bufmgr set never, Every bo is never locked.\n\n
+ * #TBM_DEVICE_DEFAULT indecates the default handle.\n
+ * #TBM_DEVICE_2D indecates the 2D memory handle.\n
+ * #TBM_DEVICE_3D indecates the 3D memory handle.\n
+ * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
+ * #TBM_DEVICE_MM indecates the multimedia handle.\n\n
+ * #TBM_OPTION_READ indecates the accss option to read.\n
+ * #TBM_OPTION_WRITE indecates the access option to write.\n
+ * #TBM_OPTION_VENDOR indecates the vendor specific option that depends on the backend.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @param[in] device : the device type to get a handle
+ * @param[in] opt : the option to access the buffer object
+ * @return the handle of the buffer object
+ * @exception #TBM_ERROR_NONE Success
+ * @exception #TBM_ERROR_BO_LOCK_FAILED tbm_bo lock failed
+ * @exception #TBM_ERROR_BO_MAP_FAILED tbm_bo map failed
+ * @retval #tbm_bo
+ * @see tbm_bo_unmap()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ tbm_bo_handle handle;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ...
+
+ handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
+ if (handle.ptr == NULL)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unmap (bo);
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_bo_handle tbm_bo_map(tbm_bo bo, int device, int opt);
+
+/**
+ * @brief Unmaps the buffer object.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @return 1 if this function succeeds, otherwise 0.
+ * @see tbm_bo_map()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo
+ tbm_bo_handle handle;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ...
+
+ handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
+
+ ...
+
+ tbm_bo_unmap (bo);
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+int tbm_bo_unmap(tbm_bo bo);
+
+/**
+ * @brief Gets the tbm_bo_handle according to the device type.
+ * @details The tbm_bo_handle can be get without the map of the tbm_bo.\n
+ * In this case, TBM does not guarantee the lock and the cache flush of the tbm_bo.\n\n
+ * #TBM_DEVICE_DEFAULT indecates the default handle.\n
+ * #TBM_DEVICE_2D indecates the 2D memory handle.\n
+ * #TBM_DEVICE_3D indecates the 3D memory handle.\n
+ * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
+ * #TBM_DEVICE_MM indecates the multimedia handle.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @param[in] device : the device type to get a handle
+ * @return the handle of the buffer object
+ * @retval #tbm_bo_handle
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ tbm_bo_handle handle;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ...
+
+ handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D);
+ if (handle.ptr == NULL)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device);
+
+/**
+ * @brief Exports the buffer object by key.
+ * @details The tbm_bo can be exported to the anther process with the unique key associated with the the tbm_bo.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @return key associated with the buffer object
+ * @retval #tbm_key
+ * @see tbm_bo_import()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo;
+ tbm_key key;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ key = tbm_bo_export (bo);
+ if (key == 0)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_key tbm_bo_export(tbm_bo bo);
+
+/**
+ * @brief Exports the buffer object by fd.
+ * @details The tbm_bo can be exported to the anther process with the unique fd associated with the the tbm_bo.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @remarks You must release the fd using close().
+ * @param[in] bo : the buffer object
+ * @return fd associated with the buffer object
+ * @retval #tbm_fd
+ * @see tbm_bo_import_fd()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_fd bo_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ bo_fd = tbm_bo_export (bo);
+ if (bo_fd == 0)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_fd tbm_bo_export_fd(tbm_bo bo);
+
+/**
+ * @brief Imports the buffer object associated with the key.
+ * @details The reference count of the tbm_bo is 1.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bufmgr : the buffer manager
+ * @param[in] key : the key associated with the buffer object
+ * @return a buffer object
+ * @retval #tbm_bo
+ * @see tbm_bo_export()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ int bo_key;
+ tbm_bufmgr bufmgr;
+ tbm_bo;
+ tbm_error_e error;
+
+ ...
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_import (bufmgr, key);
+ if (bo == NULL)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key);
+
+/**
+ * @brief Imports the buffer object associated with the fd.
+ * @details The reference count of the tbm_bo is 1.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @remarks You must release the fd using close().
+ * @param[in] bufmgr : the buffer manager
+ * @param[in] fd : the fd associated with the buffer object
+ * @return a buffer object
+ * @retval #tbm_bo
+ * @see tbm_bo_export_fd()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_fd bo_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ tbm_error_e error;
+
+ ...
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_import_fd (bo_fd);
+ if (bo == 0)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd);
+
+/**
+ * @brief Gets the size of a bo.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @return 1 if this function succeeds, otherwise 0.
+ * @see tbm_bo_alloc()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo;
+ int size;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ size = tbm_bo_size (bo);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+int tbm_bo_size(tbm_bo bo);
+
+/**
+ * @brief Gets the state where the buffer object is locked.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @return 1 if this bo is locked, otherwise 0.
+ * @see tbm_bo_map()
+ * @see tbm_bo_unmap()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ...
+
+ if (tbm_bo_locked (bo))
+ {
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+*/
+int tbm_bo_locked(tbm_bo bo);
+
+/**
+ * @brief Swaps the buffer object.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo1 : the buffer object
+ * @param[in] bo2 : the buffer object
+ * @return 1 if this function succeeds, otherwise 0.
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo1;
+ tbm_bo bo2;
+ int ret;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT);
+
+ ...
+
+ ret = tbm_bo_swap (bo1, bo2);
+ if (ret == 0)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unref (bo1);
+ tbm_bo_unref (bo2);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2);
+
+/**
+ * @brief Adds a user_data to the buffer object.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @param[in] key : the key associated with the user_data
+ * @param[in] data_free_func : the function pointer to free the user_data
+ * @return 1 if this function succeeds, otherwise 0.
+ * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data().
+ * @see tbm_data_free()
+ * @see tbm_bo_set_user_data()
+ * @see tbm_bo_get_user_data()
+ * @see tbm_bo_delete_user_data()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ void example_data_free (void *user_data)
+ {
+ char *data = (char*) user_data;
+ free(data);
+ }
+
+ int main()
+ {
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ char *user_data;
+ char *get_data;
+ int ret;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ user_data = (char*) malloc (sizeof(char) * 128);
+
+ ...
+
+ tbm_bo_add_user_data (bo, 1, example_data_free);
+ tbm_bo_set_user_data (bo, 1, user_data);
+
+ ...
+
+ ret = tbm_bo_get_user_data (bo, 1, &get_data);
+ tbm_bo_delete_user_data (bo, 1);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ }
+ @endcode
+ */
+
+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.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @param[in] key : the key associated with the user_date
+ * @return 1 if this function succeeds, otherwise 0.
+ * @see tbm_bo_add_user_data()
+ * @see tbm_bo_get_user_data()
+ * @see tbm_bo_delete_user_data()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ void example_data_free (void *user_data)
+ {
+ char *data = (char*) user_data;
+ free(data);
+ }
+
+ int main()
+ {
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ char *user_data;
+ char *get_data;
+ int ret;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ user_data = (char*) malloc (sizeof(char) * 128);
+
+ ...
+
+ tbm_bo_add_user_data (bo, 1, example_data_free);
+ tbm_bo_set_user_data (bo, 1, user_data);
+
+ ...
+
+ ret = tbm_bo_get_user_data (bo, 1, &get_data);
+ tbm_bo_delete_user_data (bo, 1);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ }
+ @endcode
+ */
+int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key);
+
+/**
+ * @brief Sets a user_date to the buffer object.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @param[in] key : the key associated with the user_date
+ * @param[in] data : a pointer of the user_data
+ * @return 1 if this function succeeds, otherwise 0.
+ * @see tbm_bo_add_user_data()
+ * @see tbm_bo_set_user_data()
+ * @see tbm_bo_delete_user_data()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ void example_data_free (void *user_data)
+ {
+ char *data = (char*) user_data;
+ free(data);
+ }
+
+ int main()
+ {
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ char *user_data;
+ char *get_data;
+ int ret;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ user_data = (char*) malloc (sizeof(char) * 128);
+
+ ...
+
+ tbm_bo_add_user_data (bo, 1, example_data_free);
+ tbm_bo_set_user_data (bo, 1, user_data);
+
+ ...
+
+ ret = tbm_bo_get_user_data (bo, 1, &get_data);
+ tbm_bo_delete_user_data (bo, 1);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ }
+ @endcode
+ */
+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.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] bo : the buffer object
+ * @param[in] key : the key associated with the user_date
+ * @param[out] data : to get the user data
+ * @return 1 if this function succeeds, otherwise 0.
+ * @see tbm_bo_add_user_data()
+ * @see tbm_bo_set_user_data()
+ * @see tbm_bo_get_user_data()
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ void example_data_free (void *user_data)
+ {
+ char *data = (char*) user_data;
+ free(data);
+ }
+
+ int main()
+ {
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ char *user_data;
+ char *get_data;
+ int ret;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ user_data = (char*) malloc (sizeof(char) * 128);
+
+ ...
+
+ tbm_bo_add_user_data (bo, 1, example_data_free);
+ tbm_bo_set_user_data (bo, 1, user_data);
+
+ ...
+
+ ret = tbm_bo_get_user_data (bo, 1, &get_data);
+ tbm_bo_delete_user_data (bo, 1);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ }
+ @endcode
+ */
+int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data);
+
+/**
+ * @brief Gets the latest tbm_error.
+ * @since_tizen 2.4
+ * @return the latest tbm_error
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo bo;
+ tbm_bo_handle handle;
+ tbm_error_e error;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ if (!bo)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
+ if (handle.ptr == NULL)
+ {
+ error = tbm_get_last_error ();
+ ...
+ }
+
+ ...
+
+ tbm_bo_unmap (bo);
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+ @endcode
+ */
+tbm_error_e tbm_get_last_error(void);
+
+/**
+ * @brief Gets the tbm bo flags.
+ * @since_tizen 2.4
+ * @param[in] bo : the buffer object
+ * @return the tbm bo flags
+ * @see TBM_BO_FLAGS
+ * @par Example
+ @code
+ #include <tbm_bufmgr.h>
+
+ int bufmgr_fd;
+ tbm_bufmgr bufmgr;
+ tbm_bo;
+ int flags;
+
+ bufmgr = tbm_bufmgr_init (bufmgr_fd);
+ bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ flags = tbm_bo_get_flags (bo);
+
+ ...
+
+ tbm_bo_unref (bo);
+ tbm_bufmgr_deinit (bufmgr);
+
+ @endcode
+ */
+int tbm_bo_get_flags(tbm_bo bo);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _TBM_BO_H_ */
\ No newline at end of file
static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER;
-static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE;
static double scale_factor = 0;
static void _tbm_bufmgr_mutex_unlock(void);
#define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB
/* values to indicate unspecified fields in XF86ModReqInfo. */
-#define MAJOR_UNSPEC 0xFF
-#define MINOR_UNSPEC 0xFF
-#define PATCH_UNSPEC 0xFFFF
+#define MAJOR_UNSPEC 0xFF
+#define MINOR_UNSPEC 0xFF
+#define PATCH_UNSPEC 0xFFFF
#define ABI_VERS_UNSPEC 0xFFFFFFFF
#define MODULE_VERSION_NUMERIC(maj, min, patch) \
} \
}
-static void
-_tbm_set_last_result(tbm_error_e err)
-{
- tbm_last_error = err;
-}
-
/* LCOV_EXCL_START */
static bool
_tbm_bufmgr_mutex_init(void)
pthread_mutex_unlock(&tbm_bufmgr_lock);
}
-static char *
-_tbm_flag_to_str(int f)
-{
- static char str[255];
-
- if (f == TBM_BO_DEFAULT)
- snprintf(str, 255, "DEFAULT");
- else {
- int c = 0;
-
- if (f & TBM_BO_SCANOUT)
- c += snprintf(&str[c], 255-c, "SCANOUT");
-
- if (f & TBM_BO_NONCACHABLE) {
- if (c >= 0 && c < 255)
- c += snprintf(&str[c], 255-c, ", ");
-
- if (c >= 0 && c < 255)
- c += snprintf(&str[c], 255-c, "NONCACHABLE,");
- }
-
- if (f & TBM_BO_WC) {
- if (c >= 0 && c < 255)
- c += snprintf(&str[c], 255-c, ", ");
-
- if (c >= 0 && c < 255)
- c += snprintf(&str[c], 255-c, "WC");
- }
- }
-
- return str;
-}
-
-static void
-_tbm_util_check_bo_cnt(tbm_bufmgr bufmgr)
-{
- static int last_chk_bo_cnt = 0;
-
- if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
- (bufmgr->bo_cnt > last_chk_bo_cnt)) {
- TBM_DEBUG("============TBM BO CNT DEBUG: bo_cnt=%d\n",
- bufmgr->bo_cnt);
-
- tbm_bufmgr_debug_show(bufmgr);
-
- last_chk_bo_cnt = bufmgr->bo_cnt;
- }
-}
-
static int
_tbm_util_get_max_surface_size(int *w, int *h)
{
snprintf(str, sizeof(cmdline), "%s", cmdline);
}
-/* LCOV_EXCL_STOP */
-
-tbm_user_data
-*user_data_lookup(struct list_head *user_data_list, unsigned long key)
-{
- tbm_user_data *old_data = NULL;
-
- if (LIST_IS_EMPTY(user_data_list))
- return NULL;
-
- LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
- if (old_data->key == key)
- return old_data;
- }
-
- return NULL;
-}
-
-tbm_user_data
-*user_data_create(unsigned long key, tbm_data_free data_free_func)
-{
- tbm_user_data *user_data;
-
- user_data = calloc(1, sizeof(tbm_user_data));
- if (!user_data) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("fail to allocate an user_date\n");
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- user_data->key = key;
- user_data->free_func = data_free_func;
-
- return user_data;
-}
-
-void
-user_data_delete(tbm_user_data *user_data)
-{
- if (user_data->data && user_data->free_func)
- user_data->free_func(user_data->data);
-
- LIST_DEL(&user_data->item_link);
-
- free(user_data);
-}
-
-static int
-_bo_lock(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- int ret = 1;
-
- if (bufmgr->backend->bo_lock)
- ret = bufmgr->backend->bo_lock(bo, device, opt);
-
- return ret;
-}
-
-static void
-_bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- if (bufmgr->backend->bo_unlock)
- bufmgr->backend->bo_unlock(bo);
-}
-
-static int
-_tbm_bo_lock(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr;
- int old, ret;
-
- if (!bo)
- return 0;
-
- bufmgr = bo->bufmgr;
-
- /* do not try to lock the bo */
- if (bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
- return 1;
-
- if (bo->lock_cnt < 0) {
- TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
- bo, bo->lock_cnt);
- return 0;
- }
-
- old = bo->lock_cnt;
-
- switch (bufmgr->bo_lock_type) {
- case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
- if (bo->lock_cnt == 0) {
- _tbm_bufmgr_mutex_unlock();
- ret = _bo_lock(bo, device, opt);
- _tbm_bufmgr_mutex_lock();
- if (ret)
- bo->lock_cnt++;
- } else
- ret = 1;
- break;
- case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
- _tbm_bufmgr_mutex_unlock();
- ret = _bo_lock(bo, device, opt);
- _tbm_bufmgr_mutex_lock();
- if (ret)
- bo->lock_cnt++;
- break;
- default:
- TBM_LOG_E("error bo:%p bo_lock_type[%d] is wrong.\n",
- bo, bufmgr->bo_lock_type);
- ret = 0;
- break;
- }
-
- TBM_DBG_LOCK(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
-
- return ret;
-}
-
-static void
-_tbm_bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr;
- int old;
-
- if (!bo)
- return;
-
- bufmgr = bo->bufmgr;
-
- /* do not try to unlock the bo */
- if (bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
- return;
-
- old = bo->lock_cnt;
-
- switch (bufmgr->bo_lock_type) {
- case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
- if (bo->lock_cnt > 0) {
- bo->lock_cnt--;
- if (bo->lock_cnt == 0)
- _bo_unlock(bo);
- }
- break;
- case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
- if (bo->lock_cnt > 0) {
- bo->lock_cnt--;
- _bo_unlock(bo);
- }
- break;
- default:
- TBM_LOG_E("error bo:%p bo_lock_type[%d] is wrong.\n",
- bo, bufmgr->bo_lock_type);
- break;
- }
-
- if (bo->lock_cnt < 0)
- bo->lock_cnt = 0;
-
- TBM_DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
-}
-
-static int
-_tbm_bo_is_valid(tbm_bo bo)
-{
- tbm_bo old_data = NULL;
-
- if (bo == NULL || gBufMgr == NULL) {
- TBM_LOG_E("error: bo is NULL or tbm_bufmgr was deinited\n");
- return 0;
- }
-
- if (LIST_IS_EMPTY(&gBufMgr->bo_list)) {
- TBM_LOG_E("error: gBufMgr->bo_list is EMPTY.\n");
- return 0;
- }
-
- LIST_FOR_EACH_ENTRY(old_data, &gBufMgr->bo_list, item_link) {
- if (old_data == bo)
- return 1;
- }
-
- TBM_LOG_E("error: No valid bo(%p).\n", bo);
-
- return 0;
-}
-
-static void
-_tbm_bo_free(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- /* destory the user_data_list */
- if (!LIST_IS_EMPTY(&bo->user_data_list)) {
- tbm_user_data *old_data = NULL, *tmp;
-
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
- &bo->user_data_list, item_link) {
- TBM_DBG("free user_data\n");
- user_data_delete(old_data);
- }
- }
-
- while (bo->lock_cnt > 0) {
- TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
- _bo_unlock(bo);
- bo->lock_cnt--;
- }
-
- /* call the bo_free */
- bufmgr->backend->bo_free(bo);
- bo->priv = NULL;
-
- LIST_DEL(&bo->item_link);
- free(bo);
-
- bufmgr->bo_cnt--;
-}
-/* LCOV_EXCL_START */
static int
_check_version(TBMModuleVersionInfo *data)
{
/* allocate bufmgr */
gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
if (!gBufMgr) {
- _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
TBM_TRACE("error: fail to alloc bufmgr fd(%d)\n", fd);
pthread_mutex_unlock(&gLock);
return NULL;
/* load bufmgr priv from env */
if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) {
- _tbm_set_last_result(TBM_BO_ERROR_LOAD_MODULE_FAILED);
TBM_LOG_E("error : Fail to load bufmgr backend\n");
free(gBufMgr);
gBufMgr = NULL;
_tbm_bufmgr_mutex_unlock();
}
-int
-tbm_bo_size(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- int size;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- size = bufmgr->backend->bo_size(bo);
-
- TBM_TRACE("bo(%p) size(%d)\n", bo, size);
-
- _tbm_bufmgr_mutex_unlock();
-
- return size;
-}
-
-tbm_bo
-tbm_bo_ref(tbm_bo bo)
-{
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
-
- bo->ref_cnt++;
-
- TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
-
- _tbm_bufmgr_mutex_unlock();
-
- return bo;
-}
-
-void
-tbm_bo_unref(tbm_bo bo)
-{
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_IF_FAIL(gBufMgr);
- TBM_BUFMGR_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
-
- TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
-
- if (bo->ref_cnt <= 0) {
- _tbm_bufmgr_mutex_unlock();
- return;
- }
-
- bo->ref_cnt--;
- if (bo->ref_cnt == 0)
- _tbm_bo_free(bo);
-
- _tbm_bufmgr_mutex_unlock();
-}
-
-tbm_bo
-tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
-{
- void *bo_priv;
- tbm_bo bo;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL);
-
- bo = calloc(1, sizeof(struct _tbm_bo));
- if (!bo) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
- size, _tbm_flag_to_str(flags));
- _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- _tbm_util_check_bo_cnt(bufmgr);
-
- bo->bufmgr = bufmgr;
-
- bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
- if (!bo_priv) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
- size, _tbm_flag_to_str(flags));
- _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED);
- free(bo);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- bufmgr->bo_cnt++;
-
- bo->ref_cnt = 1;
- bo->flags = flags;
- bo->priv = bo_priv;
-
- TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
- _tbm_flag_to_str(bo->flags));
-
- LIST_INITHEAD(&bo->user_data_list);
-
- LIST_ADD(&bo->item_link, &bufmgr->bo_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- return bo;
-}
-
-tbm_bo
-tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
-{
- void *bo_priv;
- tbm_bo bo;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
-
- if (!bufmgr->backend->bo_import) {
- /* LCOV_EXCL_START */
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- _tbm_util_check_bo_cnt(bufmgr);
-
- bo = calloc(1, sizeof(struct _tbm_bo));
- if (!bo) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- bo->bufmgr = bufmgr;
-
- bo_priv = bufmgr->backend->bo_import(bo, key);
- if (!bo_priv) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
- _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED);
- free(bo);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
- tbm_bo bo2 = NULL;
-
- LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
- if (bo2->priv == bo_priv) {
- TBM_TRACE("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
- bo2, bo2->ref_cnt, key,
- _tbm_flag_to_str(bo2->flags));
- bo2->ref_cnt++;
- free(bo);
- _tbm_bufmgr_mutex_unlock();
- return bo2;
- }
- }
- }
-
- bufmgr->bo_cnt++;
-
- bo->ref_cnt = 1;
- bo->priv = bo_priv;
-
- if (bufmgr->backend->bo_get_flags)
- bo->flags = bufmgr->backend->bo_get_flags(bo);
- else
- bo->flags = TBM_BO_DEFAULT;
-
- TBM_TRACE("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
- bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
-
- LIST_INITHEAD(&bo->user_data_list);
-
- LIST_ADD(&bo->item_link, &bufmgr->bo_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- return bo;
-}
-
-tbm_bo
-tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
-{
- void *bo_priv;
- tbm_bo bo;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
-
- if (!bufmgr->backend->bo_import_fd) {
- /* LCOV_EXCL_START */
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- _tbm_util_check_bo_cnt(bufmgr);
-
- bo = calloc(1, sizeof(struct _tbm_bo));
- if (!bo) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- bo->bufmgr = bufmgr;
-
- bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
- if (!bo_priv) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
- _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED);
- free(bo);
- _tbm_bufmgr_mutex_unlock();
- return NULL;
- /* LCOV_EXCL_STOP */
- }
-
- if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
- tbm_bo bo2 = NULL;
-
- LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
- if (bo2->priv == bo_priv) {
- TBM_TRACE("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
- bo2, bo2->ref_cnt, fd,
- _tbm_flag_to_str(bo2->flags));
- bo2->ref_cnt++;
- free(bo);
- _tbm_bufmgr_mutex_unlock();
- return bo2;
- }
- }
- }
-
- bufmgr->bo_cnt++;
-
- bo->ref_cnt = 1;
- bo->priv = bo_priv;
-
- if (bufmgr->backend->bo_get_flags)
- bo->flags = bufmgr->backend->bo_get_flags(bo);
- else
- bo->flags = TBM_BO_DEFAULT;
-
- TBM_TRACE("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
- bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
-
- LIST_INITHEAD(&bo->user_data_list);
-
- LIST_ADD(&bo->item_link, &bufmgr->bo_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- return bo;
-}
-
-tbm_key
-tbm_bo_export(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- tbm_key ret;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- if (!bufmgr->backend->bo_export) {
- /* LCOV_EXCL_START */
- _tbm_bufmgr_mutex_unlock();
- return 0;
- /* LCOV_EXCL_STOP */
- }
-
- ret = bufmgr->backend->bo_export(bo);
- if (!ret) {
- /* LCOV_EXCL_START */
- _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED);
- TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret);
- _tbm_bufmgr_mutex_unlock();
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- TBM_TRACE("bo(%p) tbm_key(%u)\n", bo, ret);
-
- _tbm_bufmgr_mutex_unlock();
-
- return ret;
-}
-
-tbm_fd
-tbm_bo_export_fd(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- tbm_fd ret;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), -1);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
-
- if (!bufmgr->backend->bo_export_fd) {
- /* LCOV_EXCL_START */
- _tbm_bufmgr_mutex_unlock();
- return -1;
- /* LCOV_EXCL_STOP */
- }
-
- ret = bufmgr->backend->bo_export_fd(bo);
- if (ret < 0) {
- /* LCOV_EXCL_START */
- _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED);
- TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret);
- _tbm_bufmgr_mutex_unlock();
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret);
-
- _tbm_bufmgr_mutex_unlock();
-
- return ret;
-}
-
-tbm_bo_handle
-tbm_bo_get_handle(tbm_bo bo, int device)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- tbm_bo_handle bo_handle;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
-
- bo_handle = bufmgr->backend->bo_get_handle(bo, device);
- if (bo_handle.ptr == NULL) {
- /* LCOV_EXCL_START */
- _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED);
- TBM_LOG_E("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
- _tbm_bufmgr_mutex_unlock();
- return (tbm_bo_handle) NULL;
- /* LCOV_EXCL_STOP */
- }
-
- TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
-
- _tbm_bufmgr_mutex_unlock();
-
- return bo_handle;
-}
-
-tbm_bo_handle
-tbm_bo_map(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- tbm_bo_handle bo_handle;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
-
- if (!_tbm_bo_lock(bo, device, opt)) {
- _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED);
- TBM_LOG_E("error: fail to lock bo:%p)\n", bo);
- _tbm_bufmgr_mutex_unlock();
- return (tbm_bo_handle) NULL;
- }
-
- bo_handle = bufmgr->backend->bo_map(bo, device, opt);
- if (bo_handle.ptr == NULL) {
- /* LCOV_EXCL_START */
- _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED);
- TBM_LOG_E("error: fail to map bo:%p\n", bo);
- _tbm_bo_unlock(bo);
- _tbm_bufmgr_mutex_unlock();
- return (tbm_bo_handle) NULL;
- /* LCOV_EXCL_STOP */
- }
-
- /* increase the map_count */
- bo->map_cnt++;
-
- TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
-
- _tbm_bufmgr_mutex_unlock();
-
- return bo_handle;
-}
-
-int
-tbm_bo_unmap(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- int ret;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
-
- ret = bufmgr->backend->bo_unmap(bo);
- if (!ret) {
- /* LCOV_EXCL_START */
- TBM_LOG_E("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
- _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED);
- _tbm_bufmgr_mutex_unlock();
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- /* decrease the map_count */
- bo->map_cnt--;
-
- TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
-
- _tbm_bo_unlock(bo);
-
- _tbm_bufmgr_mutex_unlock();
-
- return ret;
-}
-
-int
-tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
-{
- tbm_bufmgr bufmgr = gBufMgr;
- void *temp;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
-
- TBM_TRACE("before: bo1(%p) bo2(%p)\n", bo1, bo2);
-
- if (bufmgr->backend->bo_size(bo1) != bufmgr->backend->bo_size(bo2)) {
- _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED);
- TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2);
-
- temp = bo1->priv;
- bo1->priv = bo2->priv;
- bo2->priv = temp;
-
- _tbm_bufmgr_mutex_unlock();
-
- return 1;
-}
-
-int
-tbm_bo_locked(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = gBufMgr;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- if (bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
- TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- if (bo->lock_cnt > 0) {
- TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
- _tbm_bufmgr_mutex_unlock();
- return 1;
- }
-
- TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
- _tbm_bufmgr_mutex_unlock();
-
- return 0;
-}
-
-int
-tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
- tbm_data_free data_free_func)
-{
- tbm_user_data *data;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- /* check if the data according to the key exist if so, return false. */
- data = user_data_lookup(&bo->user_data_list, key);
- if (data) {
- TBM_TRACE("warning: user data already exist key(%ld)\n", key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- data = user_data_create(key, data_free_func);
- if (!data) {
- TBM_LOG_E("error: bo(%p) key(%lu)\n", bo, key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
-
- LIST_ADD(&data->item_link, &bo->user_data_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- return 1;
-}
-
-int
-tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
-{
- tbm_user_data *old_data;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- if (LIST_IS_EMPTY(&bo->user_data_list)) {
- TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- old_data = user_data_lookup(&bo->user_data_list, key);
- if (!old_data) {
- TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- if (old_data->data && old_data->free_func)
- old_data->free_func(old_data->data);
- old_data->data = data;
-
- TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
-
- _tbm_bufmgr_mutex_unlock();
-
- return 1;
-}
-
-int
-tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
-{
- tbm_user_data *old_data;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
- TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- old_data = user_data_lookup(&bo->user_data_list, key);
- if (!old_data) {
- TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
- *data = NULL;
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- *data = old_data->data;
-
- TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
-
- _tbm_bufmgr_mutex_unlock();
-
- return 1;
-}
-
-int
-tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
-{
- tbm_user_data *old_data;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- if (LIST_IS_EMPTY(&bo->user_data_list)) {
- TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- old_data = user_data_lookup(&bo->user_data_list, key);
- if (!old_data) {
- TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
-
- user_data_delete(old_data);
-
- _tbm_bufmgr_mutex_unlock();
-
- return 1;
-}
-
unsigned int
tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
{
return capabilities;
}
-int
-tbm_bo_get_flags(tbm_bo bo)
-{
- int flags;
-
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- flags = bo->flags;
-
- TBM_TRACE("bo(%p)\n", bo);
-
- _tbm_bufmgr_mutex_unlock();
-
- return flags;
-}
-
/* LCOV_EXCL_START */
-tbm_error_e
-tbm_get_last_error(void)
-{
- return tbm_last_error;
-}
-
char *
tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr)
{
}
int
-_tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
-{
- _tbm_bufmgr_mutex_lock();
-
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
-
- bo->surface = surface;
-
- _tbm_bufmgr_mutex_unlock();
-
- return 1;
-}
-
-int
tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
{
int ret;
#define _TBM_BUFMGR_H_
#include <tbm_type.h>
-#include <stdint.h>
-
-/* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
-#ifndef TBM_ERROR_BASE
-#define TBM_ERROR_BASE -0x02830000
-#endif
+#include <tbm_type_int.h>
/**
* \file tbm_bufmgr.h
* \brief Tizen Buffer Manager
*/
-/**
- * @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;
-
-/**
- * @brief Definition for the tizen buffer object
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-typedef struct _tbm_bo *tbm_bo;
-/**
- * @brief Definition for the key associated with the buffer object
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-typedef uint32_t tbm_key;
-/**
- * @brief Definition for the file descripter of the system buffer manager
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-typedef int32_t tbm_fd;
-
-/* TBM_DEVICE_TYPE */
-
-/**
- * @brief Definition for the device type to get the default handle
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_DEVICE_DEFAULT 0
-/**
- * @brief Definition for the device type to get the virtual memory
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_DEVICE_CPU 1
-/**
- * @brief Definition for the device type to get the 2D memory handle
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_DEVICE_2D 2
-/**
- * @brief Definition for the device type to get the 3D memory handle
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_DEVICE_3D 3
-/**
- * @brief Definition for the device type to get the multimedia handle
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_DEVICE_MM 4
-
-/* TBM_OPTION */
-
-/**
- * @brief Definition for the access option to read
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_OPTION_READ (1 << 0)
-/**
- * @brief Definition for the access option to write
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_OPTION_WRITE (1 << 1)
-/**
- * @brief Definition for the vendor specific option that depends on the backend
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-#define TBM_OPTION_VENDOR (0xffff0000)
-
-/**
- * @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;
-} 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 */
-};
-
-/**
- * @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 */
-} 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 */
- TBM_BUFMGR_CAPABILITY_TBM_SYNC = (1 << 2), /**< Support tbm sync */
-};
-
-/**
- * @brief Enumeration of buffer manager lock try for bo
- * @since_tizen 5.0
- */
-typedef enum {
- TBM_BUFMGR_BO_LOCK_TYPE_NEVER = 0, /**< the bufmgr do not try to lock the bos when the tbm_bo_map is called. */
- TBM_BUFMGR_BO_LOCK_TYPE_ONCE, /**< the bufmgr tries to lock the bos only once when the tbm_bo_map is called. */
- TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS, /**< the bufmgr always tries to lock the bos when the tbm_bo_map is called. */
-} tbm_bufmgr_bo_lock_type;
-
#ifdef __cplusplus
extern "C" {
#endif
*/
void tbm_bufmgr_deinit(tbm_bufmgr bufmgr);
-/* Functions for bo */
-
-/**
- * @brief Allocates the buffer object.
- * @details This function create tbm_bo and set reference count to 1.\n
- * The user can craete tbm_bo with memory type flag #TBM_BO_FLAGS\n\n
- * #TBM_BO_DEFAULT indecates default memory: it depends on the backend\n
- * #TBM_BO_SCANOUT indecates scanout memory\n
- * #TBM_BO_NONCACHABLE indecates non-cachable memory\n
- * #TBM_BO_WC indecates write-combine memory\n
- * #TBM_BO_VENDOR indecates vendor specific memory: it depends on the tbm backend
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bufmgr : the buffer manager
- * @param[in] size : the size of buffer object
- * @param[in] flags : the flags of memory type
- * @return a buffer object
- * @retval #tbm_bo
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- if (!bo)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ....
-
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags);
-
-/**
- * @brief Increases the reference count of bo.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @return a buffer object
- * @retval #tbm_bo
- * @see tbm_bo_unref()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
-
- ...
-
- bo = tbm_bo_ref (bo);
-
- ....
-
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_bo tbm_bo_ref(tbm_bo bo);
-
-/**
- * @brief Decreases the reference count of bo
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @see tbm_bo_ref()
- * @see tbm_bo_alloc()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-void tbm_bo_unref(tbm_bo bo);
-
-/**
- * @brief Maps the buffer object according to the device type and the option.
- * @details Cache flushing and Locking is executed, while tbm_bo is mapping in the proper condition according to the device type and the access option.\n
- * If the cache flush type of bufmgr set true, the map cache flushing is executed
- * If the lock type of bufmgr set once, the previous bo which is locked is unlock when the new bo is trying to be locked.\n
- * If the lock type of bufmgr set always, the new bo is locked until the previous bo which is locked is unlocked.\n
- * If the lock type of bufmgr set never, Every bo is never locked.\n\n
- * #TBM_DEVICE_DEFAULT indecates the default handle.\n
- * #TBM_DEVICE_2D indecates the 2D memory handle.\n
- * #TBM_DEVICE_3D indecates the 3D memory handle.\n
- * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
- * #TBM_DEVICE_MM indecates the multimedia handle.\n\n
- * #TBM_OPTION_READ indecates the accss option to read.\n
- * #TBM_OPTION_WRITE indecates the access option to write.\n
- * #TBM_OPTION_VENDOR indecates the vendor specific option that depends on the backend.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @param[in] device : the device type to get a handle
- * @param[in] opt : the option to access the buffer object
- * @return the handle of the buffer object
- * @exception #TBM_ERROR_NONE Success
- * @exception #TBM_ERROR_BO_LOCK_FAILED tbm_bo lock failed
- * @exception #TBM_ERROR_BO_MAP_FAILED tbm_bo map failed
- * @retval #tbm_bo
- * @see tbm_bo_unmap()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- tbm_bo_handle handle;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
-
- ...
-
- handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
- if (handle.ptr == NULL)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unmap (bo);
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_bo_handle tbm_bo_map(tbm_bo bo, int device, int opt);
-
-/**
- * @brief Unmaps the buffer object.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- * @see tbm_bo_map()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo
- tbm_bo_handle handle;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
-
- ...
-
- handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
-
- ...
-
- tbm_bo_unmap (bo);
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-int tbm_bo_unmap(tbm_bo bo);
-
-/**
- * @brief Gets the tbm_bo_handle according to the device type.
- * @details The tbm_bo_handle can be get without the map of the tbm_bo.\n
- * In this case, TBM does not guarantee the lock and the cache flush of the tbm_bo.\n\n
- * #TBM_DEVICE_DEFAULT indecates the default handle.\n
- * #TBM_DEVICE_2D indecates the 2D memory handle.\n
- * #TBM_DEVICE_3D indecates the 3D memory handle.\n
- * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
- * #TBM_DEVICE_MM indecates the multimedia handle.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @param[in] device : the device type to get a handle
- * @return the handle of the buffer object
- * @retval #tbm_bo_handle
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- tbm_bo_handle handle;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
-
- ...
-
- handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D);
- if (handle.ptr == NULL)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device);
-
-/**
- * @brief Exports the buffer object by key.
- * @details The tbm_bo can be exported to the anther process with the unique key associated with the the tbm_bo.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @return key associated with the buffer object
- * @retval #tbm_key
- * @see tbm_bo_import()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo;
- tbm_key key;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- key = tbm_bo_export (bo);
- if (key == 0)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_key tbm_bo_export(tbm_bo bo);
-
-/**
- * @brief Exports the buffer object by fd.
- * @details The tbm_bo can be exported to the anther process with the unique fd associated with the the tbm_bo.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @remarks You must release the fd using close().
- * @param[in] bo : the buffer object
- * @return fd associated with the buffer object
- * @retval #tbm_fd
- * @see tbm_bo_import_fd()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_fd bo_fd;
- tbm_bufmgr bufmgr;
- tbm_bo;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- bo_fd = tbm_bo_export (bo);
- if (bo_fd == 0)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_fd tbm_bo_export_fd(tbm_bo bo);
-
-/**
- * @brief Imports the buffer object associated with the key.
- * @details The reference count of the tbm_bo is 1.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bufmgr : the buffer manager
- * @param[in] key : the key associated with the buffer object
- * @return a buffer object
- * @retval #tbm_bo
- * @see tbm_bo_export()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- int bo_key;
- tbm_bufmgr bufmgr;
- tbm_bo;
- tbm_error_e error;
-
- ...
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_import (bufmgr, key);
- if (bo == NULL)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key);
-
-/**
- * @brief Imports the buffer object associated with the fd.
- * @details The reference count of the tbm_bo is 1.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @remarks You must release the fd using close().
- * @param[in] bufmgr : the buffer manager
- * @param[in] fd : the fd associated with the buffer object
- * @return a buffer object
- * @retval #tbm_bo
- * @see tbm_bo_export_fd()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_fd bo_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- tbm_error_e error;
-
- ...
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_import_fd (bo_fd);
- if (bo == 0)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd);
-
-/**
- * @brief Gets the size of a bo.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- * @see tbm_bo_alloc()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo;
- int size;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- size = tbm_bo_size (bo);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-int tbm_bo_size(tbm_bo bo);
-
-/**
- * @brief Gets the state where the buffer object is locked.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @return 1 if this bo is locked, otherwise 0.
- * @see tbm_bo_map()
- * @see tbm_bo_unmap()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
-
- ...
-
- if (tbm_bo_locked (bo))
- {
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
-*/
-int tbm_bo_locked(tbm_bo bo);
-
-/**
- * @brief Swaps the buffer object.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo1 : the buffer object
- * @param[in] bo2 : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo1;
- tbm_bo bo2;
- int ret;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT);
-
- ...
-
- ret = tbm_bo_swap (bo1, bo2);
- if (ret == 0)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unref (bo1);
- tbm_bo_unref (bo2);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2);
-
-/**
- * @brief Called when the user data is deleted in buffer object.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] user_data User_data to be passed to callback function
- * @pre The callback must be registered using tbm_bo_add_user_data().\n
- * tbm_bo_delete_user_data() must be called to invoke this callback.
- * @see tbm_bo_add_user_data()
- * @see tbm_bo_delete_user_data()
- */
-typedef void (*tbm_data_free) (void *user_data);
-
-/**
- * @brief Adds a user_data to the buffer object.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @param[in] key : the key associated with the user_data
- * @param[in] data_free_func : the function pointer to free the user_data
- * @return 1 if this function succeeds, otherwise 0.
- * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data().
- * @see tbm_data_free()
- * @see tbm_bo_set_user_data()
- * @see tbm_bo_get_user_data()
- * @see tbm_bo_delete_user_data()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- void example_data_free (void *user_data)
- {
- char *data = (char*) user_data;
- free(data);
- }
-
- int main()
- {
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- char *user_data;
- char *get_data;
- int ret;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- user_data = (char*) malloc (sizeof(char) * 128);
-
- ...
-
- tbm_bo_add_user_data (bo, 1, example_data_free);
- tbm_bo_set_user_data (bo, 1, user_data);
-
- ...
-
- ret = tbm_bo_get_user_data (bo, 1, &get_data);
- tbm_bo_delete_user_data (bo, 1);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- }
- @endcode
- */
-
-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.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @param[in] key : the key associated with the user_date
- * @return 1 if this function succeeds, otherwise 0.
- * @see tbm_bo_add_user_data()
- * @see tbm_bo_get_user_data()
- * @see tbm_bo_delete_user_data()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- void example_data_free (void *user_data)
- {
- char *data = (char*) user_data;
- free(data);
- }
-
- int main()
- {
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- char *user_data;
- char *get_data;
- int ret;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- user_data = (char*) malloc (sizeof(char) * 128);
-
- ...
-
- tbm_bo_add_user_data (bo, 1, example_data_free);
- tbm_bo_set_user_data (bo, 1, user_data);
-
- ...
-
- ret = tbm_bo_get_user_data (bo, 1, &get_data);
- tbm_bo_delete_user_data (bo, 1);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- }
- @endcode
- */
-int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key);
-
-/**
- * @brief Sets a user_date to the buffer object.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @param[in] key : the key associated with the user_date
- * @param[in] data : a pointer of the user_data
- * @return 1 if this function succeeds, otherwise 0.
- * @see tbm_bo_add_user_data()
- * @see tbm_bo_set_user_data()
- * @see tbm_bo_delete_user_data()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- void example_data_free (void *user_data)
- {
- char *data = (char*) user_data;
- free(data);
- }
-
- int main()
- {
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- char *user_data;
- char *get_data;
- int ret;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- user_data = (char*) malloc (sizeof(char) * 128);
-
- ...
-
- tbm_bo_add_user_data (bo, 1, example_data_free);
- tbm_bo_set_user_data (bo, 1, user_data);
-
- ...
-
- ret = tbm_bo_get_user_data (bo, 1, &get_data);
- tbm_bo_delete_user_data (bo, 1);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- }
- @endcode
- */
-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.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] bo : the buffer object
- * @param[in] key : the key associated with the user_date
- * @param[out] data : to get the user data
- * @return 1 if this function succeeds, otherwise 0.
- * @see tbm_bo_add_user_data()
- * @see tbm_bo_set_user_data()
- * @see tbm_bo_get_user_data()
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- void example_data_free (void *user_data)
- {
- char *data = (char*) user_data;
- free(data);
- }
-
- int main()
- {
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- char *user_data;
- char *get_data;
- int ret;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- user_data = (char*) malloc (sizeof(char) * 128);
-
- ...
-
- tbm_bo_add_user_data (bo, 1, example_data_free);
- tbm_bo_set_user_data (bo, 1, user_data);
-
- ...
-
- ret = tbm_bo_get_user_data (bo, 1, &get_data);
- tbm_bo_delete_user_data (bo, 1);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- }
- @endcode
- */
-int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data);
-
-/**
- * @brief Gets the latest tbm_error.
- * @since_tizen 2.4
- * @return the latest tbm_error
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo bo;
- tbm_bo_handle handle;
- tbm_error_e error;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- if (!bo)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
- if (handle.ptr == NULL)
- {
- error = tbm_get_last_error ();
- ...
- }
-
- ...
-
- tbm_bo_unmap (bo);
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
- @endcode
- */
-tbm_error_e tbm_get_last_error(void);
-
/**
* @brief Gets the tbm buffer capability.
* @since_tizen 2.4
unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr);
/**
- * @brief Gets the tbm bo flags.
- * @since_tizen 2.4
- * @param[in] bo : the buffer object
- * @return the tbm bo flags
- * @see TBM_BO_FLAGS
- * @par Example
- @code
- #include <tbm_bufmgr.h>
-
- int bufmgr_fd;
- tbm_bufmgr bufmgr;
- tbm_bo;
- int flags;
-
- bufmgr = tbm_bufmgr_init (bufmgr_fd);
- bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
- flags = tbm_bo_get_flags (bo);
-
- ...
-
- tbm_bo_unref (bo);
- tbm_bufmgr_deinit (bufmgr);
-
- @endcode
- */
-int tbm_bo_get_flags(tbm_bo bo);
-
-/**
* @brief bind the native_display.
* @since_tizen 3.0
* @param[in] bufmgr : the buffer manager
#include <errno.h>
#include <pthread.h>
#include <tbm_bufmgr.h>
+#include <tbm_bo.h>
#include <tbm_surface.h>
#include <tbm_surface_internal.h>
#include <tbm_bufmgr_backend.h>
tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
int _tbm_surface_is_valid(tbm_surface_h surface);
+void _tbm_bo_free(tbm_bo bo);
/* functions for mutex */
int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
--- /dev/null
+/**************************************************************************
+
+libtbm
+
+Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Inpyo Kang <mantiger@samsung.com>, Dongyeon Kim <dy5.kim@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _TBM_TYPE_INT_H_
+#define _TBM_TYPE_INT_H_
+
+#include <stdint.h>
+
+/**
+ * \file tbm_type_int.h
+ * \brief Type definition used internally
+ */
+
+/* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
+#ifndef TBM_ERROR_BASE
+#define TBM_ERROR_BASE -0x02830000
+#endif
+
+/**
+ * @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;
+
+/**
+ * @brief Definition for the tizen buffer object
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _tbm_bo *tbm_bo;
+/**
+ * @brief Definition for the key associated with the buffer object
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef uint32_t tbm_key;
+/**
+ * @brief Definition for the file descripter of the system buffer manager
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef int32_t tbm_fd;
+
+/* TBM_DEVICE_TYPE */
+
+/**
+ * @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 */
+} 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 */
+ TBM_BUFMGR_CAPABILITY_TBM_SYNC = (1 << 2), /**< Support tbm sync */
+};
+
+/**
+ * @brief Enumeration of buffer manager lock try for bo
+ * @since_tizen 5.0
+ */
+typedef enum {
+ TBM_BUFMGR_BO_LOCK_TYPE_NEVER = 0, /**< the bufmgr do not try to lock the bos when the tbm_bo_map is called. */
+ TBM_BUFMGR_BO_LOCK_TYPE_ONCE, /**< the bufmgr tries to lock the bos only once when the tbm_bo_map is called. */
+ TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS, /**< the bufmgr always tries to lock the bos when the tbm_bo_map is called. */
+} tbm_bufmgr_bo_lock_type;
+
+/**
+ * @brief Definition for the device type to get the default handle
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_DEVICE_DEFAULT 0
+/**
+ * @brief Definition for the device type to get the virtual memory
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_DEVICE_CPU 1
+/**
+ * @brief Definition for the device type to get the 2D memory handle
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_DEVICE_2D 2
+/**
+ * @brief Definition for the device type to get the 3D memory handle
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_DEVICE_3D 3
+/**
+ * @brief Definition for the device type to get the multimedia handle
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_DEVICE_MM 4
+
+/* TBM_OPTION */
+
+/**
+ * @brief Definition for the access option to read
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_OPTION_READ (1 << 0)
+/**
+ * @brief Definition for the access option to write
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_OPTION_WRITE (1 << 1)
+/**
+ * @brief Definition for the vendor specific option that depends on the backend
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define TBM_OPTION_VENDOR (0xffff0000)
+
+/**
+ * @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;
+} 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 */
+};
+
+/**
+ * @brief Called when the user data is deleted in buffer object.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] user_data User_data to be passed to callback function
+ * @pre The callback must be registered using tbm_bo_add_user_data().\n
+ * tbm_bo_delete_user_data() must be called to invoke this callback.
+ * @see tbm_bo_add_user_data()
+ * @see tbm_bo_delete_user_data()
+ */
+typedef void (*tbm_data_free) (void *user_data);
+
+#endif /* _TBM_TYPE_INT_H_ */
#include "gtest/gtest.h"
#include <tbm_bufmgr.h>
+#include <tbm_bo.h>
#include <tbm_surface.h>
#include <tbm_surface_internal.h>
#include <tbm_surface_queue.h>