correct the header file dependency
[platform/core/uifw/libtdm.git] / src / tdm_private_types.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_TYPES_H_
37 #define _TDM_PRIVATE_TYPES_H_
38
39 #include <pthread.h>
40 #include <tbm_bufmgr.h>
41 #include <tbm_surface_queue.h>
42
43 #include "tdm_types.h"
44 #include "tdm_list.h"
45 #include "tdm_log.h"
46 #include "tdm.h"
47 #include "tdm_backend.h"
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 //#define INIT_BUFMGR
54
55 /*****************************************************************************
56  * This file defines private Enumerations and Structures for frontend
57  *****************************************************************************/
58
59 enum {
60         TDM_DEBUG_NONE,
61         TDM_DEBUG_BUFFER    = (1 << 0),
62         TDM_DEBUG_MUTEX     = (1 << 1),
63         TDM_DEBUG_THREAD    = (1 << 2),
64         TDM_DEBUG_SERVER    = (1 << 3),
65         TDM_DEBUG_VBLANK    = (1 << 4),
66         TDM_DEBUG_COMMIT    = (1 << 5),
67 };
68
69 enum {
70         TDM_TTRACE_NONE,
71         TDM_TTRACE_VBLANK    = (1 << 0),
72         TDM_TTRACE_CLIENT    = (1 << 1),
73         TDM_TTRACE_LAYER     = (1 << 2),
74         TDM_TTRACE_PP        = (1 << 3),
75         TDM_TTRACE_CAPTURE   = (1 << 4),
76 };
77
78 typedef enum {
79         TDM_CAPTURE_TARGET_OUTPUT,
80         TDM_CAPTURE_TARGET_LAYER,
81 } tdm_capture_target;
82
83 enum {
84         TDM_DUMP_FLAG_LAYER   = (1 << 0),
85         TDM_DUMP_FLAG_PP      = (1 << 1),
86         TDM_DUMP_FLAG_CAPTURE = (1 << 2),
87         TDM_DUMP_FLAG_WINDOW = (1 << 3),
88 };
89
90 typedef enum {
91         TDM_COMMIT_TYPE_NONE,
92         TDM_COMMIT_TYPE_OUTPUT,
93         TDM_COMMIT_TYPE_LAYER,
94 } tdm_commit_type;
95
96 typedef struct _tdm_private_display tdm_private_display;
97 typedef struct _tdm_private_output tdm_private_output;
98 typedef struct _tdm_private_layer tdm_private_layer;
99 typedef struct _tdm_private_hwc_window tdm_private_hwc_window;
100 typedef struct _tdm_private_pp tdm_private_pp;
101 typedef struct _tdm_private_capture tdm_private_capture;
102 typedef struct _tdm_private_loop tdm_private_loop;
103 typedef struct _tdm_private_server tdm_private_server;
104 typedef struct _tdm_private_thread tdm_private_thread;
105 typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
106 typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler;
107 typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler;
108 typedef struct _tdm_private_change_handler tdm_private_change_handler;
109 typedef struct _tdm_private_layer_buffer tdm_private_layer_buffer;
110
111 struct _tdm_private_display {
112         pthread_mutex_t lock;
113         unsigned int init_count;
114
115         /* backend module info */
116         void *module;
117         tdm_backend_module *module_data;
118         tdm_backend_data *bdata;
119
120 #ifdef INIT_BUFMGR
121         tbm_bufmgr bufmgr;
122 #endif
123
124         /* backend function */
125         tdm_display_capability capabilities;
126         tdm_func_display func_display;
127         tdm_func_output func_output;
128         tdm_func_layer func_layer;
129         tdm_func_hwc_window func_hwc_window;
130         tdm_func_pp func_pp;
131         tdm_func_capture func_capture;
132
133         /* backend capability */
134         tdm_caps_display caps_display;
135         tdm_caps_pp caps_pp;
136         tdm_caps_capture caps_capture;
137
138         /* output, pp list */
139         struct list_head output_list;
140         struct list_head pp_list;
141         struct list_head capture_list;
142
143         void **outputs_ptr;
144
145         /* for event handling */
146         tdm_private_loop *private_loop;
147
148         /* output order */
149         tdm_output **outputs;
150
151         int print_fps;
152 };
153
154 struct _tdm_private_output {
155         struct list_head link;
156
157         int index;
158         double stamp;
159
160         tdm_private_display *private_display;
161
162         tdm_caps_output caps;
163         tdm_output *output_backend;
164
165         unsigned int pipe;
166         tdm_output_dpms current_dpms_value;
167         unsigned int waiting_dpms_change;
168         const tdm_output_mode *current_mode;
169
170         int regist_vblank_cb;
171         int regist_commit_cb;
172         int regist_change_cb;
173         int regist_dpms_cb;
174
175         struct list_head layer_list;
176         struct list_head hwc_window_list;
177         struct list_head capture_list;
178         struct list_head vblank_handler_list;
179         struct list_head output_commit_handler_list;
180
181         /* for layer commit */
182         struct list_head layer_commit_handler_list;
183         struct list_head pending_commit_handler_list;
184         tdm_vblank *vblank;
185         int layer_waiting_vblank;
186
187         /* seperate list for multi-thread*/
188         struct list_head change_handler_list_main;
189         struct list_head change_handler_list_sub;
190
191         void **layers_ptr;
192
193         /* TODO: temp solution for handling DPMS things in sub-htread */
194         tdm_event_loop_source *dpms_changed_timer;
195
196         struct {
197                 /* look at the tdm_output_set_need_revalidate_handler() declaration for the details */
198                 tdm_output_need_validate_handler hndl;
199                 int event_fd;
200                 tdm_event_loop_source *event_source;
201         } need_validate;
202
203         /* calling a output commit per a vblank */
204         int commit_per_vblank;
205         tdm_commit_type commit_type;
206
207         /* for ttrace vblank */
208         tdm_vblank *ttrace_vblank;
209 };
210
211 struct _tdm_private_layer {
212         struct list_head link;
213
214         int index;
215
216         tdm_private_display *private_display;
217         tdm_private_output *private_output;
218
219         tdm_caps_layer caps;
220         tdm_layer *layer_backend;
221
222         /* pending data until committed */
223         unsigned int pending_info_changed;
224         tdm_info_layer pending_info;
225         unsigned int pending_buffer_changed;
226         tbm_surface_h pending_buffer;
227
228         /* When a buffer is set to a layer, it will be stored to waiting_buffer.
229          * And when a layer is committed, it will be moved to committed_buffer.
230          * Finally when a commit handler is called, it will be moved to showing_buffer.
231          */
232         tdm_private_layer_buffer *waiting_buffer;
233         tdm_private_layer_buffer *committed_buffer;   /* for output_commit */
234         tdm_private_layer_buffer *showing_buffer;
235         tbm_surface_queue_h buffer_queue;
236
237         struct list_head capture_list;
238
239         unsigned int usable;
240         unsigned int committing;
241
242         double fps_stamp;
243         unsigned int fps_count;
244 };
245
246 struct _tdm_private_hwc_window {
247         struct list_head link;
248
249         int index;
250         uint32_t zpos;
251
252         tdm_private_display *private_display;
253         tdm_private_output *private_output;
254
255         tdm_hwc_window *hwc_window_backend;
256 };
257
258 struct _tdm_private_pp {
259         struct list_head link;
260
261         double stamp;
262
263         tdm_private_display *private_display;
264
265         tdm_pp *pp_backend;
266
267         struct list_head pending_buffer_list;
268         struct list_head buffer_list;
269
270         tdm_info_pp info;
271         pid_t owner_tid;
272
273         tdm_pp_done_handler done_func;
274         void *done_user_data;
275 };
276
277 struct _tdm_private_capture {
278         struct list_head link;
279         struct list_head display_link;
280
281         double stamp;
282
283         tdm_capture_target target;
284
285         tdm_private_display *private_display;
286         tdm_private_output *private_output;
287         tdm_private_layer *private_layer;
288
289         tdm_capture *capture_backend;
290
291         struct list_head pending_buffer_list;
292         struct list_head buffer_list;
293
294         tdm_info_capture info;
295         pid_t owner_tid;
296
297         tdm_capture_done_handler done_func;
298         void *done_user_data;
299 };
300
301 /* CAUTION:
302  * Note that we don't need to (un)lock mutex to use this structure. If there is
303  * no TDM thread, all TDM resources are protected by private_display's mutex.
304  * If there is a TDM thread, this struct will be used only in a TDM thread.
305  * So, we don't need to protect this structure by mutex. Not thread-safe.
306  */
307 struct _tdm_private_loop {
308         /* TDM uses wl_event_loop to handle various event sources including the TDM
309          * backend's fd.
310          */
311         struct wl_display *wl_display;
312         struct wl_event_loop *wl_loop;
313
314         int backend_fd;
315         tdm_event_loop_source *backend_source;
316
317         /* In event loop, all resources are accessed by this dpy.
318          * CAUTION:
319          * - DO NOT include other private structure in this structure because this
320          *   struct is not protected by mutex.
321          */
322         tdm_display *dpy;
323
324         /* for handling TDM client requests */
325         tdm_private_server *private_server;
326
327         /* To have a TDM event thread. If TDM_THREAD enviroment variable is not set
328          * private_thread is NULL.
329          */
330         tdm_private_thread *private_thread;
331 };
332
333 struct _tdm_private_vblank_handler {
334         struct list_head link;
335
336         tdm_private_output *private_output;
337         int interval;
338         int sync;
339         tdm_output_vblank_handler func;
340         void *user_data;
341
342         pid_t owner_tid;
343 };
344
345 struct _tdm_private_output_commit_handler {
346         struct list_head link;
347
348         tdm_private_output *private_output;
349         tdm_output_commit_handler func;
350         void *user_data;
351
352         pid_t owner_tid;
353 };
354
355 struct _tdm_private_layer_commit_handler {
356         struct list_head link;
357
358         tdm_private_layer *private_layer;
359         tdm_layer_commit_handler func;
360         void *user_data;
361
362         tdm_private_layer_buffer *committed_buffer;   /* for layer_commit */
363 };
364
365 struct _tdm_private_change_handler {
366         struct list_head link;
367
368         tdm_private_output *private_output;
369         tdm_output_change_handler func;
370         void *user_data;
371
372         pid_t owner_tid;
373 };
374
375 struct _tdm_private_layer_buffer {
376         tbm_surface_h buffer;
377         struct list_head link;
378 };
379
380 typedef struct _tdm_buffer_info {
381         tbm_surface_h buffer;
382
383         /* ref_count for backend */
384         int backend_ref_count;
385
386         struct list_head release_funcs;
387         struct list_head destroy_funcs;
388
389         struct list_head *list;
390         struct list_head link;
391 } tdm_buffer_info;
392
393 typedef struct _tdm_pp_private_buffer {
394         tbm_surface_h src;
395         tbm_surface_h dst;
396         struct list_head link;
397         struct list_head commit_link;
398 } tdm_pp_private_buffer;
399
400 typedef struct _tdm_capture_private_buffer {
401         tbm_surface_h buffer;
402         struct list_head link;
403         struct list_head commit_link;
404 } tdm_capture_private_buffer;
405
406 typedef enum {
407         TDM_THREAD_CB_NONE,
408         TDM_THREAD_CB_OUTPUT_COMMIT,
409         TDM_THREAD_CB_OUTPUT_VBLANK,
410         TDM_THREAD_CB_OUTPUT_STATUS,
411         TDM_THREAD_CB_OUTPUT_DPMS,
412         TDM_THREAD_CB_PP_DONE,
413         TDM_THREAD_CB_CAPTURE_DONE,
414         TDM_THREAD_CB_VBLANK_SW,
415         TDM_THREAD_CB_VBLANK_CREATE,
416         TDM_THREAD_CB_NEED_VALIDATE,
417 } tdm_thread_cb_type;
418
419 typedef struct _tdm_thread_cb_base tdm_thread_cb_base;
420 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_commit;
421 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_vblank;
422 typedef struct _tdm_thread_cb_output_status tdm_thread_cb_output_status;
423 typedef struct _tdm_thread_cb_output_dpms tdm_thread_cb_output_dpms;
424 typedef struct _tdm_thread_cb_pp_done tdm_thread_cb_pp_done;
425 typedef struct _tdm_thread_cb_capture_done tdm_thread_cb_capture_done;
426 typedef struct _tdm_thread_cb_vblank_sw tdm_thread_cb_vblank_sw;
427 typedef struct _tdm_thread_cb_vblank_create tdm_thread_cb_vblank_create;
428 typedef struct _tdm_thread_cb_need_validate tdm_thread_cb_need_validate;
429
430 struct _tdm_thread_cb_base {
431         tdm_thread_cb_type type;
432         unsigned int length;
433 };
434
435 struct _tdm_thread_cb_output_vblank {
436         tdm_thread_cb_base base;
437         double output_stamp;
438         unsigned int sequence;
439         unsigned int tv_sec;
440         unsigned int tv_usec;
441         void *user_data;
442 };
443
444 struct _tdm_thread_cb_output_status {
445         tdm_thread_cb_base base;
446         double output_stamp;
447         tdm_output_conn_status status;
448         void *user_data;
449 };
450
451 struct _tdm_thread_cb_output_dpms {
452         tdm_thread_cb_base base;
453         double output_stamp;
454         tdm_output_dpms dpms;
455         void *user_data;
456 };
457
458 struct _tdm_thread_cb_pp_done {
459         tdm_thread_cb_base base;
460         double pp_stamp;
461         tbm_surface_h src;
462         tbm_surface_h dst;
463         void *user_data;
464 };
465
466 struct _tdm_thread_cb_capture_done {
467         tdm_thread_cb_base base;
468         double capture_stamp;
469         tbm_surface_h buffer;
470         void *user_data;
471 };
472
473 struct _tdm_thread_cb_vblank_sw {
474         tdm_thread_cb_base base;
475         double vblank_stamp;
476 };
477
478 struct _tdm_thread_cb_vblank_create {
479         tdm_thread_cb_base base;
480         double vblank_stamp;
481 };
482
483 struct _tdm_thread_cb_need_validate {
484         tdm_thread_cb_base base;
485         tdm_private_output *o;
486 };
487
488 struct argument_details {
489         char type;
490         int nullable;
491 };
492
493 #ifdef __cplusplus
494 }
495 #endif
496
497 #endif /* _TDM_PRIVATE_TYPES_H_ */