hwc: redesign the hwc
[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 <boram1288.park@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 tdm_private_hwc;
104 typedef struct _tdm_private_hwc_window tdm_private_hwc_window;
105 typedef struct _tdm_private_pp tdm_private_pp;
106 typedef struct _tdm_private_capture tdm_private_capture;
107 typedef struct _tdm_private_loop tdm_private_loop;
108 typedef struct _tdm_private_server tdm_private_server;
109 typedef struct _tdm_private_thread tdm_private_thread;
110 typedef struct _tdm_private_output_change_handler tdm_private_output_change_handler;
111 typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler;
112 typedef struct _tdm_private_output_vblank_handler tdm_private_output_vblank_handler;
113 typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler;
114 typedef struct _tdm_private_hwc_commit_handler tdm_private_hwc_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 func_hwc;
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         /* backend output objects. allocated in backend. freed in frontend. ordered */
149         tdm_output **outputs;
150
151         int fd;
152         tdm_event_loop_source *event_source;
153 };
154
155 struct _tdm_private_display {
156         pthread_mutex_t lock;
157         unsigned int init_count;
158
159         double stamp;
160
161 #ifdef INIT_BUFMGR
162         tbm_bufmgr bufmgr;
163 #endif
164
165         struct list_head module_list;
166         tdm_private_module *current_module;  //setted only when loading
167         tdm_private_module *pp_module;       //pp-support backend
168         tdm_private_module *capture_module;  //TODO: remove later
169
170         /* for event handling */
171         tdm_private_loop *private_loop;
172
173         int print_fps;
174 };
175
176 struct _tdm_private_output {
177         struct list_head link;
178
179         tdm_private_module *private_module;
180
181         int index;
182         double stamp;
183
184         tdm_private_display *private_display;
185
186         tdm_caps_output caps;
187         tdm_output *output_backend;
188
189         unsigned int pipe;
190         tdm_output_dpms current_dpms_value;
191         unsigned int waiting_dpms_change;
192         const tdm_output_mode *current_mode;
193
194         int regist_vblank_cb;
195         int regist_commit_cb;
196         int regist_change_cb;
197         int regist_dpms_cb;
198
199         struct list_head layer_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         tdm_info_layer target_buffer_info; /* layer_info for the target_buffer */
218
219         /* calling a output commit per a vblank */
220         int commit_per_vblank;
221         tdm_commit_type commit_type;
222
223         /* for ttrace vblank */
224         tdm_vblank *ttrace_vblank;
225
226         /* hwc */
227         int need_set_target_info;
228         tdm_private_hwc *private_hwc;
229 };
230
231 struct _tdm_private_layer {
232         struct list_head link;
233
234         tdm_private_module *private_module;
235
236         int index;
237
238         tdm_private_display *private_display;
239         tdm_private_output *private_output;
240
241         tdm_caps_layer caps;
242         tdm_layer *layer_backend;
243
244         /* pending data until committed */
245         unsigned int pending_info_changed;
246         tdm_info_layer pending_info;
247         unsigned int pending_buffer_changed;
248         tbm_surface_h pending_buffer;
249
250         /* When a buffer is set to a layer, it will be stored to waiting_buffer.
251          * And when a layer is committed, it will be moved to committed_buffer.
252          * Finally when a commit handler is called, it will be moved to showing_buffer.
253          */
254         tdm_private_layer_buffer *waiting_buffer;
255         tdm_private_layer_buffer *committed_buffer;   /* for output_commit */
256         tdm_private_layer_buffer *showing_buffer;
257         tbm_surface_queue_h buffer_queue;
258
259         struct list_head capture_list;
260
261         unsigned int usable;
262         unsigned int committing;
263
264         double fps_stamp;
265         unsigned int fps_count;
266 };
267
268 struct _tdm_private_hwc {
269         struct list_head link;
270
271         tdm_private_module *private_module;
272
273         int index;
274         double stamp;
275
276         tdm_private_output *private_output;
277
278         struct list_head hwc_window_list;
279         struct list_head hwc_commit_handler_list;
280
281         int regist_commit_cb;
282
283         tdm_hwc *hwc_backend;
284 };
285
286 struct _tdm_private_hwc_window {
287         struct list_head link;
288
289         tdm_private_module *private_module;
290
291         tdm_private_hwc *private_hwc;
292         tdm_hwc_window *hwc_window_backend;
293 };
294
295 struct _tdm_private_pp {
296         struct list_head link;
297
298         tdm_private_module *private_module;
299
300         double stamp;
301
302         tdm_private_display *private_display;
303
304         tdm_pp *pp_module;
305
306         struct list_head pending_buffer_list;
307         struct list_head buffer_list;
308
309         tdm_info_pp info;
310         pid_t owner_tid;
311
312         tdm_pp_done_handler done_func;
313         void *done_user_data;
314 };
315
316 struct _tdm_private_capture {
317         struct list_head link;
318         struct list_head display_link;
319
320         tdm_private_module *private_module;
321
322         double stamp;
323
324         tdm_capture_target target;
325
326         tdm_private_display *private_display;
327         tdm_private_output *private_output;
328         tdm_private_layer *private_layer;
329
330         tdm_capture *capture_module;
331
332         struct list_head pending_buffer_list;
333         struct list_head buffer_list;
334
335         tdm_info_capture info;
336         pid_t owner_tid;
337
338         tdm_capture_done_handler done_func;
339         void *done_user_data;
340 };
341
342 /* CAUTION:
343  * Note that we don't need to (un)lock mutex to use this structure. If there is
344  * no TDM thread, all TDM resources are protected by private_display's mutex.
345  * If there is a TDM thread, this struct will be used only in a TDM thread.
346  * So, we don't need to protect this structure by mutex. Not thread-safe.
347  */
348 struct _tdm_private_loop {
349         /* TDM uses wl_event_loop to handle various event sources including the TDM
350          * backend's fd.
351          */
352         struct wl_display *wl_display;
353         struct wl_event_loop *wl_loop;
354
355         /* In event loop, all resources are accessed by this dpy.
356          * CAUTION:
357          * - DO NOT include other private structure in this structure because this
358          *   struct is not protected by mutex.
359          */
360         tdm_display *dpy;
361
362         /* for handling TDM client requests */
363         tdm_private_server *private_server;
364
365         /* To have a TDM event thread. If TDM_THREAD enviroment variable is not set
366          * private_thread is NULL.
367          */
368         tdm_private_thread *private_thread;
369
370         struct list_head source_list;
371 };
372
373 struct _tdm_private_output_vblank_handler {
374         struct list_head link;
375
376         tdm_private_output *private_output;
377         int interval;
378         int sync;
379         tdm_output_vblank_handler func;
380         void *user_data;
381
382         unsigned int sent_to_frontend;
383
384         pid_t owner_tid;
385 };
386
387 struct _tdm_private_output_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_output_commit_handler {
398         struct list_head link;
399
400         tdm_private_output *private_output;
401         tdm_output_commit_handler func;
402         void *user_data;
403
404         pid_t owner_tid;
405 };
406
407 struct _tdm_private_hwc_commit_handler {
408         struct list_head link;
409
410         tdm_private_hwc *private_hwc;
411         tdm_hwc_commit_handler func;
412         void *user_data;
413
414         pid_t owner_tid;
415 };
416
417 struct _tdm_private_layer_commit_handler {
418         struct list_head link;
419
420         tdm_private_layer *private_layer;
421         tdm_layer_commit_handler func;
422         void *user_data;
423
424         tdm_private_layer_buffer *committed_buffer;   /* for layer_commit */
425 };
426
427 struct _tdm_private_layer_buffer {
428         tbm_surface_h buffer;
429         struct list_head link;
430 };
431
432 typedef struct _tdm_buffer_info {
433         tbm_surface_h buffer;
434
435         /* ref_count for backend */
436         int backend_ref_count;
437
438         struct list_head release_funcs;
439         struct list_head destroy_funcs;
440
441         struct list_head *list;
442         struct list_head link;
443 } tdm_buffer_info;
444
445 typedef struct _tdm_pp_private_buffer {
446         tbm_surface_h src;
447         tbm_surface_h dst;
448         struct list_head link;
449         struct list_head commit_link;
450 } tdm_pp_private_buffer;
451
452 typedef struct _tdm_capture_private_buffer {
453         tbm_surface_h buffer;
454         struct list_head link;
455         struct list_head commit_link;
456 } tdm_capture_private_buffer;
457
458 typedef enum {
459         TDM_THREAD_CB_NONE,
460         TDM_THREAD_CB_EXIT,             /* special type to exit the tdm-thread */
461         TDM_THREAD_CB_OUTPUT_COMMIT,
462         TDM_THREAD_CB_OUTPUT_VBLANK,
463         TDM_THREAD_CB_OUTPUT_STATUS,
464         TDM_THREAD_CB_OUTPUT_DPMS,
465         TDM_THREAD_CB_PP_DONE,
466         TDM_THREAD_CB_CAPTURE_DONE,
467         TDM_THREAD_CB_VBLANK_SW,
468         TDM_THREAD_CB_VBLANK_CREATE,
469         TDM_THREAD_CB_HWC_COMMIT,
470         TDM_THREAD_CB_MAX,
471 } tdm_thread_cb_type;
472
473 typedef struct _tdm_thread_cb_base tdm_thread_cb_base;
474 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_commit;
475 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_vblank;
476 typedef struct _tdm_thread_cb_output_dpms tdm_thread_cb_output_dpms;
477 typedef struct _tdm_thread_cb_output_status tdm_thread_cb_output_status;
478 typedef struct _tdm_thread_cb_pp_done tdm_thread_cb_pp_done;
479 typedef struct _tdm_thread_cb_capture_done tdm_thread_cb_capture_done;
480 typedef struct _tdm_thread_cb_vblank_sw tdm_thread_cb_vblank_sw;
481 typedef struct _tdm_thread_cb_vblank_create tdm_thread_cb_vblank_create;
482 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_hwc_commit;
483
484 struct _tdm_thread_cb_base {
485         tdm_thread_cb_type type;
486         unsigned int length;
487         double object_stamp;
488         void *data;
489         unsigned int sync;
490 };
491
492 struct _tdm_thread_cb_output_vblank {
493         tdm_thread_cb_base base;
494         unsigned int sequence;
495         unsigned int tv_sec;
496         unsigned int tv_usec;
497 };
498
499 struct _tdm_thread_cb_output_status {
500         tdm_thread_cb_base base;
501         tdm_output_conn_status status;
502 };
503
504 struct _tdm_thread_cb_output_dpms {
505         tdm_thread_cb_base base;
506         tdm_output_dpms dpms;
507 };
508
509 struct _tdm_thread_cb_pp_done {
510         tdm_thread_cb_base base;
511         tbm_surface_h src;
512         tbm_surface_h dst;
513 };
514
515 struct _tdm_thread_cb_capture_done {
516         tdm_thread_cb_base base;
517         tbm_surface_h buffer;
518 };
519
520 struct _tdm_thread_cb_vblank_sw {
521         tdm_thread_cb_base base;
522 };
523
524 struct _tdm_thread_cb_vblank_create {
525         tdm_thread_cb_base base;
526         double vblank_stamp;
527 };
528
529 struct argument_details {
530         char type;
531         int nullable;
532 };
533
534 #ifdef __cplusplus
535 }
536 #endif
537
538 #endif /* _TDM_PRIVATE_TYPES_H_ */