blob: 3ac6558441a9da2eb83dfe45ba9e16658de13cf1 [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
Pekka Paalanenc61eca62012-01-06 14:10:06 +020046weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n);
47void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050048weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
49void
50weston_matrix_translate(struct weston_matrix *matrix,
51 GLfloat x, GLfloat y, GLfloat z);
52void
53weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
54
55struct weston_transform {
56 struct weston_matrix matrix;
57 struct weston_matrix inverse;
Pekka Paalanenc61eca62012-01-06 14:10:06 +020058 struct wl_list link;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050059};
60
61struct weston_surface;
62struct weston_input_device;
63
64struct weston_mode {
65 uint32_t flags;
66 int32_t width, height;
67 uint32_t refresh;
68 struct wl_list link;
69};
70
71struct weston_output {
72 struct wl_list link;
73 struct weston_compositor *compositor;
74 struct weston_matrix matrix;
75 struct wl_list frame_callback_list;
76 int32_t x, y, mm_width, mm_height;
77 pixman_region32_t region;
78 pixman_region32_t previous_damage;
79 uint32_t flags;
80 int repaint_needed;
81 int repaint_scheduled;
82
83 char *make, *model;
84 uint32_t subpixel;
85
86 struct weston_mode *current;
87 struct wl_list mode_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050088
Kristian Høgsberg68c479a2012-01-25 23:32:28 -050089 void (*repaint)(struct weston_output *output);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050090 int (*set_hardware_cursor)(struct weston_output *output,
91 struct weston_input_device *input);
92 void (*destroy)(struct weston_output *output);
93};
94
95struct weston_input_device {
96 struct wl_input_device input_device;
97 struct weston_compositor *compositor;
98 struct weston_surface *sprite;
99 int32_t hotspot_x, hotspot_y;
100 struct wl_list link;
101 uint32_t modifier_state;
Kristian Høgsberga82c4862012-01-26 01:03:58 -0500102 int hw_cursor;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500103
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500104 uint32_t num_tp;
105 struct wl_surface *touch_focus;
106 struct wl_listener touch_focus_listener;
107 struct wl_resource *touch_focus_resource;
108 struct wl_listener touch_focus_resource_listener;
109};
110
111enum weston_visual {
112 WESTON_NONE_VISUAL,
113 WESTON_ARGB_VISUAL,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500114 WESTON_RGB_VISUAL
115};
116
117struct weston_shader {
118 GLuint program;
119 GLuint vertex_shader, fragment_shader;
120 GLuint proj_uniform;
121 GLuint tex_uniform;
122 GLuint alpha_uniform;
123 GLuint color_uniform;
124};
125
126struct weston_animation {
127 void (*frame)(struct weston_animation *animation,
128 struct weston_output *output, uint32_t msecs);
129 struct wl_list link;
130};
131
132struct weston_spring {
133 double k;
134 double friction;
135 double current;
136 double target;
137 double previous;
138 uint32_t timestamp;
139};
140
141struct weston_shell {
142 void (*lock)(struct weston_shell *shell);
143 void (*unlock)(struct weston_shell *shell);
144 void (*map)(struct weston_shell *shell, struct weston_surface *surface,
145 int32_t width, int32_t height);
146 void (*configure)(struct weston_shell *shell,
147 struct weston_surface *surface,
148 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500149 void (*destroy)(struct weston_shell *shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500150};
151
152enum {
153 WESTON_COMPOSITOR_ACTIVE,
154 WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
155 WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */
156};
157
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500158struct screenshooter;
159
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500160struct weston_compositor {
161 struct wl_shm *shm;
162 struct weston_xserver *wxs;
163
164 EGLDisplay display;
165 EGLContext context;
166 EGLConfig config;
167 GLuint fbo;
168 GLuint proj_uniform, tex_uniform, alpha_uniform;
169 uint32_t current_alpha;
170 struct weston_shader texture_shader;
171 struct weston_shader solid_shader;
Kristian Høgsberg07632622012-01-25 23:02:06 -0500172 struct weston_shader *current_shader;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500173 struct wl_display *wl_display;
174
175 struct weston_shell *shell;
176
177 /* There can be more than one, but not right now... */
178 struct wl_input_device *input_device;
179
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;
185 struct {
186 struct weston_spring spring;
187 struct weston_animation animation;
Kristian Høgsberg681f9f42012-01-26 10:55:10 -0500188 struct weston_surface *surface;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500189 } fade;
190
191 uint32_t state;
192 struct wl_event_source *idle_source;
193 uint32_t idle_inhibit;
194 int option_idle_time; /* default timeout, s */
195 int idle_time; /* effective timeout, s */
196
197 /* Repaint state. */
198 struct timespec previous_swap;
199 struct wl_array vertices, indices;
200
201 struct weston_surface *overlay;
202 struct weston_switcher *switcher;
203 uint32_t focus;
204
205 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
206 image_target_renderbuffer_storage;
207 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
208 PFNEGLCREATEIMAGEKHRPROC create_image;
209 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
210 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
211 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
212 int has_bind_display;
213
214 void (*destroy)(struct weston_compositor *ec);
215 int (*authenticate)(struct weston_compositor *c, uint32_t id);
216 EGLImageKHR (*create_cursor_image)(struct weston_compositor *c,
217 int32_t *width, int32_t *height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500218
219 struct screenshooter *screenshooter;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500220};
221
222#define MODIFIER_CTRL (1 << 8)
223#define MODIFIER_ALT (1 << 9)
224#define MODIFIER_SUPER (1 << 10)
225
226enum weston_output_flags {
227 WL_OUTPUT_FLIPPED = 0x01
228};
229
230struct weston_surface {
231 struct wl_surface surface;
232 struct weston_compositor *compositor;
Kristian Høgsberg46e64ee2012-01-26 09:28:42 -0500233 GLuint texture;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500234 pixman_region32_t damage;
235 pixman_region32_t opaque;
236 int32_t x, y, width, height;
237 int32_t pitch;
238 struct wl_list link;
239 struct wl_list buffer_link;
Kristian Høgsberg07632622012-01-25 23:02:06 -0500240 struct weston_shader *shader;
241 GLfloat color[4];
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500242 uint32_t alpha;
243 uint32_t visual;
Kristian Høgsberg765bcdf2012-01-25 22:20:30 -0500244 int overlapped;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500245
Pekka Paalanenc61eca62012-01-06 14:10:06 +0200246 struct {
247 struct wl_list list;
248 int dirty;
249
250 struct weston_transform cached;
251 int enabled;
252 } transform;
253
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500254 /*
255 * Which output to vsync this surface to.
256 * Used to determine, whether to send or queue frame events.
257 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
258 */
259 struct weston_output *output;
260
261 struct weston_output *fullscreen_output;
262 struct wl_list frame_callback_list;
263
264 EGLImageKHR image;
265
266 struct wl_buffer *buffer;
267 struct wl_listener buffer_destroy_listener;
268};
269
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500270void
271weston_device_repick(struct wl_input_device *device, uint32_t time);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500272
273void
274weston_spring_init(struct weston_spring *spring,
275 double k, double current, double target);
276void
277weston_spring_update(struct weston_spring *spring, uint32_t msec);
278int
279weston_spring_done(struct weston_spring *spring);
280
281void
282weston_surface_activate(struct weston_surface *surface,
283 struct weston_input_device *device, uint32_t time);
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500284void
285weston_surface_draw(struct weston_surface *es, struct weston_output *output);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500286
287void
288notify_motion(struct wl_input_device *device,
289 uint32_t time, int x, int y);
290void
291notify_button(struct wl_input_device *device,
292 uint32_t time, int32_t button, int32_t state);
293void
294notify_key(struct wl_input_device *device,
295 uint32_t time, uint32_t key, uint32_t state);
296
297void
298notify_pointer_focus(struct wl_input_device *device,
299 uint32_t time,
300 struct weston_output *output,
301 int32_t x, int32_t y);
302
303void
304notify_keyboard_focus(struct wl_input_device *device,
305 uint32_t time, struct weston_output *output,
306 struct wl_array *keys);
307
308void
309notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
310 int x, int y, int touch_type);
311
312void
313weston_output_finish_frame(struct weston_output *output, int msecs);
314void
315weston_output_damage(struct weston_output *output);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500316struct weston_surface *
317weston_compositor_pick_surface(struct weston_compositor *compositor,
318 int32_t x, int32_t y, int32_t *sx, int32_t *sy);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500319void
320weston_compositor_repick(struct weston_compositor *compositor);
321void
322weston_compositor_schedule_repaint(struct weston_compositor *compositor);
323void
324weston_compositor_fade(struct weston_compositor *compositor, float tint);
325void
326weston_compositor_damage_all(struct weston_compositor *compositor);
327void
328weston_compositor_unlock(struct weston_compositor *compositor);
329void
330weston_compositor_wake(struct weston_compositor *compositor);
331void
332weston_compositor_activity(struct weston_compositor *compositor);
333
334struct weston_binding;
335typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
336 uint32_t time, uint32_t key,
337 uint32_t button,
338 uint32_t state, void *data);
339struct weston_binding *
340weston_compositor_add_binding(struct weston_compositor *compositor,
341 uint32_t key, uint32_t button, uint32_t modifier,
342 weston_binding_handler_t binding, void *data);
343void
344weston_binding_destroy(struct weston_binding *binding);
345
346void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500347weston_binding_list_destroy_all(struct wl_list *list);
348
349void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500350weston_compositor_run_binding(struct weston_compositor *compositor,
351 struct weston_input_device *device,
352 uint32_t time,
353 uint32_t key, uint32_t button, int32_t state);
Kristian Høgsberga82c4862012-01-26 01:03:58 -0500354struct wl_list *
355weston_compositor_top(struct weston_compositor *compositor);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500356
357struct weston_surface *
358weston_surface_create(struct weston_compositor *compositor,
359 int32_t x, int32_t y, int32_t width, int32_t height);
360
361void
362weston_surface_configure(struct weston_surface *surface,
363 int x, int y, int width, int height);
364
365void
366weston_surface_assign_output(struct weston_surface *surface);
367
368void
369weston_surface_damage(struct weston_surface *surface);
370
371void
372weston_surface_damage_below(struct weston_surface *surface);
373
374void
375weston_surface_damage_rectangle(struct weston_surface *surface,
376 int32_t x, int32_t y,
377 int32_t width, int32_t height);
378
Kristian Høgsberg9f404b72012-01-26 00:11:01 -0500379void
380weston_buffer_post_release(struct wl_buffer *buffer);
381
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500382uint32_t
383weston_compositor_get_time(void);
384
385int
386weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
387void
388weston_compositor_shutdown(struct weston_compositor *ec);
389void
390weston_output_move(struct weston_output *output, int x, int y);
391void
392weston_output_init(struct weston_output *output, struct weston_compositor *c,
393 int x, int y, int width, int height, uint32_t flags);
394void
395weston_output_destroy(struct weston_output *output);
396
397void
398weston_input_device_init(struct weston_input_device *device,
399 struct weston_compositor *ec);
400
401void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500402weston_input_device_release(struct weston_input_device *device);
403
404void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500405weston_switcher_init(struct weston_compositor *compositor);
406
407enum {
408 TTY_ENTER_VT,
409 TTY_LEAVE_VT
410};
411
412typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
413
414struct tty *
415tty_create(struct weston_compositor *compositor,
416 tty_vt_func_t vt_func, int tty_nr);
417
418void
419tty_destroy(struct tty *tty);
420
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500421struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500422screenshooter_create(struct weston_compositor *ec);
423
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500424void
425screenshooter_destroy(struct screenshooter *s);
426
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500427uint32_t *
428weston_load_image(const char *filename,
429 int32_t *width_arg, int32_t *height_arg,
430 uint32_t *stride_arg);
431
432struct weston_process;
433typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
434 int status);
435
436struct weston_process {
437 pid_t pid;
438 weston_process_cleanup_func_t cleanup;
439 struct wl_list link;
440};
441
442struct wl_client *
443weston_client_launch(struct weston_compositor *compositor,
444 struct weston_process *proc,
445 const char *path,
446 weston_process_cleanup_func_t cleanup);
447
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500448void
449weston_watch_process(struct weston_process *process);
450
451int
452weston_xserver_init(struct weston_compositor *compositor);
453void
454weston_xserver_destroy(struct weston_compositor *compositor);
455void
456weston_xserver_surface_activate(struct weston_surface *surface);
457void
458weston_xserver_set_selection(struct weston_input_device *device);
459
460struct weston_zoom;
461typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
462
463struct weston_zoom *
464weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
465 weston_zoom_done_func_t done, void *data);
466
467#endif