Implementation of TDM_HWC
[platform/adaptation/nexell/libtdm-nexell.git] / src / tdm_nexell_types.h
1 #ifndef _TDM_NEXELL_TYPES_H_
2 #define _TDM_NEXELL_TYPES_H_
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <pthread.h>
8 #include <errno.h>
9 #include <unistd.h>
10 #include <limits.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <sys/ioctl.h>
14 #include <fcntl.h>
15
16 #include <linux/fb.h>
17 #include <xf86drm.h>
18 #include <xf86drmMode.h>
19 #include <tbm_surface.h>
20 #include <tbm_surface_internal.h>
21 #include <tdm_backend.h>
22 #include <tdm_log.h>
23 #include <tdm_list.h>
24 #include <drm_fourcc.h>
25 #include <tdm_helper.h>
26
27 #if HAVE_UDEV
28 #include <libudev.h>
29 #endif
30
31 #define C(b, m)                   (((b) >> (m)) & 0xFF)
32 #define B(c, s)                   ((((unsigned int)(c)) & 0xff) << (s))
33 #define FOURCC(a, b, c, d)       (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
34 #define FOURCC_STR(id)    C(id, 0), C(id, 8), C(id, 16), C(id, 24)
35
36 #define IS_RGB(format)    (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
37                                                    format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
38
39 #define CLEAR(x) memset(&(x), 0, sizeof(x))
40 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
41 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
42 #define SWAP(a, b)  ({int t; t = a; a = b; b = t; })
43 #define ROUNDUP(x)  (ceil(floor((float)(height) / 4)))
44
45 #define ALIGN_TO_16B(x) ((((x) + (1 <<  4) - 1) >>  4) <<  4)
46 #define ALIGN_TO_32B(x) ((((x) + (1 <<  5) - 1) >>  5) <<  5)
47 #define ALIGN_TO_128B(x)   ((((x) + (1 <<  7) - 1) >>  7) <<  7)
48 #define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
49 #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
50 #define ALIGN_TO_64KB(x)   ((((x) + (1 << 16) - 1) >> 16) << 16)
51
52 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
53
54 #define CURSOR_MIN_W 192
55 #define CURSOR_MIN_H 192
56 #define CURSOR_MAX_W 192
57 #define CURSOR_MAX_H 192
58
59 #define NUM_BUFFERS    3
60
61 #define NUM_LAYERS     3
62 #define NUM_UI_LAYERS  2
63 #define ZPOS_MAX       2
64 #define ZPOS_CURSOR    2  // cursor
65 #define ZPOS_2         2  // ui
66 #define ZPOS_1         1  // ui, primary layer
67 #define ZPOS_0         0  // video
68 #define ZPOS_VIDEO1    0  // video
69 #define ZPOS_NONE      -999
70
71 #define RETURN_VAL_IF_FAIL(cond, val) {\
72         if (!(cond)) {\
73                 TDM_ERR("'%s' failed", #cond);\
74                 return val;\
75         } \
76 }
77
78 #define RETURN_IF_FAIL(cond) {\
79         if (!(cond)) {\
80                 TDM_ERR("'%s' failed", #cond);\
81                 return;\
82         } \
83 }
84
85 #define GOTO_IF_FAIL(cond, val) {\
86         if (!(cond)) {\
87                 TDM_ERR("'%s' failed", #cond);\
88                 goto val;\
89         } \
90 }
91
92 typedef struct _tdm_nexell_data tdm_nexell_data;
93 typedef struct _tdm_nexell_output_data tdm_nexell_output_data;
94 typedef struct _tdm_nexell_layer_data tdm_nexell_layer_data;
95 typedef struct _tdm_nexell_hwc_data tdm_nexell_hwc_data;
96 typedef struct _tdm_nexell_hwc_window_data tdm_nexell_hwc_window_data;
97 typedef struct _tdm_nexell_event_data tdm_nexell_event_data;
98 typedef struct _tdm_nexell_display_buffer tdm_nexell_display_buffer;
99
100 typedef enum {
101         TDM_NEXELL_EVENT_TYPE_WAIT,
102         TDM_NEXELL_EVENT_TYPE_COMMIT,
103         TDM_NEXELL_EVENT_TYPE_PAGEFLIP,
104 } tdm_nexell_event_type;
105
106 struct _tdm_nexell_data
107 {
108         tdm_display *dpy;
109
110         int drm_fd;
111         int scaler_fd;
112
113 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4  && LIBDRM_MICRO_VERSION >= 47
114         int has_universal_plane;
115 #endif
116
117 #if HAVE_UDEV
118         struct udev_monitor *uevent_monitor;
119         tdm_event_loop_source *uevent_source;
120 #endif
121
122         drmModeResPtr mode_res;
123         drmModePlaneResPtr plane_res;
124
125         int hwc_mode;
126
127         struct list_head output_list;
128         struct list_head buffer_list;
129 };
130
131 struct _tdm_nexell_display_buffer {
132         struct list_head link;
133
134         unsigned int fb_id;
135         tbm_surface_h buffer;
136         int width;
137         unsigned int height;
138         unsigned int format;
139         unsigned int handles[4];
140         unsigned int fds[4];
141         unsigned int pitches[4];
142         unsigned int offsets[4];
143         unsigned int size;
144         unsigned int count;
145 };
146
147 struct _tdm_nexell_event_data {
148         tdm_nexell_event_type type;
149         tdm_nexell_output_data *output_data;
150         void *user_data;
151 };
152
153 struct _tdm_nexell_output_data {
154         struct list_head link;
155
156         /* data which are fixed at initializing */
157         tdm_nexell_data *nexell_data;
158         uint32_t connector_id;
159         uint32_t encoder_id;
160         uint32_t crtc_id;
161         uint32_t pipe;
162         uint32_t dpms_prop_id;
163         int count_modes;
164         drmModeModeInfoPtr drm_modes;
165         tdm_output_mode *output_modes;
166         tdm_output_type connector_type;
167         unsigned int connector_type_id;
168         struct list_head layer_list;
169         tdm_nexell_layer_data *primary_layer;
170
171         /* not fixed data below */
172         tdm_output_vblank_handler vblank_func;
173         tdm_output_commit_handler commit_func;
174
175         tdm_output_conn_status status;
176         tdm_output_status_handler status_func;
177         void *status_user_data;
178
179         int mode_changed;
180         const tdm_output_mode *current_mode;
181
182         tbm_surface_h crtc_buffer;
183         int crtc_enabled;
184         unsigned int crtc_fb_id;
185
186         /* hwc */
187         int hwc_enable;
188         tdm_nexell_hwc_data *hwc_data;
189 };
190
191 struct _tdm_nexell_layer_data {
192         struct list_head link;
193
194         /* data which are fixed at initializing */
195         tdm_nexell_data *nexell_data;
196         tdm_nexell_output_data *output_data;
197         uint32_t plane_id;
198         tdm_layer_capability capabilities;
199         int zpos;
200
201         /* not fixed data below */
202         tdm_info_layer info;
203         int info_changed;
204
205         tdm_nexell_display_buffer *display_buffer;
206         int display_buffer_changed;
207 };
208
209 struct _tdm_nexell_hwc_data {
210         tdm_nexell_hwc_window_data *target_hwc_window;
211
212         int need_validate;
213         int need_target_window;
214         int need_set_crtc;
215
216         int target_window_zpos;
217
218         tdm_nexell_output_data *output_data;
219         struct list_head hwc_window_list;
220
221         tbm_surface_h cursor_tsurface;
222
223         /* UI buffer_queue list for the reserved scanout memory */
224         struct {
225                 tbm_surface_queue_h tqueue;
226                 int ref_cnt;
227         } ui_buffer_queue[NUM_LAYERS];
228
229         tdm_hwc_commit_handler commit_func;
230 };
231
232 struct _tdm_nexell_hwc_window_data {
233         struct list_head link;
234
235         tdm_nexell_hwc_data *hwc_data;
236
237         tdm_hwc_window_info info;
238         tbm_surface_h surface;
239         tdm_hwc_window_composition client_type;
240         tdm_hwc_window_composition validated_type;
241         int lzpos;
242         int lzpos_queue;
243
244         char name[TDM_NAME_LEN];
245         struct {
246                 int width;
247                 int height;
248                 int stride;
249                 void *ptr;
250         } cursor_img;
251         int cursor_img_surface;
252         int cursor_img_refresh;
253
254         int constraints;
255         tbm_surface_queue_h tqueue;
256 };
257
258 #endif /* _TDM_NEXELL_TYPES_H_ */