2425059bff83b13a80cd4b92ba11cd59c62cea30
[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 <tbm_bufmgr.h>
53 #include <tbm_surface_queue.h>
54
55 #include "tdm_backend.h"
56 #include "tdm_log.h"
57 #include "tdm_list.h"
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 /**
64  * @file tdm_private.h
65  * @brief The private header file for a frontend library
66  */
67
68 #undef EXTERN
69 #undef DEPRECATED
70 #undef INTERN
71
72 #if defined(__GNUC__) && __GNUC__ >= 4
73 #define EXTERN __attribute__ ((visibility("default")))
74 #else
75 #define EXTERN
76 #endif
77
78 #if defined(__GNUC__) && __GNUC__ >= 4
79 #define INTERN __attribute__ ((visibility("hidden")))
80 #else
81 #define INTERN
82 #endif
83
84 #if defined(__GNUC__) && __GNUC__ >= 4
85 #define DEPRECATED __attribute__ ((deprecated))
86 #else
87 #define DEPRECATED
88 #endif
89
90 /* check condition */
91 #define TDM_RETURN_IF_FAIL(cond) {\
92     if (!(cond)) {\
93         TDM_ERR ("'%s' failed", #cond);\
94         return;\
95     }\
96 }
97 #define TDM_RETURN_VAL_IF_FAIL(cond, val) {\
98     if (!(cond)) {\
99         TDM_ERR ("'%s' failed", #cond);\
100         return val;\
101     }\
102 }
103 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) {\
104     if (!(cond)) {\
105         TDM_ERR ("'%s' failed", #cond);\
106         ret = error_v;\
107         if (error) *error = ret;\
108         return val;\
109     }\
110 }
111
112 #define TDM_WARNING_IF_FAIL(cond)  {\
113     if (!(cond))\
114         TDM_ERR ("'%s' failed", #cond);\
115 }
116 #define TDM_GOTO_IF_FAIL(cond, dst) {\
117     if (!(cond)) {\
118         TDM_ERR ("'%s' failed", #cond);\
119         goto dst;\
120     }\
121 }
122
123 #define TDM_NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
124
125 #define TDM_SNPRINTF(p, len, fmt, ARG...)  \
126     do { \
127         if (p && len && *len > 0) \
128         { \
129             int s = snprintf(p, *len, fmt, ##ARG); \
130             p += s; \
131             *len -= s; \
132         } \
133     } while (0)
134
135 #define C(b,m)              (((b) >> (m)) & 0xFF)
136 #define B(c,s)              ((((unsigned int)(c)) & 0xff) << (s))
137 #define FOURCC(a,b,c,d)     (B(d,24) | B(c,16) | B(b,8) | B(a,0))
138 #define FOURCC_STR(id)      C(id,0), C(id,8), C(id,16), C(id,24)
139 #define FOURCC_ID(str)      FOURCC(((char*)str)[0],((char*)str)[1],((char*)str)[2],((char*)str)[3])
140
141 typedef enum
142 {
143     TDM_CAPTURE_TARGET_OUTPUT,
144     TDM_CAPTURE_TARGET_LAYER,
145 } tdm_capture_target;
146
147 typedef struct _tdm_private_display tdm_private_display;
148 typedef struct _tdm_private_output tdm_private_output;
149 typedef struct _tdm_private_layer tdm_private_layer;
150 typedef struct _tdm_private_pp tdm_private_pp;
151 typedef struct _tdm_private_capture tdm_private_capture;
152 typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
153 typedef struct _tdm_private_commit_handler tdm_private_commit_handler;
154
155 struct _tdm_private_display
156 {
157     pthread_mutex_t lock;
158     unsigned int init_count;
159
160     /* backend module info */
161     void *module;
162     tdm_backend_module *module_data;
163     tdm_backend_data *bdata;
164
165     /* backend function */
166     tdm_display_capability capabilities;
167     tdm_func_display func_display;
168     tdm_func_output func_output;
169     tdm_func_layer func_layer;
170     tdm_func_pp func_pp;
171     tdm_func_capture func_capture;
172
173     /* backend capability */
174     tdm_caps_display caps_display;
175     tdm_caps_pp caps_pp;
176     tdm_caps_capture caps_capture;
177
178     /* output, pp list */
179     struct list_head output_list;
180     struct list_head pp_list;
181
182     void **outputs_ptr;
183 };
184
185 struct _tdm_private_output
186 {
187     struct list_head link;
188
189     tdm_private_display *private_display;
190
191     tdm_caps_output caps;
192     tdm_output *output_backend;
193
194     unsigned int pipe;
195
196     int regist_vblank_cb;
197     int regist_commit_cb;
198
199     struct list_head layer_list;
200     struct list_head capture_list;
201     struct list_head vblank_handler_list;
202     struct list_head commit_handler_list;
203
204     void **layers_ptr;
205 };
206
207 struct _tdm_private_layer
208 {
209     struct list_head link;
210
211     tdm_private_display *private_display;
212     tdm_private_output *private_output;
213
214     tdm_caps_layer caps;
215     tdm_layer *layer_backend;
216
217     tbm_surface_h waiting_buffer;
218     tbm_surface_h showing_buffer;
219     tbm_surface_queue_h buffer_queue;
220
221     struct list_head capture_list;
222
223     unsigned int usable;
224 };
225
226 struct _tdm_private_pp
227 {
228     struct list_head link;
229
230     tdm_private_display *private_display;
231
232     tdm_pp *pp_backend;
233 };
234
235 struct _tdm_private_capture
236 {
237     struct list_head link;
238
239     tdm_capture_target target;
240
241     tdm_private_display *private_display;
242     tdm_private_output *private_output;
243     tdm_private_layer *private_layer;
244
245     tdm_capture *capture_backend;
246 };
247
248 struct _tdm_private_vblank_handler
249 {
250     struct list_head link;
251
252     tdm_private_output *private_output;
253     tdm_output_vblank_handler func;
254     void *user_data;
255 };
256
257 struct _tdm_private_commit_handler
258 {
259     struct list_head link;
260
261     tdm_private_output *private_output;
262     tdm_output_commit_handler func;
263     void *user_data;
264 };
265
266 tdm_private_pp* tdm_pp_create_internal(tdm_private_display *private_display, tdm_error *error);
267 void tdm_pp_destroy_internal(tdm_private_pp *private_pp);
268
269 tdm_private_capture* tdm_capture_create_output_internal(tdm_private_output *private_output, tdm_error *error);
270 tdm_private_capture* tdm_capture_create_layer_internal(tdm_private_layer *private_layer, tdm_error *error);
271 void tdm_capture_destroy_internal(tdm_private_capture *private_capture);
272
273 #ifdef __cplusplus
274 }
275 #endif
276
277 #endif /* _TDM_PRIVATE_H_ */