2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2011 Intel Corporation
4 * Copyright © 2012 Raspberry Pi Foundation
5 * Copyright © 2013 Philip Withnall
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of the copyright holders not be used in
12 * advertising or publicity pertaining to distribution of the software
13 * without specific, written prior permission. The copyright holders make
14 * no representations about the suitability of this software for any
15 * purpose. It is provided "as is" without express or implied warranty.
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
22 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 #include <sys/types.h>
38 #include <linux/input.h>
44 #include "compositor.h"
45 #include "launcher-util.h"
46 #include "pixman-renderer.h"
47 #include "udev-seat.h"
49 struct fbdev_compositor {
50 struct weston_compositor base;
57 struct fbdev_screeninfo {
58 unsigned int x_resolution; /* pixels, visible area */
59 unsigned int y_resolution; /* pixels, visible area */
60 unsigned int width_mm; /* visible screen width in mm */
61 unsigned int height_mm; /* visible screen height in mm */
62 unsigned int bits_per_pixel;
64 size_t buffer_length; /* length of frame buffer memory in bytes */
65 size_t line_length; /* length of a line in bytes */
66 char id[16]; /* screen identifier */
68 pixman_format_code_t pixel_format; /* frame buffer pixel format */
69 unsigned int refresh_rate; /* Hertz */
73 struct fbdev_compositor *compositor;
74 struct weston_output base;
76 struct weston_mode mode;
77 struct wl_event_source *finish_frame_timer;
79 /* Frame buffer details. */
80 const char *device; /* ownership shared with fbdev_parameters */
81 struct fbdev_screeninfo fb_info;
82 void *fb; /* length is fb_info.buffer_length */
85 pixman_image_t *hw_surface;
86 pixman_image_t *shadow_surface;
92 struct weston_seat base;
93 struct wl_list devices_list;
95 struct udev_monitor *udev_monitor;
96 struct wl_event_source *udev_monitor_source;
100 struct fbdev_parameters {
105 static const char default_seat[] = "seat0";
107 static inline struct fbdev_output *
108 to_fbdev_output(struct weston_output *base)
110 return container_of(base, struct fbdev_output, base);
113 static inline struct fbdev_seat *
114 to_fbdev_seat(struct weston_seat *base)
116 return container_of(base, struct fbdev_seat, base);
119 static inline struct fbdev_compositor *
120 to_fbdev_compositor(struct weston_compositor *base)
122 return container_of(base, struct fbdev_compositor, base);
126 fbdev_output_start_repaint_loop(struct weston_output *output)
131 gettimeofday(&tv, NULL);
132 msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
133 weston_output_finish_frame(output, msec);
137 fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage)
139 struct fbdev_output *output = to_fbdev_output(base);
140 struct weston_compositor *ec = output->base.compositor;
141 pixman_box32_t *rects;
142 int nrects, i, src_x, src_y, x1, y1, x2, y2, width, height;
144 /* Repaint the damaged region onto the back buffer. */
145 pixman_renderer_output_set_buffer(base, output->shadow_surface);
146 ec->renderer->repaint_output(base, damage);
148 /* Transform and composite onto the frame buffer. */
149 width = pixman_image_get_width(output->shadow_surface);
150 height = pixman_image_get_height(output->shadow_surface);
151 rects = pixman_region32_rectangles(damage, &nrects);
153 for (i = 0; i < nrects; i++) {
154 switch (base->transform) {
156 case WL_OUTPUT_TRANSFORM_NORMAL:
162 case WL_OUTPUT_TRANSFORM_180:
163 x1 = width - rects[i].x2;
164 x2 = width - rects[i].x1;
165 y1 = height - rects[i].y2;
166 y2 = height - rects[i].y1;
168 case WL_OUTPUT_TRANSFORM_90:
169 x1 = height - rects[i].y2;
170 x2 = height - rects[i].y1;
174 case WL_OUTPUT_TRANSFORM_270:
177 y1 = width - rects[i].x2;
178 y2 = width - rects[i].x1;
184 pixman_image_composite32(PIXMAN_OP_SRC,
185 output->shadow_surface, /* src */
187 output->hw_surface, /* dest */
188 src_x, src_y, /* src_x, src_y */
189 0, 0, /* mask_x, mask_y */
190 x1, y1, /* dest_x, dest_y */
192 y2 - y1 /* height */);
195 /* Update the damage region. */
196 pixman_region32_subtract(&ec->primary_plane.damage,
197 &ec->primary_plane.damage, damage);
199 /* Schedule the end of the frame. We do not sync this to the frame
200 * buffer clock because users who want that should be using the DRM
201 * compositor. FBIO_WAITFORVSYNC blocks and FB_ACTIVATE_VBL requires
202 * panning, which is broken in most kernel drivers.
204 * Finish the frame synchronised to the specified refresh rate. The
205 * refresh rate is given in mHz and the interval in ms. */
206 wl_event_source_timer_update(output->finish_frame_timer,
207 1000000 / output->mode.refresh);
211 finish_frame_handler(void *data)
213 struct fbdev_output *output = data;
215 fbdev_output_start_repaint_loop(&output->base);
220 static pixman_format_code_t
221 calculate_pixman_format(struct fb_var_screeninfo *vinfo,
222 struct fb_fix_screeninfo *finfo)
224 /* Calculate the pixman format supported by the frame buffer from the
225 * buffer's metadata. Return 0 if no known pixman format is supported
226 * (since this has depth 0 it's guaranteed to not conflict with any
227 * actual pixman format).
229 * Documentation on the vinfo and finfo structures:
230 * http://www.mjmwired.net/kernel/Documentation/fb/api.txt
232 * TODO: Try a bit harder to support other formats, including setting
233 * the preferred format in the hardware. */
236 weston_log("Calculating pixman format from:\n"
237 STAMP_SPACE " - type: %i (aux: %i)\n"
238 STAMP_SPACE " - visual: %i\n"
239 STAMP_SPACE " - bpp: %i (grayscale: %i)\n"
240 STAMP_SPACE " - red: offset: %i, length: %i, MSB: %i\n"
241 STAMP_SPACE " - green: offset: %i, length: %i, MSB: %i\n"
242 STAMP_SPACE " - blue: offset: %i, length: %i, MSB: %i\n"
243 STAMP_SPACE " - transp: offset: %i, length: %i, MSB: %i\n",
244 finfo->type, finfo->type_aux, finfo->visual,
245 vinfo->bits_per_pixel, vinfo->grayscale,
246 vinfo->red.offset, vinfo->red.length, vinfo->red.msb_right,
247 vinfo->green.offset, vinfo->green.length,
248 vinfo->green.msb_right,
249 vinfo->blue.offset, vinfo->blue.length,
250 vinfo->blue.msb_right,
251 vinfo->transp.offset, vinfo->transp.length,
252 vinfo->transp.msb_right);
254 /* We only handle packed formats at the moment. */
255 if (finfo->type != FB_TYPE_PACKED_PIXELS)
258 /* We only handle true-colour frame buffers at the moment. */
259 if (finfo->visual != FB_VISUAL_TRUECOLOR || vinfo->grayscale != 0)
262 /* We only support formats with MSBs on the left. */
263 if (vinfo->red.msb_right != 0 || vinfo->green.msb_right != 0 ||
264 vinfo->blue.msb_right != 0)
267 /* Work out the format type from the offsets. We only support RGBA and
268 * ARGB at the moment. */
269 type = PIXMAN_TYPE_OTHER;
271 if ((vinfo->transp.offset >= vinfo->red.offset ||
272 vinfo->transp.length == 0) &&
273 vinfo->red.offset >= vinfo->green.offset &&
274 vinfo->green.offset >= vinfo->blue.offset)
275 type = PIXMAN_TYPE_ARGB;
276 else if (vinfo->red.offset >= vinfo->green.offset &&
277 vinfo->green.offset >= vinfo->blue.offset &&
278 vinfo->blue.offset >= vinfo->transp.offset)
279 type = PIXMAN_TYPE_RGBA;
281 if (type == PIXMAN_TYPE_OTHER)
284 /* Build the format. */
285 return PIXMAN_FORMAT(vinfo->bits_per_pixel, type,
286 vinfo->transp.length,
293 calculate_refresh_rate(struct fb_var_screeninfo *vinfo)
297 /* Calculate monitor refresh rate. Default is 60 Hz. Units are mHz. */
298 quot = (vinfo->upper_margin + vinfo->lower_margin + vinfo->yres);
299 quot *= (vinfo->left_margin + vinfo->right_margin + vinfo->xres);
300 quot *= vinfo->pixclock;
303 uint64_t refresh_rate;
305 refresh_rate = 1000000000000000LLU / quot;
306 if (refresh_rate > 200000)
307 refresh_rate = 200000; /* cap at 200 Hz */
312 return 60 * 1000; /* default to 60 Hz */
316 fbdev_query_screen_info(struct fbdev_output *output, int fd,
317 struct fbdev_screeninfo *info)
319 struct fb_var_screeninfo varinfo;
320 struct fb_fix_screeninfo fixinfo;
322 /* Probe the device for screen information. */
323 if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) < 0 ||
324 ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) {
328 /* Store the pertinent data. */
329 info->x_resolution = varinfo.xres;
330 info->y_resolution = varinfo.yres;
331 info->width_mm = varinfo.width;
332 info->height_mm = varinfo.height;
333 info->bits_per_pixel = varinfo.bits_per_pixel;
335 info->buffer_length = fixinfo.smem_len;
336 info->line_length = fixinfo.line_length;
337 strncpy(info->id, fixinfo.id, sizeof(info->id) / sizeof(*info->id));
339 info->pixel_format = calculate_pixman_format(&varinfo, &fixinfo);
340 info->refresh_rate = calculate_refresh_rate(&varinfo);
342 if (info->pixel_format == 0) {
343 weston_log("Frame buffer uses an unsupported format.\n");
351 fbdev_set_screen_info(struct fbdev_output *output, int fd,
352 struct fbdev_screeninfo *info)
354 struct fb_var_screeninfo varinfo;
356 /* Grab the current screen information. */
357 if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) {
361 /* Update the information. */
362 varinfo.xres = info->x_resolution;
363 varinfo.yres = info->y_resolution;
364 varinfo.width = info->width_mm;
365 varinfo.height = info->height_mm;
366 varinfo.bits_per_pixel = info->bits_per_pixel;
368 /* Try to set up an ARGB (x8r8g8b8) pixel format. */
369 varinfo.grayscale = 0;
370 varinfo.transp.offset = 24;
371 varinfo.transp.length = 0;
372 varinfo.transp.msb_right = 0;
373 varinfo.red.offset = 16;
374 varinfo.red.length = 8;
375 varinfo.red.msb_right = 0;
376 varinfo.green.offset = 8;
377 varinfo.green.length = 8;
378 varinfo.green.msb_right = 0;
379 varinfo.blue.offset = 0;
380 varinfo.blue.length = 8;
381 varinfo.blue.msb_right = 0;
383 /* Set the device's screen information. */
384 if (ioctl(fd, FBIOPUT_VSCREENINFO, &varinfo) < 0) {
391 static void fbdev_frame_buffer_destroy(struct fbdev_output *output);
393 /* Returns an FD for the frame buffer device. */
395 fbdev_frame_buffer_open(struct fbdev_output *output, const char *fb_dev,
396 struct fbdev_screeninfo *screen_info)
400 weston_log("Opening fbdev frame buffer.\n");
402 /* Open the frame buffer device. */
403 fd = open(fb_dev, O_RDWR | O_CLOEXEC);
405 weston_log("Failed to open frame buffer device ‘%s’: %s\n",
406 fb_dev, strerror(errno));
410 /* Grab the screen info. */
411 if (fbdev_query_screen_info(output, fd, screen_info) < 0) {
412 weston_log("Failed to get frame buffer info: %s\n",
422 /* Closes the FD on success or failure. */
424 fbdev_frame_buffer_map(struct fbdev_output *output, int fd)
428 weston_log("Mapping fbdev frame buffer.\n");
430 /* Map the frame buffer. Write-only mode, since we don't want to read
431 * anything back (because it's slow). */
432 output->fb = mmap(NULL, output->fb_info.buffer_length,
433 PROT_WRITE, MAP_SHARED, fd, 0);
434 if (output->fb == MAP_FAILED) {
435 weston_log("Failed to mmap frame buffer: %s\n",
440 /* Create a pixman image to wrap the memory mapped frame buffer. */
442 pixman_image_create_bits(output->fb_info.pixel_format,
443 output->fb_info.x_resolution,
444 output->fb_info.y_resolution,
446 output->fb_info.line_length);
447 if (output->hw_surface == NULL) {
448 weston_log("Failed to create surface for frame buffer.\n");
456 if (retval != 0 && output->fb != NULL)
457 fbdev_frame_buffer_destroy(output);
467 fbdev_frame_buffer_destroy(struct fbdev_output *output)
469 weston_log("Destroying fbdev frame buffer.\n");
471 if (munmap(output->fb, output->fb_info.buffer_length) < 0)
472 weston_log("Failed to munmap frame buffer: %s\n",
478 static void fbdev_output_destroy(struct weston_output *base);
479 static void fbdev_output_disable(struct weston_output *base);
482 fbdev_output_create(struct fbdev_compositor *compositor,
485 struct fbdev_output *output;
486 pixman_transform_t transform;
488 int shadow_width, shadow_height;
490 unsigned int bytes_per_pixel;
491 struct wl_event_loop *loop;
493 weston_log("Creating fbdev output.\n");
495 output = calloc(1, sizeof *output);
499 output->compositor = compositor;
500 output->device = device;
502 /* Create the frame buffer. */
503 fb_fd = fbdev_frame_buffer_open(output, device, &output->fb_info);
505 weston_log("Creating frame buffer failed.\n");
509 if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
510 weston_log("Mapping frame buffer failed.\n");
514 output->base.start_repaint_loop = fbdev_output_start_repaint_loop;
515 output->base.repaint = fbdev_output_repaint;
516 output->base.destroy = fbdev_output_destroy;
517 output->base.assign_planes = NULL;
518 output->base.set_backlight = NULL;
519 output->base.set_dpms = NULL;
520 output->base.switch_mode = NULL;
522 /* only one static mode in list */
524 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
525 output->mode.width = output->fb_info.x_resolution;
526 output->mode.height = output->fb_info.y_resolution;
527 output->mode.refresh = output->fb_info.refresh_rate;
528 wl_list_init(&output->base.mode_list);
529 wl_list_insert(&output->base.mode_list, &output->mode.link);
531 output->base.current = &output->mode;
532 output->base.origin = &output->mode;
533 output->base.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
534 output->base.make = "unknown";
535 output->base.model = output->fb_info.id;
537 weston_output_init(&output->base, &compositor->base,
538 0, 0, output->fb_info.width_mm,
539 output->fb_info.height_mm,
540 WL_OUTPUT_TRANSFORM_NORMAL,
543 width = output->fb_info.x_resolution;
544 height = output->fb_info.y_resolution;
546 pixman_transform_init_identity(&transform);
547 switch (output->base.transform) {
549 case WL_OUTPUT_TRANSFORM_NORMAL:
550 shadow_width = width;
551 shadow_height = height;
552 pixman_transform_rotate(&transform,
554 pixman_transform_translate(&transform, NULL,
557 case WL_OUTPUT_TRANSFORM_180:
558 shadow_width = width;
559 shadow_height = height;
560 pixman_transform_rotate(&transform,
561 NULL, -pixman_fixed_1, 0);
562 pixman_transform_translate(NULL, &transform,
563 pixman_int_to_fixed(shadow_width),
564 pixman_int_to_fixed(shadow_height));
566 case WL_OUTPUT_TRANSFORM_270:
567 shadow_width = height;
568 shadow_height = width;
569 pixman_transform_rotate(&transform,
570 NULL, 0, pixman_fixed_1);
571 pixman_transform_translate(&transform,
573 pixman_int_to_fixed(shadow_width),
576 case WL_OUTPUT_TRANSFORM_90:
577 shadow_width = height;
578 shadow_height = width;
579 pixman_transform_rotate(&transform,
580 NULL, 0, -pixman_fixed_1);
581 pixman_transform_translate(&transform,
584 pixman_int_to_fixed(shadow_height));
588 bytes_per_pixel = output->fb_info.bits_per_pixel / 8;
590 output->shadow_buf = malloc(width * height * bytes_per_pixel);
591 output->shadow_surface =
592 pixman_image_create_bits(output->fb_info.pixel_format,
593 shadow_width, shadow_height,
595 shadow_width * bytes_per_pixel);
596 if (output->shadow_buf == NULL || output->shadow_surface == NULL) {
597 weston_log("Failed to create surface for frame buffer.\n");
601 /* No need in transform for normal output */
602 if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
603 pixman_image_set_transform(output->shadow_surface, &transform);
605 if (pixman_renderer_output_create(&output->base) < 0)
606 goto out_shadow_surface;
608 loop = wl_display_get_event_loop(compositor->base.wl_display);
609 output->finish_frame_timer =
610 wl_event_loop_add_timer(loop, finish_frame_handler, output);
612 wl_list_insert(compositor->base.output_list.prev, &output->base.link);
614 weston_log("fbdev output %d×%d px\n",
615 output->mode.width, output->mode.height);
616 weston_log_continue(STAMP_SPACE "guessing %d Hz and 96 dpi\n",
617 output->mode.refresh / 1000);
622 pixman_image_unref(output->shadow_surface);
623 output->shadow_surface = NULL;
625 free(output->shadow_buf);
626 pixman_image_unref(output->hw_surface);
627 output->hw_surface = NULL;
628 weston_output_destroy(&output->base);
629 fbdev_frame_buffer_destroy(output);
637 fbdev_output_destroy(struct weston_output *base)
639 struct fbdev_output *output = to_fbdev_output(base);
641 weston_log("Destroying fbdev output.\n");
643 /* Close the frame buffer. */
644 fbdev_output_disable(base);
646 if (base->renderer_state != NULL)
647 pixman_renderer_output_destroy(base);
649 if (output->shadow_surface != NULL) {
650 pixman_image_unref(output->shadow_surface);
651 output->shadow_surface = NULL;
654 if (output->shadow_buf != NULL) {
655 free(output->shadow_buf);
656 output->shadow_buf = NULL;
659 /* Remove the output. */
660 wl_list_remove(&output->base.link);
661 weston_output_destroy(&output->base);
666 /* strcmp()-style return values. */
668 compare_screen_info (const struct fbdev_screeninfo *a,
669 const struct fbdev_screeninfo *b)
671 if (a->x_resolution == b->x_resolution &&
672 a->y_resolution == b->y_resolution &&
673 a->width_mm == b->width_mm &&
674 a->height_mm == b->height_mm &&
675 a->bits_per_pixel == b->bits_per_pixel &&
676 a->pixel_format == b->pixel_format &&
677 a->refresh_rate == b->refresh_rate)
684 fbdev_output_reenable(struct fbdev_compositor *compositor,
685 struct weston_output *base)
687 struct fbdev_output *output = to_fbdev_output(base);
688 struct fbdev_screeninfo new_screen_info;
691 weston_log("Re-enabling fbdev output.\n");
693 /* Create the frame buffer. */
694 fb_fd = fbdev_frame_buffer_open(output, output->device,
697 weston_log("Creating frame buffer failed.\n");
701 /* Check whether the frame buffer details have changed since we were
703 if (compare_screen_info (&output->fb_info, &new_screen_info) != 0) {
704 /* Perform a mode-set to restore the old mode. */
705 if (fbdev_set_screen_info(output, fb_fd,
706 &output->fb_info) < 0) {
707 weston_log("Failed to restore mode settings. "
708 "Attempting to re-open output anyway.\n");
711 /* Remove and re-add the output so that resources depending on
712 * the frame buffer X/Y resolution (such as the shadow buffer)
713 * are re-initialised. */
714 fbdev_output_destroy(base);
715 fbdev_output_create(compositor, output->device);
720 /* Map the device if it has the same details as before. */
721 if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
722 weston_log("Mapping frame buffer failed.\n");
732 /* NOTE: This leaves output->fb_info populated, caching data so that if
733 * fbdev_output_reenable() is called again, it can determine whether a mode-set
736 fbdev_output_disable(struct weston_output *base)
738 struct fbdev_output *output = to_fbdev_output(base);
740 weston_log("Disabling fbdev output.\n");
742 if (output->hw_surface != NULL) {
743 pixman_image_unref(output->hw_surface);
744 output->hw_surface = NULL;
747 fbdev_frame_buffer_destroy(output);
751 fbdev_compositor_destroy(struct weston_compositor *base)
753 struct fbdev_compositor *compositor = to_fbdev_compositor(base);
754 struct udev_seat *seat, *next;
756 /* Destroy all inputs. */
757 wl_list_for_each_safe(seat, next, &compositor->base.seat_list, base.link)
758 udev_seat_destroy(seat);
760 /* Destroy the output. */
761 weston_compositor_shutdown(&compositor->base);
764 compositor->base.renderer->destroy(&compositor->base);
765 tty_destroy(compositor->tty);
771 vt_func(struct weston_compositor *base, int event)
773 struct fbdev_compositor *compositor = to_fbdev_compositor(base);
774 struct udev_seat *seat;
775 struct weston_output *output;
779 weston_log("entering VT\n");
780 compositor->base.focus = 1;
781 compositor->base.state = compositor->prev_state;
783 wl_list_for_each(output, &compositor->base.output_list, link) {
784 fbdev_output_reenable(compositor, output);
787 weston_compositor_damage_all(&compositor->base);
789 wl_list_for_each(seat, &compositor->base.seat_list, base.link)
790 udev_seat_enable(seat, compositor->udev);
793 weston_log("leaving VT\n");
794 wl_list_for_each(seat, &compositor->base.seat_list, base.link)
795 udev_seat_disable(seat);
797 wl_list_for_each(output, &compositor->base.output_list, link) {
798 fbdev_output_disable(output);
801 compositor->base.focus = 0;
802 compositor->prev_state = compositor->base.state;
803 weston_compositor_offscreen(&compositor->base);
805 /* If we have a repaint scheduled (from the idle handler), make
806 * sure we cancel that so we don't try to pageflip when we're
807 * vt switched away. The OFFSCREEN state will prevent
808 * further attemps at repainting. When we switch
809 * back, we schedule a repaint, which will process
810 * pending frame callbacks. */
812 wl_list_for_each(output,
813 &compositor->base.output_list, link) {
814 output->repaint_needed = 0;
822 fbdev_restore(struct weston_compositor *base)
824 struct fbdev_compositor *compositor = to_fbdev_compositor(base);
826 tty_reset(compositor->tty);
830 switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
832 struct fbdev_compositor *ec = data;
834 tty_activate_vt(ec->tty, key - KEY_F1 + 1);
837 static struct weston_compositor *
838 fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
839 int config_fd, struct fbdev_parameters *param)
841 struct fbdev_compositor *compositor;
842 const char *seat = default_seat;
845 weston_log("initializing fbdev backend\n");
847 compositor = calloc(1, sizeof *compositor);
848 if (compositor == NULL)
851 if (weston_compositor_init(&compositor->base, display, argc, argv,
855 compositor->udev = udev_new();
856 if (compositor->udev == NULL) {
857 weston_log("Failed to initialize udev context.\n");
861 /* Set up the TTY. */
862 compositor->tty = tty_create(&compositor->base, vt_func, param->tty);
863 if (!compositor->tty) {
864 weston_log("Failed to initialize tty.\n");
868 compositor->base.destroy = fbdev_compositor_destroy;
869 compositor->base.restore = fbdev_restore;
871 compositor->base.focus = 1;
872 compositor->prev_state = WESTON_COMPOSITOR_ACTIVE;
874 for (key = KEY_F1; key < KEY_F9; key++)
875 weston_compositor_add_key_binding(&compositor->base, key,
876 MODIFIER_CTRL | MODIFIER_ALT,
880 if (pixman_renderer_init(&compositor->base) < 0)
883 if (fbdev_output_create(compositor, param->device) < 0)
886 udev_seat_create(&compositor->base, compositor->udev, seat);
888 return &compositor->base;
891 compositor->base.renderer->destroy(&compositor->base);
894 tty_destroy(compositor->tty);
897 udev_unref(compositor->udev);
900 weston_compositor_shutdown(&compositor->base);
908 WL_EXPORT struct weston_compositor *
909 backend_init(struct wl_display *display, int *argc, char *argv[],
912 /* TODO: Ideally, available frame buffers should be enumerated using
913 * udev, rather than passing a device node in as a parameter. */
914 struct fbdev_parameters param = {
915 .tty = 0, /* default to current tty */
916 .device = "/dev/fb0", /* default frame buffer */
919 const struct weston_option fbdev_options[] = {
920 { WESTON_OPTION_INTEGER, "tty", 0, ¶m.tty },
921 { WESTON_OPTION_STRING, "device", 0, ¶m.device },
924 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
926 return fbdev_compositor_create(display, argc, argv, config_fd,