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>
55 #define TBM_RETURN_IF_FAIL(cond) {\
57 TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
61 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
63 TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
69 #define RETURN_CHECK_FLAG(cond) {\
74 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
80 /* check validation */
81 #define TBM_BUFMGR_IS_VALID(mgr) (mgr)
82 #define TBM_BO_IS_VALID(bo) (bo && \
83 TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
84 bo->item_link.next && \
85 bo->item_link.next->prev == &bo->item_link)
86 #define TBM_SURFACE_IS_VALID(surf) (surf && \
87 TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
88 surf->item_link.next && \
89 surf->item_link.next->prev == &surf->item_link)
91 #define TBM_DEBUG(fmt, ...) fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
92 #define TBM_LOG(fmt, ...) fprintf(stderr, "[TBM(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
95 struct list_head *prev;
96 struct list_head *next;
99 /* unneeded version 2.0 */
100 #define TBM_ALL_CTRL_BACKEND_VALID(flags) \
101 ((flags&TBM_CACHE_CTRL_BACKEND) &&\
102 (flags&TBM_LOCK_CTRL_BACKEND))
103 #define TBM_CACHE_CTRL_BACKEND_VALID(flags) \
104 (flags&TBM_CACHE_CTRL_BACKEND)
105 #define TBM_LOCK_CTRL_BACKEND_VALID(flags) \
106 (flags&TBM_LOCK_CTRL_BACKEND)
108 typedef union _tbm_bo_cache_state tbm_bo_cache_state;
110 union _tbm_bo_cache_state {
113 unsigned int cntFlush: 16; /*Flush all index for sync */
114 unsigned int isCacheable: 1;
115 unsigned int isCached: 1;
116 unsigned int isDirtied: 2;
119 /* unneeded version 2.0 */
122 * @brief tbm_bo : buffer object of Tizen Buffer Manager
125 tbm_bufmgr bufmgr; /* tbm buffer manager */
127 int ref_cnt; /* ref count of bo */
129 int flags; /* TBM_BO_FLAGS :bo memory type */
131 struct list_head user_data_list; /* list of the user_date in bo */
133 void *priv; /* bo private */
135 struct list_head item_link; /* link of bo */
137 tbm_surface_h surface; /* tbm_surface */
139 int lock_cnt; /* lock count of bo */
141 unsigned int map_cnt; /* device map count */
143 /* unneeded version 2.0 */
144 tbm_bo_handle default_handle; /*default handle */
146 unsigned int tgl_key; /*global key for tizen global lock */
148 /* for cache control */
149 tbm_bo_cache_state cache_state; /*cache state */
150 /* unneeded version 2.0 */
154 * @brief tbm_bufmgr : structure for tizen buffer manager
158 pthread_mutex_t lock; /* mutex lock */
160 int ref_count; /*reference count */
162 int fd; /* bufmgr fd */
164 int lock_type; /* lock_type of bufmgr */
166 struct list_head bo_list; /* list of bos belonging to bufmgr */
168 struct list_head surf_list; /* list of surfaces belonging to bufmgr */
172 tbm_bufmgr_backend backend; /* bufmgr backend */
176 /* unneeded version 2.0 */
177 int lock_fd; /* fd of tizen global lock */
179 int fd_flag; /* flag set 1 when bufmgr fd open in tbm_bufmgr_init */
181 int use_map_cache; /* flag to use the map_cahce */
182 /* unneeded version 2.0 */
186 * @brief tbm_surface : structure for tizen buffer surface
189 struct _tbm_surface {
190 tbm_bufmgr bufmgr; /* tbm buffer manager */
192 tbm_surface_info_s info; /* tbm surface information */
196 int num_bos; /* the number of buffer objects */
200 int num_planes; /* the number of buffer objects */
202 int planes_bo_idx[TBM_SURF_PLANE_MAX];
206 unsigned int debug_pid;
208 struct list_head item_link; /* link of surface */
210 struct list_head user_data_list; /* list of the user_date in surface */
216 tbm_data_free free_func;
218 /* link of user_data */
219 struct list_head item_link;
222 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
224 /* functions for mutex */
225 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
226 tbm_surface_info_s *info, int map);
227 void tbm_surface_internal_unmap(tbm_surface_h surface);
228 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
229 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
230 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
231 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
232 char *_tbm_surface_internal_format_to_str(tbm_format format);
234 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
236 tbm_user_data *user_data_create(unsigned long key,
237 tbm_data_free data_free_func);
238 void user_data_delete(tbm_user_data *user_data);
240 #endif /* _TBM_BUFMGR_INT_H_ */