1c967ac3e27a884cb07d9e40ede605d684fdb7ca
[platform/core/uifw/libtbm.git] / src / 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] bufmgr : the private of the bufmgr
80         * @return 1 if this function succeeds, otherwise 0.
81         */
82         void (*bufmgr_deinit)(void *priv);
83
84         /**
85         * @brief get the size of a bo.
86         * @param[in] bo : the buffer object
87         * @return 1 if this function succeeds, otherwise 0.
88         */
89         int (*bo_size)(tbm_bo bo);
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 import the buffer object associated with the key.
108         * @remarks If the backend doesn't support a buffer sharing by tbm key,
109                         fucntion pointer must be set to NULL.
110         * @param[in] bo : the buffer object
111         * @param[in] key : the key associated with the buffer object
112         * @return pointer of the bo private.
113         */
114         void *(*bo_import)(tbm_bo bo, unsigned int key);
115
116         /**
117         * @brief export the buffer object
118         * @remarks If the backend doesn't support a buffer sharing by tbm key,
119                         fucntion pointer must be set to NULL.
120         * @param[in] bo : the buffer object
121         * @return key associated with the buffer object
122         */
123         unsigned int (*bo_export)(tbm_bo bo);
124
125         /**
126         * @brief get the tbm_bo_handle according to the device type.
127         * @param[in] bo : the buffer object
128         * @param[in] device : the device type to get a handle
129         * @return the handle of the buffer object
130         */
131         tbm_bo_handle(*bo_get_handle)(tbm_bo bo, int device);
132
133         /**
134         * @brief map the buffer object according to the device type and the option.
135         * @param[in] bo : the buffer object
136         * @param[in] device : the device type to get a handle
137         * @param[in] option : the option to access the buffer object
138         * @return the handle of the buffer object
139         */
140         tbm_bo_handle(*bo_map)(tbm_bo bo, int device, int opt);
141
142         /**
143         * @brief unmap the buffer object.
144         * @param[in] bo : the buffer object
145         * @return 1 if this function succeeds, otherwise 0.
146         */
147         int (*bo_unmap)(tbm_bo bo);
148
149         /**
150         * @brief unlock the buffer object.
151         * @param[in] bo : the buffer object
152         * @return 1 if this function succeeds, otherwise 0.
153         * @remark This function pointer could be null. (default: use the tizen global lock)
154         */
155         int (*bo_unlock)(tbm_bo bo);
156
157         /**
158         * @brief lock the buffer object with a device and an opt.
159         * @param[in] bo : the buffer object
160         * @param[in] device : the device type to get a handle
161         * @param[in] option : the option to access the buffer object
162         * @return 1 if this function succeeds, otherwise 0.
163         * @remark This function pointer could be null. (default: use the tizen global lock)
164         */
165         int (*bo_lock)(tbm_bo bo, int device, int opt);
166
167         /**
168         * @brief query the formats list and the num to be supported by backend.
169         * @param[out] *formats : format array list. this array has to be allocated by backend funtion
170         * @param[out] *num : the number of the formats to be supported by backend
171         * @return 1 if this function succeeds, otherwise 0.
172         */
173         int (*surface_supported_format)(uint32_t **formats, uint32_t *num);
174
175         /**
176         * @brief get the plane data of the surface.
177         * @param[in] surface : the surface
178         * @param[in] width : the width of the surface
179         * @param[in] height : the height of the surface
180         * @param[in] format : the format of the surface
181         * @param[in] plane_idx : the format of the surface
182         * @param[out] size : the size of the plane
183         * @param[out] offset : the offset of the plane
184         * @param[out] pitch : the pitch of the plane
185         * @param[out] bo_idx : the bo index of the plane
186         * @return 1 if this function succeeds, otherwise 0.
187         */
188         int (*surface_get_plane_data)(int width, int height,
189                                       tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset,
190                                       uint32_t *pitch, int *bo_idx);
191
192         /**
193         * @brief import the buffer object associated with the prime fd.
194         * @remarks tbm_fd must be free by user.
195         * @remarks If the backend doesn't support a buffer sharing by tbm fd,
196                         fucntion pointer must be set to NULL.
197         * @param[in] bo : the buffer object
198         * @param[in] fd : the prime fd associated with the buffer object
199         * @return pointer of the bo private.
200         */
201         void *(*bo_import_fd)(tbm_bo bo, tbm_fd fd);
202
203         /**
204         * @brief export the buffer object
205         * @remarks tbm_fd must be free by user.
206         * @remarks If the backend doesn't support a buffer sharing by tbm fd,
207                         fucntion pointer must be set to NULL.
208         * @param[in] bo : the buffer object
209         * @return tbm_fd associated with the buffer object
210         */
211         tbm_fd (*bo_export_fd)(tbm_bo bo);
212
213         /**
214         * @brief get the tbm flags of memory type
215         * @param[in] bo : the buffer object
216         * @see #TBM_BO_FLAGS
217         * @return tbm flags of memory type is this function succeeds, otherwise 0.
218         */
219         int (*bo_get_flags)(tbm_bo bo);
220
221         /**
222         * @brief get the tbm flags of memory type
223         * @param[in] bo : the buffer object
224         * @see #TBM_BO_FLAGS
225         * @return tbm flags of memory type is this function succeeds, otherwise 0.
226         */
227         int (*bufmgr_bind_native_display)(tbm_bufmgr bufmgr, void *NativeDisplay);
228
229         /* Padding for future extension */
230         void (*reserved1)(void);
231         void (*reserved2)(void);
232         void (*reserved3)(void);
233         void (*reserved4)(void);
234         void (*reserved5)(void);
235         void (*reserved6)(void);
236 };
237
238 /**
239  * @brief tbm module information
240  *  data type for the module information
241  */
242 typedef struct {
243         const char *modname;               /**< name of module, e.g. "foo" */
244         const char *vendor;                        /**< vendor specific string */
245         unsigned long abiversion;          /**< ABI version */
246 } TBMModuleVersionInfo;
247
248 typedef int (*ModuleInitProc) (tbm_bufmgr, int);
249
250 #define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */
251
252 /**
253  * @brief tbm module data
254  *  data type for the entry point of the backend module
255  */
256 typedef struct {
257         TBMModuleVersionInfo *vers;     /**< tbm module informtaion */
258         ModuleInitProc init;            /**< init function of a backend module */
259 } TBMModuleData;
260
261 tbm_bufmgr_backend tbm_backend_alloc(void);
262 void tbm_backend_free(tbm_bufmgr_backend backend);
263 int tbm_backend_init(tbm_bufmgr bufmgr, tbm_bufmgr_backend backend);
264
265 void *tbm_backend_get_bufmgr_priv(tbm_bo bo);
266 void *tbm_backend_get_priv_from_bufmgr(tbm_bufmgr bufmgr);
267 void *tbm_backend_get_bo_priv(tbm_bo bo);
268 int tbm_backend_is_display_server(void);
269
270 #endif                                                  /* _TBM_BUFMGR_BACKEND_H_ */