bufmgr_data = (tbm_vc4_bufmgr *)backend_data->bufmgr;
TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, -1);
- if (backend_data->bo_funcs)
- free(backend_data->bo_funcs);
- if (backend_data->surface_funcs)
- free(backend_data->surface_funcs);
- if (backend_data->bufmgr_funcs)
- free(backend_data->bufmgr_funcs);
-
if (!LIST_IS_EMPTY(&bufmgr_data->surface_data_list)) {
LIST_FOR_EACH_ENTRY_SAFE(s, ss, &bufmgr_data->surface_data_list, link) {
LIST_DEL(&s->link);
close(bufmgr_data->fd);
free(backend_data->bufmgr);
- free(backend_data);
+ backend_data->bufmgr = NULL;
return HAL_TBM_ERROR_NONE;
}
hal_backend_tbm_vc4_init(void **data)
{
hal_tbm_backend_data *backend_data = NULL;
- hal_tbm_bufmgr_funcs *bufmgr_funcs = NULL;
- hal_tbm_surface_funcs *surface_funcs = NULL;
- hal_tbm_bo_funcs *bo_funcs = NULL;
tbm_vc4_bufmgr *bufmgr_data = NULL;
int drm_fd = -1;
- /* allocate a hal_tbm_backend_data */
- backend_data = calloc(1, sizeof(struct _hal_tbm_backend_data));
+ if (!data) {
+ TBM_BACKEND_ERR("data is NULL");
+ return -1;
+ }
+
+ backend_data = *(hal_tbm_backend_data **)data;
if (!backend_data) {
- TBM_BACKEND_ERR("fail to alloc backend_data!");
- *data = NULL;
+ TBM_BACKEND_ERR("backend_data is NULL");
return -1;
}
- *data = backend_data;
/* allocate a hal_tbm_bufmgr */
bufmgr_data = calloc(1, sizeof(struct _tbm_vc4_bufmgr));
if (!bufmgr_data) {
TBM_BACKEND_ERR("fail to alloc bufmgr_data!");
- goto fail_alloc_bufmgr_data;
+ return -1;
}
backend_data->bufmgr = (hal_tbm_bufmgr *)bufmgr_data;
drm_fd = _tbm_vc4_open_drm();
if (drm_fd < 0) {
TBM_BACKEND_ERR("fail to open drm!");
- goto fail_open_drm;
+ free(bufmgr_data);
+ return -1;
}
// set true when backend has a drm_device.
// initialize the surface_data list
LIST_INITHEAD(&bufmgr_data->surface_data_list);
- /* alloc and register bufmgr_funcs */
- bufmgr_funcs = calloc(1, sizeof(struct _hal_tbm_bufmgr_funcs));
- if (!bufmgr_funcs) {
- TBM_BACKEND_ERR("fail to alloc bufmgr_funcs!");
- goto fail_alloc_bufmgr_funcs;
- }
- backend_data->bufmgr_funcs = bufmgr_funcs;
-
- bufmgr_funcs->bufmgr_get_capabilities = tbm_vc4_bufmgr_get_capabilities;
- bufmgr_funcs->bufmgr_get_supported_formats = tbm_vc4_bufmgr_get_supported_formats;
- bufmgr_funcs->bufmgr_get_plane_data = tbm_vc4_bufmgr_get_plane_data;
- bufmgr_funcs->bufmgr_alloc_surface = tbm_vc4_bufmgr_alloc_surface;
- bufmgr_funcs->bufmgr_import_surface = tbm_vc4_bufmgr_import_surface;
- bufmgr_funcs->bufmgr_alloc_bo = tbm_vc4_bufmgr_alloc_bo;
- bufmgr_funcs->bufmgr_alloc_bo_with_format = NULL;
- bufmgr_funcs->bufmgr_import_fd = tbm_vc4_bufmgr_import_fd;
- bufmgr_funcs->bufmgr_import_key = tbm_vc4_bufmgr_import_key;
-
- /* alloc and register surface_funcs */
- surface_funcs = calloc(1, sizeof(struct _hal_tbm_surface_funcs));
- if (!surface_funcs) {
- TBM_BACKEND_ERR("fail to alloc surface_funcs!");
- goto fail_alloc_surface_funcs;
- }
- backend_data->surface_funcs = surface_funcs;
-
- surface_funcs->surface_free = tbm_vc4_surface_free;
- surface_funcs->surface_get_bos = tbm_vc4_surface_get_bos;
- surface_funcs->surface_get_plane_data = tbm_vc4_surface_get_plane_data;
- surface_funcs->surface_export = tbm_vc4_surface_export;
-
- /* alloc and register bo_funcs */
- bo_funcs = calloc(1, sizeof(struct _hal_tbm_bo_funcs));
- if (!bo_funcs) {
- TBM_BACKEND_ERR("fail to alloc bo_funcs!");
- goto fail_alloc_bo_funcs;
- }
- backend_data->bo_funcs = bo_funcs;
-
- bo_funcs->bo_free = tbm_vc4_bo_free;
- bo_funcs->bo_get_size = tbm_vc4_bo_get_size;
- bo_funcs->bo_get_memory_types = tbm_vc4_bo_get_memory_type;
- bo_funcs->bo_get_handle = tbm_vc4_bo_get_handle;
- bo_funcs->bo_map = tbm_vc4_bo_map;
- bo_funcs->bo_unmap = tbm_vc4_bo_unmap;
- bo_funcs->bo_lock = tbm_vc4_bo_lock;
- bo_funcs->bo_unlock = tbm_vc4_bo_unlock;
- bo_funcs->bo_export_fd = tbm_vc4_bo_export_fd;
- bo_funcs->bo_export_key = tbm_vc4_bo_export_key;
+ backend_data->bufmgr_funcs->bufmgr_get_capabilities = tbm_vc4_bufmgr_get_capabilities;
+ backend_data->bufmgr_funcs->bufmgr_get_supported_formats = tbm_vc4_bufmgr_get_supported_formats;
+ backend_data->bufmgr_funcs->bufmgr_get_plane_data = tbm_vc4_bufmgr_get_plane_data;
+ backend_data->bufmgr_funcs->bufmgr_alloc_surface = tbm_vc4_bufmgr_alloc_surface;
+ backend_data->bufmgr_funcs->bufmgr_import_surface = tbm_vc4_bufmgr_import_surface;
+ backend_data->bufmgr_funcs->bufmgr_alloc_bo = tbm_vc4_bufmgr_alloc_bo;
+ backend_data->bufmgr_funcs->bufmgr_alloc_bo_with_format = NULL;
+ backend_data->bufmgr_funcs->bufmgr_import_fd = tbm_vc4_bufmgr_import_fd;
+ backend_data->bufmgr_funcs->bufmgr_import_key = tbm_vc4_bufmgr_import_key;
+
+ backend_data->surface_funcs->surface_free = tbm_vc4_surface_free;
+ backend_data->surface_funcs->surface_get_bos = tbm_vc4_surface_get_bos;
+ backend_data->surface_funcs->surface_get_plane_data = tbm_vc4_surface_get_plane_data;
+ backend_data->surface_funcs->surface_export = tbm_vc4_surface_export;
+
+ backend_data->bo_funcs->bo_free = tbm_vc4_bo_free;
+ backend_data->bo_funcs->bo_get_size = tbm_vc4_bo_get_size;
+ backend_data->bo_funcs->bo_get_memory_types = tbm_vc4_bo_get_memory_type;
+ backend_data->bo_funcs->bo_get_handle = tbm_vc4_bo_get_handle;
+ backend_data->bo_funcs->bo_map = tbm_vc4_bo_map;
+ backend_data->bo_funcs->bo_unmap = tbm_vc4_bo_unmap;
+ backend_data->bo_funcs->bo_lock = tbm_vc4_bo_lock;
+ backend_data->bo_funcs->bo_unlock = tbm_vc4_bo_unlock;
+ backend_data->bo_funcs->bo_export_fd = tbm_vc4_bo_export_fd;
+ backend_data->bo_funcs->bo_export_key = tbm_vc4_bo_export_key;
TBM_BACKEND_DBG("drm_fd:%d", bufmgr_data->fd);
return HAL_TBM_ERROR_NONE;
-
-fail_alloc_bo_funcs:
- free(surface_funcs);
-fail_alloc_surface_funcs:
- free(bufmgr_funcs);
-fail_alloc_bufmgr_funcs:
- if (bufmgr_data->hashBos)
- drmHashDestroy(bufmgr_data->hashBos);
- close(bufmgr_data->fd);
-fail_open_drm:
- free(bufmgr_data);
-fail_alloc_bufmgr_data:
- free(backend_data);
-
- *data = NULL;
-
- return -1;
}
hal_backend hal_backend_tbm_data = {