Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdint.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 5 | #include <stdarg.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 6 | #include <i915_drm.h> |
| 7 | #include <sys/ioctl.h> |
| 8 | #include <sys/mman.h> |
| 9 | #include <fcntl.h> |
| 10 | #include <unistd.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 11 | #include <signal.h> |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 12 | #include <cairo.h> |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 13 | #include <gdk-pixbuf/gdk-pixbuf.h> |
| 14 | #include <glib.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 15 | #include <png.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 16 | #include <math.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 17 | |
| 18 | #include "wayland.h" |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 19 | #include "cairo-util.h" |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 20 | |
| 21 | #include <GL/gl.h> |
| 22 | #include <eagle.h> |
| 23 | |
| 24 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
| 25 | |
| 26 | struct egl_compositor { |
| 27 | struct wl_compositor base; |
| 28 | EGLDisplay display; |
| 29 | EGLSurface surface; |
| 30 | EGLContext context; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 31 | EGLConfig config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 32 | struct wl_display *wl_display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 33 | int gem_fd; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 34 | int width, height; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 35 | struct egl_surface *pointer; |
| 36 | struct egl_surface *background; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 37 | struct egl_surface *overlay; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 38 | }; |
| 39 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 40 | struct egl_surface { |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 41 | GLuint texture; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 42 | struct wl_map map; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 43 | EGLSurface surface; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 44 | }; |
| 45 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 46 | static int do_screenshot; |
| 47 | |
| 48 | static void |
| 49 | handle_sigusr1(int s) |
| 50 | { |
| 51 | do_screenshot = 1; |
| 52 | } |
| 53 | |
| 54 | static void |
| 55 | die(const char *msg, ...) |
| 56 | { |
| 57 | va_list ap; |
| 58 | |
| 59 | va_start (ap, msg); |
| 60 | vfprintf(stderr, msg, ap); |
| 61 | va_end (ap); |
| 62 | |
| 63 | exit(EXIT_FAILURE); |
| 64 | } |
| 65 | |
| 66 | static void |
| 67 | stdio_write_func (png_structp png, png_bytep data, png_size_t size) |
| 68 | { |
| 69 | FILE *fp; |
| 70 | size_t ret; |
| 71 | |
| 72 | fp = png_get_io_ptr (png); |
| 73 | while (size) { |
| 74 | ret = fwrite (data, 1, size, fp); |
| 75 | size -= ret; |
| 76 | data += ret; |
| 77 | if (size && ferror (fp)) |
| 78 | die("write: %m\n"); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void |
| 83 | png_simple_output_flush_fn (png_structp png_ptr) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | static void |
| 88 | png_simple_error_callback (png_structp png, |
| 89 | png_const_charp error_msg) |
| 90 | { |
| 91 | die("png error: %s\n", error_msg); |
| 92 | } |
| 93 | |
| 94 | static void |
| 95 | png_simple_warning_callback (png_structp png, |
| 96 | png_const_charp error_msg) |
| 97 | { |
| 98 | fprintf(stderr, "png warning: %s\n", error_msg); |
| 99 | } |
| 100 | |
| 101 | static void |
| 102 | convert_pixels(png_structp png, png_row_infop row_info, png_bytep data) |
| 103 | { |
| 104 | unsigned int i; |
| 105 | |
| 106 | for (i = 0; i < row_info->rowbytes; i += 4) { |
| 107 | uint8_t *b = &data[i]; |
| 108 | uint32_t pixel; |
| 109 | |
| 110 | memcpy (&pixel, b, sizeof (uint32_t)); |
| 111 | b[0] = (pixel & 0xff0000) >> 16; |
| 112 | b[1] = (pixel & 0x00ff00) >> 8; |
| 113 | b[2] = (pixel & 0x0000ff) >> 0; |
| 114 | b[3] = 0; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | screenshot(struct egl_compositor *ec) |
| 120 | { |
| 121 | png_struct *png; |
| 122 | png_info *info; |
| 123 | png_byte **volatile rows = NULL; |
| 124 | png_color_16 white; |
| 125 | int depth, i; |
| 126 | FILE *fp; |
| 127 | uint8_t *data; |
| 128 | GLuint stride; |
| 129 | static const char filename[] = "wayland-screenshot.png"; |
| 130 | |
| 131 | data = eglReadBuffer(ec->display, ec->surface, GL_FRONT_LEFT, &stride); |
| 132 | if (data == NULL) |
| 133 | die("eglReadBuffer failed\n"); |
| 134 | rows = malloc(ec->height * sizeof rows[0]); |
| 135 | if (rows == NULL) |
| 136 | die("malloc failed\n"); |
| 137 | |
| 138 | for (i = 0; i < ec->height; i++) |
| 139 | rows[i] = (png_byte *) data + i * stride; |
| 140 | |
| 141 | png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, |
| 142 | png_simple_error_callback, |
| 143 | png_simple_warning_callback); |
| 144 | if (png == NULL) |
| 145 | die("png_create_write_struct failed\n"); |
| 146 | |
| 147 | info = png_create_info_struct(png); |
| 148 | if (info == NULL) |
| 149 | die("png_create_info_struct failed\n"); |
| 150 | |
| 151 | fp = fopen(filename, "w"); |
| 152 | if (fp == NULL) |
| 153 | die("fopen failed: %m\n"); |
| 154 | |
| 155 | png_set_write_fn(png, fp, stdio_write_func, png_simple_output_flush_fn); |
| 156 | |
| 157 | depth = 8; |
| 158 | png_set_IHDR(png, info, |
| 159 | ec->width, |
| 160 | ec->height, depth, |
| 161 | PNG_COLOR_TYPE_RGB, |
| 162 | PNG_INTERLACE_NONE, |
| 163 | PNG_COMPRESSION_TYPE_DEFAULT, |
| 164 | PNG_FILTER_TYPE_DEFAULT); |
| 165 | |
| 166 | white.gray = (1 << depth) - 1; |
| 167 | white.red = white.blue = white.green = white.gray; |
| 168 | png_set_bKGD(png, info, &white); |
| 169 | png_write_info (png, info); |
| 170 | png_set_write_user_transform_fn(png, convert_pixels); |
| 171 | |
| 172 | png_set_filler(png, 0, PNG_FILLER_AFTER); |
| 173 | png_write_image(png, rows); |
| 174 | png_write_end(png, info); |
| 175 | |
| 176 | png_destroy_write_struct(&png, &info); |
| 177 | fclose(fp); |
| 178 | free(rows); |
| 179 | free(data); |
| 180 | } |
| 181 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 182 | static struct egl_surface * |
| 183 | egl_surface_create_from_cairo_surface(cairo_surface_t *surface, |
| 184 | int x, int y, int width, int height) |
| 185 | { |
| 186 | struct egl_surface *es; |
| 187 | int stride; |
| 188 | void *data; |
| 189 | |
| 190 | stride = cairo_image_surface_get_stride(surface); |
| 191 | data = cairo_image_surface_get_data(surface); |
| 192 | |
| 193 | es = malloc(sizeof *es); |
| 194 | if (es == NULL) |
| 195 | return NULL; |
| 196 | |
| 197 | glGenTextures(1, &es->texture); |
| 198 | glBindTexture(GL_TEXTURE_2D, es->texture); |
| 199 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 200 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 201 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 202 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 203 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, |
| 204 | GL_BGRA, GL_UNSIGNED_BYTE, data); |
| 205 | |
| 206 | es->map.x = x; |
| 207 | es->map.y = y; |
| 208 | es->map.width = width; |
| 209 | es->map.height = height; |
| 210 | es->surface = EGL_NO_SURFACE; |
| 211 | |
| 212 | return es; |
| 213 | } |
| 214 | |
| 215 | static void |
| 216 | egl_surface_destroy(struct egl_surface *es, struct egl_compositor *ec) |
| 217 | { |
| 218 | glDeleteTextures(1, &es->texture); |
| 219 | if (es->surface != EGL_NO_SURFACE) |
| 220 | eglDestroySurface(ec->display, es->surface); |
| 221 | free(es); |
| 222 | } |
| 223 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 224 | static void |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 225 | pointer_path(cairo_t *cr, int x, int y) |
| 226 | { |
| 227 | const int end = 3, tx = 4, ty = 12, dx = 5, dy = 10; |
| 228 | const int width = 16, height = 16; |
| 229 | |
| 230 | cairo_move_to(cr, x, y); |
| 231 | cairo_line_to(cr, x + tx, y + ty); |
| 232 | cairo_line_to(cr, x + dx, y + dy); |
| 233 | cairo_line_to(cr, x + width - end, y + height); |
| 234 | cairo_line_to(cr, x + width, y + height - end); |
| 235 | cairo_line_to(cr, x + dy, y + dx); |
| 236 | cairo_line_to(cr, x + ty, y + tx); |
| 237 | cairo_close_path(cr); |
| 238 | } |
| 239 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 240 | static struct egl_surface * |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 241 | pointer_create(int x, int y, int width, int height) |
| 242 | { |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 243 | struct egl_surface *es; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 244 | const int hotspot_x = 16, hotspot_y = 16; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 245 | cairo_surface_t *surface; |
| 246 | cairo_t *cr; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 247 | |
| 248 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 249 | width, height); |
| 250 | |
| 251 | cr = cairo_create(surface); |
| 252 | pointer_path(cr, hotspot_x + 5, hotspot_y + 4); |
| 253 | cairo_set_line_width (cr, 2); |
| 254 | cairo_set_source_rgb(cr, 0, 0, 0); |
| 255 | cairo_stroke_preserve(cr); |
| 256 | cairo_fill(cr); |
| 257 | blur_surface(surface, width); |
| 258 | |
| 259 | pointer_path(cr, hotspot_x, hotspot_y); |
| 260 | cairo_stroke_preserve(cr); |
| 261 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 262 | cairo_fill(cr); |
| 263 | cairo_destroy(cr); |
| 264 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 265 | es = egl_surface_create_from_cairo_surface(surface, x, y, width, height); |
| 266 | |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 267 | cairo_surface_destroy(surface); |
| 268 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 269 | return es; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static struct egl_surface * |
| 273 | background_create(const char *filename, int width, int height) |
| 274 | { |
| 275 | struct egl_surface *background; |
| 276 | GdkPixbuf *pixbuf; |
| 277 | GError *error = NULL; |
| 278 | int pixbuf_width, pixbuf_height; |
| 279 | void *data; |
| 280 | |
| 281 | background = malloc(sizeof *background); |
| 282 | if (background == NULL) |
| 283 | return NULL; |
| 284 | |
| 285 | g_type_init(); |
| 286 | |
| 287 | pixbuf = gdk_pixbuf_new_from_file(filename, &error); |
| 288 | if (error != NULL) { |
| 289 | free(background); |
| 290 | return NULL; |
| 291 | } |
| 292 | |
| 293 | pixbuf_width = gdk_pixbuf_get_width(pixbuf); |
| 294 | pixbuf_height = gdk_pixbuf_get_height(pixbuf); |
| 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); |
| 300 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 301 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 302 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 303 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pixbuf_width, pixbuf_height, 0, |
| 304 | GL_BGR, GL_UNSIGNED_BYTE, data); |
| 305 | |
| 306 | background->map.x = 0; |
| 307 | background->map.y = 0; |
| 308 | background->map.width = width; |
| 309 | background->map.height = height; |
| 310 | background->surface = EGL_NO_SURFACE; |
| 311 | |
| 312 | return background; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static void |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 316 | rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius) |
| 317 | { |
| 318 | cairo_move_to(cr, x0, y0 + radius); |
| 319 | cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2); |
| 320 | cairo_line_to(cr, x1 - radius, y0); |
| 321 | cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI); |
| 322 | cairo_line_to(cr, x1, y1 - radius); |
| 323 | cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2); |
| 324 | cairo_line_to(cr, x0 + radius, y1); |
| 325 | cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI); |
| 326 | cairo_close_path(cr); |
| 327 | } |
| 328 | |
| 329 | static void |
| 330 | draw_button(cairo_t *cr, int x, int y, int width, int height, const char *text) |
| 331 | { |
| 332 | cairo_pattern_t *gradient; |
| 333 | cairo_text_extents_t extents; |
| 334 | double bright = 0.15, dim = 0.02; |
| 335 | int radius = 10; |
| 336 | |
| 337 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 338 | cairo_set_line_width (cr, 2); |
| 339 | rounded_rect(cr, x, y, x + width, y + height, radius); |
| 340 | cairo_set_source_rgb(cr, dim, dim, dim); |
| 341 | cairo_stroke(cr); |
| 342 | rounded_rect(cr, x + 2, y + 2, x + width, y + height, radius); |
| 343 | cairo_set_source_rgb(cr, 0.1, 0.1, 0.1); |
| 344 | cairo_stroke(cr); |
| 345 | |
| 346 | rounded_rect(cr, x + 1, y + 1, x + width - 1, y + height - 1, radius - 1); |
| 347 | cairo_set_source_rgb(cr, bright, bright, bright); |
| 348 | cairo_stroke(cr); |
| 349 | rounded_rect(cr, x + 3, y + 3, x + width - 1, y + height - 1, radius - 1); |
| 350 | cairo_set_source_rgb(cr, dim, dim, dim); |
| 351 | cairo_stroke(cr); |
| 352 | |
| 353 | rounded_rect(cr, x + 1, y + 1, x + width - 1, y + height - 1, radius - 1); |
| 354 | gradient = cairo_pattern_create_linear (0, y, 0, y + height); |
| 355 | cairo_pattern_add_color_stop_rgb(gradient, 0, 0.15, 0.15, 0.15); |
| 356 | cairo_pattern_add_color_stop_rgb(gradient, 0.5, 0.08, 0.08, 0.08); |
| 357 | cairo_pattern_add_color_stop_rgb(gradient, 0.5, 0.07, 0.07, 0.07); |
| 358 | cairo_pattern_add_color_stop_rgb(gradient, 1, 0.1, 0.1, 0.1); |
| 359 | cairo_set_source(cr, gradient); |
| 360 | cairo_fill(cr); |
| 361 | |
| 362 | cairo_set_font_size(cr, 16); |
| 363 | cairo_text_extents(cr, text, &extents); |
| 364 | cairo_move_to(cr, x + (width - extents.width) / 2, y + (height - extents.height) / 2 - extents.y_bearing); |
| 365 | cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
| 366 | cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); |
| 367 | cairo_set_line_width (cr, 4); |
| 368 | cairo_text_path(cr, text); |
| 369 | cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
| 370 | cairo_stroke_preserve(cr); |
| 371 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 372 | cairo_fill(cr); |
| 373 | } |
| 374 | |
| 375 | static struct egl_surface * |
| 376 | overlay_create(int x, int y, int width, int height) |
| 377 | { |
| 378 | struct egl_surface *es; |
| 379 | cairo_surface_t *surface; |
| 380 | cairo_t *cr; |
| 381 | int total_width, button_x, button_y; |
| 382 | const int button_width = 150; |
| 383 | const int button_height = 40; |
| 384 | const int spacing = 50; |
| 385 | |
| 386 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 387 | width, height); |
| 388 | |
| 389 | cr = cairo_create(surface); |
| 390 | cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 0.7); |
| 391 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 392 | cairo_paint(cr); |
| 393 | |
| 394 | total_width = button_width * 2 + spacing; |
| 395 | button_x = (width - total_width) / 2; |
| 396 | button_y = height - button_height - 20; |
| 397 | draw_button(cr, button_x, button_y, button_width, button_height, "Previous"); |
| 398 | button_x += button_width + spacing; |
| 399 | draw_button(cr, button_x, button_y, button_width, button_height, "Next"); |
| 400 | |
| 401 | cairo_destroy(cr); |
| 402 | |
| 403 | es = egl_surface_create_from_cairo_surface(surface, x, y, width, height); |
| 404 | |
| 405 | cairo_surface_destroy(surface); |
| 406 | |
| 407 | return es; |
| 408 | } |
| 409 | |
| 410 | static void |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 411 | draw_surface(struct egl_surface *es) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 412 | { |
| 413 | GLint vertices[12]; |
| 414 | GLint tex_coords[12] = { 0, 0, 0, 1, 1, 0, 1, 1 }; |
| 415 | GLuint indices[4] = { 0, 1, 2, 3 }; |
| 416 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 417 | vertices[0] = es->map.x; |
| 418 | vertices[1] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 419 | vertices[2] = 0; |
| 420 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 421 | vertices[3] = es->map.x; |
| 422 | vertices[4] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 423 | vertices[5] = 0; |
| 424 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 425 | vertices[6] = es->map.x + es->map.width; |
| 426 | vertices[7] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 427 | vertices[8] = 0; |
| 428 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 429 | vertices[9] = es->map.x + es->map.width; |
| 430 | vertices[10] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 431 | vertices[11] = 0; |
| 432 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 433 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 434 | glEnable(GL_TEXTURE_2D); |
| 435 | glEnable(GL_BLEND); |
| 436 | /* Assume pre-multiplied alpha for now, this probably |
| 437 | * needs to be a wayland visual type of thing. */ |
| 438 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 439 | |
| 440 | glEnableClientState(GL_VERTEX_ARRAY); |
| 441 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 442 | glVertexPointer(3, GL_INT, 0, vertices); |
| 443 | glTexCoordPointer(2, GL_INT, 0, tex_coords); |
| 444 | glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices); |
| 445 | } |
| 446 | |
| 447 | static void |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 448 | repaint(void *data) |
| 449 | { |
| 450 | struct egl_compositor *ec = data; |
| 451 | struct wl_surface_iterator *iterator; |
| 452 | struct wl_surface *surface; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 453 | struct egl_surface *es; |
| 454 | |
| 455 | draw_surface(ec->background); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 456 | |
| 457 | iterator = wl_surface_iterator_create(ec->wl_display, 0); |
| 458 | while (wl_surface_iterator_next(iterator, &surface)) { |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 459 | es = wl_surface_get_data(surface); |
| 460 | if (es == NULL) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 461 | continue; |
| 462 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 463 | draw_surface(es); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 464 | } |
| 465 | wl_surface_iterator_destroy(iterator); |
| 466 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 467 | draw_surface(ec->overlay); |
| 468 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 469 | draw_surface(ec->pointer); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 470 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 471 | eglSwapBuffers(ec->display, ec->surface); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 472 | |
| 473 | if (do_screenshot) { |
| 474 | glFinish(); |
| 475 | /* FIXME: There's a bug somewhere so that glFinish() |
| 476 | * doesn't actually wait for all rendering to finish. |
| 477 | * I *think* it's fixed in upstream drm, but for my |
| 478 | * kernel I need this sleep now... */ |
| 479 | sleep(1); |
| 480 | screenshot(ec); |
| 481 | do_screenshot = 0; |
| 482 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 483 | } |
| 484 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 485 | static void |
| 486 | schedule_repaint(struct egl_compositor *ec) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 487 | { |
| 488 | struct wl_event_loop *loop; |
| 489 | |
| 490 | loop = wl_display_get_event_loop(ec->wl_display); |
| 491 | wl_event_loop_add_idle(loop, repaint, ec); |
| 492 | } |
| 493 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 494 | static void |
| 495 | notify_surface_create(struct wl_compositor *compositor, |
| 496 | struct wl_surface *surface) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 497 | { |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 498 | struct egl_surface *es; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 499 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 500 | es = malloc(sizeof *es); |
| 501 | if (es == NULL) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 502 | return; |
| 503 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 504 | es->surface = EGL_NO_SURFACE; |
| 505 | wl_surface_set_data(surface, es); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 506 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 507 | glGenTextures(1, &es->texture); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 508 | } |
| 509 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 510 | static void |
| 511 | notify_surface_destroy(struct wl_compositor *compositor, |
| 512 | struct wl_surface *surface) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 513 | { |
| 514 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 515 | struct egl_surface *es; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 516 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 517 | es = wl_surface_get_data(surface); |
| 518 | if (es == NULL) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 519 | return; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 520 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 521 | egl_surface_destroy(es, ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 522 | |
| 523 | schedule_repaint(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 526 | static void |
| 527 | notify_surface_attach(struct wl_compositor *compositor, |
| 528 | struct wl_surface *surface, uint32_t name, |
| 529 | uint32_t width, uint32_t height, uint32_t stride) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 530 | { |
| 531 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 532 | struct egl_surface *es; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 533 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 534 | es = wl_surface_get_data(surface); |
| 535 | if (es == NULL) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 536 | return; |
| 537 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 538 | if (es->surface != EGL_NO_SURFACE) |
| 539 | eglDestroySurface(ec->display, es->surface); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 540 | |
Kristian Høgsberg | 56f3c71 | 2008-11-05 07:55:45 -0500 | [diff] [blame] | 541 | /* FIXME: We need to use a single buffer config without depth |
| 542 | * or stencil buffers here to keep egl from creating auxillary |
| 543 | * buffers for the pixmap here. */ |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 544 | es->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 545 | name, width, height, stride, NULL); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 546 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 547 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 548 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 549 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 550 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 551 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 552 | eglBindTexImage(ec->display, es->surface, GL_TEXTURE_2D); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 553 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 554 | schedule_repaint(ec); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 555 | } |
| 556 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 557 | static void |
| 558 | notify_surface_map(struct wl_compositor *compositor, |
| 559 | struct wl_surface *surface, struct wl_map *map) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 560 | { |
| 561 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 562 | struct egl_surface *es; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 563 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 564 | es = wl_surface_get_data(surface); |
| 565 | if (es == NULL) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 566 | return; |
| 567 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 568 | es->map = *map; |
Kristian Høgsberg | 5ebb317 | 2008-10-11 19:21:35 -0400 | [diff] [blame] | 569 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 570 | schedule_repaint(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 571 | } |
| 572 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 573 | static void |
| 574 | notify_surface_copy(struct wl_compositor *compositor, |
| 575 | struct wl_surface *surface, |
| 576 | int32_t dst_x, int32_t dst_y, |
| 577 | uint32_t name, uint32_t stride, |
| 578 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 579 | { |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 580 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 581 | EGLSurface src; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 582 | struct egl_surface *es; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 583 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 584 | es = wl_surface_get_data(surface); |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 585 | |
| 586 | /* FIXME: glCopyPixels should work, but then we'll have to |
| 587 | * call eglMakeCurrent to set up the src and dest surfaces |
| 588 | * first. This seems cheaper, but maybe there's a better way |
| 589 | * to accomplish this. */ |
| 590 | |
| 591 | src = eglCreateSurfaceForName(ec->display, ec->config, |
| 592 | name, x + width, y + height, stride, NULL); |
| 593 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 594 | 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] | 595 | src, GL_FRONT_LEFT, x, y, width, height); |
| 596 | schedule_repaint(ec); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static void |
| 600 | notify_surface_damage(struct wl_compositor *compositor, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 601 | struct wl_surface *surface, |
| 602 | 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] | 603 | { |
| 604 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 605 | |
| 606 | /* FIXME: This need to take a damage region, of course. */ |
| 607 | schedule_repaint(ec); |
| 608 | } |
| 609 | |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 610 | static void |
| 611 | notify_pointer_motion(struct wl_compositor *compositor, |
| 612 | struct wl_object *source, int x, int y) |
| 613 | { |
| 614 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 615 | |
| 616 | ec->pointer->map.x = x; |
| 617 | ec->pointer->map.y = y; |
| 618 | schedule_repaint(ec); |
| 619 | } |
| 620 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 621 | static const struct wl_compositor_interface interface = { |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 622 | notify_surface_create, |
| 623 | notify_surface_destroy, |
| 624 | notify_surface_attach, |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 625 | notify_surface_map, |
| 626 | notify_surface_copy, |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 627 | notify_surface_damage, |
| 628 | notify_pointer_motion |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 629 | }; |
| 630 | |
| 631 | static const char gem_device[] = "/dev/dri/card0"; |
| 632 | |
Kristian Høgsberg | b7a0192 | 2008-11-08 15:39:41 -0500 | [diff] [blame] | 633 | WL_EXPORT struct wl_compositor * |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 634 | wl_compositor_create(struct wl_display *display) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 635 | { |
| 636 | EGLConfig configs[64]; |
| 637 | EGLint major, minor, count; |
| 638 | struct egl_compositor *ec; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 639 | const char *filename; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 640 | |
| 641 | ec = malloc(sizeof *ec); |
| 642 | if (ec == NULL) |
| 643 | return NULL; |
| 644 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 645 | ec->width = 1280; |
| 646 | ec->height = 800; |
| 647 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 648 | ec->base.interface = &interface; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 649 | ec->wl_display = display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 650 | |
Kristian Høgsberg | c508d93 | 2008-10-13 22:52:42 -0400 | [diff] [blame] | 651 | ec->display = eglCreateDisplayNative(gem_device, "i965"); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 652 | if (ec->display == NULL) { |
| 653 | fprintf(stderr, "failed to create display\n"); |
| 654 | return NULL; |
| 655 | } |
| 656 | |
| 657 | if (!eglInitialize(ec->display, &major, &minor)) { |
| 658 | fprintf(stderr, "failed to initialize display\n"); |
| 659 | return NULL; |
| 660 | } |
| 661 | |
| 662 | if (!eglGetConfigs(ec->display, configs, ARRAY_LENGTH(configs), &count)) { |
| 663 | fprintf(stderr, "failed to get configs\n"); |
| 664 | return NULL; |
| 665 | } |
| 666 | |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 667 | ec->config = configs[24]; |
| 668 | ec->surface = eglCreateSurfaceNative(ec->display, ec->config, |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 669 | 0, 0, ec->width, ec->height); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 670 | if (ec->surface == NULL) { |
| 671 | fprintf(stderr, "failed to create surface\n"); |
| 672 | return NULL; |
| 673 | } |
| 674 | |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 675 | ec->context = eglCreateContext(ec->display, ec->config, NULL, NULL); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 676 | if (ec->context == NULL) { |
| 677 | fprintf(stderr, "failed to create context\n"); |
| 678 | return NULL; |
| 679 | } |
| 680 | |
| 681 | if (!eglMakeCurrent(ec->display, ec->surface, ec->surface, ec->context)) { |
| 682 | fprintf(stderr, "failed to make context current\n"); |
| 683 | return NULL; |
| 684 | } |
| 685 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 686 | glViewport(0, 0, ec->width, ec->height); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 687 | glMatrixMode(GL_PROJECTION); |
| 688 | glLoadIdentity(); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 689 | glOrtho(0, ec->width, ec->height, 0, 0, 1000.0); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 690 | glMatrixMode(GL_MODELVIEW); |
Kristian Høgsberg | a234e70 | 2008-10-11 22:13:51 -0400 | [diff] [blame] | 691 | glClearColor(0.0, 0.05, 0.2, 0.0); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 692 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 693 | filename = getenv("WAYLAND_BACKGROUND"); |
| 694 | if (filename == NULL) |
| 695 | filename = "background.jpg"; |
| 696 | ec->background = background_create(filename, 1280, 800); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 697 | ec->pointer = pointer_create(100, 100, 64, 64); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame^] | 698 | ec->overlay = overlay_create(0, ec->height - 200, ec->width, 200); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 699 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 700 | ec->gem_fd = open(gem_device, O_RDWR); |
| 701 | if (ec->gem_fd < 0) { |
| 702 | fprintf(stderr, "failed to open drm device\n"); |
| 703 | return NULL; |
| 704 | } |
| 705 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 706 | signal(SIGUSR1, handle_sigusr1); |
| 707 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 708 | schedule_repaint(ec); |
| 709 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 710 | return &ec->base; |
| 711 | } |