summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangyeon Lee <cyeon.lee@samsung.com>2016-04-20 13:19:51 +0900
committerChangyeon Lee <cyeon.lee@samsung.com>2016-04-21 10:43:45 +0900
commitc362ebd8894a44ea3e76330ca6c70e9c19c4fadd (patch)
tree2c6a062add036cf86ae2435be0862d1ceea7bfbe
parent07d3e296dd31889bf362d6dc3de68506b55f2119 (diff)
downloadlibtbm-c362ebd8894a44ea3e76330ca6c70e9c19c4fadd.tar.gz
libtbm-c362ebd8894a44ea3e76330ca6c70e9c19c4fadd.tar.bz2
libtbm-c362ebd8894a44ea3e76330ca6c70e9c19c4fadd.zip
Add backend interface surface_alloc_bo
if surface_alloc_bo backend fuction exist, Use surface alloc bo function instead bo alloc when tbm surface is created Change-Id: Id8b68d37067ab993d59bee4a866d79283c83f741 Signed-off-by: Changyeon Lee <cyeon.lee@samsung.com>
-rw-r--r--src/tbm_bufmgr_backend.h12
-rw-r--r--src/tbm_surface_internal.c73
2 files changed, 73 insertions, 12 deletions
diff --git a/src/tbm_bufmgr_backend.h b/src/tbm_bufmgr_backend.h
index 1c967ac..839ec99 100644
--- a/src/tbm_bufmgr_backend.h
+++ b/src/tbm_bufmgr_backend.h
@@ -226,6 +226,18 @@ struct _tbm_bufmgr_backend {
*/
int (*bufmgr_bind_native_display)(tbm_bufmgr bufmgr, void *NativeDisplay);
+ /**
+ * @brief allocate the buffer object for tbm surface
+ * @param[in] bo : the buffer object
+ * @param[in] width : the width of surface
+ * @param[in] height : the height of surface
+ * @param[in] format : the format of surface
+ * @param[in] flags : the flags of memory type
+ * @param[in] idx : the index of bo in surface
+ * @return pointer of the bo private.
+ */
+ void * (*surface_bo_alloc)(tbm_bo bo, int width, int height, int format, int flags, int bo_idx);
+
/* Padding for future extension */
void (*reserved1)(void);
void (*reserved2)(void);
diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c
index bc01935..796add8 100644
--- a/src/tbm_surface_internal.c
+++ b/src/tbm_surface_internal.c
@@ -560,24 +560,56 @@ tbm_surface_internal_create_with_flags(int width, int height,
if (surf->planes_bo_idx[j] == i)
bo_size += surf->info.planes[j].size;
}
- surf->bos[i] = tbm_bo_alloc(mgr, bo_size, flags);
- if (!surf->bos[i]) {
- for (j = 0; j < i; j++) {
- if (surf->bos[j])
- tbm_bo_unref(surf->bos[j]);
+
+ if (mgr->backend->surface_bo_alloc) {
+
+ tbm_bo bo = NULL;
+ void *bo_priv = NULL;
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ TBM_LOG("[libtbm:%d] "
+ "error %s:%d fail to alloc bo struct\n",
+ getpid(), __func__, __LINE__);
+ goto alloc_fail;
}
- free(surf);
- surf = NULL;
+ bo->bufmgr = surf->bufmgr;
- if (LIST_IS_EMPTY(&mgr->surf_list)) {
- LIST_DELINIT(&mgr->surf_list);
- _deinit_surface_bufmgr();
+ pthread_mutex_lock(&surf->bufmgr->lock);
+
+ bo_priv = mgr->backend->surface_bo_alloc (bo, width, height, format, flags, i);
+ if (!bo_priv) {
+ TBM_LOG("[libtbm:%d] "
+ "error %s:%d fail to alloc bo priv\n",
+ getpid(), __func__, __LINE__);
+ free(bo);
+ pthread_mutex_unlock(&surf->bufmgr->lock);
}
- _tbm_surface_mutex_unlock();
- return NULL;
+ bo->ref_cnt = 1;
+ bo->flags = flags;
+ bo->priv = bo_priv;
+
+ LIST_INITHEAD(&bo->user_data_list);
+
+ LIST_ADD(&bo->item_link, &surf->bufmgr->bo_list);
+
+ pthread_mutex_unlock(&surf->bufmgr->lock);
+
+ surf->bos[i] = bo;
+
+ } else {
+ surf->bos[i] = tbm_bo_alloc(mgr, bo_size, flags);
+ }
+
+ if (!surf->bos[i]) {
+ TBM_LOG("[libtbm:%d] "
+ "error %s:%d fail to alloc bo\n",
+ getpid(), __func__, __LINE__);
+ goto alloc_fail;
}
+
_tbm_bo_set_surface(surf->bos[i], surf);
}
@@ -589,6 +621,23 @@ tbm_surface_internal_create_with_flags(int width, int height,
_tbm_surface_mutex_unlock();
return surf;
+
+alloc_fail:
+ for (j = 0; j < i; j++) {
+ if (surf->bos[j])
+ tbm_bo_unref(surf->bos[j]);
+ }
+
+ free(surf);
+ surf = NULL;
+
+ if (LIST_IS_EMPTY(&mgr->surf_list)) {
+ LIST_DELINIT(&mgr->surf_list);
+ _deinit_surface_bufmgr();
+ }
+
+ _tbm_surface_mutex_unlock();
+ return NULL;
}
tbm_surface_h