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 #include <GLES2/gl2.h>
28 #include <GLES2/gl2ext.h>
30 #include <EGL/eglext.h>
32 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
34 #define FD_TO_EGL_NATIVE_DPY(fd) ((EGLNativeDisplayType)(intptr_t)(fd))
41 wlsc_matrix_init(struct wlsc_matrix *matrix);
43 wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
45 wlsc_matrix_translate(struct wlsc_matrix *matrix,
46 GLfloat x, GLfloat y, GLfloat z);
48 struct wlsc_transform {
49 struct wlsc_matrix matrix;
50 struct wlsc_matrix inverse;
54 struct wlsc_input_device;
58 int32_t width, height;
64 struct wl_object object;
66 struct wlsc_compositor *compositor;
67 struct wlsc_surface *background;
68 struct wlsc_matrix matrix;
69 int32_t x, y, mm_width, mm_height;
70 pixman_region32_t region;
71 pixman_region32_t previous_damage;
74 int repaint_scheduled;
79 struct wlsc_mode *current;
80 struct wl_list mode_list;
81 struct wl_buffer *scanout_buffer;
82 struct wl_listener scanout_buffer_destroy_listener;
84 int (*prepare_render)(struct wlsc_output *output);
85 int (*present)(struct wlsc_output *output);
86 int (*prepare_scanout_surface)(struct wlsc_output *output,
87 struct wlsc_surface *es);
88 int (*set_hardware_cursor)(struct wlsc_output *output,
89 struct wlsc_input_device *input);
92 enum wlsc_pointer_type {
93 WLSC_POINTER_BOTTOM_LEFT,
94 WLSC_POINTER_BOTTOM_RIGHT,
96 WLSC_POINTER_DRAGGING,
97 WLSC_POINTER_LEFT_PTR,
100 WLSC_POINTER_TOP_LEFT,
101 WLSC_POINTER_TOP_RIGHT,
106 struct wlsc_input_device {
107 struct wl_input_device input_device;
108 struct wlsc_surface *sprite;
109 int32_t hotspot_x, hotspot_y;
111 uint32_t modifier_state;
112 struct wl_selection *selection;
118 struct wl_visual *visual;
125 GLuint vertex_shader, fragment_shader;
128 GLuint color_uniform;
131 struct wlsc_animation {
132 void (*frame)(struct wlsc_animation *animation,
133 struct wlsc_output *output, uint32_t msecs);
147 void (*lock)(struct wlsc_shell *shell);
148 void (*attach)(struct wlsc_shell *shell, struct wlsc_surface *surface);
149 void (*set_selection_focus)(struct wlsc_shell *shell,
150 struct wl_selection *selection,
151 struct wl_surface *surface, uint32_t time);
155 WLSC_COMPOSITOR_ACTIVE,
156 WLSC_COMPOSITOR_SLEEPING
159 struct wlsc_compositor {
160 struct wl_compositor compositor;
163 struct wlsc_xserver *wxs;
169 GLuint proj_uniform, tex_uniform;
170 struct wlsc_sprite **pointer_sprites;
171 struct wlsc_shader texture_shader;
172 struct wlsc_shader solid_shader;
173 struct wl_display *wl_display;
175 struct wlsc_shell *shell;
177 /* There can be more than one, but not right now... */
178 struct wl_input_device *input_device;
180 struct wl_list output_list;
181 struct wl_list input_device_list;
182 struct wl_list surface_list;
183 struct wl_list binding_list;
184 struct wl_list animation_list;
186 struct wlsc_spring spring;
187 struct wlsc_animation animation;
191 struct wl_event_source *idle_source;
192 uint32_t idle_inhibit;
195 struct timespec previous_swap;
196 pixman_region32_t damage;
197 struct wl_array vertices, indices;
199 struct wlsc_surface *overlay;
200 struct wlsc_switcher *switcher;
203 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
204 image_target_renderbuffer_storage;
205 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
206 PFNEGLCREATEIMAGEKHRPROC create_image;
207 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
208 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
209 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
210 int has_bind_display;
212 void (*destroy)(struct wlsc_compositor *ec);
213 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
214 EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
215 int32_t width, int32_t height);
218 #define MODIFIER_CTRL (1 << 8)
219 #define MODIFIER_ALT (1 << 9)
220 #define MODIFIER_SUPER (1 << 10)
222 enum wlsc_output_flags {
223 WL_OUTPUT_FLIPPED = 0x01
230 enum wlsc_surface_map_type {
231 WLSC_SURFACE_MAP_UNMAPPED,
232 WLSC_SURFACE_MAP_TOPLEVEL,
233 WLSC_SURFACE_MAP_TRANSIENT,
234 WLSC_SURFACE_MAP_FULLSCREEN
237 struct wlsc_surface {
238 struct wl_surface surface;
239 struct wlsc_compositor *compositor;
240 GLuint texture, saved_texture;
241 pixman_region32_t damage;
242 pixman_region32_t opaque;
243 int32_t x, y, width, height;
245 int32_t saved_x, saved_y;
247 struct wl_list buffer_link;
248 struct wlsc_transform *transform;
249 struct wl_visual *visual;
250 struct wlsc_output *output;
251 enum wlsc_surface_map_type map_type;
252 struct wlsc_output *fullscreen_output;
256 struct wl_buffer *buffer;
257 struct wl_listener buffer_destroy_listener;
261 wlsc_spring_init(struct wlsc_spring *spring,
262 double k, double current, double target);
264 wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec);
266 wlsc_spring_done(struct wlsc_spring *spring);
269 wlsc_surface_activate(struct wlsc_surface *surface,
270 struct wlsc_input_device *device, uint32_t time);
273 notify_motion(struct wl_input_device *device,
274 uint32_t time, int x, int y);
276 notify_button(struct wl_input_device *device,
277 uint32_t time, int32_t button, int32_t state);
279 notify_key(struct wl_input_device *device,
280 uint32_t time, uint32_t key, uint32_t state);
283 notify_pointer_focus(struct wl_input_device *device,
285 struct wlsc_output *output,
286 int32_t x, int32_t y);
289 notify_keyboard_focus(struct wl_input_device *device,
290 uint32_t time, struct wlsc_output *output,
291 struct wl_array *keys);
294 wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
296 wlsc_output_damage(struct wlsc_output *output);
298 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
300 wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint);
302 wlsc_compositor_damage_all(struct wlsc_compositor *compositor);
304 wlsc_compositor_unlock(struct wlsc_compositor *compositor);
306 wlsc_compositor_wake(struct wlsc_compositor *compositor);
309 typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
310 uint32_t time, uint32_t key,
312 uint32_t state, void *data);
313 struct wlsc_binding *
314 wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
315 uint32_t key, uint32_t button, uint32_t modifier,
316 wlsc_binding_handler_t binding, void *data);
318 wlsc_binding_destroy(struct wlsc_binding *binding);
320 struct wlsc_surface *
321 wlsc_surface_create(struct wlsc_compositor *compositor,
322 int32_t x, int32_t y, int32_t width, int32_t height);
325 wlsc_surface_configure(struct wlsc_surface *surface,
326 int x, int y, int width, int height);
329 wlsc_surface_assign_output(struct wlsc_surface *surface);
332 wlsc_surface_damage(struct wlsc_surface *surface);
335 wlsc_surface_damage_below(struct wlsc_surface *surface);
338 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
339 int32_t x, int32_t y,
340 int32_t width, int32_t height);
343 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
344 enum wlsc_pointer_type type);
345 struct wlsc_surface *
346 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
349 wlsc_compositor_get_time(void);
352 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
354 wlsc_output_move(struct wlsc_output *output, int x, int y);
356 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
357 int x, int y, int width, int height, uint32_t flags);
359 wlsc_output_destroy(struct wlsc_output *output);
362 wlsc_input_device_init(struct wlsc_input_device *device,
363 struct wlsc_compositor *ec);
366 wlsc_switcher_init(struct wlsc_compositor *compositor);
369 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
376 typedef void (*tty_vt_func_t)(struct wlsc_compositor *compositor, int event);
379 tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func);
382 tty_destroy(struct tty *tty);
385 screenshooter_create(struct wlsc_compositor *ec);
388 wlsc_load_image(const char *filename,
389 int32_t *width_arg, int32_t *height_arg, uint32_t *stride_arg);
391 struct wlsc_process {
393 void (*cleanup)(struct wlsc_process *process, int status);
398 wlsc_watch_process(struct wlsc_process *process);
401 wlsc_xserver_init(struct wlsc_compositor *compositor);
403 wlsc_xserver_destroy(struct wlsc_compositor *compositor);