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>
52 #include <tbm_bufmgr.h>
54 #include <tbm_surface.h>
55 #include <tbm_surface_internal.h>
56 #include <tbm_surface_queue.h>
58 #include <tbm_bufmgr_backend.h>
59 #include <tbm_backend.h>
60 #include <tbm_error.h>
62 extern tbm_bufmgr gBufMgr;
63 extern int b_dump_queue;
64 extern int trace_mask;
66 #define C(b, m) (((b) >> (m)) & 0xFF)
67 #define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
68 #define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
69 #define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
70 #define FOURCC_ID(str) FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3])
73 #define RETURN_CHECK_FLAG(cond) {\
78 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
84 #define TBM_TRACE_BO(fmt, args...) \
86 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO) { \
88 clock_gettime(CLOCK_MONOTONIC, &ts); \
89 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
90 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
91 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
95 #define TBM_TRACE_SURFACE_INTERNAL(fmt, args...) \
97 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL) { \
99 clock_gettime(CLOCK_MONOTONIC, &ts); \
100 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
101 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
102 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
106 #define TBM_TRACE_SURFACE(fmt, args...) \
108 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE) { \
109 struct timespec ts; \
110 clock_gettime(CLOCK_MONOTONIC, &ts); \
111 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
112 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
113 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
117 #define TBM_TRACE_SURFACE_QUEUE(fmt, args...) \
119 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE) { \
120 struct timespec ts; \
121 clock_gettime(CLOCK_MONOTONIC, &ts); \
122 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
123 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
124 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
128 #define TBM_TRACE(fmt, args...) \
130 if (trace_mask&0x1) { \
131 struct timespec ts; \
132 clock_gettime(CLOCK_MONOTONIC, &ts); \
133 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
134 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
135 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
140 /* check validation */
141 #define TBM_BUFMGR_IS_VALID(mgr) (mgr && mgr == gBufMgr)
142 #define TBM_BO_IS_VALID(bo) (bo && \
143 TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
144 bo->item_link.next && \
145 bo->item_link.next->prev == &bo->item_link)
146 #define TBM_SURFACE_IS_VALID(surf) (surf && \
147 TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
148 surf->item_link.next && \
149 surf->item_link.next->prev == &surf->item_link)
152 #define TBM_SNRPRINTF(p, len, count, fmt, ARG...) \
155 int rest = len - count; \
156 int s = snprintf(&p[count], rest, fmt, ##ARG); \
157 while (s >= rest) { \
159 p = realloc(p, len); \
160 rest = len - count; \
161 s = snprintf(&p[count], rest, fmt, ##ARG); \
168 struct list_head *prev;
169 struct list_head *next;
173 * @brief tbm_bo : buffer object of Tizen Buffer Manager
176 unsigned int magic; /* tbm bo magic number */
177 tbm_bufmgr bufmgr; /* tbm buffer manager */
178 int ref_cnt; /* ref count of bo */
179 int flags; /* TBM_BO_FLAGS :bo memory type */
180 struct list_head user_data_list; /* list of the user_date in bo */
181 void *priv; /* bo private (will be DEPRECATED) */
182 struct list_head item_link; /* link of bo */
183 tbm_surface_h surface; /* tbm_surface */
184 int lock_cnt; /* lock count of bo */
185 unsigned int map_cnt; /* device map count */
187 tbm_backend_bo_data *bo_data; /* bo data of the backend module */
191 * @brief tbm_bufmgr : structure for tizen buffer manager
195 int ref_count; /* reference count */
196 int fd; /* bufmgr fd */
197 tbm_bufmgr_bo_lock_type bo_lock_type; /* lock_type of bufmgr */
198 int capabilities; /* capabilities of bufmgr */
199 int display_server; /* used by display server */
200 unsigned int bo_cnt; /* number of bos */
201 struct list_head bo_list; /* list of bos belonging to bufmgr */
202 struct list_head surf_list; /* list of surfaces belonging to bufmgr */
203 struct list_head surf_queue_list; /* list of surface queues belonging to bufmgr */
204 struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
206 void *module_data; /* backend module */
207 tbm_bufmgr_backend backend; /* bufmgr backend (will be DEPRECATED) */
209 tbm_backend_module *backend_module_data; /* backend module data */
210 tbm_backend_bufmgr_data *bufmgr_data; /* backend data of the backend module */
211 tbm_backend_bufmgr_func *bufmgr_func; /* backend functions for bufmgr */
212 tbm_backend_bo_func *bo_func; /* backend functions for bo */
216 * @brief tbm_surface : structure for tizen buffer surface
219 struct _tbm_surface {
220 unsigned int magic; /* tbm surface magic number */
222 tbm_bufmgr bufmgr; /* tbm buffer manager */
224 tbm_surface_info_s info; /* tbm surface information */
228 int num_bos; /* the number of buffer objects */
232 int num_planes; /* the number of buffer objects */
234 int planes_bo_idx[TBM_SURF_PLANE_MAX];
238 unsigned int debug_pid;
240 struct list_head item_link; /* link of surface */
242 struct list_head user_data_list; /* list of the user_date in surface */
244 struct list_head debug_data_list; /* list of debug data */
257 tbm_data_free free_func;
259 /* link of user_data */
260 struct list_head item_link;
267 /* link of user_data */
268 struct list_head item_link;
269 } tbm_surface_debug_data;
271 tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
272 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
273 int _tbm_surface_is_valid(tbm_surface_h surface);
274 void _tbm_bo_free(tbm_bo bo);
276 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
277 tbm_surface_info_s *info, int map);
278 void tbm_surface_internal_unmap(tbm_surface_h surface);
279 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
280 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
281 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
282 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
283 char *_tbm_surface_internal_format_to_str(tbm_format format);
284 char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
286 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
288 tbm_user_data *user_data_create(unsigned long key,
289 tbm_data_free data_free_func);
290 void user_data_delete(tbm_user_data *user_data);
292 int tbm_bufmgr_get_fd_limit(void);
293 tbm_bufmgr tbm_bufmgr_get(void);
295 void _tbm_set_last_result(tbm_error_e err);
297 /* functions for mutex */
298 void _tbm_bufmgr_mutex_lock(void);
299 void _tbm_bufmgr_mutex_unlock(void);
301 tbm_bo tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
302 int height, tbm_bo_memory_type flags, tbm_error_e *error);
303 tbm_bo tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
304 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error);
305 tbm_bo tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx);
307 #endif /* _TBM_BUFMGR_INT_H_ */