blob: 93de793038152d457a8416600a85588f90d458ad [file] [log] [blame]
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -05001/*
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
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040022#include <libudev.h>
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -050023#include <pixman.h>
Kristian Høgsberga661f262010-08-10 14:12:05 -040024#include "wayland-server.h"
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040025#include "wayland-util.h"
26
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040027#include <GLES2/gl2.h>
28#include <GLES2/gl2ext.h>
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040029#include <EGL/egl.h>
30#include <EGL/eglext.h>
31
32#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
33
Benjamin Franzkee5b3b262011-04-26 09:21:13 +020034#define FD_TO_EGL_NATIVE_DPY(fd) ((EGLNativeDisplayType)(intptr_t)(fd))
35
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040036struct wlsc_matrix {
37 GLfloat d[16];
38};
39
Kristian Høgsbergd880e142011-05-02 13:53:45 -040040void
41wlsc_matrix_init(struct wlsc_matrix *matrix);
42void
43wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
44void
45wlsc_matrix_translate(struct wlsc_matrix *matrix,
46 GLfloat x, GLfloat y, GLfloat z);
47
Kristian Høgsberg0bc0e242011-05-02 14:35:40 -040048struct wlsc_transform {
49 struct wlsc_matrix matrix;
50 struct wlsc_matrix inverse;
51};
52
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040053struct wlsc_surface;
54
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040055struct wlsc_output {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050056 struct wl_object object;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040057 struct wl_list link;
58 struct wlsc_compositor *compositor;
59 struct wlsc_surface *background;
60 struct wlsc_matrix matrix;
61 int32_t x, y, width, height;
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -050062 pixman_region32_t previous_damage_region;
Benjamin Franzke9c26ff32011-03-15 15:08:41 +010063 uint32_t flags;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +010064 int repaint_needed;
65 int finished;
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +010066
67 int (*prepare_render)(struct wlsc_output *output);
Benjamin Franzkeec4d3422011-03-14 12:07:26 +010068 int (*present)(struct wlsc_output *output);
Benjamin Franzke66aa2352011-04-20 17:06:13 +020069 int (*prepare_scanout_surface)(struct wlsc_output *output,
70 struct wlsc_surface *es);
Benjamin Franzke431da9a2011-04-20 11:02:58 +020071 int (*set_hardware_cursor)(struct wlsc_output *output,
72 struct wl_input_device *input);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040073};
74
Kristian Høgsberg1db21f12010-08-16 16:08:12 -040075enum wlsc_pointer_type {
76 WLSC_POINTER_BOTTOM_LEFT,
77 WLSC_POINTER_BOTTOM_RIGHT,
78 WLSC_POINTER_BOTTOM,
79 WLSC_POINTER_DRAGGING,
80 WLSC_POINTER_LEFT_PTR,
81 WLSC_POINTER_LEFT,
82 WLSC_POINTER_RIGHT,
83 WLSC_POINTER_TOP_LEFT,
84 WLSC_POINTER_TOP_RIGHT,
85 WLSC_POINTER_TOP,
86 WLSC_POINTER_IBEAM,
87};
88
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040089struct wlsc_input_device {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050090 struct wl_input_device input_device;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040091 struct wlsc_surface *sprite;
Kristian Høgsberg77fb1672010-08-16 10:38:29 -040092 int32_t hotspot_x, hotspot_y;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040093 struct wl_list link;
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -040094 uint32_t modifier_state;
Kristian Høgsbergae6c8a62011-01-18 09:08:53 -050095 struct wl_selection *selection;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040096};
97
Benjamin Franzke431da9a2011-04-20 11:02:58 +020098struct wlsc_sprite {
99 GLuint texture;
100 EGLImageKHR image;
101 struct wl_visual *visual;
102 int width;
103 int height;
104};
105
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -0400106struct wlsc_shader {
107 GLuint program;
108 GLuint vertex_shader, fragment_shader;
109 GLuint proj_uniform;
110 GLuint tex_uniform;
111 GLuint color_uniform;
112};
113
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400114struct wlsc_animation {
115 void (*frame)(struct wlsc_animation *animation,
116 struct wlsc_output *output, uint32_t msecs);
117 struct wl_list link;
118};
119
Kristian Høgsberg269c7822011-05-02 14:38:18 -0400120struct wlsc_spring {
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400121 double k;
Kristian Høgsberg4a9be132011-05-02 13:38:03 -0400122 double friction;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400123 double current;
124 double target;
125 double previous;
126 uint32_t timestamp;
127};
128
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400129struct wlsc_shell {
130 void (*lock)(struct wlsc_shell *shell);
131 void (*attach)(struct wlsc_shell *shell, struct wlsc_surface *surface);
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400132 void (*set_selection_focus)(struct wlsc_shell *shell,
133 struct wl_selection *selection,
134 struct wl_surface *surface, uint32_t time);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400135};
136
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400137enum {
138 WLSC_COMPOSITOR_ACTIVE,
139 WLSC_COMPOSITOR_SLEEPING
140};
141
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400142struct wlsc_compositor {
Kristian Høgsbergb313b022010-12-01 17:07:41 -0500143 struct wl_compositor compositor;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400144
Benjamin Franzke315b3dc2011-03-08 11:32:57 +0100145 struct wl_shm *shm;
146
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400147 EGLDisplay display;
148 EGLContext context;
Benjamin Franzkebe014562011-02-18 17:04:24 +0100149 EGLConfig config;
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -0500150 GLuint fbo;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400151 GLuint proj_uniform, tex_uniform;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200152 struct wlsc_sprite **pointer_sprites;
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -0400153 struct wlsc_shader texture_shader;
154 struct wlsc_shader solid_shader;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400155 struct wl_display *wl_display;
156
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400157 struct wlsc_shell *shell;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400158
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400159 /* There can be more than one, but not right now... */
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500160 struct wl_input_device *input_device;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400161
162 struct wl_list output_list;
163 struct wl_list input_device_list;
164 struct wl_list surface_list;
Kristian Høgsberg3555d092011-04-11 13:58:13 -0400165 struct wl_list binding_list;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400166 struct wl_list animation_list;
167 struct {
Kristian Høgsberg269c7822011-05-02 14:38:18 -0400168 struct wlsc_spring spring;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400169 struct wlsc_animation animation;
170 } fade;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400171
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400172 uint32_t state;
173 struct wl_event_source *idle_source;
174 uint32_t idle_inhibit;
175
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400176 /* Repaint state. */
177 struct wl_event_source *timer_source;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400178 int repaint_on_timeout;
179 struct timespec previous_swap;
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500180 pixman_region32_t damage_region;
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500181 struct wl_array vertices, indices;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400182
Kristian Høgsberg547cadf2011-04-12 22:23:30 -0400183 struct wlsc_surface *overlay;
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -0500184 struct wlsc_switcher *switcher;
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400185 uint32_t focus;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400186
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400187 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
188 image_target_renderbuffer_storage;
189 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
190 PFNEGLCREATEIMAGEKHRPROC create_image;
191 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
192 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
193 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
194 int has_bind_display;
195
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500196 void (*destroy)(struct wlsc_compositor *ec);
Kristian Høgsberg640609a2010-08-09 22:11:47 -0400197 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200198 EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
199 int32_t width, int32_t height);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400200};
201
202#define MODIFIER_CTRL (1 << 8)
203#define MODIFIER_ALT (1 << 9)
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -0400204#define MODIFIER_SUPER (1 << 10)
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400205
Benjamin Franzke1b765ff2011-02-18 16:51:37 +0100206enum wlsc_output_flags {
207 WL_OUTPUT_FLIPPED = 0x01
208};
209
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400210struct wlsc_vector {
211 GLfloat f[4];
212};
213
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500214enum wlsc_surface_map_type {
215 WLSC_SURFACE_MAP_UNMAPPED,
216 WLSC_SURFACE_MAP_TOPLEVEL,
217 WLSC_SURFACE_MAP_TRANSIENT,
218 WLSC_SURFACE_MAP_FULLSCREEN
219};
220
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400221struct wlsc_surface {
Kristian Høgsbergb313b022010-12-01 17:07:41 -0500222 struct wl_surface surface;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400223 struct wlsc_compositor *compositor;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200224 GLuint texture, saved_texture;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400225 int32_t x, y, width, height;
Benjamin Franzkefab5ec12011-04-25 19:44:47 +0200226 int32_t pitch;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500227 int32_t saved_x, saved_y;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400228 struct wl_list link;
Benjamin Franzkebab41fb2011-03-07 18:04:59 +0100229 struct wl_list buffer_link;
Kristian Høgsberg0bc0e242011-05-02 14:35:40 -0400230 struct wlsc_transform *transform;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400231 struct wl_visual *visual;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100232 struct wlsc_output *output;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500233 enum wlsc_surface_map_type map_type;
234 struct wlsc_output *fullscreen_output;
Benjamin Franzke1178a3c2011-04-10 16:49:52 +0200235
236 EGLImageKHR image;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400237};
238
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500239void
Kristian Høgsberg269c7822011-05-02 14:38:18 -0400240wlsc_spring_init(struct wlsc_spring *spring,
241 double k, double current, double target);
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400242void
Kristian Høgsberg269c7822011-05-02 14:38:18 -0400243wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec);
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400244int
Kristian Høgsberg269c7822011-05-02 14:38:18 -0400245wlsc_spring_done(struct wlsc_spring *spring);
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400246
247void
Kristian Høgsberg30021d72011-04-12 17:42:30 -0400248wlsc_surface_activate(struct wlsc_surface *surface,
249 struct wlsc_input_device *device, uint32_t time);
250
251void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500252notify_motion(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400253 uint32_t time, int x, int y);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500254void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500255notify_button(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400256 uint32_t time, int32_t button, int32_t state);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500257void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500258notify_key(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400259 uint32_t time, uint32_t key, uint32_t state);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500260
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400261void
Kristian Høgsberg93331ff2011-01-26 20:35:07 -0500262notify_pointer_focus(struct wl_input_device *device,
263 uint32_t time,
264 struct wlsc_output *output,
265 int32_t x, int32_t y);
266
267void
Kristian Høgsberg3ba48582011-01-27 11:57:19 -0500268notify_keyboard_focus(struct wl_input_device *device,
269 uint32_t time, struct wlsc_output *output,
270 struct wl_array *keys);
271
272void
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100273wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400274void
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400275wlsc_output_damage(struct wlsc_output *output);
276void
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400277wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400278void
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400279wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint);
280void
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400281wlsc_compositor_damage_all(struct wlsc_compositor *compositor);
282void
283wlsc_compositor_unlock(struct wlsc_compositor *compositor);
284void
285wlsc_compositor_wake(struct wlsc_compositor *compositor);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400286
Kristian Høgsberg3555d092011-04-11 13:58:13 -0400287struct wlsc_binding;
Kristian Høgsberga8ec8632011-04-12 17:22:49 -0400288typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
Kristian Høgsberg3555d092011-04-11 13:58:13 -0400289 uint32_t time, uint32_t key,
Kristian Høgsberga8ec8632011-04-12 17:22:49 -0400290 uint32_t button,
Kristian Høgsberg3555d092011-04-11 13:58:13 -0400291 uint32_t state, void *data);
292struct wlsc_binding *
293wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
Kristian Høgsberga8ec8632011-04-12 17:22:49 -0400294 uint32_t key, uint32_t button, uint32_t modifier,
Kristian Høgsberg3555d092011-04-11 13:58:13 -0400295 wlsc_binding_handler_t binding, void *data);
296void
297wlsc_binding_destroy(struct wlsc_binding *binding);
298
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200299struct wlsc_surface *
300wlsc_surface_create(struct wlsc_compositor *compositor,
301 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg3555d092011-04-11 13:58:13 -0400302
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500303void
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100304wlsc_surface_assign_output(struct wlsc_surface *surface);
305
306void
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500307wlsc_surface_damage(struct wlsc_surface *surface);
308
309void
310wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
311 int32_t x, int32_t y,
312 int32_t width, int32_t height);
313
314void
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500315wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
316 enum wlsc_pointer_type type);
317struct wlsc_surface *
318pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
319
320uint32_t
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400321wlsc_compositor_get_time(void);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500322
Benjamin Franzke0c347f02011-03-07 15:17:56 +0100323int
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400324wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
325void
Benjamin Franzke9c26ff32011-03-15 15:08:41 +0100326wlsc_output_move(struct wlsc_output *output, int x, int y);
327void
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400328wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
Benjamin Franzke1b765ff2011-02-18 16:51:37 +0100329 int x, int y, int width, int height, uint32_t flags);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400330void
Benjamin Franzke9c26ff32011-03-15 15:08:41 +0100331wlsc_output_destroy(struct wlsc_output *output);
332
333void
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400334wlsc_input_device_init(struct wlsc_input_device *device,
335 struct wlsc_compositor *ec);
336
Kristian Høgsberg30021d72011-04-12 17:42:30 -0400337void
338wlsc_switcher_init(struct wlsc_compositor *compositor);
339
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400340void
Kristian Høgsberg43db4012011-01-14 14:45:42 -0500341evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
342
Kristian Høgsberge4762a62011-01-14 14:59:13 -0500343struct tty *
344tty_create(struct wlsc_compositor *compositor);
345
346void
347tty_destroy(struct tty *tty);
348
Kristian Høgsberg43db4012011-01-14 14:45:42 -0500349void
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400350screenshooter_create(struct wlsc_compositor *ec);
351
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500352uint32_t *
Kristian Høgsbergb41d76c2011-04-23 15:03:15 -0400353wlsc_load_image(const char *filename,
354 int32_t *width_arg, int32_t *height_arg, uint32_t *stride_arg);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500355
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500356#endif