--- /dev/null
+/**************************************************************************
+
+libtbm
+
+Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>,
+ Sangjin Lee <lsj119@samsung.com>,
+ Boram Park <boram1288.park@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 "config.h"
+#include "tbm_bufmgr_int.h"
+
+/* LCOV_EXCL_START */
+int
+tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error)
+{
+ const char *value;
+
+ if (!bufmgr) {
+ if (error)
+ *error = TBM_ERROR_INVALID_PARAMETER;
+ return 0;
+ }
+
+ /* TODO: TBM_DISPLAY_SERVER will be removed */
+ value = (const char*)getenv("TBM_DISPLAY_SERVER");
+
+ if (value || gBufMgr->display_server) {
+ if (error)
+ *error = TBM_ERROR_NONE;
+ return 1;
+ }
+
+ if (error)
+ *error = TBM_ERROR_NONE;
+
+ return 0;
+}
+
+tbm_backend_bufmgr_func *
+tbm_backend_bufmgr_alloc_bufmgr_func(tbm_bufmgr bufmgr, tbm_error_e *error)
+{
+ tbm_backend_bufmgr_func *bufmgr_func;
+
+ bufmgr_func = calloc(1, sizeof(struct _tbm_backend_bufmgr_func));
+ if (!bufmgr_func) {
+ TBM_ERR("error: fail to allocate the tbm_backend_bufmgr_func\n");
+ if (error)
+ *error = TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ if (error)
+ *error = TBM_ERROR_NONE;
+
+ return bufmgr_func;
+}
+
+void
+tbm_backend_bufmgr_free_bufmgr_func(tbm_bufmgr bufmgr, tbm_backend_bufmgr_func *func)
+{
+ TBM_RETURN_IF_FAIL(bufmgr);
+
+ if (!func)
+ free(func);
+}
+
+tbm_error_e
+tbm_backend_bufmgr_register_bufmgr_func(tbm_bufmgr bufmgr, tbm_backend_bufmgr_func *func)
+{
+ TBM_RETURN_VAL_IF_FAIL(bufmgr, TBM_ERROR_INVALID_PARAMETER);
+ TBM_RETURN_VAL_IF_FAIL(func, TBM_ERROR_INVALID_PARAMETER);
+
+ bufmgr->bufmgr_func = func;
+
+ return TBM_ERROR_NONE;
+}
+
+tbm_backend_bo_func *
+tbm_backend_bufmgr_alloc_bo_func(tbm_bufmgr bufmgr, tbm_error_e *error)
+{
+ tbm_backend_bo_func *bufmgr_bo;
+
+ bufmgr_bo = calloc(1, sizeof(struct _tbm_backend_bo_func));
+ if (!bufmgr_bo) {
+ TBM_ERR("error: fail to allocate the tbm_backend_bo_func\n");
+ if (error)
+ *error = TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ if (error)
+ *error = TBM_ERROR_NONE;
+
+ return bufmgr_bo;
+}
+
+void
+tbm_backend_bufmgr_free_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func)
+{
+ TBM_RETURN_IF_FAIL(bufmgr);
+
+ if (!func)
+ free(func);
+}
+
+tbm_error_e
+tbm_backend_bufmgr_register_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func)
+{
+ TBM_RETURN_VAL_IF_FAIL(bufmgr, TBM_ERROR_INVALID_PARAMETER);
+ TBM_RETURN_VAL_IF_FAIL(func, TBM_ERROR_INVALID_PARAMETER);
+
+ bufmgr->bo_func = func;
+
+ return TBM_ERROR_NONE;
+}
+
+/* LCOV_EXCL_STOP */
--- /dev/null
+/**************************************************************************
+
+libtbm
+
+Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>,
+ Sangjin Lee <lsj119@samsung.com>,
+ Boram Park <boram1288.park@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 _TBM_BACKEND_H_
+#define _TBM_BACKEND_H_
+
+#include <tbm_bufmgr.h>
+
+/**
+ * \file tbm_backend.h
+ * \brief The backend header file for Tizen Buffer Manager
+ * This header is for the implementation of the TBM backend module.
+ * This backend header is used from the 3.0 version of libtbm and from
+ * the 5.0 version of the tizen.
+ * @code
+ * #include <tbm_backend.h>
+ * @endcode
+ */
+
+#define TBM_BACKEND_ABI_MINOR_MASK 0x0000FFFF
+#define TBM_BACKEND_ABI_MAJOR_MASK 0xFFFF0000
+#define TBM_BACKEND_GET_ABI_MINOR(v) ((v) & TBM_BACKEND_ABI_MINOR_MASK)
+#define TBM_BACKEND_GET_ABI_MAJOR(v) (((v) & TBM_BACKEND_ABI_MAJOR_MASK) >> 16)
+/*
+ * ABI versions. Each version has a major and minor revision. Modules
+ * using lower minor revisions must work with servers of a higher minor
+ * revision. There is no compatibility between different major revisions.
+ * Whenever the ABI_ANSIC_VERSION is changed, the others must also be
+ * changed. The minor revision mask is 0x0000FFFF and the major revision
+ * mask is 0xFFFF0000.
+ */
+#define TBM_BACKEND_SET_ABI_VERSION(maj, min) \
+ ((((maj) << 16) & TBM_BACKEND_ABI_MAJOR_MASK) | ((min) & TBM_BACKEND_ABI_MINOR_MASK))
+
+#define TBM_BACKEND_ABI_VERSION_1_0 TBM_BACKEND_SET_ABI_VERSION(1, 0)
+#define TBM_BACKEND_ABI_VERSION_2_0 TBM_BACKEND_SET_ABI_VERSION(2, 0)
+#define TBM_BACKEND_ABI_VERSION_3_0 TBM_BACKEND_SET_ABI_VERSION(3, 0)
+#define TBM_BACKEND_ABI_LATEST_VERSION TBM_BACKEND_ABI_VERSION_3_0 /**< the latest version of the tbm backend abi */
+
+/**
+ * @brief The backend module data
+ * @details
+ * The init() function of #tbm_backend_module returns the backend module data.
+ * This handle will be used in #tbm_backend_bufmgr_func.
+ * @see tbm_backend_module, tbm_backend_bufmgr_func
+ */
+typedef void tbm_backend_bufmgr_data;
+
+/**
+ * @brief The backend bo data
+ * @details
+ * The allocation function and the import function in #tbm_backend_bufmgr_func
+ * returns the backend bo data. This handle will be used in #tbm_backend_bo_func.
+ * @see tbm_backend_bufmgr_funce, tbm_backend_bo_func
+ */
+typedef void tbm_backend_bo_data;
+
+/**
+ * @brief The type definition of the bufmgr functions
+ */
+typedef struct _tbm_backend_bufmgr_func tbm_backend_bufmgr_func;
+
+/**
+ * @brief The type definition of the bo functions
+ */
+typedef struct _tbm_backend_bo_func tbm_backend_bo_func;
+
+/**
+ * @brief The bufmgr functions for a backend module.
+ */
+struct _tbm_backend_bufmgr_func {
+ /**
+ * @brief Get the capabilities of a buffer manager
+ * @param[in] bufmgr_data The backend module data
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return the capabilities of a backend modul
+ */
+ tbm_bufmgr_capability (*bufmgr_get_capabilities)(tbm_backend_bufmgr_data *bufmgr_data,
+ tbm_error_e *error);
+
+ /**
+ * @brief set(bind) the native display
+ * @param[in] bufmgr_data The backend module data
+ * @param[in] native_display : the native display (wl_display in wayland window system)
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ */
+ tbm_error_e (*bufmgr_bind_native_display)(tbm_backend_bufmgr_data *bufmgr_data,
+ tbm_native_display *native_display);
+
+ /**
+ * @brief get the formats list and the num to be supported by backend.
+ * @param[in] bufmgr_data The backend module data
+ * @param[out] **formats : format array list. it is allocated by backend funtion
+ * @param[out] *num : the number of the formats to be supported by backend
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ */
+ tbm_error_e (*bufmgr_get_supported_formats)(tbm_backend_bufmgr_data *bufmgr_data,
+ uint32_t **formats, uint32_t *num);
+
+ /**
+ * @brief get the plane data of the surface.
+ * @param[in] bufmgr_data The backend module data
+ * @param[in] format : the format of the surface
+ * @param[in] plane_idx : the format of the surface
+ * @param[in] width : the width of the surface
+ * @param[in] height : the height of the surface
+ * @param[out] size : the size of the plane
+ * @param[out] offset : the offset of the plane
+ * @param[out] pitch : the pitch of the plane
+ * @param[out] bo_idx : the bo index of the plane
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ */
+ tbm_error_e (*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);
+
+ /**
+ * @brief allocate the bo_data of the tbm_backend
+ * @param[in] bufmgr_data The backend module data
+ * @param[in] size : the size of buffer object
+ * @param[in] flags : the flags of memory type
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return pointer of the bo_data of the tbm backend.
+ */
+ tbm_backend_bo_data *(*bufmgr_alloc_bo)(tbm_backend_bufmgr_data *bufmgr_data, int size,
+ tbm_bo_memory_type mem_type, tbm_error_e *error);
+
+ /**
+ * @brief allocate the buffer object for tbm surface
+ * @param[in] bo : the buffer object
+ * @param[in] width : the width of surface
+ * @param[in] height : the height of surface
+ * @param[in] format : the format of surface
+ * @param[in] flags : the flags of memory type
+ * @param[in] bo_idx : the index of bo in surface
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return pointer of the bo_data of the tbm backend.
+ */
+ tbm_backend_bo_data *(*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_type,
+ tbm_error_e *error);
+
+ /**
+ * @brief import the buffer object associated with the prime fd.
+ * @remarks tbm_fd must be free by user.
+ * @remarks If the backend doesn't support a buffer sharing by tbm fd,
+ * fucntion pointer must be set to NULL.
+ * @param[in] bufmgr_data The backend module data
+ * @param[in] fd : the prime fd associated with the buffer object
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return pointer of the bo_data of the tbm backend.
+ */
+ tbm_backend_bo_data *(*bufmgr_import_fd)(tbm_backend_bufmgr_data *bufmgr_data,
+ tbm_fd fd, tbm_error_e *error);
+
+ /**
+ * @brief import the buffer object associated with the key.
+ * @remarks If the backend doesn't support a buffer sharing by tbm key,
+ fucntion pointer must be set to NULL.
+ * @param[in] bufmgr_data The backend module data
+ * @param[in] key : the key associated with the buffer object
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return pointer of the bo_data of the tbm backend.
+ */
+ tbm_backend_bo_data *(*bufmgr_import_key)(tbm_backend_bufmgr_data *bufmgr_data,
+ tbm_key key, tbm_error_e *error);
+
+ /* Padding for future extension */
+ void (*reserved1)(void);
+ void (*reserved2)(void);
+ void (*reserved3)(void);
+ void (*reserved4)(void);
+ void (*reserved5)(void);
+ void (*reserved6)(void);
+};
+
+/**
+ * @brief The bo functions for a backend module.
+ */
+struct _tbm_backend_bo_func {
+ /**
+ * @brief free the buffer object.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ */
+ void (*bo_free)(tbm_backend_bo_data *bo_data);
+
+ /**
+ * @brief get the size of a bo.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return size if this function succeeds, otherwise 0.
+ */
+ int (*bo_get_size)(tbm_backend_bo_data *bo_data, tbm_error_e *error);
+
+ /**
+ * @brief get the tbm memory type
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @see #TBM_BO_FLAGS #tbm_bo_memory_type
+ * @return tbm flags of memory type is this function succeeds, otherwise 0.
+ */
+ tbm_bo_memory_type (*bo_get_memory_types)(tbm_backend_bo_data *bo_data,
+ tbm_error_e *error);
+
+ /**
+ * @brief get the tbm_bo_handle according to the device type.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @param[in] device : the device type to get a handle
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return the handle of the buffer object
+ */
+ tbm_bo_handle (*bo_get_handle)(tbm_backend_bo_data *bo_data,
+ tbm_bo_device_type device, tbm_error_e *error);
+
+ /**
+ * @brief map the buffer object according to the device type and the option.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @param[in] device : the device type to get a handle
+ * @param[in] opt : the option to access the buffer object
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return the handle of the buffer object
+ */
+ tbm_bo_handle (*bo_map)(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
+ tbm_bo_access_option opt, tbm_error_e *error);
+
+ /**
+ * @brief unmap the buffer object.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ */
+ tbm_error_e (*bo_unmap)(tbm_backend_bo_data *bo_data);
+
+ /**
+ * @brief lock the buffer object with a device and an opt.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @param[in] device : the device type to get a handle
+ * @param[in] opt : the option to access the buffer object
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @remark This function pointer could be null.
+ */
+ tbm_error_e (*bo_lock)(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
+ tbm_bo_access_option opt);
+
+ /**
+ * @brief unlock the buffer object.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @return #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @remark This function pointer could be null.
+ */
+ tbm_error_e (*bo_unlock)(tbm_backend_bo_data *bo_data);
+
+ /**
+ * @brief export the buffer object
+ * @remarks tbm_fd must be free by user.
+ * @remarks If the backend doesn't support a buffer sharing by tbm fd,
+ fucntion pointer must be set to NULL.
+ * @param[in] bo_data : the bo data of the tbm backend
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return tbm_fd associated with the buffer object
+ */
+ tbm_fd (*bo_export_fd)(tbm_backend_bo_data *bo_data, tbm_error_e *error);
+
+ /**
+ * @brief export the buffer object
+ * @remarks If the backend doesn't support a buffer sharing by tbm key,
+ fucntion pointer must be set to NULL.
+ * @param[in] bo : the buffer object
+ * @param[out] error #TBM_ERROR_NONE if success. Otherwise, error value.
+ * @return key associated with the buffer object
+ */
+ tbm_key (*bo_export_key)(tbm_backend_bo_data *bo_data, tbm_error_e *error);
+
+ /* Padding for future extension */
+ void (*reserved1)(void);
+ void (*reserved2)(void);
+ void (*reserved3)(void);
+ void (*reserved4)(void);
+ void (*reserved5)(void);
+ void (*reserved6)(void);
+};
+
+/**
+ * @brief The backend module information of the entry point to initialize a tbm
+ * backend module.
+ * @remark
+ * A backend module @b SHOULD define the global data symbol of which name is
+ * @b "tbm_backend_module_data". tbm will read this symbol, @b "tbm_backend_module_data",
+ * at the initial time and call init() function of #tbm_backend_module.
+ */
+typedef struct _tbm_backend_module {
+ const char *name; /**< The module name of a backend module */
+ const char *vendor; /**< The vendor name of a backend module */
+ unsigned long abi_version; /**< The ABI version of a backend module */
+
+ /**
+ * @brief The init function of a backend module
+ * @param[in] bufmgr A tbm buffer manager object.
+ * @return The backend module data
+ * @see tbm_backend_bufmgr_data
+ */
+ tbm_backend_bufmgr_data *(*init)(tbm_bufmgr bufmgr, tbm_error_e *error);
+
+ /**
+ * @brief deinitialize the bufmgr private data.
+ * @param[in] bufmgr_data : The backend module data
+ */
+ void (*deinit)(tbm_backend_bufmgr_data *bufmgr_data);
+} tbm_backend_module;
+
+int tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error);
+tbm_backend_bufmgr_func *tbm_backend_bufmgr_alloc_bufmgr_func(tbm_bufmgr bufmgr, tbm_error_e *error);
+void tbm_backend_bufmgr_free_bufmgr_func(tbm_bufmgr bufmgr, tbm_backend_bufmgr_func *func);
+tbm_error_e tbm_backend_bufmgr_register_bufmgr_func(tbm_bufmgr bufmgr, tbm_backend_bufmgr_func *func);
+tbm_backend_bo_func *tbm_backend_bufmgr_alloc_bo_func(tbm_bufmgr bufmgr, tbm_error_e *error);
+void tbm_backend_bufmgr_free_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func);
+tbm_error_e tbm_backend_bufmgr_register_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func);
+
+#endif /* _TBM_BACKEND_H_ */