2 * Copyright © 2008 Kristian Høgsberg
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.
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.
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.
19 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
20 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
24 #include "wayland-server.h"
25 #include "wayland-util.h"
27 #define GL_GLEXT_PROTOTYPES
28 #define EGL_EGLEXT_PROTOTYPES
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
32 #include <EGL/eglext.h>
34 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
43 struct wl_object object;
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;
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);
62 enum wlsc_pointer_type {
63 WLSC_POINTER_BOTTOM_LEFT,
64 WLSC_POINTER_BOTTOM_RIGHT,
66 WLSC_POINTER_DRAGGING,
67 WLSC_POINTER_LEFT_PTR,
70 WLSC_POINTER_TOP_LEFT,
71 WLSC_POINTER_TOP_RIGHT,
76 struct wlsc_input_device {
77 struct wl_input_device input_device;
78 struct wlsc_surface *sprite;
79 int32_t hotspot_x, hotspot_y;
81 uint32_t modifier_state;
82 struct wl_selection *selection;
88 struct wl_visual *visual;
95 GLuint vertex_shader, fragment_shader;
101 struct wlsc_animation {
102 void (*frame)(struct wlsc_animation *animation,
103 struct wlsc_output *output, uint32_t msecs);
107 struct wlsc_tweener {
116 void (*lock)(struct wlsc_shell *shell);
117 void (*attach)(struct wlsc_shell *shell, struct wlsc_surface *surface);
121 WLSC_COMPOSITOR_ACTIVE,
122 WLSC_COMPOSITOR_SLEEPING
125 struct wlsc_compositor {
126 struct wl_compositor compositor;
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;
140 struct wlsc_shell *shell;
142 /* There can be more than one, but not right now... */
143 struct wl_input_device *input_device;
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;
151 struct wlsc_tweener tweener;
152 struct wlsc_animation animation;
156 struct wl_event_source *idle_source;
157 uint32_t idle_inhibit;
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;
166 struct wlsc_surface *overlay;
167 struct wlsc_switcher *switcher;
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);
176 #define MODIFIER_CTRL (1 << 8)
177 #define MODIFIER_ALT (1 << 9)
178 #define MODIFIER_SUPER (1 << 10)
180 enum wlsc_output_flags {
181 WL_OUTPUT_FLIPPED = 0x01
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
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;
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;
215 wlsc_tweener_init(struct wlsc_tweener *tweener,
216 double k, double current, double target);
218 wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec);
220 wlsc_tweener_done(struct wlsc_tweener *tweener);
223 wlsc_surface_update_matrix(struct wlsc_surface *es);
226 wlsc_surface_activate(struct wlsc_surface *surface,
227 struct wlsc_input_device *device, uint32_t time);
230 notify_motion(struct wl_input_device *device,
231 uint32_t time, int x, int y);
233 notify_button(struct wl_input_device *device,
234 uint32_t time, int32_t button, int32_t state);
236 notify_key(struct wl_input_device *device,
237 uint32_t time, uint32_t key, uint32_t state);
240 notify_pointer_focus(struct wl_input_device *device,
242 struct wlsc_output *output,
243 int32_t x, int32_t y);
246 notify_keyboard_focus(struct wl_input_device *device,
247 uint32_t time, struct wlsc_output *output,
248 struct wl_array *keys);
251 wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
253 wlsc_output_damage(struct wlsc_output *output);
255 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
257 wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint);
259 wlsc_compositor_damage_all(struct wlsc_compositor *compositor);
261 wlsc_compositor_unlock(struct wlsc_compositor *compositor);
263 wlsc_compositor_wake(struct wlsc_compositor *compositor);
266 typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
267 uint32_t time, uint32_t key,
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);
275 wlsc_binding_destroy(struct wlsc_binding *binding);
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);
282 wlsc_surface_assign_output(struct wlsc_surface *surface);
285 wlsc_surface_damage(struct wlsc_surface *surface);
288 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
289 int32_t x, int32_t y,
290 int32_t width, int32_t height);
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);
299 wlsc_selection_set_focus(struct wl_selection *selection,
300 struct wl_surface *surface, uint32_t time);
303 wlsc_compositor_get_time(void);
306 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
308 wlsc_output_move(struct wlsc_output *output, int x, int y);
310 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
311 int x, int y, int width, int height, uint32_t flags);
313 wlsc_output_destroy(struct wlsc_output *output);
316 wlsc_input_device_init(struct wlsc_input_device *device,
317 struct wlsc_compositor *ec);
320 desktop_shell_init(struct wlsc_compositor *ec);
323 wlsc_switcher_init(struct wlsc_compositor *compositor);
325 struct wlsc_compositor *
326 x11_compositor_create(struct wl_display *display, int width, int height);
328 struct wlsc_compositor *
329 drm_compositor_create(struct wl_display *display, int connector);
331 struct wlsc_compositor *
332 wfd_compositor_create(struct wl_display *display, int connector);
334 struct wlsc_compositor *
335 wayland_compositor_create(struct wl_display *display, int width, int height);
338 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
341 tty_create(struct wlsc_compositor *compositor);
344 tty_destroy(struct tty *tty);
347 screenshooter_create(struct wlsc_compositor *ec);
350 wlsc_load_image(const char *filename, int width, int height);