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