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_
39 #include <sys/ioctl.h>
40 #include <sys/types.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>
58 #define DBG(...) { if (bDebug&0x1) TBM_LOG_D(__VA_ARGS__); }
59 #define DBG_LOCK(...) { if (bDebug&0x2) TBM_LOG_D(__VA_ARGS__); }
76 #define TBM_LOG_D(fmt, ...) {\
78 LOGD("[TBM:D] " fmt, ##__VA_ARGS__);\
81 fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
85 #define TBM_LOG_I(fmt, ...) {\
87 LOGD("[TBM:I] " fmt, ##__VA_ARGS__);\
90 fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
94 #define TBM_LOG_W(fmt, ...) {\
96 LOGW("[TBM:W] " fmt, ##__VA_ARGS__);\
99 fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
103 #define TBM_LOG_E(fmt, ...) {\
105 LOGE("[TBM:E] " fmt, ##__VA_ARGS__);\
108 fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
112 #define TBM_DEBUG(fmt, ...) {\
114 LOGD("[TBM_DEBUG] " fmt, ##__VA_ARGS__);\
117 fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__);\
121 #define TBM_LOG_D(fmt, ...) fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
122 #define TBM_LOG_I(fmt, ...) fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
123 #define TBM_LOG_W(fmt, ...) fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
124 #define TBM_LOG_E(fmt, ...) fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
125 #define TBM_DEBUG(fmt, ...) fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
126 #endif /* HAVE_DLOG */
128 /* check condition */
129 #define TBM_RETURN_IF_FAIL(cond) {\
131 TBM_LOG_E("'%s' failed.\n", #cond);\
135 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
137 TBM_LOG_E("'%s' failed.\n", #cond);\
141 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
143 TBM_LOG_E("'%s' failed.\n", #cond);\
149 #define RETURN_CHECK_FLAG(cond) {\
154 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
160 /* check validation */
161 #define TBM_BUFMGR_IS_VALID(mgr) (mgr)
162 #define TBM_BO_IS_VALID(bo) (bo && \
163 TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
164 bo->item_link.next && \
165 bo->item_link.next->prev == &bo->item_link)
166 #define TBM_SURFACE_IS_VALID(surf) (surf && \
167 TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
168 surf->item_link.next && \
169 surf->item_link.next->prev == &surf->item_link)
172 struct list_head *prev;
173 struct list_head *next;
177 * @brief tbm_bo : buffer object of Tizen Buffer Manager
180 tbm_bufmgr bufmgr; /* tbm buffer manager */
182 int ref_cnt; /* ref count of bo */
184 int flags; /* TBM_BO_FLAGS :bo memory type */
186 struct list_head user_data_list; /* list of the user_date in bo */
188 void *priv; /* bo private */
190 struct list_head item_link; /* link of bo */
192 tbm_surface_h surface; /* tbm_surface */
194 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 */
206 int ref_count; /*reference count */
208 int fd; /* bufmgr fd */
210 int lock_type; /* lock_type of bufmgr */
212 struct list_head bo_list; /* list of bos belonging to bufmgr */
214 struct list_head surf_list; /* list of surfaces belonging to bufmgr */
218 tbm_bufmgr_backend backend; /* bufmgr backend */
222 * @brief tbm_surface : structure for tizen buffer surface
225 struct _tbm_surface {
226 tbm_bufmgr bufmgr; /* tbm buffer manager */
228 tbm_surface_info_s info; /* tbm surface information */
232 int num_bos; /* the number of buffer objects */
236 int num_planes; /* the number of buffer objects */
238 int planes_bo_idx[TBM_SURF_PLANE_MAX];
242 unsigned int debug_pid;
244 struct list_head item_link; /* link of surface */
246 struct list_head user_data_list; /* list of the user_date in surface */
252 tbm_data_free free_func;
254 /* link of user_data */
255 struct list_head item_link;
258 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
259 int _tbm_surface_is_valid(tbm_surface_h surface);
261 /* functions for mutex */
262 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
263 tbm_surface_info_s *info, int map);
264 void tbm_surface_internal_unmap(tbm_surface_h surface);
265 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
266 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
267 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
268 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
269 char *_tbm_surface_internal_format_to_str(tbm_format format);
271 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
273 tbm_user_data *user_data_create(unsigned long key,
274 tbm_data_free data_free_func);
275 void user_data_delete(tbm_user_data *user_data);
277 #endif /* _TBM_BUFMGR_INT_H_ */