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