add the api functions (dump_all and queue_dump) for the debugging
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr_int.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 #ifndef _TBM_BUFMGR_INT_H_
33 #define _TBM_BUFMGR_INT_H_
34
35 #include <unistd.h>
36 #include <limits.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <dlfcn.h>
44 #include <dirent.h>
45 #include <string.h>
46 #include <errno.h>
47 #include <pthread.h>
48 #include <tbm_bufmgr.h>
49 #include <tbm_surface.h>
50 #include <tbm_surface_internal.h>
51 #include <tbm_bufmgr_backend.h>
52 #include <tbm_surface_queue.h>
53
54 #define DEBUG
55 #ifdef DEBUG
56 extern int bDebug;
57
58 #define DBG(...) { if (bDebug&0x1) TBM_LOG_D(__VA_ARGS__); }
59 #define DBG_LOCK(...) { if (bDebug&0x2) TBM_LOG_D(__VA_ARGS__); }
60 #else
61 #define DBG(...)
62 #define DBG_LOCK(...)
63 #endif /* DEBUG */
64
65 #define TRACE
66 #ifdef TRACE
67 extern int bTrace;
68 #endif /* TRACE */
69
70 extern int b_dump_queue;
71
72 #ifdef HAVE_DLOG
73 #include <dlog.h>
74
75 extern int bDlog;
76
77 #ifdef LOG_TAG
78 #undef LOG_TAG
79 #endif
80
81 #define LOG_TAG "TBM"
82
83 #define TBM_LOG_D(fmt, ...) {\
84         if (bDlog) {\
85                 LOGD("[TBM:D] " fmt, ##__VA_ARGS__);\
86         } \
87         else {\
88                 fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
89         } \
90 }
91
92 #define TBM_LOG_I(fmt, ...) {\
93         if (bDlog) {\
94                 LOGD("[TBM:I] " fmt, ##__VA_ARGS__);\
95         } \
96         else {\
97                 fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
98         } \
99 }
100
101 #define TBM_LOG_W(fmt, ...) {\
102         if (bDlog) {\
103                 LOGW("[TBM:W] " fmt, ##__VA_ARGS__);\
104         } \
105         else {\
106                 fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
107         } \
108 }
109
110 #define TBM_LOG_E(fmt, ...) {\
111         if (bDlog) {\
112                 LOGE("[TBM:E] " fmt, ##__VA_ARGS__);\
113         } \
114         else {\
115                 fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
116         } \
117 }
118
119 #define TBM_DEBUG(fmt, ...) {\
120         if (bDlog) {\
121                 LOGE("[TBM_DEBUG] " fmt, ##__VA_ARGS__);\
122         } \
123         else {\
124                 fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__);\
125         } \
126 }
127
128 #ifdef TRACE
129 #define TBM_TRACE(fmt, ...) {\
130         if (bDlog) {\
131                 if (bTrace&0x1) LOGE("[TBM:TRACE] " fmt, ##__VA_ARGS__);\
132         } \
133         else {\
134                 if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
135         } \
136 }
137 #else
138 #define TBM_TRACE(fmt, ...)
139 #endif /* TRACE */
140
141 #else
142 #define TBM_LOG_D(fmt, ...)   fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
143 #define TBM_LOG_I(fmt, ...)   fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
144 #define TBM_LOG_W(fmt, ...)   fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
145 #define TBM_LOG_E(fmt, ...)   fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
146 #define TBM_DEBUG(fmt, ...)   fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
147 #ifdef TRACE
148 #define TBM_TRACE(fmt, ...)   { if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__); }
149 #else
150 #define TBM_TRACE(fmt, ...)
151 #endif /* TRACE */
152 #endif /* HAVE_DLOG */
153
154 /* check condition */
155 #define TBM_RETURN_IF_FAIL(cond) {\
156         if (!(cond)) {\
157                 TBM_LOG_E("'%s' failed.\n", #cond);\
158                 return;\
159         } \
160 }
161 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
162         if (!(cond)) {\
163                 TBM_LOG_E("'%s' failed.\n", #cond);\
164                 return val;\
165         } \
166 }
167 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
168         if (!(cond)) {\
169                 TBM_LOG_E("'%s' failed.\n", #cond);\
170                 goto val;\
171         } \
172 }
173
174 /* check flags */
175 #define RETURN_CHECK_FLAG(cond) {\
176         if ((cond)) {\
177                 return;\
178         } \
179 }
180 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
181         if ((cond)) {\
182                 return val;\
183         } \
184 }
185
186 /* check validation */
187 #define TBM_BUFMGR_IS_VALID(mgr) (mgr)
188 #define TBM_BO_IS_VALID(bo) (bo && \
189                             TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
190                             bo->item_link.next && \
191                             bo->item_link.next->prev == &bo->item_link)
192 #define TBM_SURFACE_IS_VALID(surf) (surf && \
193                                    TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
194                                    surf->item_link.next && \
195                                    surf->item_link.next->prev == &surf->item_link)
196
197 struct list_head {
198         struct list_head *prev;
199         struct list_head *next;
200 };
201
202 /**
203  * @brief tbm_bo : buffer object of Tizen Buffer Manager
204  */
205 struct _tbm_bo {
206         tbm_bufmgr bufmgr;                      /* tbm buffer manager */
207
208         int ref_cnt;                            /* ref count of bo */
209
210         int flags;                                      /* TBM_BO_FLAGS :bo memory type */
211
212         struct list_head user_data_list;        /* list of the user_date in bo */
213
214         void *priv;                                     /* bo private */
215
216         struct list_head item_link;     /* link of bo */
217
218         tbm_surface_h surface; /* tbm_surface */
219
220         int lock_cnt;                           /* lock count of bo */
221
222         unsigned int map_cnt;           /* device map count */
223 };
224
225 /**
226  * @brief tbm_bufmgr : structure for tizen buffer manager
227  *
228  */
229 struct _tbm_bufmgr {
230         pthread_mutex_t lock;           /* mutex lock */
231
232         int ref_count;                          /*reference count */
233
234         int fd;                                         /* bufmgr fd */
235
236         int lock_type;                          /* lock_type of bufmgr */
237
238         int capabilities;           /* capabilities of bufmgr */
239
240         unsigned int bo_cnt;        /* number of bos */
241
242         struct list_head bo_list;       /* list of bos belonging to bufmgr */
243
244         struct list_head surf_list;     /* list of surfaces belonging to bufmgr */
245
246         struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
247
248         void *module_data;
249
250         tbm_bufmgr_backend backend;     /* bufmgr backend */
251 };
252
253 /**
254  * @brief tbm_surface : structure for tizen buffer surface
255  *
256  */
257 struct _tbm_surface {
258         tbm_bufmgr bufmgr;                      /* tbm buffer manager */
259
260         tbm_surface_info_s info;        /* tbm surface information */
261
262         int flags;
263
264         int num_bos;                            /* the number of buffer objects */
265
266         tbm_bo bos[4];
267
268         int num_planes;                         /* the number of buffer objects */
269
270         int planes_bo_idx[TBM_SURF_PLANE_MAX];
271
272         int refcnt;
273
274         unsigned int debug_pid;
275
276         struct list_head item_link; /* link of surface */
277
278         struct list_head user_data_list;        /* list of the user_date in surface */
279
280         struct list_head debug_data_list;       /* list of debug data */
281 };
282
283 typedef struct {
284         unsigned long key;
285         void *data;
286         tbm_data_free free_func;
287
288         /* link of user_data */
289         struct list_head item_link;
290 } tbm_user_data;
291
292 typedef struct {
293         char *key;
294         char *value;
295
296         /* link of user_data */
297         struct list_head item_link;
298 } tbm_surface_debug_data;
299
300 tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
301 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
302 int _tbm_surface_is_valid(tbm_surface_h surface);
303
304 /* functions for mutex */
305 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
306                                   tbm_surface_info_s *info, int map);
307 void tbm_surface_internal_unmap(tbm_surface_h surface);
308 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
309 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
310 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
311 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
312 char *_tbm_surface_internal_format_to_str(tbm_format format);
313 char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
314
315 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
316                                 unsigned long key);
317 tbm_user_data *user_data_create(unsigned long key,
318                                 tbm_data_free data_free_func);
319 void user_data_delete(tbm_user_data *user_data);
320
321 #endif                                                  /* _TBM_BUFMGR_INT_H_ */