34ca5324d758b681720c1aa9e30c1b9388edb8b2
[platform/adaptation/libtdm-drm.git] / src / libtdm-drm / tdm_drm_types.h
1 #ifndef _TDM_DRM_TYPES_H_
2 #define _TDM_DRM_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 MIN_WIDTH   32
32
33 /* drm module internal macros, structures, functions */
34 #define NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
35
36 #define C(b, m)                   (((b) >> (m)) & 0xFF)
37 #define B(c, s)                   ((((unsigned int)(c)) & 0xff) << (s))
38 #define FOURCC(a, b, c, d)       (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
39 #define FOURCC_STR(id)    C(id, 0), C(id, 8), C(id, 16), C(id, 24)
40
41 #define IS_RGB(format)    (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
42                                                          format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
43
44 #define CLEAR(x) memset(&(x), 0, sizeof(x))
45 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
46 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
47 #define SWAP(a, b)  ({int t; t = a; a = b; b = t; })
48 #define ROUNDUP(x)  (ceil(floor((float)(height) / 4)))
49
50 #define ALIGN_TO_16B(x) ((((x) + (1 <<  4) - 1) >>  4) <<  4)
51 #define ALIGN_TO_32B(x) ((((x) + (1 <<  5) - 1) >>  5) <<  5)
52 #define ALIGN_TO_128B(x)   ((((x) + (1 <<  7) - 1) >>  7) <<  7)
53 #define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
54 #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
55 #define ALIGN_TO_64KB(x)   ((((x) + (1 << 16) - 1) >> 16) << 16)
56
57 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
58
59 #define CURSOR_MIN_W 192
60 #define CURSOR_MIN_H 192
61 #define CURSOR_MAX_W 192
62 #define CURSOR_MAX_H 192
63
64 #define RETURN_VAL_IF_FAIL(cond, val) {\
65         if (!(cond)) {\
66                 TDM_ERR("'%s' failed", #cond);\
67                 return val;\
68         } \
69 }
70
71 #define RETURN_IF_FAIL(cond) {\
72         if (!(cond)) {\
73                 TDM_ERR("'%s' failed", #cond);\
74                 return;\
75         } \
76 }
77
78 #define GOTO_IF_FAIL(cond, val) {\
79         if (!(cond)) {\
80                 TDM_ERR("'%s' failed", #cond);\
81                 goto val;\
82         } \
83 }
84
85 typedef struct _tdm_drm_data tdm_drm_data;
86 typedef struct _tdm_drm_output_data tdm_drm_output_data;
87 typedef struct _tdm_drm_layer_data tdm_drm_layer_data;
88 typedef struct _tdm_drm_hwc_data tdm_drm_hwc_data;
89 typedef struct _tdm_drm_hwc_window_data tdm_drm_hwc_window_data;
90 typedef struct _tdm_drm_event_data tdm_drm_event_data;
91 typedef struct _tdm_drm_display_buffer tdm_drm_display_buffer;
92
93 typedef enum {
94                 TDM_DRM_EVENT_TYPE_WAIT,
95                 TDM_DRM_EVENT_TYPE_COMMIT,
96                 TDM_DRM_EVENT_TYPE_PAGEFLIP,
97 } tdm_drm_event_type;
98
99 struct _tdm_drm_data {
100         tdm_display *dpy;
101
102         int drm_fd;
103
104 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4  && LIBDRM_MICRO_VERSION >= 47
105         int has_universal_plane;
106 #endif
107
108 #if HAVE_UDEV
109         struct udev_monitor *uevent_monitor;
110         tdm_event_loop_source *uevent_source;
111 #endif
112
113         drmModeResPtr mode_res;
114         drmModePlaneResPtr plane_res;
115
116         int hwc_mode;
117
118         struct list_head output_list;
119         struct list_head buffer_list;
120 };
121
122 struct _tdm_drm_display_buffer {
123         struct list_head link;
124
125         unsigned int fb_id;
126         tbm_surface_h buffer;
127         int width;
128         unsigned int height;
129         unsigned int format;
130         unsigned int handles[4];
131         unsigned int fds[4];
132         unsigned int pitches[4];
133         unsigned int offsets[4];
134         unsigned int size;
135         unsigned int count;
136 };
137
138 struct _tdm_drm_event_data {
139         tdm_drm_event_type type;
140         tdm_drm_output_data *output_data;
141         void *user_data;
142 };
143
144 struct _tdm_drm_output_data {
145         struct list_head link;
146
147         /* data which are fixed at initializing */
148         tdm_drm_data *drm_data;
149         uint32_t connector_id;
150         uint32_t encoder_id;
151         uint32_t crtc_id;
152         uint32_t pipe;
153         uint32_t dpms_prop_id;
154         int count_modes;
155         drmModeModeInfoPtr drm_modes;
156         tdm_output_mode *output_modes;
157         tdm_output_type connector_type;
158         unsigned int connector_type_id;
159         struct list_head layer_list;
160         tdm_drm_layer_data *primary_layer;
161
162         /* not fixed data below */
163         tdm_output_vblank_handler vblank_func;
164         tdm_output_commit_handler commit_func;
165
166         tdm_output_conn_status status;
167         tdm_output_status_handler status_func;
168         void *status_user_data;
169
170         int mode_changed;
171         const tdm_output_mode *current_mode;
172
173         /* hwc */
174         int hwc_enable;
175         tdm_drm_hwc_data *hwc_data;
176
177         /* dpms */
178         tdm_output_dpms current_dpms;
179 };
180
181 struct _tdm_drm_layer_data {
182         struct list_head link;
183
184         /* data which are fixed at initializing */
185         tdm_drm_data *drm_data;
186         tdm_drm_output_data *output_data;
187         uint32_t plane_id;
188         tdm_layer_capability capabilities;
189         int zpos;
190
191         /* not fixed data below */
192         tdm_info_layer info;
193         int info_changed;
194
195         tdm_drm_display_buffer *display_buffer;
196         int display_buffer_changed;
197 };
198
199 struct _tdm_drm_hwc_data {
200         tdm_drm_hwc_window_data *target_hwc_window;
201
202         int need_validate;
203         int need_target_window;
204         int need_set_crtc;
205
206         int target_window_zpos;
207
208         tdm_drm_output_data *output_data;
209         struct list_head hwc_window_list;
210
211         tbm_surface_h cursor_tsurface;
212
213         tdm_hwc_commit_handler commit_func;
214 };
215
216 struct _tdm_drm_hwc_window_data {
217         struct list_head link;
218
219         tdm_drm_hwc_data *hwc_data;
220
221         tdm_hwc_window_info info;
222         tbm_surface_h surface;
223         tdm_hwc_window_composition client_type;
224         tdm_hwc_window_composition validated_type;
225         int lzpos;
226
227         char name[TDM_NAME_LEN];
228         struct {
229                 int width;
230                 int height;
231                 int stride;
232                 void *ptr;
233         } cursor_img;
234         int cursor_img_surface;
235         int cursor_img_refresh;
236 };
237
238 #endif /* _TDM_DRM_TYPES_H_ */