d71664a80c31836688e64dd30cc5bc59b5c0854a
[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_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_window tdm_private_hwc_window;
104 typedef struct _tdm_private_pp tdm_private_pp;
105 typedef struct _tdm_private_capture tdm_private_capture;
106 typedef struct _tdm_private_loop tdm_private_loop;
107 typedef struct _tdm_private_server tdm_private_server;
108 typedef struct _tdm_private_thread tdm_private_thread;
109 typedef struct _tdm_private_output_change_handler tdm_private_output_change_handler;
110 typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler;
111 typedef struct _tdm_private_output_vblank_handler tdm_private_output_vblank_handler;
112 typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler;
113 typedef struct _tdm_private_hwc_window_commit_handler tdm_private_hwc_window_commit_handler;
114 typedef struct _tdm_private_output_hwc_target_buffer_window_commit_handler tdm_private_output_hwc_target_buffer_commit_handler;
115
116 typedef struct _tdm_private_layer_buffer tdm_private_layer_buffer;
117
118 struct _tdm_private_module {
119         struct list_head link;
120
121         tdm_private_display *private_display;
122
123         /* backend module info */
124         void *module;
125         tdm_backend_module *module_data;
126         tdm_backend_data *bdata;
127
128         /* backend function */
129         tdm_display_capability capabilities;
130         tdm_func_display func_display;
131         tdm_func_output func_output;
132         tdm_func_layer func_layer;
133         tdm_func_hwc_window func_hwc_window;
134         tdm_func_pp func_pp;
135         tdm_func_capture func_capture;
136
137         /* backend capability */
138         tdm_caps_display caps_display;
139         tdm_caps_pp caps_pp;
140         tdm_caps_capture caps_capture;
141
142         /* output, pp list */
143         struct list_head output_list;
144         struct list_head pp_list;
145         struct list_head capture_list;
146
147         /* backend output objects. allocated in backend. freed in frontend. ordered */
148         tdm_output **outputs;
149
150         int fd;
151         tdm_event_loop_source *event_source;
152 };
153
154 struct _tdm_private_display {
155         pthread_mutex_t lock;
156         unsigned int init_count;
157
158         double stamp;
159
160 #ifdef INIT_BUFMGR
161         tbm_bufmgr bufmgr;
162 #endif
163
164         struct list_head module_list;
165         tdm_private_module *current_module;  //setted only when loading
166         tdm_private_module *pp_module;       //pp-support backend
167         tdm_private_module *capture_module;  //TODO: remove later
168
169         /* for event handling */
170         tdm_private_loop *private_loop;
171
172         int print_fps;
173 };
174
175 struct _tdm_private_output {
176         struct list_head link;
177
178         tdm_private_module *private_module;
179
180         int index;
181         double stamp;
182
183         tdm_private_display *private_display;
184
185         tdm_caps_output caps;
186         tdm_output *output_backend;
187
188         unsigned int pipe;
189         tdm_output_dpms current_dpms_value;
190         unsigned int waiting_dpms_change;
191         const tdm_output_mode *current_mode;
192
193         int regist_vblank_cb;
194         int regist_commit_cb;
195         int regist_change_cb;
196         int regist_dpms_cb;
197
198         struct list_head layer_list;
199         struct list_head hwc_window_list;
200         struct list_head capture_list;
201         struct list_head vblank_handler_list;
202         struct list_head output_commit_handler_list;
203
204         /* for layer commit */
205         struct list_head layer_commit_handler_list;
206         struct list_head pending_commit_handler_list;
207         tdm_vblank *vblank;
208         int layer_waiting_vblank;
209
210         tdm_event_loop_source *vblank_timeout_timer;
211         unsigned int vblank_timeout_timer_expired;
212
213         struct list_head change_handler_list;
214
215         void **layers_ptr;
216
217         struct {
218                 /* look at the tdm_output_set_need_revalidate_handler() declaration for the details */
219                 tdm_output_need_validate_handler hndl;
220                 int event_fd;
221                 tdm_event_loop_source *event_source;
222         } need_validate;
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 };
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_window {
275         struct list_head link;
276
277         int index;
278
279         tdm_private_display *private_display;
280         tdm_private_output *private_output;
281
282         tdm_hwc_window *hwc_window_backend;
283 };
284
285 struct _tdm_private_pp {
286         struct list_head link;
287
288         tdm_private_module *private_module;
289
290         double stamp;
291
292         tdm_private_display *private_display;
293
294         tdm_pp *pp_module;
295
296         struct list_head pending_buffer_list;
297         struct list_head buffer_list;
298
299         tdm_info_pp info;
300         pid_t owner_tid;
301
302         tdm_pp_done_handler done_func;
303         void *done_user_data;
304 };
305
306 struct _tdm_private_capture {
307         struct list_head link;
308         struct list_head display_link;
309
310         tdm_private_module *private_module;
311
312         double stamp;
313
314         tdm_capture_target target;
315
316         tdm_private_display *private_display;
317         tdm_private_output *private_output;
318         tdm_private_layer *private_layer;
319
320         tdm_capture *capture_module;
321
322         struct list_head pending_buffer_list;
323         struct list_head buffer_list;
324
325         tdm_info_capture info;
326         pid_t owner_tid;
327
328         tdm_capture_done_handler done_func;
329         void *done_user_data;
330 };
331
332 /* CAUTION:
333  * Note that we don't need to (un)lock mutex to use this structure. If there is
334  * no TDM thread, all TDM resources are protected by private_display's mutex.
335  * If there is a TDM thread, this struct will be used only in a TDM thread.
336  * So, we don't need to protect this structure by mutex. Not thread-safe.
337  */
338 struct _tdm_private_loop {
339         /* TDM uses wl_event_loop to handle various event sources including the TDM
340          * backend's fd.
341          */
342         struct wl_display *wl_display;
343         struct wl_event_loop *wl_loop;
344
345         /* In event loop, all resources are accessed by this dpy.
346          * CAUTION:
347          * - DO NOT include other private structure in this structure because this
348          *   struct is not protected by mutex.
349          */
350         tdm_display *dpy;
351
352         /* for handling TDM client requests */
353         tdm_private_server *private_server;
354
355         /* To have a TDM event thread. If TDM_THREAD enviroment variable is not set
356          * private_thread is NULL.
357          */
358         tdm_private_thread *private_thread;
359 };
360
361 struct _tdm_private_output_vblank_handler {
362         struct list_head link;
363
364         tdm_private_output *private_output;
365         int interval;
366         int sync;
367         tdm_output_vblank_handler func;
368         void *user_data;
369
370         unsigned int sent_to_frontend;
371
372         pid_t owner_tid;
373 };
374
375 struct _tdm_private_output_change_handler {
376         struct list_head link;
377
378         tdm_private_output *private_output;
379         tdm_output_change_handler func;
380         void *user_data;
381
382         pid_t owner_tid;
383 };
384
385 struct _tdm_private_output_commit_handler {
386         struct list_head link;
387
388         tdm_private_output *private_output;
389         tdm_output_commit_handler func;
390         void *user_data;
391
392         pid_t owner_tid;
393 };
394
395 struct _tdm_private_hwc_window_commit_handler {
396         tdm_private_hwc_window *private_hwc_window;
397         tdm_hwc_window_commit_handler func;
398         void *user_data;
399 };
400
401 struct _tdm_private_output_hwc_target_buffer_window_commit_handler {
402         tdm_private_output *private_output;
403         tdm_output_hwc_target_buffer_commit_handler func;
404         void *user_data;
405 };
406
407 struct _tdm_private_layer_commit_handler {
408         struct list_head link;
409
410         tdm_private_layer *private_layer;
411         tdm_layer_commit_handler func;
412         void *user_data;
413
414         tdm_private_layer_buffer *committed_buffer;   /* for layer_commit */
415 };
416
417 struct _tdm_private_layer_buffer {
418         tbm_surface_h buffer;
419         struct list_head link;
420 };
421
422 typedef struct _tdm_buffer_info {
423         tbm_surface_h buffer;
424
425         /* ref_count for backend */
426         int backend_ref_count;
427
428         struct list_head release_funcs;
429         struct list_head destroy_funcs;
430
431         struct list_head *list;
432         struct list_head link;
433 } tdm_buffer_info;
434
435 typedef struct _tdm_pp_private_buffer {
436         tbm_surface_h src;
437         tbm_surface_h dst;
438         struct list_head link;
439         struct list_head commit_link;
440 } tdm_pp_private_buffer;
441
442 typedef struct _tdm_capture_private_buffer {
443         tbm_surface_h buffer;
444         struct list_head link;
445         struct list_head commit_link;
446 } tdm_capture_private_buffer;
447
448 typedef enum {
449         TDM_THREAD_CB_NONE,
450         TDM_THREAD_CB_EXIT,             /* special type to exit the tdm-thread */
451         TDM_THREAD_CB_OUTPUT_COMMIT,
452         TDM_THREAD_CB_OUTPUT_VBLANK,
453         TDM_THREAD_CB_OUTPUT_STATUS,
454         TDM_THREAD_CB_OUTPUT_DPMS,
455         TDM_THREAD_CB_PP_DONE,
456         TDM_THREAD_CB_CAPTURE_DONE,
457         TDM_THREAD_CB_VBLANK_SW,
458         TDM_THREAD_CB_VBLANK_CREATE,
459         TDM_THREAD_CB_NEED_VALIDATE,
460         TDM_THREAD_CB_MAX,
461 } tdm_thread_cb_type;
462
463 typedef struct _tdm_thread_cb_base tdm_thread_cb_base;
464 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_commit;
465 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_vblank;
466 typedef struct _tdm_thread_cb_output_dpms tdm_thread_cb_output_dpms;
467 typedef struct _tdm_thread_cb_output_status tdm_thread_cb_output_status;
468 typedef struct _tdm_thread_cb_pp_done tdm_thread_cb_pp_done;
469 typedef struct _tdm_thread_cb_capture_done tdm_thread_cb_capture_done;
470 typedef struct _tdm_thread_cb_vblank_sw tdm_thread_cb_vblank_sw;
471 typedef struct _tdm_thread_cb_vblank_create tdm_thread_cb_vblank_create;
472 typedef struct _tdm_thread_cb_need_validate tdm_thread_cb_need_validate;
473
474 struct _tdm_thread_cb_base {
475         tdm_thread_cb_type type;
476         unsigned int length;
477         double object_stamp;
478         void *data;
479         unsigned int sync;
480 };
481
482 struct _tdm_thread_cb_output_vblank {
483         tdm_thread_cb_base base;
484         unsigned int sequence;
485         unsigned int tv_sec;
486         unsigned int tv_usec;
487 };
488
489 struct _tdm_thread_cb_output_status {
490         tdm_thread_cb_base base;
491         tdm_output_conn_status status;
492 };
493
494 struct _tdm_thread_cb_output_dpms {
495         tdm_thread_cb_base base;
496         tdm_output_dpms dpms;
497 };
498
499 struct _tdm_thread_cb_pp_done {
500         tdm_thread_cb_base base;
501         tbm_surface_h src;
502         tbm_surface_h dst;
503 };
504
505 struct _tdm_thread_cb_capture_done {
506         tdm_thread_cb_base base;
507         tbm_surface_h buffer;
508 };
509
510 struct _tdm_thread_cb_vblank_sw {
511         tdm_thread_cb_base base;
512 };
513
514 struct _tdm_thread_cb_vblank_create {
515         tdm_thread_cb_base base;
516         double vblank_stamp;
517 };
518
519 struct _tdm_thread_cb_need_validate {
520         tdm_thread_cb_base base;
521 };
522
523 struct argument_details {
524         char type;
525         int nullable;
526 };
527
528 #ifdef __cplusplus
529 }
530 #endif
531
532 #endif /* _TDM_PRIVATE_TYPES_H_ */