blob: 529cc1ac79a82d8cee1924555600d386085acc78 [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
99struct weston_input_device {
100 struct wl_input_device input_device;
101 struct weston_compositor *compositor;
102 struct weston_surface *sprite;
103 int32_t hotspot_x, hotspot_y;
104 struct wl_list link;
105 uint32_t modifier_state;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500106
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500107 uint32_t num_tp;
108 struct wl_surface *touch_focus;
109 struct wl_listener touch_focus_listener;
110 struct wl_resource *touch_focus_resource;
111 struct wl_listener touch_focus_resource_listener;
112};
113
114enum weston_visual {
115 WESTON_NONE_VISUAL,
116 WESTON_ARGB_VISUAL,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500117 WESTON_RGB_VISUAL
118};
119
120struct weston_shader {
121 GLuint program;
122 GLuint vertex_shader, fragment_shader;
123 GLuint proj_uniform;
124 GLuint tex_uniform;
125 GLuint alpha_uniform;
126 GLuint color_uniform;
127};
128
129struct weston_animation {
130 void (*frame)(struct weston_animation *animation,
131 struct weston_output *output, uint32_t msecs);
132 struct wl_list link;
133};
134
135struct weston_spring {
136 double k;
137 double friction;
138 double current;
139 double target;
140 double previous;
141 uint32_t timestamp;
142};
143
144struct weston_shell {
145 void (*lock)(struct weston_shell *shell);
146 void (*unlock)(struct weston_shell *shell);
147 void (*map)(struct weston_shell *shell, struct weston_surface *surface,
148 int32_t width, int32_t height);
149 void (*configure)(struct weston_shell *shell,
150 struct weston_surface *surface,
151 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500152 void (*destroy)(struct weston_shell *shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500153};
154
155enum {
156 WESTON_COMPOSITOR_ACTIVE,
157 WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
158 WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */
159};
160
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500161struct screenshooter;
162
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500163struct weston_compositor {
164 struct wl_shm *shm;
165 struct weston_xserver *wxs;
166
167 EGLDisplay display;
168 EGLContext context;
169 EGLConfig config;
170 GLuint fbo;
171 GLuint proj_uniform, tex_uniform, alpha_uniform;
172 uint32_t current_alpha;
173 struct weston_shader texture_shader;
174 struct weston_shader solid_shader;
175 struct wl_display *wl_display;
176
177 struct weston_shell *shell;
178
179 /* There can be more than one, but not right now... */
180 struct wl_input_device *input_device;
181
182 struct wl_list output_list;
183 struct wl_list input_device_list;
184 struct wl_list surface_list;
185 struct wl_list binding_list;
186 struct wl_list animation_list;
187 struct {
188 struct weston_spring spring;
189 struct weston_animation animation;
190 } fade;
191
192 uint32_t state;
193 struct wl_event_source *idle_source;
194 uint32_t idle_inhibit;
195 int option_idle_time; /* default timeout, s */
196 int idle_time; /* effective timeout, s */
197
198 /* Repaint state. */
199 struct timespec previous_swap;
200 struct wl_array vertices, indices;
201
202 struct weston_surface *overlay;
203 struct weston_switcher *switcher;
204 uint32_t focus;
205
206 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
207 image_target_renderbuffer_storage;
208 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
209 PFNEGLCREATEIMAGEKHRPROC create_image;
210 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
211 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
212 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
213 int has_bind_display;
214
215 void (*destroy)(struct weston_compositor *ec);
216 int (*authenticate)(struct weston_compositor *c, uint32_t id);
217 EGLImageKHR (*create_cursor_image)(struct weston_compositor *c,
218 int32_t *width, int32_t *height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500219
220 struct screenshooter *screenshooter;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500221};
222
223#define MODIFIER_CTRL (1 << 8)
224#define MODIFIER_ALT (1 << 9)
225#define MODIFIER_SUPER (1 << 10)
226
227enum weston_output_flags {
228 WL_OUTPUT_FLIPPED = 0x01
229};
230
231struct weston_surface {
232 struct wl_surface surface;
233 struct weston_compositor *compositor;
234 GLuint texture, saved_texture;
235 pixman_region32_t damage;
236 pixman_region32_t opaque;
237 int32_t x, y, width, height;
238 int32_t pitch;
239 struct wl_list link;
240 struct wl_list buffer_link;
241 struct weston_transform *transform;
242 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
246 /*
247 * Which output to vsync this surface to.
248 * Used to determine, whether to send or queue frame events.
249 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
250 */
251 struct weston_output *output;
252
253 struct weston_output *fullscreen_output;
254 struct wl_list frame_callback_list;
255
256 EGLImageKHR image;
257
258 struct wl_buffer *buffer;
259 struct wl_listener buffer_destroy_listener;
260};
261
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500262void
263weston_device_repick(struct wl_input_device *device, uint32_t time);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500264
265void
266weston_spring_init(struct weston_spring *spring,
267 double k, double current, double target);
268void
269weston_spring_update(struct weston_spring *spring, uint32_t msec);
270int
271weston_spring_done(struct weston_spring *spring);
272
273void
274weston_surface_activate(struct weston_surface *surface,
275 struct weston_input_device *device, uint32_t time);
276
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);
344
345struct weston_surface *
346weston_surface_create(struct weston_compositor *compositor,
347 int32_t x, int32_t y, int32_t width, int32_t height);
348
349void
350weston_surface_configure(struct weston_surface *surface,
351 int x, int y, int width, int height);
352
353void
354weston_surface_assign_output(struct weston_surface *surface);
355
356void
357weston_surface_damage(struct weston_surface *surface);
358
359void
360weston_surface_damage_below(struct weston_surface *surface);
361
362void
363weston_surface_damage_rectangle(struct weston_surface *surface,
364 int32_t x, int32_t y,
365 int32_t width, int32_t height);
366
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500367uint32_t
368weston_compositor_get_time(void);
369
370int
371weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
372void
373weston_compositor_shutdown(struct weston_compositor *ec);
374void
375weston_output_move(struct weston_output *output, int x, int y);
376void
377weston_output_init(struct weston_output *output, struct weston_compositor *c,
378 int x, int y, int width, int height, uint32_t flags);
379void
380weston_output_destroy(struct weston_output *output);
381
382void
383weston_input_device_init(struct weston_input_device *device,
384 struct weston_compositor *ec);
385
386void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500387weston_input_device_release(struct weston_input_device *device);
388
389void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500390weston_switcher_init(struct weston_compositor *compositor);
391
392enum {
393 TTY_ENTER_VT,
394 TTY_LEAVE_VT
395};
396
397typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
398
399struct tty *
400tty_create(struct weston_compositor *compositor,
401 tty_vt_func_t vt_func, int tty_nr);
402
403void
404tty_destroy(struct tty *tty);
405
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500406struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500407screenshooter_create(struct weston_compositor *ec);
408
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500409void
410screenshooter_destroy(struct screenshooter *s);
411
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500412uint32_t *
413weston_load_image(const char *filename,
414 int32_t *width_arg, int32_t *height_arg,
415 uint32_t *stride_arg);
416
417struct weston_process;
418typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
419 int status);
420
421struct weston_process {
422 pid_t pid;
423 weston_process_cleanup_func_t cleanup;
424 struct wl_list link;
425};
426
427struct wl_client *
428weston_client_launch(struct weston_compositor *compositor,
429 struct weston_process *proc,
430 const char *path,
431 weston_process_cleanup_func_t cleanup);
432
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500433void
434weston_watch_process(struct weston_process *process);
435
436int
437weston_xserver_init(struct weston_compositor *compositor);
438void
439weston_xserver_destroy(struct weston_compositor *compositor);
440void
441weston_xserver_surface_activate(struct weston_surface *surface);
442void
443weston_xserver_set_selection(struct weston_input_device *device);
444
445struct weston_zoom;
446typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
447
448struct weston_zoom *
449weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
450 weston_zoom_done_func_t done, void *data);
451
452#endif