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