Merge branch 'tizen' into sandbox/cyeon/devel
[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 <boram1288.park@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_EVENT     = (1 << 2),
64         TDM_DEBUG_THREAD    = (1 << 3),
65         TDM_DEBUG_SERVER    = (1 << 4),
66         TDM_DEBUG_VBLANK    = (1 << 5),
67         TDM_DEBUG_COMMIT    = (1 << 6),
68 };
69
70 enum {
71         TDM_TTRACE_NONE,
72         TDM_TTRACE_VSYNC            = (1 << 0),
73         TDM_TTRACE_CLIENT_VBLANK    = (1 << 1),
74         TDM_TTRACE_SERVER_VBLANK    = (1 << 2),
75         TDM_TTRACE_VBLANK           = (1 << 3),
76         TDM_TTRACE_LAYER            = (1 << 4),
77         TDM_TTRACE_PP               = (1 << 5),
78         TDM_TTRACE_CAPTURE          = (1 << 6),
79 };
80
81 typedef enum {
82         TDM_CAPTURE_TARGET_OUTPUT,
83         TDM_CAPTURE_TARGET_LAYER,
84 } tdm_capture_target;
85
86 enum {
87         TDM_DUMP_FLAG_LAYER   = (1 << 0),
88         TDM_DUMP_FLAG_PP      = (1 << 1),
89         TDM_DUMP_FLAG_CAPTURE = (1 << 2),
90         TDM_DUMP_FLAG_WINDOW = (1 << 3),
91 };
92
93 typedef enum {
94         TDM_COMMIT_TYPE_NONE,
95         TDM_COMMIT_TYPE_OUTPUT,
96         TDM_COMMIT_TYPE_LAYER,
97 } tdm_commit_type;
98
99 typedef struct _tdm_private_module tdm_private_module;
100 typedef struct _tdm_private_display tdm_private_display;
101 typedef struct _tdm_private_output tdm_private_output;
102 typedef struct _tdm_private_voutput tdm_private_voutput;
103 typedef struct _tdm_private_layer tdm_private_layer;
104 typedef struct _tdm_private_hwc tdm_private_hwc;
105 typedef struct _tdm_private_hwc_window tdm_private_hwc_window;
106 typedef struct _tdm_private_pp tdm_private_pp;
107 typedef struct _tdm_private_capture tdm_private_capture;
108 typedef struct _tdm_private_loop tdm_private_loop;
109 typedef struct _tdm_private_server tdm_private_server;
110 typedef struct _tdm_private_thread tdm_private_thread;
111 typedef struct _tdm_private_output_create_handler tdm_private_output_create_handler;
112 typedef struct _tdm_private_output_destroy_handler tdm_private_output_destroy_handler;
113 typedef struct _tdm_private_output_change_handler tdm_private_output_change_handler;
114 typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler;
115 typedef struct _tdm_private_output_vblank_handler tdm_private_output_vblank_handler;
116 typedef struct _tdm_private_output_mode_change_handler tdm_private_output_mode_change_handler;
117 typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler;
118 typedef struct _tdm_private_hwc_commit_handler tdm_private_hwc_commit_handler;
119 typedef struct _tdm_private_voutput_commit_handler tdm_private_voutput_commit_handler;
120
121 typedef struct _tdm_private_layer_buffer tdm_private_layer_buffer;
122
123 struct _tdm_private_module {
124         struct list_head link;
125
126         tdm_private_display *private_display;
127
128         /* backend module info */
129         void *module;
130         tdm_backend_module *module_data;
131         tdm_backend_data *bdata;
132
133         /* backend function */
134         tdm_display_capability capabilities;
135         tdm_func_display func_display;
136         tdm_func_output func_output;
137         tdm_func_voutput func_voutput;
138         tdm_func_layer func_layer;
139         tdm_func_hwc func_hwc;
140         tdm_func_hwc_window func_hwc_window;
141         tdm_func_pp func_pp;
142         tdm_func_capture func_capture;
143
144         /* backend capability */
145         tdm_caps_display caps_display;
146         tdm_caps_pp caps_pp;
147         tdm_caps_capture caps_capture;
148
149         /* output, pp list */
150         struct list_head output_list;
151         struct list_head voutput_list;
152         struct list_head pp_list;
153         struct list_head capture_list;
154
155         /* backend output objects. allocated in backend. freed in frontend. ordered */
156         tdm_output **outputs;
157
158         int fd;
159         tdm_event_loop_source *event_source;
160
161         /* backend virtual output target buffer type default set for hwc */
162         int use_default_type_bo;
163 };
164
165 struct _tdm_private_display {
166         pthread_mutex_t lock;
167         unsigned int init_count;
168
169         double stamp;
170
171 #ifdef INIT_BUFMGR
172         tbm_bufmgr bufmgr;
173 #endif
174
175         struct list_head module_list;
176         tdm_private_module *dummy_module;
177         tdm_private_module *virtual_module;
178         tdm_private_module *current_module;  //setted only when loading
179         tdm_private_module *pp_module;       //pp-support backend
180         tdm_private_module *capture_module;  //TODO: remove later
181
182         /* for event handling */
183         tdm_private_loop *private_loop;
184
185         struct list_head output_create_handler_list;
186
187         int print_fps;
188 };
189
190 struct _tdm_private_output {
191         struct list_head link;
192
193         tdm_private_module *private_module;
194         tdm_private_voutput *private_voutput;
195
196         int index;
197         double stamp;
198
199         tdm_private_display *private_display;
200
201         tdm_caps_output caps;
202         tdm_output *output_backend;
203
204         unsigned int pipe;
205         tdm_output_dpms current_dpms_value;
206         unsigned int waiting_dpms_change;
207         const tdm_output_mode *current_mode;
208
209         int regist_vblank_cb;
210         int regist_commit_cb;
211         int regist_change_cb;
212         int regist_dpms_cb;
213
214         struct list_head layer_list;
215         struct list_head capture_list;
216         struct list_head vblank_handler_list;
217         struct list_head output_commit_handler_list;
218
219         /* for layer commit */
220         struct list_head layer_commit_handler_list;
221         struct list_head pending_commit_handler_list;
222         tdm_vblank *vblank;
223         int layer_waiting_vblank;
224
225         tdm_event_loop_source *vblank_timeout_timer;
226         unsigned int vblank_timeout_timer_expired;
227
228         struct list_head destroy_handler_list;
229         struct list_head change_handler_list;
230
231         void **layers_ptr;
232
233         tdm_info_layer target_buffer_info; /* layer_info for the target_buffer */
234
235         /* calling a output commit per a vblank */
236         int commit_per_vblank;
237         tdm_commit_type commit_type;
238
239         /* for ttrace vblank */
240         tdm_vblank *ttrace_vblank;
241
242         /* hwc */
243         int need_set_target_info;
244         tdm_private_hwc *private_hwc;
245
246         /* virtual */
247         char name[TDM_NAME_LEN];
248         struct list_head mode_change_request_handler_list;
249 };
250
251 struct _tdm_private_voutput {
252         struct list_head link;
253
254         tdm_private_module *private_module;
255
256         int regist_commit_cb;
257
258         struct list_head voutput_commit_handler_list;
259
260         int index;
261
262         tdm_private_display *private_display;
263         tdm_private_output *private_output;
264
265         tdm_voutput *voutput_backend;
266
267         char name[TDM_NAME_LEN];
268         tdm_output_mode *modes;
269         int mode_count;
270         unsigned int mmwidth;
271         unsigned int mmheight;
272         int connect_status;
273
274         int set_voutput_commit;
275 };
276
277 struct _tdm_private_layer {
278         struct list_head link;
279
280         tdm_private_module *private_module;
281
282         int index;
283
284         tdm_private_display *private_display;
285         tdm_private_output *private_output;
286
287         tdm_caps_layer caps;
288         tdm_layer *layer_backend;
289
290         /* pending data until committed */
291         unsigned int pending_info_changed;
292         tdm_info_layer pending_info;
293         unsigned int pending_buffer_changed;
294         tbm_surface_h pending_buffer;
295
296         /* When a buffer is set to a layer, it will be stored to waiting_buffer.
297          * And when a layer is committed, it will be moved to committed_buffer.
298          * Finally when a commit handler is called, it will be moved to showing_buffer.
299          */
300         tdm_private_layer_buffer *waiting_buffer;
301         tdm_private_layer_buffer *committed_buffer;   /* for output_commit */
302         tdm_private_layer_buffer *showing_buffer;
303         tbm_surface_queue_h buffer_queue;
304
305         struct list_head capture_list;
306
307         unsigned int usable;
308         unsigned int committing;
309
310         double fps_stamp;
311         unsigned int fps_count;
312
313          /* virtual */
314         tbm_surface_h commiting_buffer;
315 };
316
317 struct _tdm_private_hwc {
318         struct list_head link;
319
320         tdm_private_module *private_module;
321
322         int index;
323         double stamp;
324
325         tdm_private_output *private_output;
326
327         struct list_head hwc_window_list;
328         struct list_head hwc_commit_handler_list;
329
330         int regist_commit_cb;
331
332         tdm_hwc *hwc_backend;
333
334         tbm_surface_h display_target_buffer;
335
336         double fps_stamp;
337         unsigned int fps_count;
338 };
339
340 struct _tdm_private_hwc_window {
341         struct list_head link;
342
343         tdm_private_module *private_module;
344
345         tdm_private_hwc *private_hwc;
346         tdm_hwc_window *hwc_window_backend;
347 };
348
349 struct _tdm_private_pp {
350         struct list_head link;
351
352         tdm_private_module *private_module;
353
354         double stamp;
355
356         tdm_private_display *private_display;
357
358         tdm_pp *pp_module;
359
360         struct list_head pending_buffer_list;
361         struct list_head buffer_list;
362
363         tdm_info_pp info;
364         pid_t owner_tid;
365
366         tdm_pp_done_handler done_func;
367         void *done_user_data;
368 };
369
370 struct _tdm_private_capture {
371         struct list_head link;
372         struct list_head display_link;
373
374         tdm_private_module *private_module;
375
376         double stamp;
377
378         tdm_capture_target target;
379
380         tdm_private_display *private_display;
381         tdm_private_output *private_output;
382         tdm_private_layer *private_layer;
383
384         tdm_capture *capture_module;
385
386         struct list_head pending_buffer_list;
387         struct list_head buffer_list;
388
389         tdm_info_capture info;
390         pid_t owner_tid;
391
392         tdm_capture_done_handler done_func;
393         void *done_user_data;
394 };
395
396 /* CAUTION:
397  * Note that we don't need to (un)lock mutex to use this structure. If there is
398  * no TDM thread, all TDM resources are protected by private_display's mutex.
399  * If there is a TDM thread, this struct will be used only in a TDM thread.
400  * So, we don't need to protect this structure by mutex. Not thread-safe.
401  */
402 struct _tdm_private_loop {
403         /* TDM uses wl_event_loop to handle various event sources including the TDM
404          * backend's fd.
405          */
406         struct wl_display *wl_display;
407         struct wl_event_loop *wl_loop;
408
409         /* In event loop, all resources are accessed by this dpy.
410          * CAUTION:
411          * - DO NOT include other private structure in this structure because this
412          *   struct is not protected by mutex.
413          */
414         tdm_display *dpy;
415
416         /* for handling TDM client requests */
417         tdm_private_server *private_server;
418
419         /* To have a TDM event thread. If TDM_THREAD enviroment variable is not set
420          * private_thread is NULL.
421          */
422         tdm_private_thread *private_thread;
423
424         struct list_head source_list;
425 };
426
427 struct _tdm_private_output_vblank_handler {
428         struct list_head link;
429
430         tdm_private_output *private_output;
431         int interval;
432         int sync;
433         tdm_output_vblank_handler func;
434         void *user_data;
435
436         unsigned int sent_to_frontend;
437
438         pid_t owner_tid;
439 };
440
441 struct _tdm_private_output_create_handler {
442         struct list_head link;
443
444         tdm_private_display *private_display;
445         tdm_output_create_handler func;
446         void *user_data;
447
448         pid_t owner_tid;
449 };
450
451 struct _tdm_private_output_destroy_handler {
452         struct list_head link;
453
454         tdm_private_output *private_output;
455         tdm_output_destroy_handler func;
456         void *user_data;
457
458         pid_t owner_tid;
459 };
460
461 struct _tdm_private_output_change_handler {
462         struct list_head link;
463
464         tdm_private_output *private_output;
465         tdm_output_change_handler func;
466         void *user_data;
467
468         pid_t owner_tid;
469 };
470
471 struct _tdm_private_output_commit_handler {
472         struct list_head link;
473
474         tdm_private_output *private_output;
475         tdm_output_commit_handler func;
476         void *user_data;
477
478         pid_t owner_tid;
479 };
480
481 struct _tdm_private_voutput_commit_handler {
482         struct list_head link;
483
484         tdm_private_voutput *private_voutput;
485         tdm_voutput_commit_func func;
486         void *user_data;
487
488         pid_t owner_tid;
489 };
490
491 struct _tdm_private_output_mode_change_handler {
492         struct list_head link;
493
494         tdm_private_output *private_output;
495         tdm_output_mode_change_request_handler func;
496         void *user_data;
497 };
498
499 struct _tdm_private_hwc_commit_handler {
500         struct list_head link;
501
502         tdm_private_hwc *private_hwc;
503         tdm_hwc_commit_handler func;
504         void *user_data;
505
506         pid_t owner_tid;
507         int use_vblank;
508 };
509
510 struct _tdm_private_layer_commit_handler {
511         struct list_head link;
512
513         tdm_private_layer *private_layer;
514         tdm_layer_commit_handler func;
515         void *user_data;
516
517         tdm_private_layer_buffer *committed_buffer;   /* for layer_commit */
518 };
519
520 struct _tdm_private_layer_buffer {
521         tbm_surface_h buffer;
522         struct list_head link;
523 };
524
525 typedef struct _tdm_buffer_info {
526         tbm_surface_h buffer;
527
528         /* ref_count for backend */
529         int backend_ref_count;
530
531         struct list_head release_funcs;
532         struct list_head destroy_funcs;
533
534         struct list_head *list;
535         struct list_head link;
536 } tdm_buffer_info;
537
538 typedef struct _tdm_pp_private_buffer {
539         tbm_surface_h src;
540         tbm_surface_h dst;
541         struct list_head link;
542         struct list_head commit_link;
543 } tdm_pp_private_buffer;
544
545 typedef struct _tdm_capture_private_buffer {
546         tbm_surface_h buffer;
547         struct list_head link;
548         struct list_head commit_link;
549 } tdm_capture_private_buffer;
550
551 typedef enum {
552         TDM_THREAD_CB_NONE,
553         TDM_THREAD_CB_EXIT,             /* special type to exit the tdm-thread */
554         TDM_THREAD_CB_DISPLAY_OUTPUT_CREATE,
555         TDM_THREAD_CB_OUTPUT_DESTROY,
556         TDM_THREAD_CB_OUTPUT_COMMIT,
557         TDM_THREAD_CB_OUTPUT_VBLANK,
558         TDM_THREAD_CB_OUTPUT_STATUS,
559         TDM_THREAD_CB_OUTPUT_DPMS,
560         TDM_THREAD_CB_PP_DONE,
561         TDM_THREAD_CB_CAPTURE_DONE,
562         TDM_THREAD_CB_VBLANK_SW,
563         TDM_THREAD_CB_VBLANK_CREATE,
564         TDM_THREAD_CB_HWC_COMMIT,
565         TDM_THREAD_CB_VOUTPUT_COMMIT,
566         TDM_THREAD_CB_MAX,
567 } tdm_thread_cb_type;
568
569 typedef struct _tdm_thread_cb_base tdm_thread_cb_base;
570 typedef struct _tdm_thread_cb_display_output_create tdm_thread_cb_display_output_create;
571 typedef struct _tdm_thread_cb_output_destroy tdm_thread_cb_output_destroy;
572 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_commit;
573 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_vblank;
574 typedef struct _tdm_thread_cb_output_dpms tdm_thread_cb_output_dpms;
575 typedef struct _tdm_thread_cb_output_status tdm_thread_cb_output_status;
576 typedef struct _tdm_thread_cb_pp_done tdm_thread_cb_pp_done;
577 typedef struct _tdm_thread_cb_capture_done tdm_thread_cb_capture_done;
578 typedef struct _tdm_thread_cb_vblank_sw tdm_thread_cb_vblank_sw;
579 typedef struct _tdm_thread_cb_vblank_create tdm_thread_cb_vblank_create;
580 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_hwc_commit;
581 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_voutput_commit;
582
583 struct _tdm_thread_cb_base {
584         tdm_thread_cb_type type;
585         unsigned int length;
586         double object_stamp;
587         void *data;
588         unsigned int sync;
589 };
590
591 struct _tdm_thread_cb_display_output_create {
592         tdm_thread_cb_base base;
593         tdm_output *output;
594 };
595
596 struct _tdm_thread_cb_output_destroy {
597         tdm_thread_cb_base base;
598 };
599
600 struct _tdm_thread_cb_output_vblank {
601         tdm_thread_cb_base base;
602         unsigned int sequence;
603         unsigned int tv_sec;
604         unsigned int tv_usec;
605 };
606
607 struct _tdm_thread_cb_output_status {
608         tdm_thread_cb_base base;
609         tdm_output_conn_status status;
610 };
611
612 struct _tdm_thread_cb_output_dpms {
613         tdm_thread_cb_base base;
614         tdm_output_dpms dpms;
615 };
616
617 struct _tdm_thread_cb_pp_done {
618         tdm_thread_cb_base base;
619         tbm_surface_h src;
620         tbm_surface_h dst;
621 };
622
623 struct _tdm_thread_cb_capture_done {
624         tdm_thread_cb_base base;
625         tbm_surface_h buffer;
626 };
627
628 struct _tdm_thread_cb_vblank_sw {
629         tdm_thread_cb_base base;
630 };
631
632 struct _tdm_thread_cb_vblank_create {
633         tdm_thread_cb_base base;
634         double vblank_stamp;
635 };
636
637 struct argument_details {
638         char type;
639         int nullable;
640 };
641
642 #ifdef __cplusplus
643 }
644 #endif
645
646 #endif /* _TDM_PRIVATE_TYPES_H_ */