2 * Copyright © 2008 Kristian Høgsberg
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
20 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
24 #include "wayland-server.h"
25 #include "wayland-util.h"
27 #define GL_GLEXT_PROTOTYPES
28 #define EGL_EGLEXT_PROTOTYPES
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
32 #include <EGL/eglext.h>
34 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
43 struct wl_object object;
45 struct wlsc_compositor *compositor;
46 struct wlsc_surface *background;
47 struct wlsc_matrix matrix;
48 int32_t x, y, width, height;
49 pixman_region32_t previous_damage_region;
54 int (*prepare_render)(struct wlsc_output *output);
55 int (*present)(struct wlsc_output *output);
56 int (*prepare_scanout_surface)(struct wlsc_output *output,
57 struct wlsc_surface *es);
58 int (*set_hardware_cursor)(struct wlsc_output *output,
59 struct wl_input_device *input);
62 enum wlsc_pointer_type {
63 WLSC_POINTER_BOTTOM_LEFT,
64 WLSC_POINTER_BOTTOM_RIGHT,
66 WLSC_POINTER_DRAGGING,
67 WLSC_POINTER_LEFT_PTR,
70 WLSC_POINTER_TOP_LEFT,
71 WLSC_POINTER_TOP_RIGHT,
76 struct wlsc_input_device {
77 struct wl_input_device input_device;
78 struct wlsc_surface *sprite;
79 int32_t hotspot_x, hotspot_y;
81 uint32_t modifier_state;
82 struct wl_selection *selection;
88 struct wl_visual *visual;
93 struct wlsc_compositor {
94 struct wl_compositor compositor;
102 GLuint proj_uniform, tex_uniform;
103 struct wlsc_sprite **pointer_sprites;
104 struct wl_display *wl_display;
106 /* We implement the shell interface. */
107 struct wl_shell shell;
109 /* There can be more than one, but not right now... */
110 struct wl_input_device *input_device;
112 struct wl_list output_list;
113 struct wl_list input_device_list;
114 struct wl_list surface_list;
115 struct wl_list binding_list;
118 struct wl_event_source *timer_source;
119 int repaint_on_timeout;
120 struct timespec previous_swap;
121 pixman_region32_t damage_region;
122 struct wl_array vertices, indices;
124 struct wlsc_surface *overlay;
125 struct wlsc_switcher *switcher;
128 void (*destroy)(struct wlsc_compositor *ec);
129 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
130 EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
131 int32_t width, int32_t height);
134 #define MODIFIER_CTRL (1 << 8)
135 #define MODIFIER_ALT (1 << 9)
136 #define MODIFIER_SUPER (1 << 10)
138 enum wlsc_output_flags {
139 WL_OUTPUT_FLIPPED = 0x01
146 enum wlsc_surface_map_type {
147 WLSC_SURFACE_MAP_UNMAPPED,
148 WLSC_SURFACE_MAP_TOPLEVEL,
149 WLSC_SURFACE_MAP_TRANSIENT,
150 WLSC_SURFACE_MAP_FULLSCREEN
153 struct wlsc_surface {
154 struct wl_surface surface;
155 struct wlsc_compositor *compositor;
156 GLuint texture, saved_texture;
157 int32_t x, y, width, height;
158 int32_t saved_x, saved_y;
160 struct wl_list buffer_link;
161 struct wlsc_matrix matrix;
162 struct wlsc_matrix matrix_inv;
163 struct wl_visual *visual;
164 struct wl_buffer *buffer;
165 struct wlsc_output *output;
166 enum wlsc_surface_map_type map_type;
167 struct wlsc_output *fullscreen_output;
173 wlsc_surface_update_matrix(struct wlsc_surface *es);
176 wlsc_surface_activate(struct wlsc_surface *surface,
177 struct wlsc_input_device *device, uint32_t time);
180 notify_motion(struct wl_input_device *device,
181 uint32_t time, int x, int y);
183 notify_button(struct wl_input_device *device,
184 uint32_t time, int32_t button, int32_t state);
186 notify_key(struct wl_input_device *device,
187 uint32_t time, uint32_t key, uint32_t state);
190 notify_pointer_focus(struct wl_input_device *device,
192 struct wlsc_output *output,
193 int32_t x, int32_t y);
196 notify_keyboard_focus(struct wl_input_device *device,
197 uint32_t time, struct wlsc_output *output,
198 struct wl_array *keys);
201 wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
203 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
206 typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
207 uint32_t time, uint32_t key,
209 uint32_t state, void *data);
210 struct wlsc_binding *
211 wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
212 uint32_t key, uint32_t button, uint32_t modifier,
213 wlsc_binding_handler_t binding, void *data);
215 wlsc_binding_destroy(struct wlsc_binding *binding);
217 struct wlsc_surface *
218 wlsc_surface_create(struct wlsc_compositor *compositor,
219 int32_t x, int32_t y, int32_t width, int32_t height);
222 wlsc_surface_assign_output(struct wlsc_surface *surface);
225 wlsc_surface_damage(struct wlsc_surface *surface);
228 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
229 int32_t x, int32_t y,
230 int32_t width, int32_t height);
233 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
234 enum wlsc_pointer_type type);
235 struct wlsc_surface *
236 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
239 wlsc_selection_set_focus(struct wl_selection *selection,
240 struct wl_surface *surface, uint32_t time);
246 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
248 wlsc_output_move(struct wlsc_output *output, int x, int y);
250 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
251 int x, int y, int width, int height, uint32_t flags);
253 wlsc_output_destroy(struct wlsc_output *output);
256 wlsc_input_device_init(struct wlsc_input_device *device,
257 struct wlsc_compositor *ec);
260 wlsc_shell_init(struct wlsc_compositor *ec);
263 wlsc_switcher_init(struct wlsc_compositor *compositor);
265 struct wlsc_compositor *
266 x11_compositor_create(struct wl_display *display, int width, int height);
268 struct wlsc_compositor *
269 drm_compositor_create(struct wl_display *display, int connector);
271 struct wlsc_compositor *
272 wfd_compositor_create(struct wl_display *display, int connector);
274 struct wlsc_compositor *
275 wayland_compositor_create(struct wl_display *display, int width, int height);
278 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
281 tty_create(struct wlsc_compositor *compositor);
284 tty_destroy(struct tty *tty);
287 screenshooter_create(struct wlsc_compositor *ec);
290 wlsc_load_image(const char *filename, int width, int height);