97d891956ae68b2b40562ef036dcf188d22e669e
[platform/adaptation/libtdm-drm.git] / src / libhal-backend-tdm-drm / tdm_backend_drm_types.h
1 #ifndef _TDM_DRM_TYPES_H_
2 #define _TDM_DRM_TYPES_H_
3
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <pthread.h>
9 #include <errno.h>
10 #include <unistd.h>
11 #include <limits.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <sys/ioctl.h>
15 #include <fcntl.h>
16 #include <drm.h>
17 #include <drm_fourcc.h>
18
19 #include <xf86drm.h>
20 #include <xf86drmMode.h>
21
22 #include <tbm_surface.h>
23 #include <tbm_surface_internal.h>
24 #include <tbm_surface_queue.h>
25
26 #include <hal-common.h>
27 #include <hal-tdm-types.h>
28 #include <hal-tdm-interface.h>
29 #include <pixman.h>
30
31 #include <linux/fb.h>
32
33 #include "tdm_backend_list.h"
34 #include "tdm_backend_log.h"
35
36 #define MIN_WIDTH   32
37
38 /* drm module internal macros, structures, functions */
39
40 #define C(b, m)                   (((b) >> (m)) & 0xFF)
41 #define B(c, s)                   ((((unsigned int)(c)) & 0xff) << (s))
42 #define FOURCC(a, b, c, d)       (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
43 #define FOURCC_STR(id)    C(id, 0), C(id, 8), C(id, 16), C(id, 24)
44
45 #define IS_RGB(format)    (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
46                                                          format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
47
48 #define CLEAR(x) memset(&(x), 0, sizeof(x))
49 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
50 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
51 #define SWAP(a, b)  ({int t; t = a; a = b; b = t; })
52 #define ROUNDUP(x)  (ceil(floor((float)(height) / 4)))
53
54 #define ALIGN_TO_16B(x) ((((x) + (1 <<  4) - 1) >>  4) <<  4)
55 #define ALIGN_TO_32B(x) ((((x) + (1 <<  5) - 1) >>  5) <<  5)
56 #define ALIGN_TO_128B(x)   ((((x) + (1 <<  7) - 1) >>  7) <<  7)
57 #define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
58 #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
59 #define ALIGN_TO_64KB(x)   ((((x) + (1 << 16) - 1) >> 16) << 16)
60
61 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
62
63 #define CURSOR_MIN_W 192
64 #define CURSOR_MIN_H 192
65 #define CURSOR_MAX_W 192
66 #define CURSOR_MAX_H 192
67
68 #define RETURN_VAL_IF_FAIL(cond, val) {\
69         if (!(cond)) {\
70                 TDM_BACKEND_ERR("'%s' failed", #cond);\
71                 return val;\
72         } \
73 }
74
75 #define RETURN_IF_FAIL(cond) {\
76         if (!(cond)) {\
77                 TDM_BACKEND_ERR("'%s' failed", #cond);\
78                 return;\
79         } \
80 }
81
82 #define GOTO_IF_FAIL(cond, val) {\
83         if (!(cond)) {\
84                 TDM_BACKEND_ERR("'%s' failed", #cond);\
85                 goto val;\
86         } \
87 }
88
89 typedef struct _tdm_drm_display tdm_drm_display;
90 typedef struct _tdm_drm_output_data tdm_drm_output;
91 typedef struct _tdm_drm_layer_data tdm_drm_layer;
92 typedef struct _tdm_drm_hwc_data tdm_drm_hwc;
93 typedef struct _tdm_drm_hwc_window_data tdm_drm_hwc_window_data;
94 typedef struct _tdm_drm_event_data tdm_drm_event_data;
95 typedef struct _tdm_drm_display_buffer tdm_drm_display_buffer;
96
97 typedef enum {
98         TDM_DRM_LAYER_CAPABILITY_CURSOR         = (1 << 0), /**< cursor */
99         TDM_DRM_LAYER_CAPABILITY_PRIMARY        = (1 << 1), /**< primary */
100         TDM_DRM_LAYER_CAPABILITY_OVERLAY        = (1 << 2), /**< overlay */
101         TDM_DRM_LAYER_CAPABILITY_GRAPHIC        = (1 << 4), /**< graphic */
102         TDM_DRM_LAYER_CAPABILITY_VIDEO          = (1 << 5), /**< video */
103         TDM_DRM_LAYER_CAPABILITY_SCALE          = (1 << 8), /**< if a layer_data has scale capability  */
104         TDM_DRM_LAYER_CAPABILITY_TRANSFORM      = (1 << 9), /**< if a layer_data has transform capability  */
105         TDM_DRM_LAYER_CAPABILITY_SCANOUT        = (1 << 10), /**< if a layer_data allows a scanout buffer only */
106         TDM_DRM_LAYER_CAPABILITY_RESEVED_MEMORY = (1 << 11), /**< if a layer_data allows a reserved buffer only */
107         TDM_DRM_LAYER_CAPABILITY_NO_CROP        = (1 << 12), /**< if a layer_data has no cropping capability */
108 } tdm_drm_layer_capability;
109
110 typedef enum {
111                 TDM_DRM_EVENT_TYPE_WAIT,
112                 TDM_DRM_EVENT_TYPE_COMMIT,
113                 TDM_DRM_EVENT_TYPE_PAGEFLIP,
114 } tdm_drm_event_type;
115
116 struct _tdm_drm_display {
117         int drm_fd;
118
119 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4  && LIBDRM_MICRO_VERSION >= 47
120         int has_universal_plane;
121 #endif
122
123 #if HAVE_UDEV
124         struct udev_monitor *uevent_monitor;
125 #endif
126
127         drmModeResPtr mode_res;
128         drmModePlaneResPtr plane_res;
129
130         struct list_head output_list;
131         struct list_head buffer_list;
132 };
133
134 struct _tdm_drm_display_buffer {
135         struct list_head link;
136
137         unsigned int fb_id;
138         tbm_surface_h buffer;
139         int width;
140         unsigned int height;
141         unsigned int format;
142         unsigned int handles[4];
143         unsigned int fds[4];
144         unsigned int pitches[4];
145         unsigned int offsets[4];
146         unsigned int size;
147         unsigned int count;
148 };
149
150 struct _tdm_drm_event_data {
151         tdm_drm_event_type type;
152         tdm_drm_output *output_data;
153         void *user_data;
154 };
155
156 struct _tdm_drm_output_data {
157         struct list_head link;
158
159         /* data which are fixed at initializing */
160         tdm_drm_display *display_data;
161         uint32_t connector_id;
162         uint32_t encoder_id;
163         uint32_t crtc_id;
164         uint32_t pipe;
165         uint32_t dpms_prop_id;
166         int count_modes;
167         drmModeModeInfoPtr drm_modes;
168         hal_tdm_output_mode *output_modes;
169         hal_tdm_output_type connector_type;
170         unsigned int connector_type_id;
171         struct list_head layer_list;
172         tdm_drm_layer *primary_layer;
173
174         /* not fixed data below */
175         hal_tdm_output_vblank_handler vblank_func;
176         hal_tdm_output_commit_handler commit_func;
177
178         hal_tdm_output_conn_status status;
179         hal_tdm_output_status_handler status_func;
180         void *status_user_data;
181
182         int mode_changed;
183         const hal_tdm_output_mode *current_mode;
184
185         /* hwc */
186         tdm_drm_hwc *hwc_data;
187
188         /* dpms */
189         hal_tdm_output_dpms current_dpms;
190 };
191
192 typedef struct _tdm_drm_layer_info {
193         hal_tdm_info_config src_config;
194         hal_tdm_pos dst_pos;
195         hal_tdm_transform transform;
196 } tdm_drm_layer_info;
197
198 typedef struct _tdm_drm_caps_layer {
199         tdm_drm_layer_capability capabilities;  /**< The capabilities of layer_data */
200
201         /**
202          * The z-order
203          * GRAPHIC layers are non-changeable. The zpos of GRAPHIC layers starts
204          * from 0. If there are 4 GRAPHIC layers, The zpos SHOULD be 0, 1, 2, 3.\n
205          * But the zpos of VIDEO layer_data is changeable by layer_set_video_pos() function
206          * of #tdm_func_layer. And The zpos of VIDEO layers is less than GRAPHIC
207          * layers or more than GRAPHIC layers.
208          * ie, ..., -2, -1, 4, 5, ... (if 0 <= GRAPHIC layer_data's zpos < 4).
209          * The zpos of VIDEO layers is @b relative. It doesn't need to start
210          * from -1 or 4. Let's suppose that there are two VIDEO layers.
211          * One has -2 zpos. Another has -4 zpos. Then -2 Video layer_data is higher
212          * than -4 VIDEO layer_data.
213         */
214         int zpos;
215
216         unsigned int format_count;      /**< The count of available formats */
217         tbm_format *formats;            /**< The @b newly-allocated array of formats. will be freed in frontend. */
218
219         unsigned int prop_count;        /**< The count of available properties */
220         hal_tdm_prop *props;                /**< The @b newly-allocated array of properties. will be freed in frontend. */
221 } tdm_drm_caps_layer;
222
223 struct _tdm_drm_layer_data {
224         struct list_head link;
225
226         /* data which are fixed at initializing */
227         tdm_drm_display *display_data;
228         tdm_drm_output *output_data;
229         uint32_t plane_id;
230         tdm_drm_layer_capability capabilities;
231         int zpos;
232
233         /* not fixed data below */
234         tdm_drm_layer_info info;
235         int info_changed;
236
237         tdm_drm_display_buffer *display_buffer;
238         int display_buffer_changed;
239 };
240
241 struct _tdm_drm_hwc_data {
242         tdm_drm_hwc_window_data *target_hwc_window;
243
244         int need_validate;
245         int need_target_window;
246         int need_set_crtc;
247
248         int target_window_zpos;
249
250         tdm_drm_output *output_data;
251         struct list_head hwc_window_list;
252
253         tbm_surface_h cursor_tsurface;
254
255         hal_tdm_hwc_commit_handler commit_func;
256 };
257
258 struct _tdm_drm_hwc_window_data {
259         struct list_head link;
260
261         tdm_drm_hwc *hwc_data;
262
263         hal_tdm_hwc_window_info info;
264         tbm_surface_h surface;
265         hal_tdm_hwc_window_composition client_type;
266         hal_tdm_hwc_window_composition validated_type;
267         int lzpos;
268
269         char name[HAL_TDM_NAME_LEN];
270         struct {
271                 int width;
272                 int height;
273                 int stride;
274                 void *ptr;
275         } cursor_img;
276         int cursor_img_surface;
277         int cursor_img_refresh;
278 };
279
280 #endif /* _TDM_DRM_TYPES_H_ */