1 #ifndef _TDM_DRM_TYPES_H_
2 #define _TDM_DRM_TYPES_H_
12 #include <sys/types.h>
14 #include <sys/ioctl.h>
17 #include <drm_fourcc.h>
20 #include <xf86drmMode.h>
22 #include <tbm_surface.h>
23 #include <tbm_surface_internal.h>
24 #include <tbm_surface_queue.h>
26 #include <hal-common.h>
27 #include <hal-tdm-types.h>
28 #include <hal-tdm-interface.h>
33 #include "tdm_backend_list.h"
34 #include "tdm_backend_log.h"
38 /* drm module internal macros, structures, functions */
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)
45 #define IS_RGB(format) (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
46 format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
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)))
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)
61 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
63 #define CURSOR_MIN_W 192
64 #define CURSOR_MIN_H 192
65 #define CURSOR_MAX_W 192
66 #define CURSOR_MAX_H 192
68 #define RETURN_VAL_IF_FAIL(cond, val) {\
70 TDM_BACKEND_ERR("'%s' failed", #cond);\
75 #define RETURN_IF_FAIL(cond) {\
77 TDM_BACKEND_ERR("'%s' failed", #cond);\
82 #define GOTO_IF_FAIL(cond, val) {\
84 TDM_BACKEND_ERR("'%s' failed", #cond);\
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;
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;
111 TDM_DRM_EVENT_TYPE_WAIT,
112 TDM_DRM_EVENT_TYPE_COMMIT,
113 TDM_DRM_EVENT_TYPE_PAGEFLIP,
114 } tdm_drm_event_type;
116 struct _tdm_drm_display {
119 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
120 int has_universal_plane;
124 struct udev_monitor *uevent_monitor;
127 drmModeResPtr mode_res;
128 drmModePlaneResPtr plane_res;
130 struct list_head output_list;
131 struct list_head buffer_list;
134 struct _tdm_drm_display_buffer {
135 struct list_head link;
138 tbm_surface_h buffer;
142 unsigned int handles[4];
144 unsigned int pitches[4];
145 unsigned int offsets[4];
150 struct _tdm_drm_event_data {
151 tdm_drm_event_type type;
152 tdm_drm_output *output_data;
156 struct _tdm_drm_output_data {
157 struct list_head link;
159 /* data which are fixed at initializing */
160 tdm_drm_display *display_data;
161 uint32_t connector_id;
165 uint32_t dpms_prop_id;
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;
174 /* not fixed data below */
175 hal_tdm_output_vblank_handler vblank_func;
176 hal_tdm_output_commit_handler commit_func;
178 hal_tdm_output_conn_status status;
179 hal_tdm_output_status_handler status_func;
180 void *status_user_data;
183 const hal_tdm_output_mode *current_mode;
186 tdm_drm_hwc *hwc_data;
189 hal_tdm_output_dpms current_dpms;
192 typedef struct _tdm_drm_layer_info {
193 hal_tdm_info_config src_config;
195 hal_tdm_transform transform;
196 } tdm_drm_layer_info;
198 typedef struct _tdm_drm_caps_layer {
199 tdm_drm_layer_capability capabilities; /**< The capabilities of layer_data */
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.
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. */
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;
223 struct _tdm_drm_layer_data {
224 struct list_head link;
226 /* data which are fixed at initializing */
227 tdm_drm_display *display_data;
228 tdm_drm_output *output_data;
230 tdm_drm_layer_capability capabilities;
233 /* not fixed data below */
234 tdm_drm_layer_info info;
237 tdm_drm_display_buffer *display_buffer;
238 int display_buffer_changed;
241 struct _tdm_drm_hwc_data {
242 tdm_drm_hwc_window_data *target_hwc_window;
245 int need_target_window;
248 int target_window_zpos;
250 tdm_drm_output *output_data;
251 struct list_head hwc_window_list;
253 tbm_surface_h cursor_tsurface;
255 hal_tdm_hwc_commit_handler commit_func;
258 struct _tdm_drm_hwc_window_data {
259 struct list_head link;
261 tdm_drm_hwc *hwc_data;
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;
269 char name[HAL_TDM_NAME_LEN];
276 int cursor_img_surface;
277 int cursor_img_refresh;
280 #endif /* _TDM_DRM_TYPES_H_ */