Split native drm part of compositor out
[profile/ivi/wayland.git] / compositor.h
1 /*
2  * Copyright © 2008 Kristian Høgsberg
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
20 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
21
22 #include <termios.h>
23 #include <xf86drm.h>
24 #include <xf86drmMode.h>
25 #include <libudev.h>
26 #include "wayland.h"
27 #include "wayland-util.h"
28
29 #include <EGL/egl.h>
30 #include <EGL/eglext.h>
31
32 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
33
34 struct wlsc_matrix {
35         GLfloat d[16];
36 };
37
38 struct wl_visual {
39         struct wl_object base;
40 };
41
42 struct wlsc_surface;
43
44 struct wlsc_listener {
45         struct wl_list link;
46         void (*func)(struct wlsc_listener *listener,
47                      struct wlsc_surface *surface);
48 };
49
50 struct wlsc_output {
51         struct wl_object base;
52         struct wl_list link;
53         struct wlsc_compositor *compositor;
54         struct wlsc_surface *background;
55         struct wlsc_matrix matrix;
56         int32_t x, y, width, height;
57
58         drmModeModeInfo mode;
59         uint32_t crtc_id;
60         uint32_t connector_id;
61
62         GLuint rbo[2];
63         uint32_t fb_id[2];
64         EGLImageKHR image[2];
65         uint32_t current;       
66 };
67
68 struct wlsc_input_device {
69         struct wl_object base;
70         int32_t x, y;
71         struct wlsc_compositor *ec;
72         struct wlsc_surface *sprite;
73         struct wl_list link;
74
75         int grab;
76         struct wlsc_surface *grab_surface;
77         struct wlsc_surface *pointer_focus;
78         struct wlsc_surface *keyboard_focus;
79         struct wl_array keys;
80
81         struct wlsc_listener listener;
82 };
83
84 struct wlsc_compositor {
85         struct wl_compositor base;
86         struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual;
87
88         EGLDisplay display;
89         EGLContext context;
90         int drm_fd;
91         GLuint fbo, vbo;
92         GLuint proj_uniform, tex_uniform;
93         struct wl_display *wl_display;
94
95         /* There can be more than one, but not right now... */
96         struct wlsc_input_device *input_device;
97
98         struct wl_list output_list;
99         struct wl_list input_device_list;
100         struct wl_list surface_list;
101
102         struct wl_list surface_destroy_listener_list;
103
104         struct wl_event_source *term_signal_source;
105
106         /* tty handling state */
107         int tty_fd;
108         uint32_t vt_active : 1;
109
110         struct termios terminal_attributes;
111         struct wl_event_source *tty_input_source;
112         struct wl_event_source *enter_vt_source;
113         struct wl_event_source *leave_vt_source;
114
115         struct udev *udev;
116
117         /* Repaint state. */
118         struct wl_event_source *timer_source;
119         int repaint_needed;
120         int repaint_on_timeout;
121         struct timespec previous_swap;
122         uint32_t current_frame;
123         struct wl_event_source *drm_source;
124
125         uint32_t modifier_state;
126 };
127
128 #define MODIFIER_CTRL   (1 << 8)
129 #define MODIFIER_ALT    (1 << 9)
130
131 struct wlsc_vector {
132         GLfloat f[4];
133 };
134
135 struct wlsc_surface {
136         struct wl_surface base;
137         struct wlsc_compositor *compositor;
138         struct wl_visual *visual;
139         GLuint texture;
140         EGLImageKHR image;
141         int width, height;
142         struct wl_list link;
143         struct wlsc_matrix matrix;
144         struct wlsc_matrix matrix_inv;
145 };
146
147 void
148 notify_motion(struct wlsc_input_device *device, int x, int y);
149 void
150 notify_button(struct wlsc_input_device *device, int32_t button, int32_t state);
151 void
152 notify_key(struct wlsc_input_device *device, uint32_t key, uint32_t state);
153
154 void
155 wlsc_compositor_present_drm(struct wlsc_compositor *wlsc);
156 int
157 wlsc_compositor_init_drm(struct wlsc_compositor *ec);
158 void
159 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
160 struct wlsc_input_device *
161 wlsc_input_device_create(struct wlsc_compositor *ec);
162
163 void
164 screenshooter_create(struct wlsc_compositor *ec);
165
166 extern const char *option_background;
167 extern int option_connector;
168
169 #endif