a406ecda9262e4889fead1dc0fd98752e3054119
[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 <sc1.lim@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_THREAD    = (1 << 2),
64         TDM_DEBUG_SERVER    = (1 << 3),
65         TDM_DEBUG_VBLANK    = (1 << 4),
66         TDM_DEBUG_COMMIT    = (1 << 5),
67 };
68
69 enum {
70         TDM_TTRACE_NONE,
71         TDM_TTRACE_VSYNC            = (1 << 0),
72         TDM_TTRACE_CLIENT_VBLANK    = (1 << 1),
73         TDM_TTRACE_SERVER_VBLANK    = (1 << 2),
74         TDM_TTRACE_VBLANK           = (1 << 3),
75         TDM_TTRACE_LAYER            = (1 << 4),
76         TDM_TTRACE_PP               = (1 << 5),
77         TDM_TTRACE_CAPTURE          = (1 << 6),
78 };
79
80 typedef enum {
81         TDM_CAPTURE_TARGET_OUTPUT,
82         TDM_CAPTURE_TARGET_LAYER,
83 } tdm_capture_target;
84
85 enum {
86         TDM_DUMP_FLAG_LAYER   = (1 << 0),
87         TDM_DUMP_FLAG_PP      = (1 << 1),
88         TDM_DUMP_FLAG_CAPTURE = (1 << 2),
89         TDM_DUMP_FLAG_WINDOW = (1 << 3),
90 };
91
92 typedef enum {
93         TDM_COMMIT_TYPE_NONE,
94         TDM_COMMIT_TYPE_OUTPUT,
95         TDM_COMMIT_TYPE_LAYER,
96 } tdm_commit_type;
97
98 typedef struct _tdm_private_display tdm_private_display;
99 typedef struct _tdm_private_output tdm_private_output;
100 typedef struct _tdm_private_layer tdm_private_layer;
101 typedef struct _tdm_private_hwc_window tdm_private_hwc_window;
102 typedef struct _tdm_private_pp tdm_private_pp;
103 typedef struct _tdm_private_capture tdm_private_capture;
104 typedef struct _tdm_private_loop tdm_private_loop;
105 typedef struct _tdm_private_server tdm_private_server;
106 typedef struct _tdm_private_thread tdm_private_thread;
107 typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
108 typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler;
109 typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler;
110 typedef struct _tdm_private_change_handler tdm_private_change_handler;
111 typedef struct _tdm_private_layer_buffer tdm_private_layer_buffer;
112
113 struct _tdm_private_display {
114         pthread_mutex_t lock;
115         unsigned int init_count;
116
117         /* backend module info */
118         void *module;
119         tdm_backend_module *module_data;
120         tdm_backend_data *bdata;
121
122 #ifdef INIT_BUFMGR
123         tbm_bufmgr bufmgr;
124 #endif
125
126         /* backend function */
127         tdm_display_capability capabilities;
128         tdm_func_display func_display;
129         tdm_func_output func_output;
130         tdm_func_layer func_layer;
131         tdm_func_hwc_window func_hwc_window;
132         tdm_func_pp func_pp;
133         tdm_func_capture func_capture;
134
135         /* backend capability */
136         tdm_caps_display caps_display;
137         tdm_caps_pp caps_pp;
138         tdm_caps_capture caps_capture;
139
140         /* output, pp list */
141         struct list_head output_list;
142         struct list_head pp_list;
143         struct list_head capture_list;
144
145         void **outputs_ptr;
146
147         /* for event handling */
148         tdm_private_loop *private_loop;
149
150         /* output order */
151         tdm_output **outputs;
152
153         int print_fps;
154 };
155
156 struct _tdm_private_output {
157         struct list_head link;
158
159         int index;
160         double stamp;
161
162         tdm_private_display *private_display;
163
164         tdm_caps_output caps;
165         tdm_output *output_backend;
166
167         unsigned int pipe;
168         tdm_output_dpms current_dpms_value;
169         unsigned int waiting_dpms_change;
170         const tdm_output_mode *current_mode;
171
172         int regist_vblank_cb;
173         int regist_commit_cb;
174         int regist_change_cb;
175         int regist_dpms_cb;
176
177         struct list_head layer_list;
178         struct list_head hwc_window_list;
179         struct list_head capture_list;
180         struct list_head vblank_handler_list;
181         struct list_head output_commit_handler_list;
182
183         /* for layer commit */
184         struct list_head layer_commit_handler_list;
185         struct list_head pending_commit_handler_list;
186         tdm_vblank *vblank;
187         int layer_waiting_vblank;
188
189         /* seperate list for multi-thread*/
190         struct list_head change_handler_list_main;
191         struct list_head change_handler_list_sub;
192
193         void **layers_ptr;
194
195         /* TODO: temp solution for handling DPMS things in sub-htread */
196         tdm_event_loop_source *dpms_changed_timer;
197
198         struct {
199                 /* look at the tdm_output_set_need_revalidate_handler() declaration for the details */
200                 tdm_output_need_validate_handler hndl;
201                 int event_fd;
202                 tdm_event_loop_source *event_source;
203         } need_validate;
204
205         /* calling a output commit per a vblank */
206         int commit_per_vblank;
207         tdm_commit_type commit_type;
208
209         /* for ttrace vblank */
210         tdm_vblank *ttrace_vblank;
211 };
212
213 struct _tdm_private_layer {
214         struct list_head link;
215
216         int index;
217
218         tdm_private_display *private_display;
219         tdm_private_output *private_output;
220
221         tdm_caps_layer caps;
222         tdm_layer *layer_backend;
223
224         /* pending data until committed */
225         unsigned int pending_info_changed;
226         tdm_info_layer pending_info;
227         unsigned int pending_buffer_changed;
228         tbm_surface_h pending_buffer;
229
230         /* When a buffer is set to a layer, it will be stored to waiting_buffer.
231          * And when a layer is committed, it will be moved to committed_buffer.
232          * Finally when a commit handler is called, it will be moved to showing_buffer.
233          */
234         tdm_private_layer_buffer *waiting_buffer;
235         tdm_private_layer_buffer *committed_buffer;   /* for output_commit */
236         tdm_private_layer_buffer *showing_buffer;
237         tbm_surface_queue_h buffer_queue;
238
239         struct list_head capture_list;
240
241         unsigned int usable;
242         unsigned int committing;
243
244         double fps_stamp;
245         unsigned int fps_count;
246 };
247
248 struct _tdm_private_hwc_window {
249         struct list_head link;
250
251         int index;
252         uint32_t zpos;
253
254         tdm_private_display *private_display;
255         tdm_private_output *private_output;
256
257         tdm_hwc_window *hwc_window_backend;
258 };
259
260 struct _tdm_private_pp {
261         struct list_head link;
262
263         double stamp;
264
265         tdm_private_display *private_display;
266
267         tdm_pp *pp_backend;
268
269         struct list_head pending_buffer_list;
270         struct list_head buffer_list;
271
272         tdm_info_pp info;
273         pid_t owner_tid;
274
275         tdm_pp_done_handler done_func;
276         void *done_user_data;
277 };
278
279 struct _tdm_private_capture {
280         struct list_head link;
281         struct list_head display_link;
282
283         double stamp;
284
285         tdm_capture_target target;
286
287         tdm_private_display *private_display;
288         tdm_private_output *private_output;
289         tdm_private_layer *private_layer;
290
291         tdm_capture *capture_backend;
292
293         struct list_head pending_buffer_list;
294         struct list_head buffer_list;
295
296         tdm_info_capture info;
297         pid_t owner_tid;
298
299         tdm_capture_done_handler done_func;
300         void *done_user_data;
301 };
302
303 /* CAUTION:
304  * Note that we don't need to (un)lock mutex to use this structure. If there is
305  * no TDM thread, all TDM resources are protected by private_display's mutex.
306  * If there is a TDM thread, this struct will be used only in a TDM thread.
307  * So, we don't need to protect this structure by mutex. Not thread-safe.
308  */
309 struct _tdm_private_loop {
310         /* TDM uses wl_event_loop to handle various event sources including the TDM
311          * backend's fd.
312          */
313         struct wl_display *wl_display;
314         struct wl_event_loop *wl_loop;
315
316         int backend_fd;
317         tdm_event_loop_source *backend_source;
318
319         /* In event loop, all resources are accessed by this dpy.
320          * CAUTION:
321          * - DO NOT include other private structure in this structure because this
322          *   struct is not protected by mutex.
323          */
324         tdm_display *dpy;
325
326         /* for handling TDM client requests */
327         tdm_private_server *private_server;
328
329         /* To have a TDM event thread. If TDM_THREAD enviroment variable is not set
330          * private_thread is NULL.
331          */
332         tdm_private_thread *private_thread;
333 };
334
335 struct _tdm_private_vblank_handler {
336         struct list_head link;
337
338         tdm_private_output *private_output;
339         int interval;
340         int sync;
341         tdm_output_vblank_handler func;
342         void *user_data;
343
344         pid_t owner_tid;
345 };
346
347 struct _tdm_private_output_commit_handler {
348         struct list_head link;
349
350         tdm_private_output *private_output;
351         tdm_output_commit_handler func;
352         void *user_data;
353
354         pid_t owner_tid;
355 };
356
357 struct _tdm_private_layer_commit_handler {
358         struct list_head link;
359
360         tdm_private_layer *private_layer;
361         tdm_layer_commit_handler func;
362         void *user_data;
363
364         tdm_private_layer_buffer *committed_buffer;   /* for layer_commit */
365 };
366
367 struct _tdm_private_change_handler {
368         struct list_head link;
369
370         tdm_private_output *private_output;
371         tdm_output_change_handler func;
372         void *user_data;
373
374         pid_t owner_tid;
375 };
376
377 struct _tdm_private_layer_buffer {
378         tbm_surface_h buffer;
379         struct list_head link;
380 };
381
382 typedef struct _tdm_buffer_info {
383         tbm_surface_h buffer;
384
385         /* ref_count for backend */
386         int backend_ref_count;
387
388         struct list_head release_funcs;
389         struct list_head destroy_funcs;
390
391         struct list_head *list;
392         struct list_head link;
393 } tdm_buffer_info;
394
395 typedef struct _tdm_pp_private_buffer {
396         tbm_surface_h src;
397         tbm_surface_h dst;
398         struct list_head link;
399         struct list_head commit_link;
400 } tdm_pp_private_buffer;
401
402 typedef struct _tdm_capture_private_buffer {
403         tbm_surface_h buffer;
404         struct list_head link;
405         struct list_head commit_link;
406 } tdm_capture_private_buffer;
407
408 typedef enum {
409         TDM_THREAD_CB_NONE,
410         TDM_THREAD_CB_OUTPUT_COMMIT,
411         TDM_THREAD_CB_OUTPUT_VBLANK,
412         TDM_THREAD_CB_OUTPUT_STATUS,
413         TDM_THREAD_CB_OUTPUT_DPMS,
414         TDM_THREAD_CB_PP_DONE,
415         TDM_THREAD_CB_CAPTURE_DONE,
416         TDM_THREAD_CB_VBLANK_SW,
417         TDM_THREAD_CB_VBLANK_CREATE,
418         TDM_THREAD_CB_NEED_VALIDATE,
419 } tdm_thread_cb_type;
420
421 typedef struct _tdm_thread_cb_base tdm_thread_cb_base;
422 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_commit;
423 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_vblank;
424 typedef struct _tdm_thread_cb_output_status tdm_thread_cb_output_status;
425 typedef struct _tdm_thread_cb_output_dpms tdm_thread_cb_output_dpms;
426 typedef struct _tdm_thread_cb_pp_done tdm_thread_cb_pp_done;
427 typedef struct _tdm_thread_cb_capture_done tdm_thread_cb_capture_done;
428 typedef struct _tdm_thread_cb_vblank_sw tdm_thread_cb_vblank_sw;
429 typedef struct _tdm_thread_cb_vblank_create tdm_thread_cb_vblank_create;
430 typedef struct _tdm_thread_cb_need_validate tdm_thread_cb_need_validate;
431
432 struct _tdm_thread_cb_base {
433         tdm_thread_cb_type type;
434         unsigned int length;
435 };
436
437 struct _tdm_thread_cb_output_vblank {
438         tdm_thread_cb_base base;
439         double output_stamp;
440         unsigned int sequence;
441         unsigned int tv_sec;
442         unsigned int tv_usec;
443         void *user_data;
444 };
445
446 struct _tdm_thread_cb_output_status {
447         tdm_thread_cb_base base;
448         double output_stamp;
449         tdm_output_conn_status status;
450         void *user_data;
451 };
452
453 struct _tdm_thread_cb_output_dpms {
454         tdm_thread_cb_base base;
455         double output_stamp;
456         tdm_output_dpms dpms;
457         void *user_data;
458 };
459
460 struct _tdm_thread_cb_pp_done {
461         tdm_thread_cb_base base;
462         double pp_stamp;
463         tbm_surface_h src;
464         tbm_surface_h dst;
465         void *user_data;
466 };
467
468 struct _tdm_thread_cb_capture_done {
469         tdm_thread_cb_base base;
470         double capture_stamp;
471         tbm_surface_h buffer;
472         void *user_data;
473 };
474
475 struct _tdm_thread_cb_vblank_sw {
476         tdm_thread_cb_base base;
477         double vblank_stamp;
478 };
479
480 struct _tdm_thread_cb_vblank_create {
481         tdm_thread_cb_base base;
482         double vblank_stamp;
483 };
484
485 struct _tdm_thread_cb_need_validate {
486         tdm_thread_cb_base base;
487         tdm_private_output *o;
488 };
489
490 struct argument_details {
491         char type;
492         int nullable;
493 };
494
495 #ifdef __cplusplus
496 }
497 #endif
498
499 #endif /* _TDM_PRIVATE_TYPES_H_ */