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 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining |
| 8 | * a copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 14 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial |
| 17 | * portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 29 | #include "config.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 30 | |
| 31 | #include <errno.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdio.h> |
| 34 | #include <string.h> |
| 35 | #include <math.h> |
| 36 | #include <sys/mman.h> |
| 37 | #include <sys/types.h> |
| 38 | #include <fcntl.h> |
| 39 | #include <unistd.h> |
| 40 | #include <linux/fb.h> |
Kristian Høgsberg | 7e597f2 | 2013-02-18 16:35:26 -0500 | [diff] [blame] | 41 | #include <linux/input.h> |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 42 | |
| 43 | #include <libudev.h> |
| 44 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 45 | #include "shared/helpers.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 46 | #include "compositor.h" |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 47 | #include "compositor-fbdev.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 48 | #include "launcher-util.h" |
| 49 | #include "pixman-renderer.h" |
Peter Hutterer | 823ad33 | 2014-11-26 07:06:31 +1000 | [diff] [blame] | 50 | #include "libinput-seat.h" |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 51 | #include "gl-renderer.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 52 | #include "presentation-time-server-protocol.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 53 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 54 | struct fbdev_backend { |
| 55 | struct weston_backend base; |
| 56 | struct weston_compositor *compositor; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 57 | uint32_t prev_state; |
| 58 | |
| 59 | struct udev *udev; |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 60 | struct udev_input input; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 61 | int use_pixman; |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 62 | uint32_t output_transform; |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 63 | struct wl_listener session_listener; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct fbdev_screeninfo { |
| 67 | unsigned int x_resolution; /* pixels, visible area */ |
| 68 | unsigned int y_resolution; /* pixels, visible area */ |
| 69 | unsigned int width_mm; /* visible screen width in mm */ |
| 70 | unsigned int height_mm; /* visible screen height in mm */ |
| 71 | unsigned int bits_per_pixel; |
| 72 | |
| 73 | size_t buffer_length; /* length of frame buffer memory in bytes */ |
| 74 | size_t line_length; /* length of a line in bytes */ |
| 75 | char id[16]; /* screen identifier */ |
| 76 | |
| 77 | pixman_format_code_t pixel_format; /* frame buffer pixel format */ |
| 78 | unsigned int refresh_rate; /* Hertz */ |
| 79 | }; |
| 80 | |
| 81 | struct fbdev_output { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 82 | struct fbdev_backend *backend; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 83 | struct weston_output base; |
| 84 | |
| 85 | struct weston_mode mode; |
| 86 | struct wl_event_source *finish_frame_timer; |
| 87 | |
| 88 | /* Frame buffer details. */ |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 89 | char *device; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 90 | struct fbdev_screeninfo fb_info; |
| 91 | void *fb; /* length is fb_info.buffer_length */ |
| 92 | |
| 93 | /* pixman details. */ |
| 94 | pixman_image_t *hw_surface; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 95 | uint8_t depth; |
| 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 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 108 | static inline struct fbdev_backend * |
| 109 | to_fbdev_backend(struct weston_compositor *base) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 110 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 111 | return container_of(base->backend, struct fbdev_backend, base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 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 | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 119 | weston_compositor_read_presentation_clock(output->compositor, &ts); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 120 | weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID); |
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; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 128 | |
| 129 | /* Repaint the damaged region onto the back buffer. */ |
Sjoerd Simons | c112e0c | 2015-12-04 19:20:12 -0600 | [diff] [blame] | 130 | pixman_renderer_output_set_buffer(base, output->hw_surface); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 131 | ec->renderer->repaint_output(base, damage); |
| 132 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 133 | /* Update the damage region. */ |
| 134 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 135 | &ec->primary_plane.damage, damage); |
| 136 | |
| 137 | /* Schedule the end of the frame. We do not sync this to the frame |
| 138 | * buffer clock because users who want that should be using the DRM |
| 139 | * compositor. FBIO_WAITFORVSYNC blocks and FB_ACTIVATE_VBL requires |
| 140 | * panning, which is broken in most kernel drivers. |
| 141 | * |
| 142 | * Finish the frame synchronised to the specified refresh rate. The |
| 143 | * refresh rate is given in mHz and the interval in ms. */ |
| 144 | wl_event_source_timer_update(output->finish_frame_timer, |
| 145 | 1000000 / output->mode.refresh); |
| 146 | } |
| 147 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 148 | static int |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 149 | fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage) |
| 150 | { |
| 151 | struct fbdev_output *output = to_fbdev_output(base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 152 | struct fbdev_backend *fbb = output->backend; |
| 153 | struct weston_compositor *ec = fbb->compositor; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 154 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 155 | if (fbb->use_pixman) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 156 | fbdev_output_repaint_pixman(base,damage); |
| 157 | } else { |
| 158 | ec->renderer->repaint_output(base, damage); |
| 159 | /* Update the damage region. */ |
| 160 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 161 | &ec->primary_plane.damage, damage); |
| 162 | |
| 163 | wl_event_source_timer_update(output->finish_frame_timer, |
| 164 | 1000000 / output->mode.refresh); |
| 165 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 166 | |
| 167 | return 0; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 168 | } |
| 169 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 170 | static int |
| 171 | finish_frame_handler(void *data) |
| 172 | { |
| 173 | struct fbdev_output *output = data; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 174 | struct timespec ts; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 175 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 176 | weston_compositor_read_presentation_clock(output->base.compositor, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 177 | weston_output_finish_frame(&output->base, &ts, 0); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 178 | |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | static pixman_format_code_t |
| 183 | calculate_pixman_format(struct fb_var_screeninfo *vinfo, |
| 184 | struct fb_fix_screeninfo *finfo) |
| 185 | { |
| 186 | /* Calculate the pixman format supported by the frame buffer from the |
| 187 | * buffer's metadata. Return 0 if no known pixman format is supported |
| 188 | * (since this has depth 0 it's guaranteed to not conflict with any |
| 189 | * actual pixman format). |
| 190 | * |
| 191 | * Documentation on the vinfo and finfo structures: |
| 192 | * http://www.mjmwired.net/kernel/Documentation/fb/api.txt |
| 193 | * |
| 194 | * TODO: Try a bit harder to support other formats, including setting |
| 195 | * the preferred format in the hardware. */ |
| 196 | int type; |
| 197 | |
| 198 | weston_log("Calculating pixman format from:\n" |
| 199 | STAMP_SPACE " - type: %i (aux: %i)\n" |
| 200 | STAMP_SPACE " - visual: %i\n" |
| 201 | STAMP_SPACE " - bpp: %i (grayscale: %i)\n" |
| 202 | STAMP_SPACE " - red: offset: %i, length: %i, MSB: %i\n" |
| 203 | STAMP_SPACE " - green: offset: %i, length: %i, MSB: %i\n" |
| 204 | STAMP_SPACE " - blue: offset: %i, length: %i, MSB: %i\n" |
| 205 | STAMP_SPACE " - transp: offset: %i, length: %i, MSB: %i\n", |
| 206 | finfo->type, finfo->type_aux, finfo->visual, |
| 207 | vinfo->bits_per_pixel, vinfo->grayscale, |
| 208 | vinfo->red.offset, vinfo->red.length, vinfo->red.msb_right, |
| 209 | vinfo->green.offset, vinfo->green.length, |
| 210 | vinfo->green.msb_right, |
| 211 | vinfo->blue.offset, vinfo->blue.length, |
| 212 | vinfo->blue.msb_right, |
| 213 | vinfo->transp.offset, vinfo->transp.length, |
| 214 | vinfo->transp.msb_right); |
| 215 | |
| 216 | /* We only handle packed formats at the moment. */ |
| 217 | if (finfo->type != FB_TYPE_PACKED_PIXELS) |
| 218 | return 0; |
| 219 | |
| 220 | /* We only handle true-colour frame buffers at the moment. */ |
Marc Chalain | ffbddff | 2013-09-03 16:47:43 +0200 | [diff] [blame] | 221 | switch(finfo->visual) { |
| 222 | case FB_VISUAL_TRUECOLOR: |
| 223 | case FB_VISUAL_DIRECTCOLOR: |
| 224 | if (vinfo->grayscale != 0) |
| 225 | return 0; |
| 226 | break; |
| 227 | default: |
| 228 | return 0; |
| 229 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 230 | |
| 231 | /* We only support formats with MSBs on the left. */ |
| 232 | if (vinfo->red.msb_right != 0 || vinfo->green.msb_right != 0 || |
| 233 | vinfo->blue.msb_right != 0) |
| 234 | return 0; |
| 235 | |
| 236 | /* Work out the format type from the offsets. We only support RGBA and |
| 237 | * ARGB at the moment. */ |
| 238 | type = PIXMAN_TYPE_OTHER; |
| 239 | |
| 240 | if ((vinfo->transp.offset >= vinfo->red.offset || |
| 241 | vinfo->transp.length == 0) && |
| 242 | vinfo->red.offset >= vinfo->green.offset && |
| 243 | vinfo->green.offset >= vinfo->blue.offset) |
| 244 | type = PIXMAN_TYPE_ARGB; |
| 245 | else if (vinfo->red.offset >= vinfo->green.offset && |
| 246 | vinfo->green.offset >= vinfo->blue.offset && |
| 247 | vinfo->blue.offset >= vinfo->transp.offset) |
| 248 | type = PIXMAN_TYPE_RGBA; |
| 249 | |
| 250 | if (type == PIXMAN_TYPE_OTHER) |
| 251 | return 0; |
| 252 | |
| 253 | /* Build the format. */ |
| 254 | return PIXMAN_FORMAT(vinfo->bits_per_pixel, type, |
| 255 | vinfo->transp.length, |
| 256 | vinfo->red.length, |
| 257 | vinfo->green.length, |
| 258 | vinfo->blue.length); |
| 259 | } |
| 260 | |
| 261 | static int |
| 262 | calculate_refresh_rate(struct fb_var_screeninfo *vinfo) |
| 263 | { |
| 264 | uint64_t quot; |
| 265 | |
| 266 | /* Calculate monitor refresh rate. Default is 60 Hz. Units are mHz. */ |
| 267 | quot = (vinfo->upper_margin + vinfo->lower_margin + vinfo->yres); |
| 268 | quot *= (vinfo->left_margin + vinfo->right_margin + vinfo->xres); |
| 269 | quot *= vinfo->pixclock; |
| 270 | |
| 271 | if (quot > 0) { |
| 272 | uint64_t refresh_rate; |
| 273 | |
| 274 | refresh_rate = 1000000000000000LLU / quot; |
| 275 | if (refresh_rate > 200000) |
| 276 | refresh_rate = 200000; /* cap at 200 Hz */ |
| 277 | |
| 278 | return refresh_rate; |
| 279 | } |
| 280 | |
| 281 | return 60 * 1000; /* default to 60 Hz */ |
| 282 | } |
| 283 | |
| 284 | static int |
| 285 | fbdev_query_screen_info(struct fbdev_output *output, int fd, |
| 286 | struct fbdev_screeninfo *info) |
| 287 | { |
| 288 | struct fb_var_screeninfo varinfo; |
| 289 | struct fb_fix_screeninfo fixinfo; |
| 290 | |
| 291 | /* Probe the device for screen information. */ |
| 292 | if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) < 0 || |
| 293 | ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 294 | return -1; |
| 295 | } |
| 296 | |
| 297 | /* Store the pertinent data. */ |
| 298 | info->x_resolution = varinfo.xres; |
| 299 | info->y_resolution = varinfo.yres; |
| 300 | info->width_mm = varinfo.width; |
| 301 | info->height_mm = varinfo.height; |
| 302 | info->bits_per_pixel = varinfo.bits_per_pixel; |
| 303 | |
| 304 | info->buffer_length = fixinfo.smem_len; |
| 305 | info->line_length = fixinfo.line_length; |
Derek Foreman | 6179338 | 2015-09-02 13:45:20 -0500 | [diff] [blame] | 306 | strncpy(info->id, fixinfo.id, sizeof(info->id)); |
Bryce Harrington | 44bbdd0 | 2015-09-23 17:39:05 -0700 | [diff] [blame] | 307 | info->id[sizeof(info->id)-1] = '\0'; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 308 | |
| 309 | info->pixel_format = calculate_pixman_format(&varinfo, &fixinfo); |
| 310 | info->refresh_rate = calculate_refresh_rate(&varinfo); |
| 311 | |
| 312 | if (info->pixel_format == 0) { |
| 313 | weston_log("Frame buffer uses an unsupported format.\n"); |
| 314 | return -1; |
| 315 | } |
| 316 | |
| 317 | return 1; |
| 318 | } |
| 319 | |
| 320 | static int |
| 321 | fbdev_set_screen_info(struct fbdev_output *output, int fd, |
| 322 | struct fbdev_screeninfo *info) |
| 323 | { |
| 324 | struct fb_var_screeninfo varinfo; |
| 325 | |
| 326 | /* Grab the current screen information. */ |
| 327 | if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 328 | return -1; |
| 329 | } |
| 330 | |
| 331 | /* Update the information. */ |
| 332 | varinfo.xres = info->x_resolution; |
| 333 | varinfo.yres = info->y_resolution; |
| 334 | varinfo.width = info->width_mm; |
| 335 | varinfo.height = info->height_mm; |
| 336 | varinfo.bits_per_pixel = info->bits_per_pixel; |
| 337 | |
| 338 | /* Try to set up an ARGB (x8r8g8b8) pixel format. */ |
| 339 | varinfo.grayscale = 0; |
| 340 | varinfo.transp.offset = 24; |
| 341 | varinfo.transp.length = 0; |
| 342 | varinfo.transp.msb_right = 0; |
| 343 | varinfo.red.offset = 16; |
| 344 | varinfo.red.length = 8; |
| 345 | varinfo.red.msb_right = 0; |
| 346 | varinfo.green.offset = 8; |
| 347 | varinfo.green.length = 8; |
| 348 | varinfo.green.msb_right = 0; |
| 349 | varinfo.blue.offset = 0; |
| 350 | varinfo.blue.length = 8; |
| 351 | varinfo.blue.msb_right = 0; |
| 352 | |
| 353 | /* Set the device's screen information. */ |
| 354 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &varinfo) < 0) { |
| 355 | return -1; |
| 356 | } |
| 357 | |
| 358 | return 1; |
| 359 | } |
| 360 | |
| 361 | static void fbdev_frame_buffer_destroy(struct fbdev_output *output); |
| 362 | |
| 363 | /* Returns an FD for the frame buffer device. */ |
| 364 | static int |
| 365 | fbdev_frame_buffer_open(struct fbdev_output *output, const char *fb_dev, |
| 366 | struct fbdev_screeninfo *screen_info) |
| 367 | { |
| 368 | int fd = -1; |
| 369 | |
| 370 | weston_log("Opening fbdev frame buffer.\n"); |
| 371 | |
| 372 | /* Open the frame buffer device. */ |
| 373 | fd = open(fb_dev, O_RDWR | O_CLOEXEC); |
| 374 | if (fd < 0) { |
| 375 | weston_log("Failed to open frame buffer device ‘%s’: %s\n", |
| 376 | fb_dev, strerror(errno)); |
| 377 | return -1; |
| 378 | } |
| 379 | |
| 380 | /* Grab the screen info. */ |
| 381 | if (fbdev_query_screen_info(output, fd, screen_info) < 0) { |
| 382 | weston_log("Failed to get frame buffer info: %s\n", |
| 383 | strerror(errno)); |
| 384 | |
| 385 | close(fd); |
| 386 | return -1; |
| 387 | } |
| 388 | |
| 389 | return fd; |
| 390 | } |
| 391 | |
| 392 | /* Closes the FD on success or failure. */ |
| 393 | static int |
| 394 | fbdev_frame_buffer_map(struct fbdev_output *output, int fd) |
| 395 | { |
| 396 | int retval = -1; |
| 397 | |
| 398 | weston_log("Mapping fbdev frame buffer.\n"); |
| 399 | |
| 400 | /* Map the frame buffer. Write-only mode, since we don't want to read |
| 401 | * anything back (because it's slow). */ |
| 402 | output->fb = mmap(NULL, output->fb_info.buffer_length, |
| 403 | PROT_WRITE, MAP_SHARED, fd, 0); |
| 404 | if (output->fb == MAP_FAILED) { |
| 405 | weston_log("Failed to mmap frame buffer: %s\n", |
| 406 | strerror(errno)); |
| 407 | goto out_close; |
| 408 | } |
| 409 | |
| 410 | /* Create a pixman image to wrap the memory mapped frame buffer. */ |
| 411 | output->hw_surface = |
| 412 | pixman_image_create_bits(output->fb_info.pixel_format, |
| 413 | output->fb_info.x_resolution, |
| 414 | output->fb_info.y_resolution, |
| 415 | output->fb, |
| 416 | output->fb_info.line_length); |
| 417 | if (output->hw_surface == NULL) { |
| 418 | weston_log("Failed to create surface for frame buffer.\n"); |
| 419 | goto out_unmap; |
| 420 | } |
| 421 | |
| 422 | /* Success! */ |
| 423 | retval = 0; |
| 424 | |
| 425 | out_unmap: |
| 426 | if (retval != 0 && output->fb != NULL) |
| 427 | fbdev_frame_buffer_destroy(output); |
| 428 | |
| 429 | out_close: |
| 430 | if (fd >= 0) |
| 431 | close(fd); |
| 432 | |
| 433 | return retval; |
| 434 | } |
| 435 | |
| 436 | static void |
| 437 | fbdev_frame_buffer_destroy(struct fbdev_output *output) |
| 438 | { |
| 439 | weston_log("Destroying fbdev frame buffer.\n"); |
| 440 | |
| 441 | if (munmap(output->fb, output->fb_info.buffer_length) < 0) |
| 442 | weston_log("Failed to munmap frame buffer: %s\n", |
| 443 | strerror(errno)); |
| 444 | |
| 445 | output->fb = NULL; |
| 446 | } |
| 447 | |
| 448 | static void fbdev_output_destroy(struct weston_output *base); |
| 449 | static void fbdev_output_disable(struct weston_output *base); |
| 450 | |
| 451 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 452 | fbdev_output_create(struct fbdev_backend *backend, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 453 | const char *device) |
| 454 | { |
| 455 | struct fbdev_output *output; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 456 | int fb_fd; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 457 | struct wl_event_loop *loop; |
| 458 | |
| 459 | weston_log("Creating fbdev output.\n"); |
| 460 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 461 | output = zalloc(sizeof *output); |
| 462 | if (output == NULL) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 463 | return -1; |
| 464 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 465 | output->backend = backend; |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 466 | output->device = strdup(device); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 467 | |
| 468 | /* Create the frame buffer. */ |
| 469 | fb_fd = fbdev_frame_buffer_open(output, device, &output->fb_info); |
| 470 | if (fb_fd < 0) { |
| 471 | weston_log("Creating frame buffer failed.\n"); |
| 472 | goto out_free; |
| 473 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 474 | if (backend->use_pixman) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 475 | if (fbdev_frame_buffer_map(output, fb_fd) < 0) { |
| 476 | weston_log("Mapping frame buffer failed.\n"); |
| 477 | goto out_free; |
| 478 | } |
Kristian Høgsberg | 8ac6a2d | 2013-10-09 09:59:06 -0700 | [diff] [blame] | 479 | } else { |
| 480 | close(fb_fd); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 483 | output->base.start_repaint_loop = fbdev_output_start_repaint_loop; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 484 | output->base.repaint = fbdev_output_repaint; |
| 485 | output->base.destroy = fbdev_output_destroy; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 486 | |
| 487 | /* only one static mode in list */ |
| 488 | output->mode.flags = |
| 489 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 490 | output->mode.width = output->fb_info.x_resolution; |
| 491 | output->mode.height = output->fb_info.y_resolution; |
| 492 | output->mode.refresh = output->fb_info.refresh_rate; |
| 493 | wl_list_init(&output->base.mode_list); |
| 494 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 495 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 496 | output->base.current_mode = &output->mode; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 497 | output->base.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 498 | output->base.make = "unknown"; |
| 499 | output->base.model = output->fb_info.id; |
Derek Foreman | e516c3b | 2015-03-17 13:22:34 -0500 | [diff] [blame] | 500 | output->base.name = strdup("fbdev"); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 501 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 502 | weston_output_init(&output->base, backend->compositor, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 503 | 0, 0, output->fb_info.width_mm, |
| 504 | output->fb_info.height_mm, |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 505 | backend->output_transform, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 506 | 1); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 507 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 508 | if (backend->use_pixman) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 509 | if (pixman_renderer_output_create(&output->base) < 0) |
Sjoerd Simons | c112e0c | 2015-12-04 19:20:12 -0600 | [diff] [blame] | 510 | goto out_hw_surface; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 511 | } else { |
| 512 | setenv("HYBRIS_EGLPLATFORM", "wayland", 1); |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 513 | if (gl_renderer->output_create(&output->base, |
Jonny Lamb | 671148f | 2015-03-20 15:26:52 +0100 | [diff] [blame] | 514 | (EGLNativeWindowType)NULL, NULL, |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 515 | gl_renderer->opaque_attribs, |
Derek Foreman | e76f185 | 2015-05-15 12:12:39 -0500 | [diff] [blame] | 516 | NULL, 0) < 0) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 517 | weston_log("gl_renderer_output_create failed.\n"); |
Sjoerd Simons | c112e0c | 2015-12-04 19:20:12 -0600 | [diff] [blame] | 518 | goto out_hw_surface; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 522 | loop = wl_display_get_event_loop(backend->compositor->wl_display); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 523 | output->finish_frame_timer = |
| 524 | wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 525 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 526 | weston_compositor_add_output(backend->compositor, &output->base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 527 | |
| 528 | weston_log("fbdev output %d×%d px\n", |
| 529 | output->mode.width, output->mode.height); |
| 530 | weston_log_continue(STAMP_SPACE "guessing %d Hz and 96 dpi\n", |
| 531 | output->mode.refresh / 1000); |
| 532 | |
| 533 | return 0; |
| 534 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 535 | out_hw_surface: |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 536 | pixman_image_unref(output->hw_surface); |
| 537 | output->hw_surface = NULL; |
| 538 | weston_output_destroy(&output->base); |
| 539 | fbdev_frame_buffer_destroy(output); |
| 540 | out_free: |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 541 | free(output->device); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 542 | free(output); |
| 543 | |
| 544 | return -1; |
| 545 | } |
| 546 | |
| 547 | static void |
| 548 | fbdev_output_destroy(struct weston_output *base) |
| 549 | { |
| 550 | struct fbdev_output *output = to_fbdev_output(base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 551 | struct fbdev_backend *backend = output->backend; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 552 | |
| 553 | weston_log("Destroying fbdev output.\n"); |
| 554 | |
| 555 | /* Close the frame buffer. */ |
| 556 | fbdev_output_disable(base); |
| 557 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 558 | if (backend->use_pixman) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 559 | if (base->renderer_state != NULL) |
| 560 | pixman_renderer_output_destroy(base); |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 561 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 562 | gl_renderer->output_destroy(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /* Remove the output. */ |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 566 | weston_output_destroy(&output->base); |
| 567 | |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 568 | free(output->device); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 569 | free(output); |
| 570 | } |
| 571 | |
| 572 | /* strcmp()-style return values. */ |
| 573 | static int |
| 574 | compare_screen_info (const struct fbdev_screeninfo *a, |
| 575 | const struct fbdev_screeninfo *b) |
| 576 | { |
| 577 | if (a->x_resolution == b->x_resolution && |
| 578 | a->y_resolution == b->y_resolution && |
| 579 | a->width_mm == b->width_mm && |
| 580 | a->height_mm == b->height_mm && |
| 581 | a->bits_per_pixel == b->bits_per_pixel && |
| 582 | a->pixel_format == b->pixel_format && |
| 583 | a->refresh_rate == b->refresh_rate) |
| 584 | return 0; |
| 585 | |
| 586 | return 1; |
| 587 | } |
| 588 | |
| 589 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 590 | fbdev_output_reenable(struct fbdev_backend *backend, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 591 | struct weston_output *base) |
| 592 | { |
| 593 | struct fbdev_output *output = to_fbdev_output(base); |
| 594 | struct fbdev_screeninfo new_screen_info; |
| 595 | int fb_fd; |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 596 | char *device; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 597 | |
| 598 | weston_log("Re-enabling fbdev output.\n"); |
| 599 | |
| 600 | /* Create the frame buffer. */ |
| 601 | fb_fd = fbdev_frame_buffer_open(output, output->device, |
| 602 | &new_screen_info); |
| 603 | if (fb_fd < 0) { |
| 604 | weston_log("Creating frame buffer failed.\n"); |
| 605 | goto err; |
| 606 | } |
| 607 | |
| 608 | /* Check whether the frame buffer details have changed since we were |
| 609 | * disabled. */ |
| 610 | if (compare_screen_info (&output->fb_info, &new_screen_info) != 0) { |
| 611 | /* Perform a mode-set to restore the old mode. */ |
| 612 | if (fbdev_set_screen_info(output, fb_fd, |
| 613 | &output->fb_info) < 0) { |
| 614 | weston_log("Failed to restore mode settings. " |
| 615 | "Attempting to re-open output anyway.\n"); |
| 616 | } |
| 617 | |
Rob Bradford | 581b3fd | 2013-07-26 16:29:39 +0100 | [diff] [blame] | 618 | close(fb_fd); |
| 619 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 620 | /* Remove and re-add the output so that resources depending on |
| 621 | * the frame buffer X/Y resolution (such as the shadow buffer) |
| 622 | * are re-initialised. */ |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 623 | device = strdup(output->device); |
| 624 | fbdev_output_destroy(&output->base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 625 | fbdev_output_create(backend, device); |
Pekka Paalanen | e5b5659 | 2016-04-28 15:12:25 +0300 | [diff] [blame] | 626 | free(device); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | /* Map the device if it has the same details as before. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 632 | if (backend->use_pixman) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 633 | if (fbdev_frame_buffer_map(output, fb_fd) < 0) { |
| 634 | weston_log("Mapping frame buffer failed.\n"); |
| 635 | goto err; |
| 636 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | return 0; |
| 640 | |
| 641 | err: |
| 642 | return -1; |
| 643 | } |
| 644 | |
| 645 | /* NOTE: This leaves output->fb_info populated, caching data so that if |
| 646 | * fbdev_output_reenable() is called again, it can determine whether a mode-set |
| 647 | * is needed. */ |
| 648 | static void |
| 649 | fbdev_output_disable(struct weston_output *base) |
| 650 | { |
| 651 | struct fbdev_output *output = to_fbdev_output(base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 652 | struct fbdev_backend *backend = output->backend; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 653 | |
| 654 | weston_log("Disabling fbdev output.\n"); |
| 655 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 656 | if ( ! backend->use_pixman) return; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 657 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 658 | if (output->hw_surface != NULL) { |
| 659 | pixman_image_unref(output->hw_surface); |
| 660 | output->hw_surface = NULL; |
| 661 | } |
| 662 | |
| 663 | fbdev_frame_buffer_destroy(output); |
| 664 | } |
| 665 | |
| 666 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 667 | fbdev_backend_destroy(struct weston_compositor *base) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 668 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 669 | struct fbdev_backend *backend = to_fbdev_backend(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 670 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 671 | udev_input_destroy(&backend->input); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 672 | |
| 673 | /* Destroy the output. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 674 | weston_compositor_shutdown(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 675 | |
| 676 | /* Chain up. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 677 | weston_launcher_destroy(base->launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 678 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 679 | free(backend); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static void |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 683 | session_notify(struct wl_listener *listener, void *data) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 684 | { |
Pekka Paalanen | 3f89794 | 2015-08-19 13:52:47 +0300 | [diff] [blame] | 685 | struct weston_compositor *compositor = data; |
| 686 | struct fbdev_backend *backend = to_fbdev_backend(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 687 | struct weston_output *output; |
| 688 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 689 | if (compositor->session_active) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 690 | weston_log("entering VT\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 691 | compositor->state = backend->prev_state; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 692 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 693 | wl_list_for_each(output, &compositor->output_list, link) { |
| 694 | fbdev_output_reenable(backend, output); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 697 | weston_compositor_damage_all(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 698 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 699 | udev_input_enable(&backend->input); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 700 | } else { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 701 | weston_log("leaving VT\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 702 | udev_input_disable(&backend->input); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 703 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 704 | wl_list_for_each(output, &compositor->output_list, link) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 705 | fbdev_output_disable(output); |
| 706 | } |
| 707 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 708 | backend->prev_state = compositor->state; |
| 709 | weston_compositor_offscreen(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 710 | |
| 711 | /* If we have a repaint scheduled (from the idle handler), make |
| 712 | * 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] | 713 | * vt switched away. The OFFSCREEN state will prevent |
Bryce Harrington | c2be857 | 2015-12-11 13:11:37 -0800 | [diff] [blame] | 714 | * further attempts at repainting. When we switch |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 715 | * back, we schedule a repaint, which will process |
| 716 | * pending frame callbacks. */ |
| 717 | |
| 718 | wl_list_for_each(output, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 719 | &compositor->output_list, link) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 720 | output->repaint_needed = 0; |
| 721 | } |
nerdopolis | 3894670 | 2014-12-03 15:53:03 +0000 | [diff] [blame] | 722 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | static void |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 726 | fbdev_restore(struct weston_compositor *compositor) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 727 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 728 | weston_launcher_restore(compositor->launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 731 | static struct fbdev_backend * |
| 732 | fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv[], |
| 733 | struct weston_config *config, |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 734 | struct weston_fbdev_backend_config *param) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 735 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 736 | struct fbdev_backend *backend; |
Rob Bradford | 2387fde | 2013-05-31 18:09:57 +0100 | [diff] [blame] | 737 | const char *seat_id = default_seat; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 738 | |
| 739 | weston_log("initializing fbdev backend\n"); |
| 740 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 741 | backend = zalloc(sizeof *backend); |
| 742 | if (backend == NULL) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 743 | return NULL; |
| 744 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 745 | backend->compositor = compositor; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 746 | if (weston_compositor_set_presentation_clock_software( |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 747 | compositor) < 0) |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 748 | goto out_compositor; |
| 749 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 750 | backend->udev = udev_new(); |
| 751 | if (backend->udev == NULL) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 752 | weston_log("Failed to initialize udev context.\n"); |
| 753 | goto out_compositor; |
| 754 | } |
| 755 | |
| 756 | /* Set up the TTY. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 757 | backend->session_listener.notify = session_notify; |
| 758 | wl_signal_add(&compositor->session_signal, |
| 759 | &backend->session_listener); |
| 760 | compositor->launcher = |
| 761 | weston_launcher_connect(compositor, param->tty, "seat0", false); |
| 762 | if (!compositor->launcher) { |
David Herrmann | 1641d14 | 2013-10-15 14:29:57 +0200 | [diff] [blame] | 763 | weston_log("fatal: fbdev backend should be run " |
| 764 | "using weston-launch binary or as root\n"); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 765 | goto out_udev; |
| 766 | } |
| 767 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 768 | backend->base.destroy = fbdev_backend_destroy; |
| 769 | backend->base.restore = fbdev_restore; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 770 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 771 | backend->prev_state = WESTON_COMPOSITOR_ACTIVE; |
| 772 | backend->use_pixman = !param->use_gl; |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 773 | backend->output_transform = param->output_transform; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 774 | |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame] | 775 | weston_setup_vt_switch_bindings(compositor); |
| 776 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 777 | if (backend->use_pixman) { |
| 778 | if (pixman_renderer_init(compositor) < 0) |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 779 | goto out_launcher; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 780 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 781 | gl_renderer = weston_load_module("gl-renderer.so", |
| 782 | "gl_renderer_interface"); |
| 783 | if (!gl_renderer) { |
| 784 | weston_log("could not load gl renderer\n"); |
| 785 | goto out_launcher; |
| 786 | } |
| 787 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 788 | if (gl_renderer->create(compositor, NO_EGL_PLATFORM, |
Jonny Lamb | 74eed31 | 2015-03-24 13:12:04 +0100 | [diff] [blame] | 789 | EGL_DEFAULT_DISPLAY, |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 790 | gl_renderer->opaque_attribs, |
Derek Foreman | e76f185 | 2015-05-15 12:12:39 -0500 | [diff] [blame] | 791 | NULL, 0) < 0) { |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 792 | weston_log("gl_renderer_create failed.\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 793 | goto out_launcher; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 794 | } |
| 795 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 796 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 797 | if (fbdev_output_create(backend, param->device) < 0) |
Dawid Gajownik | 82d4925 | 2015-07-31 00:02:28 -0300 | [diff] [blame] | 798 | goto out_launcher; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 799 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 800 | udev_input_init(&backend->input, compositor, backend->udev, seat_id); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 801 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 802 | compositor->backend = &backend->base; |
| 803 | return backend; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 804 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 805 | out_launcher: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 806 | weston_launcher_destroy(compositor->launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 807 | |
| 808 | out_udev: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 809 | udev_unref(backend->udev); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 810 | |
| 811 | out_compositor: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 812 | weston_compositor_shutdown(compositor); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 813 | free(backend); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 814 | |
| 815 | return NULL; |
| 816 | } |
| 817 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 818 | static void |
| 819 | config_init_to_defaults(struct weston_fbdev_backend_config *config) |
| 820 | { |
| 821 | /* TODO: Ideally, available frame buffers should be enumerated using |
| 822 | * udev, rather than passing a device node in as a parameter. */ |
| 823 | config->tty = 0; /* default to current tty */ |
| 824 | config->device = "/dev/fb0"; /* default frame buffer */ |
| 825 | config->use_gl = 0; |
| 826 | config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 827 | } |
| 828 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 829 | WL_EXPORT int |
| 830 | backend_init(struct weston_compositor *compositor, int *argc, char *argv[], |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 831 | struct weston_config *wc, |
Giulio Camuffo | 93daabb | 2015-10-17 19:24:14 +0300 | [diff] [blame] | 832 | struct weston_backend_config *config_base) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 833 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 834 | struct fbdev_backend *b; |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 835 | struct weston_fbdev_backend_config config = {{ 0, }}; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 836 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 837 | if (config_base == NULL || |
| 838 | config_base->struct_version != WESTON_FBDEV_BACKEND_CONFIG_VERSION || |
| 839 | config_base->struct_size > sizeof(struct weston_fbdev_backend_config)) { |
| 840 | weston_log("fbdev backend config structure is invalid\n"); |
| 841 | return -1; |
| 842 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 843 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 844 | config_init_to_defaults(&config); |
| 845 | memcpy(&config, config_base, config_base->struct_size); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 846 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame^] | 847 | b = fbdev_backend_create(compositor, argc, argv, wc, &config); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 848 | if (b == NULL) |
| 849 | return -1; |
| 850 | return 0; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 851 | } |