blob: f453004969895b1862432b3ebd58ae591549d1bd [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
Kristian Høgsberg82d9ee92012-01-03 14:11:07 -0500272struct weston_data_offer {
273 struct wl_resource resource;
274 struct weston_data_source *source;
275 struct wl_listener source_destroy_listener;
276};
277
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500278struct weston_data_source {
279 struct wl_resource resource;
280 struct wl_array mime_types;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500281
Kristian Høgsberg82d9ee92012-01-03 14:11:07 -0500282 const struct wl_data_offer_interface *offer_interface;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500283 void (*cancel)(struct weston_data_source *source);
284};
285
286void
287weston_data_source_unref(struct weston_data_source *source);
288
289void
290weston_input_device_set_selection(struct weston_input_device *device,
291 struct weston_data_source *source,
292 uint32_t time);
293
294void
295weston_spring_init(struct weston_spring *spring,
296 double k, double current, double target);
297void
298weston_spring_update(struct weston_spring *spring, uint32_t msec);
299int
300weston_spring_done(struct weston_spring *spring);
301
302void
303weston_surface_activate(struct weston_surface *surface,
304 struct weston_input_device *device, uint32_t time);
305
306void
307notify_motion(struct wl_input_device *device,
308 uint32_t time, int x, int y);
309void
310notify_button(struct wl_input_device *device,
311 uint32_t time, int32_t button, int32_t state);
312void
313notify_key(struct wl_input_device *device,
314 uint32_t time, uint32_t key, uint32_t state);
315
316void
317notify_pointer_focus(struct wl_input_device *device,
318 uint32_t time,
319 struct weston_output *output,
320 int32_t x, int32_t y);
321
322void
323notify_keyboard_focus(struct wl_input_device *device,
324 uint32_t time, struct weston_output *output,
325 struct wl_array *keys);
326
327void
328notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
329 int x, int y, int touch_type);
330
331void
332weston_output_finish_frame(struct weston_output *output, int msecs);
333void
334weston_output_damage(struct weston_output *output);
335void
336weston_compositor_repick(struct weston_compositor *compositor);
337void
338weston_compositor_schedule_repaint(struct weston_compositor *compositor);
339void
340weston_compositor_fade(struct weston_compositor *compositor, float tint);
341void
342weston_compositor_damage_all(struct weston_compositor *compositor);
343void
344weston_compositor_unlock(struct weston_compositor *compositor);
345void
346weston_compositor_wake(struct weston_compositor *compositor);
347void
348weston_compositor_activity(struct weston_compositor *compositor);
349
350struct weston_binding;
351typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
352 uint32_t time, uint32_t key,
353 uint32_t button,
354 uint32_t state, void *data);
355struct weston_binding *
356weston_compositor_add_binding(struct weston_compositor *compositor,
357 uint32_t key, uint32_t button, uint32_t modifier,
358 weston_binding_handler_t binding, void *data);
359void
360weston_binding_destroy(struct weston_binding *binding);
361
362void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500363weston_binding_list_destroy_all(struct wl_list *list);
364
365void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500366weston_compositor_run_binding(struct weston_compositor *compositor,
367 struct weston_input_device *device,
368 uint32_t time,
369 uint32_t key, uint32_t button, int32_t state);
370
371struct weston_surface *
372weston_surface_create(struct weston_compositor *compositor,
373 int32_t x, int32_t y, int32_t width, int32_t height);
374
375void
376weston_surface_configure(struct weston_surface *surface,
377 int x, int y, int width, int height);
378
379void
380weston_surface_assign_output(struct weston_surface *surface);
381
382void
383weston_surface_damage(struct weston_surface *surface);
384
385void
386weston_surface_damage_below(struct weston_surface *surface);
387
388void
389weston_surface_damage_rectangle(struct weston_surface *surface,
390 int32_t x, int32_t y,
391 int32_t width, int32_t height);
392
393struct weston_surface *
394pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
395
396uint32_t
397weston_compositor_get_time(void);
398
399int
400weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
401void
402weston_compositor_shutdown(struct weston_compositor *ec);
403void
404weston_output_move(struct weston_output *output, int x, int y);
405void
406weston_output_init(struct weston_output *output, struct weston_compositor *c,
407 int x, int y, int width, int height, uint32_t flags);
408void
409weston_output_destroy(struct weston_output *output);
410
411void
412weston_input_device_init(struct weston_input_device *device,
413 struct weston_compositor *ec);
414
415void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500416weston_input_device_release(struct weston_input_device *device);
417
418void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500419weston_switcher_init(struct weston_compositor *compositor);
420
421enum {
422 TTY_ENTER_VT,
423 TTY_LEAVE_VT
424};
425
426typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
427
428struct tty *
429tty_create(struct weston_compositor *compositor,
430 tty_vt_func_t vt_func, int tty_nr);
431
432void
433tty_destroy(struct tty *tty);
434
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500435struct screenshooter *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500436screenshooter_create(struct weston_compositor *ec);
437
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500438void
439screenshooter_destroy(struct screenshooter *s);
440
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500441uint32_t *
442weston_load_image(const char *filename,
443 int32_t *width_arg, int32_t *height_arg,
444 uint32_t *stride_arg);
445
446struct weston_process;
447typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
448 int status);
449
450struct weston_process {
451 pid_t pid;
452 weston_process_cleanup_func_t cleanup;
453 struct wl_list link;
454};
455
456struct wl_client *
457weston_client_launch(struct weston_compositor *compositor,
458 struct weston_process *proc,
459 const char *path,
460 weston_process_cleanup_func_t cleanup);
461
462int
463weston_data_device_manager_init(struct weston_compositor *compositor);
464void
465weston_data_device_set_keyboard_focus(struct weston_input_device *device);
466
467void
468weston_watch_process(struct weston_process *process);
469
470int
471weston_xserver_init(struct weston_compositor *compositor);
472void
473weston_xserver_destroy(struct weston_compositor *compositor);
474void
475weston_xserver_surface_activate(struct weston_surface *surface);
476void
477weston_xserver_set_selection(struct weston_input_device *device);
478
479struct weston_zoom;
480typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
481
482struct weston_zoom *
483weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
484 weston_zoom_done_func_t done, void *data);
485
486#endif