From: SooChan Lim Date: Tue, 13 Mar 2018 10:22:32 +0000 (+0900) Subject: make the tbm_backend file X-Git-Tag: accepted/tizen/unified/20180316.062629~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00f565769857c185aad5914ada791b81096e58c0;p=platform%2Fcore%2Fuifw%2Flibtbm.git make the tbm_backend file This is new backend interface to implement the backend module. After 3.0 version of libtbm, the vendors have to implement their tbm backend modules with the new backend header file which is tbm_backend.h file. The old backend header file which is tbm_bufmgr_backend.h file is deprecated and will be removed soon. Change-Id: I54b3694363fafa2147188de8a1bec701405ff1c4 --- diff --git a/packaging/libtbm.spec b/packaging/libtbm.spec index 40d944c..69e679e 100644 --- a/packaging/libtbm.spec +++ b/packaging/libtbm.spec @@ -115,6 +115,7 @@ rm -f %{_unitdir_user}/basic.target.wants/tbm-drm-auth-user.path %{_includedir}/tbm_sync.h %{_includedir}/tbm_bo.h %{_includedir}/tbm_log.h +%{_includedir}/tbm_backend.h %{_libdir}/libtbm.so %{_libdir}/pkgconfig/libtbm.pc diff --git a/src/Makefile.am b/src/Makefile.am index 2d60897..8e2307f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,8 @@ libtbm_la_SOURCES = \ tbm_drm_helper_server.c \ tbm_drm_helper_client.c \ tbm_sync.c \ - tbm_log.c + tbm_log.c \ + tbm_backend.c nodist_libtbm_la_SOURCES = \ wayland-tbm-drm-auth-server-protocol.h \ @@ -52,6 +53,7 @@ libtbminclude_HEADERS = tbm_bufmgr.h \ tbm_surface_queue.h \ tbm_drm_helper.h \ tbm_sync.h \ - tbm_log.h + tbm_log.h \ + tbm_backend.h CLEANFILES = $(BUILT_SOURCES) diff --git a/src/tbm_backend.c b/src/tbm_backend.c new file mode 100644 index 0000000..bec6147 --- /dev/null +++ b/src/tbm_backend.c @@ -0,0 +1,142 @@ +/************************************************************************** + +libtbm + +Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim , + Sangjin Lee , + Boram Park , + Changyeon Lee + +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 */ diff --git a/src/tbm_backend.h b/src/tbm_backend.h new file mode 100644 index 0000000..6896e6d --- /dev/null +++ b/src/tbm_backend.h @@ -0,0 +1,351 @@ +/************************************************************************** + +libtbm + +Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim , + Sangjin Lee , + Boram Park , + Changyeon Lee + +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 + +/** + * \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 + * @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_ */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 4aeb3ab..c47067c 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -56,6 +56,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include extern tbm_bufmgr gBufMgr; extern int b_dump_queue; @@ -189,11 +190,13 @@ struct _tbm_bo { int ref_cnt; /* ref count of bo */ int flags; /* TBM_BO_FLAGS :bo memory type */ struct list_head user_data_list; /* list of the user_date in bo */ - void *priv; /* bo private */ + void *priv; /* bo private (will be DEPRECATED) */ struct list_head item_link; /* link of bo */ tbm_surface_h surface; /* tbm_surface */ int lock_cnt; /* lock count of bo */ unsigned int map_cnt; /* device map count */ + + tbm_backend_bo_data *bo_data; /* bo data of the backend module */ }; /** @@ -213,8 +216,13 @@ struct _tbm_bufmgr { struct list_head surf_queue_list; /* list of surface queues belonging to bufmgr */ struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */ - void *module_data; - tbm_bufmgr_backend backend; /* bufmgr backend */ + void *module_data; /* backend module */ + tbm_bufmgr_backend backend; /* bufmgr backend (will be DEPRECATED) */ + + tbm_backend_module *backend_module_data; /* backend module data */ + tbm_backend_bufmgr_data *bufmgr_data; /* backend data of the backend module */ + tbm_backend_bufmgr_func *bufmgr_func; /* backend functions for bufmgr */ + tbm_backend_bo_func *bo_func; /* backend functions for bo */ }; /**