add surface destroy callback add/remove api
[platform/core/uifw/libtbm.git] / include / tbm_bufmgr_backend.h
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 /*
33  * This file is referenced by the xf86Module.h in xorg server.
34  */
35
36 #ifndef _TBM_BUFMGR_BACKEND_H_
37 #define _TBM_BUFMGR_BACKEND_H_
38
39 #include <tbm_bufmgr.h>
40 #include <pthread.h>
41
42 /**
43  * \file tbm_bufmgr_backend.h
44  * \brief backend header for Tizen Buffer Manager
45  *   This header is for the implementation of the TBM backend module.
46  */
47
48 #define ABI_MINOR_MASK          0x0000FFFF
49 #define ABI_MAJOR_MASK          0xFFFF0000
50 #define GET_ABI_MINOR(v)        ((v) & ABI_MINOR_MASK)
51 #define GET_ABI_MAJOR(v)        (((v) & ABI_MAJOR_MASK) >> 16)
52
53 /*
54  * ABI versions.  Each version has a major and minor revision.  Modules
55  * using lower minor revisions must work with servers of a higher minor
56  * revision.  There is no compatibility between different major revisions.
57  * Whenever the ABI_ANSIC_VERSION is changed, the others must also be
58  * changed.  The minor revision mask is 0x0000FFFF and the major revision
59  * mask is 0xFFFF0000.
60  */
61 #define SET_ABI_VERSION(maj, min) \
62                 ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK))
63
64 #define TBM_ABI_VERSION SET_ABI_VERSION(1, 1) /**< current abi vertion  */
65
66 typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend;
67
68 /**
69  * @brief TBM backend functions
70  *  the set of function pointers for the backend module of TBM.
71  */
72 struct _tbm_bufmgr_backend {
73         int flags;
74
75         void *priv;     /**< bufmgr private */
76
77         /**
78         * @brief deinitialize the bufmgr private.
79         * @param[in] priv : the private of the bufmgr
80         */
81         void (*bufmgr_deinit)(void *priv);
82
83         /**
84         * @brief get(bind) the native display
85         * @param[in] bufmgr : the buffer object
86         * @param[in] native_display : the native display
87         * @return 1 if this function succeeds, otherwise 0.
88         */
89         int (*bufmgr_bind_native_display)(tbm_bufmgr bufmgr, void *native_display);
90
91         /**
92         * @brief allocate the buffer object
93         * @param[in] bo : the buffer object
94         * @param[in] size : the size of buffer object
95         * @param[in] flags : the flags of memory type
96         * @return pointer of the bo private.
97         */
98         void *(*bo_alloc)(tbm_bo bo, int size, int flags);
99
100         /**
101         * @brief free the buffer object.
102         * @param[in] bo : the buffer object
103         */
104         void (*bo_free)(tbm_bo bo);
105
106         /**
107         * @brief get the size of a bo.
108         * @param[in] bo : the buffer object
109         * @return size if this function succeeds, otherwise 0.
110         */
111         int (*bo_size)(tbm_bo bo);
112
113         /**
114         * @brief get the tbm flags of memory type
115         * @param[in] bo : the buffer object
116         * @see #TBM_BO_FLAGS
117         * @return tbm flags of memory type is this function succeeds, otherwise 0.
118         */
119         int (*bo_get_flags)(tbm_bo bo);
120
121         /**
122         * @brief get the tbm_bo_handle according to the device type.
123         * @param[in] bo : the buffer object
124         * @param[in] device : the device type to get a handle
125         * @return the handle of the buffer object
126         */
127         tbm_bo_handle(*bo_get_handle)(tbm_bo bo, int device);
128
129         /**
130         * @brief map the buffer object according to the device type and the option.
131         * @param[in] bo : the buffer object
132         * @param[in] device : the device type to get a handle
133         * @param[in] opt : the option to access the buffer object
134         * @return the handle of the buffer object
135         */
136         tbm_bo_handle(*bo_map)(tbm_bo bo, int device, int opt);
137
138         /**
139         * @brief unmap the buffer object.
140         * @param[in] bo : the buffer object
141         * @return 1 if this function succeeds, otherwise 0.
142         */
143         int (*bo_unmap)(tbm_bo bo);
144
145         /**
146         * @brief lock the buffer object with a device and an opt.
147         * @param[in] bo : the buffer object
148         * @param[in] device : the device type to get a handle
149         * @param[in] opt : the option to access the buffer object
150         * @return 1 if this function succeeds, otherwise 0.
151         * @remark This function pointer could be null. (default: use the tizen global lock)
152         */
153         int (*bo_lock)(tbm_bo bo, int device, int opt);
154
155         /**
156         * @brief unlock the buffer object.
157         * @param[in] bo : the buffer object
158         * @return 1 if this function succeeds, otherwise 0.
159         * @remark This function pointer could be null. (default: use the tizen global lock)
160         */
161         int (*bo_unlock)(tbm_bo bo);
162
163         /**
164         * @brief export the buffer object
165         * @remarks tbm_fd must be free by user.
166         * @remarks If the backend doesn't support a buffer sharing by tbm fd,
167                         fucntion pointer must be set to NULL.
168         * @param[in] bo : the buffer object
169         * @return tbm_fd associated with the buffer object
170         */
171         tbm_fd (*bo_export_fd)(tbm_bo bo);
172
173         /**
174         * @brief import the buffer object associated with the prime fd.
175         * @remarks tbm_fd must be free by user.
176         * @remarks If the backend doesn't support a buffer sharing by tbm fd,
177                         fucntion pointer must be set to NULL.
178         * @param[in] bo : the buffer object
179         * @param[in] fd : the prime fd associated with the buffer object
180         * @return pointer of the bo private.
181         */
182         void *(*bo_import_fd)(tbm_bo bo, tbm_fd fd);
183
184         /**
185         * @brief export the buffer object
186         * @remarks If the backend doesn't support a buffer sharing by tbm key,
187                         fucntion pointer must be set to NULL.
188         * @param[in] bo : the buffer object
189         * @return key associated with the buffer object
190         */
191         unsigned int (*bo_export)(tbm_bo bo);
192
193         /**
194         * @brief import the buffer object associated with the key.
195         * @remarks If the backend doesn't support a buffer sharing by tbm key,
196                         fucntion pointer must be set to NULL.
197         * @param[in] bo : the buffer object
198         * @param[in] key : the key associated with the buffer object
199         * @return pointer of the bo private.
200         */
201         void *(*bo_import)(tbm_bo bo, unsigned int key);
202
203         /**
204         * @brief query the formats list and the num to be supported by backend.
205         * @param[out] **formats : format array list. this array has to be allocated by backend funtion
206         * @param[out] *num : the number of the formats to be supported by backend
207         * @return 1 if this function succeeds, otherwise 0.
208         */
209         int (*surface_supported_format)(uint32_t **formats, uint32_t *num);
210
211         /**
212         * @brief get the plane data of the surface.
213         * @param[in] width : the width of the surface
214         * @param[in] height : the height of the surface
215         * @param[in] format : the format of the surface
216         * @param[in] plane_idx : the format of the surface
217         * @param[out] size : the size of the plane
218         * @param[out] offset : the offset of the plane
219         * @param[out] pitch : the pitch of the plane
220         * @param[out] bo_idx : the bo index of the plane
221         * @return 1 if this function succeeds, otherwise 0.
222         */
223         int (*surface_get_plane_data)(int width, int height,
224                                       tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset,
225                                       uint32_t *pitch, int *bo_idx);
226
227         /**
228         * @brief allocate the buffer object for tbm surface
229         * @param[in] bo : the buffer object
230         * @param[in] width : the width of surface
231         * @param[in] height : the height of surface
232         * @param[in] format : the format of surface
233         * @param[in] flags : the flags of memory type
234         * @param[in] bo_idx : the index of bo in surface
235         * @return pointer of the bo private.
236         */
237         void * (*surface_bo_alloc)(tbm_bo bo, int width, int height, int format, int flags, int bo_idx);
238
239         /* Padding for future extension */
240         void (*reserved1)(void);
241         void (*reserved2)(void);
242         void (*reserved3)(void);
243         void (*reserved4)(void);
244         void (*reserved5)(void);
245         void (*reserved6)(void);
246 };
247
248 /**
249  * @brief tbm module information
250  *  data type for the module information
251  */
252 typedef struct {
253         const char *modname;               /**< name of module, e.g. "foo" */
254         const char *vendor;                        /**< vendor specific string */
255         unsigned long abiversion;          /**< ABI version */
256 } TBMModuleVersionInfo;
257
258 typedef int (*ModuleInitProc) (tbm_bufmgr, int);
259
260 #define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */
261
262 /**
263  * @brief tbm module data
264  *  data type for the entry point of the backend module
265  */
266 typedef struct {
267         TBMModuleVersionInfo *vers;     /**< tbm module informtaion */
268         ModuleInitProc init;            /**< init function of a backend module */
269 } TBMModuleData;
270
271 #ifdef __cplusplus
272 extern "C" {
273 #endif
274
275 tbm_bufmgr_backend tbm_backend_alloc(void);
276 void tbm_backend_free(tbm_bufmgr_backend backend);
277 int tbm_backend_init(tbm_bufmgr bufmgr, tbm_bufmgr_backend backend);
278
279 void *tbm_backend_get_bufmgr_priv(tbm_bo bo);
280 void *tbm_backend_get_priv_from_bufmgr(tbm_bufmgr bufmgr);
281 void *tbm_backend_get_bo_priv(tbm_bo bo);
282 int tbm_backend_is_display_server(void);
283
284 #ifdef __cplusplus
285 }
286 #endif
287 #endif                                                  /* _TBM_BUFMGR_BACKEND_H_ */