Fix missing initalize
[platform/core/uifw/libtbm.git] / src / tbm_module.c
index 2f38521..16beb7f 100644 (file)
@@ -701,8 +701,8 @@ tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int for
                                                                                           0,
                                                                                           (hal_tbm_error *)error);
        if (!surface_data->hal_surface) {
-               TBM_ERR("hal_tbm_bufmgr_alloc_surface failed.");
-               *error = TBM_ERROR_INVALID_OPERATION;
+               if (*error != TBM_ERROR_NOT_SUPPORTED) // do not print the error message when it is not supported.
+                       TBM_ERR("hal_tbm_bufmgr_alloc_surface failed.");
                free(surface_data);
                return NULL;
        }
@@ -821,7 +821,8 @@ tbm_module_alloc_bo_data_with_format(tbm_module *module, int format, int bo_idx,
                bo_data->hal_bo = hal_tbm_bufmgr_alloc_bo_with_format(module->hal_bufmgr,
                                                                                        format, bo_idx, width, height, bpp,
                                                                                        (hal_tbm_bo_memory_type)flags, (hal_tbm_error *)error);
-               TBM_GOTO_VAL_IF_FAIL(bo_data->hal_bo, failed);
+               if (!bo_data->hal_bo)
+                       goto failed;
                break;
 /* LCOV_EXCL_START */
        case TBM_MODULE_TYPE_TBM_BACKEND:
@@ -833,11 +834,12 @@ tbm_module_alloc_bo_data_with_format(tbm_module *module, int format, int bo_idx,
                }
 
                bo_data->backend_bo_data = bufmgr_func->bufmgr_alloc_bo_with_format(module->bufmgr_data, format, bo_idx, width, height, flags, error);
-               TBM_GOTO_VAL_IF_FAIL(bo_data->backend_bo_data, failed);
+               if (!bo_data->backend_bo_data)
+                       goto failed;
                break;
        case TBM_MODULE_TYPE_BUFMGR_BACKEND:
                TBM_WRN("!!WARNING: This backend interface will be DEPRECATED after Tizen 6.5.");
-               TBM_ERR("error: not supported tbm_bufmgr_internal_alloc_bo_with_format.");
+               TBM_ERR("error: not supported tbm_module_alloc_bo_data_with_format.");
 
                *error = TBM_ERROR_NOT_SUPPORTED;
                goto failed;
@@ -1035,7 +1037,7 @@ tbm_surface_data_get_plane_data(tbm_surface_data *surface_data, int plane_idx, u
 }
 
 tbm_bo_data **
-tbm_surface_data_get_bo_data_array(tbm_surface_data *surface_data, int *num_bos, tbm_error_e *error)
+tbm_surface_data_get_bo_data_array(tbm_surface_data *surface_data, int *num_bos, int *memory_types, tbm_error_e *error)
 {
        tbm_bo_data **bo_data_array = NULL;
        hal_tbm_bo **hal_bos = NULL;
@@ -1047,11 +1049,12 @@ tbm_surface_data_get_bo_data_array(tbm_surface_data *surface_data, int *num_bos,
        hal_bos = hal_tbm_surface_get_bos(surface_data->hal_surface, num_bos, (hal_tbm_error *)error);
        TBM_RETURN_VAL_IF_FAIL(hal_bos, NULL);
 
-       bo_data_array = calloc(*num_bos, sizeof(struct _tbm_bo_data));
-       if (bo_data_array) {
-               TBM_ERR("memory allocation failed.");
-               *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
+       bo_data_array = calloc(*num_bos, sizeof(tbm_bo_data *));
+       TBM_RETURN_VAL_IF_FAIL(bo_data_array, NULL);
+
+       for (i = 0; i < *num_bos; i++) {
+               bo_data_array[i] = calloc(*num_bos, sizeof(struct _tbm_bo_data));
+               TBM_GOTO_VAL_SET_ERR_IF_FAIL(bo_data_array[i], failed, *error, TBM_ERROR_OUT_OF_MEMORY);
        }
 
        for (i = 0; i < *num_bos; i++) {
@@ -1059,7 +1062,22 @@ tbm_surface_data_get_bo_data_array(tbm_surface_data *surface_data, int *num_bos,
                bo_data_array[i]->module = surface_data->module;
        }
 
+       // get memory_types(bo flags)
+       *memory_types = tbm_bo_data_get_memory_types(bo_data_array[0], error);
+       TBM_GOTO_VAL_IF_FAIL(*error == TBM_ERROR_NONE, failed);
+
        return bo_data_array;
+
+/* LCOV_EXCL_START */
+failed:
+       for (i = 0; i < *num_bos; i++) {
+               if (bo_data_array[i])
+                       free(bo_data_array[i]);
+       }
+       free(bo_data_array);
+
+       return NULL;
+/* LCOV_EXCL_STOP */
 }
 
 tbm_surface_buffer_data *
@@ -1274,7 +1292,7 @@ tbm_bo_data_map(tbm_bo_data *bo_data, int device, int opt, tbm_error_e *error)
        tbm_backend_bo_func *bo_func = NULL;
        tbm_bufmgr_backend backend = NULL;
        tbm_bo_handle bo_handle = (tbm_bo_handle)NULL;
-       hal_tbm_bo_handle hbo_handle;
+       hal_tbm_bo_handle hbo_handle = (hal_tbm_bo_handle)NULL;
 
        TBM_RETURN_VAL_SET_ERR_IF_FAIL(bo_data, (tbm_bo_handle)NULL, *error, TBM_ERROR_INVALID_PARAMETER);
        TBM_RETURN_VAL_SET_ERR_IF_FAIL(bo_data->module, (tbm_bo_handle)NULL, *error, TBM_ERROR_INVALID_PARAMETER);