blob: dfe995166537537b2045977fac5c79ca67826b35 [file] [log] [blame]
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
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.
8 *
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.
13 *
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.
17 */
18
19#ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
20#define _WAYLAND_SYSTEM_COMPOSITOR_H_
21
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040022#include <xf86drm.h>
23#include <xf86drmMode.h>
24#include <libudev.h>
Kristian Høgsberga661f262010-08-10 14:12:05 -040025#include "wayland-server.h"
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040026#include "wayland-util.h"
27
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040028#define GL_GLEXT_PROTOTYPES
29#define EGL_EGLEXT_PROTOTYPES
30#include <GLES2/gl2.h>
31#include <GLES2/gl2ext.h>
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040032#include <EGL/egl.h>
33#include <EGL/eglext.h>
34
35#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
36
37struct wlsc_matrix {
38 GLfloat d[16];
39};
40
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040041struct wlsc_surface;
42
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040043struct wlsc_output {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050044 struct wl_object object;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040045 struct wl_list link;
46 struct wlsc_compositor *compositor;
47 struct wlsc_surface *background;
48 struct wlsc_matrix matrix;
49 int32_t x, y, width, height;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040050};
51
Kristian Høgsberg1db21f12010-08-16 16:08:12 -040052enum wlsc_pointer_type {
53 WLSC_POINTER_BOTTOM_LEFT,
54 WLSC_POINTER_BOTTOM_RIGHT,
55 WLSC_POINTER_BOTTOM,
56 WLSC_POINTER_DRAGGING,
57 WLSC_POINTER_LEFT_PTR,
58 WLSC_POINTER_LEFT,
59 WLSC_POINTER_RIGHT,
60 WLSC_POINTER_TOP_LEFT,
61 WLSC_POINTER_TOP_RIGHT,
62 WLSC_POINTER_TOP,
63 WLSC_POINTER_IBEAM,
64};
65
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040066struct wlsc_input_device {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050067 struct wl_input_device input_device;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040068 struct wlsc_surface *sprite;
Kristian Høgsberg77fb1672010-08-16 10:38:29 -040069 int32_t hotspot_x, hotspot_y;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040070 struct wl_list link;
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -040071 uint32_t modifier_state;
Kristian Høgsbergae6c8a62011-01-18 09:08:53 -050072 struct wl_selection *selection;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040073};
74
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040075struct wlsc_drm {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050076 struct wl_object object;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040077 int fd;
78 char *filename;
79};
80
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -040081struct wlsc_shm {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050082 struct wl_object object;
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -040083};
84
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040085struct wlsc_compositor {
Kristian Høgsbergb313b022010-12-01 17:07:41 -050086 struct wl_compositor compositor;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040087
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040088 struct wlsc_drm drm;
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -040089 struct wlsc_shm shm;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040090 EGLDisplay display;
91 EGLContext context;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040092 GLuint fbo, vbo;
93 GLuint proj_uniform, tex_uniform;
Kristian Høgsberg8525a502011-01-14 16:20:21 -050094 struct wl_buffer **pointer_buffers;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040095 struct wl_display *wl_display;
96
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040097 /* We implement the shell interface. */
Kristian Høgsberg77a4a792010-08-16 16:24:19 -040098 struct wl_shell shell;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040099
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400100 /* There can be more than one, but not right now... */
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500101 struct wl_input_device *input_device;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400102
103 struct wl_list output_list;
104 struct wl_list input_device_list;
105 struct wl_list surface_list;
106
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400107 /* Repaint state. */
108 struct wl_event_source *timer_source;
109 int repaint_needed;
110 int repaint_on_timeout;
111 struct timespec previous_swap;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400112
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -0500113 struct wlsc_switcher *switcher;
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400114 uint32_t focus;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400115
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500116 void (*destroy)(struct wlsc_compositor *ec);
Kristian Høgsberg640609a2010-08-09 22:11:47 -0400117 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400118 void (*present)(struct wlsc_compositor *c);
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500119 struct wl_buffer *(*create_buffer)(struct wlsc_compositor *c,
120 int32_t width, int32_t height,
121 struct wl_visual *visual,
122 const void *data);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400123};
124
125#define MODIFIER_CTRL (1 << 8)
126#define MODIFIER_ALT (1 << 9)
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -0400127#define MODIFIER_SUPER (1 << 10)
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400128
129struct wlsc_vector {
130 GLfloat f[4];
131};
132
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500133enum wlsc_surface_map_type {
134 WLSC_SURFACE_MAP_UNMAPPED,
135 WLSC_SURFACE_MAP_TOPLEVEL,
136 WLSC_SURFACE_MAP_TRANSIENT,
137 WLSC_SURFACE_MAP_FULLSCREEN
138};
139
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400140struct wlsc_surface {
Kristian Høgsbergb313b022010-12-01 17:07:41 -0500141 struct wl_surface surface;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400142 struct wlsc_compositor *compositor;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400143 GLuint texture;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400144 int32_t x, y, width, height;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500145 int32_t saved_x, saved_y;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400146 struct wl_list link;
147 struct wlsc_matrix matrix;
148 struct wlsc_matrix matrix_inv;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400149 struct wl_visual *visual;
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -0400150 struct wl_buffer *buffer;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500151 enum wlsc_surface_map_type map_type;
152 struct wlsc_output *fullscreen_output;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400153};
154
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500155void
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500156wlsc_surface_update_matrix(struct wlsc_surface *es);
157
158void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500159notify_motion(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400160 uint32_t time, int x, int y);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500161void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500162notify_button(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400163 uint32_t time, int32_t button, int32_t state);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500164void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500165notify_key(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400166 uint32_t time, uint32_t key, uint32_t state);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500167
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400168void
Kristian Høgsberg93331ff2011-01-26 20:35:07 -0500169notify_pointer_focus(struct wl_input_device *device,
170 uint32_t time,
171 struct wlsc_output *output,
172 int32_t x, int32_t y);
173
174void
Kristian Høgsberg3ba48582011-01-27 11:57:19 -0500175notify_keyboard_focus(struct wl_input_device *device,
176 uint32_t time, struct wlsc_output *output,
177 struct wl_array *keys);
178
179void
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400180wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400181void
182wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400183
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500184void
185wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
186 enum wlsc_pointer_type type);
187struct wlsc_surface *
188pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
189
Kristian Høgsbergae6c8a62011-01-18 09:08:53 -0500190void
191wlsc_selection_set_focus(struct wl_selection *selection,
192 struct wl_surface *surface, uint32_t time);
193
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500194uint32_t
195get_time(void);
196
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500197struct wl_buffer *
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -0400198wlsc_drm_buffer_create(struct wlsc_compositor *ec,
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500199 int width, int height,
200 struct wl_visual *visual, const void *data);
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -0400201
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400202int
203wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
204void
205wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
206 int x, int y, int width, int height);
207void
208wlsc_input_device_init(struct wlsc_input_device *device,
209 struct wlsc_compositor *ec);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400210int
211wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400212
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -0400213int
214wlsc_shm_init(struct wlsc_compositor *ec);
215
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500216int
217wlsc_shell_init(struct wlsc_compositor *ec);
218
219void
220shell_move(struct wl_client *client, struct wl_shell *shell,
221 struct wl_surface *surface,
222 struct wl_input_device *device, uint32_t time);
223
224void
225shell_resize(struct wl_client *client, struct wl_shell *shell,
226 struct wl_surface *surface,
227 struct wl_input_device *device, uint32_t time, uint32_t edges);
228
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -0400229struct wl_buffer *
230wl_buffer_create_drm(struct wlsc_compositor *compositor,
231 struct wl_visual *visual);
232
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400233struct wlsc_compositor *
Kristian Høgsberg61a82512010-10-26 11:26:44 -0400234x11_compositor_create(struct wl_display *display, int width, int height);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400235
236struct wlsc_compositor *
Kristian Høgsberg61a82512010-10-26 11:26:44 -0400237drm_compositor_create(struct wl_display *display, int connector);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400238
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100239struct wlsc_compositor *
240wayland_compositor_create(struct wl_display *display, int width, int height);
241
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400242void
Kristian Høgsberg43db4012011-01-14 14:45:42 -0500243evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
244
Kristian Høgsberge4762a62011-01-14 14:59:13 -0500245struct tty *
246tty_create(struct wlsc_compositor *compositor);
247
248void
249tty_destroy(struct tty *tty);
250
Kristian Høgsberg43db4012011-01-14 14:45:42 -0500251void
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400252screenshooter_create(struct wlsc_compositor *ec);
253
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500254uint32_t *
255wlsc_load_image(const char *filename, int width, int height);
256
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500257#endif