compositor-wayland: Use wayland-egl window surfaces
[profile/ivi/weston.git] / compositor / 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 <xf86drm.h>
23 #include <xf86drmMode.h>
24 #include <libudev.h>
25 #include <pixman.h>
26 #include "wayland-server.h"
27 #include "wayland-util.h"
28
29 #define GL_GLEXT_PROTOTYPES
30 #define EGL_EGLEXT_PROTOTYPES
31 #include <GLES2/gl2.h>
32 #include <GLES2/gl2ext.h>
33 #include <EGL/egl.h>
34 #include <EGL/eglext.h>
35
36 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
37
38 struct wlsc_matrix {
39         GLfloat d[16];
40 };
41
42 struct wlsc_surface;
43
44 struct wlsc_output {
45         struct wl_object object;
46         struct wl_list link;
47         struct wlsc_compositor *compositor;
48         struct wlsc_surface *background;
49         struct wlsc_matrix matrix;
50         int32_t x, y, width, height;
51         pixman_region32_t previous_damage_region;
52 };
53
54 enum wlsc_pointer_type {
55         WLSC_POINTER_BOTTOM_LEFT,
56         WLSC_POINTER_BOTTOM_RIGHT,
57         WLSC_POINTER_BOTTOM,
58         WLSC_POINTER_DRAGGING,
59         WLSC_POINTER_LEFT_PTR,
60         WLSC_POINTER_LEFT,
61         WLSC_POINTER_RIGHT,
62         WLSC_POINTER_TOP_LEFT,
63         WLSC_POINTER_TOP_RIGHT,
64         WLSC_POINTER_TOP,
65         WLSC_POINTER_IBEAM,
66 };
67
68 struct wlsc_input_device {
69         struct wl_input_device input_device;
70         struct wlsc_surface *sprite;
71         int32_t hotspot_x, hotspot_y;
72         struct wl_list link;
73         uint32_t modifier_state;
74         struct wl_selection *selection;
75 };
76
77 struct wlsc_drm {
78         struct wl_object object;
79         int fd;
80         char *filename;
81 };
82
83 struct wlsc_shm {
84         struct wl_object object;
85 };
86
87 struct wlsc_compositor {
88         struct wl_compositor compositor;
89
90         struct wlsc_drm drm;
91         struct wlsc_shm shm;
92         EGLDisplay display;
93         EGLContext context;
94         EGLConfig config;
95         GLuint fbo;
96         GLuint proj_uniform, tex_uniform;
97         struct wl_buffer **pointer_buffers;
98         struct wl_display *wl_display;
99
100         /* We implement the shell interface. */
101         struct wl_shell shell;
102
103         /* There can be more than one, but not right now... */
104         struct wl_input_device *input_device;
105
106         struct wl_list output_list;
107         struct wl_list input_device_list;
108         struct wl_list surface_list;
109
110         /* Repaint state. */
111         struct wl_event_source *timer_source;
112         int repaint_needed;
113         int repaint_on_timeout;
114         struct timespec previous_swap;
115         pixman_region32_t damage_region;
116         struct wl_array vertices, indices;
117
118         struct wlsc_switcher *switcher;
119         uint32_t focus;
120
121         void (*destroy)(struct wlsc_compositor *ec);
122         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
123         void (*present)(struct wlsc_compositor *c);
124         struct wl_buffer *(*create_buffer)(struct wlsc_compositor *c,
125                                            int32_t width, int32_t height,
126                                            struct wl_visual *visual,
127                                            const void *data);
128 };
129
130 #define MODIFIER_CTRL   (1 << 8)
131 #define MODIFIER_ALT    (1 << 9)
132 #define MODIFIER_SUPER  (1 << 10)
133
134 enum wlsc_output_flags {
135         WL_OUTPUT_FLIPPED = 0x01
136 };
137
138 struct wlsc_vector {
139         GLfloat f[4];
140 };
141
142 enum wlsc_surface_map_type {
143         WLSC_SURFACE_MAP_UNMAPPED,
144         WLSC_SURFACE_MAP_TOPLEVEL,
145         WLSC_SURFACE_MAP_TRANSIENT,
146         WLSC_SURFACE_MAP_FULLSCREEN
147 };
148
149 struct wlsc_surface {
150         struct wl_surface surface;
151         struct wlsc_compositor *compositor;
152         GLuint texture;
153         int32_t x, y, width, height;
154         int32_t saved_x, saved_y;
155         struct wl_list link;
156         struct wlsc_matrix matrix;
157         struct wlsc_matrix matrix_inv;
158         struct wl_visual *visual;
159         struct wl_buffer *buffer;
160         enum wlsc_surface_map_type map_type;
161         struct wlsc_output *fullscreen_output;
162 };
163
164 void
165 wlsc_surface_update_matrix(struct wlsc_surface *es);
166
167 void
168 notify_motion(struct wl_input_device *device,
169               uint32_t time, int x, int y);
170 void
171 notify_button(struct wl_input_device *device,
172               uint32_t time, int32_t button, int32_t state);
173 void
174 notify_key(struct wl_input_device *device,
175            uint32_t time, uint32_t key, uint32_t state);
176
177 void
178 notify_pointer_focus(struct wl_input_device *device,
179                      uint32_t time,
180                      struct wlsc_output *output,
181                      int32_t x, int32_t y);
182
183 void
184 notify_keyboard_focus(struct wl_input_device *device,
185                       uint32_t time, struct wlsc_output *output,
186                       struct wl_array *keys);
187
188 void
189 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
190 void
191 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
192
193 void
194 wlsc_surface_damage(struct wlsc_surface *surface);
195
196 void
197 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
198                               int32_t x, int32_t y,
199                               int32_t width, int32_t height);
200
201 void
202 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
203                                     enum wlsc_pointer_type type);
204 struct wlsc_surface *
205 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
206
207 void
208 wlsc_selection_set_focus(struct wl_selection *selection,
209                          struct wl_surface *surface, uint32_t time);
210
211 uint32_t
212 get_time(void);
213
214 struct wl_buffer *
215 wlsc_drm_buffer_create(struct wlsc_compositor *ec,
216                        int width, int height,
217                        struct wl_visual *visual, const void *data);
218
219 int
220 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
221 void
222 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
223                  int x, int y, int width, int height, uint32_t flags);
224 void
225 wlsc_input_device_init(struct wlsc_input_device *device,
226                        struct wlsc_compositor *ec);
227 int
228 wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
229
230 int
231 wlsc_shm_init(struct wlsc_compositor *ec);
232
233 int
234 wlsc_shell_init(struct wlsc_compositor *ec);
235
236 void
237 shell_move(struct wl_client *client, struct wl_shell *shell,
238            struct wl_surface *surface,
239            struct wl_input_device *device, uint32_t time);
240
241 void
242 shell_resize(struct wl_client *client, struct wl_shell *shell,
243              struct wl_surface *surface,
244              struct wl_input_device *device, uint32_t time, uint32_t edges);
245
246 struct wl_buffer *
247 wl_buffer_create_drm(struct wlsc_compositor *compositor,
248                      struct wl_visual *visual);
249
250 struct wlsc_compositor *
251 x11_compositor_create(struct wl_display *display, int width, int height);
252
253 struct wlsc_compositor *
254 drm_compositor_create(struct wl_display *display, int connector);
255
256 struct wlsc_compositor *
257 wayland_compositor_create(struct wl_display *display, int width, int height);
258
259 void
260 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
261
262 struct tty *
263 tty_create(struct wlsc_compositor *compositor);
264
265 void
266 tty_destroy(struct tty *tty);
267
268 void
269 screenshooter_create(struct wlsc_compositor *ec);
270
271 uint32_t *
272 wlsc_load_image(const char *filename, int width, int height);
273
274 #endif