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