Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1 | /* |
| 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øgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 22 | #include <termios.h> |
| 23 | #include <xf86drm.h> |
| 24 | #include <xf86drmMode.h> |
| 25 | #include <libudev.h> |
Kristian Høgsberg | a661f26 | 2010-08-10 14:12:05 -0400 | [diff] [blame] | 26 | #include "wayland-server.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 27 | #include "wayland-util.h" |
| 28 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 29 | #define GL_GLEXT_PROTOTYPES |
| 30 | #define EGL_EGLEXT_PROTOTYPES |
| 31 | #include <GLES2/gl2.h> |
| 32 | #include <GLES2/gl2ext.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 33 | #include <EGL/egl.h> |
| 34 | #include <EGL/eglext.h> |
| 35 | |
| 36 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
| 37 | |
| 38 | struct wlsc_matrix { |
| 39 | GLfloat d[16]; |
| 40 | }; |
| 41 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 42 | struct wlsc_surface; |
| 43 | |
| 44 | struct wlsc_listener { |
| 45 | struct wl_list link; |
| 46 | void (*func)(struct wlsc_listener *listener, |
| 47 | struct wlsc_surface *surface); |
| 48 | }; |
| 49 | |
| 50 | struct 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øgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 59 | /* These should be part of the protocol */ |
| 60 | enum 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øgsberg | eef08fb | 2010-08-17 21:23:10 -0400 | [diff] [blame] | 72 | WLSC_DEVICE_GRAB_MOTION = 17, |
| 73 | WLSC_DEVICE_GRAB_DRAG = 18 |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 74 | }; |
| 75 | |
Kristian Høgsberg | 1db21f1 | 2010-08-16 16:08:12 -0400 | [diff] [blame] | 76 | enum 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øgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 90 | struct wlsc_input_device { |
Kristian Høgsberg | 77a4a79 | 2010-08-16 16:24:19 -0400 | [diff] [blame] | 91 | struct wl_input_device base; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 92 | int32_t x, y; |
| 93 | struct wlsc_compositor *ec; |
| 94 | struct wlsc_surface *sprite; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 95 | int32_t hotspot_x, hotspot_y; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 96 | struct wl_list link; |
| 97 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 98 | struct wlsc_surface *pointer_focus; |
| 99 | struct wlsc_surface *keyboard_focus; |
| 100 | struct wl_array keys; |
Kristian Høgsberg | 5b75f1b | 2010-08-04 23:21:41 -0400 | [diff] [blame] | 101 | uint32_t modifier_state; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 102 | |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 103 | enum wlsc_grab_type grab; |
Kristian Høgsberg | 1db21f1 | 2010-08-16 16:08:12 -0400 | [diff] [blame] | 104 | struct wlsc_surface *grab_surface; |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 105 | 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øgsberg | 1db21f1 | 2010-08-16 16:08:12 -0400 | [diff] [blame] | 109 | uint32_t grab_button; |
Kristian Høgsberg | eef08fb | 2010-08-17 21:23:10 -0400 | [diff] [blame] | 110 | struct wl_drag drag; |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 111 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 112 | struct wlsc_listener listener; |
| 113 | }; |
| 114 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 115 | struct wlsc_drm { |
| 116 | struct wl_object base; |
| 117 | int fd; |
| 118 | char *filename; |
| 119 | }; |
| 120 | |
| 121 | struct wlsc_buffer { |
| 122 | struct wl_buffer base; |
Kristian Høgsberg | eef08fb | 2010-08-17 21:23:10 -0400 | [diff] [blame] | 123 | int32_t width, height; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 124 | EGLImageKHR image; |
| 125 | struct wl_visual *visual; |
| 126 | }; |
| 127 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 128 | struct wlsc_compositor { |
| 129 | struct wl_compositor base; |
| 130 | struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual; |
| 131 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 132 | struct wlsc_drm drm; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 133 | EGLDisplay display; |
| 134 | EGLContext context; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 135 | GLuint fbo, vbo; |
| 136 | GLuint proj_uniform, tex_uniform; |
Kristian Høgsberg | eef08fb | 2010-08-17 21:23:10 -0400 | [diff] [blame] | 137 | struct wlsc_buffer *pointer_buffers; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 138 | struct wl_display *wl_display; |
| 139 | |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 140 | /* We implement the shell interface. */ |
Kristian Høgsberg | 77a4a79 | 2010-08-16 16:24:19 -0400 | [diff] [blame] | 141 | struct wl_shell shell; |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 142 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 143 | /* 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øgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 152 | /* 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øgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 158 | |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 159 | uint32_t focus; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 160 | |
Kristian Høgsberg | 640609a | 2010-08-09 22:11:47 -0400 | [diff] [blame] | 161 | int (*authenticate)(struct wlsc_compositor *c, uint32_t id); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 162 | void (*present)(struct wlsc_compositor *c); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | #define MODIFIER_CTRL (1 << 8) |
| 166 | #define MODIFIER_ALT (1 << 9) |
Kristian Høgsberg | 5b75f1b | 2010-08-04 23:21:41 -0400 | [diff] [blame] | 167 | #define MODIFIER_SUPER (1 << 10) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 168 | |
| 169 | struct wlsc_vector { |
| 170 | GLfloat f[4]; |
| 171 | }; |
| 172 | |
| 173 | struct wlsc_surface { |
| 174 | struct wl_surface base; |
| 175 | struct wlsc_compositor *compositor; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 176 | GLuint texture; |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 177 | int32_t x, y, width, height; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 178 | struct wl_list link; |
| 179 | struct wlsc_matrix matrix; |
| 180 | struct wlsc_matrix matrix_inv; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 181 | struct wl_visual *visual; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 182 | }; |
| 183 | |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 184 | void |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 185 | notify_motion(struct wlsc_input_device *device, |
| 186 | uint32_t time, int x, int y); |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 187 | void |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 188 | notify_button(struct wlsc_input_device *device, |
| 189 | uint32_t time, int32_t button, int32_t state); |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 190 | void |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 191 | notify_key(struct wlsc_input_device *device, |
| 192 | uint32_t time, uint32_t key, uint32_t state); |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 193 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 194 | void |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 195 | wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 196 | void |
| 197 | wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 198 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 199 | int |
| 200 | wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display); |
| 201 | void |
| 202 | wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c, |
| 203 | int x, int y, int width, int height); |
| 204 | void |
| 205 | wlsc_input_device_init(struct wlsc_input_device *device, |
| 206 | struct wlsc_compositor *ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 207 | int |
| 208 | wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 209 | |
| 210 | struct wlsc_compositor * |
| 211 | x11_compositor_create(struct wl_display *display); |
| 212 | |
| 213 | struct wlsc_compositor * |
| 214 | drm_compositor_create(struct wl_display *display); |
| 215 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 216 | void |
| 217 | screenshooter_create(struct wlsc_compositor *ec); |
| 218 | |
| 219 | extern const char *option_background; |
| 220 | extern int option_connector; |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 221 | |
| 222 | #endif |