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