bd670622e900a75ff3c6e5483074cc09513bd151
[platform/core/uifw/libtdm.git] / src / tdm_private.h
1 /**************************************************************************
2
3 libtdm
4
5 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8          JinYoung Jeon <jy0.jeon@samsung.com>,
9          Taeheon Kim <th908.kim@samsung.com>,
10          YoungJun Cho <yj44.cho@samsung.com>,
11          SooChan Lim <sc1.lim@samsung.com>,
12          Boram Park <sc1.lim@samsung.com>
13
14 Permission is hereby granted, free of charge, to any person obtaining a
15 copy of this software and associated documentation files (the
16 "Software"), to deal in the Software without restriction, including
17 without limitation the rights to use, copy, modify, merge, publish,
18 distribute, sub license, and/or sell copies of the Software, and to
19 permit persons to whom the Software is furnished to do so, subject to
20 the following conditions:
21
22 The above copyright notice and this permission notice (including the
23 next paragraph) shall be included in all copies or substantial portions
24 of the Software.
25
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
34 **************************************************************************/
35
36 #ifndef _TDM_PRIVATE_H_
37 #define _TDM_PRIVATE_H_
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <pthread.h>
43 #include <errno.h>
44 #include <unistd.h>
45 #include <limits.h>
46 #include <sys/types.h>
47 #include <sys/stat.h>
48 #include <fcntl.h>
49 #include <dlfcn.h>
50 #include <dirent.h>
51
52 #include "tdm_backend.h"
53 #include "tdm_log.h"
54 #include "tdm_list.h"
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 #undef EXTERN
61 #undef DEPRECATED
62 #undef INTERN
63
64 #if defined(__GNUC__) && __GNUC__ >= 4
65 #define EXTERN __attribute__ ((visibility("default")))
66 #else
67 #define EXTERN
68 #endif
69
70 #if defined(__GNUC__) && __GNUC__ >= 4
71 #define INTERN __attribute__ ((visibility("hidden")))
72 #else
73 #define INTERN
74 #endif
75
76 #if defined(__GNUC__) && __GNUC__ >= 4
77 #define DEPRECATED __attribute__ ((deprecated))
78 #else
79 #define DEPRECATED
80 #endif
81
82 /* check condition */
83 #define TDM_RETURN_IF_FAIL(cond) {\
84     if (!(cond)) {\
85         TDM_ERR ("'%s' failed", #cond);\
86         return;\
87     }\
88 }
89 #define TDM_RETURN_VAL_IF_FAIL(cond, val) {\
90     if (!(cond)) {\
91         TDM_ERR ("'%s' failed", #cond);\
92         return val;\
93     }\
94 }
95 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) {\
96     if (!(cond)) {\
97         TDM_ERR ("'%s' failed", #cond);\
98         ret = error_v;\
99         if (error) *error = ret;\
100         return val;\
101     }\
102 }
103
104 #define TDM_WARNING_IF_FAIL(cond)  {\
105     if (!(cond))\
106         TDM_ERR ("'%s' failed", #cond);\
107 }
108 #define TDM_GOTO_IF_FAIL(cond, dst) {\
109     if (!(cond)) {\
110         TDM_ERR ("'%s' failed", #cond);\
111         goto dst;\
112     }\
113 }
114
115 #define TDM_NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
116
117 #define TDM_SNPRINTF(p, len, fmt, ARG...)  \
118     do { \
119         if (p && len && *len > 0) \
120         { \
121             int s = snprintf(p, *len, fmt, ##ARG); \
122             p += s; \
123             *len -= s; \
124         } \
125     } while (0)
126
127 #define C(b,m)              (((b) >> (m)) & 0xFF)
128 #define B(c,s)              ((((unsigned int)(c)) & 0xff) << (s))
129 #define FOURCC(a,b,c,d)     (B(d,24) | B(c,16) | B(b,8) | B(a,0))
130 #define FOURCC_STR(id)      C(id,0), C(id,8), C(id,16), C(id,24)
131 #define FOURCC_ID(str)      FOURCC(((char*)str)[0],((char*)str)[1],((char*)str)[2],((char*)str)[3])
132
133 typedef enum
134 {
135     TDM_CAPTURE_TARGET_OUTPUT,
136     TDM_CAPTURE_TARGET_LAYER,
137 } tdm_capture_target;
138
139 typedef struct _tdm_private_display tdm_private_display;
140 typedef struct _tdm_private_output tdm_private_output;
141 typedef struct _tdm_private_layer tdm_private_layer;
142 typedef struct _tdm_private_pp tdm_private_pp;
143 typedef struct _tdm_private_capture tdm_private_capture;
144 typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
145 typedef struct _tdm_private_commit_handler tdm_private_commit_handler;
146
147 struct _tdm_private_display
148 {
149     pthread_mutex_t lock;
150     unsigned int init_count;
151
152     /* backend module info */
153     void *module;
154     tdm_backend_module *module_data;
155     tdm_backend_data *bdata;
156
157     /* backend function */
158     tdm_func_display func_display;
159     tdm_func_pp func_pp;
160     tdm_func_capture func_capture;
161
162     /* backend capability */
163     tdm_display_capability capabilities;
164     tdm_caps_pp caps_pp;
165     tdm_caps_capture caps_capture;
166
167     /* output, pp list */
168     struct list_head output_list;
169     struct list_head pp_list;
170
171     void **outputs_ptr;
172 };
173
174 struct _tdm_private_output
175 {
176     struct list_head link;
177
178     tdm_func_display *func_display;
179     tdm_private_display *private_display;
180
181     tdm_caps_output caps;
182     tdm_output *output;
183
184     unsigned int pipe;
185
186     int regist_vblank_cb;
187     int regist_commit_cb;
188
189     struct list_head layer_list;
190     struct list_head capture_list;
191     struct list_head vblank_handler_list;
192     struct list_head commit_handler_list;
193
194     void **layers_ptr;
195 };
196
197 struct _tdm_private_layer
198 {
199     struct list_head link;
200
201     tdm_func_display *func_display;
202     tdm_private_display *private_display;
203     tdm_private_output *private_output;
204
205     tdm_caps_layer caps;
206     tdm_layer *layer;
207
208     struct list_head capture_list;
209 };
210
211 struct _tdm_private_pp
212 {
213     struct list_head link;
214
215     tdm_func_pp *func_pp;
216     tdm_private_display *private_display;
217
218     tdm_pp *pp;
219 };
220
221 struct _tdm_private_capture
222 {
223     struct list_head link;
224
225     tdm_capture_target target;
226
227     tdm_func_capture *func_capture;
228     tdm_private_display *private_display;
229     tdm_private_output *private_output;
230     tdm_private_layer *private_layer;
231
232     tdm_capture *capture;
233 };
234
235 struct _tdm_private_vblank_handler
236 {
237     struct list_head link;
238
239     tdm_output_vblank_handler func;
240     void *user_data;
241 };
242
243 struct _tdm_private_commit_handler
244 {
245     struct list_head link;
246
247     tdm_output_commit_handler func;
248     void *user_data;
249 };
250
251 tdm_buffer*   tdm_buffer_ref_backend(tdm_buffer *buffer);
252 void          tdm_buffer_unref_backend(tdm_buffer *buffer);
253 tbm_surface_h tdm_buffer_get_surface(tdm_buffer *buffer);
254 tdm_buffer*   tdm_buffer_get(tbm_surface_h buffer);
255
256 tdm_private_pp* tdm_pp_create_internal(tdm_private_display *private_display, tdm_error *error);
257 void tdm_pp_destroy_internal(tdm_private_pp *private_pp);
258
259 tdm_private_capture* tdm_capture_create_output_internal(tdm_private_output *private_output, tdm_error *error);
260 tdm_private_capture* tdm_capture_create_layer_internal(tdm_private_layer *private_layer, tdm_error *error);
261 void tdm_capture_destroy_internal(tdm_private_capture *private_capture);
262
263 #ifdef __cplusplus
264 }
265 #endif
266
267 #endif /* _TDM_PRIVATE_H_ */