blob: fe7176a15a377aff7380d25f7617ff8a1ccb234c [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;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050085
Kristian Høgsberg68c479a2012-01-25 23:32:28 -050086 void (*repaint)(struct weston_output *output);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050087 int (*set_hardware_cursor)(struct weston_output *output,
88 struct weston_input_device *input);
89 void (*destroy)(struct weston_output *output);
90};
91
92struct weston_input_device {
93 struct wl_input_device input_device;
94 struct weston_compositor *compositor;
95 struct weston_surface *sprite;
96 int32_t hotspot_x, hotspot_y;
97 struct wl_list link;
98 uint32_t modifier_state;
Kristian Høgsberga82c4862012-01-26 01:03:58 -050099 int hw_cursor;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500100
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500101 uint32_t num_tp;
102 struct wl_surface *touch_focus;
103 struct wl_listener touch_focus_listener;
104 struct wl_resource *touch_focus_resource;
105 struct wl_listener touch_focus_resource_listener;
106};
107
108enum weston_visual {
109 WESTON_NONE_VISUAL,
110 WESTON_ARGB_VISUAL,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500111 WESTON_RGB_VISUAL
112};
113
114struct weston_shader {
115 GLuint program;
116 GLuint vertex_shader, fragment_shader;
117 GLuint proj_uniform;
118 GLuint tex_uniform;
119 GLuint alpha_uniform;
120 GLuint color_uniform;
121};
122
123struct weston_animation {
124 void (*frame)(struct weston_animation *animation,
125 struct weston_output *output, uint32_t msecs);
126 struct wl_list link;
127};
128
129struct weston_spring {
130 double k;
131 double friction;
132 double current;
133 double target;
134 double previous;
135 uint32_t timestamp;
136};
137
138struct weston_shell {
139 void (*lock)(struct weston_shell *shell);
140 void (*unlock)(struct weston_shell *shell);
141 void (*map)(struct weston_shell *shell, struct weston_surface *surface,
142 int32_t width, int32_t height);
143 void (*configure)(struct weston_shell *shell,
144 struct weston_surface *surface,
145 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500146 void (*destroy)(struct weston_shell *shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500147};
148
149enum {
150 WESTON_COMPOSITOR_ACTIVE,
151 WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
152 WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */
153};
154
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500155struct screenshooter;
156
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500157struct weston_compositor {
158 struct wl_shm *shm;
159 struct weston_xserver *wxs;
160
161 EGLDisplay display;
162 EGLContext context;
163 EGLConfig config;
164 GLuint fbo;
165 GLuint proj_uniform, tex_uniform, alpha_uniform;
166 uint32_t current_alpha;
167 struct weston_shader texture_shader;
168 struct weston_shader solid_shader;
Kristian Høgsberg07632622012-01-25 23:02:06 -0500169 struct weston_shader *current_shader;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500170 struct wl_display *wl_display;
171
172 struct weston_shell *shell;
173
174 /* There can be more than one, but not right now... */
175 struct wl_input_device *input_device;
176
177 struct wl_list output_list;
178 struct wl_list input_device_list;
179 struct wl_list surface_list;
180 struct wl_list binding_list;
181 struct wl_list animation_list;
182 struct {
183 struct weston_spring spring;
184 struct weston_animation animation;
Kristian Høgsberg681f9f42012-01-26 10:55:10 -0500185 struct weston_surface *surface;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500186 } fade;
187
188 uint32_t state;
189 struct wl_event_source *idle_source;
190 uint32_t idle_inhibit;
191 int option_idle_time; /* default timeout, s */
192 int idle_time; /* effective timeout, s */
193
194 /* Repaint state. */
195 struct timespec previous_swap;
196 struct wl_array vertices, indices;
197
198 struct weston_surface *overlay;
199 struct weston_switcher *switcher;
200 uint32_t focus;
201
202 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
203 image_target_renderbuffer_storage;
204 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
205 PFNEGLCREATEIMAGEKHRPROC create_image;
206 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
207 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
208 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
209 int has_bind_display;
210
211 void (*destroy)(struct weston_compositor *ec);
212 int (*authenticate)(struct weston_compositor *c, uint32_t id);
213 EGLImageKHR (*create_cursor_image)(struct weston_compositor *c,
214 int32_t *width, int32_t *height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500215
216 struct screenshooter *screenshooter;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500217};
218
219#define MODIFIER_CTRL (1 << 8)
220#define MODIFIER_ALT (1 << 9)
221#define MODIFIER_SUPER (1 << 10)
222
223enum weston_output_flags {
224 WL_OUTPUT_FLIPPED = 0x01
225};
226
227struct weston_surface {
228 struct wl_surface surface;
229 struct weston_compositor *compositor;
Kristian Høgsberg46e64ee2012-01-26 09:28:42 -0500230 GLuint texture;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500231 pixman_region32_t damage;
232 pixman_region32_t opaque;
233 int32_t x, y, width, height;
234 int32_t pitch;
235 struct wl_list link;
236 struct wl_list buffer_link;
237 struct weston_transform *transform;
Kristian Høgsberg07632622012-01-25 23:02:06 -0500238 struct weston_shader *shader;
239 GLfloat color[4];
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500240 uint32_t alpha;
241 uint32_t visual;
Kristian Høgsberg765bcdf2012-01-25 22:20:30 -0500242 int overlapped;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500243
244 /*
245 * Which output to vsync this surface to.
246 * Used to determine, whether to send or queue frame events.
247 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
248 */
249 struct weston_output *output;
250
251 struct weston_output *fullscreen_output;
252 struct wl_list frame_callback_list;
253
254 EGLImageKHR image;
255
256 struct wl_buffer *buffer;
257 struct wl_listener buffer_destroy_listener;
258};
259
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500260void
261weston_device_repick(struct wl_input_device *device, uint32_t time);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500262
263void
264weston_spring_init(struct weston_spring *spring,
265 double k, double current, double target);
266void
267weston_spring_update(struct weston_spring *spring, uint32_t msec);
268int
269weston_spring_done(struct weston_spring *spring);
270
271void
272weston_surface_activate(struct weston_surface *surface,
273 struct weston_input_device *device, uint32_t time);
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500274void
275weston_surface_draw(struct weston_surface *es, struct weston_output *output);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500276
277void
278notify_motion(struct wl_input_device *device,
279 uint32_t time, int x, int y);
280void
281notify_button(struct wl_input_device *device,
282 uint32_t time, int32_t button, int32_t state);
283void
284notify_key(struct wl_input_device *device,
285 uint32_t time, uint32_t key, uint32_t state);
286
287void
288notify_pointer_focus(struct wl_input_device *device,
289 uint32_t time,
290 struct weston_output *output,
291 int32_t x, int32_t y);
292
293void
294notify_keyboard_focus(struct wl_input_device *device,
295 uint32_t time, struct weston_output *output,
296 struct wl_array *keys);
297
298void
299notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
300 int x, int y, int touch_type);
301
302void
303weston_output_finish_frame(struct weston_output *output, int msecs);
304void
305weston_output_damage(struct weston_output *output);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500306struct weston_surface *
307weston_compositor_pick_surface(struct weston_compositor *compositor,
308 int32_t x, int32_t y, int32_t *sx, int32_t *sy);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500309void
310weston_compositor_repick(struct weston_compositor *compositor);
311void
312weston_compositor_schedule_repaint(struct weston_compositor *compositor);
313void
314weston_compositor_fade(struct weston_compositor *compositor, float tint);
315void
316weston_compositor_damage_all(struct weston_compositor *compositor);
317void
318weston_compositor_unlock(struct weston_compositor *compositor);
319void
320weston_compositor_wake(struct weston_compositor *compositor);
321void
322weston_compositor_activity(struct weston_compositor *compositor);
323
324struct weston_binding;
325typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
326 uint32_t time, uint32_t key,
327 uint32_t button,
328 uint32_t state, void *data);
329struct weston_binding *
330weston_compositor_add_binding(struct weston_compositor *compositor,
331 uint32_t key, uint32_t button, uint32_t modifier,
332 weston_binding_handler_t binding, void *data);
333void
334weston_binding_destroy(struct weston_binding *binding);
335
336void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500337weston_binding_list_destroy_all(struct wl_list *list);
338
339void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500340weston_compositor_run_binding(struct weston_compositor *compositor,
341 struct weston_input_device *device,
342 uint32_t time,
343 uint32_t key, uint32_t button, int32_t state);
Kristian Høgsberga82c4862012-01-26 01:03:58 -0500344struct wl_list *
345weston_compositor_top(struct weston_compositor *compositor);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500346
347struct weston_surface *
348weston_surface_create(struct weston_compositor *compositor,
349 int32_t x, int32_t y, int32_t width, int32_t height);
350
351void
352weston_surface_configure(struct weston_surface *surface,
353 int x, int y, int width, int height);
354
355void
356weston_surface_assign_output(struct weston_surface *surface);
357
358void
359weston_surface_damage(struct weston_surface *surface);
360
361void
362weston_surface_damage_below(struct weston_surface *surface);
363
364void
365weston_surface_damage_rectangle(struct weston_surface *surface,
366 int32_t x, int32_t y,
367 int32_t width, int32_t height);
368
Kristian Høgsberg9f404b72012-01-26 00:11:01 -0500369void
370weston_buffer_post_release(struct wl_buffer *buffer);
371
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500372uint32_t
373weston_compositor_get_time(void);
374
375int
376weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
377void
378weston_compositor_shutdown(struct weston_compositor *ec);
379void
380weston_output_move(struct weston_output *output, int x, int y);
381void
382weston_output_init(struct weston_output *output, struct weston_compositor *c,
383 int x, int y, int width, int height, uint32_t flags);
384void
385weston_output_destroy(struct weston_output *output);
386
387void
388weston_input_device_init(struct weston_input_device *device,
389 struct weston_compositor *ec);
390
391void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500392weston_input_device_release(struct weston_input_device *device);
393
394void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500395weston_switcher_init(struct weston_compositor *compositor);
396
397enum {
398 TTY_ENTER_VT,
399 TTY_LEAVE_VT
400};
401
402typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
403
404struct tty *
405tty_create(struct weston_compositor *compositor,
406 tty_vt_func_t vt_func, int tty_nr);
407
408void
409tty_destroy(struct tty *tty);
410
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500411struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500412screenshooter_create(struct weston_compositor *ec);
413
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500414void
415screenshooter_destroy(struct screenshooter *s);
416
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500417uint32_t *
418weston_load_image(const char *filename,
419 int32_t *width_arg, int32_t *height_arg,
420 uint32_t *stride_arg);
421
422struct weston_process;
423typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
424 int status);
425
426struct weston_process {
427 pid_t pid;
428 weston_process_cleanup_func_t cleanup;
429 struct wl_list link;
430};
431
432struct wl_client *
433weston_client_launch(struct weston_compositor *compositor,
434 struct weston_process *proc,
435 const char *path,
436 weston_process_cleanup_func_t cleanup);
437
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500438void
439weston_watch_process(struct weston_process *process);
440
441int
442weston_xserver_init(struct weston_compositor *compositor);
443void
444weston_xserver_destroy(struct weston_compositor *compositor);
445void
446weston_xserver_surface_activate(struct weston_surface *surface);
447void
448weston_xserver_set_selection(struct weston_input_device *device);
449
450struct weston_zoom;
451typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
452
453struct weston_zoom *
454weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
455 weston_zoom_done_func_t done, void *data);
456
457#endif