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> |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 43 | #include <assert.h> |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 44 | |
| 45 | #include <libudev.h> |
| 46 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 47 | #include "shared/helpers.h" |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 48 | #include <libweston/libweston.h> |
Pekka Paalanen | 7571027 | 2019-03-29 16:39:12 +0200 | [diff] [blame] | 49 | #include <libweston/backend-fbdev.h> |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 50 | #include "launcher-util.h" |
| 51 | #include "pixman-renderer.h" |
Peter Hutterer | 823ad33 | 2014-11-26 07:06:31 +1000 | [diff] [blame] | 52 | #include "libinput-seat.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 53 | #include "presentation-time-server-protocol.h" |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 54 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 55 | struct fbdev_backend { |
| 56 | struct weston_backend base; |
| 57 | struct weston_compositor *compositor; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 58 | uint32_t prev_state; |
| 59 | |
| 60 | struct udev *udev; |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 61 | struct udev_input input; |
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 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 81 | struct fbdev_head { |
| 82 | struct weston_head base; |
| 83 | |
| 84 | /* Frame buffer details. */ |
| 85 | char *device; |
| 86 | struct fbdev_screeninfo fb_info; |
| 87 | }; |
| 88 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 89 | struct fbdev_output { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 90 | struct fbdev_backend *backend; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 91 | struct weston_output base; |
| 92 | |
| 93 | struct weston_mode mode; |
| 94 | struct wl_event_source *finish_frame_timer; |
| 95 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 96 | /* framebuffer mmap details */ |
| 97 | size_t buffer_length; |
| 98 | void *fb; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 99 | |
| 100 | /* pixman details. */ |
| 101 | pixman_image_t *hw_surface; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Kristian Høgsberg | 7e597f2 | 2013-02-18 16:35:26 -0500 | [diff] [blame] | 104 | static const char default_seat[] = "seat0"; |
| 105 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 106 | static inline struct fbdev_head * |
| 107 | to_fbdev_head(struct weston_head *base) |
| 108 | { |
| 109 | return container_of(base, struct fbdev_head, base); |
| 110 | } |
| 111 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 112 | static inline struct fbdev_output * |
| 113 | to_fbdev_output(struct weston_output *base) |
| 114 | { |
| 115 | return container_of(base, struct fbdev_output, base); |
| 116 | } |
| 117 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 118 | static inline struct fbdev_backend * |
| 119 | to_fbdev_backend(struct weston_compositor *base) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 120 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 121 | return container_of(base->backend, struct fbdev_backend, base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 124 | static struct fbdev_head * |
| 125 | fbdev_output_get_head(struct fbdev_output *output) |
| 126 | { |
| 127 | if (wl_list_length(&output->base.head_list) != 1) |
| 128 | return NULL; |
| 129 | |
| 130 | return container_of(output->base.head_list.next, |
| 131 | struct fbdev_head, base.output_link); |
| 132 | } |
| 133 | |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 134 | static int |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 135 | fbdev_output_start_repaint_loop(struct weston_output *output) |
| 136 | { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 137 | struct timespec ts; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 138 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 139 | weston_compositor_read_presentation_clock(output->compositor, &ts); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 140 | weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID); |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 141 | |
| 142 | return 0; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Pekka Paalanen | e77f8ad | 2016-06-08 17:39:37 +0300 | [diff] [blame] | 145 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 146 | fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage, |
| 147 | void *repaint_data) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 148 | { |
| 149 | struct fbdev_output *output = to_fbdev_output(base); |
| 150 | struct weston_compositor *ec = output->base.compositor; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 151 | |
| 152 | /* Repaint the damaged region onto the back buffer. */ |
Sjoerd Simons | c112e0c | 2015-12-04 19:20:12 -0600 | [diff] [blame] | 153 | pixman_renderer_output_set_buffer(base, output->hw_surface); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 154 | ec->renderer->repaint_output(base, damage); |
| 155 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 156 | /* Update the damage region. */ |
| 157 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 158 | &ec->primary_plane.damage, damage); |
| 159 | |
| 160 | /* Schedule the end of the frame. We do not sync this to the frame |
| 161 | * buffer clock because users who want that should be using the DRM |
| 162 | * compositor. FBIO_WAITFORVSYNC blocks and FB_ACTIVATE_VBL requires |
| 163 | * panning, which is broken in most kernel drivers. |
| 164 | * |
| 165 | * Finish the frame synchronised to the specified refresh rate. The |
| 166 | * refresh rate is given in mHz and the interval in ms. */ |
| 167 | wl_event_source_timer_update(output->finish_frame_timer, |
| 168 | 1000000 / output->mode.refresh); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 169 | |
| 170 | return 0; |
Adrian Negreanu | 4aa756d | 2013-09-06 15:16:09 +0300 | [diff] [blame] | 171 | } |
| 172 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 173 | static int |
| 174 | finish_frame_handler(void *data) |
| 175 | { |
| 176 | struct fbdev_output *output = data; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 177 | struct timespec ts; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 178 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 179 | weston_compositor_read_presentation_clock(output->base.compositor, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 180 | weston_output_finish_frame(&output->base, &ts, 0); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 181 | |
| 182 | return 1; |
| 183 | } |
| 184 | |
| 185 | static pixman_format_code_t |
| 186 | calculate_pixman_format(struct fb_var_screeninfo *vinfo, |
| 187 | struct fb_fix_screeninfo *finfo) |
| 188 | { |
| 189 | /* Calculate the pixman format supported by the frame buffer from the |
| 190 | * buffer's metadata. Return 0 if no known pixman format is supported |
| 191 | * (since this has depth 0 it's guaranteed to not conflict with any |
| 192 | * actual pixman format). |
| 193 | * |
| 194 | * Documentation on the vinfo and finfo structures: |
| 195 | * http://www.mjmwired.net/kernel/Documentation/fb/api.txt |
| 196 | * |
| 197 | * TODO: Try a bit harder to support other formats, including setting |
| 198 | * the preferred format in the hardware. */ |
| 199 | int type; |
| 200 | |
| 201 | weston_log("Calculating pixman format from:\n" |
| 202 | STAMP_SPACE " - type: %i (aux: %i)\n" |
| 203 | STAMP_SPACE " - visual: %i\n" |
| 204 | STAMP_SPACE " - bpp: %i (grayscale: %i)\n" |
| 205 | STAMP_SPACE " - red: offset: %i, length: %i, MSB: %i\n" |
| 206 | STAMP_SPACE " - green: offset: %i, length: %i, MSB: %i\n" |
| 207 | STAMP_SPACE " - blue: offset: %i, length: %i, MSB: %i\n" |
| 208 | STAMP_SPACE " - transp: offset: %i, length: %i, MSB: %i\n", |
| 209 | finfo->type, finfo->type_aux, finfo->visual, |
| 210 | vinfo->bits_per_pixel, vinfo->grayscale, |
| 211 | vinfo->red.offset, vinfo->red.length, vinfo->red.msb_right, |
| 212 | vinfo->green.offset, vinfo->green.length, |
| 213 | vinfo->green.msb_right, |
| 214 | vinfo->blue.offset, vinfo->blue.length, |
| 215 | vinfo->blue.msb_right, |
| 216 | vinfo->transp.offset, vinfo->transp.length, |
| 217 | vinfo->transp.msb_right); |
| 218 | |
| 219 | /* We only handle packed formats at the moment. */ |
| 220 | if (finfo->type != FB_TYPE_PACKED_PIXELS) |
| 221 | return 0; |
| 222 | |
| 223 | /* We only handle true-colour frame buffers at the moment. */ |
Dongjin Kim | ba89f00 | 2024-09-30 17:49:36 +0900 | [diff] [blame] | 224 | switch (finfo->visual) { |
Marc Chalain | ffbddff | 2013-09-03 16:47:43 +0200 | [diff] [blame] | 225 | case FB_VISUAL_TRUECOLOR: |
| 226 | case FB_VISUAL_DIRECTCOLOR: |
| 227 | if (vinfo->grayscale != 0) |
| 228 | return 0; |
| 229 | break; |
| 230 | default: |
| 231 | return 0; |
| 232 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 233 | |
| 234 | /* We only support formats with MSBs on the left. */ |
| 235 | if (vinfo->red.msb_right != 0 || vinfo->green.msb_right != 0 || |
| 236 | vinfo->blue.msb_right != 0) |
| 237 | return 0; |
| 238 | |
Pablo Castellano | f0ba93c | 2018-11-28 08:45:46 +0100 | [diff] [blame] | 239 | /* Work out the format type from the offsets. We only support RGBA, ARGB |
| 240 | * and ABGR at the moment. */ |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 241 | type = PIXMAN_TYPE_OTHER; |
| 242 | |
| 243 | if ((vinfo->transp.offset >= vinfo->red.offset || |
| 244 | vinfo->transp.length == 0) && |
| 245 | vinfo->red.offset >= vinfo->green.offset && |
| 246 | vinfo->green.offset >= vinfo->blue.offset) |
| 247 | type = PIXMAN_TYPE_ARGB; |
| 248 | else if (vinfo->red.offset >= vinfo->green.offset && |
| 249 | vinfo->green.offset >= vinfo->blue.offset && |
| 250 | vinfo->blue.offset >= vinfo->transp.offset) |
| 251 | type = PIXMAN_TYPE_RGBA; |
Pablo Castellano | f0ba93c | 2018-11-28 08:45:46 +0100 | [diff] [blame] | 252 | else if (vinfo->transp.offset >= vinfo->blue.offset && |
| 253 | vinfo->blue.offset >= vinfo->green.offset && |
| 254 | vinfo->green.offset >= vinfo->red.offset) |
| 255 | type = PIXMAN_TYPE_ABGR; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 256 | |
| 257 | if (type == PIXMAN_TYPE_OTHER) |
| 258 | return 0; |
| 259 | |
| 260 | /* Build the format. */ |
| 261 | return PIXMAN_FORMAT(vinfo->bits_per_pixel, type, |
| 262 | vinfo->transp.length, |
| 263 | vinfo->red.length, |
| 264 | vinfo->green.length, |
| 265 | vinfo->blue.length); |
| 266 | } |
| 267 | |
| 268 | static int |
| 269 | calculate_refresh_rate(struct fb_var_screeninfo *vinfo) |
| 270 | { |
| 271 | uint64_t quot; |
| 272 | |
| 273 | /* Calculate monitor refresh rate. Default is 60 Hz. Units are mHz. */ |
| 274 | quot = (vinfo->upper_margin + vinfo->lower_margin + vinfo->yres); |
| 275 | quot *= (vinfo->left_margin + vinfo->right_margin + vinfo->xres); |
| 276 | quot *= vinfo->pixclock; |
| 277 | |
| 278 | if (quot > 0) { |
| 279 | uint64_t refresh_rate; |
| 280 | |
| 281 | refresh_rate = 1000000000000000LLU / quot; |
| 282 | if (refresh_rate > 200000) |
| 283 | refresh_rate = 200000; /* cap at 200 Hz */ |
| 284 | |
Oliver Smith | a5066e0 | 2017-04-17 11:11:00 +0000 | [diff] [blame] | 285 | if (refresh_rate >= 1000) /* at least 1 Hz */ |
| 286 | return refresh_rate; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | return 60 * 1000; /* default to 60 Hz */ |
| 290 | } |
| 291 | |
| 292 | static int |
Pekka Paalanen | 82db6b7 | 2017-09-12 17:15:42 +0300 | [diff] [blame] | 293 | fbdev_query_screen_info(int fd, struct fbdev_screeninfo *info) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 294 | { |
| 295 | struct fb_var_screeninfo varinfo; |
| 296 | struct fb_fix_screeninfo fixinfo; |
| 297 | |
| 298 | /* Probe the device for screen information. */ |
| 299 | if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) < 0 || |
| 300 | ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 301 | return -1; |
| 302 | } |
| 303 | |
| 304 | /* Store the pertinent data. */ |
| 305 | info->x_resolution = varinfo.xres; |
| 306 | info->y_resolution = varinfo.yres; |
| 307 | info->width_mm = varinfo.width; |
| 308 | info->height_mm = varinfo.height; |
| 309 | info->bits_per_pixel = varinfo.bits_per_pixel; |
| 310 | |
| 311 | info->buffer_length = fixinfo.smem_len; |
| 312 | info->line_length = fixinfo.line_length; |
Derek Foreman | 6179338 | 2015-09-02 13:45:20 -0500 | [diff] [blame] | 313 | strncpy(info->id, fixinfo.id, sizeof(info->id)); |
Bryce Harrington | 44bbdd0 | 2015-09-23 17:39:05 -0700 | [diff] [blame] | 314 | info->id[sizeof(info->id)-1] = '\0'; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 315 | |
| 316 | info->pixel_format = calculate_pixman_format(&varinfo, &fixinfo); |
| 317 | info->refresh_rate = calculate_refresh_rate(&varinfo); |
| 318 | |
| 319 | if (info->pixel_format == 0) { |
| 320 | weston_log("Frame buffer uses an unsupported format.\n"); |
| 321 | return -1; |
| 322 | } |
| 323 | |
| 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | static int |
Pekka Paalanen | 82db6b7 | 2017-09-12 17:15:42 +0300 | [diff] [blame] | 328 | fbdev_set_screen_info(int fd, struct fbdev_screeninfo *info) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 329 | { |
| 330 | struct fb_var_screeninfo varinfo; |
| 331 | |
| 332 | /* Grab the current screen information. */ |
| 333 | if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 334 | return -1; |
| 335 | } |
| 336 | |
| 337 | /* Update the information. */ |
| 338 | varinfo.xres = info->x_resolution; |
| 339 | varinfo.yres = info->y_resolution; |
| 340 | varinfo.width = info->width_mm; |
| 341 | varinfo.height = info->height_mm; |
| 342 | varinfo.bits_per_pixel = info->bits_per_pixel; |
| 343 | |
| 344 | /* Try to set up an ARGB (x8r8g8b8) pixel format. */ |
| 345 | varinfo.grayscale = 0; |
| 346 | varinfo.transp.offset = 24; |
| 347 | varinfo.transp.length = 0; |
| 348 | varinfo.transp.msb_right = 0; |
| 349 | varinfo.red.offset = 16; |
| 350 | varinfo.red.length = 8; |
| 351 | varinfo.red.msb_right = 0; |
| 352 | varinfo.green.offset = 8; |
| 353 | varinfo.green.length = 8; |
| 354 | varinfo.green.msb_right = 0; |
| 355 | varinfo.blue.offset = 0; |
| 356 | varinfo.blue.length = 8; |
| 357 | varinfo.blue.msb_right = 0; |
| 358 | |
| 359 | /* Set the device's screen information. */ |
| 360 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &varinfo) < 0) { |
| 361 | return -1; |
| 362 | } |
| 363 | |
| 364 | return 1; |
| 365 | } |
| 366 | |
n3rdopolis | fa2742b | 2019-01-09 01:59:58 +0000 | [diff] [blame] | 367 | static int |
| 368 | fbdev_wakeup_screen(int fd, struct fbdev_screeninfo *info) |
| 369 | { |
| 370 | struct fb_var_screeninfo varinfo; |
| 371 | |
| 372 | /* Grab the current screen information. */ |
| 373 | if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { |
| 374 | return -1; |
| 375 | } |
| 376 | |
| 377 | /* force the framebuffer to wake up */ |
| 378 | varinfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE; |
| 379 | |
| 380 | /* Set the device's screen information. */ |
| 381 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &varinfo) < 0) { |
| 382 | return -1; |
| 383 | } |
| 384 | |
| 385 | return 1; |
| 386 | } |
| 387 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 388 | /* Returns an FD for the frame buffer device. */ |
| 389 | static int |
Pekka Paalanen | 82db6b7 | 2017-09-12 17:15:42 +0300 | [diff] [blame] | 390 | fbdev_frame_buffer_open(const char *fb_dev, |
| 391 | struct fbdev_screeninfo *screen_info) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 392 | { |
| 393 | int fd = -1; |
| 394 | |
| 395 | weston_log("Opening fbdev frame buffer.\n"); |
| 396 | |
| 397 | /* Open the frame buffer device. */ |
| 398 | fd = open(fb_dev, O_RDWR | O_CLOEXEC); |
| 399 | if (fd < 0) { |
| 400 | weston_log("Failed to open frame buffer device ‘%s’: %s\n", |
| 401 | fb_dev, strerror(errno)); |
| 402 | return -1; |
| 403 | } |
| 404 | |
| 405 | /* Grab the screen info. */ |
Pekka Paalanen | 82db6b7 | 2017-09-12 17:15:42 +0300 | [diff] [blame] | 406 | if (fbdev_query_screen_info(fd, screen_info) < 0) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 407 | weston_log("Failed to get frame buffer info: %s\n", |
| 408 | strerror(errno)); |
| 409 | |
| 410 | close(fd); |
| 411 | return -1; |
| 412 | } |
| 413 | |
nerdopolis | 92a06a9 | 2018-06-29 08:17:49 -0400 | [diff] [blame] | 414 | /* Attempt to wake up the framebuffer device, needed for secondary |
| 415 | * framebuffer devices */ |
n3rdopolis | fa2742b | 2019-01-09 01:59:58 +0000 | [diff] [blame] | 416 | if (fbdev_wakeup_screen(fd, screen_info) < 0) { |
| 417 | weston_log("Failed to activate framebuffer display. " |
nerdopolis | 92a06a9 | 2018-06-29 08:17:49 -0400 | [diff] [blame] | 418 | "Attempting to open output anyway.\n"); |
| 419 | } |
| 420 | |
| 421 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 422 | return fd; |
| 423 | } |
| 424 | |
| 425 | /* Closes the FD on success or failure. */ |
| 426 | static int |
| 427 | fbdev_frame_buffer_map(struct fbdev_output *output, int fd) |
| 428 | { |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 429 | struct fbdev_head *head; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 430 | int retval = -1; |
| 431 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 432 | head = fbdev_output_get_head(output); |
| 433 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 434 | weston_log("Mapping fbdev frame buffer.\n"); |
| 435 | |
| 436 | /* Map the frame buffer. Write-only mode, since we don't want to read |
| 437 | * anything back (because it's slow). */ |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 438 | output->buffer_length = head->fb_info.buffer_length; |
| 439 | output->fb = mmap(NULL, output->buffer_length, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 440 | PROT_WRITE, MAP_SHARED, fd, 0); |
| 441 | if (output->fb == MAP_FAILED) { |
| 442 | weston_log("Failed to mmap frame buffer: %s\n", |
| 443 | strerror(errno)); |
Pekka Paalanen | 82b8ddf | 2017-09-13 11:58:00 +0300 | [diff] [blame] | 444 | output->fb = NULL; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 445 | goto out_close; |
| 446 | } |
| 447 | |
| 448 | /* Create a pixman image to wrap the memory mapped frame buffer. */ |
| 449 | output->hw_surface = |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 450 | pixman_image_create_bits(head->fb_info.pixel_format, |
| 451 | head->fb_info.x_resolution, |
| 452 | head->fb_info.y_resolution, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 453 | output->fb, |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 454 | head->fb_info.line_length); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 455 | if (output->hw_surface == NULL) { |
| 456 | weston_log("Failed to create surface for frame buffer.\n"); |
| 457 | goto out_unmap; |
| 458 | } |
| 459 | |
| 460 | /* Success! */ |
| 461 | retval = 0; |
| 462 | |
| 463 | out_unmap: |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 464 | if (retval != 0 && output->fb != NULL) { |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 465 | munmap(output->fb, output->buffer_length); |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 466 | output->fb = NULL; |
| 467 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 468 | |
| 469 | out_close: |
| 470 | if (fd >= 0) |
| 471 | close(fd); |
| 472 | |
| 473 | return retval; |
| 474 | } |
| 475 | |
| 476 | static void |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 477 | fbdev_frame_buffer_unmap(struct fbdev_output *output) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 478 | { |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 479 | if (!output->fb) { |
| 480 | assert(!output->hw_surface); |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | weston_log("Unmapping fbdev frame buffer.\n"); |
| 485 | |
| 486 | if (output->hw_surface) |
| 487 | pixman_image_unref(output->hw_surface); |
| 488 | output->hw_surface = NULL; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 489 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 490 | if (munmap(output->fb, output->buffer_length) < 0) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 491 | weston_log("Failed to munmap frame buffer: %s\n", |
| 492 | strerror(errno)); |
| 493 | |
| 494 | output->fb = NULL; |
| 495 | } |
| 496 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 497 | |
| 498 | static int |
| 499 | fbdev_output_attach_head(struct weston_output *output_base, |
| 500 | struct weston_head *head_base) |
| 501 | { |
| 502 | struct fbdev_output *output = to_fbdev_output(output_base); |
| 503 | struct fbdev_head *head = to_fbdev_head(head_base); |
| 504 | |
| 505 | /* Clones not supported. */ |
| 506 | if (!wl_list_empty(&output->base.head_list)) |
| 507 | return -1; |
| 508 | |
| 509 | /* only one static mode in list */ |
| 510 | output->mode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 511 | output->mode.width = head->fb_info.x_resolution; |
| 512 | output->mode.height = head->fb_info.y_resolution; |
| 513 | output->mode.refresh = head->fb_info.refresh_rate; |
| 514 | wl_list_init(&output->base.mode_list); |
| 515 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 516 | output->base.current_mode = &output->mode; |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 521 | static void fbdev_output_destroy(struct weston_output *base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 522 | |
| 523 | static int |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 524 | fbdev_output_enable(struct weston_output *base) |
| 525 | { |
| 526 | struct fbdev_output *output = to_fbdev_output(base); |
| 527 | struct fbdev_backend *backend = to_fbdev_backend(base->compositor); |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 528 | struct fbdev_head *head; |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 529 | int fb_fd; |
| 530 | struct wl_event_loop *loop; |
Daniel Stone | 61abf35 | 2020-03-06 12:46:30 +0000 | [diff] [blame] | 531 | const struct pixman_renderer_output_options options = { |
| 532 | .use_shadow = true, |
| 533 | }; |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 534 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 535 | head = fbdev_output_get_head(output); |
| 536 | |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 537 | /* Create the frame buffer. */ |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 538 | fb_fd = fbdev_frame_buffer_open(head->device, &head->fb_info); |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 539 | if (fb_fd < 0) { |
| 540 | weston_log("Creating frame buffer failed.\n"); |
| 541 | return -1; |
| 542 | } |
| 543 | |
| 544 | if (fbdev_frame_buffer_map(output, fb_fd) < 0) { |
| 545 | weston_log("Mapping frame buffer failed.\n"); |
| 546 | return -1; |
| 547 | } |
| 548 | |
| 549 | output->base.start_repaint_loop = fbdev_output_start_repaint_loop; |
| 550 | output->base.repaint = fbdev_output_repaint; |
| 551 | |
Daniel Stone | 61abf35 | 2020-03-06 12:46:30 +0000 | [diff] [blame] | 552 | if (pixman_renderer_output_create(&output->base, &options) < 0) |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 553 | goto out_hw_surface; |
| 554 | |
| 555 | loop = wl_display_get_event_loop(backend->compositor->wl_display); |
| 556 | output->finish_frame_timer = |
| 557 | wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 558 | |
| 559 | weston_log("fbdev output %d×%d px\n", |
| 560 | output->mode.width, output->mode.height); |
| 561 | weston_log_continue(STAMP_SPACE "guessing %d Hz and 96 dpi\n", |
| 562 | output->mode.refresh / 1000); |
| 563 | |
| 564 | return 0; |
| 565 | |
| 566 | out_hw_surface: |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 567 | fbdev_frame_buffer_unmap(output); |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 568 | |
| 569 | return -1; |
| 570 | } |
| 571 | |
| 572 | static int |
Pekka Paalanen | 82ffe79 | 2017-09-13 17:25:41 +0300 | [diff] [blame] | 573 | fbdev_output_disable(struct weston_output *base) |
Pekka Paalanen | acd71fb | 2017-08-15 10:35:09 +0300 | [diff] [blame] | 574 | { |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 575 | struct fbdev_output *output = to_fbdev_output(base); |
| 576 | |
Pekka Paalanen | acd71fb | 2017-08-15 10:35:09 +0300 | [diff] [blame] | 577 | if (!base->enabled) |
| 578 | return 0; |
| 579 | |
Pekka Paalanen | cbe7fb0 | 2017-09-14 11:43:29 +0300 | [diff] [blame] | 580 | wl_event_source_remove(output->finish_frame_timer); |
| 581 | output->finish_frame_timer = NULL; |
| 582 | |
Pekka Paalanen | 61e5a27 | 2017-09-13 17:22:38 +0300 | [diff] [blame] | 583 | pixman_renderer_output_destroy(&output->base); |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 584 | fbdev_frame_buffer_unmap(output); |
Pekka Paalanen | acd71fb | 2017-08-15 10:35:09 +0300 | [diff] [blame] | 585 | |
Pekka Paalanen | acd71fb | 2017-08-15 10:35:09 +0300 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 589 | static struct fbdev_head * |
| 590 | fbdev_head_create(struct fbdev_backend *backend, const char *device) |
| 591 | { |
| 592 | struct fbdev_head *head; |
| 593 | int fb_fd; |
| 594 | |
| 595 | head = zalloc(sizeof *head); |
| 596 | if (!head) |
| 597 | return NULL; |
| 598 | |
| 599 | head->device = strdup(device); |
| 600 | |
| 601 | /* Create the frame buffer. */ |
| 602 | fb_fd = fbdev_frame_buffer_open(head->device, &head->fb_info); |
| 603 | if (fb_fd < 0) { |
| 604 | weston_log("Creating frame buffer head failed.\n"); |
| 605 | goto out_free; |
| 606 | } |
| 607 | close(fb_fd); |
| 608 | |
| 609 | weston_head_init(&head->base, "fbdev"); |
| 610 | weston_head_set_connection_status(&head->base, true); |
| 611 | weston_head_set_monitor_strings(&head->base, "unknown", |
| 612 | head->fb_info.id, NULL); |
| 613 | weston_head_set_subpixel(&head->base, WL_OUTPUT_SUBPIXEL_UNKNOWN); |
| 614 | weston_head_set_physical_size(&head->base, head->fb_info.width_mm, |
| 615 | head->fb_info.height_mm); |
| 616 | |
| 617 | weston_compositor_add_head(backend->compositor, &head->base); |
| 618 | |
| 619 | weston_log("Created head '%s' for device %s (%s)\n", |
| 620 | head->base.name, head->device, head->base.model); |
| 621 | |
| 622 | return head; |
| 623 | |
| 624 | out_free: |
| 625 | free(head->device); |
| 626 | free(head); |
| 627 | |
| 628 | return NULL; |
| 629 | } |
| 630 | |
| 631 | static void |
| 632 | fbdev_head_destroy(struct fbdev_head *head) |
| 633 | { |
| 634 | weston_head_release(&head->base); |
| 635 | free(head->device); |
| 636 | free(head); |
| 637 | } |
| 638 | |
| 639 | static struct weston_output * |
| 640 | fbdev_output_create(struct weston_compositor *compositor, |
| 641 | const char *name) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 642 | { |
| 643 | struct fbdev_output *output; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 644 | |
| 645 | weston_log("Creating fbdev output.\n"); |
| 646 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 647 | output = zalloc(sizeof *output); |
| 648 | if (output == NULL) |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 649 | return NULL; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 650 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 651 | output->backend = to_fbdev_backend(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 652 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 653 | weston_output_init(&output->base, compositor, name); |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 654 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 655 | output->base.destroy = fbdev_output_destroy; |
Pekka Paalanen | 82ffe79 | 2017-09-13 17:25:41 +0300 | [diff] [blame] | 656 | output->base.disable = fbdev_output_disable; |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 657 | output->base.enable = fbdev_output_enable; |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 658 | output->base.attach_head = fbdev_output_attach_head; |
Armin Krezović | 6ba369d | 2016-09-30 14:11:06 +0200 | [diff] [blame] | 659 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 660 | weston_compositor_add_pending_output(&output->base, compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 661 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 662 | return &output->base; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static void |
| 666 | fbdev_output_destroy(struct weston_output *base) |
| 667 | { |
| 668 | struct fbdev_output *output = to_fbdev_output(base); |
| 669 | |
| 670 | weston_log("Destroying fbdev output.\n"); |
| 671 | |
Pekka Paalanen | 82ffe79 | 2017-09-13 17:25:41 +0300 | [diff] [blame] | 672 | fbdev_output_disable(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 673 | |
| 674 | /* Remove the output. */ |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 675 | weston_output_release(&output->base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 676 | |
| 677 | free(output); |
| 678 | } |
| 679 | |
| 680 | /* strcmp()-style return values. */ |
| 681 | static int |
| 682 | compare_screen_info (const struct fbdev_screeninfo *a, |
| 683 | const struct fbdev_screeninfo *b) |
| 684 | { |
| 685 | if (a->x_resolution == b->x_resolution && |
| 686 | a->y_resolution == b->y_resolution && |
| 687 | a->width_mm == b->width_mm && |
| 688 | a->height_mm == b->height_mm && |
| 689 | a->bits_per_pixel == b->bits_per_pixel && |
| 690 | a->pixel_format == b->pixel_format && |
| 691 | a->refresh_rate == b->refresh_rate) |
| 692 | return 0; |
| 693 | |
| 694 | return 1; |
| 695 | } |
| 696 | |
| 697 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 698 | fbdev_output_reenable(struct fbdev_backend *backend, |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 699 | struct weston_output *base) |
| 700 | { |
| 701 | struct fbdev_output *output = to_fbdev_output(base); |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 702 | struct fbdev_head *head; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 703 | struct fbdev_screeninfo new_screen_info; |
| 704 | int fb_fd; |
| 705 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 706 | head = fbdev_output_get_head(output); |
| 707 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 708 | weston_log("Re-enabling fbdev output.\n"); |
Pekka Paalanen | 55916d5 | 2017-09-13 16:19:02 +0300 | [diff] [blame] | 709 | assert(output->base.enabled); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 710 | |
| 711 | /* Create the frame buffer. */ |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 712 | fb_fd = fbdev_frame_buffer_open(head->device, &new_screen_info); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 713 | if (fb_fd < 0) { |
| 714 | weston_log("Creating frame buffer failed.\n"); |
Pekka Paalanen | 55916d5 | 2017-09-13 16:19:02 +0300 | [diff] [blame] | 715 | return -1; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | /* Check whether the frame buffer details have changed since we were |
| 719 | * disabled. */ |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 720 | if (compare_screen_info(&head->fb_info, &new_screen_info) != 0) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 721 | /* Perform a mode-set to restore the old mode. */ |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 722 | if (fbdev_set_screen_info(fb_fd, &head->fb_info) < 0) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 723 | weston_log("Failed to restore mode settings. " |
| 724 | "Attempting to re-open output anyway.\n"); |
| 725 | } |
| 726 | |
Rob Bradford | 581b3fd | 2013-07-26 16:29:39 +0100 | [diff] [blame] | 727 | close(fb_fd); |
| 728 | |
Pekka Paalanen | 55916d5 | 2017-09-13 16:19:02 +0300 | [diff] [blame] | 729 | /* Disable and enable the output so that resources depending on |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 730 | * the frame buffer X/Y resolution (such as the shadow buffer) |
| 731 | * are re-initialised. */ |
Pekka Paalanen | 55916d5 | 2017-09-13 16:19:02 +0300 | [diff] [blame] | 732 | fbdev_output_disable(&output->base); |
| 733 | return fbdev_output_enable(&output->base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /* Map the device if it has the same details as before. */ |
Pekka Paalanen | e77f8ad | 2016-06-08 17:39:37 +0300 | [diff] [blame] | 737 | if (fbdev_frame_buffer_map(output, fb_fd) < 0) { |
| 738 | weston_log("Mapping frame buffer failed.\n"); |
Pekka Paalanen | 55916d5 | 2017-09-13 16:19:02 +0300 | [diff] [blame] | 739 | return -1; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | return 0; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 745 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 746 | fbdev_backend_destroy(struct weston_compositor *base) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 747 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 748 | struct fbdev_backend *backend = to_fbdev_backend(base); |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 749 | struct weston_head *head, *next; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 750 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 751 | udev_input_destroy(&backend->input); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 752 | |
| 753 | /* Destroy the output. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 754 | weston_compositor_shutdown(base); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 755 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 756 | wl_list_for_each_safe(head, next, &base->head_list, compositor_link) |
| 757 | fbdev_head_destroy(to_fbdev_head(head)); |
| 758 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 759 | /* Chain up. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 760 | weston_launcher_destroy(base->launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 761 | |
Pekka Paalanen | 513f9a4 | 2017-09-13 16:49:02 +0300 | [diff] [blame] | 762 | udev_unref(backend->udev); |
| 763 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 764 | free(backend); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static void |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 768 | session_notify(struct wl_listener *listener, void *data) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 769 | { |
Pekka Paalanen | 3f89794 | 2015-08-19 13:52:47 +0300 | [diff] [blame] | 770 | struct weston_compositor *compositor = data; |
| 771 | struct fbdev_backend *backend = to_fbdev_backend(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 772 | struct weston_output *output; |
| 773 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 774 | if (compositor->session_active) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 775 | weston_log("entering VT\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 776 | compositor->state = backend->prev_state; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 777 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 778 | wl_list_for_each(output, &compositor->output_list, link) { |
| 779 | fbdev_output_reenable(backend, output); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 782 | weston_compositor_damage_all(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 783 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 784 | udev_input_enable(&backend->input); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 785 | } else { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 786 | weston_log("leaving VT\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 787 | udev_input_disable(&backend->input); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 788 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 789 | wl_list_for_each(output, &compositor->output_list, link) { |
Pekka Paalanen | a51e71f | 2017-09-13 17:14:19 +0300 | [diff] [blame] | 790 | fbdev_frame_buffer_unmap(to_fbdev_output(output)); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 793 | backend->prev_state = compositor->state; |
| 794 | weston_compositor_offscreen(compositor); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 795 | |
| 796 | /* If we have a repaint scheduled (from the idle handler), make |
| 797 | * 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] | 798 | * vt switched away. The OFFSCREEN state will prevent |
Bryce Harrington | c2be857 | 2015-12-11 13:11:37 -0800 | [diff] [blame] | 799 | * further attempts at repainting. When we switch |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 800 | * back, we schedule a repaint, which will process |
| 801 | * pending frame callbacks. */ |
| 802 | |
| 803 | wl_list_for_each(output, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 804 | &compositor->output_list, link) { |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 805 | output->repaint_needed = false; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 806 | } |
nerdopolis | 3894670 | 2014-12-03 15:53:03 +0000 | [diff] [blame] | 807 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 808 | } |
| 809 | |
nerdopolis | 4381040 | 2018-06-29 08:17:50 -0400 | [diff] [blame] | 810 | static char * |
| 811 | find_framebuffer_device(struct fbdev_backend *b, const char *seat) |
| 812 | { |
| 813 | struct udev_enumerate *e; |
| 814 | struct udev_list_entry *entry; |
| 815 | const char *path, *device_seat, *id; |
| 816 | char *fb_device_path = NULL; |
| 817 | struct udev_device *device, *fb_device, *pci; |
| 818 | |
| 819 | e = udev_enumerate_new(b->udev); |
| 820 | udev_enumerate_add_match_subsystem(e, "graphics"); |
| 821 | udev_enumerate_add_match_sysname(e, "fb[0-9]*"); |
| 822 | |
| 823 | udev_enumerate_scan_devices(e); |
| 824 | fb_device = NULL; |
| 825 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 826 | bool is_boot_vga = false; |
| 827 | |
| 828 | path = udev_list_entry_get_name(entry); |
| 829 | device = udev_device_new_from_syspath(b->udev, path); |
| 830 | if (!device) |
| 831 | continue; |
| 832 | device_seat = udev_device_get_property_value(device, "ID_SEAT"); |
| 833 | if (!device_seat) |
| 834 | device_seat = default_seat; |
| 835 | if (strcmp(device_seat, seat)) { |
| 836 | udev_device_unref(device); |
| 837 | continue; |
| 838 | } |
| 839 | |
| 840 | pci = udev_device_get_parent_with_subsystem_devtype(device, |
| 841 | "pci", NULL); |
| 842 | if (pci) { |
| 843 | id = udev_device_get_sysattr_value(pci, "boot_vga"); |
| 844 | if (id && !strcmp(id, "1")) |
| 845 | is_boot_vga = true; |
| 846 | } |
| 847 | |
| 848 | /* If a framebuffer device was found, and this device isn't |
| 849 | * the boot-VGA device, don't use it. */ |
| 850 | if (!is_boot_vga && fb_device) { |
| 851 | udev_device_unref(device); |
| 852 | continue; |
| 853 | } |
| 854 | |
| 855 | /* There can only be one boot_vga device. Try to use it |
| 856 | * at all costs. */ |
| 857 | if (is_boot_vga) { |
| 858 | if (fb_device) |
| 859 | udev_device_unref(fb_device); |
| 860 | fb_device = device; |
| 861 | break; |
| 862 | } |
| 863 | |
| 864 | /* Per the (!is_boot_vga && fb_device) test above, only |
| 865 | * trump existing saved devices with boot-VGA devices, so if |
| 866 | * the test ends up here, this must be the first device seen. */ |
| 867 | assert(!fb_device); |
| 868 | fb_device = device; |
| 869 | } |
| 870 | |
| 871 | udev_enumerate_unref(e); |
| 872 | |
| 873 | if (fb_device) { |
| 874 | fb_device_path = strdup(udev_device_get_devnode(fb_device)); |
| 875 | udev_device_unref(fb_device); |
| 876 | } |
| 877 | |
| 878 | return fb_device_path; |
| 879 | } |
| 880 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 881 | static struct fbdev_backend * |
Pekka Paalanen | a256c5e | 2016-06-03 14:56:18 +0300 | [diff] [blame] | 882 | fbdev_backend_create(struct weston_compositor *compositor, |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 883 | struct weston_fbdev_backend_config *param) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 884 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 885 | struct fbdev_backend *backend; |
Rob Bradford | 2387fde | 2013-05-31 18:09:57 +0100 | [diff] [blame] | 886 | const char *seat_id = default_seat; |
nerdopolis | d68109b | 2018-06-29 08:17:47 -0400 | [diff] [blame] | 887 | const char *session_seat; |
| 888 | |
| 889 | session_seat = getenv("XDG_SEAT"); |
| 890 | if (session_seat) |
| 891 | seat_id = session_seat; |
| 892 | if (param->seat_id) |
| 893 | seat_id = param->seat_id; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 894 | |
| 895 | weston_log("initializing fbdev backend\n"); |
Simon Ser | 6338dbd | 2022-01-20 13:27:52 +0100 | [diff] [blame] | 896 | weston_log("warning: the fbdev backend is deprecated, please migrate " |
| 897 | "to the DRM backend\n"); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 898 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 899 | backend = zalloc(sizeof *backend); |
| 900 | if (backend == NULL) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 901 | return NULL; |
| 902 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 903 | backend->compositor = compositor; |
Pekka Paalanen | 7da9a38 | 2017-08-30 11:29:49 +0300 | [diff] [blame] | 904 | compositor->backend = &backend->base; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 905 | if (weston_compositor_set_presentation_clock_software( |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 906 | compositor) < 0) |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 907 | goto out_compositor; |
| 908 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 909 | backend->udev = udev_new(); |
| 910 | if (backend->udev == NULL) { |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 911 | weston_log("Failed to initialize udev context.\n"); |
| 912 | goto out_compositor; |
| 913 | } |
| 914 | |
nerdopolis | 4381040 | 2018-06-29 08:17:50 -0400 | [diff] [blame] | 915 | if (!param->device) |
| 916 | param->device = find_framebuffer_device(backend, seat_id); |
| 917 | if (!param->device) { |
| 918 | weston_log("fatal: no framebuffer devices detected.\n"); |
| 919 | goto out_udev; |
| 920 | } |
| 921 | |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 922 | /* Set up the TTY. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 923 | backend->session_listener.notify = session_notify; |
| 924 | wl_signal_add(&compositor->session_signal, |
| 925 | &backend->session_listener); |
| 926 | compositor->launcher = |
nerdopolis | d68109b | 2018-06-29 08:17:47 -0400 | [diff] [blame] | 927 | weston_launcher_connect(compositor, param->tty, seat_id, false); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 928 | if (!compositor->launcher) { |
Pekka Paalanen | a453f4d | 2017-10-31 10:19:48 +0200 | [diff] [blame] | 929 | weston_log("fatal: fbdev backend should be run using " |
| 930 | "weston-launch binary, or your system should " |
| 931 | "provide the logind D-Bus API.\n"); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 932 | goto out_udev; |
| 933 | } |
| 934 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 935 | backend->base.destroy = fbdev_backend_destroy; |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 936 | backend->base.create_output = fbdev_output_create; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 937 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 938 | backend->prev_state = WESTON_COMPOSITOR_ACTIVE; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 939 | |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame] | 940 | weston_setup_vt_switch_bindings(compositor); |
| 941 | |
Pekka Paalanen | e77f8ad | 2016-06-08 17:39:37 +0300 | [diff] [blame] | 942 | if (pixman_renderer_init(compositor) < 0) |
| 943 | goto out_launcher; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 944 | |
Pekka Paalanen | 2305812 | 2017-09-14 16:50:44 +0300 | [diff] [blame] | 945 | if (!fbdev_head_create(backend, param->device)) |
Dawid Gajownik | 82d4925 | 2015-07-31 00:02:28 -0300 | [diff] [blame] | 946 | goto out_launcher; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 947 | |
nerdopolis | 4381040 | 2018-06-29 08:17:50 -0400 | [diff] [blame] | 948 | free(param->device); |
| 949 | |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 950 | udev_input_init(&backend->input, compositor, backend->udev, |
| 951 | seat_id, param->configure_device); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 952 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 953 | return backend; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 954 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 955 | out_launcher: |
nerdopolis | 4381040 | 2018-06-29 08:17:50 -0400 | [diff] [blame] | 956 | free(param->device); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 957 | weston_launcher_destroy(compositor->launcher); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 958 | |
| 959 | out_udev: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 960 | udev_unref(backend->udev); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 961 | |
| 962 | out_compositor: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 963 | weston_compositor_shutdown(compositor); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 964 | free(backend); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 965 | |
| 966 | return NULL; |
| 967 | } |
| 968 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 969 | static void |
| 970 | config_init_to_defaults(struct weston_fbdev_backend_config *config) |
| 971 | { |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 972 | config->tty = 0; /* default to current tty */ |
nerdopolis | 4381040 | 2018-06-29 08:17:50 -0400 | [diff] [blame] | 973 | config->device = NULL; |
nerdopolis | d68109b | 2018-06-29 08:17:47 -0400 | [diff] [blame] | 974 | config->seat_id = NULL; |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 975 | } |
| 976 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 977 | WL_EXPORT int |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 978 | weston_backend_init(struct weston_compositor *compositor, |
| 979 | struct weston_backend_config *config_base) |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 980 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 981 | struct fbdev_backend *b; |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 982 | struct weston_fbdev_backend_config config = {{ 0, }}; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 983 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 984 | if (config_base == NULL || |
| 985 | config_base->struct_version != WESTON_FBDEV_BACKEND_CONFIG_VERSION || |
| 986 | config_base->struct_size > sizeof(struct weston_fbdev_backend_config)) { |
| 987 | weston_log("fbdev backend config structure is invalid\n"); |
| 988 | return -1; |
| 989 | } |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 990 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 991 | config_init_to_defaults(&config); |
| 992 | memcpy(&config, config_base, config_base->struct_size); |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 993 | |
Pekka Paalanen | a256c5e | 2016-06-03 14:56:18 +0300 | [diff] [blame] | 994 | b = fbdev_backend_create(compositor, &config); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 995 | if (b == NULL) |
| 996 | return -1; |
| 997 | return 0; |
Philip Withnall | 4f49917 | 2013-02-02 12:02:32 +0000 | [diff] [blame] | 998 | } |