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