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