tbm_module: add tbm_module_alloc_surface_data 94/260294/1
authorSooChan Lim <sc1.lim@samsung.com>
Tue, 22 Jun 2021 01:39:41 +0000 (10:39 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 22 Jun 2021 02:13:40 +0000 (11:13 +0900)
This allocates a tbm_backend_surface_data resource.

Change-Id: I3548be16f63fa616feff4e740749f8ac1356a548

src/tbm_module.c
src/tbm_module.h

index c9b64f3..b752cd2 100644 (file)
@@ -644,6 +644,41 @@ tbm_module_get_plane_data(tbm_module *module, int format, int plane_idx, uint32_
        return error;
 }
 
+tbm_backend_surface_data *
+tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int format, int flags, tbm_error_e *error)
+{
+       tbm_backend_surface_data *surface_data = NULL;
+
+       TBM_RETURN_VAL_SET_ERR_IF_FAIL(module, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_RETURN_VAL_SET_ERR_IF_FAIL(module->type == TBM_MODULE_TYPE_HAL_TBM, NULL, *error, TBM_ERROR_INVALID_OPERATION);
+
+       surface_data = calloc(1, sizeof(struct _tbm_backend_surface_data));
+       if (!surface_data) {
+               TBM_ERR("memory allocation failed.");
+               *error = TBM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+
+       surface_data->hal_surface = hal_tbm_bufmgr_alloc_surface(module->hal_bufmgr,
+                                                                                          (uint32_t)width,
+                                                                                          (uint32_t)height,
+                                                                                          (hal_tbm_format)format,
+                                                                                          (hal_tbm_bo_memory_type)flags,
+                                                                                          NULL,
+                                                                                          0,
+                                                                                          (hal_tbm_error *)error);
+       if (!surface_data->hal_surface) {
+               TBM_ERR("hal_tbm_bufmgr_alloc_surface failed.");
+               *error = TBM_ERROR_INVALID_OPERATION;
+               free(surface_data);
+               return NULL;
+       }
+
+       surface_data->module = module;
+
+       return surface_data;
+}
+
 tbm_backend_bo_data *
 tbm_module_alloc_bo_data(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error)
 {
@@ -1247,4 +1282,4 @@ tbm_module_bo_export_key(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_
        }
 
        return ret;
-}
\ No newline at end of file
+}
index b85b855..df4c22f 100644 (file)
@@ -81,6 +81,9 @@ int                  tbm_module_get_capabilities(tbm_module *module, tbm_error_e
 tbm_error_e          tbm_module_bind_native_display(tbm_module *module, void *native_display);
 tbm_error_e          tbm_module_get_supported_formats(tbm_module *module, uint32_t **formats, uint32_t *num);
 tbm_error_e          tbm_module_get_plane_data(tbm_module *module, int format, int plane_idx, uint32_t w, uint32_t h, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx);
+
+tbm_backend_surface_data  *tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int format, int flags, tbm_error_e *error);
+
 tbm_backend_bo_data *tbm_module_alloc_bo_data(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error);
 tbm_backend_bo_data *tbm_module_alloc_bo_data_with_format(tbm_module *module, int format, int bo_idx, int width, int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error);
 tbm_backend_bo_data *tbm_module_import_bo_data_with_fd(tbm_module *module, tbm_bo bo, tbm_fd fd, tbm_error_e *error);