--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(hal-api-tbm C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin")
+SET(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+SET(LIBDIR ${CMAKE_LIBDIR_PREFIX})
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.1.0")
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "${PREFIX}/bin")
+SET(INCLUDEDIR "${PREFIX}/include")
+SET(LIBDIR ${CMAKE_LIBDIR_PREFIX})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+SET(PKG_MODULES
+ hal-api-common
+ dlog
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${PKG_MODULES})
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt")
+SET(CMAKE_EXE_LINKER_FLAGS "-pie")
+
+ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_TBM\"")
+
+SET(SRCS
+ src/hal-api-tbm.c)
+
+ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -lm -Wl,-z,nodelete,--no-undefined)
+SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
+
+CONFIGURE_FILE( ${PROJECT_NAME}.pc ${PROJECT_NAME}.pc @ONLY)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR}/hal)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-tbm-types.h DESTINATION ${INCLUDEDIR}/hal)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-tbm.h DESTINATION ${INCLUDEDIR}/hal)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-tbm-interface.h DESTINATION ${INCLUDEDIR}/hal)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig)
--- /dev/null
+Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null
+hal api tbm
--- /dev/null
+# Package Information for pkg-config
+
+package_name=hal-api-tbm
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@/hal
+libdir=@LIBDIR@/hal
+includedir=@INCLUDEDIR@/hal
+
+Name: ${package_name}
+Description: ${package_name} interface
+Version: @VERSION@
+
+Requires:
+Libs: -L${libdir} -l${package_name}
+Cflags: -I${includedir}
+CXXflags: -I${includedir}
--- /dev/null
+/**************************************************************************
+ *
+ * hal-api-tbm
+ *
+ * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: SooChan Lim <sc1.lim@samsung.com>,
+ * Junkyeong Kim <jk0430.kim@samsung.com>,
+ * Changyeon Lee <cyeon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#ifndef __HAL_TBM_INTERFACE__
+#define __HAL_TBM_INTERFACE__
+
+#include <hal/hal-common-interface.h>
+#include "hal-tbm-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _hal_tbm_bufmgr_func {
+ /* tbm_bufmgr_func */
+ hal_tbm_bufmgr_capability (*bufmgr_get_capabilities)(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_error *error);
+ hal_tbm_error (*bufmgr_bind_native_display)(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_native_display *native_display);
+ hal_tbm_error (*bufmgr_get_supported_formats)(hal_tbm_bufmgr_data *bufmgr_data, uint32_t **formats, uint32_t *num);
+ hal_tbm_error (*bufmgr_get_plane_data)(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_format format, int plane_idx, int width, int height,
+ uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx);
+ hal_tbm_bo_data *(*bufmgr_alloc_bo)(hal_tbm_bufmgr_data *bufmgr_data, unsigned int size, hal_tbm_bo_memory_type mem_types, hal_tbm_error *error);
+ hal_tbm_bo_data *(*bufmgr_alloc_bo_with_format)(hal_tbm_bufmgr_data *bufmgr_data, int format, int bo_idx, int width, int height,
+ hal_tbm_bo_memory_type mem_types, hal_tbm_error *error);
+ hal_tbm_bo_data *(*bufmgr_alloc_bo_with_tiled_format)(hal_tbm_bufmgr_data *bufmgr_data, int width, int height, int bpp, int format,
+ hal_tbm_bo_memory_type flags, int bo_idx, hal_tbm_error *error);
+ hal_tbm_bo_data *(*bufmgr_import_fd)(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_fd fd, hal_tbm_error *error);
+ hal_tbm_bo_data *(*bufmgr_import_key)(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_key key, hal_tbm_error *error);
+} hal_tbm_bufmgr_func;
+
+typedef struct _hal_tbm_bo_func {
+ void (*bo_free)(hal_tbm_bo_data *bo_data);
+ int (*bo_get_size)(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+ hal_tbm_bo_memory_type (*bo_get_memory_types)(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+ hal_tbm_bo_handle (*bo_get_handle)(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, hal_tbm_error *error);
+ hal_tbm_bo_handle (*bo_map)(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt, hal_tbm_error *error);
+ hal_tbm_error (*bo_unmap)(hal_tbm_bo_data *bo_data);
+ hal_tbm_error (*bo_lock)(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt);
+ hal_tbm_error (*bo_unlock)(hal_tbm_bo_data *bo_data);
+ hal_tbm_fd (*bo_export_fd)(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+ hal_tbm_key (*bo_export_key)(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+} hal_tbm_bo_func;
+
+int hal_tbm_query_display_server(hal_tbm_error *error);
+hal_tbm_bufmgr_func *hal_tbm_alloc_bufmgr_func(hal_tbm_error *error);
+void hal_tbm_free_bufmgr_func(hal_tbm_bufmgr_func *func);
+hal_tbm_error hal_tbm_register_bufmgr_func(hal_tbm_bufmgr_func *func);
+hal_tbm_bo_func *hal_tbm_alloc_bo_func(hal_tbm_error *error);
+void hal_tbm_free_bo_func(hal_tbm_bo_func *func);
+hal_tbm_error hal_tbm_register_bo_func(hal_tbm_bo_func *func);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_TBM_INTERFACE__ */
--- /dev/null
+/**************************************************************************
+ *
+ * hal-api-tbm
+ *
+ * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: SooChan Lim <sc1.lim@samsung.com>,
+ * Junkyeong Kim <jk0430.kim@samsung.com>,
+ * Changyeon Lee <cyeon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#ifndef _HAL_TBM_TYPES_H_
+#define _HAL_TBM_TYPES_H_
+
+#include <stdint.h>
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* hal tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
+#ifndef HAL_TBM_ERROR_BASE // CAUTION :: This MUST be the same as TBM_ERROR_BASE.
+#define HAL_TBM_ERROR_BASE -0x02830000
+#endif
+
+/**
+ * @brief Enumeration for hal tbm error type.
+ */
+typedef enum {
+ /* HAL_TBM_ERROR_XXX. start from (HAL_TBM_ERROR_BASE | 0x0001) to (HAL_TBM_ERROR_BASE | 0x0099) */
+ HAL_TBM_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ HAL_TBM_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ HAL_TBM_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */
+ HAL_TBM_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented */
+ HAL_TBM_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+
+ /* HAL_TBM_BO_ERROR_XXX. start from (HAL_TBM_ERROR_BASE | 0x0101) to (HAL_TBM_ERROR_BASE | 0x0199) */
+ HAL_TBM_BO_ERROR_GET_FD_FAILED = HAL_TBM_ERROR_BASE | 0x0101, /**< failed to get fd in bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_HEAP_ALLOC_FAILED = HAL_TBM_ERROR_OUT_OF_MEMORY, /**< failed to allocate the heap memory in bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_LOAD_MODULE_FAILED = HAL_TBM_ERROR_BASE | 0x0103, /**< failed to load module (DEPRECATED) */
+ HAL_TBM_BO_ERROR_THREAD_INIT_FAILED = HAL_TBM_ERROR_BASE | 0x0104, /**< failed to initialize the pthread (DEPRECATED) */
+ HAL_TBM_BO_ERROR_BO_ALLOC_FAILED = HAL_TBM_ERROR_OUT_OF_MEMORY, /**< failed to allocate hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_INIT_STATE_FAILED = HAL_TBM_ERROR_BASE | 0x0106, /**< failed to initialize the state of hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_IMPORT_FAILED = HAL_TBM_ERROR_BASE | 0x0107, /**< failed to import the handle of hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_IMPORT_FD_FAILED = HAL_TBM_ERROR_BASE | 0x0108, /**< failed to import fd of hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_EXPORT_FAILED = HAL_TBM_ERROR_BASE | 0x0109, /**< failed to export the handle of the hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_EXPORT_FD_FAILED = HAL_TBM_ERROR_BASE | 0x0110, /**< failed to export fd of hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_GET_HANDLE_FAILED = HAL_TBM_ERROR_BASE | 0x0111, /**< failed to get the hal_tbm_bo_handle (DEPRECATED) */
+ HAL_TBM_BO_ERROR_LOCK_FAILED = HAL_TBM_ERROR_BASE | 0x0112, /**< failed to lock the hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_MAP_FAILED = HAL_TBM_ERROR_BASE | 0x0113, /**< failed to map the hal_tbm_bo to get the hal_tbm_bo_handle (DEPRECATED) */
+ HAL_TBM_BO_ERROR_UNMAP_FAILED = HAL_TBM_ERROR_BASE | 0x0114, /**< failed to unmap the hal_tbm_bo (DEPRECATED) */
+ HAL_TBM_BO_ERROR_SWAP_FAILED = HAL_TBM_ERROR_BASE | 0x0115, /**< failed to swap the tbm_bos (DEPRECATED) */
+ HAL_TBM_BO_ERROR_DUP_FD_FAILED = HAL_TBM_ERROR_BASE | 0x0116, /**< failed to duplicate fd (DEPRECATED) */
+} hal_tbm_error;
+
+/**
+ * @brief Enumeration of tbm buffer manager capability.
+ */
+typedef enum {
+ HAL_TBM_BUFMGR_CAPABILITY_NONE = 0, /**< Not Support capability*/
+ HAL_TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0), /**< Support sharing buffer by tbm key */
+ HAL_TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1), /**< Support sharing buffer by tbm fd */
+ HAL_TBM_BUFMGR_CAPABILITY_TBM_SYNC = (1 << 2), /**< Support timeline sync */
+ HAL_TBM_BUFMGR_CAPABILITY_TILED_MEMORY = (1 << 3), /**< Support tiled memory */
+} hal_tbm_bufmgr_capability;
+
+/**
+ * @brief Enumeration of bo memory type
+ */
+typedef enum {
+ HAL_TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */
+ HAL_TBM_BO_SCANOUT = (1 << 0), /**< scanout memory */
+ HAL_TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory */
+ HAL_TBM_BO_WC = (1 << 2), /**< write-combine memory */
+ HAL_TBM_BO_TILED = (1 << 3), /**< tiled memory */
+ HAL_TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */
+} hal_tbm_bo_memory_type;
+
+/**
+ * @brief Definition for the device type to access hal_tbm_bo
+ */
+typedef enum {
+ HAL_TBM_DEVICE_DEFAULT = 0, /**< the device type to get the default handle */
+ HAL_TBM_DEVICE_CPU, /**< the device type to get the virtual memory */
+ HAL_TBM_DEVICE_2D, /**< the device type to get the 2D memory handle */
+ HAL_TBM_DEVICE_3D, /**< the device type to get the 3D memory handle */
+ HAL_TBM_DEVICE_MM, /**< the device type to get the the multimedia handle */
+
+} tbm_bo_device_type;
+
+/**
+ * @brief Definition for the optoin to access hal_tbm_bo
+ */
+typedef enum {
+ HAL_TBM_OPTION_NONE = (1 << 0), /**< the option is none */
+ HAL_TBM_OPTION_READ = (1 << 0), /**< the option to access to read the bo */
+ HAL_TBM_OPTION_WRITE = (1 << 1), /**< the option to access to write the bo */
+ HAL_TBM_OPTION_VENDOR = (0xffff0000), /**< the the vendor specific option that depends on the backend */
+} tbm_bo_access_option;
+
+/**
+ * @brief hal_tbm_bo_handle abstraction of the memory handle by HAL_TBM_DEVICE_TYPE
+ */
+typedef union _hal_tbm_bo_handle {
+ void *ptr;
+ int32_t s32;
+ uint32_t u32;
+ int64_t s64;
+ uint64_t u64;
+} hal_tbm_bo_handle;
+
+/**
+ * @brief Definition for hal_tbm_bufmgr handle
+ */
+typedef struct _hal_tbm_bufmgr hal_tbm_bufmgr;
+
+/**
+ * @brief Definition for hal_tbm_bufmgr_data handle created by hal tbm backend
+ */
+typedef void hal_tbm_bufmgr_data;
+
+/**
+ * @brief Definition for the tizen buffer object
+ */
+typedef void hal_tbm_bo_data;
+
+/**
+ * @brief Definition for native display (wl_display in tizen)
+ */
+typedef void hal_tbm_native_display;
+
+/**
+ * @brief Definition for the file descripter of the system buffer manager
+ */
+typedef int32_t hal_tbm_fd;
+
+/**
+ * @brief Definition for the key associated with the buffer object
+ */
+typedef uint32_t hal_tbm_key;
+
+/**
+ * @brief Definition for the Tizen buffer surface.
+ */
+typedef struct _hal_tbm_surface *hal_tbm_surface_h;
+/**
+ * @brief Definition for the Tizen buffer surface format.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef uint32_t hal_tbm_format;
+
+#define __hal_tbm_fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
+ ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
+
+/* color index */
+/**
+ * @brief Definition for the TBM surface format C8 ([7:0] C).
+ */
+#define HAL_TBM_FORMAT_C8 __hal_tbm_fourcc_code('C', '8', ' ', ' ')
+
+/* 8 bpp RGB */
+/**
+ * @brief Definition for the TBM surface format RGB322 ([7:0] R:G:B 3:3:2).
+ */
+#define HAL_TBM_FORMAT_RGB332 __hal_tbm_fourcc_code('R', 'G', 'B', '8')
+/**
+ * @brief Definition for the TBM surface format RGB233 ([7:0] B:G:R 2:3:3).
+ */
+#define HAL_TBM_FORMAT_BGR233 __hal_tbm_fourcc_code('B', 'G', 'R', '8')
+
+/* 16 bpp RGB */
+/**
+ * @brief Definition for the TBM surface format XRGB4444 ([15:0] x:R:G:B 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_XRGB4444 __hal_tbm_fourcc_code('X', 'R', '1', '2')
+/**
+ * @brief Definition for the TBM surface format XBRG4444 ([15:0] x:B:G:R 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_XBGR4444 __hal_tbm_fourcc_code('X', 'B', '1', '2')
+/**
+ * @brief Definition for the TBM surface format RGBX4444 ([15:0] R:G:B:x 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBX4444 __hal_tbm_fourcc_code('R', 'X', '1', '2')
+/**
+ * @brief Definition for the TBM surface format BGRX4444 ([15:0] B:G:R:x 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRX4444 __hal_tbm_fourcc_code('B', 'X', '1', '2')
+
+/**
+ * @brief Definition for the TBM surface format ARGB4444 ([15:0] A:R:G:B 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_ARGB4444 __hal_tbm_fourcc_code('A', 'R', '1', '2')
+/**
+ * @brief Definition for the TBM surface format ABGR4444 ([15:0] A:B:G:R 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_ABGR4444 __hal_tbm_fourcc_code('A', 'B', '1', '2')
+/**
+ * @brief Definition for the TBM surface format RGBA4444 ([15:0] R:G:B:A 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBA4444 __hal_tbm_fourcc_code('R', 'A', '1', '2')
+/**
+ * @brief Definition for the TBM surface format BGRA4444 ([15:0] B:G:R:A 4:4:4:4 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRA4444 __hal_tbm_fourcc_code('B', 'A', '1', '2')
+
+/**
+ * @brief Definition for the TBM surface format XRGB1555 ([15:0] x:R:G:B 1:5:5:5 little endian).
+ */
+#define HAL_TBM_FORMAT_XRGB1555 __hal_tbm_fourcc_code('X', 'R', '1', '5')
+/**
+ * @brief Definition for the TBM surface format XBGR1555 ([15:0] x:B:G:R 1:5:5:5 little endian).
+ */
+#define HAL_TBM_FORMAT_XBGR1555 __hal_tbm_fourcc_code('X', 'B', '1', '5')
+/**
+ * @brief Definition for the TBM surface format RGBX5551 ([15:0] R:G:B:x 5:5:5:1 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBX5551 __hal_tbm_fourcc_code('R', 'X', '1', '5')
+/**
+ * @brief Definition for the TBM surface format BGRX5551 ([15:0] B:G:R:x 5:5:5:1 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRX5551 __hal_tbm_fourcc_code('B', 'X', '1', '5')
+
+/**
+ * @brief Definition for the TBM surface format ARGB1555 ([15:0] A:R:G:B 1:5:5:5 little endian).
+ */
+#define HAL_TBM_FORMAT_ARGB1555 __hal_tbm_fourcc_code('A', 'R', '1', '5')
+/**
+ * @brief Definition for the TBM surface format ABGR1555 ([15:0] A:B:G:R 1:5:5:5 little endian).
+ */
+#define HAL_TBM_FORMAT_ABGR1555 __hal_tbm_fourcc_code('A', 'B', '1', '5')
+/**
+ * @brief Definition for the TBM surface format RGBA5551 ([15:0] R:G:B:A 5:5:5:1 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBA5551 __hal_tbm_fourcc_code('R', 'A', '1', '5')
+/**
+ * @brief Definition for the TBM surface format BGRA5551 ([15:0] B:G:R:A 5:5:5:1 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRA5551 __hal_tbm_fourcc_code('B', 'A', '1', '5')
+
+/**
+ * @brief Definition for the TBM surface format RGB565 ([15:0] R:G:B 5:6:5 little endian).
+ */
+#define HAL_TBM_FORMAT_RGB565 __hal_tbm_fourcc_code('R', 'G', '1', '6')
+/**
+ * @brief Definition for the TBM surface format BGR565 ([15:0] B:G:R 5:6:5 little endian).
+ */
+#define HAL_TBM_FORMAT_BGR565 __hal_tbm_fourcc_code('B', 'G', '1', '6')
+
+/* 24 bpp RGB */
+/**
+ * @brief Definition for the TBM surface format RGB888 ([23:0] R:G:B little endian).
+ */
+#define HAL_TBM_FORMAT_RGB888 __hal_tbm_fourcc_code('R', 'G', '2', '4')
+/**
+ * @brief Definition for the TBM surface format BGR888 ([23:0] B:G:R little endian).
+ */
+#define HAL_TBM_FORMAT_BGR888 __hal_tbm_fourcc_code('B', 'G', '2', '4')
+
+/* 32 bpp RGB */
+/**
+ * @brief Definition for the TBM surface format XRGB8888 ([31:0] x:R:G:B 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_XRGB8888 __hal_tbm_fourcc_code('X', 'R', '2', '4')
+/**
+ * @brief Definition for the TBM surface format XBGR8888 ([31:0] x:B:G:R 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_XBGR8888 __hal_tbm_fourcc_code('X', 'B', '2', '4')
+/**
+ * @brief Definition for the TBM surface format RGBX8888 ([31:0] R:G:B:x 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBX8888 __hal_tbm_fourcc_code('R', 'X', '2', '4')
+/**
+ * @brief Definition for the TBM surface format BGRX8888 ([31:0] B:G:R:x 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRX8888 __hal_tbm_fourcc_code('B', 'X', '2', '4')
+
+/**
+ * @brief Definition for the TBM surface format ARGB8888 ([31:0] A:R:G:B 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_ARGB8888 __hal_tbm_fourcc_code('A', 'R', '2', '4')
+/**
+ * @brief Definition for the TBM surface format ABGR8888 ([31:0] [31:0] A:B:G:R 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_ABGR8888 __hal_tbm_fourcc_code('A', 'B', '2', '4')
+/**
+ * @brief Definition for the TBM surface format RGBA8888 ([31:0] R:G:B:A 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBA8888 __hal_tbm_fourcc_code('R', 'A', '2', '4')
+/**
+ * @brief Definition for the TBM surface format BGRA8888 ([31:0] B:G:R:A 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRA8888 __hal_tbm_fourcc_code('B', 'A', '2', '4')
+
+/**
+ * @brief Definition for the TBM surface format XRGB2101010 ([31:0] x:R:G:B 2:10:10:10 little endian).
+ */
+#define HAL_TBM_FORMAT_XRGB2101010 __hal_tbm_fourcc_code('X', 'R', '3', '0')
+/**
+ * @brief Definition for the TBM surface format XBGR2101010 ([31:0] x:B:G:R 2:10:10:10 little endian).
+ */
+#define HAL_TBM_FORMAT_XBGR2101010 __hal_tbm_fourcc_code('X', 'B', '3', '0')
+/**
+ * @brief Definition for the TBM surface format RGBX1010102 ([31:0] R:G:B:x 10:10:10:2 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBX1010102 __hal_tbm_fourcc_code('R', 'X', '3', '0')
+/**
+ * @brief Definition for the TBM surface format BGRX1010102 ([31:0] B:G:R:x 10:10:10:2 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRX1010102 __hal_tbm_fourcc_code('B', 'X', '3', '0')
+
+/**
+ * @brief Definition for the TBM surface format ARGB2101010 ([31:0] A:R:G:B 2:10:10:10 little endian).
+ */
+#define HAL_TBM_FORMAT_ARGB2101010 __hal_tbm_fourcc_code('A', 'R', '3', '0')
+/**
+ * @brief Definition for the TBM surface format ABGR2101010 ([31:0] A:B:G:R 2:10:10:10 little endian).
+ */
+#define HAL_TBM_FORMAT_ABGR2101010 __hal_tbm_fourcc_code('A', 'B', '3', '0')
+/**
+ * @brief Definition for the TBM surface format RGBA1010102 ([31:0] R:G:B:A 10:10:10:2 little endian).
+ */
+#define HAL_TBM_FORMAT_RGBA1010102 __hal_tbm_fourcc_code('R', 'A', '3', '0')
+/**
+ * @brief Definition for the TBM surface format BGRA1010102 ([31:0] B:G:R:A 10:10:10:2 little endian).
+ */
+#define HAL_TBM_FORMAT_BGRA1010102 __hal_tbm_fourcc_code('B', 'A', '3', '0')
+
+/* packed YCbCr */
+/**
+ * @brief Definition for the TBM surface format YUYV ([31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_YUYV __hal_tbm_fourcc_code('Y', 'U', 'Y', 'V')
+/**
+ * @brief Definition for the TBM surface format YVYU ([31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_YVYU __hal_tbm_fourcc_code('Y', 'V', 'Y', 'U')
+/**
+ * @brief Definition for the TBM surface format UYVY ([31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_UYVY __hal_tbm_fourcc_code('U', 'Y', 'V', 'Y')
+/**
+ * @brief Definition for the TBM surface format VYUY ([31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_VYUY __hal_tbm_fourcc_code('V', 'Y', 'U', 'Y')
+
+/**
+ * @brief Definition for the TBM surface format AYUV ([31:0] A:Y:Cb:Cr 8:8:8:8 little endian).
+ */
+#define HAL_TBM_FORMAT_AYUV __hal_tbm_fourcc_code('A', 'Y', 'U', 'V')
+
+/*
+ * 2 plane YCbCr
+ * index 0 = Y plane, [7:0] Y
+ * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
+ * or
+ * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
+ */
+/**
+ * @brief Definition for the TBM surface format NV12 (2x2 subsampled Cr:Cb plane).
+ */
+#define HAL_TBM_FORMAT_NV12 __hal_tbm_fourcc_code('N', 'V', '1', '2')
+/**
+ * @brief Definition for the TBM surface format NV21 (2x2 subsampled Cb:Cr plane).
+ */
+#define HAL_TBM_FORMAT_NV21 __hal_tbm_fourcc_code('N', 'V', '2', '1')
+/**
+ * @brief Definition for the TBM surface format NV16 (2x1 subsampled Cr:Cb plane).
+ */
+#define HAL_TBM_FORMAT_NV16 __hal_tbm_fourcc_code('N', 'V', '1', '6')
+/**
+ * @brief Definition for the TBM surface format NV61 (2x1 subsampled Cb:Cr plane).
+ */
+#define HAL_TBM_FORMAT_NV61 __hal_tbm_fourcc_code('N', 'V', '6', '1')
+
+/*
+ * 3 plane YCbCr
+ * index 0: Y plane, [7:0] Y
+ * index 1: Cb plane, [7:0] Cb
+ * index 2: Cr plane, [7:0] Cr
+ * or
+ * index 1: Cr plane, [7:0] Cr
+ * index 2: Cb plane, [7:0] Cb
+ */
+/**
+ * @brief Definition for the TBM surface format YUV410 (4x4 subsampled Cb (1) and Cr (2) planes).
+ */
+#define HAL_TBM_FORMAT_YUV410 __hal_tbm_fourcc_code('Y', 'U', 'V', '9')
+/**
+ * @brief Definition for the TBM surface format YVU410 (4x4 subsampled Cr (1) and Cb (2) planes).
+ */
+#define HAL_TBM_FORMAT_YVU410 __hal_tbm_fourcc_code('Y', 'V', 'U', '9')
+/**
+ * @brief Definition for the TBM surface format YUV411 (4x1 subsampled Cb (1) and Cr (2) planes).
+ */
+#define HAL_TBM_FORMAT_YUV411 __hal_tbm_fourcc_code('Y', 'U', '1', '1')
+/**
+ * @brief Definition for the TBM surface format YVU411 (4x1 subsampled Cr (1) and Cb (2) planes).
+ */
+#define HAL_TBM_FORMAT_YVU411 __hal_tbm_fourcc_code('Y', 'V', '1', '1')
+/**
+ * @brief Definition for the TBM surface format YUV420 (2x2 subsampled Cb (1) and Cr (2) planes).
+ */
+#define HAL_TBM_FORMAT_YUV420 __hal_tbm_fourcc_code('Y', 'U', '1', '2')
+/**
+ * @brief Definition for the TBM surface format YVU420 (2x2 subsampled Cr (1) and Cb (2) planes).
+ */
+#define HAL_TBM_FORMAT_YVU420 __hal_tbm_fourcc_code('Y', 'V', '1', '2')
+/**
+ * @brief Definition for the TBM surface format YUV422 (2x1 subsampled Cb (1) and Cr (2) planes).
+ */
+#define HAL_TBM_FORMAT_YUV422 __hal_tbm_fourcc_code('Y', 'U', '1', '6')
+/**
+ * @brief Definition for the TBM surface format YVU422 (2x1 subsampled Cr (1) and Cb (2) planes).
+ */
+#define HAL_TBM_FORMAT_YVU422 __hal_tbm_fourcc_code('Y', 'V', '1', '6')
+/**
+ * @brief Definition for the TBM surface format YUV444 (non-subsampled Cb (1) and Cr (2) planes).
+ */
+#define HAL_TBM_FORMAT_YUV444 __hal_tbm_fourcc_code('Y', 'U', '2', '4')
+/**
+ * @brief Definition for the TBM surface format YVU444 (non-subsampled Cr (1) and Cb (2) planes).
+ */
+#define HAL_TBM_FORMAT_YVU444 __hal_tbm_fourcc_code('Y', 'V', '2', '4')
+
+/* 2 plane YCbCr */
+/**
+ * @brief Definition for the TBM surface format NV12MT (tiled '64x32' & multi-plane version of NV12).
+ */
+#define HAL_TBM_FORMAT_NV12MT __hal_tbm_fourcc_code('T', 'M', '1', '2')
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _HAL_TBM_TYPES_H_ */
--- /dev/null
+/**************************************************************************
+ *
+ * hal-api-tbm
+ *
+ * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: SooChan Lim <sc1.lim@samsung.com>,
+ * Junkyeong Kim <jk0430.kim@samsung.com>,
+ * Changyeon Lee <cyeon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#ifndef __HAL_TBM__
+#define __HAL_TBM__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <hal-tbm-types.h>
+
+hal_tbm_error hal_tbm_get_backend(hal_tbm_bufmgr_data *bufmgr_data);
+void hal_tbm_put_backend(void);
+
+/* hal_tbm_bufmgr_func */
+hal_tbm_bufmgr_capability hal_tbm_bufmgr_get_capabilities(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_error *error);
+hal_tbm_error hal_tbm_bufmgr_bind_native_display(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_native_display *native_display);
+hal_tbm_error hal_tbm_bufmgr_get_supported_formats(hal_tbm_bufmgr_data *bufmgr_data, uint32_t **formats, uint32_t *num);
+hal_tbm_error hal_tbm_bufmgr_get_plane_data(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_format format, int plane_idx, int width, int height,
+ uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx);
+hal_tbm_bo_data *hal_tbm_bufmgr_alloc_bo(hal_tbm_bufmgr_data *bufmgr_data, unsigned int size, hal_tbm_bo_memory_type mem_types, hal_tbm_error *error);
+hal_tbm_bo_data *hal_tbm_bufmgr_alloc_bo_with_format(hal_tbm_bufmgr_data *bufmgr_data, int format, int bo_idx, int width, int height,
+ hal_tbm_bo_memory_type mem_types, hal_tbm_error *error);
+hal_tbm_bo_data *hal_tbm_bufmgr_alloc_bo_with_tiled_format(hal_tbm_bufmgr_data *bufmgr_data, int width, int height, int bpp, int format,
+ hal_tbm_bo_memory_type flags, int bo_idx, hal_tbm_error *error);
+hal_tbm_bo_data *hal_tbm_bufmgr_import_fd(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_fd fd, hal_tbm_error *error);
+hal_tbm_bo_data *hal_tbm_bufmgr_import_key(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_key key, hal_tbm_error *error);
+
+/* hal_tbm_bo_func*/
+void hal_tbm_bo_free(hal_tbm_bo_data *bo_data);
+int hal_tbm_bo_get_size(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+hal_tbm_bo_memory_type hal_tbm_bo_get_memory_types(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+hal_tbm_bo_handle hal_tbm_bo_get_handle(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, hal_tbm_error *error);
+hal_tbm_bo_handle hal_tbm_bo_map(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt, hal_tbm_error *error);
+hal_tbm_error hal_tbm_bo_unmap(hal_tbm_bo_data *bo_data);
+hal_tbm_error hal_tbm_bo_lock(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt);
+hal_tbm_error hal_tbm_bo_unlock(hal_tbm_bo_data *bo_data);
+hal_tbm_fd hal_tbm_bo_export_fd(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+hal_tbm_key hal_tbm_bo_export_key(hal_tbm_bo_data *bo_data, hal_tbm_error *error);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_TBM__ */
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
+
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
+
--- /dev/null
+%define module_name tbm
+%define name hal-api-tbm
+%define devel_name hal-api-tbm-devel
+
+### main package #########
+Name: %{name}
+Summary: %{name} interface
+Version: 0.0.1
+Release: 1
+Group: Development/Libraries
+License: MIT
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
+Source2: %{devel_name}.manifest
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(hal-api-common)
+
+%description
+%{name} interface
+
+### devel package #########
+%package -n %{devel_name}
+Summary: %{name} interface
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description -n %{devel_name}
+%{name} Interface for product vendor developer
+
+### build and install #########
+%prep
+%setup -q
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir}/
+
+%build
+cp %{SOURCE1} .
+cp %{SOURCE2} .
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%clean
+rm -rf %{buildroot}
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+### contain files to package #########
+%files -n %{name}
+%manifest %{name}.manifest
+%license COPYING
+%defattr(-,root,root,-)
+%{_libdir}/hal/*.so*
+
+%files -n %{devel_name}
+%defattr(-,root,root,-)
+%manifest %{devel_name}.manifest
+%{_includedir}/hal/*.h
+%{_libdir}/pkgconfig/%{name}.pc
--- /dev/null
+/**************************************************************************
+ *
+ * hal-api-tbm
+ *
+ * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: SooChan Lim <sc1.lim@samsung.com>,
+ * Junkyeong Kim <jk0430.kim@samsung.com>,
+ * Changyeon Lee <cyeon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#ifndef __COMMON_H__
+#define __COMMON_H__
+
+#include <dlog.h>
+#define _D(fmt, args...) SLOGD(fmt, ##args)
+#define _I(fmt, args...) SLOGI(fmt, ##args)
+#define _W(fmt, args...) SLOGW(fmt, ##args)
+#define _E(fmt, args...) SLOGE(fmt, ##args)
+
+#endif /* __COMMON_H__ */
--- /dev/null
+/**************************************************************************
+ *
+ * hal-api-tbm
+ *
+ * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: SooChan Lim <sc1.lim@samsung.com>,
+ * Junkyeong Kim <jk0430.kim@samsung.com>,
+ * Changyeon Lee <cyeon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <hal/hal-common.h>
+#include "common.h"
+#include "hal-tbm-types.h"
+#include "hal-tbm.h"
+#include "hal-tbm-interface.h"
+
+#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_ENTRY() \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr) return HAL_TBM_ERROR_NOT_SUPPORTED;
+
+#define BUFMGR_ENTRY_NULL() \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr) { if (error) *error = HAL_TBM_ERROR_NOT_SUPPORTED; return NULL; }
+
+#define BUFMGR_ENTRY_VOID() \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr) return;
+
+#define BUFMGR_ENTRY_GOTO(__goto__) \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr) goto __goto__;
+
+#define BUFMGR_FUNC_ENTRY(__func__) \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr || !g_hal_tbm_bufmgr->bufmgr_func) return HAL_TBM_ERROR_NOT_SUPPORTED; \
+ bufmgr_func = g_hal_tbm_bufmgr->bufmgr_func; \
+ if (!bufmgr_func->__func__) return HAL_TBM_ERROR_NOT_SUPPORTED;
+
+#define BUFMGR_FUNC_ENTRY_NULL(__func__) \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr || !g_hal_tbm_bufmgr->bufmgr_func) { if (error) *error = HAL_TBM_ERROR_NOT_SUPPORTED; return NULL; } \
+ bufmgr_func = g_hal_tbm_bufmgr->bufmgr_func; \
+ if (!bufmgr_func->__func__) { if (error) *error = HAL_TBM_ERROR_NOT_SUPPORTED; return NULL; };
+
+#define BUFMGR_FUNC_ENTRY_GOTO(__func__, __goto__) \
+ hal_tbm_bufmgr_func *bufmgr_func; \
+ if (!g_hal_tbm_bufmgr || !g_hal_tbm_bufmgr->bufmgr_func) goto __goto__; \
+ bufmgr_func = g_hal_tbm_bufmgr->bufmgr_func; \
+ if (!bufmgr_func->__func__) goto __goto__;
+
+#define BO_FUNC_ENTRY(__func__) \
+ hal_tbm_bo_func *bo_func; \
+ if (!g_hal_tbm_bufmgr || !g_hal_tbm_bufmgr->bo_func) return HAL_TBM_ERROR_NOT_SUPPORTED; \
+ bo_func = g_hal_tbm_bufmgr->bo_func; \
+ if (!bo_func->__func__) return HAL_TBM_ERROR_NOT_SUPPORTED;
+
+#define BO_FUNC_ENTRY_VOID(__func__) \
+ hal_tbm_bo_func *bo_func; \
+ if (!g_hal_tbm_bufmgr || !g_hal_tbm_bufmgr->bo_func) return; \
+ bo_func = g_hal_tbm_bufmgr->bo_func; \
+ if (!bo_func->__func__) return;
+
+#define BO_FUNC_ENTRY_GOTO(__func__, __goto__) \
+ hal_tbm_bo_func *bo_func; \
+ if (!g_hal_tbm_bufmgr || !g_hal_tbm_bufmgr->bo_func) goto __goto__; \
+ bo_func = g_hal_tbm_bufmgr->bo_func; \
+ if (!bo_func->__func__) goto __goto__;
+
+typedef struct _hal_tbm_bufmgr
+{
+ hal_tbm_bufmgr_func *bufmgr_func;
+ hal_tbm_bo_func *bo_func;
+} hal_tbm_bufmgr;
+
+static hal_tbm_bufmgr *g_hal_tbm_bufmgr = NULL;
+
+EXTERN hal_tbm_error
+hal_tbm_get_backend(hal_tbm_bufmgr_data *bufmgr_data)
+{
+ int ret;
+
+ if (g_hal_tbm_bufmgr)
+ return HAL_TBM_ERROR_INVALID_OPERATION;
+
+ g_hal_tbm_bufmgr = calloc(1, sizeof(hal_tbm_bufmgr));
+ if (!g_hal_tbm_bufmgr)
+ return HAL_TBM_ERROR_OUT_OF_MEMORY;
+
+ ret = hal_common_get_backend(HAL_MODULE_TBM, (void **)&bufmgr_data);
+ if (ret < 0) {
+ _E("Failed to get backend\n");
+ free(g_hal_tbm_bufmgr);
+ g_hal_tbm_bufmgr = NULL;
+ return HAL_TBM_ERROR_NOT_SUPPORTED;
+ }
+
+ _I("hal_tbm_get_backend");
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+EXTERN void
+hal_tbm_put_backend(void)
+{
+ if (!g_hal_tbm_bufmgr)
+ return;
+
+ hal_common_put_backend(HAL_MODULE_TBM, NULL);
+ free(g_hal_tbm_bufmgr);
+ g_hal_tbm_bufmgr = NULL;
+
+ _I("hal_tbm_put_backend");
+}
+
+
+/* tbm_bufmgr_func */
+EXTERN hal_tbm_bufmgr_capability
+hal_tbm_bufmgr_get_capabilities(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_error *error)
+{
+ BUFMGR_FUNC_ENTRY_GOTO(bufmgr_get_capabilities, fail);
+
+ return bufmgr_func->bufmgr_get_capabilities((hal_tbm_bufmgr_data *)bufmgr_data, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return HAL_TBM_BUFMGR_CAPABILITY_NONE;
+}
+
+EXTERN hal_tbm_error
+hal_tbm_bufmgr_bind_native_display(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_native_display *native_display)
+{
+ BUFMGR_FUNC_ENTRY(bufmgr_bind_native_display);
+
+ return bufmgr_func->bufmgr_bind_native_display((hal_tbm_bufmgr_data *)bufmgr_data, native_display);
+}
+
+EXTERN hal_tbm_error
+hal_tbm_bufmgr_get_supported_formats(hal_tbm_bufmgr_data *bufmgr_data, uint32_t **formats, uint32_t *num)
+{
+ BUFMGR_FUNC_ENTRY(bufmgr_get_supported_formats);
+
+ return bufmgr_func->bufmgr_get_supported_formats((hal_tbm_bufmgr_data *)bufmgr_data, formats, num);
+}
+
+EXTERN hal_tbm_error
+hal_tbm_bufmgr_get_plane_data(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_format format, int plane_idx, int width, int height,
+ uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx)
+{
+ BUFMGR_FUNC_ENTRY(bufmgr_get_plane_data);
+
+ return bufmgr_func->bufmgr_get_plane_data((hal_tbm_bufmgr_data *)bufmgr_data, format, plane_idx, width, height, size, offset, pitch, bo_idx);
+}
+
+EXTERN hal_tbm_bo_data *
+hal_tbm_bufmgr_alloc_bo(hal_tbm_bufmgr_data *bufmgr_data, unsigned int size, hal_tbm_bo_memory_type mem_types, hal_tbm_error *error)
+{
+ BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo);
+
+ return bufmgr_func->bufmgr_alloc_bo((hal_tbm_bufmgr_data *)bufmgr_data, size, mem_types, error);
+}
+
+EXTERN hal_tbm_bo_data *
+hal_tbm_bufmgr_alloc_bo_with_format(hal_tbm_bufmgr_data *bufmgr_data, int format, int bo_idx, int width, int height,
+ hal_tbm_bo_memory_type mem_types, hal_tbm_error *error)
+{
+ BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo_with_format);
+
+ return bufmgr_func->bufmgr_alloc_bo_with_format((hal_tbm_bufmgr_data *)bufmgr_data, format, bo_idx, width, height, mem_types, error);
+}
+
+EXTERN hal_tbm_bo_data *
+hal_tbm_bufmgr_alloc_bo_with_tiled_format(hal_tbm_bufmgr_data *bufmgr_data, int width, int height, int bpp, int format,
+ hal_tbm_bo_memory_type flags, int bo_idx, hal_tbm_error *error)
+{
+ BUFMGR_FUNC_ENTRY_NULL(bufmgr_alloc_bo_with_tiled_format);
+
+ return bufmgr_func->bufmgr_alloc_bo_with_tiled_format((hal_tbm_bufmgr_data *)bufmgr_data, width, height, bpp, format, flags, bo_idx, error);
+}
+
+EXTERN hal_tbm_bo_data *
+hal_tbm_bufmgr_import_fd(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_fd fd, hal_tbm_error *error)
+{
+ BUFMGR_FUNC_ENTRY_NULL(bufmgr_import_fd);
+
+ return bufmgr_func->bufmgr_import_fd((hal_tbm_bufmgr_data *)bufmgr_data, fd, error);
+}
+
+EXTERN hal_tbm_bo_data *
+hal_tbm_bufmgr_import_key(hal_tbm_bufmgr_data *bufmgr_data, hal_tbm_key key, hal_tbm_error *error)
+{
+ BUFMGR_FUNC_ENTRY_NULL(bufmgr_import_key);
+
+ return bufmgr_func->bufmgr_import_key((hal_tbm_bufmgr_data *)bufmgr_data, key, error);
+}
+
+
+/* tbm_bo_func*/
+EXTERN void
+hal_tbm_bo_free(hal_tbm_bo_data *bo_data)
+{
+ BO_FUNC_ENTRY_VOID(bo_free);
+ bo_func->bo_free((hal_tbm_bo_data *)bo_data);
+}
+
+EXTERN int
+hal_tbm_bo_get_size(hal_tbm_bo_data *bo_data, hal_tbm_error *error)
+{
+ BO_FUNC_ENTRY_GOTO(bo_get_size, fail);
+
+ return bo_func->bo_get_size((hal_tbm_bo_data *)bo_data, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return 0;
+}
+
+EXTERN hal_tbm_bo_memory_type
+hal_tbm_bo_get_memory_types(hal_tbm_bo_data *bo_data, hal_tbm_error *error)
+{
+ BO_FUNC_ENTRY_GOTO(bo_get_memory_types, fail);
+
+ return bo_func->bo_get_memory_types((hal_tbm_bo_data *)bo_data, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return HAL_TBM_BO_DEFAULT;
+}
+
+EXTERN hal_tbm_bo_handle
+hal_tbm_bo_get_handle(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, hal_tbm_error *error)
+{
+ BO_FUNC_ENTRY_GOTO(bo_get_handle, fail);
+
+ return bo_func->bo_get_handle((hal_tbm_bo_data *)bo_data, device, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return (hal_tbm_bo_handle)NULL;
+}
+
+EXTERN hal_tbm_bo_handle
+hal_tbm_bo_map(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt, hal_tbm_error *error)
+{
+ BO_FUNC_ENTRY_GOTO(bo_map, fail);
+
+ return bo_func->bo_map((hal_tbm_bo_data *)bo_data, device, opt, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return (hal_tbm_bo_handle)NULL;
+}
+
+EXTERN hal_tbm_error
+hal_tbm_bo_unmap(hal_tbm_bo_data *bo_data)
+{
+ BO_FUNC_ENTRY(bo_unmap);
+
+ return bo_func->bo_unmap((hal_tbm_bo_data *)bo_data);
+}
+
+EXTERN hal_tbm_error
+hal_tbm_bo_lock(hal_tbm_bo_data *bo_data, tbm_bo_device_type device, tbm_bo_access_option opt)
+{
+ BO_FUNC_ENTRY(bo_unmap);
+
+ return bo_func->bo_lock((hal_tbm_bo_data *)bo_data, device, opt);
+}
+
+EXTERN hal_tbm_error
+hal_tbm_bo_unlock(hal_tbm_bo_data *bo_data)
+{
+ BO_FUNC_ENTRY(bo_unmap);
+
+ return bo_func->bo_unlock((hal_tbm_bo_data *)bo_data);
+}
+
+EXTERN hal_tbm_fd
+hal_tbm_bo_export_fd(hal_tbm_bo_data *bo_data, hal_tbm_error *error)
+{
+ BO_FUNC_ENTRY_GOTO(bo_export_fd, fail);
+
+ return bo_func->bo_export_fd((hal_tbm_bo_data *)bo_data, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return -1;
+}
+
+EXTERN hal_tbm_key
+hal_tbm_bo_export_key(hal_tbm_bo_data *bo_data, hal_tbm_error *error)
+{
+ BO_FUNC_ENTRY_GOTO(bo_export_key, fail);
+
+ return bo_func->bo_export_key((hal_tbm_bo_data *)bo_data, error);
+
+fail:
+ if (error)
+ *error = HAL_TBM_ERROR_NOT_SUPPORTED;
+
+ return 0;
+}
+
+
+/* tbm_func*/
+EXTERN int
+hal_tbm_query_display_server(hal_tbm_error *error)
+{
+// BUFMGR_ENTRY_NULL();
+
+ //TODO:
+ return 0;
+}
+
+EXTERN hal_tbm_bufmgr_func *
+hal_tbm_alloc_bufmgr_func(hal_tbm_error *error)
+{
+ BUFMGR_ENTRY_NULL();
+
+ bufmgr_func = calloc(1, sizeof(hal_tbm_bufmgr_func));
+ if (!bufmgr_func) {
+ _E("error: fail to allocate the tbm_bufmgr_func\n");
+ if (error)
+ *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
+
+ return NULL;
+ }
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return bufmgr_func;
+}
+
+EXTERN void
+hal_tbm_free_bufmgr_func(hal_tbm_bufmgr_func *func)
+{
+ BUFMGR_ENTRY_VOID();
+
+ if (func)
+ free(func);
+
+ g_hal_tbm_bufmgr->bufmgr_func = NULL;
+}
+
+EXTERN hal_tbm_error
+hal_tbm_register_bufmgr_func(hal_tbm_bufmgr_func *func)
+{
+ if (!g_hal_tbm_bufmgr) return HAL_TBM_ERROR_INVALID_OPERATION;
+ if (g_hal_tbm_bufmgr->bufmgr_func) return HAL_TBM_ERROR_INVALID_OPERATION;
+ if (!func) return HAL_TBM_ERROR_INVALID_PARAMETER;
+ g_hal_tbm_bufmgr->bufmgr_func = func;
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+EXTERN hal_tbm_bo_func *
+hal_tbm_alloc_bo_func(hal_tbm_error *error)
+{
+ BUFMGR_ENTRY_NULL();
+
+ hal_tbm_bo_func *bo_func;
+
+ bo_func = calloc(1, sizeof(hal_tbm_bo_func));
+ if (!bo_func) {
+ _E("error: fail to allocate the tbm_bufmgr_func\n");
+ if (error)
+ *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
+
+ return NULL;
+ }
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return bo_func;
+}
+
+EXTERN void
+hal_tbm_free_bo_func(hal_tbm_bo_func *func)
+{
+ BUFMGR_ENTRY_VOID();
+
+ if (func)
+ free(func);
+
+ g_hal_tbm_bufmgr->bo_func = NULL;
+}
+
+EXTERN hal_tbm_error
+hal_tbm_register_bo_func(hal_tbm_bo_func *func)
+{
+ if (!g_hal_tbm_bufmgr) return HAL_TBM_ERROR_INVALID_OPERATION;
+ if (g_hal_tbm_bufmgr->bo_func) return HAL_TBM_ERROR_INVALID_OPERATION;
+ if (!func) return HAL_TBM_ERROR_INVALID_PARAMETER;
+ g_hal_tbm_bufmgr->bo_func = func;
+
+ return HAL_TBM_ERROR_NONE;
+}
\ No newline at end of file