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