tbm_module: change the tbm_module_bo_xxx signature
[platform/core/uifw/libtbm.git] / include / tbm_type_common.h
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2012-2018 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Inpyo Kang <mantiger@samsung.com>, Dongyeon Kim <dy5.kim@samsung.com>
9 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
10
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:
18
19 The above copyright notice and this permission notice (including the
20 next paragraph) shall be included in all copies or substantial portions
21 of the Software.
22
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.
30
31 **************************************************************************/
32
33 #ifndef _TBM_TYPE_COMMON_H_
34 #define _TBM_TYPE_COMMON_H_
35
36 #include <tbm_type.h>
37
38 /**
39  * \file tbm_type_common.h
40  * \brief Type definition used internally
41  */
42
43 /* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
44 #ifndef TBM_ERROR_BASE
45 #define TBM_ERROR_BASE                  -0x02830000
46 #endif
47
48 /**
49  * @brief Definition for the tizen buffer manager
50  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
51  */
52 typedef struct _tbm_bufmgr *tbm_bufmgr;
53
54 /**
55  * @brief Definition for the tizen buffer object
56  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
57  */
58 typedef struct _tbm_bo *tbm_bo;
59
60 /**
61  * @brief Definition for the key associated with the buffer object
62  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
63  */
64
65 typedef uint32_t tbm_key;
66 /**
67  * @brief Definition for the file descripter of the system buffer manager
68  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
69  */
70 typedef int32_t tbm_fd;
71
72 /**
73  * @brief Definition for native display (wl_display in tizen)
74  * @since_tizen 5.0
75  */
76 typedef void tbm_native_display;
77
78 /* TBM_DEVICE_TYPE */
79
80 /**
81  * @brief Enumeration for tbm error type.
82  * @since_tizen 2.4
83  */
84 typedef enum {
85         /* TBM_ERROR_XXX. start from (TBM_ERROR_BASE | 0x0001) to (TBM_ERROR_BASE | 0x0099) */
86         TBM_ERROR_NONE = TIZEN_ERROR_NONE,                               /**< Successful */
87         TBM_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,             /**< Out of memory */
88         TBM_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,     /**< Invalid function parameter */
89         TBM_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,     /**< Function not implemented */
90         TBM_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,             /**< Not supported */
91
92         /* TBM_BO_ERROR_XXX. start from (TBM_ERROR_BASE | 0x0101) to (TBM_ERROR_BASE | 0x0199) */
93         TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE | 0x0101,            /**< failed to get fd in bo  (DEPRECATED) */
94         TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_OUT_OF_MEMORY,        /**< failed to allocate the heap memory in bo  (DEPRECATED) */
95         TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE | 0x0103,       /**< failed to load module  (DEPRECATED) */
96         TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE | 0x0104,       /**< failed to initialize the pthread  (DEPRECATED) */
97         TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_OUT_OF_MEMORY,          /**< failed to allocate tbm_bo  (DEPRECATED) */
98         TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE | 0x0106,        /**< failed to initialize the state of tbm_bo  (DEPRECATED) */
99         TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE | 0x0107,            /**< failed to import the handle of tbm_bo  (DEPRECATED) */
100         TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE | 0x0108,         /**< failed to import fd of tbm_bo  (DEPRECATED) */
101         TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE | 0x0109,            /**< failed to export the handle of the tbm_bo  (DEPRECATED) */
102         TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE | 0x0110,         /**< failed to export fd of tbm_bo  (DEPRECATED) */
103         TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE | 0x0111,        /**< failed to get the tbm_bo_handle  (DEPRECATED) */
104         TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE | 0x0112,              /**< failed to lock the tbm_bo  (DEPRECATED) */
105         TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE | 0x0113,               /**< failed to map the tbm_bo to get the tbm_bo_handle  (DEPRECATED) */
106         TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE | 0x0114,             /**< failed to unmap the tbm_bo  (DEPRECATED) */
107         TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE | 0x0115,              /**< failed to swap the tbm_bos  (DEPRECATED) */
108         TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE | 0x0116,            /**< failed to duplicate fd  (DEPRECATED) */
109
110         /* TBM_SURFACE_ERROR_XXX. start from (TBM_ERROR_BASE | 0x0201) to (TBM_ERROR_BASE | 0x0299)
111          * TBM_SURFACE_ERROR_XXX is defined in tbm_surface.h file because it is CAPI.
112          *
113          * TBM_SURFACE_ERROR_NONE = TIZEN_ERROR_NONE,                             // Successful
114          * TBM_SURFACE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   // Invalid parameter
115          * TBM_SURFACE_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,   // Invalid Operation
116          *
117          */
118
119         /* TBM_SURFACE_QUEUE_ERROR_XXX. start from (TBM_ERROR_BASE | 0x0301) to (TBM_ERROR_BASE | 0x0399) */
120         TBM_SURFACE_QUEUE_ERROR_NONE = TBM_ERROR_NONE,                            /**< Successful */
121         TBM_SURFACE_QUEUE_ERROR_EMPTY = TBM_ERROR_BASE | 0x0301,                  /**< Empty queue */
122         TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE = TBM_ERROR_BASE | 0x0302,          /**< Invalid queue */
123         TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE = TBM_ERROR_BASE | 0x0303,        /**< Invalid surface */
124         TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED = TBM_ERROR_BASE | 0x0304,   /**< Allocation of surface failed */
125         TBM_SURFACE_QUEUE_ERROR_ALREADY_EXIST = TBM_ERROR_BASE | 0x0305,              /**< Already existed surface */
126         TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE = TBM_ERROR_BASE | 0x0306,            /**< Unknown surface */
127         TBM_SURFACE_QUEUE_ERROR_INVALID_SEQUENCE = TBM_ERROR_BASE | 0x0307,       /**< Invalid sequence */
128         TBM_SURFACE_QUEUE_ERROR_TIMEOUT = TBM_ERROR_BASE | 0x0308,                /**< Timeout */
129 } tbm_error_e;
130
131 typedef tbm_error_e tbm_surface_queue_error_e;
132
133 /**
134  * @brief Enumeration of tbm buffer manager capability.
135  * @since_tizen 2.4
136  */
137 enum TBM_BUFMGR_CAPABILITY {
138         TBM_BUFMGR_CAPABILITY_NONE = 0,                  /**< Not Support capability*/
139         TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0),      /**< Support sharing buffer by tbm key */
140         TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1),       /**< Support sharing buffer by tbm fd */
141         TBM_BUFMGR_CAPABILITY_TBM_SYNC = (1 << 2),       /**< Support timeline sync */
142         TBM_BUFMGR_CAPABILITY_TILED_MEMORY = (1 << 3),   /**< Support tiled memory */
143 };
144
145 /**
146  * @brief Definition for the device type to access tbm_bo
147  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
148  */
149 typedef enum {
150         TBM_DEVICE_DEFAULT = 0,  /**< the device type to get the default handle */
151         TBM_DEVICE_CPU,          /**< the device type to get the virtual memory */
152         TBM_DEVICE_2D,           /**< the device type to get the 2D memory handle */
153         TBM_DEVICE_3D,           /**< the device type to get the 3D memory handle */
154         TBM_DEVICE_MM,           /**< the device type to get the the multimedia handle */
155
156 } tbm_bo_device_type;
157
158 /**
159  * @brief Definition for the optoin to access tbm_bo
160  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
161  */
162 typedef enum {
163         TBM_OPTION_NONE = (1 << 0),        /**< the option is none */
164         TBM_OPTION_READ = (1 << 0),        /**< the option to access to read the bo */
165         TBM_OPTION_WRITE = (1 << 1),       /**< the option to access to write the bo */
166         TBM_OPTION_VENDOR = (0xffff0000),  /**< the the vendor specific option that depends on the backend */
167 } tbm_bo_access_option;
168
169 /**
170  * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE
171  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
172  */
173 typedef union _tbm_bo_handle {
174         void *ptr;
175         int32_t s32;
176         uint32_t u32;
177         int64_t s64;
178         uint64_t u64;
179 } tbm_bo_handle;
180
181 /**
182  * @brief Enumeration of bo memory type
183  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
184  */
185 enum TBM_BO_FLAGS {
186         TBM_BO_DEFAULT = 0,                        /**< default memory: it depends on the backend         */
187         TBM_BO_SCANOUT = (1 << 0),         /**< scanout memory                                    */
188         TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory                               */
189         TBM_BO_WC = (1 << 2),              /**< write-combine memory                              */
190         TBM_BO_TILED = (1 << 3),       /**< tiled memory                                      */
191         TBM_BO_VENDOR = (0xffff0000),  /**< vendor specific memory: it depends on the backend */
192 };
193
194 /**
195  * @brief Definition for the TBM surface buffer data struct.
196  * @since_tizen 6.5
197  */
198 typedef struct _tbm_surface_buffer_data {
199         int *fds;                       /**< an array of dmabuf fds */
200         unsigned int num_fds;           /**< the number of dmabuf fds */
201         int *meta_data;                 /**< an array of meta data */
202         unsigned int num_meta_data;     /**< the number of meta data */
203         void *reserved1;                /**< reserved data1 */
204         void *reserved2;                /**< reserved data2 */
205 } tbm_surface_buffer_data;
206
207 /**
208  * @brief Called when the user data is deleted in buffer object.
209  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
210  * @param[in] user_data User_data to be passed to callback function
211  * @pre The callback must be registered using tbm_bo_add_user_data().\n
212  * tbm_bo_delete_user_data() must be called to invoke this callback.
213  * @see tbm_bo_add_user_data()
214  * @see tbm_bo_delete_user_data()
215  */
216 typedef void (*tbm_data_free) (void *user_data);
217
218 /**
219  * @brief Enumeration of tbm buffer manager capability.
220  * @since_tizen 5.0
221  */
222 typedef enum TBM_BUFMGR_CAPABILITY tbm_bufmgr_capability;
223
224 /**
225  * @brief Enumeration of tbm bo memory type.
226  * @since_tizen 5.0
227  */
228 typedef enum TBM_BO_FLAGS tbm_bo_memory_type;
229
230 /**
231  * @brief Enumeration of buffer manager lock try for bo
232  * @since_tizen 5.0
233  */
234 typedef enum {
235         TBM_BUFMGR_BO_LOCK_TYPE_NEVER = 0,  /**< the bufmgr do not try to lock the bos when the tbm_bo_map is called. */
236         TBM_BUFMGR_BO_LOCK_TYPE_ONCE,       /**< the bufmgr tries to lock the bos only once when the tbm_bo_map is called. */
237         TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS,     /**< the bufmgr always tries to lock the bos when the tbm_bo_map is called. */
238 } tbm_bufmgr_bo_lock_type;
239
240 /**
241  * @brief Enumeration of the trace log for debug
242  * @since_tizen 5.0
243  */
244 typedef enum {
245         TBM_BUFGMR_DEBUG_TRACE_NONE             = 0,
246         TBM_BUFGMR_DEBUG_TRACE_BO               = (1 << 0),
247         TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL = (1 << 1),
248         TBM_BUFGMR_DEBUG_TRACE_SURFACE          = (1 << 2),
249         TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE    = (1 << 3),
250 } tbm_bufmgr_debug_trace_mask;
251
252 /* type to string ***********************************************************/
253 struct tbm_type_name {
254         int type;
255         const char *name;
256 };
257
258 #define TBM_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
259
260 #define TBM_TYPE_NAME_FN(res) \
261 static inline const char * tbm_##res##_str(int type)    \
262 {                       \
263         unsigned int i;                                 \
264         for (i = 0; i < TBM_ARRAY_SIZE(tbm_##res##_names); i++) { \
265                 if (tbm_##res##_names[i].type == type)  \
266                         return tbm_##res##_names[i].name;       \
267         }                                               \
268         return "(invalid)";                             \
269 }
270
271 static struct tbm_type_name tbm_error_names[] = {
272         { TBM_ERROR_NONE, "TBM_ERROR_NONE" },
273         { TBM_ERROR_OUT_OF_MEMORY, "TBM_ERROR_OUT_OF_MEMORY" },
274         { TBM_ERROR_INVALID_PARAMETER, "TBM_ERROR_INVALID_PARAMETER" },
275         { TBM_ERROR_INVALID_OPERATION, "TBM_ERROR_INVALID_OPERATION" },
276         { TBM_ERROR_NOT_SUPPORTED, "TBM_ERROR_NOT_SUPPORTED" },
277         { TBM_SURFACE_QUEUE_ERROR_EMPTY, "TBM_SURFACE_QUEUE_ERROR_EMPTY" },
278         { TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE, "TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE" },
279         { TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE, "TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE" },
280         { TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED, "TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED" },
281         { TBM_SURFACE_QUEUE_ERROR_ALREADY_EXIST, "TBM_SURFACE_QUEUE_ERROR_ALREADY_EXIST" },
282         { TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE, "TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE" },
283 };
284 TBM_TYPE_NAME_FN(error)
285
286 #endif                                                  /* _TBM_TYPE_COMMON_H_ */