return 1;
}
+static void
+_tbm_bo_init(tbm_bufmgr bufmgr, tbm_bo bo, int flags)
+{
+ bo->bufmgr = bufmgr;
+ bo->flags = flags;
+ bo->magic = TBM_BO_MAGIC;
+ bo->ref_cnt = 1;
+
+ LIST_INITHEAD(&bo->user_data_list);
+
+ bufmgr->bo_cnt++;
+ LIST_ADD(&bo->item_link, &bufmgr->bo_list);
+}
+
+static void
+_tbm_bo_deinit(tbm_bo bo)
+{
+ bo->magic = 0;
+
+ bo->bufmgr->bo_cnt--;
+ LIST_DEL(&bo->item_link);
+}
+
tbm_bo
tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
{
_tbm_util_check_bo_cnt(bufmgr);
- bo->bufmgr = bufmgr;
-
if (bufmgr->backend_module_data) {
bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error);
if (!bo_data) {
}
bo->bo_data = bo_data;
} else {
- bo_priv = bo->bufmgr->backend->bo_alloc(bo, size, flags);
+ bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
if (!bo_priv) {
/* LCOV_EXCL_START */
TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n",
bo->priv = bo_priv;
}
- bo->bufmgr->bo_cnt++;
- bo->magic = TBM_BO_MAGIC;
- bo->ref_cnt = 1;
- bo->flags = flags;
+ _tbm_bo_init(bufmgr, bo, flags);
TBM_TRACE_BO("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);
+ _tbm_bufmgr_mutex_unlock();
+
+ return bo;
+}
+
+/* LCOV_EXCL_START */
+tbm_bo
+tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
+ int height, tbm_bo_memory_type flags, tbm_error_e *error)
+{
+ tbm_bo bo;
+ tbm_backend_bo_data *bo_data;
+
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
+ FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ _tbm_util_check_bo_cnt(bufmgr);
+
+ if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
+ /* LCOV_EXCL_START */
+ TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
+ _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
+ width, height, flags, error);
+ if (!bo_data) {
+ TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
+ FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(*error);
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ bo->bo_data = bo_data;
+ _tbm_bo_init(bufmgr, bo, flags);
+
+ _tbm_bufmgr_mutex_unlock();
+
+ return bo;
+}
+
+tbm_bo
+tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
+ tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
+{
+ tbm_bo bo;
+ tbm_backend_bo_data *bo_data;
+
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
+ FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ _tbm_util_check_bo_cnt(bufmgr);
+
+ if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
+ TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
+ _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
+ bpp, format, flags, bo_idx, error);
+ if (!bo_data) {
+ TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
+ FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(*error);
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
- LIST_ADD(&bo->item_link, &bo->bufmgr->bo_list);
+ bo->bo_data = bo_data;
+ _tbm_bo_init(bufmgr, bo, flags);
_tbm_bufmgr_mutex_unlock();
}
tbm_bo
+tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
+{
+ tbm_bo bo;
+ void *bo_priv;
+
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
+ FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ _tbm_util_check_bo_cnt(bufmgr);
+
+ if (!bufmgr->backend->surface_bo_alloc) {
+ TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
+ _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
+ if (!bo_priv) {
+ TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
+ FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
+ _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+ return NULL;
+ }
+
+ bo->priv = bo_priv;
+ _tbm_bo_init(bufmgr, bo, flags);
+
+ _tbm_bufmgr_mutex_unlock();
+
+ return bo;
+}
+/* LCOV_EXCL_STOP */
+
+tbm_bo
tbm_bo_ref(tbm_bo bo)
{
_tbm_bufmgr_mutex_lock();
void *bo_priv;
tbm_error_e error;
tbm_backend_bo_data *bo_data;
+ int flags;
_tbm_bufmgr_mutex_lock();
_tbm_set_last_result(TBM_ERROR_NONE);
/* LCOV_EXCL_STOP */
}
- bo->bufmgr = bufmgr;
-
- if (bo->bufmgr->backend_module_data) {
- bo_data = bo->bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
+ if (bufmgr->backend_module_data) {
+ bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
if (!bo_data) {
/* LCOV_EXCL_START */
TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
/* LCOV_EXCL_STOP */
}
- if (!LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY(bo2, &bo->bufmgr->bo_list, item_link) {
+ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
+ LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
if (bo2->bo_data == bo_data) {
TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
bo2, bo2->ref_cnt, key,
}
bo->bo_data = bo_data;
} else {
- bo_priv = bo->bufmgr->backend->bo_import(bo, key);
+ bo_priv = bufmgr->backend->bo_import(bo, key);
if (!bo_priv) {
/* LCOV_EXCL_START */
TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
/* LCOV_EXCL_STOP */
}
- if (!LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY(bo2, &bo->bufmgr->bo_list, item_link) {
+ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
+ LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
if (bo2->priv == bo_priv) {
TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
bo2, bo2->ref_cnt, key,
bo->priv = bo_priv;
}
- bo->bufmgr->bo_cnt++;
- bo->magic = TBM_BO_MAGIC;
- bo->ref_cnt = 1;
-
- if (bo->bufmgr->backend_module_data) {
- bo->flags = bo->bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
+ if (bufmgr->backend_module_data) {
+ flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
if (error != TBM_ERROR_NONE) {
TBM_ERR("fail to get the bo flags(memory_types)");
_tbm_set_last_result(error);
- bo->flags = TBM_BO_DEFAULT;
+ flags = TBM_BO_DEFAULT;
}
} else {
- if (bo->bufmgr->backend->bo_get_flags)
- bo->flags = bo->bufmgr->backend->bo_get_flags(bo);
+ if (bufmgr->backend->bo_get_flags)
+ flags = bufmgr->backend->bo_get_flags(bo);
else
- bo->flags = TBM_BO_DEFAULT;
+ flags = TBM_BO_DEFAULT;
}
+ _tbm_bo_init(bufmgr, bo, flags);
+
TBM_TRACE_BO("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_bufmgr_mutex_unlock();
return bo;
void *bo_priv;
tbm_backend_bo_data *bo_data;
tbm_error_e error;
+ int flags;
_tbm_bufmgr_mutex_lock();
_tbm_set_last_result(TBM_ERROR_NONE);
/* LCOV_EXCL_STOP */
}
- bo->bufmgr = bufmgr;
-
- if (bo->bufmgr->backend_module_data) {
- bo_data = bo->bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
+ if (bufmgr->backend_module_data) {
+ bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
if (!bo_data) {
/* LCOV_EXCL_START */
TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
/* LCOV_EXCL_STOP */
}
- if (!LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY(bo2, &bo->bufmgr->bo_list, item_link) {
+ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
+ LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
if (bo2->bo_data == bo_data) {
TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
bo2, bo2->ref_cnt, fd,
}
bo->bo_data = bo_data;
} else {
- bo_priv = bo->bufmgr->backend->bo_import_fd(bo, fd);
+ bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
if (!bo_priv) {
/* LCOV_EXCL_START */
TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
/* LCOV_EXCL_STOP */
}
- if (!LIST_IS_EMPTY(&bo->bufmgr->bo_list)) {
- LIST_FOR_EACH_ENTRY(bo2, &bo->bufmgr->bo_list, item_link) {
+ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
+ LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
if (bo2->priv == bo_priv) {
TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
bo2, bo2->ref_cnt, fd,
bo->priv = bo_priv;
}
- bo->bufmgr->bo_cnt++;
- bo->magic = TBM_BO_MAGIC;
- bo->ref_cnt = 1;
-
- if (bo->bufmgr->backend_module_data) {
- bo->flags = bo->bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
+ if (bufmgr->backend_module_data) {
+ flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
if (error != TBM_ERROR_NONE) {
TBM_ERR("fail to get the bo flags(memory_types)");
_tbm_set_last_result(error);
- bo->flags = TBM_BO_DEFAULT;
+ flags = TBM_BO_DEFAULT;
}
} else {
- if (bo->bufmgr->backend->bo_get_flags)
- bo->flags = bo->bufmgr->backend->bo_get_flags(bo);
+ if (bufmgr->backend->bo_get_flags)
+ flags = bufmgr->backend->bo_get_flags(bo);
else
- bo->flags = TBM_BO_DEFAULT;
+ flags = TBM_BO_DEFAULT;
}
+ _tbm_bo_init(bufmgr, bo, flags);
+
TBM_TRACE_BO("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_bufmgr_mutex_unlock();
return bo;
bo->priv = NULL;
}
- bo->magic = 0;
- bo->bufmgr->bo_cnt--;
+ _tbm_bo_deinit(bo);
- LIST_DEL(&bo->item_link);
free(bo);
}
/* LCOV_EXCL_STOP */
static pthread_mutex_t tbm_surface_lock = PTHREAD_MUTEX_INITIALIZER;
void _tbm_surface_mutex_unlock(void);
-#define C(b, m) (((b) >> (m)) & 0xFF)
-#define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
-#define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
-#define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
-#define FOURCC_ID(str) FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3])
-
/* check condition */
#define TBM_SURFACE_RETURN_IF_FAIL(cond) {\
if (!(cond)) {\
int bo_idx;
int i, j;
bool bufmgr_initialized = false;
- tbm_bo bo = NULL;
- void *bo_priv = NULL;
- tbm_backend_bo_data *bo_data = NULL;
tbm_error_e error;
_tbm_surface_mutex_lock();
if (bufmgr->backend_module_data) {
if (bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
/* LCOV_EXCL_START */
- bo = calloc(1, sizeof(struct _tbm_bo));
- if (!bo) {
- TBM_ERR("fail to alloc bo struct\n");
- _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
- goto alloc_bo_fail;
- }
-
- bo->bufmgr = surf->bufmgr;
-
- _tbm_bufmgr_mutex_lock();
-
- bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, i,
- width, height, flags, &error);
- if (!bo_data) {
- TBM_ERR("fail to alloc bo priv. error(%d)\n", error);
- _tbm_set_last_result(error);
- free(bo);
- _tbm_bufmgr_mutex_unlock();
+ surf->bos[i] = tbm_bo_alloc_with_format(bufmgr, format, i, width, height, flags, &error);
+ if (!surf->bos[i]) {
+ TBM_ERR("fail to tbm_bo_alloc_with_format idx:%d\n", i);
goto alloc_bo_fail;
}
- bo->bo_data = bo_data;
-
- bo->ref_cnt = 1;
- bo->flags = flags;
- LIST_INITHEAD(&bo->user_data_list);
-
- LIST_ADD(&bo->item_link, &surf->bufmgr->bo_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- surf->bos[i] = bo;
/* LCOV_EXCL_STOP */
} else if (bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format && (flags & TBM_BO_TILED)) {
- bo = calloc(1, sizeof(struct _tbm_bo));
- if (!bo) {
- TBM_ERR("fail to alloc bo struct\n");
- _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
- goto alloc_bo_fail;
- }
-
- bo->bufmgr = surf->bufmgr;
-
- _tbm_bufmgr_mutex_lock();
-
- bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height, surf->info.bpp/8, format, flags, i, &error);
- if (!bo_data) {
- TBM_ERR("fail to alloc bo priv. error(%d)\n", error);
- _tbm_set_last_result(error);
- free(bo);
- _tbm_bufmgr_mutex_unlock();
+ /* LCOV_EXCL_START */
+ surf->bos[i] = tbm_bo_alloc_with_tiled_format(bufmgr, width, height, surf->info.bpp/8, format, flags, i, &error);
+ if (!surf->bos[i]) {
+ TBM_ERR("fail to tbm_bo_alloc_with_tiled_format idx:%d\n", i);
goto alloc_bo_fail;
}
- bo->bo_data = bo_data;
-
- bo->ref_cnt = 1;
- bo->flags = flags;
- LIST_INITHEAD(&bo->user_data_list);
-
- LIST_ADD(&bo->item_link, &surf->bufmgr->bo_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- surf->bos[i] = bo;
-
+ /* LCOV_EXCL_STOP */
} else {
surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
if (!surf->bos[i]) {
} else {
if (bufmgr->backend->surface_bo_alloc) {
/* LCOV_EXCL_START */
- bo = calloc(1, sizeof(struct _tbm_bo));
- if (!bo) {
- TBM_ERR("fail to alloc bo struct\n");
- _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
- goto alloc_bo_fail;
- }
-
- bo->bufmgr = surf->bufmgr;
-
- _tbm_bufmgr_mutex_lock();
-
- bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, i);
- if (!bo_priv) {
- TBM_ERR("fail to alloc bo priv\n");
- _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
- free(bo);
- _tbm_bufmgr_mutex_unlock();
+ surf->bos[i] = tbm_bo_alloc_with_surface(bufmgr, width, height, format, flags, i);
+ if (!surf->bos[i]) {
+ TBM_ERR("fail to tbm_bo_alloc_with_surface idx:%d\n", i);
goto alloc_bo_fail;
- }
- bo->priv = bo_priv;
-
- bo->ref_cnt = 1;
- bo->flags = flags;
- LIST_INITHEAD(&bo->user_data_list);
-
- LIST_ADD(&bo->item_link, &surf->bufmgr->bo_list);
-
- _tbm_bufmgr_mutex_unlock();
-
- surf->bos[i] = bo;
/* LCOV_EXCL_STOP */
+ }
} else {
surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
if (!surf->bos[i]) {