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