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