4290cc1f42a6f0c09569b85ad0a7997a35f56903
[platform/adaptation/nexell/libtdm-nexell.git] / src / tdm_nexell.h
1 #ifndef _TDM_NEXELL_H_
2 #define _TDM_NEXELL_H_
3
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <pthread.h>
12 #include <errno.h>
13 #include <unistd.h>
14 #include <limits.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/ioctl.h>
18 #include <fcntl.h>
19
20 #include <xf86drm.h>
21 #include <xf86drmMode.h>
22 #include <tbm_surface.h>
23 #include <tbm_surface_internal.h>
24 #include <tdm_backend.h>
25 #include <tdm_log.h>
26 #include <tdm_list.h>
27
28 #if HAVE_UDEV
29 #include <libudev.h>
30 #endif
31
32 /* drm backend functions (display) */
33 tdm_error    nexell_display_get_capability(tdm_backend_data *bdata, tdm_caps_display *caps);
34 tdm_error    nexell_display_get_pp_capability(tdm_backend_data *bdata, tdm_caps_pp *caps);
35 tdm_output** nexell_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error);
36 tdm_error    nexell_display_get_fd(tdm_backend_data *bdata, int *fd);
37 tdm_error    nexell_display_handle_events(tdm_backend_data *bdata);
38 tdm_pp*      nexell_display_create_pp(tdm_backend_data *bdata, tdm_error *error);
39 tdm_error    nexell_output_get_capability(tdm_output *output, tdm_caps_output *caps);
40 tdm_layer**  nexell_output_get_layers(tdm_output *output, int *count, tdm_error *error);
41 tdm_error    nexell_output_set_property(tdm_output *output, unsigned int id, tdm_value value);
42 tdm_error    nexell_output_get_property(tdm_output *output, unsigned int id, tdm_value *value);
43 tdm_error    nexell_output_wait_vblank(tdm_output *output, int interval, int sync, void *user_data);
44 tdm_error    nexell_output_set_vblank_handler(tdm_output *output, tdm_output_vblank_handler func);
45 tdm_error    nexell_output_commit(tdm_output *output, int sync, void *user_data);
46 tdm_error    nexell_output_set_commit_handler(tdm_output *output, tdm_output_commit_handler func);
47 tdm_error    nexell_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value);
48 tdm_error    nexell_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value);
49 tdm_error    nexell_output_set_mode(tdm_output *output, const tdm_output_mode *mode);
50 tdm_error    nexell_output_get_mode(tdm_output *output, const tdm_output_mode **mode);
51 tdm_error    nexell_output_set_status_handler(tdm_output *output, tdm_output_status_handler func, void *user_data);
52 tdm_error    nexell_layer_get_capability(tdm_layer *layer, tdm_caps_layer *caps);
53 tdm_error    nexell_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value);
54 tdm_error    nexell_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value);
55 tdm_error    nexell_layer_set_info(tdm_layer *layer, tdm_info_layer *info);
56 tdm_error    nexell_layer_get_info(tdm_layer *layer, tdm_info_layer *info);
57 tdm_error    nexell_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
58 tdm_error    nexell_layer_unset_buffer(tdm_layer *layer);
59 void         nexell_pp_destroy(tdm_pp *pp);
60 tdm_error    nexell_pp_set_info(tdm_pp *pp, tdm_info_pp *info);
61 tdm_error    nexell_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst);
62 tdm_error    nexell_pp_commit(tdm_pp *pp);
63 tdm_error    nexell_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, void *user_data);
64
65 /* drm module internal macros, structures, functions */
66 #define NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
67
68 #define C(b,m)              (((b) >> (m)) & 0xFF)
69 #define B(c,s)              ((((unsigned int)(c)) & 0xff) << (s))
70 #define FOURCC(a,b,c,d)     (B(d,24) | B(c,16) | B(b,8) | B(a,0))
71 #define FOURCC_STR(id)      C(id,0), C(id,8), C(id,16), C(id,24)
72
73 #define IS_RGB(format)      (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
74                              format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
75
76 #define CLEAR(x) memset(&(x), 0, sizeof(x))
77 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
78 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
79 #define SWAP(a, b)  ({int t; t = a; a = b; b = t;})
80 #define ROUNDUP(x)  (ceil (floor ((float)(height) / 4)))
81
82 #define ALIGN_TO_16B(x)    ((((x) + (1 <<  4) - 1) >>  4) <<  4)
83 #define ALIGN_TO_32B(x)    ((((x) + (1 <<  5) - 1) >>  5) <<  5)
84 #define ALIGN_TO_128B(x)   ((((x) + (1 <<  7) - 1) >>  7) <<  7)
85 #define ALIGN_TO_2KB(x)    ((((x) + (1 << 11) - 1) >> 11) << 11)
86 #define ALIGN_TO_8KB(x)    ((((x) + (1 << 13) - 1) >> 13) << 13)
87 #define ALIGN_TO_64KB(x)   ((((x) + (1 << 16) - 1) >> 16) << 16)
88
89 #define RETURN_VAL_IF_FAIL(cond, val) {\
90         if (!(cond)) {\
91                 TDM_ERR("'%s' failed", #cond);\
92                 return val;\
93         }\
94 }
95
96 #define GOTO_IF_FAIL(cond, val) {\
97         if (!(cond)) {\
98                 TDM_ERR("'%s' failed", #cond);\
99                 goto val;\
100         }\
101 }
102
103 typedef struct _tdm_nexell_data
104 {
105         tdm_display *dpy;
106
107         int drm_fd;
108
109 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4  && LIBDRM_MICRO_VERSION >= 47
110         int has_universal_plane;
111 #endif
112
113 #if HAVE_UDEV
114         struct udev_monitor *uevent_monitor;
115         tdm_event_loop_source *uevent_source;
116 #endif
117
118         drmModeResPtr mode_res;
119         drmModePlaneResPtr plane_res;
120
121         struct list_head output_list;
122         struct list_head buffer_list;
123 } tdm_nexell_data;
124
125 uint32_t     tdm_nexell_format_to_drm_format(tbm_format format);
126 tbm_format   tdm_nexell_format_to_tbm_format(uint32_t format);
127
128 void         tdm_nexell_display_update_output_status(tdm_nexell_data *nexell_data);
129 tdm_error    tdm_nexell_display_create_output_list(tdm_nexell_data *nexell_data);
130 void         tdm_nexell_display_destroy_output_list(tdm_nexell_data *nexell_data);
131 tdm_error    tdm_nexell_display_create_layer_list(tdm_nexell_data *nexell_data);
132
133 #endif /* _TDM_NEXELL_H_ */