3e3150f8af24f9b13b61d47db16dc14af0e8e144
[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
49 #define ABI_MINOR_MASK          0x0000FFFF
50 #define ABI_MAJOR_MASK          0xFFFF0000
51 #define GET_ABI_MINOR(v)        ((v) & ABI_MINOR_MASK)
52 #define GET_ABI_MAJOR(v)        (((v) & ABI_MAJOR_MASK) >> 16)
53
54 /*
55  * ABI versions.  Each version has a major and minor revision.  Modules
56  * using lower minor revisions must work with servers of a higher minor
57  * revision.  There is no compatibility between different major revisions.
58  * Whenever the ABI_ANSIC_VERSION is changed, the others must also be
59  * changed.  The minor revision mask is 0x0000FFFF and the major revision
60  * mask is 0xFFFF0000.
61  */
62 #define SET_ABI_VERSION(maj, min) \
63         ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK))
64
65 #define TBM_ABI_VERSION SET_ABI_VERSION(1, 1) /**< current abi vertion  */
66
67 /* TBM_CACHE */
68 #define TBM_CACHE_INV       0x01 /**< cache invalidate  */
69 #define TBM_CACHE_CLN       0x02 /**< cache clean */
70 #define TBM_CACHE_ALL       0x10 /**< cache all */
71 #define TBM_CACHE_FLUSH     (TBM_CACHE_INV|TBM_CACHE_CLN) /**< cache flush  */
72 #define TBM_CACHE_FLUSH_ALL (TBM_CACHE_FLUSH|TBM_CACHE_ALL) /**< cache flush all */
73
74 /*  TBM flag for cache control and lock control */
75 /**
76  * TBM_CACHE_CTRL_BACKEND indicates that the backend control the cache coherency.
77  */
78 #define TBM_CACHE_CTRL_BACKEND    (1 << 0)
79
80 /**
81  * TBM_LOCK_CTRL_BACKEND indicates  that the backend control the lock of bos.
82  */
83 #define TBM_LOCK_CTRL_BACKEND    (1 << 1)
84
85 typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend;
86
87 /**
88  * @brief TBM backend functions
89  *  the set of function pointers for the backend module of TBM.
90  */
91 struct _tbm_bufmgr_backend
92 {
93     int   flags;
94
95     void *priv; /**< bufmgr private */
96
97     /**
98     * @brief deinitialize the bufmgr private.
99     * @param[in] bufmgr : the private of the bufmgr
100     * @return 1 if this function succeeds, otherwise 0.
101     */
102     void          (*bufmgr_deinit) (void *priv);
103
104     /**
105     * @brief get the size of a bo.
106     * @param[in] bo : the buffer object
107     * @return 1 if this function succeeds, otherwise 0.
108     */
109     int           (*bo_size)           (tbm_bo bo);
110
111     /**
112     * @brief allocate the buffer object
113     * @param[in] bo : the buffer object
114     * @param[in] size : the size of buffer object
115     * @param[in] flags : the flags of memory type
116     * @return pointer of the bo private.
117     */
118     void *       (*bo_alloc)          (tbm_bo bo, int size, int flags);
119
120     /**
121     * @brief free the buffer object.
122     * @param[in] bo : the buffer object
123     */
124     void          (*bo_free)           (tbm_bo bo);
125
126     /**
127     * @brief import the buffer object associated with the key.
128     * @param[in] bo : the buffer object
129     * @param[in] key : the key associated with the buffer object
130     * @return pointer of the bo private.
131     */
132     void *       (*bo_import)         (tbm_bo bo, unsigned int key);
133
134     /**
135     * @brief export the buffer object
136     * @param[in] bo : the buffer object
137     * @return key associated with the buffer object
138     */
139     unsigned int  (*bo_export)         (tbm_bo bo);
140
141     /**
142     * @brief get the tbm_bo_handle according to the device type.
143     * @param[in] bo : the buffer object
144     * @param[in] device : the device type to get a handle
145     * @return the handle of the buffer object
146     */
147     tbm_bo_handle (*bo_get_handle)     (tbm_bo bo, int device);
148
149     /**
150     * @brief map the buffer object according to the device type and the option.
151     * @param[in] bo : the buffer object
152     * @param[in] device : the device type to get a handle
153     * @param[in] option : the option to access the buffer object
154     * @return the handle of the buffer object
155     */
156     tbm_bo_handle (*bo_map)            (tbm_bo bo, int device, int opt);
157
158     /**
159     * @brief unmap the buffer object.
160     * @param[in] bo : the buffer object
161     * @return 1 if this function succeeds, otherwise 0.
162     */
163     int           (*bo_unmap)          (tbm_bo bo);
164
165     /**
166     * @brief flush the cache of the buffer object.
167     * @param[in] bo : the buffer object
168     * @param[in] flags : the flags of cache flush type
169     * @return 1 if this function succeeds, otherwise 0.
170     */
171     int           (*bo_cache_flush)    (tbm_bo bo, int flags);
172
173     /**
174     * @brief get the global key associated with the buffer object.
175     * @param[in] bo : the buffer object
176     * @return global key associated with the buffer object.
177     */
178     int           (*bo_get_global_key) (tbm_bo bo);
179
180     /**
181     * @brief lock the buffer object.
182     * @param[in] bo : the buffer object
183     * @return 1 if this function succeeds, otherwise 0.
184     * @remark This function pointer could be null. (default: use the tizen global lock)
185     */
186     int           (*bo_lock)           (tbm_bo bo);
187
188     /**
189     * @brief unlock the buffer object.
190     * @param[in] bo : the buffer object
191     * @return 1 if this function succeeds, otherwise 0.
192     * @remark This function pointer could be null. (default: use the tizen global lock)
193     */
194     int           (*bo_unlock)         (tbm_bo bo);
195
196     /**
197     * @brief lock the buffer object with a device and an opt.
198     * @param[in] bo : the buffer object
199     * @param[in] device : the device type to get a handle
200     * @param[in] option : the option to access the buffer object
201     * @return 1 if this function succeeds, otherwise 0.
202     * @remark This function pointer could be null. (default: use the tizen global lock)
203     */
204     int           (*bo_lock2)           (tbm_bo bo, int device, int opt);
205
206     /**
207     * @brief query the formats list and the num to be supported by backend.
208     * @param[out] *formats : format array list. this array has to be allocated by backend funtion
209     * @param[out] *num : the number of the formats to be supported by backend
210     * @return 1 if this function succeeds, otherwise 0.
211     */
212     int           (*surface_supported_format) (uint32_t **formats, uint32_t *num);
213
214     /**
215     * @brief get the size of the surface with a format.
216     * @param[in] surface : the surface
217     * @param[in] width : the width of the surface
218     * @param[in] height : the height of the surface
219     * @param[in] format : the format of the surface
220     * @return size of the surface if this function succeeds, otherwise 0.
221     */
222     int           (*surface_get_size)   (tbm_surface_h surface, int width, int height, tbm_format format);
223
224     /**
225     * @brief get the plane data of the surface.
226     * @param[in] surface : the surface
227     * @param[in] width : the width of the surface
228     * @param[in] height : the height of the surface
229     * @param[in] format : the format of the surface
230     * @param[in] plane_idx : the format of the surface
231     * @param[out] size : the size of the plane
232     * @param[out] offset : the offset of the plane
233     * @param[out] pitch : the pitch of the plane
234     * @return 1 if this function succeeds, otherwise 0.
235     */
236     int           (*surface_get_plane_data)   (tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch);
237
238     /**
239     * @brief import the buffer object associated with the prime fd.
240     * @param[in] bo : the buffer object
241     * @param[in] fd : the prime fd associated with the buffer object
242     * @return pointer of the bo private.
243     */
244     void *       (*bo_import_fd)         (tbm_bo bo, tbm_fd fd);
245
246     /**
247     * @brief export the buffer object
248     * @param[in] bo : the buffer object
249     * @return tbm_fd associated with the buffer object
250     */
251     tbm_fd              (*bo_export_fd)         (tbm_bo bo);
252
253     /* Padding for future extension */
254     void (*reserved1)    (void);
255     void (*reserved2)    (void);
256     void (*reserved3)    (void);
257     void (*reserved4)    (void);
258     void (*reserved5)    (void);
259     void (*reserved6)    (void);
260 };
261
262 /**
263  * @brief tbm module information
264  *  data type for the module information
265  */
266 typedef struct
267 {
268     const char    *modname;        /**< name of module, e.g. "foo" */
269     const char    *vendor;         /**< vendor specific string */
270     unsigned long abiversion;      /**< ABI version */
271 } TBMModuleVersionInfo;
272
273 typedef int (*ModuleInitProc) (tbm_bufmgr, int);
274
275 #define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */
276
277 /**
278  * @brief tbm module data
279  *  data type for the entry point of the backend module
280  */
281 typedef struct
282 {
283     TBMModuleVersionInfo *vers; /**< tbm module informtaion */
284     ModuleInitProc init;        /**< init function of a backend module */
285 } TBMModuleData;
286
287 tbm_bufmgr_backend tbm_backend_alloc (void);
288 void                tbm_backend_free  (tbm_bufmgr_backend backend);
289 int                 tbm_backend_init  (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend);
290
291 void *tbm_backend_get_bufmgr_priv (tbm_bo bo);
292 void *tbm_backend_get_bo_priv     (tbm_bo bo);
293
294 #endif  /* _TBM_BUFMGR_BACKEND_H_ */