1 /**************************************************************************
5 * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: SooChan Lim <sc1.lim@samsung.com>,
8 * Junkyeong Kim <jk0430.kim@samsung.com>,
9 * Changyeon Lee <cyeon.lee@samsung.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the
13 * "Software"), to deal in the Software without restriction, including
14 * without limitation the rights to use, copy, modify, merge, publish,
15 * distribute, sub license, and/or sell copies of the Software, and to
16 * permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
19 * The above copyright notice and this permission notice (including the
20 * next paragraph) shall be included in all copies or substantial portions
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
26 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
27 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 **************************************************************************/
38 #include <hal/hal-common.h>
39 #include "hal-tbm-interface.h"
43 #if defined(__GNUC__) && __GNUC__ >= 4
44 #define EXTERN __attribute__ ((visibility("default")))
49 #if defined(__GNUC__) && __GNUC__ >= 4
50 #define INTERN __attribute__ ((visibility("hidden")))
55 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
57 #define BUFMGR_FUNC_ENTRY(__func__) \
58 hal_tbm_backend_bufmgr_func *bufmgr_func; \
59 if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_func) return TBM_ERROR_NOT_SUPPORTED; \
60 bufmgr_func = g_tbm_funcs->bufmgr_func; \
61 if (!bufmgr_func->__func__) return TBM_ERROR_NOT_SUPPORTED;
63 #define BUFMGR_FUNC_ENTRY_NULL(__func__) \
64 hal_tbm_backend_bufmgr_func *bufmgr_func; \
65 if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_func) { if (error) *error = TBM_ERROR_NOT_SUPPORTED; return NULL; } \
66 bufmgr_func = g_tbm_funcs->bufmgr_func; \
67 if (!bufmgr_func->__func__) { if (error) *error = TBM_ERROR_NOT_SUPPORTED; return NULL; };
69 #define BUFMGR_FUNC_ENTRY_GOTO(__func__, __goto__) \
70 hal_tbm_backend_bufmgr_func *bufmgr_func; \
71 if (!g_tbm_funcs || !g_tbm_funcs->bufmgr_func) goto __goto__; \
72 bufmgr_func = g_tbm_funcs->bufmgr_func; \
73 if (!bufmgr_func->__func__) goto __goto__;
75 #define BO_FUNC_ENTRY(__func__) \
76 hal_tbm_backend_bo_func *bo_func; \
77 if (!g_tbm_funcs || !g_tbm_funcs->bo_func) return TBM_ERROR_NOT_SUPPORTED; \
78 bo_func = g_tbm_funcs->bo_func; \
79 if (!bo_func->__func__) return TBM_ERROR_NOT_SUPPORTED;
81 #define BO_FUNC_ENTRY_VOID(__func__) \
82 hal_tbm_backend_bo_func *bo_func; \
83 if (!g_tbm_funcs || !g_tbm_funcs->bo_func) return; \
84 bo_func = g_tbm_funcs->bo_func; \
85 if (!bo_func->__func__) return;
87 #define BO_FUNC_ENTRY_GOTO(__func__, __goto__) \
88 hal_tbm_backend_bo_func *bo_func; \
89 if (!g_tbm_funcs || !g_tbm_funcs->bo_func) goto __goto__; \
90 bo_func = g_tbm_funcs->bo_func; \
91 if (!bo_func->__func__) goto __goto__;
93 static hal_backend_tbm_funcs *g_tbm_funcs = NULL;
96 int hal_tbm_get_backend(void)
103 ret = hal_common_get_backend(HAL_MODULE_TBM, (void **)&g_tbm_funcs);
105 _E("Failed to get backend\n");
113 int hal_tbm_put_backend(void)
118 hal_common_put_backend(HAL_MODULE_TBM, (void *)g_tbm_funcs);
125 /* tbm_bufmgr_func */
126 EXTERN tbm_bufmgr_capability
127 hal_tbm_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error)
129 BUFMGR_FUNC_ENTRY_GOTO(bufmgr_get_capabilities, fail);
130 return bufmgr_func->bufmgr_get_capabilities((hal_tbm_backend_bufmgr_data *)bufmgr_data, error);
134 *error = TBM_ERROR_NOT_SUPPORTED;
135 return TBM_BUFMGR_CAPABILITY_NONE;
139 hal_tbm_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display)
141 BUFMGR_FUNC_ENTRY(bufmgr_bind_native_display);
142 return bufmgr_func->bufmgr_bind_native_display((hal_tbm_backend_bufmgr_data *)bufmgr_data, native_display);
146 hal_tbm_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, uint32_t **formats, uint32_t *num)
148 BUFMGR_FUNC_ENTRY(bufmgr_get_supported_formats);
149 return bufmgr_func->bufmgr_get_supported_formats((hal_tbm_backend_bufmgr_data *)bufmgr_data, formats, num);
153 hal_tbm_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, tbm_format format, int plane_idx, int width, int height,
154 uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx)
156 BUFMGR_FUNC_ENTRY(bufmgr_get_plane_data);
157 return bufmgr_func->bufmgr_get_plane_data((hal_tbm_backend_bufmgr_data *)bufmgr_data, format, plane_idx, width, height, size, offset, pitch, bo_idx);
160 EXTERN tbm_backend_bo_data *
161 hal_tbm_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size, tbm_bo_memory_type mem_types, tbm_error_e *error)
163 BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo);
164 return bufmgr_func->bufmgr_alloc_bo((hal_tbm_backend_bufmgr_data *)bufmgr_data, size, mem_types, error);
167 EXTERN tbm_backend_bo_data *
168 hal_tbm_bufmgr_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data, int format, int bo_idx, int width, int height,
169 tbm_bo_memory_type mem_types, tbm_error_e *error)
171 BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo_with_format);
172 return bufmgr_func->bufmgr_alloc_bo_with_format((hal_tbm_backend_bufmgr_data *)bufmgr_data, format, bo_idx, width, height, mem_types, error);
175 EXTERN tbm_backend_bo_data *
176 hal_tbm_bufmgr_alloc_bo_with_tiled_format(tbm_backend_bufmgr_data *bufmgr_data, int width, int height, int bpp, int format,
177 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
179 BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo_with_tiled_format);
180 return bufmgr_func->bufmgr_alloc_bo_with_tiled_format((hal_tbm_backend_bufmgr_data *)bufmgr_data, width, height, bpp, format, flags, bo_idx, error);
183 EXTERN tbm_backend_bo_data *
184 hal_tbm_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd fd, tbm_error_e *error)
186 BUFMGR_FUNC_ENTRY_NULL(bufmgr_import_fd);
187 return bufmgr_func->bufmgr_import_fd((hal_tbm_backend_bufmgr_data *)bufmgr_data, fd, error);
190 EXTERN tbm_backend_bo_data *
191 hal_tbm_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error)
193 BUFMGR_FUNC_ENTRY_NULL(bufmgr_import_key);
194 return bufmgr_func->bufmgr_import_key((hal_tbm_backend_bufmgr_data *)bufmgr_data, key, error);
200 hal_tbm_bo_free(tbm_backend_bo_data *bo_data)
202 BO_FUNC_ENTRY_VOID(bo_free);
203 bo_func->bo_free((hal_tbm_backend_bo_data *)bo_data);
207 hal_tbm_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error)
209 BO_FUNC_ENTRY_GOTO(bo_get_size, fail);
210 return bo_func->bo_get_size((hal_tbm_backend_bo_data *)bo_data, error);
214 *error = TBM_ERROR_NOT_SUPPORTED;
218 EXTERN tbm_bo_memory_type
219 hal_tbm_bo_get_memory_types(tbm_backend_bo_data *bo_data, tbm_error_e *error)
221 BO_FUNC_ENTRY_GOTO(bo_get_memory_types, fail);
222 return bo_func->bo_get_memory_types((hal_tbm_backend_bo_data *)bo_data, error);
226 *error = TBM_ERROR_NOT_SUPPORTED;
227 return TBM_BO_DEFAULT;
231 hal_tbm_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error)
233 BO_FUNC_ENTRY_GOTO(bo_get_handle, fail);
234 return bo_func->bo_get_handle((hal_tbm_backend_bo_data *)bo_data, device, error);
238 *error = TBM_ERROR_NOT_SUPPORTED;
239 return (tbm_bo_handle)NULL;
243 hal_tbm_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt, tbm_error_e *error)
245 BO_FUNC_ENTRY_GOTO(bo_map, fail);
246 return bo_func->bo_map((hal_tbm_backend_bo_data *)bo_data, device, opt, error);
250 *error = TBM_ERROR_NOT_SUPPORTED;
251 return (tbm_bo_handle)NULL;
255 hal_tbm_bo_unmap(tbm_backend_bo_data *bo_data)
257 BO_FUNC_ENTRY(bo_unmap);
258 return bo_func->bo_unmap((hal_tbm_backend_bo_data *)bo_data);
262 hal_tbm_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt)
264 BO_FUNC_ENTRY(bo_unmap);
265 return bo_func->bo_lock((hal_tbm_backend_bo_data *)bo_data, device, opt);
269 hal_tbm_bo_unlock(tbm_backend_bo_data *bo_data)
271 BO_FUNC_ENTRY(bo_unmap);
272 return bo_func->bo_unlock((hal_tbm_backend_bo_data *)bo_data);
276 hal_tbm_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error)
278 BO_FUNC_ENTRY_GOTO(bo_export_fd, fail);
279 return bo_func->bo_export_fd((hal_tbm_backend_bo_data *)bo_data, error);
283 *error = TBM_ERROR_NOT_SUPPORTED;
288 hal_tbm_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
290 BO_FUNC_ENTRY_GOTO(bo_export_key, fail);
291 return bo_func->bo_export_key((hal_tbm_backend_bo_data *)bo_data, error);
295 *error = TBM_ERROR_NOT_SUPPORTED;
300 /* tbm_backend_func*/
302 hal_tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error)
304 return tbm_backend_bufmgr_query_display_server(bufmgr, error);