1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
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>
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:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
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.
30 **************************************************************************/
33 * This file is referenced by the xf86Module.h in xorg server.
36 #ifndef _TBM_BUFMGR_BACKEND_H_
37 #define _TBM_BUFMGR_BACKEND_H_
39 #include <tbm_bufmgr.h>
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.
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)
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
62 #define SET_ABI_VERSION(maj, min) \
63 ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK))
65 #define TBM_ABI_VERSION SET_ABI_VERSION(1, 1) /**< current abi vertion */
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 */
74 /* TBM flag for cache control and lock control */
76 * TBM_CACHE_CTRL_BACKEND indicates that the backend control the cache coherency.
78 #define TBM_CACHE_CTRL_BACKEND (1 << 0)
81 * TBM_LOCK_CTRL_BACKEND indicates that the backend control the lock of bos.
83 #define TBM_LOCK_CTRL_BACKEND (1 << 1)
85 typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend;
88 * @brief TBM backend functions
89 * the set of function pointers for the backend module of TBM.
91 struct _tbm_bufmgr_backend
95 void *priv; /**< bufmgr private */
98 * @brief deinitialize the bufmgr private.
99 * @param[in] bufmgr : the private of the bufmgr
100 * @return 1 if this function succeeds, otherwise 0.
102 void (*bufmgr_deinit) (void *priv);
105 * @brief get the size of a bo.
106 * @param[in] bo : the buffer object
107 * @return 1 if this function succeeds, otherwise 0.
109 int (*bo_size) (tbm_bo bo);
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.
118 void * (*bo_alloc) (tbm_bo bo, int size, int flags);
121 * @brief free the buffer object.
122 * @param[in] bo : the buffer object
124 void (*bo_free) (tbm_bo bo);
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.
132 void * (*bo_import) (tbm_bo bo, unsigned int key);
135 * @brief export the buffer object
136 * @param[in] bo : the buffer object
137 * @return key associated with the buffer object
139 unsigned int (*bo_export) (tbm_bo bo);
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
147 tbm_bo_handle (*bo_get_handle) (tbm_bo bo, int device);
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
156 tbm_bo_handle (*bo_map) (tbm_bo bo, int device, int opt);
159 * @brief unmap the buffer object.
160 * @param[in] bo : the buffer object
161 * @return 1 if this function succeeds, otherwise 0.
163 int (*bo_unmap) (tbm_bo bo);
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.
171 int (*bo_cache_flush) (tbm_bo bo, int flags);
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.
178 int (*bo_get_global_key) (tbm_bo bo);
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)
186 int (*bo_lock) (tbm_bo bo);
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)
194 int (*bo_unlock) (tbm_bo bo);
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)
204 int (*bo_lock2) (tbm_bo bo, int device, int opt);
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.
212 int (*surface_supported_format) (uint32_t **formats, uint32_t *num);
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.
222 int (*surface_get_size) (tbm_surface_h surface, int width, int height, tbm_format format);
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.
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);
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.
244 void * (*bo_import_fd) (tbm_bo bo, tbm_fd fd);
247 * @brief export the buffer object
248 * @param[in] bo : the buffer object
249 * @return tbm_fd associated with the buffer object
251 tbm_fd (*bo_export_fd) (tbm_bo bo);
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);
263 * @brief tbm module information
264 * data type for the module information
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;
273 typedef int (*ModuleInitProc) (tbm_bufmgr, int);
275 #define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */
278 * @brief tbm module data
279 * data type for the entry point of the backend module
283 TBMModuleVersionInfo *vers; /**< tbm module informtaion */
284 ModuleInitProc init; /**< init function of a backend module */
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);
291 void *tbm_backend_get_bufmgr_priv (tbm_bo bo);
292 void *tbm_backend_get_bo_priv (tbm_bo bo);
294 #endif /* _TBM_BUFMGR_BACKEND_H_ */