1st implementation of tbm surface dump
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr_int.h
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
6
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>
9
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:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
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.
29
30 **************************************************************************/
31
32 #ifndef _TBM_BUFMGR_INT_H_
33 #define _TBM_BUFMGR_INT_H_
34
35 #include <unistd.h>
36 #include <limits.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <dlfcn.h>
44 #include <dirent.h>
45 #include <string.h>
46 #include <errno.h>
47 #include <pthread.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>
53
54 /* check condition */
55 #define TBM_RETURN_IF_FAIL(cond) {\
56         if (!(cond)) {\
57                 TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
58                 return;\
59         } \
60 }
61 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
62         if (!(cond)) {\
63                 TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
64                 return val;\
65         } \
66 }
67 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
68         if (!(cond)) {\
69                 TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
70                 goto val;\
71         } \
72 }
73
74 /* check flags */
75 #define RETURN_CHECK_FLAG(cond) {\
76         if ((cond)) {\
77                 return;\
78         } \
79 }
80 #define RETURN_VAL_CHECK_FLAG(cond, val) {\
81         if ((cond)) {\
82                 return val;\
83         } \
84 }
85
86 /* check validation */
87 #define TBM_BUFMGR_IS_VALID(mgr) (mgr)
88 #define TBM_BO_IS_VALID(bo) (bo && \
89                             TBM_BUFMGR_IS_VALID(bo->bufmgr) && \
90                             bo->item_link.next && \
91                             bo->item_link.next->prev == &bo->item_link)
92 #define TBM_SURFACE_IS_VALID(surf) (surf && \
93                                    TBM_BUFMGR_IS_VALID(surf->bufmgr) && \
94                                    surf->item_link.next && \
95                                    surf->item_link.next->prev == &surf->item_link)
96
97 #define TBM_DEBUG(fmt, ...)   fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
98 #define TBM_LOG(fmt, ...)  fprintf(stderr, "[TBM(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
99
100 struct list_head {
101         struct list_head *prev;
102         struct list_head *next;
103 };
104
105 /**
106  * @brief tbm_bo : buffer object of Tizen Buffer Manager
107  */
108 struct _tbm_bo {
109         tbm_bufmgr bufmgr;                      /* tbm buffer manager */
110
111         int ref_cnt;                            /* ref count of bo */
112
113         int flags;                                      /* TBM_BO_FLAGS :bo memory type */
114
115         struct list_head user_data_list;        /* list of the user_date in bo */
116
117         void *priv;                                     /* bo private */
118
119         struct list_head item_link;     /* link of bo */
120
121         tbm_surface_h surface; /* tbm_surface */
122
123         int lock_cnt;                           /* lock count of bo */
124
125         unsigned int map_cnt;           /* device map count */
126 };
127
128 /**
129  * @brief tbm_bufmgr : structure for tizen buffer manager
130  *
131  */
132 struct _tbm_bufmgr {
133         pthread_mutex_t lock;           /* mutex lock */
134
135         int ref_count;                          /*reference count */
136
137         int fd;                                         /* bufmgr fd */
138
139         int lock_type;                          /* lock_type of bufmgr */
140
141         struct list_head bo_list;       /* list of bos belonging to bufmgr */
142
143         struct list_head surf_list;     /* list of surfaces belonging to bufmgr */
144
145         void *module_data;
146
147         tbm_bufmgr_backend backend;     /* bufmgr backend */
148 };
149
150 /**
151  * @brief tbm_surface : structure for tizen buffer surface
152  *
153  */
154 struct _tbm_surface {
155         tbm_bufmgr bufmgr;                      /* tbm buffer manager */
156
157         tbm_surface_info_s info;        /* tbm surface information */
158
159         int flags;
160
161         int num_bos;                            /* the number of buffer objects */
162
163         tbm_bo bos[4];
164
165         int num_planes;                         /* the number of buffer objects */
166
167         int planes_bo_idx[TBM_SURF_PLANE_MAX];
168
169         int refcnt;
170
171         unsigned int debug_pid;
172
173         struct list_head item_link; /* link of surface */
174
175         struct list_head user_data_list;        /* list of the user_date in surface */
176 };
177
178 typedef struct {
179         unsigned long key;
180         void *data;
181         tbm_data_free free_func;
182
183         /* link of user_data */
184         struct list_head item_link;
185 } tbm_user_data;
186
187 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
188 int _tbm_surface_is_valid(tbm_surface_h surface);
189
190 /* functions for mutex */
191 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
192                                   tbm_surface_info_s *info, int map);
193 void tbm_surface_internal_unmap(tbm_surface_h surface);
194 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface);
195 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
196 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
197 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
198 char *_tbm_surface_internal_format_to_str(tbm_format format);
199
200 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
201                                 unsigned long key);
202 tbm_user_data *user_data_create(unsigned long key,
203                                 tbm_data_free data_free_func);
204 void user_data_delete(tbm_user_data *user_data);
205
206 #endif                                                  /* _TBM_BUFMGR_INT_H_ */