add a private resource for hal_tbm_surface private resource and hal_tbm_surface_funcs 80/258280/3
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 13 May 2021 05:36:15 +0000 (14:36 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 23 Jun 2021 23:52:01 +0000 (08:52 +0900)
The tbm backend can manage a new resource which names hal_tbm_surface.
Therefore, it has to register the backend funcs for managing hal_tbm_surface.

Change-Id: I0ed0a867d5252f7250add9dfd97fd555c2bb47cb

src/libhal-backend-tbm-vc4/tbm_backend_vc4.c

index d73adce..38f85bf 100644 (file)
@@ -128,8 +128,22 @@ union _tbm_bo_cache_state {
        } data;
 };
 
-typedef struct _tbm_vc4_bufmgr tbm_vc4_bufmgr;
-typedef struct _tbm_vc4_bo tbm_vc4_bo;
+typedef struct _tbm_vc4_bufmgr  tbm_vc4_bufmgr;
+typedef struct _tbm_vc4_surface tbm_vc4_surface;
+typedef struct _tbm_vc4_bo      tbm_vc4_bo;
+
+/* tbm surface object for vc4 */
+struct _tbm_vc4_surface {
+       struct list_head link;
+       uint32_t refcnt;
+
+       uint32_t width;
+       uint32_t height;
+       hal_tbm_format format;
+       tbm_vc4_bufmgr *bufmgr_data;
+       int num_bos;
+       tbm_vc4_bo *bo_data;
+};
 
 /* tbm buffor object for vc4 */
 struct _tbm_vc4_bo {
@@ -165,6 +179,8 @@ struct _tbm_vc4_bufmgr {
        int isLocal;
        void *hashBos;
 
+       struct list_head surface_data_list;
+
        int use_dma_fence;
 
        int tgl_fd;
@@ -1349,6 +1365,20 @@ tbm_vc4_bufmgr_get_plane_data(hal_tbm_bufmgr *bufmgr,
        return HAL_TBM_ERROR_NONE;
 }
 
+static hal_tbm_surface *
+tbm_vc4_bufmgr_alloc_surface(hal_tbm_bufmgr *bufmgr, uint32_t width, uint32_t height, hal_tbm_format format,
+                       hal_tbm_bo_memory_type mem_types, uint64_t *modifiers, uint32_t num_modifiers, hal_tbm_error *error)
+{
+       return NULL;
+}
+
+static hal_tbm_surface *
+tbm_vc4_bufmgr_import_surface(hal_tbm_bufmgr *bufmgr, uint32_t width, uint32_t height, hal_tbm_format format,
+                       hal_tbm_surface_buffer_data *buffer_data, hal_tbm_error *error)
+{
+       return NULL;
+}
+
 static hal_tbm_bo *
 tbm_vc4_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
                                        hal_tbm_bo_memory_type flags, hal_tbm_error *error)
@@ -1663,6 +1693,30 @@ tbm_vc4_bufmgr_import_key(hal_tbm_bufmgr *bufmgr, hal_tbm_key key, hal_tbm_error
 }
 
 static void
+tbm_vc4_surface_free(hal_tbm_surface *surface)
+{
+
+}
+
+static hal_tbm_bo **
+tbm_vc4_surface_get_bos(hal_tbm_surface *surface, int *num_bos, hal_tbm_error *error)
+{
+       return NULL;
+}
+
+static hal_tbm_error
+tbm_vc4_surface_get_plane_data(hal_tbm_surface *surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx)
+{
+       return HAL_TBM_ERROR_NONE;
+}
+
+static hal_tbm_surface_buffer_data *
+tbm_vc4_surface_export(hal_tbm_surface *surface, hal_tbm_error *error)
+{
+       return NULL;
+}
+
+static void
 tbm_vc4_bo_free(hal_tbm_bo *bo)
 {
        tbm_vc4_bo *bo_data = (tbm_vc4_bo *)bo;
@@ -2148,6 +2202,7 @@ hal_backend_tbm_vc4_exit(void *data)
 {
        hal_tbm_backend_data *backend_data = (hal_tbm_backend_data *)data;
        tbm_vc4_bufmgr *bufmgr_data;
+       tbm_vc4_surface *s = NULL, *ss = NULL;
        unsigned long key;
        void *value;
 
@@ -2156,19 +2211,26 @@ hal_backend_tbm_vc4_exit(void *data)
        bufmgr_data = (tbm_vc4_bufmgr *)backend_data->bufmgr;
        TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, -1);
 
-       if (backend_data->bufmgr_funcs)
-               free(backend_data->bufmgr_funcs);
        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);
+                       tbm_vc4_surface_free(s);
+               }
+       }
 
        if (bufmgr_data->hashBos) {
                while (drmHashFirst(bufmgr_data->hashBos, &key, &value) > 0) {
-                       free(value);
                        drmHashDelete(bufmgr_data->hashBos, key);
+                       free(value);
                }
-
                drmHashDestroy(bufmgr_data->hashBos);
-               bufmgr_data->hashBos = NULL;
        }
 
        _bufmgr_deinit_cache_state(bufmgr_data);
@@ -2186,6 +2248,7 @@ 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;
@@ -2258,6 +2321,9 @@ hal_backend_tbm_vc4_init(void **data)
        /*Create Hash Table*/
        bufmgr_data->hashBos = drmHashCreate();
 
+       // 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) {
@@ -2269,6 +2335,8 @@ hal_backend_tbm_vc4_init(void **data)
        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;
 #ifdef VC4_TILED_FORMAT
        bufmgr_funcs->bufmgr_alloc_bo_with_format = tbm_vc4_bufmgr_alloc_bo_with_tiled_format;
@@ -2278,6 +2346,19 @@ hal_backend_tbm_vc4_init(void **data)
        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!\n");
+               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) {
@@ -2302,6 +2383,8 @@ hal_backend_tbm_vc4_init(void **data)
        return HAL_TBM_ERROR_NONE;
 
 fail_alloc_bo_funcs:
+       free(surface_funcs);
+fail_alloc_surface_funcs:
        free(bufmgr_funcs);
 fail_alloc_bufmgr_funcs:
        _bufmgr_deinit_cache_state(bufmgr_data);