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_
23 #include <xf86drmMode.h>
26 #include "wayland-server.h"
27 #include "wayland-util.h"
29 #define GL_GLEXT_PROTOTYPES
30 #define EGL_EGLEXT_PROTOTYPES
31 #include <GLES2/gl2.h>
32 #include <GLES2/gl2ext.h>
34 #include <EGL/eglext.h>
36 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
45 struct wl_object object;
47 struct wlsc_compositor *compositor;
48 struct wlsc_surface *background;
49 struct wlsc_matrix matrix;
50 int32_t x, y, width, height;
51 pixman_region32_t previous_damage_region;
54 enum wlsc_pointer_type {
55 WLSC_POINTER_BOTTOM_LEFT,
56 WLSC_POINTER_BOTTOM_RIGHT,
58 WLSC_POINTER_DRAGGING,
59 WLSC_POINTER_LEFT_PTR,
62 WLSC_POINTER_TOP_LEFT,
63 WLSC_POINTER_TOP_RIGHT,
68 struct wlsc_input_device {
69 struct wl_input_device input_device;
70 struct wlsc_surface *sprite;
71 int32_t hotspot_x, hotspot_y;
73 uint32_t modifier_state;
74 struct wl_selection *selection;
78 struct wl_object object;
84 struct wl_object object;
87 struct wlsc_compositor {
88 struct wl_compositor compositor;
95 GLuint proj_uniform, tex_uniform;
96 struct wl_buffer **pointer_buffers;
97 struct wl_display *wl_display;
99 /* We implement the shell interface. */
100 struct wl_shell shell;
102 /* There can be more than one, but not right now... */
103 struct wl_input_device *input_device;
105 struct wl_list output_list;
106 struct wl_list input_device_list;
107 struct wl_list surface_list;
110 struct wl_event_source *timer_source;
112 int repaint_on_timeout;
113 struct timespec previous_swap;
114 pixman_region32_t damage_region;
116 struct wlsc_switcher *switcher;
119 void (*destroy)(struct wlsc_compositor *ec);
120 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
121 void (*present)(struct wlsc_compositor *c);
122 struct wl_buffer *(*create_buffer)(struct wlsc_compositor *c,
123 int32_t width, int32_t height,
124 struct wl_visual *visual,
128 #define MODIFIER_CTRL (1 << 8)
129 #define MODIFIER_ALT (1 << 9)
130 #define MODIFIER_SUPER (1 << 10)
136 enum wlsc_surface_map_type {
137 WLSC_SURFACE_MAP_UNMAPPED,
138 WLSC_SURFACE_MAP_TOPLEVEL,
139 WLSC_SURFACE_MAP_TRANSIENT,
140 WLSC_SURFACE_MAP_FULLSCREEN
143 struct wlsc_surface {
144 struct wl_surface surface;
145 struct wlsc_compositor *compositor;
147 int32_t x, y, width, height;
148 int32_t saved_x, saved_y;
150 struct wlsc_matrix matrix;
151 struct wlsc_matrix matrix_inv;
152 struct wl_visual *visual;
153 struct wl_buffer *buffer;
154 enum wlsc_surface_map_type map_type;
155 struct wlsc_output *fullscreen_output;
159 wlsc_surface_update_matrix(struct wlsc_surface *es);
162 notify_motion(struct wl_input_device *device,
163 uint32_t time, int x, int y);
165 notify_button(struct wl_input_device *device,
166 uint32_t time, int32_t button, int32_t state);
168 notify_key(struct wl_input_device *device,
169 uint32_t time, uint32_t key, uint32_t state);
172 notify_pointer_focus(struct wl_input_device *device,
174 struct wlsc_output *output,
175 int32_t x, int32_t y);
178 notify_keyboard_focus(struct wl_input_device *device,
179 uint32_t time, struct wlsc_output *output,
180 struct wl_array *keys);
183 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
185 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
188 wlsc_surface_damage(struct wlsc_surface *surface);
191 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
192 int32_t x, int32_t y,
193 int32_t width, int32_t height);
196 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
197 enum wlsc_pointer_type type);
198 struct wlsc_surface *
199 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
202 wlsc_selection_set_focus(struct wl_selection *selection,
203 struct wl_surface *surface, uint32_t time);
209 wlsc_drm_buffer_create(struct wlsc_compositor *ec,
210 int width, int height,
211 struct wl_visual *visual, const void *data);
214 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
216 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
217 int x, int y, int width, int height);
219 wlsc_input_device_init(struct wlsc_input_device *device,
220 struct wlsc_compositor *ec);
222 wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
225 wlsc_shm_init(struct wlsc_compositor *ec);
228 wlsc_shell_init(struct wlsc_compositor *ec);
231 shell_move(struct wl_client *client, struct wl_shell *shell,
232 struct wl_surface *surface,
233 struct wl_input_device *device, uint32_t time);
236 shell_resize(struct wl_client *client, struct wl_shell *shell,
237 struct wl_surface *surface,
238 struct wl_input_device *device, uint32_t time, uint32_t edges);
241 wl_buffer_create_drm(struct wlsc_compositor *compositor,
242 struct wl_visual *visual);
244 struct wlsc_compositor *
245 x11_compositor_create(struct wl_display *display, int width, int height);
247 struct wlsc_compositor *
248 drm_compositor_create(struct wl_display *display, int connector);
250 struct wlsc_compositor *
251 wayland_compositor_create(struct wl_display *display, int width, int height);
254 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
257 tty_create(struct wlsc_compositor *compositor);
260 tty_destroy(struct tty *tty);
263 screenshooter_create(struct wlsc_compositor *ec);
266 wlsc_load_image(const char *filename, int width, int height);