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