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>
54 #include <tbm_bufmgr.h>
56 #include <tbm_surface.h>
57 #include <tbm_surface_internal.h>
58 #include <tbm_surface_queue.h>
60 #include <tbm_error.h>
61 #include "tbm_module.h"
63 extern tbm_bufmgr gBufMgr;
64 extern int b_dump_queue;
65 extern int trace_mask;
67 #define TBM_BO_MAGIC 0xBF011234
69 #define C(b, m) (((b) >> (m)) & 0xFF)
70 #define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
71 #define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
72 #define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
73 #define FOURCC_ID(str) FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3])
76 #define RETURN_CHECK_FLAG(cond) {\
81 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
87 #define TBM_TRACE_BO(fmt, args...) \
89 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO) { \
91 clock_gettime(CLOCK_MONOTONIC, &ts); \
92 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
93 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
94 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
98 #define TBM_TRACE_SURFACE_INTERNAL(fmt, args...) \
100 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL) { \
101 struct timespec ts; \
102 clock_gettime(CLOCK_MONOTONIC, &ts); \
103 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
104 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
105 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
109 #define TBM_TRACE_SURFACE(fmt, args...) \
111 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE) { \
112 struct timespec ts; \
113 clock_gettime(CLOCK_MONOTONIC, &ts); \
114 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
115 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
116 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
120 #define TBM_TRACE_SURFACE_QUEUE(fmt, args...) \
122 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE) { \
123 struct timespec ts; \
124 clock_gettime(CLOCK_MONOTONIC, &ts); \
125 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
126 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
127 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
131 #define TBM_TRACE(fmt, args...) \
133 if (trace_mask&0x1) { \
134 struct timespec ts; \
135 clock_gettime(CLOCK_MONOTONIC, &ts); \
136 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d](TRACE)"fmt, \
137 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
138 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
143 /* check validation */
144 #define TBM_BUFMGR_IS_VALID(mgr) (mgr && mgr == gBufMgr)
145 #define TBM_BO_IS_VALID(bo) (bo && \
146 TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
147 bo->item_link.next && \
148 bo->item_link.next->prev == &bo->item_link)
149 #define TBM_SURFACE_IS_VALID(surf) (surf && \
150 TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
151 surf->item_link.next && \
152 surf->item_link.next->prev == &surf->item_link)
155 #define TBM_SNRPRINTF(p, len, count, fmt, ARG...) \
158 int rest = len - count; \
159 int s = snprintf(&p[count], rest, fmt, ##ARG); \
160 while (s >= rest) { \
162 p = realloc(p, len); \
163 rest = len - count; \
164 s = snprintf(&p[count], rest, fmt, ##ARG); \
171 struct list_head *prev;
172 struct list_head *next;
176 * @brief tbm_bo : buffer object of Tizen Buffer Manager
179 unsigned int magic; /* tbm bo magic number */
180 tbm_bufmgr bufmgr; /* tbm buffer manager */
181 int ref_cnt; /* ref count of bo */
182 int flags; /* TBM_BO_FLAGS :bo memory type */
183 struct list_head user_data_list; /* list of the user_date in bo */
184 struct list_head item_link; /* link of bo */
185 tbm_surface_h surface; /* tbm_surface */
186 int lock_cnt; /* lock count of bo */
187 unsigned int map_cnt; /* device map count */
189 tbm_bo_data *bo_data; /* bo data of the module */
190 int get_from_surface_data; /* bo_data has be detroyed by surface_data */
194 * @brief tbm_bufmgr : structure for tizen buffer manager
198 int ref_count; /* reference count */
199 int fd; /* bufmgr fd */
200 tbm_bufmgr_bo_lock_type bo_lock_type; /* lock_type of bufmgr */
201 int capabilities; /* capabilities of bufmgr */
202 int display_server; /* used by display server */
203 unsigned int bo_cnt; /* number of bos */
204 struct list_head bo_list; /* list of bos belonging to bufmgr */
205 struct list_head surf_list; /* list of surfaces belonging to bufmgr */
206 struct list_head surf_queue_list; /* list of surface queues belonging to bufmgr */
207 struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
209 tbm_module *module; /* tbm module information */
213 * @brief tbm_surface : structure for tizen buffer surface
216 struct _tbm_surface {
217 unsigned int magic; /* tbm surface magic number */
219 tbm_bufmgr bufmgr; /* tbm buffer manager */
221 tbm_surface_info_s info; /* tbm surface information */
225 int num_bos; /* the number of buffer objects */
229 int num_planes; /* the number of buffer objects */
231 int planes_bo_idx[TBM_SURF_PLANE_MAX];
235 unsigned int debug_pid;
237 struct list_head item_link; /* link of surface */
239 struct list_head user_data_list; /* list of the user_data in surface */
241 struct list_head debug_data_list; /* list of debug data */
243 struct list_head destroy_funcs; /* list of destory callback function */
252 tbm_surface_data *surface_data; /* surface data of the module */
258 tbm_data_free free_func;
260 /* link of user_data */
261 struct list_head item_link;
268 /* link of user_data */
269 struct list_head item_link;
270 } tbm_surface_debug_data;
272 typedef struct _tbm_surface_destroy_func_info {
273 tbm_surface_internal_destroy_handler destroy_func;
276 struct list_head item_link;
277 } tbm_surface_destroy_func_info;
279 tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
280 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
281 int _tbm_surface_is_valid(tbm_surface_h surface);
282 void _tbm_bo_free(tbm_bo bo);
284 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
285 tbm_surface_info_s *info, int map);
286 void tbm_surface_internal_unmap(tbm_surface_h surface);
287 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
288 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
289 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
290 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
291 char *_tbm_surface_internal_format_to_str(tbm_format format);
292 char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
294 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
296 tbm_user_data *user_data_create(unsigned long key,
297 tbm_data_free data_free_func);
298 void user_data_delete(tbm_user_data *user_data);
300 int tbm_bufmgr_get_fd_limit(void);
301 tbm_bufmgr tbm_bufmgr_get(void);
303 void _tbm_set_last_result(tbm_error_e err);
305 char *_tbm_flag_to_str(int f);
307 /* functions for mutex */
308 void _tbm_bufmgr_mutex_lock(void);
309 void _tbm_bufmgr_mutex_unlock(void);
310 tbm_bo tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo);
312 tbm_bo tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags);
313 tbm_bo tbm_bufmgr_internal_alloc_bo_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width, int bpp, int height, tbm_bo_memory_type flags, tbm_error_e *error);
314 tbm_bo tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_data, int flags, tbm_error_e *error);
315 tbm_bo tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, tbm_key key);
316 tbm_bo tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd);
317 int tbm_bufmgr_internal_support_capabilites(tbm_bufmgr bufmgr, int capabilities);
319 #endif /* _TBM_BUFMGR_INT_H_ */