2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2011 Intel Corporation
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 #include <linux/input.h>
40 #include <xf86drmMode.h>
41 #include <drm_fourcc.h>
44 #include <libbacklight.h>
47 #include "compositor.h"
48 #include "gl-renderer.h"
49 #include "pixman-renderer.h"
50 #include "udev-seat.h"
51 #include "launcher-util.h"
52 #include "vaapi-recorder.h"
54 #ifndef DRM_CAP_TIMESTAMP_MONOTONIC
55 #define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
58 static int option_current_mode = 0;
61 OUTPUT_CONFIG_INVALID = 0,
63 OUTPUT_CONFIG_PREFERRED,
64 OUTPUT_CONFIG_CURRENT,
66 OUTPUT_CONFIG_MODELINE
69 struct drm_compositor {
70 struct weston_compositor base;
73 struct wl_event_source *drm_source;
75 struct udev_monitor *udev_monitor;
76 struct wl_event_source *udev_drm_source;
83 struct gbm_device *gbm;
86 uint32_t crtc_allocator;
87 uint32_t connector_allocator;
88 struct wl_listener session_listener;
91 /* we need these parameters in order to not fail drmModeAddFB2()
92 * due to out of bounds dimensions, and then mistakenly set
95 uint32_t min_width, max_width;
96 uint32_t min_height, max_height;
99 struct wl_list sprite_list;
100 int sprites_are_broken;
103 int cursors_are_broken;
110 struct udev_input input;
114 struct weston_mode base;
115 drmModeModeInfo mode_info;
121 struct drm_output *output;
122 uint32_t fb_id, stride, handle, size;
124 int is_client_buffer;
125 struct weston_buffer_reference buffer_ref;
127 /* Used by gbm fbs */
130 /* Used by dumb fbs */
136 char monitor_name[13];
138 char serial_number[13];
142 struct weston_output base;
146 uint32_t connector_id;
147 drmModeCrtcPtr original_crtc;
148 struct drm_edid edid;
149 drmModePropertyPtr dpms_prop;
152 int page_flip_pending;
155 struct gbm_surface *surface;
156 struct gbm_bo *cursor_bo[2];
157 struct weston_plane cursor_plane;
158 struct weston_plane fb_plane;
159 struct weston_surface *cursor_surface;
161 struct drm_fb *current, *next;
162 struct backlight *backlight;
164 struct drm_fb *dumb[2];
165 pixman_image_t *image[2];
167 pixman_region32_t previous_damage;
169 struct vaapi_recorder *recorder;
170 struct wl_listener recorder_frame_listener;
174 * An output has a primary display plane plus zero or more sprites for
175 * blending display contents.
180 struct weston_plane plane;
182 struct drm_fb *current, *next;
183 struct drm_output *output;
184 struct drm_compositor *compositor;
186 uint32_t possible_crtcs;
188 uint32_t count_formats;
190 int32_t src_x, src_y;
191 uint32_t src_w, src_h;
192 uint32_t dest_x, dest_y;
193 uint32_t dest_w, dest_h;
198 static struct gl_renderer_interface *gl_renderer;
200 static const char default_seat[] = "seat0";
203 drm_output_set_cursor(struct drm_output *output);
206 drm_sprite_crtc_supported(struct weston_output *output_base, uint32_t supported)
208 struct weston_compositor *ec = output_base->compositor;
209 struct drm_compositor *c =(struct drm_compositor *) ec;
210 struct drm_output *output = (struct drm_output *) output_base;
213 for (crtc = 0; crtc < c->num_crtcs; crtc++) {
214 if (c->crtcs[crtc] != output->crtc_id)
217 if (supported & (1 << crtc))
225 drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
227 struct drm_fb *fb = data;
228 struct gbm_device *gbm = gbm_bo_get_device(bo);
231 drmModeRmFB(gbm_device_get_fd(gbm), fb->fb_id);
233 weston_buffer_reference(&fb->buffer_ref, NULL);
238 static struct drm_fb *
239 drm_fb_create_dumb(struct drm_compositor *ec, unsigned width, unsigned height)
244 struct drm_mode_create_dumb create_arg;
245 struct drm_mode_destroy_dumb destroy_arg;
246 struct drm_mode_map_dumb map_arg;
248 fb = zalloc(sizeof *fb);
252 memset(&create_arg, 0, sizeof create_arg);
254 create_arg.width = width;
255 create_arg.height = height;
257 ret = drmIoctl(ec->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
261 fb->handle = create_arg.handle;
262 fb->stride = create_arg.pitch;
263 fb->size = create_arg.size;
266 ret = drmModeAddFB(ec->drm.fd, width, height, 24, 32,
267 fb->stride, fb->handle, &fb->fb_id);
271 memset(&map_arg, 0, sizeof map_arg);
272 map_arg.handle = fb->handle;
273 ret = drmIoctl(fb->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
277 fb->map = mmap(0, fb->size, PROT_WRITE,
278 MAP_SHARED, ec->drm.fd, map_arg.offset);
279 if (fb->map == MAP_FAILED)
285 drmModeRmFB(ec->drm.fd, fb->fb_id);
287 memset(&destroy_arg, 0, sizeof(destroy_arg));
288 destroy_arg.handle = create_arg.handle;
289 drmIoctl(ec->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
296 drm_fb_destroy_dumb(struct drm_fb *fb)
298 struct drm_mode_destroy_dumb destroy_arg;
304 drmModeRmFB(fb->fd, fb->fb_id);
306 weston_buffer_reference(&fb->buffer_ref, NULL);
308 munmap(fb->map, fb->size);
310 memset(&destroy_arg, 0, sizeof(destroy_arg));
311 destroy_arg.handle = fb->handle;
312 drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
317 static struct drm_fb *
318 drm_fb_get_from_bo(struct gbm_bo *bo,
319 struct drm_compositor *compositor, uint32_t format)
321 struct drm_fb *fb = gbm_bo_get_user_data(bo);
322 uint32_t width, height;
323 uint32_t handles[4], pitches[4], offsets[4];
329 fb = calloc(1, sizeof *fb);
335 width = gbm_bo_get_width(bo);
336 height = gbm_bo_get_height(bo);
337 fb->stride = gbm_bo_get_stride(bo);
338 fb->handle = gbm_bo_get_handle(bo).u32;
339 fb->size = fb->stride * height;
340 fb->fd = compositor->drm.fd;
342 if (compositor->min_width > width || width > compositor->max_width ||
343 compositor->min_height > height ||
344 height > compositor->max_height) {
345 weston_log("bo geometry out of bounds\n");
351 if (format && !compositor->no_addfb2) {
352 handles[0] = fb->handle;
353 pitches[0] = fb->stride;
356 ret = drmModeAddFB2(compositor->drm.fd, width, height,
357 format, handles, pitches, offsets,
360 weston_log("addfb2 failed: %m\n");
361 compositor->no_addfb2 = 1;
362 compositor->sprites_are_broken = 1;
367 ret = drmModeAddFB(compositor->drm.fd, width, height, 24, 32,
368 fb->stride, fb->handle, &fb->fb_id);
371 weston_log("failed to create kms fb: %m\n");
375 gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback);
385 drm_fb_set_buffer(struct drm_fb *fb, struct weston_buffer *buffer)
387 assert(fb->buffer_ref.buffer == NULL);
389 fb->is_client_buffer = 1;
391 weston_buffer_reference(&fb->buffer_ref, buffer);
395 drm_output_release_fb(struct drm_output *output, struct drm_fb *fb)
401 (fb != output->dumb[0] && fb != output->dumb[1])) {
402 drm_fb_destroy_dumb(fb);
404 if (fb->is_client_buffer)
405 gbm_bo_destroy(fb->bo);
407 gbm_surface_release_buffer(output->surface,
408 output->current->bo);
413 drm_output_check_scanout_format(struct drm_output *output,
414 struct weston_surface *es, struct gbm_bo *bo)
419 format = gbm_bo_get_format(bo);
422 case GBM_FORMAT_XRGB8888:
424 case GBM_FORMAT_ARGB8888:
425 /* We can only scanout an ARGB buffer if the surface's
426 * opaque region covers the whole output */
427 pixman_region32_init(&r);
428 pixman_region32_subtract(&r, &output->base.region,
431 if (!pixman_region32_not_empty(&r))
432 format = GBM_FORMAT_XRGB8888;
436 pixman_region32_fini(&r);
444 static struct weston_plane *
445 drm_output_prepare_scanout_surface(struct weston_output *_output,
446 struct weston_surface *es)
448 struct drm_output *output = (struct drm_output *) _output;
449 struct drm_compositor *c =
450 (struct drm_compositor *) output->base.compositor;
451 struct weston_buffer *buffer = es->buffer_ref.buffer;
455 if (es->geometry.x != output->base.x ||
456 es->geometry.y != output->base.y ||
457 buffer == NULL || c->gbm == NULL ||
458 buffer->width != output->base.current_mode->width ||
459 buffer->height != output->base.current_mode->height ||
460 output->base.transform != es->buffer_transform ||
461 es->transform.enabled)
464 bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER,
465 buffer->resource, GBM_BO_USE_SCANOUT);
467 /* Unable to use the buffer for scanout */
471 format = drm_output_check_scanout_format(output, es, bo);
477 output->next = drm_fb_get_from_bo(bo, c, format);
483 drm_fb_set_buffer(output->next, buffer);
485 return &output->fb_plane;
489 drm_output_render_gl(struct drm_output *output, pixman_region32_t *damage)
491 struct drm_compositor *c =
492 (struct drm_compositor *) output->base.compositor;
495 c->base.renderer->repaint_output(&output->base, damage);
497 bo = gbm_surface_lock_front_buffer(output->surface);
499 weston_log("failed to lock front buffer: %m\n");
503 output->next = drm_fb_get_from_bo(bo, c, c->format);
505 weston_log("failed to get drm_fb for bo\n");
506 gbm_surface_release_buffer(output->surface, bo);
512 drm_output_render_pixman(struct drm_output *output, pixman_region32_t *damage)
514 struct weston_compositor *ec = output->base.compositor;
515 pixman_region32_t total_damage, previous_damage;
517 pixman_region32_init(&total_damage);
518 pixman_region32_init(&previous_damage);
520 pixman_region32_copy(&previous_damage, damage);
522 pixman_region32_union(&total_damage, damage, &output->previous_damage);
523 pixman_region32_copy(&output->previous_damage, &previous_damage);
525 output->current_image ^= 1;
527 output->next = output->dumb[output->current_image];
528 pixman_renderer_output_set_buffer(&output->base,
529 output->image[output->current_image]);
531 ec->renderer->repaint_output(&output->base, &total_damage);
533 pixman_region32_fini(&total_damage);
534 pixman_region32_fini(&previous_damage);
538 drm_output_render(struct drm_output *output, pixman_region32_t *damage)
540 struct drm_compositor *c =
541 (struct drm_compositor *) output->base.compositor;
544 drm_output_render_pixman(output, damage);
546 drm_output_render_gl(output, damage);
548 pixman_region32_subtract(&c->base.primary_plane.damage,
549 &c->base.primary_plane.damage, damage);
553 drm_output_set_gamma(struct weston_output *output_base,
554 uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b)
557 struct drm_output *output = (struct drm_output *) output_base;
558 struct drm_compositor *compositor = (struct drm_compositor *) output->base.compositor;
561 if (output_base->gamma_size != size)
563 if (!output->original_crtc)
566 rc = drmModeCrtcSetGamma(compositor->drm.fd,
570 weston_log("set gamma failed: %m\n");
574 drm_output_repaint(struct weston_output *output_base,
575 pixman_region32_t *damage)
577 struct drm_output *output = (struct drm_output *) output_base;
578 struct drm_compositor *compositor =
579 (struct drm_compositor *) output->base.compositor;
580 struct drm_sprite *s;
581 struct drm_mode *mode;
584 if (output->destroy_pending)
588 drm_output_render(output, damage);
592 mode = container_of(output->base.current_mode, struct drm_mode, base);
593 if (!output->current) {
594 ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
595 output->next->fb_id, 0, 0,
596 &output->connector_id, 1,
599 weston_log("set mode failed: %m\n");
602 output_base->set_dpms(output_base, WESTON_DPMS_ON);
605 if (drmModePageFlip(compositor->drm.fd, output->crtc_id,
607 DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
608 weston_log("queueing pageflip failed: %m\n");
612 output->page_flip_pending = 1;
614 drm_output_set_cursor(output);
617 * Now, update all the sprite surfaces
619 wl_list_for_each(s, &compositor->sprite_list, link) {
620 uint32_t flags = 0, fb_id = 0;
622 .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT,
623 .request.sequence = 1,
626 if ((!s->current && !s->next) ||
627 !drm_sprite_crtc_supported(output_base, s->possible_crtcs))
630 if (s->next && !compositor->sprites_hidden)
631 fb_id = s->next->fb_id;
633 ret = drmModeSetPlane(compositor->drm.fd, s->plane_id,
634 output->crtc_id, fb_id, flags,
635 s->dest_x, s->dest_y,
636 s->dest_w, s->dest_h,
640 weston_log("setplane failed: %d: %s\n",
641 ret, strerror(errno));
643 if (output->pipe > 0)
644 vbl.request.type |= DRM_VBLANK_SECONDARY;
647 * Queue a vblank signal so we know when the surface
648 * becomes active on the display or has been replaced.
650 vbl.request.signal = (unsigned long)s;
651 ret = drmWaitVBlank(compositor->drm.fd, &vbl);
653 weston_log("vblank event request failed: %d: %s\n",
654 ret, strerror(errno));
658 output->vblank_pending = 1;
665 drm_output_start_repaint_loop(struct weston_output *output_base)
667 struct drm_output *output = (struct drm_output *) output_base;
668 struct drm_compositor *compositor = (struct drm_compositor *)
669 output_base->compositor;
674 if (output->destroy_pending)
677 if (!output->current) {
678 /* We can't page flip if there's no mode set */
681 clock_gettime(compositor->clock, &ts);
682 msec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
683 weston_output_finish_frame(output_base, msec);
687 fb_id = output->current->fb_id;
689 if (drmModePageFlip(compositor->drm.fd, output->crtc_id, fb_id,
690 DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
691 weston_log("queueing pageflip failed: %m\n");
697 vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec,
700 struct drm_sprite *s = (struct drm_sprite *)data;
701 struct drm_output *output = s->output;
704 output->vblank_pending = 0;
706 drm_output_release_fb(output, s->current);
707 s->current = s->next;
710 if (!output->page_flip_pending) {
711 msecs = sec * 1000 + usec / 1000;
712 weston_output_finish_frame(&output->base, msecs);
717 drm_output_destroy(struct weston_output *output_base);
720 page_flip_handler(int fd, unsigned int frame,
721 unsigned int sec, unsigned int usec, void *data)
723 struct drm_output *output = (struct drm_output *) data;
726 /* We don't set page_flip_pending on start_repaint_loop, in that case
727 * we just want to page flip to the current buffer to get an accurate
729 if (output->page_flip_pending) {
730 drm_output_release_fb(output, output->current);
731 output->current = output->next;
735 output->page_flip_pending = 0;
737 if (output->destroy_pending)
738 drm_output_destroy(&output->base);
739 else if (!output->vblank_pending) {
740 msecs = sec * 1000 + usec / 1000;
741 weston_output_finish_frame(&output->base, msecs);
743 /* We can't call this from frame_notify, because the output's
744 * repaint needed flag is cleared just after that */
745 if (output->recorder)
746 weston_output_schedule_repaint(&output->base);
751 drm_output_check_sprite_format(struct drm_sprite *s,
752 struct weston_surface *es, struct gbm_bo *bo)
756 format = gbm_bo_get_format(bo);
758 if (format == GBM_FORMAT_ARGB8888) {
761 pixman_region32_init_rect(&r, 0, 0,
763 es->geometry.height);
764 pixman_region32_subtract(&r, &r, &es->opaque);
766 if (!pixman_region32_not_empty(&r))
767 format = GBM_FORMAT_XRGB8888;
769 pixman_region32_fini(&r);
772 for (i = 0; i < s->count_formats; i++)
773 if (s->formats[i] == format)
780 drm_surface_transform_supported(struct weston_surface *es)
782 return !es->transform.enabled ||
783 (es->transform.matrix.type < WESTON_MATRIX_TRANSFORM_ROTATE);
786 static struct weston_plane *
787 drm_output_prepare_overlay_surface(struct weston_output *output_base,
788 struct weston_surface *es)
790 struct weston_compositor *ec = output_base->compositor;
791 struct drm_compositor *c =(struct drm_compositor *) ec;
792 struct drm_sprite *s;
795 pixman_region32_t dest_rect, src_rect;
796 pixman_box32_t *box, tbox;
798 wl_fixed_t sx1, sy1, sx2, sy2;
803 if (es->buffer_transform != output_base->transform)
806 if (es->buffer_scale != output_base->current_scale)
809 if (c->sprites_are_broken)
812 if (es->output_mask != (1u << output_base->id))
815 if (es->buffer_ref.buffer == NULL)
818 if (es->alpha != 1.0f)
821 if (wl_shm_buffer_get(es->buffer_ref.buffer->resource))
824 if (!drm_surface_transform_supported(es))
827 wl_list_for_each(s, &c->sprite_list, link) {
828 if (!drm_sprite_crtc_supported(output_base, s->possible_crtcs))
837 /* No sprites available */
841 bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER,
842 es->buffer_ref.buffer->resource,
847 format = drm_output_check_sprite_format(s, es, bo);
853 s->next = drm_fb_get_from_bo(bo, c, format);
859 drm_fb_set_buffer(s->next, es->buffer_ref.buffer);
861 box = pixman_region32_extents(&es->transform.boundingbox);
862 s->plane.x = box->x1;
863 s->plane.y = box->y1;
866 * Calculate the source & dest rects properly based on actual
867 * position (note the caller has called weston_surface_update_transform()
870 pixman_region32_init(&dest_rect);
871 pixman_region32_intersect(&dest_rect, &es->transform.boundingbox,
872 &output_base->region);
873 pixman_region32_translate(&dest_rect, -output_base->x, -output_base->y);
874 box = pixman_region32_extents(&dest_rect);
875 tbox = weston_transformed_rect(output_base->width,
877 output_base->transform,
878 output_base->current_scale,
882 s->dest_w = tbox.x2 - tbox.x1;
883 s->dest_h = tbox.y2 - tbox.y1;
884 pixman_region32_fini(&dest_rect);
886 pixman_region32_init(&src_rect);
887 pixman_region32_intersect(&src_rect, &es->transform.boundingbox,
888 &output_base->region);
889 box = pixman_region32_extents(&src_rect);
891 weston_surface_from_global_fixed(es,
892 wl_fixed_from_int(box->x1),
893 wl_fixed_from_int(box->y1),
895 weston_surface_from_global_fixed(es,
896 wl_fixed_from_int(box->x2),
897 wl_fixed_from_int(box->y2),
904 if (sx2 > wl_fixed_from_int(es->geometry.width))
905 sx2 = wl_fixed_from_int(es->geometry.width);
906 if (sy2 > wl_fixed_from_int(es->geometry.height))
907 sy2 = wl_fixed_from_int(es->geometry.height);
914 tbox = weston_transformed_rect(wl_fixed_from_int(es->geometry.width),
915 wl_fixed_from_int(es->geometry.height),
916 es->buffer_transform, es->buffer_scale, tbox);
918 s->src_x = tbox.x1 << 8;
919 s->src_y = tbox.y1 << 8;
920 s->src_w = (tbox.x2 - tbox.x1) << 8;
921 s->src_h = (tbox.y2 - tbox.y1) << 8;
922 pixman_region32_fini(&src_rect);
927 static struct weston_plane *
928 drm_output_prepare_cursor_surface(struct weston_output *output_base,
929 struct weston_surface *es)
931 struct drm_compositor *c =
932 (struct drm_compositor *) output_base->compositor;
933 struct drm_output *output = (struct drm_output *) output_base;
937 if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
939 if (output->cursor_surface)
941 if (es->output_mask != (1u << output_base->id))
943 if (c->cursors_are_broken)
945 if (es->buffer_ref.buffer == NULL ||
946 !wl_shm_buffer_get(es->buffer_ref.buffer->resource) ||
947 es->geometry.width > 64 || es->geometry.height > 64)
950 output->cursor_surface = es;
952 return &output->cursor_plane;
956 drm_output_set_cursor(struct drm_output *output)
958 struct weston_surface *es = output->cursor_surface;
959 struct drm_compositor *c =
960 (struct drm_compositor *) output->base.compositor;
961 EGLint handle, stride;
963 uint32_t buf[64 * 64];
967 output->cursor_surface = NULL;
969 drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
973 if (es->buffer_ref.buffer &&
974 pixman_region32_not_empty(&output->cursor_plane.damage)) {
975 pixman_region32_fini(&output->cursor_plane.damage);
976 pixman_region32_init(&output->cursor_plane.damage);
977 output->current_cursor ^= 1;
978 bo = output->cursor_bo[output->current_cursor];
979 memset(buf, 0, sizeof buf);
980 stride = wl_shm_buffer_get_stride(es->buffer_ref.buffer->shm_buffer);
981 s = wl_shm_buffer_get_data(es->buffer_ref.buffer->shm_buffer);
982 for (i = 0; i < es->geometry.height; i++)
983 memcpy(buf + i * 64, s + i * stride,
984 es->geometry.width * 4);
986 if (gbm_bo_write(bo, buf, sizeof buf) < 0)
987 weston_log("failed update cursor: %m\n");
989 handle = gbm_bo_get_handle(bo).s32;
990 if (drmModeSetCursor(c->drm.fd,
991 output->crtc_id, handle, 64, 64)) {
992 weston_log("failed to set cursor: %m\n");
993 c->cursors_are_broken = 1;
997 x = (es->geometry.x - output->base.x) * output->base.current_scale;
998 y = (es->geometry.y - output->base.y) * output->base.current_scale;
999 if (output->cursor_plane.x != x || output->cursor_plane.y != y) {
1000 if (drmModeMoveCursor(c->drm.fd, output->crtc_id, x, y)) {
1001 weston_log("failed to move cursor: %m\n");
1002 c->cursors_are_broken = 1;
1005 output->cursor_plane.x = x;
1006 output->cursor_plane.y = y;
1011 drm_assign_planes(struct weston_output *output)
1013 struct drm_compositor *c =
1014 (struct drm_compositor *) output->compositor;
1015 struct weston_surface *es, *next;
1016 pixman_region32_t overlap, surface_overlap;
1017 struct weston_plane *primary, *next_plane;
1020 * Find a surface for each sprite in the output using some heuristics:
1022 * 2) frequency of update
1023 * 3) opacity (though some hw might support alpha blending)
1024 * 4) clipping (this can be fixed with color keys)
1026 * The idea is to save on blitting since this should save power.
1027 * If we can get a large video surface on the sprite for example,
1028 * the main display surface may not need to update at all, and
1029 * the client buffer can be used directly for the sprite surface
1030 * as we do for flipping full screen surfaces.
1032 pixman_region32_init(&overlap);
1033 primary = &c->base.primary_plane;
1034 wl_list_for_each_safe(es, next, &c->base.surface_list, link) {
1035 /* test whether this buffer can ever go into a plane:
1036 * non-shm, or small enough to be a cursor
1038 if ((es->buffer_ref.buffer &&
1039 !wl_shm_buffer_get(es->buffer_ref.buffer->resource)) ||
1040 (es->geometry.width <= 64 && es->geometry.height <= 64))
1041 es->keep_buffer = 1;
1043 es->keep_buffer = 0;
1045 pixman_region32_init(&surface_overlap);
1046 pixman_region32_intersect(&surface_overlap, &overlap,
1047 &es->transform.boundingbox);
1050 if (pixman_region32_not_empty(&surface_overlap))
1051 next_plane = primary;
1052 if (next_plane == NULL)
1053 next_plane = drm_output_prepare_cursor_surface(output, es);
1054 if (next_plane == NULL)
1055 next_plane = drm_output_prepare_scanout_surface(output, es);
1056 if (next_plane == NULL)
1057 next_plane = drm_output_prepare_overlay_surface(output, es);
1058 if (next_plane == NULL)
1059 next_plane = primary;
1060 weston_surface_move_to_plane(es, next_plane);
1061 if (next_plane == primary)
1062 pixman_region32_union(&overlap, &overlap,
1063 &es->transform.boundingbox);
1065 pixman_region32_fini(&surface_overlap);
1067 pixman_region32_fini(&overlap);
1071 drm_output_fini_pixman(struct drm_output *output);
1074 drm_output_destroy(struct weston_output *output_base)
1076 struct drm_output *output = (struct drm_output *) output_base;
1077 struct drm_compositor *c =
1078 (struct drm_compositor *) output->base.compositor;
1079 drmModeCrtcPtr origcrtc = output->original_crtc;
1081 if (output->page_flip_pending) {
1082 output->destroy_pending = 1;
1083 weston_log("destroy output while page flip pending\n");
1087 if (output->backlight)
1088 backlight_destroy(output->backlight);
1090 drmModeFreeProperty(output->dpms_prop);
1092 /* Turn off hardware cursor */
1093 drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
1095 /* Restore original CRTC state */
1096 drmModeSetCrtc(c->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id,
1097 origcrtc->x, origcrtc->y,
1098 &output->connector_id, 1, &origcrtc->mode);
1099 drmModeFreeCrtc(origcrtc);
1101 c->crtc_allocator &= ~(1 << output->crtc_id);
1102 c->connector_allocator &= ~(1 << output->connector_id);
1104 if (c->use_pixman) {
1105 drm_output_fini_pixman(output);
1107 gl_renderer->output_destroy(output_base);
1108 gbm_surface_destroy(output->surface);
1111 weston_plane_release(&output->fb_plane);
1112 weston_plane_release(&output->cursor_plane);
1114 weston_output_destroy(&output->base);
1115 wl_list_remove(&output->base.link);
1120 static struct drm_mode *
1121 choose_mode (struct drm_output *output, struct weston_mode *target_mode)
1123 struct drm_mode *tmp_mode = NULL, *mode;
1125 if (output->base.current_mode->width == target_mode->width &&
1126 output->base.current_mode->height == target_mode->height &&
1127 (output->base.current_mode->refresh == target_mode->refresh ||
1128 target_mode->refresh == 0))
1129 return (struct drm_mode *)output->base.current_mode;
1131 wl_list_for_each(mode, &output->base.mode_list, base.link) {
1132 if (mode->mode_info.hdisplay == target_mode->width &&
1133 mode->mode_info.vdisplay == target_mode->height) {
1134 if (mode->mode_info.vrefresh == target_mode->refresh ||
1135 target_mode->refresh == 0) {
1137 } else if (!tmp_mode)
1146 drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec);
1148 drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c);
1151 drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode)
1153 struct drm_output *output;
1154 struct drm_mode *drm_mode;
1155 struct drm_compositor *ec;
1157 if (output_base == NULL) {
1158 weston_log("output is NULL.\n");
1163 weston_log("mode is NULL.\n");
1167 ec = (struct drm_compositor *)output_base->compositor;
1168 output = (struct drm_output *)output_base;
1169 drm_mode = choose_mode (output, mode);
1172 weston_log("%s, invalid resolution:%dx%d\n", __func__, mode->width, mode->height);
1176 if (&drm_mode->base == output->base.current_mode)
1179 output->base.current_mode->flags = 0;
1181 output->base.current_mode = &drm_mode->base;
1182 output->base.current_mode->flags =
1183 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
1185 /* reset rendering stuff. */
1186 drm_output_release_fb(output, output->current);
1187 drm_output_release_fb(output, output->next);
1188 output->current = output->next = NULL;
1190 if (ec->use_pixman) {
1191 drm_output_fini_pixman(output);
1192 if (drm_output_init_pixman(output, ec) < 0) {
1193 weston_log("failed to init output pixman state with "
1198 gl_renderer->output_destroy(&output->base);
1199 gbm_surface_destroy(output->surface);
1201 if (drm_output_init_egl(output, ec) < 0) {
1202 weston_log("failed to init output egl state with "
1212 on_drm_input(int fd, uint32_t mask, void *data)
1214 drmEventContext evctx;
1216 memset(&evctx, 0, sizeof evctx);
1217 evctx.version = DRM_EVENT_CONTEXT_VERSION;
1218 evctx.page_flip_handler = page_flip_handler;
1219 evctx.vblank_handler = vblank_handler;
1220 drmHandleEvent(fd, &evctx);
1226 init_drm(struct drm_compositor *ec, struct udev_device *device)
1228 const char *filename, *sysnum;
1232 sysnum = udev_device_get_sysnum(device);
1234 ec->drm.id = atoi(sysnum);
1235 if (!sysnum || ec->drm.id < 0) {
1236 weston_log("cannot get device sysnum\n");
1240 filename = udev_device_get_devnode(device);
1241 fd = weston_launcher_open(ec->base.launcher, filename, O_RDWR);
1243 /* Probably permissions error */
1244 weston_log("couldn't open %s, skipping\n",
1245 udev_device_get_devnode(device));
1249 weston_log("using %s\n", filename);
1252 ec->drm.filename = strdup(filename);
1254 ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
1255 if (ret == 0 && cap == 1)
1256 ec->clock = CLOCK_MONOTONIC;
1258 ec->clock = CLOCK_REALTIME;
1264 init_egl(struct drm_compositor *ec)
1268 gl_renderer = weston_load_module("gl-renderer.so",
1269 "gl_renderer_interface");
1273 /* GBM will load a dri driver, but even though they need symbols from
1274 * libglapi, in some version of Mesa they are not linked to it. Since
1275 * only the gl-renderer module links to it, the call above won't make
1276 * these symbols globally available, and loading the DRI driver fails.
1277 * Workaround this by dlopen()'ing libglapi with RTLD_GLOBAL. */
1278 dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL);
1280 ec->gbm = gbm_create_device(ec->drm.fd);
1285 format = ec->format;
1286 if (gl_renderer->create(&ec->base, ec->gbm,
1287 gl_renderer->opaque_attribs, &format) < 0) {
1288 gbm_device_destroy(ec->gbm);
1296 init_pixman(struct drm_compositor *ec)
1298 return pixman_renderer_init(&ec->base);
1301 static struct drm_mode *
1302 drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info)
1304 struct drm_mode *mode;
1307 mode = malloc(sizeof *mode);
1311 mode->base.flags = 0;
1312 mode->base.width = info->hdisplay;
1313 mode->base.height = info->vdisplay;
1315 /* Calculate higher precision (mHz) refresh rate */
1316 refresh = (info->clock * 1000000LL / info->htotal +
1317 info->vtotal / 2) / info->vtotal;
1319 if (info->flags & DRM_MODE_FLAG_INTERLACE)
1321 if (info->flags & DRM_MODE_FLAG_DBLSCAN)
1323 if (info->vscan > 1)
1324 refresh /= info->vscan;
1326 mode->base.refresh = refresh;
1327 mode->mode_info = *info;
1329 if (info->type & DRM_MODE_TYPE_PREFERRED)
1330 mode->base.flags |= WL_OUTPUT_MODE_PREFERRED;
1332 wl_list_insert(output->base.mode_list.prev, &mode->base.link);
1338 drm_subpixel_to_wayland(int drm_value)
1340 switch (drm_value) {
1342 case DRM_MODE_SUBPIXEL_UNKNOWN:
1343 return WL_OUTPUT_SUBPIXEL_UNKNOWN;
1344 case DRM_MODE_SUBPIXEL_NONE:
1345 return WL_OUTPUT_SUBPIXEL_NONE;
1346 case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
1347 return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
1348 case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
1349 return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
1350 case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
1351 return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
1352 case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
1353 return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
1357 /* returns a value between 0-255 range, where higher is brighter */
1359 drm_get_backlight(struct drm_output *output)
1361 long brightness, max_brightness, norm;
1363 brightness = backlight_get_brightness(output->backlight);
1364 max_brightness = backlight_get_max_brightness(output->backlight);
1366 /* convert it on a scale of 0 to 255 */
1367 norm = (brightness * 255)/(max_brightness);
1369 return (uint32_t) norm;
1372 /* values accepted are between 0-255 range */
1374 drm_set_backlight(struct weston_output *output_base, uint32_t value)
1376 struct drm_output *output = (struct drm_output *) output_base;
1377 long max_brightness, new_brightness;
1379 if (!output->backlight)
1385 max_brightness = backlight_get_max_brightness(output->backlight);
1387 /* get denormalized value */
1388 new_brightness = (value * max_brightness) / 255;
1390 backlight_set_brightness(output->backlight, new_brightness);
1393 static drmModePropertyPtr
1394 drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name)
1396 drmModePropertyPtr props;
1399 for (i = 0; i < connector->count_props; i++) {
1400 props = drmModeGetProperty(fd, connector->props[i]);
1404 if (!strcmp(props->name, name))
1407 drmModeFreeProperty(props);
1414 drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)
1416 struct drm_output *output = (struct drm_output *) output_base;
1417 struct weston_compositor *ec = output_base->compositor;
1418 struct drm_compositor *c = (struct drm_compositor *) ec;
1420 if (!output->dpms_prop)
1423 drmModeConnectorSetProperty(c->drm.fd, output->connector_id,
1424 output->dpms_prop->prop_id, level);
1427 static const char *connector_type_names[] = {
1446 find_crtc_for_connector(struct drm_compositor *ec,
1447 drmModeRes *resources, drmModeConnector *connector)
1449 drmModeEncoder *encoder;
1450 uint32_t possible_crtcs;
1453 for (j = 0; j < connector->count_encoders; j++) {
1454 encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[j]);
1455 if (encoder == NULL) {
1456 weston_log("Failed to get encoder.\n");
1459 possible_crtcs = encoder->possible_crtcs;
1460 drmModeFreeEncoder(encoder);
1462 for (i = 0; i < resources->count_crtcs; i++) {
1463 if (possible_crtcs & (1 << i) &&
1464 !(ec->crtc_allocator & (1 << resources->crtcs[i])))
1472 /* Init output state that depends on gl or gbm */
1474 drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec)
1478 output->surface = gbm_surface_create(ec->gbm,
1479 output->base.current_mode->width,
1480 output->base.current_mode->height,
1482 GBM_BO_USE_SCANOUT |
1483 GBM_BO_USE_RENDERING);
1484 if (!output->surface) {
1485 weston_log("failed to create gbm surface\n");
1489 if (gl_renderer->output_create(&output->base, output->surface) < 0) {
1490 weston_log("failed to create gl renderer output state\n");
1491 gbm_surface_destroy(output->surface);
1495 flags = GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE;
1497 for (i = 0; i < 2; i++) {
1498 if (output->cursor_bo[i])
1501 output->cursor_bo[i] =
1502 gbm_bo_create(ec->gbm, 64, 64, GBM_FORMAT_ARGB8888,
1506 if (output->cursor_bo[0] == NULL || output->cursor_bo[1] == NULL) {
1507 weston_log("cursor buffers unavailable, using gl cursors\n");
1508 ec->cursors_are_broken = 1;
1515 drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c)
1517 int w = output->base.current_mode->width;
1518 int h = output->base.current_mode->height;
1521 /* FIXME error checking */
1523 for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
1524 output->dumb[i] = drm_fb_create_dumb(c, w, h);
1525 if (!output->dumb[i])
1529 pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h,
1530 output->dumb[i]->map,
1531 output->dumb[i]->stride);
1532 if (!output->image[i])
1536 if (pixman_renderer_output_create(&output->base) < 0)
1539 pixman_region32_init_rect(&output->previous_damage,
1540 output->base.x, output->base.y, output->base.width, output->base.height);
1545 for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
1546 if (output->dumb[i])
1547 drm_fb_destroy_dumb(output->dumb[i]);
1548 if (output->image[i])
1549 pixman_image_unref(output->image[i]);
1551 output->dumb[i] = NULL;
1552 output->image[i] = NULL;
1559 drm_output_fini_pixman(struct drm_output *output)
1563 pixman_renderer_output_destroy(&output->base);
1564 pixman_region32_fini(&output->previous_damage);
1566 for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
1567 drm_fb_destroy_dumb(output->dumb[i]);
1568 pixman_image_unref(output->image[i]);
1569 output->dumb[i] = NULL;
1570 output->image[i] = NULL;
1575 edid_parse_string(const uint8_t *data, char text[])
1580 /* this is always 12 bytes, but we can't guarantee it's null
1581 * terminated or not junk. */
1582 strncpy(text, (const char *) data, 12);
1584 /* remove insane chars */
1585 for (i = 0; text[i] != '\0'; i++) {
1586 if (text[i] == '\n' ||
1593 /* ensure string is printable */
1594 for (i = 0; text[i] != '\0'; i++) {
1595 if (!isprint(text[i])) {
1601 /* if the string is random junk, ignore the string */
1606 #define EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe
1607 #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc
1608 #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff
1609 #define EDID_OFFSET_DATA_BLOCKS 0x36
1610 #define EDID_OFFSET_LAST_BLOCK 0x6c
1611 #define EDID_OFFSET_PNPID 0x08
1612 #define EDID_OFFSET_SERIAL 0x0c
1615 edid_parse(struct drm_edid *edid, const uint8_t *data, size_t length)
1618 uint32_t serial_number;
1623 if (data[0] != 0x00 || data[1] != 0xff)
1626 /* decode the PNP ID from three 5 bit words packed into 2 bytes
1631 edid->pnp_id[0] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x7c) / 4) - 1;
1632 edid->pnp_id[1] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x3) * 8) + ((data[EDID_OFFSET_PNPID + 1] & 0xe0) / 32) - 1;
1633 edid->pnp_id[2] = 'A' + (data[EDID_OFFSET_PNPID + 1] & 0x1f) - 1;
1634 edid->pnp_id[3] = '\0';
1636 /* maybe there isn't a ASCII serial number descriptor, so use this instead */
1637 serial_number = (uint32_t) data[EDID_OFFSET_SERIAL + 0];
1638 serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 1] * 0x100;
1639 serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 2] * 0x10000;
1640 serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 3] * 0x1000000;
1641 if (serial_number > 0)
1642 sprintf(edid->serial_number, "%lu", (unsigned long) serial_number);
1644 /* parse EDID data */
1645 for (i = EDID_OFFSET_DATA_BLOCKS;
1646 i <= EDID_OFFSET_LAST_BLOCK;
1648 /* ignore pixel clock data */
1654 /* any useful blocks? */
1655 if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME) {
1656 edid_parse_string(&data[i+5],
1657 edid->monitor_name);
1658 } else if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) {
1659 edid_parse_string(&data[i+5],
1660 edid->serial_number);
1661 } else if (data[i+3] == EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) {
1662 edid_parse_string(&data[i+5],
1670 find_and_parse_output_edid(struct drm_compositor *ec,
1671 struct drm_output *output,
1672 drmModeConnector *connector)
1674 drmModePropertyBlobPtr edid_blob = NULL;
1675 drmModePropertyPtr property;
1679 for (i = 0; i < connector->count_props && !edid_blob; i++) {
1680 property = drmModeGetProperty(ec->drm.fd, connector->props[i]);
1683 if ((property->flags & DRM_MODE_PROP_BLOB) &&
1684 !strcmp(property->name, "EDID")) {
1685 edid_blob = drmModeGetPropertyBlob(ec->drm.fd,
1686 connector->prop_values[i]);
1688 drmModeFreeProperty(property);
1693 rc = edid_parse(&output->edid,
1697 weston_log("EDID data '%s', '%s', '%s'\n",
1698 output->edid.pnp_id,
1699 output->edid.monitor_name,
1700 output->edid.serial_number);
1701 if (output->edid.pnp_id[0] != '\0')
1702 output->base.make = output->edid.pnp_id;
1703 if (output->edid.monitor_name[0] != '\0')
1704 output->base.model = output->edid.monitor_name;
1705 if (output->edid.serial_number[0] != '\0')
1706 output->base.serial_number = output->edid.serial_number;
1708 drmModeFreePropertyBlob(edid_blob);
1714 parse_modeline(const char *s, drmModeModeInfo *mode)
1720 mode->type = DRM_MODE_TYPE_USERDEF;
1726 if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s",
1735 &mode->vtotal, hsync, vsync) != 11)
1738 mode->clock = fclock * 1000;
1739 if (strcmp(hsync, "+hsync") == 0)
1740 mode->flags |= DRM_MODE_FLAG_PHSYNC;
1741 else if (strcmp(hsync, "-hsync") == 0)
1742 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1746 if (strcmp(vsync, "+vsync") == 0)
1747 mode->flags |= DRM_MODE_FLAG_PVSYNC;
1748 else if (strcmp(vsync, "-vsync") == 0)
1749 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1757 parse_transform(const char *transform, const char *output_name)
1759 static const struct { const char *name; uint32_t token; } names[] = {
1760 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
1761 { "90", WL_OUTPUT_TRANSFORM_90 },
1762 { "180", WL_OUTPUT_TRANSFORM_180 },
1763 { "270", WL_OUTPUT_TRANSFORM_270 },
1764 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
1765 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
1766 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
1767 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
1771 for (i = 0; i < ARRAY_LENGTH(names); i++)
1772 if (strcmp(names[i].name, transform) == 0)
1773 return names[i].token;
1775 weston_log("Invalid transform \"%s\" for output %s\n",
1776 transform, output_name);
1778 return WL_OUTPUT_TRANSFORM_NORMAL;
1782 setup_output_seat_constraint(struct drm_compositor *ec,
1783 struct weston_output *output,
1786 if (strcmp(s, "") != 0) {
1787 struct udev_seat *seat;
1789 seat = udev_seat_get_named(&ec->base, s);
1791 seat->base.output = output;
1793 if (seat && seat->base.pointer)
1794 weston_pointer_clamp(seat->base.pointer,
1795 &seat->base.pointer->x,
1796 &seat->base.pointer->y);
1801 create_output_for_connector(struct drm_compositor *ec,
1802 drmModeRes *resources,
1803 drmModeConnector *connector,
1804 int x, int y, struct udev_device *drm_device)
1806 struct drm_output *output;
1807 struct drm_mode *drm_mode, *next, *preferred, *current, *configured;
1808 struct weston_mode *m;
1809 struct weston_config_section *section;
1810 drmModeEncoder *encoder;
1811 drmModeModeInfo crtc_mode, modeline;
1813 int i, width, height, scale;
1815 const char *type_name;
1816 enum output_config config;
1819 i = find_crtc_for_connector(ec, resources, connector);
1821 weston_log("No usable crtc/encoder pair for connector.\n");
1825 output = zalloc(sizeof *output);
1829 output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);
1830 output->base.make = "unknown";
1831 output->base.model = "unknown";
1832 output->base.serial_number = "unknown";
1833 wl_list_init(&output->base.mode_list);
1835 if (connector->connector_type < ARRAY_LENGTH(connector_type_names))
1836 type_name = connector_type_names[connector->connector_type];
1838 type_name = "UNKNOWN";
1839 snprintf(name, 32, "%s%d", type_name, connector->connector_type_id);
1840 output->base.name = strdup(name);
1842 section = weston_config_get_section(ec->base.config, "output", "name",
1844 weston_config_section_get_string(section, "mode", &s, "preferred");
1845 if (strcmp(s, "off") == 0)
1846 config = OUTPUT_CONFIG_OFF;
1847 else if (strcmp(s, "preferred") == 0)
1848 config = OUTPUT_CONFIG_PREFERRED;
1849 else if (strcmp(s, "current") == 0)
1850 config = OUTPUT_CONFIG_CURRENT;
1851 else if (sscanf(s, "%dx%d", &width, &height) == 2)
1852 config = OUTPUT_CONFIG_MODE;
1853 else if (parse_modeline(s, &modeline) == 0)
1854 config = OUTPUT_CONFIG_MODELINE;
1856 weston_log("Invalid mode \"%s\" for output %s\n",
1857 s, output->base.name);
1858 config = OUTPUT_CONFIG_PREFERRED;
1862 weston_config_section_get_int(section, "scale", &scale, 1);
1863 weston_config_section_get_string(section, "transform", &s, "normal");
1864 transform = parse_transform(s, output->base.name);
1867 weston_config_section_get_string(section, "seat", &s, "");
1868 setup_output_seat_constraint(ec, &output->base, s);
1871 output->crtc_id = resources->crtcs[i];
1873 ec->crtc_allocator |= (1 << output->crtc_id);
1874 output->connector_id = connector->connector_id;
1875 ec->connector_allocator |= (1 << output->connector_id);
1877 output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id);
1878 output->dpms_prop = drm_get_prop(ec->drm.fd, connector, "DPMS");
1880 /* Get the current mode on the crtc that's currently driving
1881 * this connector. */
1882 encoder = drmModeGetEncoder(ec->drm.fd, connector->encoder_id);
1883 memset(&crtc_mode, 0, sizeof crtc_mode);
1884 if (encoder != NULL) {
1885 crtc = drmModeGetCrtc(ec->drm.fd, encoder->crtc_id);
1886 drmModeFreeEncoder(encoder);
1889 if (crtc->mode_valid)
1890 crtc_mode = crtc->mode;
1891 drmModeFreeCrtc(crtc);
1894 for (i = 0; i < connector->count_modes; i++) {
1895 drm_mode = drm_output_add_mode(output, &connector->modes[i]);
1900 if (config == OUTPUT_CONFIG_OFF) {
1901 weston_log("Disabling output %s\n", output->base.name);
1902 drmModeSetCrtc(ec->drm.fd, output->crtc_id,
1903 0, 0, 0, 0, 0, NULL);
1911 wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
1912 if (config == OUTPUT_CONFIG_MODE &&
1913 width == drm_mode->base.width &&
1914 height == drm_mode->base.height)
1915 configured = drm_mode;
1916 if (!memcmp(&crtc_mode, &drm_mode->mode_info, sizeof crtc_mode))
1918 if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED)
1919 preferred = drm_mode;
1922 if (config == OUTPUT_CONFIG_MODELINE) {
1923 configured = drm_output_add_mode(output, &modeline);
1928 if (current == NULL && crtc_mode.clock != 0) {
1929 current = drm_output_add_mode(output, &crtc_mode);
1934 if (config == OUTPUT_CONFIG_CURRENT)
1935 configured = current;
1937 if (option_current_mode && current)
1938 output->base.current_mode = ¤t->base;
1939 else if (configured)
1940 output->base.current_mode = &configured->base;
1942 output->base.current_mode = &preferred->base;
1944 output->base.current_mode = ¤t->base;
1946 if (output->base.current_mode == NULL) {
1947 weston_log("no available modes for %s\n", output->base.name);
1951 output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
1953 weston_output_init(&output->base, &ec->base, x, y,
1954 connector->mmWidth, connector->mmHeight,
1957 if (ec->use_pixman) {
1958 if (drm_output_init_pixman(output, ec) < 0) {
1959 weston_log("Failed to init output pixman state\n");
1962 } else if (drm_output_init_egl(output, ec) < 0) {
1963 weston_log("Failed to init output gl state\n");
1967 output->backlight = backlight_init(drm_device,
1968 connector->connector_type);
1969 if (output->backlight) {
1970 weston_log("Initialized backlight, device %s\n",
1971 output->backlight->path);
1972 output->base.set_backlight = drm_set_backlight;
1973 output->base.backlight_current = drm_get_backlight(output);
1975 weston_log("Failed to initialize backlight\n");
1978 wl_list_insert(ec->base.output_list.prev, &output->base.link);
1980 find_and_parse_output_edid(ec, output, connector);
1981 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
1982 output->base.connection_internal = 1;
1984 output->base.start_repaint_loop = drm_output_start_repaint_loop;
1985 output->base.repaint = drm_output_repaint;
1986 output->base.destroy = drm_output_destroy;
1987 output->base.assign_planes = drm_assign_planes;
1988 output->base.set_dpms = drm_set_dpms;
1989 output->base.switch_mode = drm_output_switch_mode;
1991 output->base.gamma_size = output->original_crtc->gamma_size;
1992 output->base.set_gamma = drm_output_set_gamma;
1994 weston_plane_init(&output->cursor_plane, 0, 0);
1995 weston_plane_init(&output->fb_plane, 0, 0);
1997 weston_compositor_stack_plane(&ec->base, &output->cursor_plane, NULL);
1998 weston_compositor_stack_plane(&ec->base, &output->fb_plane,
1999 &ec->base.primary_plane);
2001 weston_log("Output %s, (connector %d, crtc %d)\n",
2002 output->base.name, output->connector_id, output->crtc_id);
2003 wl_list_for_each(m, &output->base.mode_list, link)
2004 weston_log_continue(" mode %dx%d@%.1f%s%s%s\n",
2005 m->width, m->height, m->refresh / 1000.0,
2006 m->flags & WL_OUTPUT_MODE_PREFERRED ?
2008 m->flags & WL_OUTPUT_MODE_CURRENT ?
2010 connector->count_modes == 0 ?
2016 weston_output_destroy(&output->base);
2018 wl_list_for_each_safe(drm_mode, next, &output->base.mode_list,
2020 wl_list_remove(&drm_mode->base.link);
2024 drmModeFreeCrtc(output->original_crtc);
2025 ec->crtc_allocator &= ~(1 << output->crtc_id);
2026 ec->connector_allocator &= ~(1 << output->connector_id);
2033 create_sprites(struct drm_compositor *ec)
2035 struct drm_sprite *sprite;
2036 drmModePlaneRes *plane_res;
2037 drmModePlane *plane;
2040 plane_res = drmModeGetPlaneResources(ec->drm.fd);
2042 weston_log("failed to get plane resources: %s\n",
2047 for (i = 0; i < plane_res->count_planes; i++) {
2048 plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]);
2052 sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
2053 plane->count_formats));
2055 weston_log("%s: out of memory\n",
2061 sprite->possible_crtcs = plane->possible_crtcs;
2062 sprite->plane_id = plane->plane_id;
2063 sprite->current = NULL;
2064 sprite->next = NULL;
2065 sprite->compositor = ec;
2066 sprite->count_formats = plane->count_formats;
2067 memcpy(sprite->formats, plane->formats,
2068 plane->count_formats * sizeof(plane->formats[0]));
2069 drmModeFreePlane(plane);
2070 weston_plane_init(&sprite->plane, 0, 0);
2071 weston_compositor_stack_plane(&ec->base, &sprite->plane,
2072 &ec->base.primary_plane);
2074 wl_list_insert(&ec->sprite_list, &sprite->link);
2077 drmModeFreePlaneResources(plane_res);
2081 destroy_sprites(struct drm_compositor *compositor)
2083 struct drm_sprite *sprite, *next;
2084 struct drm_output *output;
2086 output = container_of(compositor->base.output_list.next,
2087 struct drm_output, base.link);
2089 wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) {
2090 drmModeSetPlane(compositor->drm.fd,
2092 output->crtc_id, 0, 0,
2093 0, 0, 0, 0, 0, 0, 0, 0);
2094 drm_output_release_fb(output, sprite->current);
2095 drm_output_release_fb(output, sprite->next);
2096 weston_plane_release(&sprite->plane);
2102 create_outputs(struct drm_compositor *ec, uint32_t option_connector,
2103 struct udev_device *drm_device)
2105 drmModeConnector *connector;
2106 drmModeRes *resources;
2110 resources = drmModeGetResources(ec->drm.fd);
2112 weston_log("drmModeGetResources failed\n");
2116 ec->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t));
2118 drmModeFreeResources(resources);
2122 ec->min_width = resources->min_width;
2123 ec->max_width = resources->max_width;
2124 ec->min_height = resources->min_height;
2125 ec->max_height = resources->max_height;
2127 ec->num_crtcs = resources->count_crtcs;
2128 memcpy(ec->crtcs, resources->crtcs, sizeof(uint32_t) * ec->num_crtcs);
2130 for (i = 0; i < resources->count_connectors; i++) {
2131 connector = drmModeGetConnector(ec->drm.fd,
2132 resources->connectors[i]);
2133 if (connector == NULL)
2136 if (connector->connection == DRM_MODE_CONNECTED &&
2137 (option_connector == 0 ||
2138 connector->connector_id == option_connector)) {
2139 if (create_output_for_connector(ec, resources,
2142 drmModeFreeConnector(connector);
2146 x += container_of(ec->base.output_list.prev,
2147 struct weston_output,
2151 drmModeFreeConnector(connector);
2154 if (wl_list_empty(&ec->base.output_list)) {
2155 weston_log("No currently active connector found.\n");
2156 drmModeFreeResources(resources);
2160 drmModeFreeResources(resources);
2166 update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
2168 drmModeConnector *connector;
2169 drmModeRes *resources;
2170 struct drm_output *output, *next;
2172 int x_offset = 0, y_offset = 0;
2173 uint32_t connected = 0, disconnects = 0;
2176 resources = drmModeGetResources(ec->drm.fd);
2178 weston_log("drmModeGetResources failed\n");
2182 /* collect new connects */
2183 for (i = 0; i < resources->count_connectors; i++) {
2184 int connector_id = resources->connectors[i];
2186 connector = drmModeGetConnector(ec->drm.fd, connector_id);
2187 if (connector == NULL)
2190 if (connector->connection != DRM_MODE_CONNECTED) {
2191 drmModeFreeConnector(connector);
2195 connected |= (1 << connector_id);
2197 if (!(ec->connector_allocator & (1 << connector_id))) {
2198 struct weston_output *last =
2199 container_of(ec->base.output_list.prev,
2200 struct weston_output, link);
2202 /* XXX: not yet needed, we die with 0 outputs */
2203 if (!wl_list_empty(&ec->base.output_list))
2204 x = last->x + last->width;
2208 create_output_for_connector(ec, resources,
2211 weston_log("connector %d connected\n", connector_id);
2214 drmModeFreeConnector(connector);
2216 drmModeFreeResources(resources);
2218 disconnects = ec->connector_allocator & ~connected;
2220 wl_list_for_each_safe(output, next, &ec->base.output_list,
2222 if (x_offset != 0 || y_offset != 0) {
2223 weston_output_move(&output->base,
2224 output->base.x - x_offset,
2225 output->base.y - y_offset);
2228 if (disconnects & (1 << output->connector_id)) {
2229 disconnects &= ~(1 << output->connector_id);
2230 weston_log("connector %d disconnected\n",
2231 output->connector_id);
2232 x_offset += output->base.width;
2233 drm_output_destroy(&output->base);
2238 /* FIXME: handle zero outputs, without terminating */
2239 if (ec->connector_allocator == 0)
2240 wl_display_terminate(ec->base.wl_display);
2244 udev_event_is_hotplug(struct drm_compositor *ec, struct udev_device *device)
2249 sysnum = udev_device_get_sysnum(device);
2250 if (!sysnum || atoi(sysnum) != ec->drm.id)
2253 val = udev_device_get_property_value(device, "HOTPLUG");
2257 return strcmp(val, "1") == 0;
2261 udev_drm_event(int fd, uint32_t mask, void *data)
2263 struct drm_compositor *ec = data;
2264 struct udev_device *event;
2266 event = udev_monitor_receive_device(ec->udev_monitor);
2268 if (udev_event_is_hotplug(ec, event))
2269 update_outputs(ec, event);
2271 udev_device_unref(event);
2277 drm_restore(struct weston_compositor *ec)
2279 weston_launcher_restore(ec->launcher);
2283 drm_destroy(struct weston_compositor *ec)
2285 struct drm_compositor *d = (struct drm_compositor *) ec;
2287 udev_input_destroy(&d->input);
2289 wl_event_source_remove(d->udev_drm_source);
2290 wl_event_source_remove(d->drm_source);
2294 weston_compositor_shutdown(ec);
2296 ec->renderer->destroy(ec);
2299 gbm_device_destroy(d->gbm);
2301 weston_launcher_destroy(d->base.launcher);
2309 drm_compositor_set_modes(struct drm_compositor *compositor)
2311 struct drm_output *output;
2312 struct drm_mode *drm_mode;
2315 wl_list_for_each(output, &compositor->base.output_list, base.link) {
2316 if (!output->current) {
2317 /* If something that would cause the output to
2318 * switch mode happened while in another vt, we
2319 * might not have a current drm_fb. In that case,
2320 * schedule a repaint and let drm_output_repaint
2321 * handle setting the mode. */
2322 weston_output_schedule_repaint(&output->base);
2326 drm_mode = (struct drm_mode *) output->base.current_mode;
2327 ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
2328 output->current->fb_id, 0, 0,
2329 &output->connector_id, 1,
2330 &drm_mode->mode_info);
2333 "failed to set mode %dx%d for output at %d,%d: %m\n",
2334 drm_mode->base.width, drm_mode->base.height,
2335 output->base.x, output->base.y);
2341 session_notify(struct wl_listener *listener, void *data)
2343 struct weston_compositor *compositor = data;
2344 struct drm_compositor *ec = data;
2345 struct drm_sprite *sprite;
2346 struct drm_output *output;
2348 if (ec->base.session_active) {
2349 weston_log("activating session\n");
2350 compositor->focus = 1;
2351 if (ec->base.launcher == NULL && drmSetMaster(ec->drm.fd)) {
2352 weston_log("failed to set master: %m\n");
2353 wl_display_terminate(compositor->wl_display);
2355 compositor->state = ec->prev_state;
2356 drm_compositor_set_modes(ec);
2357 weston_compositor_damage_all(compositor);
2358 udev_input_enable(&ec->input, ec->udev);
2360 weston_log("deactivating session\n");
2361 udev_input_disable(&ec->input);
2363 compositor->focus = 0;
2364 ec->prev_state = compositor->state;
2365 weston_compositor_offscreen(compositor);
2367 /* If we have a repaint scheduled (either from a
2368 * pending pageflip or the idle handler), make sure we
2369 * cancel that so we don't try to pageflip when we're
2370 * vt switched away. The OFFSCREEN state will prevent
2371 * further attemps at repainting. When we switch
2372 * back, we schedule a repaint, which will process
2373 * pending frame callbacks. */
2375 wl_list_for_each(output, &ec->base.output_list, base.link) {
2376 output->base.repaint_needed = 0;
2377 drmModeSetCursor(ec->drm.fd, output->crtc_id, 0, 0, 0);
2380 output = container_of(ec->base.output_list.next,
2381 struct drm_output, base.link);
2383 wl_list_for_each(sprite, &ec->sprite_list, link)
2384 drmModeSetPlane(ec->drm.fd,
2386 output->crtc_id, 0, 0,
2387 0, 0, 0, 0, 0, 0, 0, 0);
2389 if (ec->base.launcher == NULL && drmDropMaster(ec->drm.fd) < 0)
2390 weston_log("failed to drop master: %m\n");
2395 switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
2397 struct weston_compositor *compositor = data;
2399 weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
2404 * Some systems may have multiple DRM devices attached to a single seat. This
2405 * function loops over all devices and tries to find a PCI device with the
2406 * boot_vga sysfs attribute set to 1.
2407 * If no such device is found, the first DRM device reported by udev is used.
2409 static struct udev_device*
2410 find_primary_gpu(struct drm_compositor *ec, const char *seat)
2412 struct udev_enumerate *e;
2413 struct udev_list_entry *entry;
2414 const char *path, *device_seat, *id;
2415 struct udev_device *device, *drm_device, *pci;
2417 e = udev_enumerate_new(ec->udev);
2418 udev_enumerate_add_match_subsystem(e, "drm");
2419 udev_enumerate_add_match_sysname(e, "card[0-9]*");
2421 udev_enumerate_scan_devices(e);
2423 udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
2424 path = udev_list_entry_get_name(entry);
2425 device = udev_device_new_from_syspath(ec->udev, path);
2428 device_seat = udev_device_get_property_value(device, "ID_SEAT");
2430 device_seat = default_seat;
2431 if (strcmp(device_seat, seat)) {
2432 udev_device_unref(device);
2436 pci = udev_device_get_parent_with_subsystem_devtype(device,
2439 id = udev_device_get_sysattr_value(pci, "boot_vga");
2440 if (id && !strcmp(id, "1")) {
2442 udev_device_unref(drm_device);
2443 drm_device = device;
2449 drm_device = device;
2451 udev_device_unref(device);
2454 udev_enumerate_unref(e);
2459 planes_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
2461 struct drm_compositor *c = data;
2465 c->cursors_are_broken ^= 1;
2468 c->sprites_are_broken ^= 1;
2471 c->sprites_hidden ^= 1;
2478 #ifdef BUILD_VAAPI_RECORDER
2480 recorder_frame_notify(struct wl_listener *listener, void *data)
2482 struct drm_output *output;
2483 struct drm_compositor *c;
2486 output = container_of(listener, struct drm_output,
2487 recorder_frame_listener);
2488 c = (struct drm_compositor *) output->base.compositor;
2490 if (!output->recorder)
2493 ret = drmPrimeHandleToFD(c->drm.fd, output->current->handle,
2496 weston_log("[libva recorder] "
2497 "failed to create prime fd for front buffer\n");
2501 vaapi_recorder_frame(output->recorder, fd, output->current->stride / 4);
2505 create_recorder(struct drm_compositor *c, int width, int height,
2506 const char *filename)
2511 fd = open(c->drm.filename, O_RDWR | O_CLOEXEC);
2515 drmGetMagic(fd, &magic);
2516 drmAuthMagic(c->drm.fd, magic);
2518 return vaapi_recorder_create(fd, width, height, filename);
2522 recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2525 struct drm_compositor *c = data;
2526 struct drm_output *output;
2529 output = container_of(c->base.output_list.next,
2530 struct drm_output, base.link);
2532 if (!output->recorder) {
2533 width = output->base.current_mode->width;
2534 height = output->base.current_mode->height;
2537 create_recorder(c, width, height, "capture.h264");
2538 if (!output->recorder) {
2539 weston_log("failed to create vaapi recorder\n");
2543 output->base.disable_planes++;
2545 output->recorder_frame_listener.notify = recorder_frame_notify;
2546 wl_signal_add(&output->base.frame_signal,
2547 &output->recorder_frame_listener);
2549 weston_output_schedule_repaint(&output->base);
2551 weston_log("[libva recorder] initialized\n");
2553 vaapi_recorder_destroy(output->recorder);
2554 output->recorder = NULL;
2556 output->base.disable_planes--;
2558 wl_list_remove(&output->recorder_frame_listener.link);
2559 weston_log("[libva recorder] done\n");
2564 recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2567 weston_log("Compiled without libva support\n");
2571 static struct weston_compositor *
2572 drm_compositor_create(struct wl_display *display,
2573 int connector, const char *seat_id, int tty, int pixman,
2574 int *argc, char *argv[],
2575 struct weston_config *config)
2577 struct drm_compositor *ec;
2578 struct udev_device *drm_device;
2579 struct wl_event_loop *loop;
2583 weston_log("initializing drm backend\n");
2585 ec = zalloc(sizeof *ec);
2589 /* KMS support for sprites is not complete yet, so disable the
2590 * functionality for now. */
2591 ec->sprites_are_broken = 1;
2592 ec->format = GBM_FORMAT_XRGB8888;
2593 ec->use_pixman = pixman;
2595 if (weston_compositor_init(&ec->base, display, argc, argv,
2597 weston_log("%s failed\n", __func__);
2601 /* Check if we run drm-backend using weston-launch */
2602 ec->base.launcher = weston_launcher_connect(&ec->base, tty);
2603 if (ec->base.launcher == NULL) {
2604 weston_log("fatal: drm backend should be run "
2605 "using weston-launch binary or as root\n");
2606 goto err_compositor;
2609 ec->udev = udev_new();
2610 if (ec->udev == NULL) {
2611 weston_log("failed to initialize udev context\n");
2615 ec->base.wl_display = display;
2616 ec->session_listener.notify = session_notify;
2617 wl_signal_add(&ec->base.session_signal, &ec->session_listener);
2619 drm_device = find_primary_gpu(ec, seat_id);
2620 if (drm_device == NULL) {
2621 weston_log("no drm device found\n");
2624 path = udev_device_get_syspath(drm_device);
2626 if (init_drm(ec, drm_device) < 0) {
2627 weston_log("failed to initialize kms\n");
2631 if (ec->use_pixman) {
2632 if (init_pixman(ec) < 0) {
2633 weston_log("failed to initialize pixman renderer\n");
2637 if (init_egl(ec) < 0) {
2638 weston_log("failed to initialize egl\n");
2643 ec->base.destroy = drm_destroy;
2644 ec->base.restore = drm_restore;
2648 ec->prev_state = WESTON_COMPOSITOR_ACTIVE;
2650 for (key = KEY_F1; key < KEY_F9; key++)
2651 weston_compositor_add_key_binding(&ec->base, key,
2652 MODIFIER_CTRL | MODIFIER_ALT,
2653 switch_vt_binding, ec);
2655 wl_list_init(&ec->sprite_list);
2658 if (create_outputs(ec, connector, drm_device) < 0) {
2659 weston_log("failed to create output for %s\n", path);
2665 if (udev_input_init(&ec->input, &ec->base, ec->udev, seat_id) < 0) {
2666 weston_log("failed to create input devices\n");
2670 loop = wl_display_get_event_loop(ec->base.wl_display);
2672 wl_event_loop_add_fd(loop, ec->drm.fd,
2673 WL_EVENT_READABLE, on_drm_input, ec);
2675 ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
2676 if (ec->udev_monitor == NULL) {
2677 weston_log("failed to intialize udev monitor\n");
2678 goto err_drm_source;
2680 udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor,
2682 ec->udev_drm_source =
2683 wl_event_loop_add_fd(loop,
2684 udev_monitor_get_fd(ec->udev_monitor),
2685 WL_EVENT_READABLE, udev_drm_event, ec);
2687 if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) {
2688 weston_log("failed to enable udev-monitor receiving\n");
2689 goto err_udev_monitor;
2692 udev_device_unref(drm_device);
2694 weston_compositor_add_debug_binding(&ec->base, KEY_O,
2695 planes_binding, ec);
2696 weston_compositor_add_debug_binding(&ec->base, KEY_C,
2697 planes_binding, ec);
2698 weston_compositor_add_debug_binding(&ec->base, KEY_V,
2699 planes_binding, ec);
2700 weston_compositor_add_debug_binding(&ec->base, KEY_Q,
2701 recorder_binding, ec);
2706 wl_event_source_remove(ec->udev_drm_source);
2707 udev_monitor_unref(ec->udev_monitor);
2709 wl_event_source_remove(ec->drm_source);
2710 udev_input_destroy(&ec->input);
2712 ec->base.renderer->destroy(&ec->base);
2713 gbm_device_destroy(ec->gbm);
2714 destroy_sprites(ec);
2716 udev_device_unref(drm_device);
2718 weston_launcher_destroy(ec->base.launcher);
2720 udev_unref(ec->udev);
2722 weston_compositor_shutdown(&ec->base);
2728 WL_EXPORT struct weston_compositor *
2729 backend_init(struct wl_display *display, int *argc, char *argv[],
2730 struct weston_config *config)
2732 int connector = 0, tty = 0, use_pixman = 0;
2733 const char *seat_id = default_seat;
2735 const struct weston_option drm_options[] = {
2736 { WESTON_OPTION_INTEGER, "connector", 0, &connector },
2737 { WESTON_OPTION_STRING, "seat", 0, &seat_id },
2738 { WESTON_OPTION_INTEGER, "tty", 0, &tty },
2739 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &option_current_mode },
2740 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
2743 parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv);
2745 return drm_compositor_create(display, connector, seat_id, tty, use_pixman,
2746 argc, argv, config);