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