blob: 44fc1a8dacf1e1b0b9df4d0a1abb3472b385b83c [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 <termios.h>
23#include <xf86drm.h>
24#include <xf86drmMode.h>
25#include <libudev.h>
Kristian Høgsberga661f262010-08-10 14:12:05 -040026#include "wayland-server.h"
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040027#include "wayland-util.h"
28
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040029#define GL_GLEXT_PROTOTYPES
30#define EGL_EGLEXT_PROTOTYPES
31#include <GLES2/gl2.h>
32#include <GLES2/gl2ext.h>
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040033#include <EGL/egl.h>
34#include <EGL/eglext.h>
35
36#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
37
38struct wlsc_matrix {
39 GLfloat d[16];
40};
41
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040042struct wlsc_surface;
43
44struct wlsc_listener {
45 struct wl_list link;
46 void (*func)(struct wlsc_listener *listener,
47 struct wlsc_surface *surface);
48};
49
50struct wlsc_output {
51 struct wl_object base;
52 struct wl_list link;
53 struct wlsc_compositor *compositor;
54 struct wlsc_surface *background;
55 struct wlsc_matrix matrix;
56 int32_t x, y, width, height;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040057};
58
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040059/* These should be part of the protocol */
60enum wlsc_grab_type {
61 WLSC_DEVICE_GRAB_NONE = 0,
62 WLSC_DEVICE_GRAB_RESIZE_TOP = 1,
63 WLSC_DEVICE_GRAB_RESIZE_BOTTOM = 2,
64 WLSC_DEVICE_GRAB_RESIZE_LEFT = 4,
65 WLSC_DEVICE_GRAB_RESIZE_TOP_LEFT = 5,
66 WLSC_DEVICE_GRAB_RESIZE_BOTTOM_LEFT = 6,
67 WLSC_DEVICE_GRAB_RESIZE_RIGHT = 8,
68 WLSC_DEVICE_GRAB_RESIZE_TOP_RIGHT = 9,
69 WLSC_DEVICE_GRAB_RESIZE_BOTTOM_RIGHT = 10,
70 WLSC_DEVICE_GRAB_RESIZE_MASK = 15,
71 WLSC_DEVICE_GRAB_MOVE = 16,
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -040072 WLSC_DEVICE_GRAB_MOTION = 17,
73 WLSC_DEVICE_GRAB_DRAG = 18
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040074};
75
Kristian Høgsberg1db21f12010-08-16 16:08:12 -040076enum wlsc_pointer_type {
77 WLSC_POINTER_BOTTOM_LEFT,
78 WLSC_POINTER_BOTTOM_RIGHT,
79 WLSC_POINTER_BOTTOM,
80 WLSC_POINTER_DRAGGING,
81 WLSC_POINTER_LEFT_PTR,
82 WLSC_POINTER_LEFT,
83 WLSC_POINTER_RIGHT,
84 WLSC_POINTER_TOP_LEFT,
85 WLSC_POINTER_TOP_RIGHT,
86 WLSC_POINTER_TOP,
87 WLSC_POINTER_IBEAM,
88};
89
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040090struct wlsc_input_device {
Kristian Høgsberg77a4a792010-08-16 16:24:19 -040091 struct wl_input_device base;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040092 int32_t x, y;
93 struct wlsc_compositor *ec;
94 struct wlsc_surface *sprite;
Kristian Høgsberg77fb1672010-08-16 10:38:29 -040095 int32_t hotspot_x, hotspot_y;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040096 struct wl_list link;
97
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040098 struct wlsc_surface *pointer_focus;
99 struct wlsc_surface *keyboard_focus;
100 struct wl_array keys;
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -0400101 uint32_t modifier_state;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400102
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400103 enum wlsc_grab_type grab;
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400104 struct wlsc_surface *grab_surface;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400105 uint32_t grab_time;
106 int32_t grab_x, grab_y;
107 int32_t grab_width, grab_height;
108 int32_t grab_dx, grab_dy;
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400109 uint32_t grab_button;
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -0400110 struct wl_drag drag;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400111
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400112 struct wlsc_listener listener;
113};
114
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400115struct wlsc_drm {
116 struct wl_object base;
117 int fd;
118 char *filename;
119};
120
121struct wlsc_buffer {
122 struct wl_buffer base;
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -0400123 int32_t width, height;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400124 EGLImageKHR image;
125 struct wl_visual *visual;
126};
127
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400128struct wlsc_compositor {
129 struct wl_compositor base;
130 struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual;
131
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400132 struct wlsc_drm drm;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400133 EGLDisplay display;
134 EGLContext context;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400135 GLuint fbo, vbo;
136 GLuint proj_uniform, tex_uniform;
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -0400137 struct wlsc_buffer *pointer_buffers;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400138 struct wl_display *wl_display;
139
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400140 /* We implement the shell interface. */
Kristian Høgsberg77a4a792010-08-16 16:24:19 -0400141 struct wl_shell shell;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400142
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400143 /* There can be more than one, but not right now... */
144 struct wlsc_input_device *input_device;
145
146 struct wl_list output_list;
147 struct wl_list input_device_list;
148 struct wl_list surface_list;
149
150 struct wl_list surface_destroy_listener_list;
151
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400152 /* Repaint state. */
153 struct wl_event_source *timer_source;
154 int repaint_needed;
155 int repaint_on_timeout;
156 struct timespec previous_swap;
157 uint32_t current_frame;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400158
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400159 uint32_t focus;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400160
Kristian Høgsberg640609a2010-08-09 22:11:47 -0400161 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400162 void (*present)(struct wlsc_compositor *c);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400163};
164
165#define MODIFIER_CTRL (1 << 8)
166#define MODIFIER_ALT (1 << 9)
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -0400167#define MODIFIER_SUPER (1 << 10)
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400168
169struct wlsc_vector {
170 GLfloat f[4];
171};
172
173struct wlsc_surface {
174 struct wl_surface base;
175 struct wlsc_compositor *compositor;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400176 GLuint texture;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400177 int32_t x, y, width, height;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400178 struct wl_list link;
179 struct wlsc_matrix matrix;
180 struct wlsc_matrix matrix_inv;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400181 struct wl_visual *visual;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400182};
183
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500184void
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400185notify_motion(struct wlsc_input_device *device,
186 uint32_t time, int x, int y);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500187void
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400188notify_button(struct wlsc_input_device *device,
189 uint32_t time, int32_t button, int32_t state);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500190void
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400191notify_key(struct wlsc_input_device *device,
192 uint32_t time, uint32_t key, uint32_t state);
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500193
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400194void
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400195wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400196void
197wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400198
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400199int
200wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
201void
202wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
203 int x, int y, int width, int height);
204void
205wlsc_input_device_init(struct wlsc_input_device *device,
206 struct wlsc_compositor *ec);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400207int
208wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400209
210struct wlsc_compositor *
211x11_compositor_create(struct wl_display *display);
212
213struct wlsc_compositor *
214drm_compositor_create(struct wl_display *display);
215
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400216void
217screenshooter_create(struct wlsc_compositor *ec);
218
219extern const char *option_background;
220extern int option_connector;
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500221
222#endif