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