Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 Kristian Høgsberg |
| 3 | * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 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. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 8 | * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 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. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 17 | */ |
| 18 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <string.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <stdint.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 23 | #include <stdarg.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 24 | #include <i915_drm.h> |
| 25 | #include <sys/ioctl.h> |
| 26 | #include <sys/mman.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <unistd.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 29 | #include <signal.h> |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 30 | #include <cairo.h> |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 31 | #include <gdk-pixbuf/gdk-pixbuf.h> |
| 32 | #include <glib.h> |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 33 | #include <sys/poll.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 34 | #include <png.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 36 | #include <linux/input.h> |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 37 | #include <linux/vt.h> |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 38 | #include <xf86drmMode.h> |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 39 | #include <time.h> |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 40 | #include <fnmatch.h> |
| 41 | #include <dirent.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 42 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 43 | #include <GL/gl.h> |
| 44 | #include <eagle.h> |
| 45 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 46 | #include "wayland.h" |
| 47 | #include "cairo-util.h" |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 48 | #include "wayland-system-compositor.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 49 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 50 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
| 51 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 52 | struct wl_visual { |
| 53 | struct wl_object base; |
| 54 | }; |
| 55 | |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 56 | struct wlsc_input_device { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 57 | struct wl_object base; |
| 58 | int32_t x, y; |
| 59 | struct egl_compositor *ec; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 60 | struct egl_surface *pointer_surface; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 61 | struct wl_list link; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 62 | |
| 63 | int grab; |
| 64 | struct egl_surface *grab_surface; |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 65 | struct egl_surface *focus_surface; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 66 | }; |
| 67 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 68 | struct egl_compositor { |
| 69 | struct wl_compositor base; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 70 | struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual; |
| 71 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 72 | EGLDisplay display; |
| 73 | EGLSurface surface; |
| 74 | EGLContext context; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 75 | EGLConfig config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 76 | struct wl_display *wl_display; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 77 | int tty_fd; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 78 | int width, height, stride; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 79 | struct egl_surface *background; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 80 | struct egl_surface *overlay; |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 81 | double overlay_y, overlay_target, overlay_previous; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 82 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 83 | struct wl_list input_device_list; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 84 | struct wl_list surface_list; |
| 85 | |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 86 | struct wl_event_source *enter_vt_source; |
| 87 | struct wl_event_source *leave_vt_source; |
| 88 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 89 | /* Modesetting info. */ |
| 90 | struct drm_mode_modeinfo *mode; |
| 91 | uint32_t fb_id; |
| 92 | uint32_t crtc_id; |
| 93 | uint32_t connector_id; |
| 94 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 95 | /* Repaint state. */ |
| 96 | struct wl_event_source *timer_source; |
| 97 | int repaint_needed; |
| 98 | int repaint_on_timeout; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 99 | struct timespec previous_swap; |
| 100 | uint32_t current_frame; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 101 | }; |
| 102 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 103 | struct egl_surface { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 104 | struct wl_surface base; |
| 105 | struct egl_compositor *compositor; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 106 | struct wl_visual *visual; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 107 | GLuint texture; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 108 | struct wl_map map; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 109 | EGLSurface surface; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 110 | int width, height; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 111 | struct wl_list link; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 112 | }; |
| 113 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 114 | struct screenshooter { |
| 115 | struct wl_object base; |
| 116 | struct egl_compositor *ec; |
| 117 | }; |
| 118 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 119 | struct screenshooter_interface { |
| 120 | void (*shoot)(struct wl_client *client, struct screenshooter *shooter); |
| 121 | }; |
| 122 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 123 | static void |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 124 | screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter) |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 125 | { |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 126 | struct egl_compositor *ec = shooter->ec; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 127 | GLuint stride; |
| 128 | static const char filename[] = "wayland-screenshot.png"; |
Kristian Høgsberg | 0ea4710 | 2008-12-14 15:53:13 -0500 | [diff] [blame] | 129 | GdkPixbuf *pixbuf; |
| 130 | GError *error = NULL; |
| 131 | void *data; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 132 | |
| 133 | data = eglReadBuffer(ec->display, ec->surface, GL_FRONT_LEFT, &stride); |
Kristian Høgsberg | 0ea4710 | 2008-12-14 15:53:13 -0500 | [diff] [blame] | 134 | pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, |
| 135 | 8, ec->width, ec->height, stride, |
| 136 | NULL, NULL); |
| 137 | gdk_pixbuf_save(pixbuf, filename, "png", &error, NULL); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 140 | static const struct wl_method screenshooter_methods[] = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 141 | { "shoot", "", NULL } |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | static const struct wl_interface screenshooter_interface = { |
| 145 | "screenshooter", 1, |
| 146 | ARRAY_LENGTH(screenshooter_methods), |
| 147 | screenshooter_methods, |
| 148 | }; |
| 149 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 150 | struct screenshooter_interface screenshooter_implementation = { |
| 151 | screenshooter_shoot |
| 152 | }; |
| 153 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 154 | static struct screenshooter * |
| 155 | screenshooter_create(struct egl_compositor *ec) |
| 156 | { |
| 157 | struct screenshooter *shooter; |
| 158 | |
| 159 | shooter = malloc(sizeof *shooter); |
| 160 | if (shooter == NULL) |
| 161 | return NULL; |
| 162 | |
| 163 | shooter->base.interface = &screenshooter_interface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 164 | shooter->base.implementation = (void(**)(void)) &screenshooter_implementation; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 165 | shooter->ec = ec; |
| 166 | |
| 167 | return shooter; |
| 168 | }; |
| 169 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 170 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 171 | egl_surface_create_from_cairo_surface(struct egl_compositor *ec, |
| 172 | cairo_surface_t *surface, |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 173 | int x, int y, int width, int height) |
| 174 | { |
| 175 | struct egl_surface *es; |
| 176 | int stride; |
| 177 | void *data; |
| 178 | |
| 179 | stride = cairo_image_surface_get_stride(surface); |
| 180 | data = cairo_image_surface_get_data(surface); |
| 181 | |
| 182 | es = malloc(sizeof *es); |
| 183 | if (es == NULL) |
| 184 | return NULL; |
| 185 | |
| 186 | glGenTextures(1, &es->texture); |
| 187 | glBindTexture(GL_TEXTURE_2D, es->texture); |
| 188 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 189 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 190 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 191 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 192 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, |
| 193 | GL_BGRA, GL_UNSIGNED_BYTE, data); |
| 194 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 195 | es->compositor = ec; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 196 | es->map.x = x; |
| 197 | es->map.y = y; |
| 198 | es->map.width = width; |
| 199 | es->map.height = height; |
| 200 | es->surface = EGL_NO_SURFACE; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 201 | es->visual = &ec->premultiplied_argb_visual; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 202 | |
| 203 | return es; |
| 204 | } |
| 205 | |
| 206 | static void |
| 207 | egl_surface_destroy(struct egl_surface *es, struct egl_compositor *ec) |
| 208 | { |
| 209 | glDeleteTextures(1, &es->texture); |
| 210 | if (es->surface != EGL_NO_SURFACE) |
| 211 | eglDestroySurface(ec->display, es->surface); |
| 212 | free(es); |
| 213 | } |
| 214 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 215 | static void |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 216 | pointer_path(cairo_t *cr, int x, int y) |
| 217 | { |
| 218 | const int end = 3, tx = 4, ty = 12, dx = 5, dy = 10; |
| 219 | const int width = 16, height = 16; |
| 220 | |
| 221 | cairo_move_to(cr, x, y); |
| 222 | cairo_line_to(cr, x + tx, y + ty); |
| 223 | cairo_line_to(cr, x + dx, y + dy); |
| 224 | cairo_line_to(cr, x + width - end, y + height); |
| 225 | cairo_line_to(cr, x + width, y + height - end); |
| 226 | cairo_line_to(cr, x + dy, y + dx); |
| 227 | cairo_line_to(cr, x + ty, y + tx); |
| 228 | cairo_close_path(cr); |
| 229 | } |
| 230 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 231 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 232 | pointer_create(struct egl_compositor *ec, int x, int y, int width, int height) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 233 | { |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 234 | struct egl_surface *es; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 235 | const int hotspot_x = 16, hotspot_y = 16; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 236 | cairo_surface_t *surface; |
| 237 | cairo_t *cr; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 238 | |
| 239 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 240 | width, height); |
| 241 | |
| 242 | cr = cairo_create(surface); |
| 243 | pointer_path(cr, hotspot_x + 5, hotspot_y + 4); |
| 244 | cairo_set_line_width (cr, 2); |
| 245 | cairo_set_source_rgb(cr, 0, 0, 0); |
| 246 | cairo_stroke_preserve(cr); |
| 247 | cairo_fill(cr); |
| 248 | blur_surface(surface, width); |
| 249 | |
| 250 | pointer_path(cr, hotspot_x, hotspot_y); |
| 251 | cairo_stroke_preserve(cr); |
| 252 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 253 | cairo_fill(cr); |
| 254 | cairo_destroy(cr); |
| 255 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 256 | es = egl_surface_create_from_cairo_surface(ec, |
| 257 | surface, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 258 | x - hotspot_x, |
| 259 | y - hotspot_y, |
| 260 | width, height); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 261 | |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 262 | cairo_surface_destroy(surface); |
| 263 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 264 | return es; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 268 | background_create(struct egl_compositor *ec, |
| 269 | const char *filename, int width, int height) |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 270 | { |
| 271 | struct egl_surface *background; |
| 272 | GdkPixbuf *pixbuf; |
| 273 | GError *error = NULL; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 274 | void *data; |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 275 | GLenum format; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 276 | |
| 277 | background = malloc(sizeof *background); |
| 278 | if (background == NULL) |
| 279 | return NULL; |
| 280 | |
| 281 | g_type_init(); |
| 282 | |
Kristian Høgsberg | 2d4219e | 2008-12-18 21:40:03 -0500 | [diff] [blame] | 283 | pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, |
| 284 | width, height, |
| 285 | FALSE, &error); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 286 | if (error != NULL) { |
| 287 | free(background); |
| 288 | return NULL; |
| 289 | } |
| 290 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 291 | data = gdk_pixbuf_get_pixels(pixbuf); |
| 292 | |
| 293 | glGenTextures(1, &background->texture); |
| 294 | glBindTexture(GL_TEXTURE_2D, background->texture); |
| 295 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 296 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 297 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 298 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 299 | |
| 300 | if (gdk_pixbuf_get_has_alpha (pixbuf)) { |
| 301 | format = GL_RGBA; |
| 302 | } else { |
| 303 | format = GL_RGB; |
| 304 | } |
| 305 | |
Kristian Høgsberg | 2d4219e | 2008-12-18 21:40:03 -0500 | [diff] [blame] | 306 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 307 | format, GL_UNSIGNED_BYTE, data); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 308 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 309 | background->compositor = ec; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 310 | background->map.x = 0; |
| 311 | background->map.y = 0; |
| 312 | background->map.width = width; |
| 313 | background->map.height = height; |
| 314 | background->surface = EGL_NO_SURFACE; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 315 | background->visual = &ec->rgb_visual; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 316 | |
| 317 | return background; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static void |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 321 | rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius) |
| 322 | { |
| 323 | cairo_move_to(cr, x0, y0 + radius); |
| 324 | cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2); |
| 325 | cairo_line_to(cr, x1 - radius, y0); |
| 326 | cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI); |
| 327 | cairo_line_to(cr, x1, y1 - radius); |
| 328 | cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2); |
| 329 | cairo_line_to(cr, x0 + radius, y1); |
| 330 | cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI); |
| 331 | cairo_close_path(cr); |
| 332 | } |
| 333 | |
| 334 | static void |
| 335 | draw_button(cairo_t *cr, int x, int y, int width, int height, const char *text) |
| 336 | { |
| 337 | cairo_pattern_t *gradient; |
| 338 | cairo_text_extents_t extents; |
| 339 | double bright = 0.15, dim = 0.02; |
| 340 | int radius = 10; |
| 341 | |
| 342 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 343 | cairo_set_line_width (cr, 2); |
| 344 | rounded_rect(cr, x, y, x + width, y + height, radius); |
| 345 | cairo_set_source_rgb(cr, dim, dim, dim); |
| 346 | cairo_stroke(cr); |
| 347 | rounded_rect(cr, x + 2, y + 2, x + width, y + height, radius); |
| 348 | cairo_set_source_rgb(cr, 0.1, 0.1, 0.1); |
| 349 | cairo_stroke(cr); |
| 350 | |
| 351 | rounded_rect(cr, x + 1, y + 1, x + width - 1, y + height - 1, radius - 1); |
| 352 | cairo_set_source_rgb(cr, bright, bright, bright); |
| 353 | cairo_stroke(cr); |
| 354 | rounded_rect(cr, x + 3, y + 3, x + width - 1, y + height - 1, radius - 1); |
| 355 | cairo_set_source_rgb(cr, dim, dim, dim); |
| 356 | cairo_stroke(cr); |
| 357 | |
| 358 | rounded_rect(cr, x + 1, y + 1, x + width - 1, y + height - 1, radius - 1); |
| 359 | gradient = cairo_pattern_create_linear (0, y, 0, y + height); |
| 360 | cairo_pattern_add_color_stop_rgb(gradient, 0, 0.15, 0.15, 0.15); |
| 361 | cairo_pattern_add_color_stop_rgb(gradient, 0.5, 0.08, 0.08, 0.08); |
| 362 | cairo_pattern_add_color_stop_rgb(gradient, 0.5, 0.07, 0.07, 0.07); |
| 363 | cairo_pattern_add_color_stop_rgb(gradient, 1, 0.1, 0.1, 0.1); |
| 364 | cairo_set_source(cr, gradient); |
| 365 | cairo_fill(cr); |
| 366 | |
| 367 | cairo_set_font_size(cr, 16); |
| 368 | cairo_text_extents(cr, text, &extents); |
| 369 | cairo_move_to(cr, x + (width - extents.width) / 2, y + (height - extents.height) / 2 - extents.y_bearing); |
| 370 | cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
| 371 | cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); |
| 372 | cairo_set_line_width (cr, 4); |
| 373 | cairo_text_path(cr, text); |
| 374 | cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
| 375 | cairo_stroke_preserve(cr); |
| 376 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 377 | cairo_fill(cr); |
| 378 | } |
| 379 | |
| 380 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 381 | overlay_create(struct egl_compositor *ec, int x, int y, int width, int height) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 382 | { |
| 383 | struct egl_surface *es; |
| 384 | cairo_surface_t *surface; |
| 385 | cairo_t *cr; |
| 386 | int total_width, button_x, button_y; |
| 387 | const int button_width = 150; |
| 388 | const int button_height = 40; |
| 389 | const int spacing = 50; |
| 390 | |
| 391 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 392 | width, height); |
| 393 | |
| 394 | cr = cairo_create(surface); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 395 | cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 0.8); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 396 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 397 | cairo_paint(cr); |
| 398 | |
| 399 | total_width = button_width * 2 + spacing; |
| 400 | button_x = (width - total_width) / 2; |
| 401 | button_y = height - button_height - 20; |
| 402 | draw_button(cr, button_x, button_y, button_width, button_height, "Previous"); |
| 403 | button_x += button_width + spacing; |
| 404 | draw_button(cr, button_x, button_y, button_width, button_height, "Next"); |
| 405 | |
| 406 | cairo_destroy(cr); |
| 407 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 408 | es = egl_surface_create_from_cairo_surface(ec, surface, |
| 409 | x, y, width, height); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 410 | |
| 411 | cairo_surface_destroy(surface); |
| 412 | |
| 413 | return es; |
| 414 | } |
| 415 | |
| 416 | static void |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 417 | draw_surface(struct egl_surface *es) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 418 | { |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 419 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 420 | GLint vertices[12]; |
| 421 | GLint tex_coords[12] = { 0, 0, 0, 1, 1, 0, 1, 1 }; |
| 422 | GLuint indices[4] = { 0, 1, 2, 3 }; |
| 423 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 424 | vertices[0] = es->map.x; |
| 425 | vertices[1] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 426 | vertices[2] = 0; |
| 427 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 428 | vertices[3] = es->map.x; |
| 429 | vertices[4] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 430 | vertices[5] = 0; |
| 431 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 432 | vertices[6] = es->map.x + es->map.width; |
| 433 | vertices[7] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 434 | vertices[8] = 0; |
| 435 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 436 | vertices[9] = es->map.x + es->map.width; |
| 437 | vertices[10] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 438 | vertices[11] = 0; |
| 439 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 440 | if (es->visual == &ec->argb_visual) { |
| 441 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 442 | glEnable(GL_BLEND); |
| 443 | } else if (es->visual == &ec->premultiplied_argb_visual) { |
| 444 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 445 | glEnable(GL_BLEND); |
| 446 | } else { |
| 447 | glDisable(GL_BLEND); |
| 448 | } |
| 449 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 450 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 451 | glEnable(GL_TEXTURE_2D); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 452 | glEnableClientState(GL_VERTEX_ARRAY); |
| 453 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 454 | glVertexPointer(3, GL_INT, 0, vertices); |
| 455 | glTexCoordPointer(2, GL_INT, 0, tex_coords); |
| 456 | glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices); |
| 457 | } |
| 458 | |
| 459 | static void |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 460 | schedule_repaint(struct egl_compositor *ec); |
| 461 | |
| 462 | static void |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 463 | animate_overlay(struct egl_compositor *ec) |
| 464 | { |
| 465 | double force, y; |
| 466 | int32_t top, bottom; |
Kristian Høgsberg | ffb7406 | 2008-11-25 18:10:39 -0500 | [diff] [blame] | 467 | #if 1 |
| 468 | double bounce = 0.0; |
| 469 | double friction = 1.0; |
| 470 | double spring = 0.2; |
| 471 | #else |
| 472 | double bounce = 0.2; |
| 473 | double friction = 0.04; |
| 474 | double spring = 0.09; |
| 475 | #endif |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 476 | |
| 477 | y = ec->overlay_y; |
Kristian Høgsberg | ffb7406 | 2008-11-25 18:10:39 -0500 | [diff] [blame] | 478 | force = (ec->overlay_target - ec->overlay_y) * spring + |
| 479 | (ec->overlay_previous - y) * friction; |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 480 | |
| 481 | ec->overlay_y = y + (y - ec->overlay_previous) + force; |
| 482 | ec->overlay_previous = y; |
| 483 | |
| 484 | top = ec->height - ec->overlay->map.height; |
| 485 | bottom = ec->height; |
| 486 | if (ec->overlay_y >= bottom) { |
| 487 | ec->overlay_y = bottom; |
| 488 | ec->overlay_previous = bottom; |
| 489 | } |
| 490 | |
| 491 | if (ec->overlay_y <= top) { |
Kristian Høgsberg | ffb7406 | 2008-11-25 18:10:39 -0500 | [diff] [blame] | 492 | ec->overlay_y = top + bounce * (top - ec->overlay_y); |
| 493 | ec->overlay_previous = |
| 494 | top + bounce * (top - ec->overlay_previous); |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | ec->overlay->map.y = ec->overlay_y + 0.5; |
Kristian Høgsberg | ffb7406 | 2008-11-25 18:10:39 -0500 | [diff] [blame] | 498 | |
Kristian Høgsberg | 73c3058 | 2008-11-25 22:45:46 -0500 | [diff] [blame] | 499 | if (fabs(y - ec->overlay_target) > 0.2 || |
| 500 | fabs(ec->overlay_y - ec->overlay_target) > 0.2) |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 501 | schedule_repaint(ec); |
| 502 | } |
| 503 | |
| 504 | static void |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 505 | repaint(void *data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 506 | { |
| 507 | struct egl_compositor *ec = data; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 508 | struct egl_surface *es; |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 509 | struct wlsc_input_device *eid; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 510 | struct timespec ts; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 511 | uint32_t msecs; |
| 512 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 513 | if (!ec->repaint_needed) { |
| 514 | ec->repaint_on_timeout = 0; |
| 515 | return; |
| 516 | } |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 517 | |
Kristian Høgsberg | 5b7f832 | 2008-12-18 12:08:19 -0500 | [diff] [blame] | 518 | if (ec->background) |
| 519 | draw_surface(ec->background); |
| 520 | else |
| 521 | glClear(GL_COLOR_BUFFER_BIT); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 522 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 523 | es = container_of(ec->surface_list.next, |
| 524 | struct egl_surface, link); |
| 525 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 526 | draw_surface(es); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 527 | |
| 528 | es = container_of(es->link.next, |
| 529 | struct egl_surface, link); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 530 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 531 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 532 | draw_surface(ec->overlay); |
| 533 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 534 | eid = container_of(ec->input_device_list.next, |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 535 | struct wlsc_input_device, link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 536 | while (&eid->link != &ec->input_device_list) { |
| 537 | draw_surface(eid->pointer_surface); |
| 538 | |
| 539 | eid = container_of(eid->link.next, |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 540 | struct wlsc_input_device, link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 541 | } |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 542 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 543 | eglSwapBuffers(ec->display, ec->surface); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 544 | ec->repaint_needed = 0; |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 545 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 546 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 547 | msecs = ts.tv_sec * 1000 + ts.tv_nsec / (1000 * 1000); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 548 | wl_display_post_frame(ec->wl_display, &ec->base, |
| 549 | ec->current_frame, msecs); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 550 | ec->current_frame++; |
| 551 | |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 552 | wl_event_source_timer_update(ec->timer_source, 10); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 553 | ec->repaint_on_timeout = 1; |
Kristian Høgsberg | 44f36e3 | 2008-11-26 12:57:31 -0500 | [diff] [blame] | 554 | |
Kristian Høgsberg | 5c1e6ec | 2008-11-25 13:51:36 -0500 | [diff] [blame] | 555 | animate_overlay(ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 556 | } |
| 557 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 558 | static void |
| 559 | schedule_repaint(struct egl_compositor *ec) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 560 | { |
| 561 | struct wl_event_loop *loop; |
| 562 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 563 | ec->repaint_needed = 1; |
| 564 | if (!ec->repaint_on_timeout) { |
| 565 | loop = wl_display_get_event_loop(ec->wl_display); |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 566 | wl_event_loop_add_idle(loop, repaint, ec); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 567 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 568 | } |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 569 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 570 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 571 | surface_destroy(struct wl_client *client, |
| 572 | struct wl_surface *surface) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 573 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 574 | struct egl_surface *es = (struct egl_surface *) surface; |
| 575 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 576 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 577 | wl_list_remove(&es->link); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 578 | egl_surface_destroy(es, ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 579 | |
| 580 | schedule_repaint(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 581 | } |
| 582 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 583 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 584 | surface_attach(struct wl_client *client, |
| 585 | struct wl_surface *surface, uint32_t name, |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 586 | uint32_t width, uint32_t height, uint32_t stride, |
| 587 | struct wl_object *visual) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 588 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 589 | struct egl_surface *es = (struct egl_surface *) surface; |
| 590 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 591 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 592 | if (es->surface != EGL_NO_SURFACE) |
| 593 | eglDestroySurface(ec->display, es->surface); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 594 | |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 595 | es->width = width; |
| 596 | es->height = height; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 597 | es->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 598 | name, width, height, stride, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 599 | if (visual == &ec->argb_visual.base) |
| 600 | es->visual = &ec->argb_visual; |
| 601 | else if (visual == &ec->premultiplied_argb_visual.base) |
| 602 | es->visual = &ec->premultiplied_argb_visual; |
Kristian Høgsberg | e10b828 | 2008-12-18 19:58:44 -0500 | [diff] [blame] | 603 | else if (visual == &ec->rgb_visual.base) |
| 604 | es->visual = &ec->rgb_visual; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 605 | else |
| 606 | /* FIXME: Smack client with an exception event */; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 607 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 608 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 609 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 610 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 611 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 612 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 613 | eglBindTexImage(ec->display, es->surface, GL_TEXTURE_2D); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 616 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 617 | surface_map(struct wl_client *client, |
| 618 | struct wl_surface *surface, |
| 619 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 620 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 621 | struct egl_surface *es = (struct egl_surface *) surface; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 622 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 623 | es->map.x = x; |
| 624 | es->map.y = y; |
| 625 | es->map.width = width; |
| 626 | es->map.height = height; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 629 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 630 | surface_copy(struct wl_client *client, |
| 631 | struct wl_surface *surface, |
| 632 | int32_t dst_x, int32_t dst_y, |
| 633 | uint32_t name, uint32_t stride, |
| 634 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 635 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 636 | struct egl_surface *es = (struct egl_surface *) surface; |
| 637 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 638 | EGLSurface src; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 639 | |
| 640 | /* FIXME: glCopyPixels should work, but then we'll have to |
| 641 | * call eglMakeCurrent to set up the src and dest surfaces |
| 642 | * first. This seems cheaper, but maybe there's a better way |
| 643 | * to accomplish this. */ |
| 644 | |
| 645 | src = eglCreateSurfaceForName(ec->display, ec->config, |
| 646 | name, x + width, y + height, stride, NULL); |
| 647 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 648 | eglCopyNativeBuffers(ec->display, es->surface, GL_FRONT_LEFT, dst_x, dst_y, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 649 | src, GL_FRONT_LEFT, x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 650 | eglDestroySurface(ec->display, src); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 654 | surface_damage(struct wl_client *client, |
| 655 | struct wl_surface *surface, |
| 656 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 657 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 658 | /* FIXME: This need to take a damage region, of course. */ |
| 659 | } |
| 660 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 661 | const static struct wl_surface_interface surface_interface = { |
| 662 | surface_destroy, |
| 663 | surface_attach, |
| 664 | surface_map, |
| 665 | surface_copy, |
| 666 | surface_damage |
| 667 | }; |
| 668 | |
| 669 | static void |
| 670 | compositor_create_surface(struct wl_client *client, |
| 671 | struct wl_compositor *compositor, uint32_t id) |
| 672 | { |
| 673 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 674 | struct egl_surface *es; |
| 675 | |
| 676 | es = malloc(sizeof *es); |
| 677 | if (es == NULL) |
| 678 | /* FIXME: Send OOM event. */ |
| 679 | return; |
| 680 | |
| 681 | es->compositor = ec; |
| 682 | es->surface = EGL_NO_SURFACE; |
| 683 | wl_list_insert(ec->surface_list.prev, &es->link); |
| 684 | glGenTextures(1, &es->texture); |
| 685 | wl_client_add_surface(client, &es->base, |
| 686 | &surface_interface, id); |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | compositor_commit(struct wl_client *client, |
| 691 | struct wl_compositor *compositor, uint32_t key) |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 692 | { |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 693 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 694 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 695 | schedule_repaint(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 696 | wl_client_send_acknowledge(client, compositor, key, ec->current_frame); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 697 | } |
| 698 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 699 | const static struct wl_compositor_interface compositor_interface = { |
| 700 | compositor_create_surface, |
| 701 | compositor_commit |
| 702 | }; |
| 703 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 704 | static struct egl_surface * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 705 | pick_surface(struct wlsc_input_device *device) |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 706 | { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 707 | struct egl_compositor *ec = device->ec; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 708 | struct egl_surface *es; |
| 709 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 710 | if (device->grab > 0) |
| 711 | return device->grab_surface; |
| 712 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 713 | es = container_of(ec->surface_list.prev, |
| 714 | struct egl_surface, link); |
| 715 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 716 | if (es->map.x <= device->x && |
| 717 | device->x < es->map.x + es->map.width && |
| 718 | es->map.y <= device->y && |
| 719 | device->y < es->map.y + es->map.height) |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 720 | return es; |
| 721 | |
| 722 | es = container_of(es->link.prev, |
| 723 | struct egl_surface, link); |
| 724 | } |
| 725 | |
| 726 | return NULL; |
| 727 | } |
| 728 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 729 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 730 | notify_motion(struct wlsc_input_device *device, int x, int y) |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 731 | { |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 732 | struct egl_surface *es; |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 733 | struct egl_compositor *ec = device->ec; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 734 | const int hotspot_x = 16, hotspot_y = 16; |
| 735 | int32_t sx, sy; |
| 736 | |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 737 | if (x < 0) |
| 738 | x = 0; |
| 739 | if (y < 0) |
| 740 | y = 0; |
| 741 | if (x >= ec->width) |
| 742 | x = ec->width - 1; |
| 743 | if (y >= ec->height) |
| 744 | y = ec->height - 1; |
| 745 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 746 | es = pick_surface(device); |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 747 | |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 748 | if (es) { |
| 749 | sx = (x - es->map.x) * es->width / es->map.width; |
| 750 | sy = (y - es->map.y) * es->height / es->map.height; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 751 | wl_surface_post_event(&es->base, &device->base, |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 752 | WL_INPUT_MOTION, x, y, sx, sy); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 753 | } |
| 754 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 755 | device->x = x; |
| 756 | device->y = y; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 757 | device->pointer_surface->map.x = x - hotspot_x; |
| 758 | device->pointer_surface->map.y = y - hotspot_y; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 759 | |
| 760 | schedule_repaint(device->ec); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 761 | } |
| 762 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 763 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 764 | notify_button(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 765 | int32_t button, int32_t state) |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 766 | { |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 767 | struct egl_surface *es; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 768 | int32_t sx, sy; |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 769 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 770 | es = pick_surface(device); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 771 | if (es) { |
| 772 | wl_list_remove(&es->link); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 773 | wl_list_insert(device->ec->surface_list.prev, &es->link); |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 774 | |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 775 | if (state) { |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 776 | /* FIXME: We need callbacks when the surfaces |
| 777 | * we reference here go away. */ |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 778 | device->grab++; |
| 779 | device->grab_surface = es; |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 780 | device->focus_surface = es; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 781 | } else { |
| 782 | device->grab--; |
| 783 | } |
| 784 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 785 | sx = (device->x - es->map.x) * es->width / es->map.width; |
| 786 | sy = (device->y - es->map.y) * es->height / es->map.height; |
| 787 | |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 788 | /* FIXME: Swallow click on raise? */ |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 789 | wl_surface_post_event(&es->base, &device->base, |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 790 | WL_INPUT_BUTTON, button, state, |
| 791 | device->x, device->y, sx, sy); |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 792 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 793 | schedule_repaint(device->ec); |
| 794 | } |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 795 | } |
| 796 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 797 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 798 | notify_key(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 799 | uint32_t key, uint32_t state) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 800 | { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 801 | struct egl_compositor *ec = device->ec; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 802 | |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 803 | if (key == KEY_ESC && state == 1) { |
| 804 | if (ec->overlay_target == ec->height) |
| 805 | ec->overlay_target -= 200; |
| 806 | else |
| 807 | ec->overlay_target += 200; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 808 | schedule_repaint(ec); |
Kristian Høgsberg | 7fdff04 | 2008-12-10 13:25:00 -0500 | [diff] [blame] | 809 | } else if (!wl_list_empty(&ec->surface_list)) { |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 810 | if (device->focus_surface != NULL) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 811 | wl_surface_post_event(&device->focus_surface->base, |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 812 | &device->base, |
| 813 | WL_INPUT_KEY, key, state); |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 814 | } |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 817 | struct evdev_input_device * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 818 | evdev_input_device_create(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 819 | struct wl_display *display, const char *path); |
| 820 | |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 821 | static void |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 822 | create_input_device(struct egl_compositor *ec, const char *glob) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 823 | { |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 824 | struct wlsc_input_device *device; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 825 | struct dirent *de; |
| 826 | char path[PATH_MAX]; |
| 827 | const char *by_path_dir = "/dev/input/by-path"; |
| 828 | DIR *dir; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 829 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 830 | device = malloc(sizeof *device); |
| 831 | if (device == NULL) |
| 832 | return; |
| 833 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 834 | memset(device, 0, sizeof *device); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 835 | device->base.interface = wl_input_device_get_interface(); |
| 836 | wl_display_add_object(ec->wl_display, &device->base); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 837 | device->x = 100; |
| 838 | device->y = 100; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 839 | device->pointer_surface = pointer_create(ec, |
| 840 | device->x, device->y, 64, 64); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 841 | device->ec = ec; |
| 842 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 843 | dir = opendir(by_path_dir); |
| 844 | if (dir == NULL) { |
| 845 | fprintf(stderr, "couldn't read dir %s\n", by_path_dir); |
| 846 | return; |
| 847 | } |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 848 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 849 | while (de = readdir(dir), de != NULL) { |
| 850 | if (fnmatch(glob, de->d_name, 0)) |
| 851 | continue; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 852 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 853 | snprintf(path, sizeof path, "%s/%s", by_path_dir, de->d_name); |
| 854 | evdev_input_device_create(device, ec->wl_display, path); |
| 855 | } |
| 856 | closedir(dir); |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 857 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 858 | wl_list_insert(ec->input_device_list.prev, &device->link); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame^] | 862 | wlsc_device_get_position(struct wlsc_input_device *device, int32_t *x, int32_t *y) |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 863 | { |
| 864 | *x = device->x; |
| 865 | *y = device->y; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 866 | } |
| 867 | |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 868 | static uint32_t |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 869 | create_frontbuffer(struct egl_compositor *ec) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 870 | { |
| 871 | drmModeConnector *connector; |
| 872 | drmModeRes *resources; |
| 873 | drmModeEncoder *encoder; |
| 874 | struct drm_mode_modeinfo *mode; |
| 875 | struct drm_i915_gem_create create; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 876 | struct drm_gem_flink flink; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 877 | int i, ret, fd; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 878 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 879 | fd = eglGetDisplayFD(ec->display); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 880 | resources = drmModeGetResources(fd); |
| 881 | if (!resources) { |
| 882 | fprintf(stderr, "drmModeGetResources failed\n"); |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | for (i = 0; i < resources->count_connectors; i++) { |
| 887 | connector = drmModeGetConnector(fd, resources->connectors[i]); |
| 888 | if (connector == NULL) |
| 889 | continue; |
| 890 | |
| 891 | if (connector->connection == DRM_MODE_CONNECTED && |
| 892 | connector->count_modes > 0) |
| 893 | break; |
| 894 | |
| 895 | drmModeFreeConnector(connector); |
| 896 | } |
| 897 | |
| 898 | if (i == resources->count_connectors) { |
| 899 | fprintf(stderr, "No currently active connector found.\n"); |
| 900 | return -1; |
| 901 | } |
| 902 | |
| 903 | mode = &connector->modes[0]; |
| 904 | |
| 905 | for (i = 0; i < resources->count_encoders; i++) { |
| 906 | encoder = drmModeGetEncoder(fd, resources->encoders[i]); |
| 907 | |
| 908 | if (encoder == NULL) |
| 909 | continue; |
| 910 | |
| 911 | if (encoder->encoder_id == connector->encoder_id) |
| 912 | break; |
| 913 | |
| 914 | drmModeFreeEncoder(encoder); |
| 915 | } |
| 916 | |
| 917 | /* Mode size at 32 bpp */ |
| 918 | create.size = mode->hdisplay * mode->vdisplay * 4; |
| 919 | if (ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { |
| 920 | fprintf(stderr, "gem create failed: %m\n"); |
| 921 | return 0; |
| 922 | } |
| 923 | |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 924 | ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay, |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 925 | 32, 32, mode->hdisplay * 4, create.handle, &ec->fb_id); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 926 | if (ret) { |
| 927 | fprintf(stderr, "failed to add fb: %m\n"); |
| 928 | return 0; |
| 929 | } |
| 930 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 931 | ret = drmModeSetCrtc(fd, encoder->crtc_id, ec->fb_id, 0, 0, |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 932 | &connector->connector_id, 1, mode); |
| 933 | if (ret) { |
| 934 | fprintf(stderr, "failed to set mode: %m\n"); |
| 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | flink.handle = create.handle; |
| 939 | if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) != 0) { |
| 940 | fprintf(stderr, "gem flink failed: %m\n"); |
| 941 | return 0; |
| 942 | } |
| 943 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 944 | ec->crtc_id = encoder->crtc_id; |
| 945 | ec->connector_id = connector->connector_id; |
| 946 | ec->mode = mode; |
| 947 | ec->width = mode->hdisplay; |
| 948 | ec->height = mode->vdisplay; |
| 949 | ec->stride = mode->hdisplay * 4; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 950 | |
| 951 | return flink.name; |
| 952 | } |
| 953 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 954 | static const struct wl_interface visual_interface = { |
| 955 | "visual", 1, |
| 956 | }; |
| 957 | |
| 958 | static void |
| 959 | add_visuals(struct egl_compositor *ec) |
| 960 | { |
| 961 | ec->argb_visual.base.interface = &visual_interface; |
| 962 | ec->argb_visual.base.implementation = NULL; |
| 963 | wl_display_add_object(ec->wl_display, &ec->argb_visual.base); |
| 964 | wl_display_add_global(ec->wl_display, &ec->argb_visual.base); |
| 965 | |
| 966 | ec->premultiplied_argb_visual.base.interface = &visual_interface; |
| 967 | ec->premultiplied_argb_visual.base.implementation = NULL; |
| 968 | wl_display_add_object(ec->wl_display, |
| 969 | &ec->premultiplied_argb_visual.base); |
| 970 | wl_display_add_global(ec->wl_display, |
| 971 | &ec->premultiplied_argb_visual.base); |
| 972 | |
| 973 | ec->rgb_visual.base.interface = &visual_interface; |
| 974 | ec->rgb_visual.base.implementation = NULL; |
| 975 | wl_display_add_object(ec->wl_display, &ec->rgb_visual.base); |
| 976 | wl_display_add_global(ec->wl_display, &ec->rgb_visual.base); |
| 977 | } |
| 978 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 979 | static const char gem_device[] = "/dev/dri/card0"; |
| 980 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 981 | static const char *macbook_air_default_input_device[] = { |
Kristian Høgsberg | 6494997 | 2008-12-12 14:48:46 -0500 | [diff] [blame] | 982 | "pci-0000:00:1d.2-usb-0:2:1*event*", |
| 983 | NULL |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 984 | }; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 985 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 986 | static const char *option_background = "background.jpg"; |
| 987 | static const char **option_input_devices = macbook_air_default_input_device; |
| 988 | |
| 989 | static const GOptionEntry option_entries[] = { |
| 990 | { "background", 'b', 0, G_OPTION_ARG_STRING, |
| 991 | &option_background, "Background image" }, |
| 992 | { "input-device", 'i', 0, G_OPTION_ARG_STRING_ARRAY, |
| 993 | &option_input_devices, "Input device glob" }, |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 994 | { NULL } |
| 995 | }; |
| 996 | |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 997 | static void on_enter_vt(int signal_number, void *data) |
| 998 | { |
| 999 | struct egl_compositor *ec = data; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1000 | int ret, fd; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1001 | |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 1002 | ioctl(ec->tty_fd, VT_RELDISP, VT_ACKACQ); |
| 1003 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1004 | fd = eglGetDisplayFD(ec->display); |
| 1005 | ret = drmModeSetCrtc(fd, ec->crtc_id, ec->fb_id, 0, 0, |
| 1006 | &ec->connector_id, 1, ec->mode); |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1007 | if (ret) { |
| 1008 | fprintf(stderr, "failed to set mode: %m\n"); |
| 1009 | return; |
| 1010 | } |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static void on_leave_vt(int signal_number, void *data) |
| 1014 | { |
| 1015 | struct egl_compositor *ec = data; |
| 1016 | |
| 1017 | ioctl (ec->tty_fd, VT_RELDISP, 1); |
| 1018 | } |
| 1019 | |
| 1020 | static void watch_for_vt_changes(struct egl_compositor *ec, struct wl_event_loop *loop) |
| 1021 | { |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1022 | struct vt_mode mode = { 0 }; |
| 1023 | |
| 1024 | ec->tty_fd = open("/dev/tty0", O_RDWR | O_NOCTTY); |
| 1025 | mode.mode = VT_PROCESS; |
| 1026 | mode.relsig = SIGUSR1; |
| 1027 | mode.acqsig = SIGUSR2; |
| 1028 | |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 1029 | if (!ioctl (ec->tty_fd, VT_SETMODE, &mode) < 0) { |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1030 | fprintf(stderr, "failed to take control of vt handling\n"); |
| 1031 | } |
| 1032 | |
| 1033 | ec->leave_vt_source = wl_event_loop_add_signal (loop, SIGUSR1, |
| 1034 | on_leave_vt, |
| 1035 | ec); |
| 1036 | ec->enter_vt_source = wl_event_loop_add_signal (loop, SIGUSR2, |
| 1037 | on_enter_vt, |
| 1038 | ec); |
| 1039 | } |
| 1040 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1041 | static struct egl_compositor * |
| 1042 | egl_compositor_create(struct wl_display *display) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1043 | { |
Kristian Høgsberg | 15d0f8b | 2008-12-19 12:13:42 -0500 | [diff] [blame] | 1044 | static const EGLint config_attribs[] = { |
| 1045 | EGL_DEPTH_SIZE, 0, |
| 1046 | EGL_STENCIL_SIZE, 0, |
| 1047 | EGL_CONFIG_CAVEAT, EGL_NONE, |
| 1048 | EGL_NONE |
| 1049 | }; |
| 1050 | |
| 1051 | const static EGLint attribs[] = { |
| 1052 | EGL_RENDER_BUFFER, EGL_BACK_BUFFER, |
| 1053 | EGL_NONE |
| 1054 | }; |
| 1055 | |
Kristian Høgsberg | 443853c | 2008-11-25 12:12:05 -0500 | [diff] [blame] | 1056 | EGLint major, minor; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1057 | struct egl_compositor *ec; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1058 | struct screenshooter *shooter; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1059 | uint32_t fb_name; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1060 | int i; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1061 | struct wl_event_loop *loop; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1062 | |
| 1063 | ec = malloc(sizeof *ec); |
| 1064 | if (ec == NULL) |
| 1065 | return NULL; |
| 1066 | |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1067 | ec->wl_display = display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1068 | |
Kristian Høgsberg | c508d93 | 2008-10-13 22:52:42 -0400 | [diff] [blame] | 1069 | ec->display = eglCreateDisplayNative(gem_device, "i965"); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1070 | if (ec->display == NULL) { |
| 1071 | fprintf(stderr, "failed to create display\n"); |
| 1072 | return NULL; |
| 1073 | } |
| 1074 | |
| 1075 | if (!eglInitialize(ec->display, &major, &minor)) { |
| 1076 | fprintf(stderr, "failed to initialize display\n"); |
| 1077 | return NULL; |
| 1078 | } |
| 1079 | |
Kristian Høgsberg | 15d0f8b | 2008-12-19 12:13:42 -0500 | [diff] [blame] | 1080 | if (!eglChooseConfig(ec->display, config_attribs, &ec->config, 1, NULL)) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1081 | return NULL; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1082 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1083 | fb_name = create_frontbuffer(ec); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1084 | ec->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1085 | fb_name, ec->width, ec->height, ec->stride, attribs); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1086 | if (ec->surface == NULL) { |
| 1087 | fprintf(stderr, "failed to create surface\n"); |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 1091 | ec->context = eglCreateContext(ec->display, ec->config, NULL, NULL); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1092 | if (ec->context == NULL) { |
| 1093 | fprintf(stderr, "failed to create context\n"); |
| 1094 | return NULL; |
| 1095 | } |
| 1096 | |
| 1097 | if (!eglMakeCurrent(ec->display, ec->surface, ec->surface, ec->context)) { |
| 1098 | fprintf(stderr, "failed to make context current\n"); |
| 1099 | return NULL; |
| 1100 | } |
| 1101 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1102 | glViewport(0, 0, ec->width, ec->height); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1103 | glMatrixMode(GL_PROJECTION); |
| 1104 | glLoadIdentity(); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1105 | glOrtho(0, ec->width, ec->height, 0, 0, 1000.0); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1106 | glMatrixMode(GL_MODELVIEW); |
Kristian Høgsberg | 5b7f832 | 2008-12-18 12:08:19 -0500 | [diff] [blame] | 1107 | glClearColor(0, 0, 0.2, 1); |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1108 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1109 | wl_display_set_compositor(display, &ec->base, &compositor_interface); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1110 | add_visuals(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1111 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1112 | wl_list_init(&ec->input_device_list); |
| 1113 | for (i = 0; option_input_devices[i]; i++) |
| 1114 | create_input_device(ec, option_input_devices[i]); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1115 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1116 | wl_list_init(&ec->surface_list); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1117 | ec->background = background_create(ec, option_background, |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 1118 | ec->width, ec->height); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1119 | ec->overlay = overlay_create(ec, 0, ec->height, ec->width, 200); |
Kristian Høgsberg | 9f88b18 | 2008-12-08 13:52:08 -0500 | [diff] [blame] | 1120 | ec->overlay_y = ec->height; |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 1121 | ec->overlay_target = ec->height; |
| 1122 | ec->overlay_previous = ec->height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 1123 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1124 | shooter = screenshooter_create(ec); |
| 1125 | wl_display_add_object(display, &shooter->base); |
| 1126 | wl_display_add_global(display, &shooter->base); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1127 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1128 | loop = wl_display_get_event_loop(ec->wl_display); |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1129 | watch_for_vt_changes (ec, loop); |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 1130 | ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1131 | ec->repaint_needed = 0; |
| 1132 | ec->repaint_on_timeout = 0; |
| 1133 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1134 | schedule_repaint(ec); |
| 1135 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1136 | return ec; |
| 1137 | } |
| 1138 | |
| 1139 | /* The plan here is to generate a random anonymous socket name and |
| 1140 | * advertise that through a service on the session dbus. |
| 1141 | */ |
| 1142 | static const char socket_name[] = "\0wayland"; |
| 1143 | |
| 1144 | int main(int argc, char *argv[]) |
| 1145 | { |
| 1146 | struct wl_display *display; |
| 1147 | struct egl_compositor *ec; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 1148 | GError *error = NULL; |
| 1149 | GOptionContext *context; |
| 1150 | |
| 1151 | context = g_option_context_new(NULL); |
| 1152 | g_option_context_add_main_entries(context, option_entries, "Wayland"); |
| 1153 | if (!g_option_context_parse(context, &argc, &argv, &error)) { |
| 1154 | fprintf(stderr, "option parsing failed: %s\n", error->message); |
| 1155 | exit(EXIT_FAILURE); |
| 1156 | } |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1157 | |
| 1158 | display = wl_display_create(); |
| 1159 | |
| 1160 | ec = egl_compositor_create(display); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 1161 | if (ec == NULL) { |
| 1162 | fprintf(stderr, "failed to create compositor\n"); |
| 1163 | exit(EXIT_FAILURE); |
| 1164 | } |
| 1165 | |
Kristian Høgsberg | dc0f355 | 2008-12-07 15:22:22 -0500 | [diff] [blame] | 1166 | if (wl_display_add_socket(display, socket_name, sizeof socket_name)) { |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1167 | fprintf(stderr, "failed to add socket: %m\n"); |
| 1168 | exit(EXIT_FAILURE); |
| 1169 | } |
| 1170 | |
| 1171 | wl_display_run(display); |
| 1172 | |
| 1173 | return 0; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1174 | } |