22095ffc33fda099e747bb5eb4777b3d45b46f59
[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 <libudev.h>
23 #include <pixman.h>
24 #include "wayland-server.h"
25 #include "wayland-util.h"
26
27 #define GL_GLEXT_PROTOTYPES
28 #define EGL_EGLEXT_PROTOTYPES
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
31 #include <EGL/egl.h>
32 #include <EGL/eglext.h>
33
34 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
35
36 struct wlsc_matrix {
37         GLfloat d[16];
38 };
39
40 struct wlsc_surface;
41
42 struct wlsc_output {
43         struct wl_object object;
44         struct wl_list link;
45         struct wlsc_compositor *compositor;
46         struct wlsc_surface *background;
47         struct wlsc_matrix matrix;
48         int32_t x, y, width, height;
49         pixman_region32_t previous_damage_region;
50         uint32_t flags;
51         int repaint_needed;
52         int finished;
53
54         int (*prepare_render)(struct wlsc_output *output);
55         int (*present)(struct wlsc_output *output);
56         int (*prepare_scanout_surface)(struct wlsc_output *output,
57                                        struct wlsc_surface *es);
58         int (*set_hardware_cursor)(struct wlsc_output *output,
59                                    struct wl_input_device *input);
60 };
61
62 enum wlsc_pointer_type {
63         WLSC_POINTER_BOTTOM_LEFT,
64         WLSC_POINTER_BOTTOM_RIGHT,
65         WLSC_POINTER_BOTTOM,
66         WLSC_POINTER_DRAGGING,
67         WLSC_POINTER_LEFT_PTR,
68         WLSC_POINTER_LEFT,
69         WLSC_POINTER_RIGHT,
70         WLSC_POINTER_TOP_LEFT,
71         WLSC_POINTER_TOP_RIGHT,
72         WLSC_POINTER_TOP,
73         WLSC_POINTER_IBEAM,
74 };
75
76 struct wlsc_input_device {
77         struct wl_input_device input_device;
78         struct wlsc_surface *sprite;
79         int32_t hotspot_x, hotspot_y;
80         struct wl_list link;
81         uint32_t modifier_state;
82         struct wl_selection *selection;
83 };
84
85 struct wlsc_sprite {
86         GLuint texture;
87         EGLImageKHR image;
88         struct wl_visual *visual;
89         int width;
90         int height;
91 };
92
93 struct wlsc_shader {
94         GLuint program;
95         GLuint vertex_shader, fragment_shader;
96         GLuint proj_uniform;
97         GLuint tex_uniform;
98         GLuint color_uniform;
99 };
100
101 struct wlsc_animation {
102         void (*frame)(struct wlsc_animation *animation,
103                       struct wlsc_output *output, uint32_t msecs);
104         struct wl_list link;
105 };
106
107 struct wlsc_tweener {
108         double k;
109         double current;
110         double target;
111         double previous;
112         uint32_t timestamp;
113 };
114
115 struct wlsc_shell {
116         void (*lock)(struct wlsc_shell *shell);
117         void (*attach)(struct wlsc_shell *shell, struct wlsc_surface *surface);
118 };
119
120 enum {
121         WLSC_COMPOSITOR_ACTIVE,
122         WLSC_COMPOSITOR_SLEEPING
123 };
124
125 struct wlsc_compositor {
126         struct wl_compositor compositor;
127
128         struct wl_shm *shm;
129
130         EGLDisplay display;
131         EGLContext context;
132         EGLConfig config;
133         GLuint fbo;
134         GLuint proj_uniform, tex_uniform;
135         struct wlsc_sprite **pointer_sprites;
136         struct wlsc_shader texture_shader;
137         struct wlsc_shader solid_shader;
138         struct wl_display *wl_display;
139
140         struct wlsc_shell *shell;
141
142         /* There can be more than one, but not right now... */
143         struct wl_input_device *input_device;
144
145         struct wl_list output_list;
146         struct wl_list input_device_list;
147         struct wl_list surface_list;
148         struct wl_list binding_list;
149         struct wl_list animation_list;
150         struct {
151                 struct wlsc_tweener tweener;
152                 struct wlsc_animation animation;
153         } fade;
154
155         uint32_t state;
156         struct wl_event_source *idle_source;
157         uint32_t idle_inhibit;
158
159         /* Repaint state. */
160         struct wl_event_source *timer_source;
161         int repaint_on_timeout;
162         struct timespec previous_swap;
163         pixman_region32_t damage_region;
164         struct wl_array vertices, indices;
165
166         struct wlsc_surface *overlay;
167         struct wlsc_switcher *switcher;
168         uint32_t focus;
169
170         void (*destroy)(struct wlsc_compositor *ec);
171         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
172         EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
173                                            int32_t width, int32_t height);
174 };
175
176 #define MODIFIER_CTRL   (1 << 8)
177 #define MODIFIER_ALT    (1 << 9)
178 #define MODIFIER_SUPER  (1 << 10)
179
180 enum wlsc_output_flags {
181         WL_OUTPUT_FLIPPED = 0x01
182 };
183
184 struct wlsc_vector {
185         GLfloat f[4];
186 };
187
188 enum wlsc_surface_map_type {
189         WLSC_SURFACE_MAP_UNMAPPED,
190         WLSC_SURFACE_MAP_TOPLEVEL,
191         WLSC_SURFACE_MAP_TRANSIENT,
192         WLSC_SURFACE_MAP_FULLSCREEN
193 };
194
195 struct wlsc_surface {
196         struct wl_surface surface;
197         struct wlsc_compositor *compositor;
198         GLuint texture, saved_texture;
199         int32_t x, y, width, height;
200         int32_t saved_x, saved_y;
201         struct wl_list link;
202         struct wl_list buffer_link;
203         struct wlsc_matrix matrix;
204         struct wlsc_matrix matrix_inv;
205         struct wl_visual *visual;
206         struct wl_buffer *buffer;
207         struct wlsc_output *output;
208         enum wlsc_surface_map_type map_type;
209         struct wlsc_output *fullscreen_output;
210
211         EGLImageKHR image;
212 };
213
214 void
215 wlsc_tweener_init(struct wlsc_tweener *tweener,
216                   double k, double current, double target);
217 void
218 wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec);
219 int
220 wlsc_tweener_done(struct wlsc_tweener *tweener);
221
222 void
223 wlsc_surface_update_matrix(struct wlsc_surface *es);
224
225 void
226 wlsc_surface_activate(struct wlsc_surface *surface,
227                       struct wlsc_input_device *device, uint32_t time);
228
229 void
230 notify_motion(struct wl_input_device *device,
231               uint32_t time, int x, int y);
232 void
233 notify_button(struct wl_input_device *device,
234               uint32_t time, int32_t button, int32_t state);
235 void
236 notify_key(struct wl_input_device *device,
237            uint32_t time, uint32_t key, uint32_t state);
238
239 void
240 notify_pointer_focus(struct wl_input_device *device,
241                      uint32_t time,
242                      struct wlsc_output *output,
243                      int32_t x, int32_t y);
244
245 void
246 notify_keyboard_focus(struct wl_input_device *device,
247                       uint32_t time, struct wlsc_output *output,
248                       struct wl_array *keys);
249
250 void
251 wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
252 void
253 wlsc_output_damage(struct wlsc_output *output);
254 void
255 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
256 void
257 wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint);
258 void
259 wlsc_compositor_damage_all(struct wlsc_compositor *compositor);
260 void
261 wlsc_compositor_unlock(struct wlsc_compositor *compositor);
262 void
263 wlsc_compositor_wake(struct wlsc_compositor *compositor);
264
265 struct wlsc_binding;
266 typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
267                                        uint32_t time, uint32_t key,
268                                        uint32_t button,
269                                        uint32_t state, void *data);
270 struct wlsc_binding *
271 wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
272                             uint32_t key, uint32_t button, uint32_t modifier,
273                             wlsc_binding_handler_t binding, void *data);
274 void
275 wlsc_binding_destroy(struct wlsc_binding *binding);
276
277 struct wlsc_surface *
278 wlsc_surface_create(struct wlsc_compositor *compositor,
279                     int32_t x, int32_t y, int32_t width, int32_t height);
280
281 void
282 wlsc_surface_assign_output(struct wlsc_surface *surface);
283
284 void
285 wlsc_surface_damage(struct wlsc_surface *surface);
286
287 void
288 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
289                               int32_t x, int32_t y,
290                               int32_t width, int32_t height);
291
292 void
293 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
294                                     enum wlsc_pointer_type type);
295 struct wlsc_surface *
296 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
297
298 void
299 wlsc_selection_set_focus(struct wl_selection *selection,
300                          struct wl_surface *surface, uint32_t time);
301
302 uint32_t
303 wlsc_compositor_get_time(void);
304
305 int
306 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
307 void
308 wlsc_output_move(struct wlsc_output *output, int x, int y);
309 void
310 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
311                  int x, int y, int width, int height, uint32_t flags);
312 void
313 wlsc_output_destroy(struct wlsc_output *output);
314
315 void
316 wlsc_input_device_init(struct wlsc_input_device *device,
317                        struct wlsc_compositor *ec);
318
319 int
320 desktop_shell_init(struct wlsc_compositor *ec);
321
322 void
323 wlsc_switcher_init(struct wlsc_compositor *compositor);
324
325 struct wlsc_compositor *
326 x11_compositor_create(struct wl_display *display, int width, int height);
327
328 struct wlsc_compositor *
329 drm_compositor_create(struct wl_display *display, int connector);
330
331 struct wlsc_compositor *
332 wfd_compositor_create(struct wl_display *display, int connector);
333
334 struct wlsc_compositor *
335 wayland_compositor_create(struct wl_display *display, int width, int height);
336
337 void
338 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
339
340 struct tty *
341 tty_create(struct wlsc_compositor *compositor);
342
343 void
344 tty_destroy(struct tty *tty);
345
346 void
347 screenshooter_create(struct wlsc_compositor *ec);
348
349 uint32_t *
350 wlsc_load_image(const char *filename, int width, int height);
351
352 #endif