Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008-2011 Kristian Høgsberg |
| 3 | * Copyright © 2011 Intel Corporation |
| 4 | * Copyright © 2012 Raspberry Pi Foundation |
| 5 | * Copyright © 2013 Philip Withnall |
| 6 | * |
| 7 | * Permission to use, copy, modify, distribute, and sell this software and |
| 8 | * its documentation for any purpose is hereby granted without fee, provided |
| 9 | * that the above copyright notice appear in all copies and that both that |
| 10 | * copyright notice and this permission notice appear in supporting |
| 11 | * documentation, and that the name of the copyright holders not be used in |
| 12 | * advertising or publicity pertaining to distribution of the software |
| 13 | * without specific, written prior permission. The copyright holders make |
| 14 | * no representations about the suitability of this software for any |
| 15 | * purpose. It is provided "as is" without express or implied warranty. |
| 16 | * |
| 17 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 18 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 19 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 20 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 21 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 22 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 23 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 27 | |
| 28 | #include <errno.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <math.h> |
| 33 | #include <sys/mman.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <unistd.h> |
| 37 | #include <linux/fb.h> |
Kristian Høgsberg | 7e597f2 | 2013-02-18 16:35:26 -0500 | [diff] [blame] | 38 | #include <linux/input.h> |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 39 | |
| 40 | #include <libudev.h> |
| 41 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 42 | #include "compositor.h" |
| 43 | #include "launcher-util.h" |
| 44 | #include "pixman-renderer.h" |
Peter Hutterer | 823ad33 | 2014-11-26 07:06:31 +1000 | [diff] [blame] | 45 | #include "libinput-seat.h" |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 46 | #include "gl-renderer.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 47 | |
| 48 | struct fbdev_compositor { |
| 49 | struct weston_compositor base; |
| 50 | uint32_t prev_state; |
| 51 | |
| 52 | struct udev *udev; |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 53 | struct udev_input input; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 54 | int use_pixman; |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 55 | struct wl_listener session_listener; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct fbdev_screeninfo { |
| 59 | unsigned int x_resolution; /* pixels, visible area */ |
| 60 | unsigned int y_resolution; /* pixels, visible area */ |
| 61 | unsigned int width_mm; /* visible screen width in mm */ |
| 62 | unsigned int height_mm; /* visible screen height in mm */ |
| 63 | unsigned int bits_per_pixel; |
| 64 | |
| 65 | size_t buffer_length; /* length of frame buffer memory in bytes */ |
| 66 | size_t line_length; /* length of a line in bytes */ |
| 67 | char id[16]; /* screen identifier */ |
| 68 | |
| 69 | pixman_format_code_t pixel_format; /* frame buffer pixel format */ |
| 70 | unsigned int refresh_rate; /* Hertz */ |
| 71 | }; |
| 72 | |
| 73 | struct fbdev_output { |
| 74 | struct fbdev_compositor *compositor; |
| 75 | struct weston_output base; |
| 76 | |
| 77 | struct weston_mode mode; |
| 78 | struct wl_event_source *finish_frame_timer; |
| 79 | |
| 80 | /* Frame buffer details. */ |
| 81 | const char *device; /* ownership shared with fbdev_parameters */ |
| 82 | struct fbdev_screeninfo fb_info; |
| 83 | void *fb; /* length is fb_info.buffer_length */ |
| 84 | |
| 85 | /* pixman details. */ |
| 86 | pixman_image_t *hw_surface; |
| 87 | pixman_image_t *shadow_surface; |
| 88 | void *shadow_buf; |
| 89 | uint8_t depth; |
| 90 | }; |
| 91 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 92 | struct fbdev_parameters { |
| 93 | int tty; |
| 94 | char *device; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 95 | int use_gl; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 98 | struct gl_renderer_interface *gl_renderer; |
| 99 | |
Kristian Høgsberg | 7e597f2 | 2013-02-18 16:35:26 -0500 | [diff] [blame] | 100 | static const char default_seat[] = "seat0"; |
| 101 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 102 | static inline struct fbdev_output * |
| 103 | to_fbdev_output(struct weston_output *base) |
| 104 | { |
| 105 | return container_of(base, struct fbdev_output, base); |
| 106 | } |
| 107 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 108 | static inline struct fbdev_compositor * |
| 109 | to_fbdev_compositor(struct weston_compositor *base) |
| 110 | { |
| 111 | return container_of(base, struct fbdev_compositor, base); |
| 112 | } |
| 113 | |
| 114 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 115 | fbdev_output_start_repaint_loop(struct weston_output *output) |
| 116 | { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 117 | struct timespec ts; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 118 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 119 | clock_gettime(output->compositor->presentation_clock, &ts); |
| 120 | weston_output_finish_frame(output, &ts); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 124 | fbdev_output_repaint_pixman(struct weston_output *base, pixman_region32_t *damage) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 125 | { |
| 126 | struct fbdev_output *output = to_fbdev_output(base); |
| 127 | struct weston_compositor *ec = output->base.compositor; |
| 128 | pixman_box32_t *rects; |
| 129 | int nrects, i, src_x, src_y, x1, y1, x2, y2, width, height; |
| 130 | |
| 131 | /* Repaint the damaged region onto the back buffer. */ |
| 132 | pixman_renderer_output_set_buffer(base, output->shadow_surface); |
| 133 | ec->renderer->repaint_output(base, damage); |
| 134 | |
| 135 | /* Transform and composite onto the frame buffer. */ |
| 136 | width = pixman_image_get_width(output->shadow_surface); |
| 137 | height = pixman_image_get_height(output->shadow_surface); |
| 138 | rects = pixman_region32_rectangles(damage, &nrects); |
| 139 | |
| 140 | for (i = 0; i < nrects; i++) { |
| 141 | switch (base->transform) { |
| 142 | default: |
| 143 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 144 | x1 = rects[i].x1; |
| 145 | x2 = rects[i].x2; |
| 146 | y1 = rects[i].y1; |
| 147 | y2 = rects[i].y2; |
| 148 | break; |
| 149 | case WL_OUTPUT_TRANSFORM_180: |
| 150 | x1 = width - rects[i].x2; |
| 151 | x2 = width - rects[i].x1; |
| 152 | y1 = height - rects[i].y2; |
| 153 | y2 = height - rects[i].y1; |
| 154 | break; |
| 155 | case WL_OUTPUT_TRANSFORM_90: |
| 156 | x1 = height - rects[i].y2; |
| 157 | x2 = height - rects[i].y1; |
| 158 | y1 = rects[i].x1; |
| 159 | y2 = rects[i].x2; |
| 160 | break; |
| 161 | case WL_OUTPUT_TRANSFORM_270: |
| 162 | x1 = rects[i].y1; |
| 163 | x2 = rects[i].y2; |
| 164 | y1 = width - rects[i].x2; |
| 165 | y2 = width - rects[i].x1; |
| 166 | break; |
| 167 | } |
| 168 | src_x = x1; |
| 169 | src_y = y1; |
| 170 | |
| 171 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 172 | output->shadow_surface, /* src */ |
| 173 | NULL /* mask */, |
| 174 | output->hw_surface, /* dest */ |
| 175 | src_x, src_y, /* src_x, src_y */ |
| 176 | 0, 0, /* mask_x, mask_y */ |
| 177 | x1, y1, /* dest_x, dest_y */ |
| 178 | x2 - x1, /* width */ |
| 179 | y2 - y1 /* height */); |
| 180 | } |
| 181 | |
| 182 | /* Update the damage region. */ |
| 183 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 184 | &ec->primary_plane.damage, damage); |
| 185 | |
| 186 | /* Schedule the end of the frame. We do not sync this to the frame |
| 187 | * buffer clock because users who want that should be using the DRM |
| 188 | * compositor. FBIO_WAITFORVSYNC blocks and FB_ACTIVATE_VBL requires |
| 189 | * panning, which is broken in most kernel drivers. |
| 190 | * |
| 191 | * Finish the frame synchronised to the specified refresh rate. The |
| 192 | * refresh rate is given in mHz and the interval in ms. */ |
| 193 | wl_event_source_timer_update(output->finish_frame_timer, |
| 194 | 1000000 / output->mode.refresh); |
| 195 | } |
| 196 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 197 | static int |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 198 | fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage) |
| 199 | { |
| 200 | struct fbdev_output *output = to_fbdev_output(base); |
| 201 | struct fbdev_compositor *fbc = output->compositor; |
| 202 | struct weston_compositor *ec = & fbc->base; |
| 203 | |
| 204 | if (fbc->use_pixman) { |
| 205 | fbdev_output_repaint_pixman(base,damage); |
| 206 | } else { |
| 207 | ec->renderer->repaint_output(base, damage); |
| 208 | /* Update the damage region. */ |
| 209 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 210 | &ec->primary_plane.damage, damage); |
| 211 | |
| 212 | wl_event_source_timer_update(output->finish_frame_timer, |
| 213 | 1000000 / output->mode.refresh); |
| 214 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 215 | |
| 216 | return 0; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 217 | } |
| 218 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 219 | static int |
| 220 | finish_frame_handler(void *data) |
| 221 | { |
| 222 | struct fbdev_output *output = data; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 223 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 224 | fbdev_output_start_repaint_loop(&output->base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 225 | |
| 226 | return 1; |
| 227 | } |
| 228 | |
| 229 | static pixman_format_code_t |
| 230 | calculate_pixman_format(struct fb_var_screeninfo *vinfo, |
| 231 | struct fb_fix_screeninfo *finfo) |
| 232 | { |
| 233 | /* Calculate the pixman format supported by the frame buffer from the |
| 234 | * buffer's metadata. Return 0 if no known pixman format is supported |
| 235 | * (since this has depth 0 it's guaranteed to not conflict with any |
| 236 | * actual pixman format). |
| 237 | * |
| 238 | * Documentation on the vinfo and finfo structures: |
| 239 | * http://www.mjmwired.net/kernel/Documentation/fb/api.txt |
| 240 | * |
| 241 | * TODO: Try a bit harder to support other formats, including setting |
| 242 | * the preferred format in the hardware. */ |
| 243 | int type; |
| 244 | |
| 245 | weston_log("Calculating pixman format from:\n" |
| 246 | STAMP_SPACE " - type: %i (aux: %i)\n" |
| 247 | STAMP_SPACE " - visual: %i\n" |
| 248 | STAMP_SPACE " - bpp: %i (grayscale: %i)\n" |
| 249 | STAMP_SPACE " - red: offset: %i, length: %i, MSB: %i\n" |
| 250 | STAMP_SPACE " - green: offset: %i, length: %i, MSB: %i\n" |
| 251 | STAMP_SPACE " - blue: offset: %i, length: %i, MSB: %i\n" |
| 252 | STAMP_SPACE " - transp: offset: %i, length: %i, MSB: %i\n", |
| 253 | finfo->type, finfo->type_aux, finfo->visual, |
| 254 | vinfo->bits_per_pixel, vinfo->grayscale, |
| 255 | vinfo->red.offset, vinfo->red.length, vinfo->red.msb_right, |
| 256 | vinfo->green.offset, vinfo->green.length, |
| 257 | vinfo->green.msb_right, |
| 258 | vinfo->blue.offset, vinfo->blue.length, |
| 259 | vinfo->blue.msb_right, |
| 260 | vinfo->transp.offset, vinfo->transp.length, |
| 261 | vinfo->transp.msb_right); |
| 262 | |
| 263 | /* We only handle packed formats at the moment. */ |
| 264 | if (finfo->type != FB_TYPE_PACKED_PIXELS) |
| 265 | return 0; |
| 266 | |
| 267 | /* We only handle true-colour frame buffers at the moment. */ |
Marc Chalain | ffbddff | 2013-09-03 16:47:43 +0200 | [diff] [blame] | 268 | switch(finfo->visual) { |
| 269 | case FB_VISUAL_TRUECOLOR: |
| 270 | case FB_VISUAL_DIRECTCOLOR: |
| 271 | if (vinfo->grayscale != 0) |
| 272 | return 0; |
| 273 | break; |
| 274 | default: |
| 275 | return 0; |
| 276 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 277 | |
| 278 | /* We only support formats with MSBs on the left. */ |
| 279 | if (vinfo->red.msb_right != 0 || vinfo->green.msb_right != 0 || |
| 280 | vinfo->blue.msb_right != 0) |
| 281 | return 0; |
| 282 | |
| 283 | /* Work out the format type from the offsets. We only support RGBA and |
| 284 | * ARGB at the moment. */ |
| 285 | type = PIXMAN_TYPE_OTHER; |
| 286 | |
| 287 | if ((vinfo->transp.offset >= vinfo->red.offset || |
| 288 | vinfo->transp.length == 0) && |
| 289 | vinfo->red.offset >= vinfo->green.offset && |
| 290 | vinfo->green.offset >= vinfo->blue.offset) |
| 291 | type = PIXMAN_TYPE_ARGB; |
| 292 | else if (vinfo->red.offset >= vinfo->green.offset && |
| 293 | vinfo->green.offset >= vinfo->blue.offset && |
| 294 | vinfo->blue.offset >= vinfo->transp.offset) |
| 295 | type = PIXMAN_TYPE_RGBA; |
| 296 | |
| 297 | if (type == PIXMAN_TYPE_OTHER) |
| 298 | return 0; |
| 299 | |
| 300 | /* Build the format. */ |
| 301 | return PIXMAN_FORMAT(vinfo->bits_per_pixel, type, |
| 302 | vinfo->transp.length, |
| 303 | vinfo->red.length, |
| 304 | vinfo->green.length, |
| 305 | vinfo->blue.length); |
| 306 | } |
| 307 | |
| 308 | static int |
| 309 | calculate_refresh_rate(struct fb_var_screeninfo *vinfo) |
| 310 | { |
| 311 | uint64_t quot; |
| 312 | |
| 313 | /* Calculate monitor refresh rate. Default is 60 Hz. Units are mHz. */ |
| 314 | quot = (vinfo->upper_margin + vinfo->lower_margin + vinfo->yres); |
| 315 | quot *= (vinfo->left_margin + vinfo->right_margin + vinfo->xres); |
| 316 | quot *= vinfo->pixclock; |
| 317 | |
| 318 | if (quot > 0) { |
| 319 | uint64_t refresh_rate; |
| 320 | |
| 321 | refresh_rate = 1000000000000000LLU / quot; |
| 322 | if (refresh_rate > 200000) |
| 323 | refresh_rate = 200000; /* cap at 200 Hz */ |
| 324 | |
| 325 | return refresh_rate; |
| 326 | } |
| 327 | |
| 328 | return 60 * 1000; /* default to 60 Hz */ |
| 329 | } |
| 330 | |
| 331 | static int |
| 332 | fbdev_query_screen_info(struct fbdev_output *output, int fd, |
| 333 | struct fbdev_screeninfo *info) |
| 334 | { |
| 335 | struct fb_var_screeninfo varinfo; |
| 336 | struct fb_fix_screeninfo fixinfo; |
| 337 | |
| 338 | /* Probe the device for screen information. */ |
| 339 | if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) < 0 || |
| 340 | ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 341 | return -1; |
| 342 | } |
| 343 | |
| 344 | /* Store the pertinent data. */ |
| 345 | info->x_resolution = varinfo.xres; |
| 346 | info->y_resolution = varinfo.yres; |
| 347 | info->width_mm = varinfo.width; |
| 348 | info->height_mm = varinfo.height; |
| 349 | info->bits_per_pixel = varinfo.bits_per_pixel; |
| 350 | |
| 351 | info->buffer_length = fixinfo.smem_len; |
| 352 | info->line_length = fixinfo.line_length; |
| 353 | strncpy(info->id, fixinfo.id, sizeof(info->id) / sizeof(*info->id)); |
| 354 | |
| 355 | info->pixel_format = calculate_pixman_format(&varinfo, &fixinfo); |
| 356 | info->refresh_rate = calculate_refresh_rate(&varinfo); |
| 357 | |
| 358 | if (info->pixel_format == 0) { |
| 359 | weston_log("Frame buffer uses an unsupported format.\n"); |
| 360 | return -1; |
| 361 | } |
| 362 | |
| 363 | return 1; |
| 364 | } |
| 365 | |
| 366 | static int |
| 367 | fbdev_set_screen_info(struct fbdev_output *output, int fd, |
| 368 | struct fbdev_screeninfo *info) |
| 369 | { |
| 370 | struct fb_var_screeninfo varinfo; |
| 371 | |
| 372 | /* Grab the current screen information. */ |
| 373 | if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 374 | return -1; |
| 375 | } |
| 376 | |
| 377 | /* Update the information. */ |
| 378 | varinfo.xres = info->x_resolution; |
| 379 | varinfo.yres = info->y_resolution; |
| 380 | varinfo.width = info->width_mm; |
| 381 | varinfo.height = info->height_mm; |
| 382 | varinfo.bits_per_pixel = info->bits_per_pixel; |
| 383 | |
| 384 | /* Try to set up an ARGB (x8r8g8b8) pixel format. */ |
| 385 | varinfo.grayscale = 0; |
| 386 | varinfo.transp.offset = 24; |
| 387 | varinfo.transp.length = 0; |
| 388 | varinfo.transp.msb_right = 0; |
| 389 | varinfo.red.offset = 16; |
| 390 | varinfo.red.length = 8; |
| 391 | varinfo.red.msb_right = 0; |
| 392 | varinfo.green.offset = 8; |
| 393 | varinfo.green.length = 8; |
| 394 | varinfo.green.msb_right = 0; |
| 395 | varinfo.blue.offset = 0; |
| 396 | varinfo.blue.length = 8; |
| 397 | varinfo.blue.msb_right = 0; |
| 398 | |
| 399 | /* Set the device's screen information. */ |
| 400 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &varinfo) < 0) { |
| 401 | return -1; |
| 402 | } |
| 403 | |
| 404 | return 1; |
| 405 | } |
| 406 | |
| 407 | static void fbdev_frame_buffer_destroy(struct fbdev_output *output); |
| 408 | |
| 409 | /* Returns an FD for the frame buffer device. */ |
| 410 | static int |
| 411 | fbdev_frame_buffer_open(struct fbdev_output *output, const char *fb_dev, |
| 412 | struct fbdev_screeninfo *screen_info) |
| 413 | { |
| 414 | int fd = -1; |
| 415 | |
| 416 | weston_log("Opening fbdev frame buffer.\n"); |
| 417 | |
| 418 | /* Open the frame buffer device. */ |
| 419 | fd = open(fb_dev, O_RDWR | O_CLOEXEC); |
| 420 | if (fd < 0) { |
| 421 | weston_log("Failed to open frame buffer device ‘%s’: %s\n", |
| 422 | fb_dev, strerror(errno)); |
| 423 | return -1; |
| 424 | } |
| 425 | |
| 426 | /* Grab the screen info. */ |
| 427 | if (fbdev_query_screen_info(output, fd, screen_info) < 0) { |
| 428 | weston_log("Failed to get frame buffer info: %s\n", |
| 429 | strerror(errno)); |
| 430 | |
| 431 | close(fd); |
| 432 | return -1; |
| 433 | } |
| 434 | |
| 435 | return fd; |
| 436 | } |
| 437 | |
| 438 | /* Closes the FD on success or failure. */ |
| 439 | static int |
| 440 | fbdev_frame_buffer_map(struct fbdev_output *output, int fd) |
| 441 | { |
| 442 | int retval = -1; |
| 443 | |
| 444 | weston_log("Mapping fbdev frame buffer.\n"); |
| 445 | |
| 446 | /* Map the frame buffer. Write-only mode, since we don't want to read |
| 447 | * anything back (because it's slow). */ |
| 448 | output->fb = mmap(NULL, output->fb_info.buffer_length, |
| 449 | PROT_WRITE, MAP_SHARED, fd, 0); |
| 450 | if (output->fb == MAP_FAILED) { |
| 451 | weston_log("Failed to mmap frame buffer: %s\n", |
| 452 | strerror(errno)); |
| 453 | goto out_close; |
| 454 | } |
| 455 | |
| 456 | /* Create a pixman image to wrap the memory mapped frame buffer. */ |
| 457 | output->hw_surface = |
| 458 | pixman_image_create_bits(output->fb_info.pixel_format, |
| 459 | output->fb_info.x_resolution, |
| 460 | output->fb_info.y_resolution, |
| 461 | output->fb, |
| 462 | output->fb_info.line_length); |
| 463 | if (output->hw_surface == NULL) { |
| 464 | weston_log("Failed to create surface for frame buffer.\n"); |
| 465 | goto out_unmap; |
| 466 | } |
| 467 | |
| 468 | /* Success! */ |
| 469 | retval = 0; |
| 470 | |
| 471 | out_unmap: |
| 472 | if (retval != 0 && output->fb != NULL) |
| 473 | fbdev_frame_buffer_destroy(output); |
| 474 | |
| 475 | out_close: |
| 476 | if (fd >= 0) |
| 477 | close(fd); |
| 478 | |
| 479 | return retval; |
| 480 | } |
| 481 | |
| 482 | static void |
| 483 | fbdev_frame_buffer_destroy(struct fbdev_output *output) |
| 484 | { |
| 485 | weston_log("Destroying fbdev frame buffer.\n"); |
| 486 | |
| 487 | if (munmap(output->fb, output->fb_info.buffer_length) < 0) |
| 488 | weston_log("Failed to munmap frame buffer: %s\n", |
| 489 | strerror(errno)); |
| 490 | |
| 491 | output->fb = NULL; |
| 492 | } |
| 493 | |
| 494 | static void fbdev_output_destroy(struct weston_output *base); |
| 495 | static void fbdev_output_disable(struct weston_output *base); |
| 496 | |
| 497 | static int |
| 498 | fbdev_output_create(struct fbdev_compositor *compositor, |
| 499 | const char *device) |
| 500 | { |
| 501 | struct fbdev_output *output; |
| 502 | pixman_transform_t transform; |
| 503 | int fb_fd; |
| 504 | int shadow_width, shadow_height; |
| 505 | int width, height; |
| 506 | unsigned int bytes_per_pixel; |
| 507 | struct wl_event_loop *loop; |
| 508 | |
| 509 | weston_log("Creating fbdev output.\n"); |
| 510 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 511 | output = zalloc(sizeof *output); |
| 512 | if (output == NULL) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 513 | return -1; |
| 514 | |
| 515 | output->compositor = compositor; |
| 516 | output->device = device; |
| 517 | |
| 518 | /* Create the frame buffer. */ |
| 519 | fb_fd = fbdev_frame_buffer_open(output, device, &output->fb_info); |
| 520 | if (fb_fd < 0) { |
| 521 | weston_log("Creating frame buffer failed.\n"); |
| 522 | goto out_free; |
| 523 | } |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 524 | if (compositor->use_pixman) { |
| 525 | if (fbdev_frame_buffer_map(output, fb_fd) < 0) { |
| 526 | weston_log("Mapping frame buffer failed.\n"); |
| 527 | goto out_free; |
| 528 | } |
Kristian Høgsberg | 8ac6a2d | 2013-10-09 09:59:06 -0700 | [diff] [blame] | 529 | } else { |
| 530 | close(fb_fd); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 533 | output->base.start_repaint_loop = fbdev_output_start_repaint_loop; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 534 | output->base.repaint = fbdev_output_repaint; |
| 535 | output->base.destroy = fbdev_output_destroy; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 536 | |
| 537 | /* only one static mode in list */ |
| 538 | output->mode.flags = |
| 539 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 540 | output->mode.width = output->fb_info.x_resolution; |
| 541 | output->mode.height = output->fb_info.y_resolution; |
| 542 | output->mode.refresh = output->fb_info.refresh_rate; |
| 543 | wl_list_init(&output->base.mode_list); |
| 544 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 545 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 546 | output->base.current_mode = &output->mode; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 547 | output->base.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 548 | output->base.make = "unknown"; |
| 549 | output->base.model = output->fb_info.id; |
| 550 | |
| 551 | weston_output_init(&output->base, &compositor->base, |
| 552 | 0, 0, output->fb_info.width_mm, |
| 553 | output->fb_info.height_mm, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 554 | WL_OUTPUT_TRANSFORM_NORMAL, |
| 555 | 1); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 556 | |
| 557 | width = output->fb_info.x_resolution; |
| 558 | height = output->fb_info.y_resolution; |
| 559 | |
| 560 | pixman_transform_init_identity(&transform); |
| 561 | switch (output->base.transform) { |
| 562 | default: |
| 563 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 564 | shadow_width = width; |
| 565 | shadow_height = height; |
| 566 | pixman_transform_rotate(&transform, |
| 567 | NULL, 0, 0); |
| 568 | pixman_transform_translate(&transform, NULL, |
| 569 | 0, 0); |
| 570 | break; |
| 571 | case WL_OUTPUT_TRANSFORM_180: |
| 572 | shadow_width = width; |
| 573 | shadow_height = height; |
| 574 | pixman_transform_rotate(&transform, |
| 575 | NULL, -pixman_fixed_1, 0); |
| 576 | pixman_transform_translate(NULL, &transform, |
| 577 | pixman_int_to_fixed(shadow_width), |
| 578 | pixman_int_to_fixed(shadow_height)); |
| 579 | break; |
| 580 | case WL_OUTPUT_TRANSFORM_270: |
| 581 | shadow_width = height; |
| 582 | shadow_height = width; |
| 583 | pixman_transform_rotate(&transform, |
| 584 | NULL, 0, pixman_fixed_1); |
| 585 | pixman_transform_translate(&transform, |
| 586 | NULL, |
| 587 | pixman_int_to_fixed(shadow_width), |
| 588 | 0); |
| 589 | break; |
| 590 | case WL_OUTPUT_TRANSFORM_90: |
| 591 | shadow_width = height; |
| 592 | shadow_height = width; |
| 593 | pixman_transform_rotate(&transform, |
| 594 | NULL, 0, -pixman_fixed_1); |
| 595 | pixman_transform_translate(&transform, |
| 596 | NULL, |
| 597 | 0, |
| 598 | pixman_int_to_fixed(shadow_height)); |
| 599 | break; |
| 600 | } |
| 601 | |
| 602 | bytes_per_pixel = output->fb_info.bits_per_pixel / 8; |
| 603 | |
| 604 | output->shadow_buf = malloc(width * height * bytes_per_pixel); |
| 605 | output->shadow_surface = |
| 606 | pixman_image_create_bits(output->fb_info.pixel_format, |
| 607 | shadow_width, shadow_height, |
| 608 | output->shadow_buf, |
| 609 | shadow_width * bytes_per_pixel); |
| 610 | if (output->shadow_buf == NULL || output->shadow_surface == NULL) { |
| 611 | weston_log("Failed to create surface for frame buffer.\n"); |
| 612 | goto out_hw_surface; |
| 613 | } |
| 614 | |
| 615 | /* No need in transform for normal output */ |
| 616 | if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL) |
| 617 | pixman_image_set_transform(output->shadow_surface, &transform); |
| 618 | |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 619 | if (compositor->use_pixman) { |
| 620 | if (pixman_renderer_output_create(&output->base) < 0) |
| 621 | goto out_shadow_surface; |
| 622 | } else { |
| 623 | setenv("HYBRIS_EGLPLATFORM", "wayland", 1); |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 624 | if (gl_renderer->output_create(&output->base, |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 625 | (EGLNativeWindowType)NULL, |
| 626 | gl_renderer->opaque_attribs, |
| 627 | NULL) < 0) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 628 | weston_log("gl_renderer_output_create failed.\n"); |
| 629 | goto out_shadow_surface; |
| 630 | } |
| 631 | } |
| 632 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 633 | |
| 634 | loop = wl_display_get_event_loop(compositor->base.wl_display); |
| 635 | output->finish_frame_timer = |
| 636 | wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 637 | |
| 638 | wl_list_insert(compositor->base.output_list.prev, &output->base.link); |
| 639 | |
| 640 | weston_log("fbdev output %d×%d px\n", |
| 641 | output->mode.width, output->mode.height); |
| 642 | weston_log_continue(STAMP_SPACE "guessing %d Hz and 96 dpi\n", |
| 643 | output->mode.refresh / 1000); |
| 644 | |
| 645 | return 0; |
| 646 | |
| 647 | out_shadow_surface: |
| 648 | pixman_image_unref(output->shadow_surface); |
| 649 | output->shadow_surface = NULL; |
| 650 | out_hw_surface: |
| 651 | free(output->shadow_buf); |
| 652 | pixman_image_unref(output->hw_surface); |
| 653 | output->hw_surface = NULL; |
| 654 | weston_output_destroy(&output->base); |
| 655 | fbdev_frame_buffer_destroy(output); |
| 656 | out_free: |
| 657 | free(output); |
| 658 | |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | static void |
| 663 | fbdev_output_destroy(struct weston_output *base) |
| 664 | { |
| 665 | struct fbdev_output *output = to_fbdev_output(base); |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 666 | struct fbdev_compositor *compositor = output->compositor; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 667 | |
| 668 | weston_log("Destroying fbdev output.\n"); |
| 669 | |
| 670 | /* Close the frame buffer. */ |
| 671 | fbdev_output_disable(base); |
| 672 | |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 673 | if (compositor->use_pixman) { |
| 674 | if (base->renderer_state != NULL) |
| 675 | pixman_renderer_output_destroy(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 676 | |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 677 | if (output->shadow_surface != NULL) { |
| 678 | pixman_image_unref(output->shadow_surface); |
| 679 | output->shadow_surface = NULL; |
| 680 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 681 | |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 682 | if (output->shadow_buf != NULL) { |
| 683 | free(output->shadow_buf); |
| 684 | output->shadow_buf = NULL; |
| 685 | } |
| 686 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 687 | gl_renderer->output_destroy(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | /* Remove the output. */ |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 691 | weston_output_destroy(&output->base); |
| 692 | |
| 693 | free(output); |
| 694 | } |
| 695 | |
| 696 | /* strcmp()-style return values. */ |
| 697 | static int |
| 698 | compare_screen_info (const struct fbdev_screeninfo *a, |
| 699 | const struct fbdev_screeninfo *b) |
| 700 | { |
| 701 | if (a->x_resolution == b->x_resolution && |
| 702 | a->y_resolution == b->y_resolution && |
| 703 | a->width_mm == b->width_mm && |
| 704 | a->height_mm == b->height_mm && |
| 705 | a->bits_per_pixel == b->bits_per_pixel && |
| 706 | a->pixel_format == b->pixel_format && |
| 707 | a->refresh_rate == b->refresh_rate) |
| 708 | return 0; |
| 709 | |
| 710 | return 1; |
| 711 | } |
| 712 | |
| 713 | static int |
| 714 | fbdev_output_reenable(struct fbdev_compositor *compositor, |
| 715 | struct weston_output *base) |
| 716 | { |
| 717 | struct fbdev_output *output = to_fbdev_output(base); |
| 718 | struct fbdev_screeninfo new_screen_info; |
| 719 | int fb_fd; |
Rob Bradford | f8ef42f | 2013-07-26 16:29:38 +0100 | [diff] [blame] | 720 | const char *device; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 721 | |
| 722 | weston_log("Re-enabling fbdev output.\n"); |
| 723 | |
| 724 | /* Create the frame buffer. */ |
| 725 | fb_fd = fbdev_frame_buffer_open(output, output->device, |
| 726 | &new_screen_info); |
| 727 | if (fb_fd < 0) { |
| 728 | weston_log("Creating frame buffer failed.\n"); |
| 729 | goto err; |
| 730 | } |
| 731 | |
| 732 | /* Check whether the frame buffer details have changed since we were |
| 733 | * disabled. */ |
| 734 | if (compare_screen_info (&output->fb_info, &new_screen_info) != 0) { |
| 735 | /* Perform a mode-set to restore the old mode. */ |
| 736 | if (fbdev_set_screen_info(output, fb_fd, |
| 737 | &output->fb_info) < 0) { |
| 738 | weston_log("Failed to restore mode settings. " |
| 739 | "Attempting to re-open output anyway.\n"); |
| 740 | } |
| 741 | |
Rob Bradford | 581b3fd | 2013-07-26 16:29:39 +0100 | [diff] [blame] | 742 | close(fb_fd); |
| 743 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 744 | /* Remove and re-add the output so that resources depending on |
| 745 | * the frame buffer X/Y resolution (such as the shadow buffer) |
| 746 | * are re-initialised. */ |
Rob Bradford | f8ef42f | 2013-07-26 16:29:38 +0100 | [diff] [blame] | 747 | device = output->device; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 748 | fbdev_output_destroy(base); |
Rob Bradford | f8ef42f | 2013-07-26 16:29:38 +0100 | [diff] [blame] | 749 | fbdev_output_create(compositor, device); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | /* Map the device if it has the same details as before. */ |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 755 | if (compositor->use_pixman) { |
| 756 | if (fbdev_frame_buffer_map(output, fb_fd) < 0) { |
| 757 | weston_log("Mapping frame buffer failed.\n"); |
| 758 | goto err; |
| 759 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | return 0; |
| 763 | |
| 764 | err: |
| 765 | return -1; |
| 766 | } |
| 767 | |
| 768 | /* NOTE: This leaves output->fb_info populated, caching data so that if |
| 769 | * fbdev_output_reenable() is called again, it can determine whether a mode-set |
| 770 | * is needed. */ |
| 771 | static void |
| 772 | fbdev_output_disable(struct weston_output *base) |
| 773 | { |
| 774 | struct fbdev_output *output = to_fbdev_output(base); |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 775 | struct fbdev_compositor *compositor = output->compositor; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 776 | |
| 777 | weston_log("Disabling fbdev output.\n"); |
| 778 | |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 779 | if ( ! compositor->use_pixman) return; |
| 780 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 781 | if (output->hw_surface != NULL) { |
| 782 | pixman_image_unref(output->hw_surface); |
| 783 | output->hw_surface = NULL; |
| 784 | } |
| 785 | |
| 786 | fbdev_frame_buffer_destroy(output); |
| 787 | } |
| 788 | |
| 789 | static void |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 790 | fbdev_compositor_destroy(struct weston_compositor *base) |
| 791 | { |
| 792 | struct fbdev_compositor *compositor = to_fbdev_compositor(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 793 | |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 794 | udev_input_destroy(&compositor->input); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 795 | |
| 796 | /* Destroy the output. */ |
| 797 | weston_compositor_shutdown(&compositor->base); |
| 798 | |
| 799 | /* Chain up. */ |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 800 | weston_launcher_destroy(compositor->base.launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 801 | |
| 802 | free(compositor); |
| 803 | } |
| 804 | |
| 805 | static void |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 806 | session_notify(struct wl_listener *listener, void *data) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 807 | { |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 808 | struct fbdev_compositor *compositor = data; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 809 | struct weston_output *output; |
| 810 | |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 811 | if (compositor->base.session_active) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 812 | weston_log("entering VT\n"); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 813 | compositor->base.state = compositor->prev_state; |
| 814 | |
| 815 | wl_list_for_each(output, &compositor->base.output_list, link) { |
| 816 | fbdev_output_reenable(compositor, output); |
| 817 | } |
| 818 | |
| 819 | weston_compositor_damage_all(&compositor->base); |
| 820 | |
Jonas Ådahl | 0feb32e | 2014-03-12 22:08:41 +0100 | [diff] [blame] | 821 | udev_input_enable(&compositor->input); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 822 | } else { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 823 | weston_log("leaving VT\n"); |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 824 | udev_input_disable(&compositor->input); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 825 | |
| 826 | wl_list_for_each(output, &compositor->base.output_list, link) { |
| 827 | fbdev_output_disable(output); |
| 828 | } |
| 829 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 830 | compositor->prev_state = compositor->base.state; |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 831 | weston_compositor_offscreen(&compositor->base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 832 | |
| 833 | /* If we have a repaint scheduled (from the idle handler), make |
| 834 | * sure we cancel that so we don't try to pageflip when we're |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 835 | * vt switched away. The OFFSCREEN state will prevent |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 836 | * further attemps at repainting. When we switch |
| 837 | * back, we schedule a repaint, which will process |
| 838 | * pending frame callbacks. */ |
| 839 | |
| 840 | wl_list_for_each(output, |
| 841 | &compositor->base.output_list, link) { |
| 842 | output->repaint_needed = 0; |
| 843 | } |
nerdopolis | 3894670 | 2014-12-03 15:53:03 +0000 | [diff] [blame^] | 844 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static void |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 848 | fbdev_restore(struct weston_compositor *compositor) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 849 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 850 | weston_launcher_restore(compositor->launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 854 | switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 855 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 856 | struct weston_compositor *compositor = data; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 857 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 858 | weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static struct weston_compositor * |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 862 | fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 863 | struct weston_config *config, |
| 864 | struct fbdev_parameters *param) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 865 | { |
| 866 | struct fbdev_compositor *compositor; |
Rob Bradford | 2387fde | 2013-05-31 18:09:57 +0100 | [diff] [blame] | 867 | const char *seat_id = default_seat; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 868 | uint32_t key; |
| 869 | |
| 870 | weston_log("initializing fbdev backend\n"); |
| 871 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 872 | compositor = zalloc(sizeof *compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 873 | if (compositor == NULL) |
| 874 | return NULL; |
| 875 | |
| 876 | if (weston_compositor_init(&compositor->base, display, argc, argv, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 877 | config) < 0) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 878 | goto out_free; |
| 879 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 880 | if (weston_compositor_set_presentation_clock_software( |
| 881 | &compositor->base) < 0) |
| 882 | goto out_compositor; |
| 883 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 884 | compositor->udev = udev_new(); |
| 885 | if (compositor->udev == NULL) { |
| 886 | weston_log("Failed to initialize udev context.\n"); |
| 887 | goto out_compositor; |
| 888 | } |
| 889 | |
| 890 | /* Set up the TTY. */ |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 891 | compositor->session_listener.notify = session_notify; |
| 892 | wl_signal_add(&compositor->base.session_signal, |
| 893 | &compositor->session_listener); |
Kristian Høgsberg | 6ff3ff5 | 2013-10-02 10:53:33 -0700 | [diff] [blame] | 894 | compositor->base.launcher = |
David Herrmann | cc5b2ed | 2013-10-22 00:28:09 +0200 | [diff] [blame] | 895 | weston_launcher_connect(&compositor->base, param->tty, "seat0"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 896 | if (!compositor->base.launcher) { |
David Herrmann | 1641d14 | 2013-10-15 14:29:57 +0200 | [diff] [blame] | 897 | weston_log("fatal: fbdev backend should be run " |
| 898 | "using weston-launch binary or as root\n"); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 899 | goto out_udev; |
| 900 | } |
| 901 | |
| 902 | compositor->base.destroy = fbdev_compositor_destroy; |
| 903 | compositor->base.restore = fbdev_restore; |
| 904 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 905 | compositor->prev_state = WESTON_COMPOSITOR_ACTIVE; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 906 | compositor->use_pixman = !param->use_gl; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 907 | |
| 908 | for (key = KEY_F1; key < KEY_F9; key++) |
| 909 | weston_compositor_add_key_binding(&compositor->base, key, |
| 910 | MODIFIER_CTRL | MODIFIER_ALT, |
| 911 | switch_vt_binding, |
| 912 | compositor); |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 913 | if (compositor->use_pixman) { |
| 914 | if (pixman_renderer_init(&compositor->base) < 0) |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 915 | goto out_launcher; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 916 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 917 | gl_renderer = weston_load_module("gl-renderer.so", |
| 918 | "gl_renderer_interface"); |
| 919 | if (!gl_renderer) { |
| 920 | weston_log("could not load gl renderer\n"); |
| 921 | goto out_launcher; |
| 922 | } |
| 923 | |
| 924 | if (gl_renderer->create(&compositor->base, EGL_DEFAULT_DISPLAY, |
| 925 | gl_renderer->opaque_attribs, |
| 926 | NULL) < 0) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 927 | weston_log("gl_renderer_create failed.\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 928 | goto out_launcher; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 929 | } |
| 930 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 931 | |
| 932 | if (fbdev_output_create(compositor, param->device) < 0) |
| 933 | goto out_pixman; |
| 934 | |
Rob Bradford | 2387fde | 2013-05-31 18:09:57 +0100 | [diff] [blame] | 935 | udev_input_init(&compositor->input, &compositor->base, compositor->udev, seat_id); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 936 | |
| 937 | return &compositor->base; |
| 938 | |
| 939 | out_pixman: |
| 940 | compositor->base.renderer->destroy(&compositor->base); |
| 941 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 942 | out_launcher: |
| 943 | weston_launcher_destroy(compositor->base.launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 944 | |
| 945 | out_udev: |
| 946 | udev_unref(compositor->udev); |
| 947 | |
| 948 | out_compositor: |
| 949 | weston_compositor_shutdown(&compositor->base); |
| 950 | |
| 951 | out_free: |
| 952 | free(compositor); |
| 953 | |
| 954 | return NULL; |
| 955 | } |
| 956 | |
| 957 | WL_EXPORT struct weston_compositor * |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 958 | backend_init(struct wl_display *display, int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 959 | struct weston_config *config) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 960 | { |
| 961 | /* TODO: Ideally, available frame buffers should be enumerated using |
| 962 | * udev, rather than passing a device node in as a parameter. */ |
| 963 | struct fbdev_parameters param = { |
| 964 | .tty = 0, /* default to current tty */ |
| 965 | .device = "/dev/fb0", /* default frame buffer */ |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 966 | .use_gl = 0, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 967 | }; |
| 968 | |
| 969 | const struct weston_option fbdev_options[] = { |
| 970 | { WESTON_OPTION_INTEGER, "tty", 0, ¶m.tty }, |
| 971 | { WESTON_OPTION_STRING, "device", 0, ¶m.device }, |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 972 | { WESTON_OPTION_BOOLEAN, "use-gl", 0, ¶m.use_gl }, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 973 | }; |
| 974 | |
| 975 | parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv); |
| 976 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 977 | return fbdev_compositor_create(display, argc, argv, config, ¶m); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 978 | } |