blob: b995b13a0b2e88b9b3014cd3db8548d324145752 [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;
185 } fade;
186
187 uint32_t state;
188 struct wl_event_source *idle_source;
189 uint32_t idle_inhibit;
190 int option_idle_time; /* default timeout, s */
191 int idle_time; /* effective timeout, s */
192
193 /* Repaint state. */
194 struct timespec previous_swap;
195 struct wl_array vertices, indices;
196
197 struct weston_surface *overlay;
198 struct weston_switcher *switcher;
199 uint32_t focus;
200
201 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
202 image_target_renderbuffer_storage;
203 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
204 PFNEGLCREATEIMAGEKHRPROC create_image;
205 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
206 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
207 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
208 int has_bind_display;
209
210 void (*destroy)(struct weston_compositor *ec);
211 int (*authenticate)(struct weston_compositor *c, uint32_t id);
212 EGLImageKHR (*create_cursor_image)(struct weston_compositor *c,
213 int32_t *width, int32_t *height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500214
215 struct screenshooter *screenshooter;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500216};
217
218#define MODIFIER_CTRL (1 << 8)
219#define MODIFIER_ALT (1 << 9)
220#define MODIFIER_SUPER (1 << 10)
221
222enum weston_output_flags {
223 WL_OUTPUT_FLIPPED = 0x01
224};
225
226struct weston_surface {
227 struct wl_surface surface;
228 struct weston_compositor *compositor;
229 GLuint texture, saved_texture;
230 pixman_region32_t damage;
231 pixman_region32_t opaque;
232 int32_t x, y, width, height;
233 int32_t pitch;
234 struct wl_list link;
235 struct wl_list buffer_link;
236 struct weston_transform *transform;
Kristian Høgsberg07632622012-01-25 23:02:06 -0500237 struct weston_shader *shader;
238 GLfloat color[4];
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500239 uint32_t alpha;
240 uint32_t visual;
Kristian Høgsberg765bcdf2012-01-25 22:20:30 -0500241 int overlapped;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500242
243 /*
244 * Which output to vsync this surface to.
245 * Used to determine, whether to send or queue frame events.
246 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
247 */
248 struct weston_output *output;
249
250 struct weston_output *fullscreen_output;
251 struct wl_list frame_callback_list;
252
253 EGLImageKHR image;
254
255 struct wl_buffer *buffer;
256 struct wl_listener buffer_destroy_listener;
257};
258
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500259void
260weston_device_repick(struct wl_input_device *device, uint32_t time);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500261
262void
263weston_spring_init(struct weston_spring *spring,
264 double k, double current, double target);
265void
266weston_spring_update(struct weston_spring *spring, uint32_t msec);
267int
268weston_spring_done(struct weston_spring *spring);
269
270void
271weston_surface_activate(struct weston_surface *surface,
272 struct weston_input_device *device, uint32_t time);
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500273void
274weston_surface_draw(struct weston_surface *es, struct weston_output *output);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500275
276void
277notify_motion(struct wl_input_device *device,
278 uint32_t time, int x, int y);
279void
280notify_button(struct wl_input_device *device,
281 uint32_t time, int32_t button, int32_t state);
282void
283notify_key(struct wl_input_device *device,
284 uint32_t time, uint32_t key, uint32_t state);
285
286void
287notify_pointer_focus(struct wl_input_device *device,
288 uint32_t time,
289 struct weston_output *output,
290 int32_t x, int32_t y);
291
292void
293notify_keyboard_focus(struct wl_input_device *device,
294 uint32_t time, struct weston_output *output,
295 struct wl_array *keys);
296
297void
298notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
299 int x, int y, int touch_type);
300
301void
302weston_output_finish_frame(struct weston_output *output, int msecs);
303void
304weston_output_damage(struct weston_output *output);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500305struct weston_surface *
306weston_compositor_pick_surface(struct weston_compositor *compositor,
307 int32_t x, int32_t y, int32_t *sx, int32_t *sy);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500308void
309weston_compositor_repick(struct weston_compositor *compositor);
310void
311weston_compositor_schedule_repaint(struct weston_compositor *compositor);
312void
313weston_compositor_fade(struct weston_compositor *compositor, float tint);
314void
315weston_compositor_damage_all(struct weston_compositor *compositor);
316void
317weston_compositor_unlock(struct weston_compositor *compositor);
318void
319weston_compositor_wake(struct weston_compositor *compositor);
320void
321weston_compositor_activity(struct weston_compositor *compositor);
322
323struct weston_binding;
324typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
325 uint32_t time, uint32_t key,
326 uint32_t button,
327 uint32_t state, void *data);
328struct weston_binding *
329weston_compositor_add_binding(struct weston_compositor *compositor,
330 uint32_t key, uint32_t button, uint32_t modifier,
331 weston_binding_handler_t binding, void *data);
332void
333weston_binding_destroy(struct weston_binding *binding);
334
335void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500336weston_binding_list_destroy_all(struct wl_list *list);
337
338void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500339weston_compositor_run_binding(struct weston_compositor *compositor,
340 struct weston_input_device *device,
341 uint32_t time,
342 uint32_t key, uint32_t button, int32_t state);
Kristian Høgsberga82c4862012-01-26 01:03:58 -0500343struct wl_list *
344weston_compositor_top(struct weston_compositor *compositor);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500345
346struct weston_surface *
347weston_surface_create(struct weston_compositor *compositor,
348 int32_t x, int32_t y, int32_t width, int32_t height);
349
350void
351weston_surface_configure(struct weston_surface *surface,
352 int x, int y, int width, int height);
353
354void
355weston_surface_assign_output(struct weston_surface *surface);
356
357void
358weston_surface_damage(struct weston_surface *surface);
359
360void
361weston_surface_damage_below(struct weston_surface *surface);
362
363void
364weston_surface_damage_rectangle(struct weston_surface *surface,
365 int32_t x, int32_t y,
366 int32_t width, int32_t height);
367
Kristian Høgsberg9f404b72012-01-26 00:11:01 -0500368void
369weston_buffer_post_release(struct wl_buffer *buffer);
370
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500371uint32_t
372weston_compositor_get_time(void);
373
374int
375weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
376void
377weston_compositor_shutdown(struct weston_compositor *ec);
378void
379weston_output_move(struct weston_output *output, int x, int y);
380void
381weston_output_init(struct weston_output *output, struct weston_compositor *c,
382 int x, int y, int width, int height, uint32_t flags);
383void
384weston_output_destroy(struct weston_output *output);
385
386void
387weston_input_device_init(struct weston_input_device *device,
388 struct weston_compositor *ec);
389
390void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500391weston_input_device_release(struct weston_input_device *device);
392
393void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500394weston_switcher_init(struct weston_compositor *compositor);
395
396enum {
397 TTY_ENTER_VT,
398 TTY_LEAVE_VT
399};
400
401typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
402
403struct tty *
404tty_create(struct weston_compositor *compositor,
405 tty_vt_func_t vt_func, int tty_nr);
406
407void
408tty_destroy(struct tty *tty);
409
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500410struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500411screenshooter_create(struct weston_compositor *ec);
412
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500413void
414screenshooter_destroy(struct screenshooter *s);
415
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500416uint32_t *
417weston_load_image(const char *filename,
418 int32_t *width_arg, int32_t *height_arg,
419 uint32_t *stride_arg);
420
421struct weston_process;
422typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
423 int status);
424
425struct weston_process {
426 pid_t pid;
427 weston_process_cleanup_func_t cleanup;
428 struct wl_list link;
429};
430
431struct wl_client *
432weston_client_launch(struct weston_compositor *compositor,
433 struct weston_process *proc,
434 const char *path,
435 weston_process_cleanup_func_t cleanup);
436
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500437void
438weston_watch_process(struct weston_process *process);
439
440int
441weston_xserver_init(struct weston_compositor *compositor);
442void
443weston_xserver_destroy(struct weston_compositor *compositor);
444void
445weston_xserver_surface_activate(struct weston_surface *surface);
446void
447weston_xserver_set_selection(struct weston_input_device *device);
448
449struct weston_zoom;
450typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
451
452struct weston_zoom *
453weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
454 weston_zoom_done_func_t done, void *data);
455
456#endif