From 4543625791f15d87f59a17958f9bebd89d76981c Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Wed, 27 Jan 2021 15:43:54 +0900 Subject: [PATCH] split hal_backend_tbm_funcs Signed-off-by: Junkyeong Kim --- include/hal-tbm-interface.h | 14 ++- src/hal-api-tbm.c | 295 ++++++++++++++++++++++++-------------------- 2 files changed, 172 insertions(+), 137 deletions(-) diff --git a/include/hal-tbm-interface.h b/include/hal-tbm-interface.h index ba61185..fc7b9b1 100644 --- a/include/hal-tbm-interface.h +++ b/include/hal-tbm-interface.h @@ -43,10 +43,7 @@ extern "C" { typedef void hal_tbm_backend_bufmgr_data; typedef void hal_tbm_backend_bo_data; -typedef struct _hal_backend_tbm_funcs { - int (*start)(void); - int (*stop)(void); - +typedef struct _hal_tbm_backend_bufmgr_func { /* tbm_bufmgr_func */ tbm_bufmgr_capability (*bufmgr_get_capabilities)(hal_tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error); tbm_error_e (*bufmgr_bind_native_display)(hal_tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display); @@ -60,8 +57,9 @@ typedef struct _hal_backend_tbm_funcs { tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error); hal_tbm_backend_bo_data *(*bufmgr_import_fd)(hal_tbm_backend_bufmgr_data *bufmgr_data, tbm_fd fd, tbm_error_e *error); hal_tbm_backend_bo_data *(*bufmgr_import_key)(hal_tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error); +} hal_tbm_backend_bufmgr_func; - /* tbm_bo_func*/ +typedef struct _hal_tbm_backend_bo_func { void (*bo_free)(hal_tbm_backend_bo_data *bo_data); int (*bo_get_size)(hal_tbm_backend_bo_data *bo_data, tbm_error_e *error); tbm_bo_memory_type (*bo_get_memory_types)(hal_tbm_backend_bo_data *bo_data, tbm_error_e *error); @@ -72,6 +70,12 @@ typedef struct _hal_backend_tbm_funcs { tbm_error_e (*bo_unlock)(hal_tbm_backend_bo_data *bo_data); tbm_fd (*bo_export_fd)(hal_tbm_backend_bo_data *bo_data, tbm_error_e *error); tbm_key (*bo_export_key)(hal_tbm_backend_bo_data *bo_data, tbm_error_e *error); +} hal_tbm_backend_bo_func; + +typedef struct _hal_backend_tbm_funcs +{ + hal_tbm_backend_bufmgr_func *bufmgr_func; + hal_tbm_backend_bo_func *bo_func; } hal_backend_tbm_funcs; int hal_tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error); diff --git a/src/hal-api-tbm.c b/src/hal-api-tbm.c index acff60e..c49d066 100644 --- a/src/hal-api-tbm.c +++ b/src/hal-api-tbm.c @@ -40,15 +40,59 @@ #include "hal-tbm.h" #include "common.h" -#ifndef EXPORT -#define EXPORT __attribute__ ((visibility("default"))) +#if defined(__GNUC__) && __GNUC__ >= 4 +#define EXTERN __attribute__ ((visibility("default"))) +#else +#define EXTERN +#endif + +#if defined(__GNUC__) && __GNUC__ >= 4 +#define INTERN __attribute__ ((visibility("hidden"))) +#else +#define INTERN #endif #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) +#define BUFMGR_FUNC_ENTRY(__func__) \ + hal_tbm_backend_bufmgr_func *bufmgr_func; \ + if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_func) return TBM_ERROR_NOT_SUPPORTED; \ + bufmgr_func = g_tbm_funcs->bufmgr_func; \ + if (!bufmgr_func->__func__) return TBM_ERROR_NOT_SUPPORTED; + +#define BUFMGR_FUNC_ENTRY_NULL(__func__) \ + hal_tbm_backend_bufmgr_func *bufmgr_func; \ + if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_func) { if (error) *error = TBM_ERROR_NOT_SUPPORTED; return NULL; } \ + bufmgr_func = g_tbm_funcs->bufmgr_func; \ + if (!bufmgr_func->__func__) { if (error) *error = TBM_ERROR_NOT_SUPPORTED; return NULL; }; + +#define BUFMGR_FUNC_ENTRY_GOTO(__func__, __goto__) \ + hal_tbm_backend_bufmgr_func *bufmgr_func; \ + if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_func) goto __goto__; \ + bufmgr_func = g_tbm_funcs->bufmgr_func; \ + if (!bufmgr_func->__func__) goto __goto__; + +#define BO_FUNC_ENTRY(__func__) \ + hal_tbm_backend_bo_func *bo_func; \ + if (!g_tbm_funcs || !g_tbm_funcs->bo_func) return TBM_ERROR_NOT_SUPPORTED; \ + bo_func = g_tbm_funcs->bo_func; \ + if (!bo_func->__func__) return TBM_ERROR_NOT_SUPPORTED; + +#define BO_FUNC_ENTRY_VOID(__func__) \ + hal_tbm_backend_bo_func *bo_func; \ + if (!g_tbm_funcs || !g_tbm_funcs->bo_func) return; \ + bo_func = g_tbm_funcs->bo_func; \ + if (!bo_func->__func__) return; + +#define BO_FUNC_ENTRY_GOTO(__func__, __goto__) \ + hal_tbm_backend_bo_func *bo_func; \ + if (!g_tbm_funcs || !g_tbm_funcs->bo_func) goto __goto__; \ + bo_func = g_tbm_funcs->bo_func; \ + if (!bo_func->__func__) goto __goto__; + static hal_backend_tbm_funcs *g_tbm_funcs = NULL; -EXPORT +EXTERN int hal_tbm_get_backend(void) { int ret; @@ -65,7 +109,7 @@ int hal_tbm_get_backend(void) return 0; } -EXPORT +EXTERN int hal_tbm_put_backend(void) { if (!g_tbm_funcs) @@ -77,198 +121,185 @@ int hal_tbm_put_backend(void) return 0; } -EXPORT -int hal_tbm_start(void) -{ - if (!g_tbm_funcs) - return -ENOTSUP; - return g_tbm_funcs->start(); -} - -EXPORT -int hal_tbm_stop(void) -{ - if (!g_tbm_funcs) - return -ENOTSUP; - return g_tbm_funcs->stop(); -} /* tbm_bufmgr_func */ -tbm_bufmgr_capability hal_tbm_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) +EXTERN tbm_bufmgr_capability +hal_tbm_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_get_capabilities) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return TBM_BUFMGR_CAPABILITY_NONE; - } - return g_tbm_funcs->bufmgr_get_capabilities((hal_tbm_backend_bufmgr_data *)bufmgr_data, error); + BUFMGR_FUNC_ENTRY_GOTO(bufmgr_get_capabilities, fail); + return bufmgr_func->bufmgr_get_capabilities((hal_tbm_backend_bufmgr_data *)bufmgr_data, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return TBM_BUFMGR_CAPABILITY_NONE; } -tbm_error_e hal_tbm_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) +EXTERN tbm_error_e +hal_tbm_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_bind_native_display) - return TBM_ERROR_NOT_SUPPORTED; - return g_tbm_funcs->bufmgr_bind_native_display((hal_tbm_backend_bufmgr_data *)bufmgr_data, native_display); + BUFMGR_FUNC_ENTRY(bufmgr_bind_native_display); + return bufmgr_func->bufmgr_bind_native_display((hal_tbm_backend_bufmgr_data *)bufmgr_data, native_display); } -tbm_error_e hal_tbm_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, uint32_t **formats, uint32_t *num) +EXTERN tbm_error_e +hal_tbm_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, uint32_t **formats, uint32_t *num) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_get_supported_formats) - return TBM_ERROR_NOT_SUPPORTED; - return g_tbm_funcs->bufmgr_get_supported_formats((hal_tbm_backend_bufmgr_data *)bufmgr_data, formats, num); + BUFMGR_FUNC_ENTRY(bufmgr_get_supported_formats); + return bufmgr_func->bufmgr_get_supported_formats((hal_tbm_backend_bufmgr_data *)bufmgr_data, formats, num); } -tbm_error_e hal_tbm_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, tbm_format format, int plane_idx, int width, int height, +EXTERN tbm_error_e +hal_tbm_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, tbm_format format, int plane_idx, int width, int height, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_get_plane_data) - return TBM_ERROR_NOT_SUPPORTED; - return g_tbm_funcs->bufmgr_get_plane_data((hal_tbm_backend_bufmgr_data *)bufmgr_data, format, plane_idx, width, height, size, offset, pitch, bo_idx); + BUFMGR_FUNC_ENTRY(bufmgr_get_plane_data); + return bufmgr_func->bufmgr_get_plane_data((hal_tbm_backend_bufmgr_data *)bufmgr_data, format, plane_idx, width, height, size, offset, pitch, bo_idx); } -tbm_backend_bo_data *hal_tbm_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size, tbm_bo_memory_type mem_types, tbm_error_e *error) +EXTERN tbm_backend_bo_data * +hal_tbm_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size, tbm_bo_memory_type mem_types, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_alloc_bo) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return NULL; - } - return g_tbm_funcs->bufmgr_alloc_bo((hal_tbm_backend_bufmgr_data *)bufmgr_data, size, mem_types, error); + BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo); + return bufmgr_func->bufmgr_alloc_bo((hal_tbm_backend_bufmgr_data *)bufmgr_data, size, mem_types, error); } -tbm_backend_bo_data *hal_tbm_bufmgr_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data, int format, int bo_idx, int width, int height, +EXTERN tbm_backend_bo_data * +hal_tbm_bufmgr_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data, int format, int bo_idx, int width, int height, tbm_bo_memory_type mem_types, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_alloc_bo_with_format) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return NULL; - } - return g_tbm_funcs->bufmgr_alloc_bo_with_format((hal_tbm_backend_bufmgr_data *)bufmgr_data, format, bo_idx, width, height, mem_types, error); + BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo_with_format); + return bufmgr_func->bufmgr_alloc_bo_with_format((hal_tbm_backend_bufmgr_data *)bufmgr_data, format, bo_idx, width, height, mem_types, error); } -tbm_backend_bo_data *hal_tbm_bufmgr_alloc_bo_with_tiled_format(tbm_backend_bufmgr_data *bufmgr_data, int width, int height, int bpp, int format, +EXTERN tbm_backend_bo_data * +hal_tbm_bufmgr_alloc_bo_with_tiled_format(tbm_backend_bufmgr_data *bufmgr_data, int width, int height, int bpp, int format, tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_alloc_bo_with_tiled_format) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return NULL; - } - return g_tbm_funcs->bufmgr_alloc_bo_with_tiled_format((hal_tbm_backend_bufmgr_data *)bufmgr_data, width, height, bpp, format, flags, bo_idx, error); + BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo_with_tiled_format); + return bufmgr_func->bufmgr_alloc_bo_with_tiled_format((hal_tbm_backend_bufmgr_data *)bufmgr_data, width, height, bpp, format, flags, bo_idx, error); } -tbm_backend_bo_data *hal_tbm_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd fd, tbm_error_e *error) +EXTERN tbm_backend_bo_data * +hal_tbm_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd fd, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_import_fd) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return NULL; - } - return g_tbm_funcs->bufmgr_import_fd((hal_tbm_backend_bufmgr_data *)bufmgr_data, fd, error); + BUFMGR_FUNC_ENTRY_NULL(bufmgr_import_fd); + return bufmgr_func->bufmgr_import_fd((hal_tbm_backend_bufmgr_data *)bufmgr_data, fd, error); } -tbm_backend_bo_data *hal_tbm_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) +EXTERN tbm_backend_bo_data * +hal_tbm_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_import_key) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return NULL; - } - return g_tbm_funcs->bufmgr_import_key((hal_tbm_backend_bufmgr_data *)bufmgr_data, key, error); + BUFMGR_FUNC_ENTRY_NULL(bufmgr_import_key); + return bufmgr_func->bufmgr_import_key((hal_tbm_backend_bufmgr_data *)bufmgr_data, key, error); } /* tbm_bo_func*/ -void hal_tbm_bo_free(tbm_backend_bo_data *bo_data) +EXTERN void +hal_tbm_bo_free(tbm_backend_bo_data *bo_data) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_free) - return; - g_tbm_funcs->bo_free((hal_tbm_backend_bo_data *)bo_data); + BO_FUNC_ENTRY_VOID(bo_free); + bo_func->bo_free((hal_tbm_backend_bo_data *)bo_data); } -int hal_tbm_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) +EXTERN int +hal_tbm_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_get_size) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return 0; - } - return g_tbm_funcs->bo_get_size((hal_tbm_backend_bo_data *)bo_data, error); + BO_FUNC_ENTRY_GOTO(bo_get_size, fail); + return bo_func->bo_get_size((hal_tbm_backend_bo_data *)bo_data, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return 0; } -tbm_bo_memory_type hal_tbm_bo_get_memory_types(tbm_backend_bo_data *bo_data, tbm_error_e *error) +EXTERN tbm_bo_memory_type +hal_tbm_bo_get_memory_types(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_get_memory_types) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return TBM_BO_DEFAULT; - } - return g_tbm_funcs->bo_get_memory_types((hal_tbm_backend_bo_data *)bo_data, error); + BO_FUNC_ENTRY_GOTO(bo_get_memory_types, fail); + return bo_func->bo_get_memory_types((hal_tbm_backend_bo_data *)bo_data, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return TBM_BO_DEFAULT; } -tbm_bo_handle hal_tbm_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) +EXTERN tbm_bo_handle +hal_tbm_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_get_handle) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return (tbm_bo_handle)NULL; - } - return g_tbm_funcs->bo_get_handle((hal_tbm_backend_bo_data *)bo_data, device, error); + BO_FUNC_ENTRY_GOTO(bo_get_handle, fail); + return bo_func->bo_get_handle((hal_tbm_backend_bo_data *)bo_data, device, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return (tbm_bo_handle)NULL; } -tbm_bo_handle hal_tbm_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt, tbm_error_e *error) +EXTERN tbm_bo_handle +hal_tbm_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_map) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return (tbm_bo_handle)NULL; - } - return g_tbm_funcs->bo_map((hal_tbm_backend_bo_data *)bo_data, device, opt, error); + BO_FUNC_ENTRY_GOTO(bo_map, fail); + return bo_func->bo_map((hal_tbm_backend_bo_data *)bo_data, device, opt, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return (tbm_bo_handle)NULL; } -tbm_error_e hal_tbm_bo_unmap(tbm_backend_bo_data *bo_data) +EXTERN tbm_error_e +hal_tbm_bo_unmap(tbm_backend_bo_data *bo_data) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_unmap) - return TBM_ERROR_NOT_SUPPORTED; - return g_tbm_funcs->bo_unmap((hal_tbm_backend_bo_data *)bo_data); + BO_FUNC_ENTRY(bo_unmap); + return bo_func->bo_unmap((hal_tbm_backend_bo_data *)bo_data); } -tbm_error_e hal_tbm_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt) +EXTERN tbm_error_e +hal_tbm_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_lock) - return TBM_ERROR_NOT_SUPPORTED; - return g_tbm_funcs->bo_lock((hal_tbm_backend_bo_data *)bo_data, device, opt); + BO_FUNC_ENTRY(bo_unmap); + return bo_func->bo_lock((hal_tbm_backend_bo_data *)bo_data, device, opt); } -tbm_error_e hal_tbm_bo_unlock(tbm_backend_bo_data *bo_data) +EXTERN tbm_error_e +hal_tbm_bo_unlock(tbm_backend_bo_data *bo_data) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_unlock) - return TBM_ERROR_NOT_SUPPORTED; - return g_tbm_funcs->bo_unlock((hal_tbm_backend_bo_data *)bo_data); + BO_FUNC_ENTRY(bo_unmap); + return bo_func->bo_unlock((hal_tbm_backend_bo_data *)bo_data); } -tbm_fd hal_tbm_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) +EXTERN tbm_fd +hal_tbm_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_export_fd) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return -1; - } - return g_tbm_funcs->bo_export_fd((hal_tbm_backend_bo_data *)bo_data, error); + BO_FUNC_ENTRY_GOTO(bo_export_fd, fail); + return bo_func->bo_export_fd((hal_tbm_backend_bo_data *)bo_data, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return -1; } -tbm_key hal_tbm_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) +EXTERN tbm_key +hal_tbm_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - if (!g_tbm_funcs || !g_tbm_funcs->bo_export_key) { - if (error) - *error = TBM_ERROR_NOT_SUPPORTED; - return 0; - } - return g_tbm_funcs->bo_export_key((hal_tbm_backend_bo_data *)bo_data, error); + BO_FUNC_ENTRY_GOTO(bo_export_key, fail); + return bo_func->bo_export_key((hal_tbm_backend_bo_data *)bo_data, error); + +fail: + if (error) + *error = TBM_ERROR_NOT_SUPPORTED; + return 0; } -int hal_tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error) + +/* tbm_backend_func*/ +EXTERN int +hal_tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error) { return tbm_backend_bufmgr_query_display_server(bufmgr, error); } -- 2.7.4