tbm_bo: add get_from_hal_surface flag at tbm_bo
[platform/core/uifw/libtbm.git] / src / tbm_bo.c
index 5cc343d..0d31ea5 100644 (file)
@@ -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);