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 **************************************************************************/
32 #ifndef _TBM_BUFMGR_INT_H_
33 #define _TBM_BUFMGR_INT_H_
41 #include <sys/ioctl.h>
42 #include <sys/types.h>
51 #include <tbm_bufmgr.h>
53 #include <tbm_surface.h>
54 #include <tbm_surface_internal.h>
55 #include <tbm_bufmgr_backend.h>
56 #include <tbm_surface_queue.h>
60 extern tbm_bufmgr gBufMgr;
61 extern int b_dump_queue;
62 extern int trace_mask;
65 #define TBM_RETURN_IF_FAIL(cond) {\
67 TBM_ERR("'%s' failed.\n", #cond);\
71 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
73 TBM_ERR("'%s' failed.\n", #cond);\
77 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
79 TBM_ERR("'%s' failed.\n", #cond);\
85 #define RETURN_CHECK_FLAG(cond) {\
90 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
96 #define TBM_TRACE_BO(fmt, args...) \
98 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO) { \
100 clock_gettime(CLOCK_MONOTONIC, &ts); \
101 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
102 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
103 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
107 #define TBM_TRACE_SURFACE_INTERNAL(fmt, args...) \
109 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL) { \
110 struct timespec ts; \
111 clock_gettime(CLOCK_MONOTONIC, &ts); \
112 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
113 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
114 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
118 #define TBM_TRACE_SURFACE(fmt, args...) \
120 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE) { \
121 struct timespec ts; \
122 clock_gettime(CLOCK_MONOTONIC, &ts); \
123 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
124 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
125 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
129 #define TBM_TRACE_SURFACE_QUEUE(fmt, args...) \
131 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE) { \
132 struct timespec ts; \
133 clock_gettime(CLOCK_MONOTONIC, &ts); \
134 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
135 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
136 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
140 #define TBM_TRACE(fmt, args...) \
142 if (trace_mask&0x1) { \
143 struct timespec ts; \
144 clock_gettime(CLOCK_MONOTONIC, &ts); \
145 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
146 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
147 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
152 /* check validation */
153 #define TBM_BUFMGR_IS_VALID(mgr) (mgr && mgr == gBufMgr)
154 #define TBM_BO_IS_VALID(bo) (bo && \
155 TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
156 bo->item_link.next && \
157 bo->item_link.next->prev == &bo->item_link)
158 #define TBM_SURFACE_IS_VALID(surf) (surf && \
159 TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
160 surf->item_link.next && \
161 surf->item_link.next->prev == &surf->item_link)
164 #define TBM_SNRPRINTF(p, len, count, fmt, ARG...) \
167 int rest = len - count; \
168 int s = snprintf(&p[count], rest, fmt, ##ARG); \
169 while (s >= rest) { \
171 p = realloc(p, len); \
172 rest = len - count; \
173 s = snprintf(&p[count], rest, fmt, ##ARG); \
180 struct list_head *prev;
181 struct list_head *next;
185 * @brief tbm_bo : buffer object of Tizen Buffer Manager
188 tbm_bufmgr bufmgr; /* tbm buffer manager */
189 int ref_cnt; /* ref count of bo */
190 int flags; /* TBM_BO_FLAGS :bo memory type */
191 struct list_head user_data_list; /* list of the user_date in bo */
192 void *priv; /* bo private */
193 struct list_head item_link; /* link of bo */
194 tbm_surface_h surface; /* tbm_surface */
195 int lock_cnt; /* lock count of bo */
196 unsigned int map_cnt; /* device map count */
200 * @brief tbm_bufmgr : structure for tizen buffer manager
204 pthread_mutex_t lock; /* mutex lock */
205 int ref_count; /* reference count */
206 int fd; /* bufmgr fd */
207 tbm_bufmgr_bo_lock_type bo_lock_type; /* lock_type of bufmgr */
208 int capabilities; /* capabilities of bufmgr */
209 unsigned int bo_cnt; /* number of bos */
210 struct list_head bo_list; /* list of bos belonging to bufmgr */
211 struct list_head surf_list; /* list of surfaces belonging to bufmgr */
212 struct list_head surf_queue_list; /* list of surface queues belonging to bufmgr */
213 struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
215 tbm_bufmgr_backend backend; /* bufmgr backend */
216 int display_server; /* used by display server */
220 * @brief tbm_surface : structure for tizen buffer surface
223 struct _tbm_surface {
224 tbm_bufmgr bufmgr; /* tbm buffer manager */
226 tbm_surface_info_s info; /* tbm surface information */
230 int num_bos; /* the number of buffer objects */
234 int num_planes; /* the number of buffer objects */
236 int planes_bo_idx[TBM_SURF_PLANE_MAX];
240 unsigned int debug_pid;
242 struct list_head item_link; /* link of surface */
244 struct list_head user_data_list; /* list of the user_date in surface */
246 struct list_head debug_data_list; /* list of debug data */
252 tbm_data_free free_func;
254 /* link of user_data */
255 struct list_head item_link;
262 /* link of user_data */
263 struct list_head item_link;
264 } tbm_surface_debug_data;
266 tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
267 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
268 int _tbm_surface_is_valid(tbm_surface_h surface);
269 void _tbm_bo_free(tbm_bo bo);
271 /* functions for mutex */
272 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
273 tbm_surface_info_s *info, int map);
274 void tbm_surface_internal_unmap(tbm_surface_h surface);
275 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
276 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
277 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
278 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
279 char *_tbm_surface_internal_format_to_str(tbm_format format);
280 char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
282 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
284 tbm_user_data *user_data_create(unsigned long key,
285 tbm_data_free data_free_func);
286 void user_data_delete(tbm_user_data *user_data);
288 int tbm_bufmgr_get_fd_limit(void);
289 tbm_bufmgr tbm_bufmgr_get(void);
290 #endif /* _TBM_BUFMGR_INT_H_ */