screenshooter: Grab pixel data directly before buffer swap
[profile/ivi/weston-ivi-shell.git] / src / compositor.h
1 /*
2  * Copyright © 2008-2011 Kristian Høgsberg
3  * Copyright © 2012 Collabora, Ltd.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of the copyright holders not be used in
10  * advertising or publicity pertaining to distribution of the software
11  * without specific, written prior permission.  The copyright holders make
12  * no representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
25 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
26
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
35 #include "matrix.h"
36 #include "../shared/config-parser.h"
37 #include "weston-egl-ext.h"
38
39
40 struct weston_transform {
41         struct weston_matrix matrix;
42         struct wl_list link;
43 };
44
45 struct weston_surface;
46 struct weston_input_device;
47 struct weston_output;
48
49 struct weston_mode {
50         uint32_t flags;
51         int32_t width, height;
52         uint32_t refresh;
53         struct wl_list link;
54 };
55
56 struct weston_border {
57         int32_t left, right, top, bottom;
58 };
59
60 struct weston_output_zoom {
61         int active;
62         float increment;
63         float level;
64         float magnification;
65         float trans_x, trans_y;
66 };
67
68 /* bit compatible with drm definitions. */
69 enum dpms_enum {
70         WESTON_DPMS_ON,
71         WESTON_DPMS_STANDBY,
72         WESTON_DPMS_SUSPEND,
73         WESTON_DPMS_OFF
74 };
75
76 struct weston_read_pixels {
77         void *data;
78         int x, y, width, height;
79         void (*done)(struct weston_read_pixels *read_pixels,
80                      struct weston_output *output);
81         struct wl_list link;
82 };
83
84 struct weston_output {
85         uint32_t id;
86
87         struct wl_list link;
88         struct wl_list resource_list;
89         struct wl_global *global;
90         struct weston_compositor *compositor;
91         struct weston_matrix matrix;
92         struct wl_list frame_callback_list;
93         int32_t x, y, mm_width, mm_height;
94         struct weston_border border;
95         pixman_region32_t region;
96         pixman_region32_t previous_damage;
97         uint32_t flags;
98         int repaint_needed;
99         int repaint_scheduled;
100         struct weston_output_zoom zoom;
101         int dirty;
102         struct wl_list read_pixels_list;
103
104         char *make, *model;
105         uint32_t subpixel;
106         
107         struct weston_mode *current;
108         struct weston_mode *origin;
109         struct wl_list mode_list;
110
111         void (*repaint)(struct weston_output *output,
112                         pixman_region32_t *damage);
113         void (*destroy)(struct weston_output *output);
114         void (*assign_planes)(struct weston_output *output);
115         int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
116
117         /* backlight values are on 0-255 range, where higher is brighter */
118         uint32_t backlight_current;
119         void (*set_backlight)(struct weston_output *output, uint32_t value);
120         void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
121 };
122
123 struct weston_input_device {
124         struct wl_input_device input_device;
125         struct weston_compositor *compositor;
126         struct weston_surface *sprite;
127         struct weston_surface *drag_surface;
128         struct wl_listener drag_surface_destroy_listener;
129         int32_t hotspot_x, hotspot_y;
130         struct wl_list link;
131         uint32_t modifier_state;
132         int hw_cursor;
133         struct wl_surface *saved_kbd_focus;
134         struct wl_listener saved_kbd_focus_listener;
135
136         uint32_t num_tp;
137         struct wl_surface *touch_focus;
138         struct wl_listener touch_focus_listener;
139         struct wl_resource *touch_focus_resource;
140         struct wl_listener touch_focus_resource_listener;
141
142         struct wl_listener new_drag_icon_listener;
143 };
144
145 struct weston_shader {
146         GLuint program;
147         GLuint vertex_shader, fragment_shader;
148         GLint proj_uniform;
149         GLint tex_uniform;
150         GLint alpha_uniform;
151         GLint brightness_uniform;
152         GLint saturation_uniform;
153         GLint color_uniform;
154         GLint texwidth_uniform;
155 };
156
157 struct weston_animation {
158         void (*frame)(struct weston_animation *animation,
159                       struct weston_output *output, uint32_t msecs);
160         struct wl_list link;
161 };
162
163 struct weston_spring {
164         double k;
165         double friction;
166         double current;
167         double target;
168         double previous;
169         uint32_t timestamp;
170 };
171
172 enum {
173         WESTON_COMPOSITOR_ACTIVE,
174         WESTON_COMPOSITOR_IDLE,         /* shell->unlock called on activity */
175         WESTON_COMPOSITOR_SLEEPING      /* no rendering, no frame events */
176 };
177
178 struct screenshooter;
179
180 struct weston_layer {
181         struct wl_list surface_list;
182         struct wl_list link;
183 };
184
185 struct weston_compositor {
186         struct wl_shm *shm;
187         struct wl_signal destroy_signal;
188
189         EGLDisplay display;
190         EGLContext context;
191         EGLConfig config;
192         GLuint fbo;
193         struct weston_shader texture_shader;
194         struct weston_shader solid_shader;
195         struct weston_shader *current_shader;
196         struct wl_display *wl_display;
197
198         struct wl_signal activate_signal;
199         struct wl_signal lock_signal;
200         struct wl_signal unlock_signal;
201
202         struct wl_event_loop *input_loop;
203         struct wl_event_source *input_loop_source;
204
205         /* There can be more than one, but not right now... */
206         struct wl_input_device *input_device;
207
208         struct weston_layer fade_layer;
209         struct weston_layer cursor_layer;
210
211         struct wl_list output_list;
212         struct wl_list input_device_list;
213         struct wl_list layer_list;
214         struct wl_list surface_list;
215         struct wl_list binding_list;
216         struct wl_list animation_list;
217         struct {
218                 struct weston_spring spring;
219                 struct weston_animation animation;
220                 struct weston_surface *surface;
221         } fade;
222
223         uint32_t state;
224         struct wl_event_source *idle_source;
225         uint32_t idle_inhibit;
226         int option_idle_time;           /* default timeout, s */
227         int idle_time;                  /* effective timeout, s */
228
229         /* Repaint state. */
230         struct wl_array vertices, indices;
231         pixman_region32_t damage;
232
233         uint32_t focus;
234
235         PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
236                 image_target_renderbuffer_storage;
237         PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
238         PFNEGLCREATEIMAGEKHRPROC create_image;
239         PFNEGLDESTROYIMAGEKHRPROC destroy_image;
240
241         int has_unpack_subimage;
242         GLenum read_format;
243
244         PFNEGLBINDWAYLANDDISPLAYWL bind_display;
245         PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
246         int has_bind_display;
247
248         void (*destroy)(struct weston_compositor *ec);
249         int (*authenticate)(struct weston_compositor *c, uint32_t id);
250
251         void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
252
253         struct screenshooter *screenshooter;
254         int launcher_sock;
255
256         uint32_t output_id_pool;
257 };
258
259 #define MODIFIER_CTRL   (1 << 8)
260 #define MODIFIER_ALT    (1 << 9)
261 #define MODIFIER_SUPER  (1 << 10)
262
263 enum weston_output_flags {
264         WL_OUTPUT_FLIPPED = 0x01
265 };
266
267 struct weston_region {
268         struct wl_resource resource;
269         pixman_region32_t region;
270 };
271
272 /* Using weston_surface transformations
273  *
274  * To add a transformation to a surface, create a struct weston_transform, and
275  * add it to the list surface->geometry.transformation_list. Whenever you
276  * change the list, anything under surface->geometry, or anything in the
277  * weston_transforms linked into the list, you must set
278  * surface->geometry.dirty = 1.
279  *
280  * The order in the list defines the order of transformations. Let the list
281  * contain the transformation matrices M1, ..., Mn as head to tail. The
282  * transformation is applied to surface-local coordinate vector p as
283  *    P = Mn * ... * M2 * M1 * p
284  * to produce the global coordinate vector P. The total transform
285  *    Mn * ... * M2 * M1
286  * is cached in surface->transform.matrix, and the inverse of it in
287  * surface->transform.inverse.
288  *
289  * The list always contains surface->transform.position transformation, which
290  * is the translation by surface->geometry.x and y.
291  *
292  * If you want to apply a transformation in local coordinates, add your
293  * weston_transform to the head of the list. If you want to apply a
294  * transformation in global coordinates, add it to the tail of the list.
295  */
296
297 struct weston_surface {
298         struct wl_surface surface;
299         struct weston_compositor *compositor;
300         GLuint texture;
301         pixman_region32_t clip;
302         pixman_region32_t damage;
303         pixman_region32_t opaque;
304         pixman_region32_t input;
305         int32_t pitch;
306         struct wl_list link;
307         struct wl_list layer_link;
308         struct weston_shader *shader;
309         GLfloat color[4];
310         uint32_t alpha;
311         uint32_t brightness;
312         uint32_t saturation;
313
314         /* Surface geometry state, mutable.
315          * If you change anything, set dirty = 1.
316          * That includes the transformations referenced from the list.
317          */
318         struct {
319                 GLfloat x, y; /* surface translation on display */
320                 int32_t width, height;
321
322                 /* struct weston_transform */
323                 struct wl_list transformation_list;
324
325                 int dirty;
326         } geometry;
327
328         /* State derived from geometry state, read-only.
329          * This is updated by weston_surface_update_transform().
330          */
331         struct {
332                 pixman_region32_t boundingbox;
333                 pixman_region32_t opaque;
334
335                 /* matrix and inverse are used only if enabled = 1.
336                  * If enabled = 0, use x, y, width, height directly.
337                  */
338                 int enabled;
339                 struct weston_matrix matrix;
340                 struct weston_matrix inverse;
341
342                 struct weston_transform position; /* matrix from x, y */
343         } transform;
344
345         /*
346          * Which output to vsync this surface to.
347          * Used to determine, whether to send or queue frame events.
348          * Must be NULL, if 'link' is not in weston_compositor::surface_list.
349          */
350         struct weston_output *output;
351
352         /*
353          * A more complete representation of all outputs this surface is
354          * displayed on.
355          */
356         uint32_t output_mask;
357
358         struct wl_list frame_callback_list;
359
360         EGLImageKHR image;
361
362         struct wl_buffer *buffer;
363         struct wl_listener buffer_destroy_listener;
364
365         /*
366          * If non-NULL, this function will be called on surface::attach after
367          * a new buffer has been set up for this surface. The integer params
368          * are the sx and sy paramerters supplied to surface::attach .
369          */
370         void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy);
371         void *private;
372 };
373
374 void
375 weston_surface_update_transform(struct weston_surface *surface);
376
377 void
378 weston_surface_to_global(struct weston_surface *surface,
379                          int32_t sx, int32_t sy, int32_t *x, int32_t *y);
380 void
381 weston_surface_to_global_float(struct weston_surface *surface,
382                                int32_t sx, int32_t sy, GLfloat *x, GLfloat *y);
383
384 void
385 weston_surface_from_global(struct weston_surface *surface,
386                            int32_t x, int32_t y, int32_t *sx, int32_t *sy);
387
388 void
389 weston_spring_init(struct weston_spring *spring,
390                    double k, double current, double target);
391 void
392 weston_spring_update(struct weston_spring *spring, uint32_t msec);
393 int
394 weston_spring_done(struct weston_spring *spring);
395
396 void
397 weston_surface_activate(struct weston_surface *surface,
398                         struct weston_input_device *device);
399 void
400 weston_surface_draw(struct weston_surface *es,
401                     struct weston_output *output, pixman_region32_t *damage);
402
403 void
404 notify_motion(struct wl_input_device *device,
405               uint32_t time, int x, int y);
406 void
407 notify_button(struct wl_input_device *device,
408               uint32_t time, int32_t button, int32_t state);
409 void
410 notify_axis(struct wl_input_device *device,
411               uint32_t time, uint32_t axis, int32_t value);
412 void
413 notify_key(struct wl_input_device *device,
414            uint32_t time, uint32_t key, uint32_t state);
415
416 void
417 notify_pointer_focus(struct wl_input_device *device,
418                      struct weston_output *output,
419                      int32_t x, int32_t y);
420
421 void
422 notify_keyboard_focus(struct wl_input_device *device, struct wl_array *keys);
423
424 void
425 notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
426              int x, int y, int touch_type);
427
428 void
429 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
430
431 void
432 weston_output_finish_frame(struct weston_output *output, int msecs);
433 void
434 weston_output_damage(struct weston_output *output);
435 void
436 weston_output_do_read_pixels(struct weston_output *output);
437 void
438 weston_compositor_repick(struct weston_compositor *compositor);
439 void
440 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
441 void
442 weston_compositor_fade(struct weston_compositor *compositor, float tint);
443 void
444 weston_compositor_damage_all(struct weston_compositor *compositor);
445 void
446 weston_compositor_unlock(struct weston_compositor *compositor);
447 void
448 weston_compositor_wake(struct weston_compositor *compositor);
449 void
450 weston_compositor_activity(struct weston_compositor *compositor);
451 void
452 weston_compositor_update_drag_surfaces(struct weston_compositor *compositor);
453
454
455 struct weston_binding;
456 typedef void (*weston_binding_handler_t)(struct wl_input_device *device,
457                                          uint32_t time, uint32_t key,
458                                          uint32_t button,
459                                          uint32_t axis,
460                                          int32_t state, void *data);
461 struct weston_binding *
462 weston_compositor_add_binding(struct weston_compositor *compositor,
463                               uint32_t key, uint32_t button, uint32_t axis, uint32_t modifier,
464                               weston_binding_handler_t binding, void *data);
465 void
466 weston_binding_destroy(struct weston_binding *binding);
467
468 void
469 weston_binding_list_destroy_all(struct wl_list *list);
470
471 void
472 weston_compositor_run_binding(struct weston_compositor *compositor,
473                               struct weston_input_device *device,
474                               uint32_t time,
475                               uint32_t key, uint32_t button, uint32_t axis, int32_t state);
476 int
477 weston_environment_get_fd(const char *env);
478
479 struct wl_list *
480 weston_compositor_top(struct weston_compositor *compositor);
481
482 struct weston_surface *
483 weston_surface_create(struct weston_compositor *compositor);
484
485 void
486 weston_surface_configure(struct weston_surface *surface,
487                          GLfloat x, GLfloat y, int width, int height);
488
489 void
490 weston_surface_restack(struct weston_surface *surface, struct wl_list *below);
491
492 void
493 weston_surface_set_position(struct weston_surface *surface,
494                             GLfloat x, GLfloat y);
495
496 int
497 weston_surface_is_mapped(struct weston_surface *surface);
498
499 void
500 weston_surface_assign_output(struct weston_surface *surface);
501
502 void
503 weston_surface_damage(struct weston_surface *surface);
504
505 void
506 weston_surface_damage_below(struct weston_surface *surface);
507
508 void
509 weston_buffer_post_release(struct wl_buffer *buffer);
510
511 uint32_t
512 weston_compositor_get_time(void);
513
514 int
515 weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
516 void
517 weston_compositor_shutdown(struct weston_compositor *ec);
518 void
519 weston_output_update_zoom(struct weston_output *output, int x, int y);
520 void
521 weston_output_update_matrix(struct weston_output *output);
522 void
523 weston_output_move(struct weston_output *output, int x, int y);
524 void
525 weston_output_init(struct weston_output *output, struct weston_compositor *c,
526                    int x, int y, int width, int height, uint32_t flags);
527 void
528 weston_output_destroy(struct weston_output *output);
529
530 void
531 weston_input_device_init(struct weston_input_device *device,
532                          struct weston_compositor *ec);
533
534 void
535 weston_input_device_release(struct weston_input_device *device);
536
537 enum {
538         TTY_ENTER_VT,
539         TTY_LEAVE_VT
540 };
541
542 typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
543
544 struct tty *
545 tty_create(struct weston_compositor *compositor,
546            tty_vt_func_t vt_func, int tty_nr);
547
548 void
549 tty_destroy(struct tty *tty);
550
551 int
552 tty_activate_vt(struct tty *tty, int vt);
553
554 void
555 screenshooter_create(struct weston_compositor *ec);
556
557 struct weston_process;
558 typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
559                                             int status);
560
561 struct weston_process {
562         pid_t pid;
563         weston_process_cleanup_func_t cleanup;
564         struct wl_list link;
565 };
566
567 struct wl_client *
568 weston_client_launch(struct weston_compositor *compositor,
569                      struct weston_process *proc,
570                      const char *path,
571                      weston_process_cleanup_func_t cleanup);
572
573 void
574 weston_watch_process(struct weston_process *process);
575
576 int
577 weston_xserver_init(struct weston_compositor *compositor);
578
579 struct weston_zoom;
580 typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
581
582 struct weston_zoom *
583 weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
584                 weston_zoom_done_func_t done, void *data);
585
586 void
587 weston_surface_set_color(struct weston_surface *surface,
588                          GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
589
590 void
591 weston_surface_destroy(struct weston_surface *surface);
592
593 struct weston_compositor *
594 backend_init(struct wl_display *display, int argc, char *argv[]);
595
596 int
597 weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode);
598
599 #endif