blob: 0f473937ffc02f69d30f6b44bee2c6bc26c84cf2 [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
107 struct wl_list drag_resource_list;
108 struct weston_data_source *drag_data_source;
109 struct wl_surface *drag_focus;
110 struct wl_resource *drag_focus_resource;
111 struct wl_listener drag_focus_listener;
112
113 struct weston_data_source *selection_data_source;
114 struct wl_listener selection_data_source_listener;
115 struct wl_grab grab;
116
117 uint32_t num_tp;
118 struct wl_surface *touch_focus;
119 struct wl_listener touch_focus_listener;
120 struct wl_resource *touch_focus_resource;
121 struct wl_listener touch_focus_resource_listener;
122};
123
124enum weston_visual {
125 WESTON_NONE_VISUAL,
126 WESTON_ARGB_VISUAL,
127 WESTON_PREMUL_ARGB_VISUAL,
128 WESTON_RGB_VISUAL
129};
130
131struct weston_shader {
132 GLuint program;
133 GLuint vertex_shader, fragment_shader;
134 GLuint proj_uniform;
135 GLuint tex_uniform;
136 GLuint alpha_uniform;
137 GLuint color_uniform;
138};
139
140struct weston_animation {
141 void (*frame)(struct weston_animation *animation,
142 struct weston_output *output, uint32_t msecs);
143 struct wl_list link;
144};
145
146struct weston_spring {
147 double k;
148 double friction;
149 double current;
150 double target;
151 double previous;
152 uint32_t timestamp;
153};
154
155struct weston_shell {
156 void (*lock)(struct weston_shell *shell);
157 void (*unlock)(struct weston_shell *shell);
158 void (*map)(struct weston_shell *shell, struct weston_surface *surface,
159 int32_t width, int32_t height);
160 void (*configure)(struct weston_shell *shell,
161 struct weston_surface *surface,
162 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500163 void (*destroy)(struct weston_shell *shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500164};
165
166enum {
167 WESTON_COMPOSITOR_ACTIVE,
168 WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
169 WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */
170};
171
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500172struct screenshooter;
173
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500174struct weston_compositor {
175 struct wl_shm *shm;
176 struct weston_xserver *wxs;
177
178 EGLDisplay display;
179 EGLContext context;
180 EGLConfig config;
181 GLuint fbo;
182 GLuint proj_uniform, tex_uniform, alpha_uniform;
183 uint32_t current_alpha;
184 struct weston_shader texture_shader;
185 struct weston_shader solid_shader;
186 struct wl_display *wl_display;
187
188 struct weston_shell *shell;
189
190 /* There can be more than one, but not right now... */
191 struct wl_input_device *input_device;
192
193 struct wl_list output_list;
194 struct wl_list input_device_list;
195 struct wl_list surface_list;
196 struct wl_list binding_list;
197 struct wl_list animation_list;
198 struct {
199 struct weston_spring spring;
200 struct weston_animation animation;
201 } fade;
202
203 uint32_t state;
204 struct wl_event_source *idle_source;
205 uint32_t idle_inhibit;
206 int option_idle_time; /* default timeout, s */
207 int idle_time; /* effective timeout, s */
208
209 /* Repaint state. */
210 struct timespec previous_swap;
211 struct wl_array vertices, indices;
212
213 struct weston_surface *overlay;
214 struct weston_switcher *switcher;
215 uint32_t focus;
216
217 PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
218 image_target_renderbuffer_storage;
219 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
220 PFNEGLCREATEIMAGEKHRPROC create_image;
221 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
222 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
223 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
224 int has_bind_display;
225
226 void (*destroy)(struct weston_compositor *ec);
227 int (*authenticate)(struct weston_compositor *c, uint32_t id);
228 EGLImageKHR (*create_cursor_image)(struct weston_compositor *c,
229 int32_t *width, int32_t *height);
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500230
231 struct screenshooter *screenshooter;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500232};
233
234#define MODIFIER_CTRL (1 << 8)
235#define MODIFIER_ALT (1 << 9)
236#define MODIFIER_SUPER (1 << 10)
237
238enum weston_output_flags {
239 WL_OUTPUT_FLIPPED = 0x01
240};
241
242struct weston_surface {
243 struct wl_surface surface;
244 struct weston_compositor *compositor;
245 GLuint texture, saved_texture;
246 pixman_region32_t damage;
247 pixman_region32_t opaque;
248 int32_t x, y, width, height;
249 int32_t pitch;
250 struct wl_list link;
251 struct wl_list buffer_link;
252 struct weston_transform *transform;
253 uint32_t alpha;
254 uint32_t visual;
255
256 /*
257 * Which output to vsync this surface to.
258 * Used to determine, whether to send or queue frame events.
259 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
260 */
261 struct weston_output *output;
262
263 struct weston_output *fullscreen_output;
264 struct wl_list frame_callback_list;
265
266 EGLImageKHR image;
267
268 struct wl_buffer *buffer;
269 struct wl_listener buffer_destroy_listener;
270};
271
272struct weston_data_source {
273 struct wl_resource resource;
274 struct wl_array mime_types;
275 int refcount;
276 void *data;
277
278 struct wl_resource *(*create_offer)(struct weston_data_source *source,
279 struct wl_resource *target);
280
281 void (*cancel)(struct weston_data_source *source);
282};
283
284void
285weston_data_source_unref(struct weston_data_source *source);
286
287void
288weston_input_device_set_selection(struct weston_input_device *device,
289 struct weston_data_source *source,
290 uint32_t time);
291
292void
293weston_spring_init(struct weston_spring *spring,
294 double k, double current, double target);
295void
296weston_spring_update(struct weston_spring *spring, uint32_t msec);
297int
298weston_spring_done(struct weston_spring *spring);
299
300void
301weston_surface_activate(struct weston_surface *surface,
302 struct weston_input_device *device, uint32_t time);
303
304void
305notify_motion(struct wl_input_device *device,
306 uint32_t time, int x, int y);
307void
308notify_button(struct wl_input_device *device,
309 uint32_t time, int32_t button, int32_t state);
310void
311notify_key(struct wl_input_device *device,
312 uint32_t time, uint32_t key, uint32_t state);
313
314void
315notify_pointer_focus(struct wl_input_device *device,
316 uint32_t time,
317 struct weston_output *output,
318 int32_t x, int32_t y);
319
320void
321notify_keyboard_focus(struct wl_input_device *device,
322 uint32_t time, struct weston_output *output,
323 struct wl_array *keys);
324
325void
326notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
327 int x, int y, int touch_type);
328
329void
330weston_output_finish_frame(struct weston_output *output, int msecs);
331void
332weston_output_damage(struct weston_output *output);
333void
334weston_compositor_repick(struct weston_compositor *compositor);
335void
336weston_compositor_schedule_repaint(struct weston_compositor *compositor);
337void
338weston_compositor_fade(struct weston_compositor *compositor, float tint);
339void
340weston_compositor_damage_all(struct weston_compositor *compositor);
341void
342weston_compositor_unlock(struct weston_compositor *compositor);
343void
344weston_compositor_wake(struct weston_compositor *compositor);
345void
346weston_compositor_activity(struct weston_compositor *compositor);
347
348struct weston_binding;
349typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
350 uint32_t time, uint32_t key,
351 uint32_t button,
352 uint32_t state, void *data);
353struct weston_binding *
354weston_compositor_add_binding(struct weston_compositor *compositor,
355 uint32_t key, uint32_t button, uint32_t modifier,
356 weston_binding_handler_t binding, void *data);
357void
358weston_binding_destroy(struct weston_binding *binding);
359
360void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500361weston_binding_list_destroy_all(struct wl_list *list);
362
363void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500364weston_compositor_run_binding(struct weston_compositor *compositor,
365 struct weston_input_device *device,
366 uint32_t time,
367 uint32_t key, uint32_t button, int32_t state);
368
369struct weston_surface *
370weston_surface_create(struct weston_compositor *compositor,
371 int32_t x, int32_t y, int32_t width, int32_t height);
372
373void
374weston_surface_configure(struct weston_surface *surface,
375 int x, int y, int width, int height);
376
377void
378weston_surface_assign_output(struct weston_surface *surface);
379
380void
381weston_surface_damage(struct weston_surface *surface);
382
383void
384weston_surface_damage_below(struct weston_surface *surface);
385
386void
387weston_surface_damage_rectangle(struct weston_surface *surface,
388 int32_t x, int32_t y,
389 int32_t width, int32_t height);
390
391struct weston_surface *
392pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
393
394uint32_t
395weston_compositor_get_time(void);
396
397int
398weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
399void
400weston_compositor_shutdown(struct weston_compositor *ec);
401void
402weston_output_move(struct weston_output *output, int x, int y);
403void
404weston_output_init(struct weston_output *output, struct weston_compositor *c,
405 int x, int y, int width, int height, uint32_t flags);
406void
407weston_output_destroy(struct weston_output *output);
408
409void
410weston_input_device_init(struct weston_input_device *device,
411 struct weston_compositor *ec);
412
413void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500414weston_input_device_release(struct weston_input_device *device);
415
416void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500417weston_switcher_init(struct weston_compositor *compositor);
418
419enum {
420 TTY_ENTER_VT,
421 TTY_LEAVE_VT
422};
423
424typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
425
426struct tty *
427tty_create(struct weston_compositor *compositor,
428 tty_vt_func_t vt_func, int tty_nr);
429
430void
431tty_destroy(struct tty *tty);
432
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500433struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500434screenshooter_create(struct weston_compositor *ec);
435
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500436void
437screenshooter_destroy(struct screenshooter *s);
438
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500439uint32_t *
440weston_load_image(const char *filename,
441 int32_t *width_arg, int32_t *height_arg,
442 uint32_t *stride_arg);
443
444struct weston_process;
445typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
446 int status);
447
448struct weston_process {
449 pid_t pid;
450 weston_process_cleanup_func_t cleanup;
451 struct wl_list link;
452};
453
454struct wl_client *
455weston_client_launch(struct weston_compositor *compositor,
456 struct weston_process *proc,
457 const char *path,
458 weston_process_cleanup_func_t cleanup);
459
460int
461weston_data_device_manager_init(struct weston_compositor *compositor);
462void
463weston_data_device_set_keyboard_focus(struct weston_input_device *device);
464
465void
466weston_watch_process(struct weston_process *process);
467
468int
469weston_xserver_init(struct weston_compositor *compositor);
470void
471weston_xserver_destroy(struct weston_compositor *compositor);
472void
473weston_xserver_surface_activate(struct weston_surface *surface);
474void
475weston_xserver_set_selection(struct weston_input_device *device);
476
477struct weston_zoom;
478typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
479
480struct weston_zoom *
481weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
482 weston_zoom_done_func_t done, void *data);
483
484#endif