blob: bf21feefb39c82fe439de1eccadc020f9adb2298 [file] [log] [blame]
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001/*
2 * Copyright © 2008-2011 Kristian Høgsberg
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
24#define _WAYLAND_SYSTEM_COMPOSITOR_H_
25
26#include <libudev.h>
27#include <pixman.h>
28#include <wayland-server.h>
29
30#include <GLES2/gl2.h>
31#include <GLES2/gl2ext.h>
32#include <EGL/egl.h>
33#include <EGL/eglext.h>
34
35struct weston_matrix {
36 GLfloat d[16];
37};
38
39struct weston_vector {
40 GLfloat f[4];
41};
42
43void
44weston_matrix_init(struct weston_matrix *matrix);
45void
46weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
47void
48weston_matrix_translate(struct weston_matrix *matrix,
49 GLfloat x, GLfloat y, GLfloat z);
50void
51weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
52
53struct weston_transform {
54 struct weston_matrix matrix;
55 struct weston_matrix inverse;
56};
57
58struct weston_surface;
59struct weston_input_device;
60
61struct weston_mode {
62 uint32_t flags;
63 int32_t width, height;
64 uint32_t refresh;
65 struct wl_list link;
66};
67
68struct weston_output {
69 struct wl_list link;
70 struct weston_compositor *compositor;
71 struct weston_matrix matrix;
72 struct wl_list frame_callback_list;
73 int32_t x, y, mm_width, mm_height;
74 pixman_region32_t region;
75 pixman_region32_t previous_damage;
76 uint32_t flags;
77 int repaint_needed;
78 int repaint_scheduled;
79
80 char *make, *model;
81 uint32_t subpixel;
82
83 struct weston_mode *current;
84 struct wl_list mode_list;
85 struct wl_buffer *scanout_buffer;
86 struct wl_listener scanout_buffer_destroy_listener;
87 struct wl_buffer *pending_scanout_buffer;
88 struct wl_listener pending_scanout_buffer_destroy_listener;
89
90 int (*prepare_render)(struct weston_output *output);
91 int (*present)(struct weston_output *output);
92 int (*prepare_scanout_surface)(struct weston_output *output,
93 struct weston_surface *es);
94 int (*set_hardware_cursor)(struct weston_output *output,
95 struct weston_input_device *input);
96 void (*destroy)(struct weston_output *output);
97};
98
Kristian Høgsberga33d0c32012-01-03 22:58:14 -050099struct weston_selection_listener {
100 void (*func)(struct weston_selection_listener *listener,
101 struct weston_input_device *device);
102 struct wl_list link;
103};
104
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500105struct weston_input_device {
106 struct wl_input_device input_device;
107 struct weston_compositor *compositor;
108 struct weston_surface *sprite;
109 int32_t hotspot_x, hotspot_y;
110 struct wl_list link;
111 uint32_t modifier_state;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500112
113 struct wl_list drag_resource_list;
114 struct weston_data_source *drag_data_source;
115 struct wl_surface *drag_focus;
116 struct wl_resource *drag_focus_resource;
117 struct wl_listener drag_focus_listener;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500118 struct wl_grab drag_grab;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500119
120 struct weston_data_source *selection_data_source;
121 struct wl_listener selection_data_source_listener;
Kristian Høgsberga33d0c32012-01-03 22:58:14 -0500122 struct wl_list selection_listener_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500123
124 uint32_t num_tp;
125 struct wl_surface *touch_focus;
126 struct wl_listener touch_focus_listener;
127 struct wl_resource *touch_focus_resource;
128 struct wl_listener touch_focus_resource_listener;
129};
130
131enum weston_visual {
132 WESTON_NONE_VISUAL,
133 WESTON_ARGB_VISUAL,
134 WESTON_PREMUL_ARGB_VISUAL,
135 WESTON_RGB_VISUAL
136};
137
138struct weston_shader {
139 GLuint program;
140 GLuint vertex_shader, fragment_shader;
141 GLuint proj_uniform;
142 GLuint tex_uniform;
143 GLuint alpha_uniform;
144 GLuint color_uniform;
145};
146
147struct weston_animation {
148 void (*frame)(struct weston_animation *animation,
149 struct weston_output *output, uint32_t msecs);
150 struct wl_list link;
151};
152
153struct weston_spring {
154 double k;
155 double friction;
156 double current;
157 double target;
158 double previous;
159 uint32_t timestamp;
160};
161
162struct weston_shell {
163 void (*lock)(struct weston_shell *shell);
164 void (*unlock)(struct weston_shell *shell);
165 void (*map)(struct weston_shell *shell, struct weston_surface *surface,
166 int32_t width, int32_t height);
167 void (*configure)(struct weston_shell *shell,
168 struct weston_surface *surface,
169 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500170 void (*destroy)(struct weston_shell *shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500171};
172
173enum {
174 WESTON_COMPOSITOR_ACTIVE,
175 WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
176 WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */
177};
178
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500179struct screenshooter;
180
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500181struct weston_compositor {
182 struct wl_shm *shm;
183 struct weston_xserver *wxs;
184
185 EGLDisplay display;
186 EGLContext context;
187 EGLConfig config;
188 GLuint fbo;
189 GLuint proj_uniform, tex_uniform, alpha_uniform;
190 uint32_t current_alpha;
191 struct weston_shader texture_shader;
192 struct weston_shader solid_shader;
193 struct wl_display *wl_display;
194
195 struct weston_shell *shell;
196
197 /* There can be more than one, but not right now... */
198 struct wl_input_device *input_device;
199
200 struct wl_list output_list;
201 struct wl_list input_device_list;
202 struct wl_list surface_list;
203 struct wl_list binding_list;
204 struct wl_list animation_list;
205 struct {
206 struct weston_spring spring;
207 struct weston_animation animation;
208 } fade;
209
210 uint32_t state;
211 struct wl_event_source *idle_source;
212 uint32_t idle_inhibit;
213 int option_idle_time; /* default timeout, s */
214 int idle_time; /* effective timeout, s */
215
216 /* Repaint state. */
217 struct timespec previous_swap;
218 struct wl_array vertices, indices;
219
220 struct weston_surface *overlay;
221 struct weston_switcher *switcher;
222 uint32_t focus;
223
224 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
225 image_target_renderbuffer_storage;
226 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
227 PFNEGLCREATEIMAGEKHRPROC create_image;
228 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
229 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
230 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
231 int has_bind_display;
232
233 void (*destroy)(struct weston_compositor *ec);
234 int (*authenticate)(struct weston_compositor *c, uint32_t id);
235 EGLImageKHR (*create_cursor_image)(struct weston_compositor *c,
236 int32_t *width, int32_t *height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500237
238 struct screenshooter *screenshooter;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500239};
240
241#define MODIFIER_CTRL (1 << 8)
242#define MODIFIER_ALT (1 << 9)
243#define MODIFIER_SUPER (1 << 10)
244
245enum weston_output_flags {
246 WL_OUTPUT_FLIPPED = 0x01
247};
248
249struct weston_surface {
250 struct wl_surface surface;
251 struct weston_compositor *compositor;
252 GLuint texture, saved_texture;
253 pixman_region32_t damage;
254 pixman_region32_t opaque;
255 int32_t x, y, width, height;
256 int32_t pitch;
257 struct wl_list link;
258 struct wl_list buffer_link;
259 struct weston_transform *transform;
260 uint32_t alpha;
261 uint32_t visual;
262
263 /*
264 * Which output to vsync this surface to.
265 * Used to determine, whether to send or queue frame events.
266 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
267 */
268 struct weston_output *output;
269
270 struct weston_output *fullscreen_output;
271 struct wl_list frame_callback_list;
272
273 EGLImageKHR image;
274
275 struct wl_buffer *buffer;
276 struct wl_listener buffer_destroy_listener;
277};
278
Kristian Høgsberg82d9ee92012-01-03 14:11:07 -0500279struct weston_data_offer {
280 struct wl_resource resource;
281 struct weston_data_source *source;
282 struct wl_listener source_destroy_listener;
283};
284
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500285struct weston_data_source {
286 struct wl_resource resource;
287 struct wl_array mime_types;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500288
Kristian Høgsberg82d9ee92012-01-03 14:11:07 -0500289 const struct wl_data_offer_interface *offer_interface;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500290 void (*cancel)(struct weston_data_source *source);
291};
292
293void
294weston_data_source_unref(struct weston_data_source *source);
295
296void
297weston_input_device_set_selection(struct weston_input_device *device,
298 struct weston_data_source *source,
299 uint32_t time);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500300void
301weston_device_repick(struct wl_input_device *device, uint32_t time);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500302
303void
304weston_spring_init(struct weston_spring *spring,
305 double k, double current, double target);
306void
307weston_spring_update(struct weston_spring *spring, uint32_t msec);
308int
309weston_spring_done(struct weston_spring *spring);
310
311void
312weston_surface_activate(struct weston_surface *surface,
313 struct weston_input_device *device, uint32_t time);
314
315void
316notify_motion(struct wl_input_device *device,
317 uint32_t time, int x, int y);
318void
319notify_button(struct wl_input_device *device,
320 uint32_t time, int32_t button, int32_t state);
321void
322notify_key(struct wl_input_device *device,
323 uint32_t time, uint32_t key, uint32_t state);
324
325void
326notify_pointer_focus(struct wl_input_device *device,
327 uint32_t time,
328 struct weston_output *output,
329 int32_t x, int32_t y);
330
331void
332notify_keyboard_focus(struct wl_input_device *device,
333 uint32_t time, struct weston_output *output,
334 struct wl_array *keys);
335
336void
337notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
338 int x, int y, int touch_type);
339
340void
341weston_output_finish_frame(struct weston_output *output, int msecs);
342void
343weston_output_damage(struct weston_output *output);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500344struct weston_surface *
345weston_compositor_pick_surface(struct weston_compositor *compositor,
346 int32_t x, int32_t y, int32_t *sx, int32_t *sy);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500347void
348weston_compositor_repick(struct weston_compositor *compositor);
349void
350weston_compositor_schedule_repaint(struct weston_compositor *compositor);
351void
352weston_compositor_fade(struct weston_compositor *compositor, float tint);
353void
354weston_compositor_damage_all(struct weston_compositor *compositor);
355void
356weston_compositor_unlock(struct weston_compositor *compositor);
357void
358weston_compositor_wake(struct weston_compositor *compositor);
359void
360weston_compositor_activity(struct weston_compositor *compositor);
361
362struct weston_binding;
363typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
364 uint32_t time, uint32_t key,
365 uint32_t button,
366 uint32_t state, void *data);
367struct weston_binding *
368weston_compositor_add_binding(struct weston_compositor *compositor,
369 uint32_t key, uint32_t button, uint32_t modifier,
370 weston_binding_handler_t binding, void *data);
371void
372weston_binding_destroy(struct weston_binding *binding);
373
374void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500375weston_binding_list_destroy_all(struct wl_list *list);
376
377void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500378weston_compositor_run_binding(struct weston_compositor *compositor,
379 struct weston_input_device *device,
380 uint32_t time,
381 uint32_t key, uint32_t button, int32_t state);
382
383struct weston_surface *
384weston_surface_create(struct weston_compositor *compositor,
385 int32_t x, int32_t y, int32_t width, int32_t height);
386
387void
388weston_surface_configure(struct weston_surface *surface,
389 int x, int y, int width, int height);
390
391void
392weston_surface_assign_output(struct weston_surface *surface);
393
394void
395weston_surface_damage(struct weston_surface *surface);
396
397void
398weston_surface_damage_below(struct weston_surface *surface);
399
400void
401weston_surface_damage_rectangle(struct weston_surface *surface,
402 int32_t x, int32_t y,
403 int32_t width, int32_t height);
404
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500405uint32_t
406weston_compositor_get_time(void);
407
408int
409weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
410void
411weston_compositor_shutdown(struct weston_compositor *ec);
412void
413weston_output_move(struct weston_output *output, int x, int y);
414void
415weston_output_init(struct weston_output *output, struct weston_compositor *c,
416 int x, int y, int width, int height, uint32_t flags);
417void
418weston_output_destroy(struct weston_output *output);
419
420void
421weston_input_device_init(struct weston_input_device *device,
422 struct weston_compositor *ec);
423
424void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500425weston_input_device_release(struct weston_input_device *device);
426
427void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500428weston_switcher_init(struct weston_compositor *compositor);
429
430enum {
431 TTY_ENTER_VT,
432 TTY_LEAVE_VT
433};
434
435typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
436
437struct tty *
438tty_create(struct weston_compositor *compositor,
439 tty_vt_func_t vt_func, int tty_nr);
440
441void
442tty_destroy(struct tty *tty);
443
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500444struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500445screenshooter_create(struct weston_compositor *ec);
446
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500447void
448screenshooter_destroy(struct screenshooter *s);
449
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500450uint32_t *
451weston_load_image(const char *filename,
452 int32_t *width_arg, int32_t *height_arg,
453 uint32_t *stride_arg);
454
455struct weston_process;
456typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
457 int status);
458
459struct weston_process {
460 pid_t pid;
461 weston_process_cleanup_func_t cleanup;
462 struct wl_list link;
463};
464
465struct wl_client *
466weston_client_launch(struct weston_compositor *compositor,
467 struct weston_process *proc,
468 const char *path,
469 weston_process_cleanup_func_t cleanup);
470
471int
472weston_data_device_manager_init(struct weston_compositor *compositor);
473void
474weston_data_device_set_keyboard_focus(struct weston_input_device *device);
475
476void
477weston_watch_process(struct weston_process *process);
478
479int
480weston_xserver_init(struct weston_compositor *compositor);
481void
482weston_xserver_destroy(struct weston_compositor *compositor);
483void
484weston_xserver_surface_activate(struct weston_surface *surface);
485void
486weston_xserver_set_selection(struct weston_input_device *device);
487
488struct weston_zoom;
489typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
490
491struct weston_zoom *
492weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
493 weston_zoom_done_func_t done, void *data);
494
495#endif