compositor: quick fix for sub-surface mapping
[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 #ifdef  __cplusplus
28 extern "C" {
29 #endif
30
31 #include <pixman.h>
32 #include <xkbcommon/xkbcommon.h>
33
34 #define WL_HIDE_DEPRECATED
35 #include <wayland-server.h>
36
37 #include "version.h"
38 #include "matrix.h"
39 #include "config-parser.h"
40 #include "zalloc.h"
41
42 #ifndef MIN
43 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
44 #endif
45
46 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
47
48 #define container_of(ptr, type, member) ({                              \
49         const __typeof__( ((type *)0)->member ) *__mptr = (ptr);        \
50         (type *)( (char *)__mptr - offsetof(type,member) );})
51
52 struct weston_transform {
53         struct weston_matrix matrix;
54         struct wl_list link;
55 };
56
57 struct weston_surface;
58 struct weston_buffer;
59 struct shell_surface;
60 struct weston_seat;
61 struct weston_output;
62 struct input_method;
63
64 enum weston_keyboard_modifier {
65         MODIFIER_CTRL = (1 << 0),
66         MODIFIER_ALT = (1 << 1),
67         MODIFIER_SUPER = (1 << 2),
68         MODIFIER_SHIFT = (1 << 3),
69 };
70
71 enum weston_led {
72         LED_NUM_LOCK = (1 << 0),
73         LED_CAPS_LOCK = (1 << 1),
74         LED_SCROLL_LOCK = (1 << 2),
75 };
76
77 struct weston_mode {
78         uint32_t flags;
79         int32_t width, height;
80         uint32_t refresh;
81         struct wl_list link;
82 };
83
84 struct weston_shell_client {
85         void (*send_configure)(struct weston_surface *surface, int32_t width, int32_t height);
86 };
87
88 struct weston_shell_interface {
89         void *shell;                    /* either desktop or tablet */
90
91         struct shell_surface *(*create_shell_surface)(void *shell,
92                                                       struct weston_surface *surface,
93                                                       const struct weston_shell_client *client);
94         struct weston_view *(*get_primary_view)(void *shell,
95                                                 struct shell_surface *shsurf);
96
97         void (*set_toplevel)(struct shell_surface *shsurf);
98
99         void (*set_transient)(struct shell_surface *shsurf,
100                               struct weston_surface *parent,
101                               int x, int y, uint32_t flags);
102         void (*set_fullscreen)(struct shell_surface *shsurf,
103                                uint32_t method,
104                                uint32_t framerate,
105                                struct weston_output *output);
106         void (*set_xwayland)(struct shell_surface *shsurf,
107                                int x, int y, uint32_t flags);
108         int (*move)(struct shell_surface *shsurf, struct weston_seat *ws);
109         int (*resize)(struct shell_surface *shsurf,
110                       struct weston_seat *ws, uint32_t edges);
111         void (*set_title)(struct shell_surface *shsurf,
112                           const char *title);
113         void (*set_window_geometry)(struct shell_surface *shsurf,
114                                     int32_t x, int32_t y,
115                                     int32_t width, int32_t height);
116 };
117
118 struct weston_animation {
119         void (*frame)(struct weston_animation *animation,
120                       struct weston_output *output, uint32_t msecs);
121         int frame_counter;
122         struct wl_list link;
123 };
124
125 enum {
126         WESTON_SPRING_OVERSHOOT,
127         WESTON_SPRING_CLAMP,
128         WESTON_SPRING_BOUNCE
129 };
130
131 struct weston_spring {
132         double k;
133         double friction;
134         double current;
135         double target;
136         double previous;
137         double min, max;
138         uint32_t timestamp;
139         uint32_t clip;
140 };
141
142 struct weston_fixed_point {
143         wl_fixed_t x, y;
144 };
145
146 struct weston_output_zoom {
147         int active;
148         float increment;
149         float level;
150         float max_level;
151         float trans_x, trans_y;
152         struct weston_animation animation_z;
153         struct weston_spring spring_z;
154         struct weston_animation animation_xy;
155         struct weston_spring spring_xy;
156         struct weston_fixed_point from;
157         struct weston_fixed_point to;
158         struct weston_fixed_point current;
159         struct wl_listener motion_listener;
160 };
161
162 /* bit compatible with drm definitions. */
163 enum dpms_enum {
164         WESTON_DPMS_ON,
165         WESTON_DPMS_STANDBY,
166         WESTON_DPMS_SUSPEND,
167         WESTON_DPMS_OFF
168 };
169
170 enum weston_mode_switch_op {
171         WESTON_MODE_SWITCH_SET_NATIVE,
172         WESTON_MODE_SWITCH_SET_TEMPORARY,
173         WESTON_MODE_SWITCH_RESTORE_NATIVE
174 };
175
176 struct weston_output {
177         uint32_t id;
178         char *name;
179
180         void *renderer_state;
181
182         struct wl_list link;
183         struct wl_list resource_list;
184         struct wl_global *global;
185         struct weston_compositor *compositor;
186         struct weston_matrix matrix;
187         struct wl_list animation_list;
188         int32_t x, y, width, height;
189         int32_t mm_width, mm_height;
190         pixman_region32_t region;
191         pixman_region32_t previous_damage;
192         int repaint_needed;
193         int repaint_scheduled;
194         struct weston_output_zoom zoom;
195         int dirty;
196         struct wl_signal frame_signal;
197         struct wl_signal destroy_signal;
198         struct wl_signal move_signal;
199         int move_x, move_y;
200         uint32_t frame_time;
201         int disable_planes;
202         int destroying;
203
204         char *make, *model, *serial_number;
205         uint32_t subpixel;
206         uint32_t transform;
207         int32_t native_scale;
208         int32_t current_scale;
209         int32_t original_scale;
210
211         struct weston_mode *native_mode;
212         struct weston_mode *current_mode;
213         struct weston_mode *original_mode;
214         struct wl_list mode_list;
215
216         void (*start_repaint_loop)(struct weston_output *output);
217         int (*repaint)(struct weston_output *output,
218                         pixman_region32_t *damage);
219         void (*destroy)(struct weston_output *output);
220         void (*assign_planes)(struct weston_output *output);
221         int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
222
223         /* backlight values are on 0-255 range, where higher is brighter */
224         int32_t backlight_current;
225         void (*set_backlight)(struct weston_output *output, uint32_t value);
226         void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
227
228         int connection_internal;
229         uint16_t gamma_size;
230         void (*set_gamma)(struct weston_output *output,
231                           uint16_t size,
232                           uint16_t *r,
233                           uint16_t *g,
234                           uint16_t *b);
235 };
236
237 struct weston_pointer_grab;
238 struct weston_pointer_grab_interface {
239         void (*focus)(struct weston_pointer_grab *grab);
240         void (*motion)(struct weston_pointer_grab *grab, uint32_t time,
241                        wl_fixed_t x, wl_fixed_t y);
242         void (*button)(struct weston_pointer_grab *grab,
243                        uint32_t time, uint32_t button, uint32_t state);
244         void (*cancel)(struct weston_pointer_grab *grab);
245 };
246
247 struct weston_pointer_grab {
248         const struct weston_pointer_grab_interface *interface;
249         struct weston_pointer *pointer;
250 };
251
252 struct weston_keyboard_grab;
253 struct weston_keyboard_grab_interface {
254         void (*key)(struct weston_keyboard_grab *grab, uint32_t time,
255                     uint32_t key, uint32_t state);
256         void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial,
257                           uint32_t mods_depressed, uint32_t mods_latched,
258                           uint32_t mods_locked, uint32_t group);
259         void (*cancel)(struct weston_keyboard_grab *grab);
260 };
261
262 struct weston_keyboard_grab {
263         const struct weston_keyboard_grab_interface *interface;
264         struct weston_keyboard *keyboard;
265 };
266
267 struct weston_touch_grab;
268 struct weston_touch_grab_interface {
269         void (*down)(struct weston_touch_grab *grab,
270                         uint32_t time,
271                         int touch_id,
272                         wl_fixed_t sx,
273                         wl_fixed_t sy);
274         void (*up)(struct weston_touch_grab *grab,
275                         uint32_t time,
276                         int touch_id);
277         void (*motion)(struct weston_touch_grab *grab,
278                         uint32_t time,
279                         int touch_id,
280                         wl_fixed_t sx,
281                         wl_fixed_t sy);
282         void (*frame)(struct weston_touch_grab *grab);
283         void (*cancel)(struct weston_touch_grab *grab);
284 };
285
286 struct weston_touch_grab {
287         const struct weston_touch_grab_interface *interface;
288         struct weston_touch *touch;
289 };
290
291 struct weston_data_offer {
292         struct wl_resource *resource;
293         struct weston_data_source *source;
294         struct wl_listener source_destroy_listener;
295 };
296
297 struct weston_data_source {
298         struct wl_resource *resource;
299         struct wl_signal destroy_signal;
300         struct wl_array mime_types;
301
302         void (*accept)(struct weston_data_source *source,
303                        uint32_t serial, const char *mime_type);
304         void (*send)(struct weston_data_source *source,
305                      const char *mime_type, int32_t fd);
306         void (*cancel)(struct weston_data_source *source);
307 };
308
309 struct weston_pointer {
310         struct weston_seat *seat;
311
312         struct wl_list resource_list;
313         struct wl_list focus_resource_list;
314         struct weston_view *focus;
315         uint32_t focus_serial;
316         struct wl_listener focus_view_listener;
317         struct wl_listener focus_resource_listener;
318         struct wl_signal focus_signal;
319         struct wl_signal motion_signal;
320
321         struct weston_view *sprite;
322         struct wl_listener sprite_destroy_listener;
323         int32_t hotspot_x, hotspot_y;
324
325         struct weston_pointer_grab *grab;
326         struct weston_pointer_grab default_grab;
327         wl_fixed_t grab_x, grab_y;
328         uint32_t grab_button;
329         uint32_t grab_serial;
330         uint32_t grab_time;
331
332         wl_fixed_t x, y;
333         wl_fixed_t sx, sy;
334         uint32_t button_count;
335
336         struct wl_listener output_destroy_listener;
337 };
338
339
340 struct weston_touch {
341         struct weston_seat *seat;
342
343         struct wl_list resource_list;
344         struct wl_list focus_resource_list;
345         struct weston_view *focus;
346         struct wl_listener focus_view_listener;
347         struct wl_listener focus_resource_listener;
348         uint32_t focus_serial;
349         struct wl_signal focus_signal;
350
351         uint32_t num_tp;
352
353         struct weston_touch_grab *grab;
354         struct weston_touch_grab default_grab;
355         int grab_touch_id;
356         wl_fixed_t grab_x, grab_y;
357         uint32_t grab_serial;
358         uint32_t grab_time;
359 };
360
361 struct weston_pointer *
362 weston_pointer_create(struct weston_seat *seat);
363 void
364 weston_pointer_destroy(struct weston_pointer *pointer);
365 void
366 weston_pointer_set_focus(struct weston_pointer *pointer,
367                          struct weston_view *view,
368                          wl_fixed_t sx, wl_fixed_t sy);
369 void
370 weston_pointer_start_grab(struct weston_pointer *pointer,
371                           struct weston_pointer_grab *grab);
372 void
373 weston_pointer_end_grab(struct weston_pointer *pointer);
374 void
375 weston_pointer_clamp(struct weston_pointer *pointer,
376                             wl_fixed_t *fx, wl_fixed_t *fy);
377 void
378 weston_pointer_move(struct weston_pointer *pointer,
379                     wl_fixed_t x, wl_fixed_t y);
380 void
381 weston_pointer_set_default_grab(struct weston_pointer *pointer,
382                 const struct weston_pointer_grab_interface *interface);
383
384 struct weston_keyboard *
385 weston_keyboard_create(void);
386 void
387 weston_keyboard_destroy(struct weston_keyboard *keyboard);
388 void
389 weston_keyboard_set_focus(struct weston_keyboard *keyboard,
390                           struct weston_surface *surface);
391 void
392 weston_keyboard_start_grab(struct weston_keyboard *device,
393                            struct weston_keyboard_grab *grab);
394 void
395 weston_keyboard_end_grab(struct weston_keyboard *keyboard);
396
397 struct weston_touch *
398 weston_touch_create(void);
399 void
400 weston_touch_destroy(struct weston_touch *touch);
401 void
402 weston_touch_set_focus(struct weston_seat *seat,
403                        struct weston_view *view);
404 void
405 weston_touch_start_grab(struct weston_touch *device,
406                         struct weston_touch_grab *grab);
407 void
408 weston_touch_end_grab(struct weston_touch *touch);
409
410 void
411 wl_data_device_set_keyboard_focus(struct weston_seat *seat);
412
413 int
414 wl_data_device_manager_init(struct wl_display *display);
415
416
417 void
418 weston_seat_set_selection(struct weston_seat *seat,
419                           struct weston_data_source *source, uint32_t serial);
420 int
421 weston_pointer_start_drag(struct weston_pointer *pointer,
422                        struct weston_data_source *source,
423                        struct weston_surface *icon,
424                        struct wl_client *client);
425 int
426 weston_touch_start_drag(struct weston_touch *touch,
427                         struct weston_data_source *source,
428                         struct weston_surface *icon,
429                         struct wl_client *client);
430
431 struct weston_xkb_info {
432         struct xkb_keymap *keymap;
433         int keymap_fd;
434         size_t keymap_size;
435         char *keymap_area;
436         int32_t ref_count;
437         xkb_mod_index_t shift_mod;
438         xkb_mod_index_t caps_mod;
439         xkb_mod_index_t ctrl_mod;
440         xkb_mod_index_t alt_mod;
441         xkb_mod_index_t mod2_mod;
442         xkb_mod_index_t mod3_mod;
443         xkb_mod_index_t super_mod;
444         xkb_mod_index_t mod5_mod;
445         xkb_led_index_t num_led;
446         xkb_led_index_t caps_led;
447         xkb_led_index_t scroll_led;
448 };
449
450 struct weston_keyboard {
451         struct weston_seat *seat;
452
453         struct wl_list resource_list;
454         struct wl_list focus_resource_list;
455         struct weston_surface *focus;
456         struct wl_listener focus_resource_listener;
457         uint32_t focus_serial;
458         struct wl_signal focus_signal;
459
460         struct weston_keyboard_grab *grab;
461         struct weston_keyboard_grab default_grab;
462         uint32_t grab_key;
463         uint32_t grab_serial;
464         uint32_t grab_time;
465
466         struct wl_array keys;
467
468         struct {
469                 uint32_t mods_depressed;
470                 uint32_t mods_latched;
471                 uint32_t mods_locked;
472                 uint32_t group;
473         } modifiers;
474
475         struct weston_keyboard_grab input_method_grab;
476         struct wl_resource *input_method_resource;
477
478         struct weston_xkb_info *xkb_info;
479         struct {
480                 struct xkb_state *state;
481                 enum weston_led leds;
482         } xkb_state;
483         struct xkb_keymap *pending_keymap;
484 };
485
486 struct weston_seat {
487         struct wl_list base_resource_list;
488
489         struct wl_global *global;
490         struct weston_pointer *pointer;
491         struct weston_keyboard *keyboard;
492         struct weston_touch *touch;
493         int pointer_device_count;
494         int keyboard_device_count;
495         int touch_device_count;
496
497         struct weston_output *output; /* constraint */
498
499         struct wl_signal destroy_signal;
500         struct wl_signal updated_caps_signal;
501
502         struct weston_compositor *compositor;
503         struct wl_list link;
504         enum weston_keyboard_modifier modifier_state;
505         struct weston_surface *saved_kbd_focus;
506         struct wl_listener saved_kbd_focus_listener;
507         struct wl_list drag_resource_list;
508
509         uint32_t selection_serial;
510         struct weston_data_source *selection_data_source;
511         struct wl_listener selection_data_source_listener;
512         struct wl_signal selection_signal;
513
514         void (*led_update)(struct weston_seat *ws, enum weston_led leds);
515
516         uint32_t slot_map;
517         struct input_method *input_method;
518         char *seat_name;
519 };
520
521 enum {
522         WESTON_COMPOSITOR_ACTIVE,
523         WESTON_COMPOSITOR_IDLE,         /* shell->unlock called on activity */
524         WESTON_COMPOSITOR_OFFSCREEN,    /* no rendering, no frame events */
525         WESTON_COMPOSITOR_SLEEPING      /* same as offscreen, but also set dmps
526                                          * to off */
527 };
528
529 struct weston_layer_entry {
530         struct wl_list link;
531         struct weston_layer *layer;
532 };
533
534 struct weston_layer {
535         struct weston_layer_entry view_list;
536         struct wl_list link;
537         pixman_box32_t mask;
538 };
539
540 struct weston_plane {
541         struct weston_compositor *compositor;
542         pixman_region32_t damage;
543         pixman_region32_t clip;
544         int32_t x, y;
545         struct wl_list link;
546 };
547
548 struct weston_renderer {
549         int (*read_pixels)(struct weston_output *output,
550                                pixman_format_code_t format, void *pixels,
551                                uint32_t x, uint32_t y,
552                                uint32_t width, uint32_t height);
553         void (*repaint_output)(struct weston_output *output,
554                                pixman_region32_t *output_damage);
555         void (*flush_damage)(struct weston_surface *surface);
556         void (*attach)(struct weston_surface *es, struct weston_buffer *buffer);
557         void (*surface_set_color)(struct weston_surface *surface,
558                                float red, float green,
559                                float blue, float alpha);
560         void (*destroy)(struct weston_compositor *ec);
561 };
562
563 enum weston_capability {
564         /* backend/renderer supports arbitrary rotation */
565         WESTON_CAP_ROTATION_ANY                 = 0x0001,
566
567         /* screencaptures need to be y-flipped */
568         WESTON_CAP_CAPTURE_YFLIP                = 0x0002,
569
570         /* backend/renderer has a seperate cursor plane */
571         WESTON_CAP_CURSOR_PLANE                 = 0x0004,
572
573         /* backend supports setting arbitrary resolutions */
574         WESTON_CAP_ARBITRARY_MODES              = 0x0008,
575 };
576
577 struct weston_compositor {
578         struct wl_signal destroy_signal;
579
580         struct wl_display *wl_display;
581         struct weston_shell_interface shell_interface;
582         struct weston_config *config;
583
584         /* surface signals */
585         struct wl_signal create_surface_signal;
586         struct wl_signal activate_signal;
587         struct wl_signal transform_signal;
588
589         struct wl_signal kill_signal;
590         struct wl_signal idle_signal;
591         struct wl_signal wake_signal;
592
593         struct wl_signal show_input_panel_signal;
594         struct wl_signal hide_input_panel_signal;
595         struct wl_signal update_input_panel_signal;
596
597         struct wl_signal seat_created_signal;
598         struct wl_signal output_created_signal;
599         struct wl_signal output_destroyed_signal;
600         struct wl_signal output_moved_signal;
601
602         struct wl_event_loop *input_loop;
603         struct wl_event_source *input_loop_source;
604
605         struct wl_signal session_signal;
606         int session_active;
607
608         struct weston_layer fade_layer;
609         struct weston_layer cursor_layer;
610
611         struct wl_list output_list;
612         struct wl_list seat_list;
613         struct wl_list layer_list;
614         struct wl_list view_list;
615         struct wl_list plane_list;
616         struct wl_list key_binding_list;
617         struct wl_list modifier_binding_list;
618         struct wl_list button_binding_list;
619         struct wl_list touch_binding_list;
620         struct wl_list axis_binding_list;
621         struct wl_list debug_binding_list;
622
623         uint32_t state;
624         struct wl_event_source *idle_source;
625         uint32_t idle_inhibit;
626         int idle_time;                  /* timeout, s */
627
628         const struct weston_pointer_grab_interface *default_pointer_grab;
629
630         /* Repaint state. */
631         struct weston_plane primary_plane;
632         uint32_t capabilities; /* combination of enum weston_capability */
633
634         struct weston_renderer *renderer;
635
636         pixman_format_code_t read_format;
637
638         void (*destroy)(struct weston_compositor *ec);
639         void (*restore)(struct weston_compositor *ec);
640         int (*authenticate)(struct weston_compositor *c, uint32_t id);
641
642         struct weston_launcher *launcher;
643
644         uint32_t output_id_pool;
645
646         struct xkb_rule_names xkb_names;
647         struct xkb_context *xkb_context;
648         struct weston_xkb_info *xkb_info;
649
650         /* Raw keyboard processing (no libxkbcommon initialization or handling) */
651         int use_xkbcommon;
652 };
653
654 struct weston_buffer {
655         struct wl_resource *resource;
656         struct wl_signal destroy_signal;
657         struct wl_listener destroy_listener;
658
659         union {
660                 struct wl_shm_buffer *shm_buffer;
661                 void *legacy_buffer;
662         };
663         int32_t width, height;
664         uint32_t busy_count;
665         int y_inverted;
666 };
667
668 struct weston_buffer_reference {
669         struct weston_buffer *buffer;
670         struct wl_listener destroy_listener;
671 };
672
673 struct weston_buffer_viewport {
674         struct {
675                 /* wl_surface.set_buffer_transform */
676                 uint32_t transform;
677
678                 /* wl_surface.set_scaling_factor */
679                 int32_t scale;
680
681                 /*
682                  * If src_width != wl_fixed_from_int(-1),
683                  * then and only then src_* are used.
684                  */
685                 wl_fixed_t src_x, src_y;
686                 wl_fixed_t src_width, src_height;
687         } buffer;
688
689         struct {
690                 /*
691                  * If width == -1, the size is inferred from the buffer.
692                  */
693                 int32_t width, height;
694         } surface;
695
696         int changed;
697 };
698
699 struct weston_region {
700         struct wl_resource *resource;
701         pixman_region32_t region;
702 };
703
704 /* Using weston_view transformations
705  *
706  * To add a transformation to a view, create a struct weston_transform, and
707  * add it to the list view->geometry.transformation_list. Whenever you
708  * change the list, anything under view->geometry, or anything in the
709  * weston_transforms linked into the list, you must call
710  * weston_view_geometry_dirty().
711  *
712  * The order in the list defines the order of transformations. Let the list
713  * contain the transformation matrices M1, ..., Mn as head to tail. The
714  * transformation is applied to view-local coordinate vector p as
715  *    P = Mn * ... * M2 * M1 * p
716  * to produce the global coordinate vector P. The total transform
717  *    Mn * ... * M2 * M1
718  * is cached in view->transform.matrix, and the inverse of it in
719  * view->transform.inverse.
720  *
721  * The list always contains view->transform.position transformation, which
722  * is the translation by view->geometry.x and y.
723  *
724  * If you want to apply a transformation in local coordinates, add your
725  * weston_transform to the head of the list. If you want to apply a
726  * transformation in global coordinates, add it to the tail of the list.
727  *
728  * If view->geometry.parent is set, the total transformation of this
729  * view will be the parent's total transformation and this transformation
730  * combined:
731  *    Mparent * Mn * ... * M2 * M1
732  */
733
734 struct weston_view {
735         struct weston_surface *surface;
736         struct wl_list surface_link;
737         struct wl_signal destroy_signal;
738
739         struct wl_list link;
740         struct weston_layer_entry layer_link;
741         struct weston_plane *plane;
742         struct weston_view *parent_view;
743
744         pixman_region32_t clip;
745         float alpha;                     /* part of geometry, see below */
746
747         void *renderer_state;
748
749         /* Surface geometry state, mutable.
750          * If you change anything, call weston_surface_geometry_dirty().
751          * That includes the transformations referenced from the list.
752          */
753         struct {
754                 float x, y; /* surface translation on display */
755
756                 /* struct weston_transform */
757                 struct wl_list transformation_list;
758
759                 /* managed by weston_surface_set_transform_parent() */
760                 struct weston_view *parent;
761                 struct wl_listener parent_destroy_listener;
762                 struct wl_list child_list; /* geometry.parent_link */
763                 struct wl_list parent_link;
764         } geometry;
765
766         /* State derived from geometry state, read-only.
767          * This is updated by weston_view_update_transform().
768          */
769         struct {
770                 int dirty;
771
772                 pixman_region32_t boundingbox;
773                 pixman_region32_t opaque;
774                 pixman_region32_t masked_boundingbox;
775                 pixman_region32_t masked_opaque;
776
777                 /* matrix and inverse are used only if enabled = 1.
778                  * If enabled = 0, use x, y, width, height directly.
779                  */
780                 int enabled;
781                 struct weston_matrix matrix;
782                 struct weston_matrix inverse;
783
784                 struct weston_transform position; /* matrix from x, y */
785         } transform;
786
787         /*
788          * Which output to vsync this surface to.
789          * Used to determine, whether to send or queue frame events.
790          * Must be NULL, if 'link' is not in weston_compositor::surface_list.
791          */
792         struct weston_output *output;
793
794         /*
795          * A more complete representation of all outputs this surface is
796          * displayed on.
797          */
798         uint32_t output_mask;
799 };
800
801 struct weston_surface_state {
802         /* wl_surface.attach */
803         int newly_attached;
804         struct weston_buffer *buffer;
805         struct wl_listener buffer_destroy_listener;
806         int32_t sx;
807         int32_t sy;
808
809         /* wl_surface.damage */
810         pixman_region32_t damage;
811
812         /* wl_surface.set_opaque_region */
813         pixman_region32_t opaque;
814
815         /* wl_surface.set_input_region */
816         pixman_region32_t input;
817
818         /* wl_surface.frame */
819         struct wl_list frame_callback_list;
820
821         /* wl_surface.set_buffer_transform */
822         /* wl_surface.set_scaling_factor */
823         /* wl_viewport.set */
824         struct weston_buffer_viewport buffer_viewport;
825 };
826
827 struct weston_surface {
828         struct wl_resource *resource;
829         struct wl_signal destroy_signal;
830         struct weston_compositor *compositor;
831         pixman_region32_t damage;
832         pixman_region32_t opaque;        /* part of geometry, see below */
833         pixman_region32_t input;
834         int32_t width, height;
835         int32_t ref_count;
836
837         /* Not for long-term storage.  This exists for book-keeping while
838          * iterating over surfaces and views
839          */
840         int32_t touched;
841
842         void *renderer_state;
843
844         struct wl_list views;
845
846         /*
847          * Which output to vsync this surface to.
848          * Used to determine, whether to send or queue frame events.
849          * Must be NULL, if 'link' is not in weston_compositor::surface_list.
850          */
851         struct weston_output *output;
852
853         /*
854          * A more complete representation of all outputs this surface is
855          * displayed on.
856          */
857         uint32_t output_mask;
858
859         struct wl_list frame_callback_list;
860
861         struct weston_buffer_reference buffer_ref;
862         struct weston_buffer_viewport buffer_viewport;
863         int32_t width_from_buffer; /* before applying viewport */
864         int32_t height_from_buffer;
865         int keep_buffer; /* bool for backends to prevent early release */
866
867         /* wl_viewport resource for this surface */
868         struct wl_resource *viewport_resource;
869
870         /* All the pending state, that wl_surface.commit will apply. */
871         struct weston_surface_state pending;
872
873         /*
874          * If non-NULL, this function will be called on
875          * wl_surface::commit after a new buffer has been set up for
876          * this surface. The integer params are the sx and sy
877          * parameters supplied to wl_surface::attach.
878          */
879         void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy);
880         void *configure_private;
881
882         /* Parent's list of its sub-surfaces, weston_subsurface:parent_link.
883          * Contains also the parent itself as a dummy weston_subsurface,
884          * if the list is not empty.
885          */
886         struct wl_list subsurface_list; /* weston_subsurface::parent_link */
887         struct wl_list subsurface_list_pending; /* ...::parent_link_pending */
888 };
889
890 struct weston_subsurface {
891         struct wl_resource *resource;
892
893         /* guaranteed to be valid and non-NULL */
894         struct weston_surface *surface;
895         struct wl_listener surface_destroy_listener;
896
897         /* can be NULL */
898         struct weston_surface *parent;
899         struct wl_listener parent_destroy_listener;
900         struct wl_list parent_link;
901         struct wl_list parent_link_pending;
902
903         struct {
904                 int32_t x;
905                 int32_t y;
906                 int set;
907         } position;
908
909         int has_cached_data;
910         struct weston_surface_state cached;
911         struct weston_buffer_reference cached_buffer_ref;
912
913         int synchronized;
914
915         /* Used for constructing the view tree */
916         struct wl_list unused_views;
917 };
918
919 enum weston_key_state_update {
920         STATE_UPDATE_AUTOMATIC,
921         STATE_UPDATE_NONE,
922 };
923
924 void
925 weston_version(int *major, int *minor, int *micro);
926
927 void
928 weston_view_update_transform(struct weston_view *view);
929
930 void
931 weston_view_geometry_dirty(struct weston_view *view);
932
933 void
934 weston_view_to_global_fixed(struct weston_view *view,
935                             wl_fixed_t sx, wl_fixed_t sy,
936                             wl_fixed_t *x, wl_fixed_t *y);
937 void
938 weston_view_to_global_float(struct weston_view *view,
939                             float sx, float sy, float *x, float *y);
940
941 void
942 weston_view_from_global_float(struct weston_view *view,
943                               float x, float y, float *vx, float *vy);
944 void
945 weston_view_from_global(struct weston_view *view,
946                         int32_t x, int32_t y, int32_t *vx, int32_t *vy);
947 void
948 weston_view_from_global_fixed(struct weston_view *view,
949                               wl_fixed_t x, wl_fixed_t y,
950                               wl_fixed_t *vx, wl_fixed_t *vy);
951
952 WL_EXPORT void
953 weston_surface_to_buffer_float(struct weston_surface *surface,
954                                float x, float y, float *bx, float *by);
955 WL_EXPORT void
956 weston_surface_to_buffer(struct weston_surface *surface,
957                          int sx, int sy, int *bx, int *by);
958 pixman_box32_t
959 weston_surface_to_buffer_rect(struct weston_surface *surface,
960                               pixman_box32_t rect);
961
962 void
963 weston_spring_init(struct weston_spring *spring,
964                    double k, double current, double target);
965 void
966 weston_spring_update(struct weston_spring *spring, uint32_t msec);
967 int
968 weston_spring_done(struct weston_spring *spring);
969
970 void
971 weston_surface_activate(struct weston_surface *surface,
972                         struct weston_seat *seat);
973 void
974 notify_motion(struct weston_seat *seat, uint32_t time,
975               wl_fixed_t dx, wl_fixed_t dy);
976 void
977 notify_motion_absolute(struct weston_seat *seat, uint32_t time,
978                        wl_fixed_t x, wl_fixed_t y);
979 void
980 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
981               enum wl_pointer_button_state state);
982 void
983 notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
984             wl_fixed_t value);
985 void
986 notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
987            enum wl_keyboard_key_state state,
988            enum weston_key_state_update update_state);
989 void
990 notify_modifiers(struct weston_seat *seat, uint32_t serial);
991
992 void
993 notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
994                      wl_fixed_t x, wl_fixed_t y);
995
996 void
997 notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
998                          enum weston_key_state_update update_state);
999 void
1000 notify_keyboard_focus_out(struct weston_seat *seat);
1001
1002 void
1003 notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
1004              wl_fixed_t x, wl_fixed_t y, int touch_type);
1005 void
1006 notify_touch_frame(struct weston_seat *seat);
1007
1008 void
1009 weston_layer_entry_insert(struct weston_layer_entry *list,
1010                           struct weston_layer_entry *entry);
1011 void
1012 weston_layer_entry_remove(struct weston_layer_entry *entry);
1013 void
1014 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
1015
1016 void
1017 weston_layer_set_mask(struct weston_layer *layer, int x, int y, int width, int height);
1018
1019 void
1020 weston_layer_set_mask_infinite(struct weston_layer *layer);
1021
1022 void
1023 weston_plane_init(struct weston_plane *plane,
1024                         struct weston_compositor *ec,
1025                         int32_t x, int32_t y);
1026 void
1027 weston_plane_release(struct weston_plane *plane);
1028
1029 void
1030 weston_compositor_stack_plane(struct weston_compositor *ec,
1031                               struct weston_plane *plane,
1032                               struct weston_plane *above);
1033
1034 void
1035 weston_output_finish_frame(struct weston_output *output, uint32_t msecs);
1036 void
1037 weston_output_schedule_repaint(struct weston_output *output);
1038 void
1039 weston_output_damage(struct weston_output *output);
1040 void
1041 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
1042 void
1043 weston_compositor_fade(struct weston_compositor *compositor, float tint);
1044 void
1045 weston_compositor_damage_all(struct weston_compositor *compositor);
1046 void
1047 weston_compositor_unlock(struct weston_compositor *compositor);
1048 void
1049 weston_compositor_wake(struct weston_compositor *compositor);
1050 void
1051 weston_compositor_offscreen(struct weston_compositor *compositor);
1052 void
1053 weston_compositor_sleep(struct weston_compositor *compositor);
1054 struct weston_view *
1055 weston_compositor_pick_view(struct weston_compositor *compositor,
1056                             wl_fixed_t x, wl_fixed_t y,
1057                             wl_fixed_t *sx, wl_fixed_t *sy);
1058
1059
1060 struct weston_binding;
1061 typedef void (*weston_key_binding_handler_t)(struct weston_seat *seat,
1062                                              uint32_t time, uint32_t key,
1063                                              void *data);
1064 struct weston_binding *
1065 weston_compositor_add_key_binding(struct weston_compositor *compositor,
1066                                   uint32_t key,
1067                                   enum weston_keyboard_modifier modifier,
1068                                   weston_key_binding_handler_t binding,
1069                                   void *data);
1070
1071 typedef void (*weston_modifier_binding_handler_t)(struct weston_seat *seat,
1072                                                   enum weston_keyboard_modifier modifier,
1073                                                   void *data);
1074 struct weston_binding *
1075 weston_compositor_add_modifier_binding(struct weston_compositor *compositor,
1076                                        enum weston_keyboard_modifier modifier,
1077                                        weston_modifier_binding_handler_t binding,
1078                                        void *data);
1079
1080 typedef void (*weston_button_binding_handler_t)(struct weston_seat *seat,
1081                                                 uint32_t time, uint32_t button,
1082                                                 void *data);
1083 struct weston_binding *
1084 weston_compositor_add_button_binding(struct weston_compositor *compositor,
1085                                      uint32_t button,
1086                                      enum weston_keyboard_modifier modifier,
1087                                      weston_button_binding_handler_t binding,
1088                                      void *data);
1089
1090 typedef void (*weston_touch_binding_handler_t)(struct weston_seat *seat,
1091                                                uint32_t time,
1092                                                void *data);
1093 struct weston_binding *
1094 weston_compositor_add_touch_binding(struct weston_compositor *compositor,
1095                                     enum weston_keyboard_modifier modifier,
1096                                     weston_touch_binding_handler_t binding,
1097                                     void *data);
1098
1099 typedef void (*weston_axis_binding_handler_t)(struct weston_seat *seat,
1100                                               uint32_t time, uint32_t axis,
1101                                               wl_fixed_t value, void *data);
1102 struct weston_binding *
1103 weston_compositor_add_axis_binding(struct weston_compositor *compositor,
1104                                    uint32_t axis,
1105                                    enum weston_keyboard_modifier modifier,
1106                                    weston_axis_binding_handler_t binding,
1107                                    void *data);
1108 struct weston_binding *
1109 weston_compositor_add_debug_binding(struct weston_compositor *compositor,
1110                                     uint32_t key,
1111                                     weston_key_binding_handler_t binding,
1112                                     void *data);
1113 void
1114 weston_binding_destroy(struct weston_binding *binding);
1115
1116 void
1117 weston_binding_list_destroy_all(struct wl_list *list);
1118
1119 void
1120 weston_compositor_run_key_binding(struct weston_compositor *compositor,
1121                                   struct weston_seat *seat, uint32_t time,
1122                                   uint32_t key,
1123                                   enum wl_keyboard_key_state state);
1124
1125 void
1126 weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
1127                                        struct weston_seat *seat,
1128                                        enum weston_keyboard_modifier modifier,
1129                                        enum wl_keyboard_key_state state);
1130 void
1131 weston_compositor_run_button_binding(struct weston_compositor *compositor,
1132                                      struct weston_seat *seat, uint32_t time,
1133                                      uint32_t button,
1134                                      enum wl_pointer_button_state value);
1135 void
1136 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
1137                                     struct weston_seat *seat, uint32_t time,
1138                                     int touch_type);
1139 int
1140 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
1141                                    struct weston_seat *seat, uint32_t time,
1142                                    uint32_t axis, int32_t value);
1143 int
1144 weston_compositor_run_debug_binding(struct weston_compositor *compositor,
1145                                     struct weston_seat *seat, uint32_t time,
1146                                     uint32_t key,
1147                                     enum wl_keyboard_key_state state);
1148
1149 void
1150 weston_compositor_set_default_pointer_grab(struct weston_compositor *compositor,
1151                         const struct weston_pointer_grab_interface *interface);
1152
1153 int
1154 weston_environment_get_fd(const char *env);
1155
1156 struct wl_list *
1157 weston_compositor_top(struct weston_compositor *compositor);
1158
1159 struct weston_surface *
1160 weston_surface_create(struct weston_compositor *compositor);
1161
1162 struct weston_view *
1163 weston_view_create(struct weston_surface *surface);
1164
1165 void
1166 weston_view_destroy(struct weston_view *view);
1167
1168 void
1169 weston_view_set_position(struct weston_view *view,
1170                          float x, float y);
1171
1172 void
1173 weston_view_set_transform_parent(struct weston_view *view,
1174                                  struct weston_view *parent);
1175
1176 int
1177 weston_view_is_mapped(struct weston_view *view);
1178
1179 void
1180 weston_view_schedule_repaint(struct weston_view *view);
1181
1182 int
1183 weston_surface_is_mapped(struct weston_surface *surface);
1184
1185 WL_EXPORT void
1186 weston_surface_set_size(struct weston_surface *surface,
1187                         int32_t width, int32_t height);
1188
1189 void
1190 weston_surface_schedule_repaint(struct weston_surface *surface);
1191
1192 void
1193 weston_surface_damage(struct weston_surface *surface);
1194
1195 void
1196 weston_view_damage_below(struct weston_view *view);
1197
1198 void
1199 weston_view_move_to_plane(struct weston_view *view,
1200                           struct weston_plane *plane);
1201 void
1202 weston_view_unmap(struct weston_view *view);
1203
1204 void
1205 weston_surface_unmap(struct weston_surface *surface);
1206
1207 struct weston_surface *
1208 weston_surface_get_main_surface(struct weston_surface *surface);
1209
1210 struct weston_buffer *
1211 weston_buffer_from_resource(struct wl_resource *resource);
1212
1213 void
1214 weston_buffer_reference(struct weston_buffer_reference *ref,
1215                         struct weston_buffer *buffer);
1216
1217 uint32_t
1218 weston_compositor_get_time(void);
1219
1220 int
1221 weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
1222                        int *argc, char *argv[], struct weston_config *config);
1223 void
1224 weston_compositor_shutdown(struct weston_compositor *ec);
1225 void
1226 weston_output_init_zoom(struct weston_output *output);
1227 void
1228 weston_output_update_zoom(struct weston_output *output);
1229 void
1230 weston_output_activate_zoom(struct weston_output *output);
1231 void
1232 weston_output_update_matrix(struct weston_output *output);
1233 void
1234 weston_output_move(struct weston_output *output, int x, int y);
1235 void
1236 weston_output_init(struct weston_output *output, struct weston_compositor *c,
1237                    int x, int y, int width, int height, uint32_t transform, int32_t scale);
1238 void
1239 weston_output_destroy(struct weston_output *output);
1240 void
1241 weston_output_transform_coordinate(struct weston_output *output,
1242                                    wl_fixed_t device_x, wl_fixed_t device_y,
1243                                    wl_fixed_t *x, wl_fixed_t *y);
1244
1245 void
1246 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,
1247                  const char *seat_name);
1248 void
1249 weston_seat_init_pointer(struct weston_seat *seat);
1250 void
1251 weston_seat_release_pointer(struct weston_seat *seat);
1252 int
1253 weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap);
1254 void
1255 weston_seat_release_keyboard(struct weston_seat *seat);
1256 void
1257 weston_seat_init_touch(struct weston_seat *seat);
1258 void
1259 weston_seat_release_touch(struct weston_seat *seat);
1260 void
1261 weston_seat_repick(struct weston_seat *seat);
1262 void
1263 weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap);
1264
1265 void
1266 weston_seat_release(struct weston_seat *seat);
1267 int
1268 weston_compositor_xkb_init(struct weston_compositor *ec,
1269                            struct xkb_rule_names *names);
1270 void
1271 weston_compositor_xkb_destroy(struct weston_compositor *ec);
1272
1273 /* String literal of spaces, the same width as the timestamp. */
1274 #define STAMP_SPACE "               "
1275
1276 void
1277 weston_log_file_open(const char *filename);
1278 void
1279 weston_log_file_close(void);
1280 int
1281 weston_vlog(const char *fmt, va_list ap);
1282 int
1283 weston_vlog_continue(const char *fmt, va_list ap);
1284 int
1285 weston_log(const char *fmt, ...)
1286         __attribute__ ((format (printf, 1, 2)));
1287 int
1288 weston_log_continue(const char *fmt, ...)
1289         __attribute__ ((format (printf, 1, 2)));
1290
1291 enum {
1292         TTY_ENTER_VT,
1293         TTY_LEAVE_VT
1294 };
1295
1296 struct tty *
1297 tty_create(struct weston_compositor *compositor, int tty_nr);
1298
1299 void
1300 tty_destroy(struct tty *tty);
1301
1302 void
1303 tty_reset(struct tty *tty);
1304
1305 int
1306 tty_activate_vt(struct tty *tty, int vt);
1307
1308 void
1309 screenshooter_create(struct weston_compositor *ec);
1310
1311 enum weston_screenshooter_outcome {
1312         WESTON_SCREENSHOOTER_SUCCESS,
1313         WESTON_SCREENSHOOTER_NO_MEMORY,
1314         WESTON_SCREENSHOOTER_BAD_BUFFER
1315 };
1316
1317 typedef void (*weston_screenshooter_done_func_t)(void *data,
1318                                 enum weston_screenshooter_outcome outcome);
1319 int
1320 weston_screenshooter_shoot(struct weston_output *output, struct weston_buffer *buffer,
1321                            weston_screenshooter_done_func_t done, void *data);
1322
1323 struct clipboard *
1324 clipboard_create(struct weston_seat *seat);
1325
1326 int
1327 text_backend_init(struct weston_compositor *ec);
1328
1329 struct weston_process;
1330 typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
1331                                             int status);
1332
1333 struct weston_process {
1334         pid_t pid;
1335         weston_process_cleanup_func_t cleanup;
1336         struct wl_list link;
1337 };
1338
1339 struct wl_client *
1340 weston_client_launch(struct weston_compositor *compositor,
1341                      struct weston_process *proc,
1342                      const char *path,
1343                      weston_process_cleanup_func_t cleanup);
1344
1345 void
1346 weston_watch_process(struct weston_process *process);
1347
1348 struct weston_view_animation;
1349 typedef void (*weston_view_animation_done_func_t)(struct weston_view_animation *animation, void *data);
1350
1351 void
1352 weston_view_animation_destroy(struct weston_view_animation *animation);
1353
1354 struct weston_view_animation *
1355 weston_zoom_run(struct weston_view *view, float start, float stop,
1356                 weston_view_animation_done_func_t done, void *data);
1357
1358 struct weston_view_animation *
1359 weston_fade_run(struct weston_view *view,
1360                 float start, float end, float k,
1361                 weston_view_animation_done_func_t done, void *data);
1362
1363 struct weston_view_animation *
1364 weston_move_scale_run(struct weston_view *view, int dx, int dy,
1365                       float start, float end, int reverse,
1366                       weston_view_animation_done_func_t done, void *data);
1367
1368 void
1369 weston_fade_update(struct weston_view_animation *fade, float target);
1370
1371 struct weston_view_animation *
1372 weston_stable_fade_run(struct weston_view *front_view, float start,
1373                        struct weston_view *back_view, float end,
1374                        weston_view_animation_done_func_t done, void *data);
1375
1376 struct weston_view_animation *
1377 weston_slide_run(struct weston_view *view, float start, float stop,
1378                  weston_view_animation_done_func_t done, void *data);
1379
1380 void
1381 weston_surface_set_color(struct weston_surface *surface,
1382                          float red, float green, float blue, float alpha);
1383
1384 void
1385 weston_surface_destroy(struct weston_surface *surface);
1386
1387 int
1388 weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode,
1389                         int32_t scale, enum weston_mode_switch_op op);
1390
1391 int
1392 noop_renderer_init(struct weston_compositor *ec);
1393
1394 struct weston_compositor *
1395 backend_init(struct wl_display *display, int *argc, char *argv[],
1396              struct weston_config *config);
1397
1398 int
1399 module_init(struct weston_compositor *compositor,
1400             int *argc, char *argv[]);
1401
1402 void
1403 weston_transformed_coord(int width, int height,
1404                          enum wl_output_transform transform,
1405                          int32_t scale,
1406                          float sx, float sy, float *bx, float *by);
1407 pixman_box32_t
1408 weston_transformed_rect(int width, int height,
1409                         enum wl_output_transform transform,
1410                         int32_t scale,
1411                         pixman_box32_t rect);
1412 void
1413 weston_transformed_region(int width, int height,
1414                           enum wl_output_transform transform,
1415                           int32_t scale,
1416                           pixman_region32_t *src, pixman_region32_t *dest);
1417
1418 void *
1419 weston_load_module(const char *name, const char *entrypoint);
1420
1421 #ifdef  __cplusplus
1422 }
1423 #endif
1424
1425 #endif