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>
50 #include <tbm_bufmgr.h>
51 #include <tbm_surface.h>
52 #include <tbm_surface_internal.h>
53 #include <tbm_bufmgr_backend.h>
54 #include <tbm_surface_queue.h>
60 #define TBM_DBG(...) { if (bDebug&0x1) TBM_LOG_D(__VA_ARGS__); }
61 #define TBM_DBG_LOCK(...) { if (bDebug&0x2) TBM_LOG_D(__VA_ARGS__); }
64 #define TBM_DBG_LOCK(...)
72 extern int b_dump_queue;
85 #define TBM_LOG_D(fmt, ...) {\
87 LOGD("[TBM:D] " fmt, ##__VA_ARGS__);\
90 fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
94 #define TBM_LOG_I(fmt, ...) {\
96 LOGI("[TBM:I] " fmt, ##__VA_ARGS__);\
99 fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
103 #define TBM_LOG_W(fmt, ...) {\
105 LOGW("[TBM:W] " fmt, ##__VA_ARGS__);\
108 fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
112 #define TBM_LOG_E(fmt, ...) {\
114 LOGE("[TBM:E] " fmt, ##__VA_ARGS__);\
117 fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
121 #define TBM_DEBUG(fmt, ...) {\
123 LOGE("[TBM_DEBUG] " fmt, ##__VA_ARGS__);\
126 fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__);\
131 #define TBM_TRACE(fmt, ...) {\
133 if (bTrace&0x1) LOGE("[TBM:TRACE] " fmt, ##__VA_ARGS__);\
136 if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
140 #define TBM_TRACE(fmt, ...)
144 #define TBM_LOG_D(fmt, ...) fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
145 #define TBM_LOG_I(fmt, ...) fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
146 #define TBM_LOG_W(fmt, ...) fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
147 #define TBM_LOG_E(fmt, ...) fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
148 #define TBM_DEBUG(fmt, ...) fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
150 #define TBM_TRACE(fmt, ...) { if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__); }
152 #define TBM_TRACE(fmt, ...)
154 #endif /* HAVE_DLOG */
156 /* check condition */
157 #define TBM_RETURN_IF_FAIL(cond) {\
159 TBM_LOG_E("'%s' failed.\n", #cond);\
163 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
165 TBM_LOG_E("'%s' failed.\n", #cond);\
169 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
171 TBM_LOG_E("'%s' failed.\n", #cond);\
177 #define RETURN_CHECK_FLAG(cond) {\
182 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
188 /* check validation */
189 #define TBM_BUFMGR_IS_VALID(mgr) (mgr)
190 #define TBM_BO_IS_VALID(bo) (bo && \
191 TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
192 bo->item_link.next && \
193 bo->item_link.next->prev == &bo->item_link)
194 #define TBM_SURFACE_IS_VALID(surf) (surf && \
195 TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
196 surf->item_link.next && \
197 surf->item_link.next->prev == &surf->item_link)
200 struct list_head *prev;
201 struct list_head *next;
205 * @brief tbm_bo : buffer object of Tizen Buffer Manager
208 tbm_bufmgr bufmgr; /* tbm buffer manager */
210 int ref_cnt; /* ref count of bo */
212 int flags; /* TBM_BO_FLAGS :bo memory type */
214 struct list_head user_data_list; /* list of the user_date in bo */
216 void *priv; /* bo private */
218 struct list_head item_link; /* link of bo */
220 tbm_surface_h surface; /* tbm_surface */
222 int lock_cnt; /* lock count of bo */
224 unsigned int map_cnt; /* device map count */
228 * @brief tbm_bufmgr : structure for tizen buffer manager
232 pthread_mutex_t lock; /* mutex lock */
234 int ref_count; /*reference count */
236 int fd; /* bufmgr fd */
238 int lock_type; /* lock_type of bufmgr */
240 int capabilities; /* capabilities of bufmgr */
242 unsigned int bo_cnt; /* number of bos */
244 struct list_head bo_list; /* list of bos belonging to bufmgr */
246 struct list_head surf_list; /* list of surfaces belonging to bufmgr */
248 struct list_head surf_queue_list; /* list of surface queues belonging to bufmgr */
250 struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
254 tbm_bufmgr_backend backend; /* bufmgr backend */
258 * @brief tbm_surface : structure for tizen buffer surface
261 struct _tbm_surface {
262 tbm_bufmgr bufmgr; /* tbm buffer manager */
264 tbm_surface_info_s info; /* tbm surface information */
268 int num_bos; /* the number of buffer objects */
272 int num_planes; /* the number of buffer objects */
274 int planes_bo_idx[TBM_SURF_PLANE_MAX];
278 unsigned int debug_pid;
280 struct list_head item_link; /* link of surface */
282 struct list_head user_data_list; /* list of the user_date in surface */
284 struct list_head debug_data_list; /* list of debug data */
290 tbm_data_free free_func;
292 /* link of user_data */
293 struct list_head item_link;
300 /* link of user_data */
301 struct list_head item_link;
302 } tbm_surface_debug_data;
304 tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
305 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
306 int _tbm_surface_is_valid(tbm_surface_h surface);
308 /* functions for mutex */
309 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
310 tbm_surface_info_s *info, int map);
311 void tbm_surface_internal_unmap(tbm_surface_h surface);
312 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
313 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
314 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
315 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
316 char *_tbm_surface_internal_format_to_str(tbm_format format);
317 char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
319 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
321 tbm_user_data *user_data_create(unsigned long key,
322 tbm_data_free data_free_func);
323 void user_data_delete(tbm_user_data *user_data);
325 #endif /* _TBM_BUFMGR_INT_H_ */