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