From 08e8584d49e308eb667d79119fde948721449d57 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 10 Jun 2021 09:36:08 +0900 Subject: [PATCH] tbm_bo: add get_from_hal_surface flag at tbm_bo The bo_data has to be freed at hal backend when the get_from_hal_surface flag at tbm_bo is set. Otherwise, the bo_data is freed at libtbm. hal_tbm_surface has to deal with the life-cycle of the hal_tbm_bo created by hal_tbm_surface. Change-Id: I9342e5990796543bf6cf4a366fce6753a279f1e2 Signed-off-by: SooChan Lim --- src/tbm_bo.c | 15 ++++++++------- src/tbm_bufmgr_int.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/tbm_bo.c b/src/tbm_bo.c index 5cc343d..0d31ea5 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -384,7 +384,6 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) } /* LCOV_EXCL_STOP */ bo->bo_data = bo_data; - bo->allocated_hal_tbm_bo = 1; } else if (bufmgr->backend_module_data) { bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error); if (!bo_data) { @@ -398,7 +397,6 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) bo_priv = bufmgr->backend->bo_alloc(bo, size, flags); if (!bo_priv) { /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); goto alloc_fail; /* LCOV_EXCL_STOP */ @@ -448,7 +446,6 @@ tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width, /* LCOV_EXCL_START */ if (!bufmgr->use_hal_tbm) { if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) { - TBM_ERR("error: not supported tbm_bo_alloc_with_format\n"); _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED); goto bo_alloc_fail; @@ -470,6 +467,7 @@ tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width, } goto bo_alloc_fail; } + bo->bo_data = bo_data; } else { bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx, width, height, flags, error); @@ -480,9 +478,9 @@ tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width, _tbm_set_last_result(*error); goto bo_alloc_fail; } + bo->bo_data = bo_data; } - bo->bo_data = bo_data; _tbm_bo_init(bufmgr, bo, flags); _tbm_bufmgr_mutex_unlock(); @@ -542,6 +540,7 @@ tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp } goto bo_alloc_fail; } + bo->bo_data = bo_data; } else { bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height, bpp, format, flags, bo_idx, error); @@ -552,9 +551,9 @@ tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp _tbm_set_last_result(*error); goto bo_alloc_fail; } + bo->bo_data = bo_data; } - bo->bo_data = bo_data; _tbm_bo_init(bufmgr, bo, flags); _tbm_bufmgr_mutex_unlock(); @@ -650,6 +649,7 @@ tbm_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int f _tbm_util_check_bo_cnt(bufmgr); + bo->get_from_hal_surface = 1; bo->bo_data = bo_data; _tbm_bo_init(bufmgr, bo, flags); @@ -1640,10 +1640,11 @@ _tbm_bo_free(tbm_bo bo) /* call the bo_free */ if (bo->bufmgr->use_hal_tbm) { // call hal_tbm_bo_free when bo is created by tbm_bo_alloc api. - if (bo->allocated_hal_tbm_bo) { + if (!bo->get_from_hal_surface) { + bo->get_from_hal_surface = 0; + hal_tbm_bo_free(bo->bo_data); bo->bo_data = NULL; - bo->allocated_hal_tbm_bo = 0; } } else if (bo->bufmgr->backend_module_data) { bo->bufmgr->bo_func->bo_free(bo->bo_data); diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 0eb5f79..4b6644e 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -186,7 +186,7 @@ struct _tbm_bo { unsigned int map_cnt; /* device map count */ tbm_backend_bo_data *bo_data; /* bo data of the backend module */ - int allocated_hal_tbm_bo; /* this bo is by calling hal_tbm_bo_alloc */ + int get_from_hal_surface; /* bo_data has be detroyed by hal backend */ }; /** -- 2.7.4