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)
416 struct drm_compositor *c =
417 (struct drm_compositor *) output->base.compositor;
421 format = gbm_bo_get_format(bo);
423 if (format == GBM_FORMAT_ARGB8888) {
424 /* We can scanout an ARGB buffer if the surface's
425 * opaque region covers the whole output, but we have
426 * to use XRGB as the KMS format code. */
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;
434 pixman_region32_fini(&r);
437 if (c->format == format)
443 static struct weston_plane *
444 drm_output_prepare_scanout_surface(struct weston_output *_output,
445 struct weston_surface *es)
447 struct drm_output *output = (struct drm_output *) _output;
448 struct drm_compositor *c =
449 (struct drm_compositor *) output->base.compositor;
450 struct weston_buffer *buffer = es->buffer_ref.buffer;
454 if (es->geometry.x != output->base.x ||
455 es->geometry.y != output->base.y ||
456 buffer == NULL || c->gbm == NULL ||
457 buffer->width != output->base.current_mode->width ||
458 buffer->height != output->base.current_mode->height ||
459 output->base.transform != es->buffer_transform ||
460 es->transform.enabled)
463 bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER,
464 buffer->resource, GBM_BO_USE_SCANOUT);
466 /* Unable to use the buffer for scanout */
470 format = drm_output_check_scanout_format(output, es, bo);
476 output->next = drm_fb_get_from_bo(bo, c, format);
482 drm_fb_set_buffer(output->next, buffer);
484 return &output->fb_plane;
488 drm_output_render_gl(struct drm_output *output, pixman_region32_t *damage)
490 struct drm_compositor *c =
491 (struct drm_compositor *) output->base.compositor;
494 c->base.renderer->repaint_output(&output->base, damage);
496 bo = gbm_surface_lock_front_buffer(output->surface);
498 weston_log("failed to lock front buffer: %m\n");
502 output->next = drm_fb_get_from_bo(bo, c, c->format);
504 weston_log("failed to get drm_fb for bo\n");
505 gbm_surface_release_buffer(output->surface, bo);
511 drm_output_render_pixman(struct drm_output *output, pixman_region32_t *damage)
513 struct weston_compositor *ec = output->base.compositor;
514 pixman_region32_t total_damage, previous_damage;
516 pixman_region32_init(&total_damage);
517 pixman_region32_init(&previous_damage);
519 pixman_region32_copy(&previous_damage, damage);
521 pixman_region32_union(&total_damage, damage, &output->previous_damage);
522 pixman_region32_copy(&output->previous_damage, &previous_damage);
524 output->current_image ^= 1;
526 output->next = output->dumb[output->current_image];
527 pixman_renderer_output_set_buffer(&output->base,
528 output->image[output->current_image]);
530 ec->renderer->repaint_output(&output->base, &total_damage);
532 pixman_region32_fini(&total_damage);
533 pixman_region32_fini(&previous_damage);
537 drm_output_render(struct drm_output *output, pixman_region32_t *damage)
539 struct drm_compositor *c =
540 (struct drm_compositor *) output->base.compositor;
543 drm_output_render_pixman(output, damage);
545 drm_output_render_gl(output, damage);
547 pixman_region32_subtract(&c->base.primary_plane.damage,
548 &c->base.primary_plane.damage, damage);
552 drm_output_set_gamma(struct weston_output *output_base,
553 uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b)
556 struct drm_output *output = (struct drm_output *) output_base;
557 struct drm_compositor *compositor = (struct drm_compositor *) output->base.compositor;
560 if (output_base->gamma_size != size)
562 if (!output->original_crtc)
565 rc = drmModeCrtcSetGamma(compositor->drm.fd,
569 weston_log("set gamma failed: %m\n");
573 drm_output_repaint(struct weston_output *output_base,
574 pixman_region32_t *damage)
576 struct drm_output *output = (struct drm_output *) output_base;
577 struct drm_compositor *compositor =
578 (struct drm_compositor *) output->base.compositor;
579 struct drm_sprite *s;
580 struct drm_mode *mode;
583 if (output->destroy_pending)
587 drm_output_render(output, damage);
591 mode = container_of(output->base.current_mode, struct drm_mode, base);
592 if (!output->current) {
593 ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
594 output->next->fb_id, 0, 0,
595 &output->connector_id, 1,
598 weston_log("set mode failed: %m\n");
601 output_base->set_dpms(output_base, WESTON_DPMS_ON);
604 if (drmModePageFlip(compositor->drm.fd, output->crtc_id,
606 DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
607 weston_log("queueing pageflip failed: %m\n");
611 output->page_flip_pending = 1;
613 drm_output_set_cursor(output);
616 * Now, update all the sprite surfaces
618 wl_list_for_each(s, &compositor->sprite_list, link) {
619 uint32_t flags = 0, fb_id = 0;
621 .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT,
622 .request.sequence = 1,
625 if ((!s->current && !s->next) ||
626 !drm_sprite_crtc_supported(output_base, s->possible_crtcs))
629 if (s->next && !compositor->sprites_hidden)
630 fb_id = s->next->fb_id;
632 ret = drmModeSetPlane(compositor->drm.fd, s->plane_id,
633 output->crtc_id, fb_id, flags,
634 s->dest_x, s->dest_y,
635 s->dest_w, s->dest_h,
639 weston_log("setplane failed: %d: %s\n",
640 ret, strerror(errno));
642 if (output->pipe > 0)
643 vbl.request.type |= DRM_VBLANK_SECONDARY;
646 * Queue a vblank signal so we know when the surface
647 * becomes active on the display or has been replaced.
649 vbl.request.signal = (unsigned long)s;
650 ret = drmWaitVBlank(compositor->drm.fd, &vbl);
652 weston_log("vblank event request failed: %d: %s\n",
653 ret, strerror(errno));
657 output->vblank_pending = 1;
664 drm_output_start_repaint_loop(struct weston_output *output_base)
666 struct drm_output *output = (struct drm_output *) output_base;
667 struct drm_compositor *compositor = (struct drm_compositor *)
668 output_base->compositor;
673 if (output->destroy_pending)
676 if (!output->current) {
677 /* We can't page flip if there's no mode set */
680 clock_gettime(compositor->clock, &ts);
681 msec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
682 weston_output_finish_frame(output_base, msec);
686 fb_id = output->current->fb_id;
688 if (drmModePageFlip(compositor->drm.fd, output->crtc_id, fb_id,
689 DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
690 weston_log("queueing pageflip failed: %m\n");
696 vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec,
699 struct drm_sprite *s = (struct drm_sprite *)data;
700 struct drm_output *output = s->output;
703 output->vblank_pending = 0;
705 drm_output_release_fb(output, s->current);
706 s->current = s->next;
709 if (!output->page_flip_pending) {
710 msecs = sec * 1000 + usec / 1000;
711 weston_output_finish_frame(&output->base, msecs);
716 drm_output_destroy(struct weston_output *output_base);
719 page_flip_handler(int fd, unsigned int frame,
720 unsigned int sec, unsigned int usec, void *data)
722 struct drm_output *output = (struct drm_output *) data;
725 /* We don't set page_flip_pending on start_repaint_loop, in that case
726 * we just want to page flip to the current buffer to get an accurate
728 if (output->page_flip_pending) {
729 drm_output_release_fb(output, output->current);
730 output->current = output->next;
734 output->page_flip_pending = 0;
736 if (output->destroy_pending)
737 drm_output_destroy(&output->base);
738 else if (!output->vblank_pending) {
739 msecs = sec * 1000 + usec / 1000;
740 weston_output_finish_frame(&output->base, msecs);
742 /* We can't call this from frame_notify, because the output's
743 * repaint needed flag is cleared just after that */
744 if (output->recorder)
745 weston_output_schedule_repaint(&output->base);
750 drm_output_check_sprite_format(struct drm_sprite *s,
751 struct weston_surface *es, struct gbm_bo *bo)
755 format = gbm_bo_get_format(bo);
757 if (format == GBM_FORMAT_ARGB8888) {
760 pixman_region32_init_rect(&r, 0, 0,
762 es->geometry.height);
763 pixman_region32_subtract(&r, &r, &es->opaque);
765 if (!pixman_region32_not_empty(&r))
766 format = GBM_FORMAT_XRGB8888;
768 pixman_region32_fini(&r);
771 for (i = 0; i < s->count_formats; i++)
772 if (s->formats[i] == format)
779 drm_surface_transform_supported(struct weston_surface *es)
781 return !es->transform.enabled ||
782 (es->transform.matrix.type < WESTON_MATRIX_TRANSFORM_ROTATE);
785 static struct weston_plane *
786 drm_output_prepare_overlay_surface(struct weston_output *output_base,
787 struct weston_surface *es)
789 struct weston_compositor *ec = output_base->compositor;
790 struct drm_compositor *c =(struct drm_compositor *) ec;
791 struct drm_sprite *s;
794 pixman_region32_t dest_rect, src_rect;
795 pixman_box32_t *box, tbox;
797 wl_fixed_t sx1, sy1, sx2, sy2;
802 if (es->buffer_transform != output_base->transform)
805 if (es->buffer_scale != output_base->current_scale)
808 if (c->sprites_are_broken)
811 if (es->output_mask != (1u << output_base->id))
814 if (es->buffer_ref.buffer == NULL)
817 if (es->alpha != 1.0f)
820 if (wl_shm_buffer_get(es->buffer_ref.buffer->resource))
823 if (!drm_surface_transform_supported(es))
826 wl_list_for_each(s, &c->sprite_list, link) {
827 if (!drm_sprite_crtc_supported(output_base, s->possible_crtcs))
836 /* No sprites available */
840 bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER,
841 es->buffer_ref.buffer->resource,
846 format = drm_output_check_sprite_format(s, es, bo);
852 s->next = drm_fb_get_from_bo(bo, c, format);
858 drm_fb_set_buffer(s->next, es->buffer_ref.buffer);
860 box = pixman_region32_extents(&es->transform.boundingbox);
861 s->plane.x = box->x1;
862 s->plane.y = box->y1;
865 * Calculate the source & dest rects properly based on actual
866 * position (note the caller has called weston_surface_update_transform()
869 pixman_region32_init(&dest_rect);
870 pixman_region32_intersect(&dest_rect, &es->transform.boundingbox,
871 &output_base->region);
872 pixman_region32_translate(&dest_rect, -output_base->x, -output_base->y);
873 box = pixman_region32_extents(&dest_rect);
874 tbox = weston_transformed_rect(output_base->width,
876 output_base->transform,
877 output_base->current_scale,
881 s->dest_w = tbox.x2 - tbox.x1;
882 s->dest_h = tbox.y2 - tbox.y1;
883 pixman_region32_fini(&dest_rect);
885 pixman_region32_init(&src_rect);
886 pixman_region32_intersect(&src_rect, &es->transform.boundingbox,
887 &output_base->region);
888 box = pixman_region32_extents(&src_rect);
890 weston_surface_from_global_fixed(es,
891 wl_fixed_from_int(box->x1),
892 wl_fixed_from_int(box->y1),
894 weston_surface_from_global_fixed(es,
895 wl_fixed_from_int(box->x2),
896 wl_fixed_from_int(box->y2),
903 if (sx2 > wl_fixed_from_int(es->geometry.width))
904 sx2 = wl_fixed_from_int(es->geometry.width);
905 if (sy2 > wl_fixed_from_int(es->geometry.height))
906 sy2 = wl_fixed_from_int(es->geometry.height);
913 tbox = weston_transformed_rect(wl_fixed_from_int(es->geometry.width),
914 wl_fixed_from_int(es->geometry.height),
915 es->buffer_transform, es->buffer_scale, tbox);
917 s->src_x = tbox.x1 << 8;
918 s->src_y = tbox.y1 << 8;
919 s->src_w = (tbox.x2 - tbox.x1) << 8;
920 s->src_h = (tbox.y2 - tbox.y1) << 8;
921 pixman_region32_fini(&src_rect);
926 static struct weston_plane *
927 drm_output_prepare_cursor_surface(struct weston_output *output_base,
928 struct weston_surface *es)
930 struct drm_compositor *c =
931 (struct drm_compositor *) output_base->compositor;
932 struct drm_output *output = (struct drm_output *) output_base;
936 if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
938 if (output->cursor_surface)
940 if (es->output_mask != (1u << output_base->id))
942 if (c->cursors_are_broken)
944 if (es->buffer_ref.buffer == NULL ||
945 !wl_shm_buffer_get(es->buffer_ref.buffer->resource) ||
946 es->geometry.width > 64 || es->geometry.height > 64)
949 output->cursor_surface = es;
951 return &output->cursor_plane;
955 drm_output_set_cursor(struct drm_output *output)
957 struct weston_surface *es = output->cursor_surface;
958 struct drm_compositor *c =
959 (struct drm_compositor *) output->base.compositor;
960 EGLint handle, stride;
962 uint32_t buf[64 * 64];
966 output->cursor_surface = NULL;
968 drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
972 if (es->buffer_ref.buffer &&
973 pixman_region32_not_empty(&output->cursor_plane.damage)) {
974 pixman_region32_fini(&output->cursor_plane.damage);
975 pixman_region32_init(&output->cursor_plane.damage);
976 output->current_cursor ^= 1;
977 bo = output->cursor_bo[output->current_cursor];
978 memset(buf, 0, sizeof buf);
979 stride = wl_shm_buffer_get_stride(es->buffer_ref.buffer->shm_buffer);
980 s = wl_shm_buffer_get_data(es->buffer_ref.buffer->shm_buffer);
981 for (i = 0; i < es->geometry.height; i++)
982 memcpy(buf + i * 64, s + i * stride,
983 es->geometry.width * 4);
985 if (gbm_bo_write(bo, buf, sizeof buf) < 0)
986 weston_log("failed update cursor: %m\n");
988 handle = gbm_bo_get_handle(bo).s32;
989 if (drmModeSetCursor(c->drm.fd,
990 output->crtc_id, handle, 64, 64)) {
991 weston_log("failed to set cursor: %m\n");
992 c->cursors_are_broken = 1;
996 x = (es->geometry.x - output->base.x) * output->base.current_scale;
997 y = (es->geometry.y - output->base.y) * output->base.current_scale;
998 if (output->cursor_plane.x != x || output->cursor_plane.y != y) {
999 if (drmModeMoveCursor(c->drm.fd, output->crtc_id, x, y)) {
1000 weston_log("failed to move cursor: %m\n");
1001 c->cursors_are_broken = 1;
1004 output->cursor_plane.x = x;
1005 output->cursor_plane.y = y;
1010 drm_assign_planes(struct weston_output *output)
1012 struct drm_compositor *c =
1013 (struct drm_compositor *) output->compositor;
1014 struct weston_surface *es, *next;
1015 pixman_region32_t overlap, surface_overlap;
1016 struct weston_plane *primary, *next_plane;
1019 * Find a surface for each sprite in the output using some heuristics:
1021 * 2) frequency of update
1022 * 3) opacity (though some hw might support alpha blending)
1023 * 4) clipping (this can be fixed with color keys)
1025 * The idea is to save on blitting since this should save power.
1026 * If we can get a large video surface on the sprite for example,
1027 * the main display surface may not need to update at all, and
1028 * the client buffer can be used directly for the sprite surface
1029 * as we do for flipping full screen surfaces.
1031 pixman_region32_init(&overlap);
1032 primary = &c->base.primary_plane;
1033 wl_list_for_each_safe(es, next, &c->base.surface_list, link) {
1034 /* test whether this buffer can ever go into a plane:
1035 * non-shm, or small enough to be a cursor
1037 if ((es->buffer_ref.buffer &&
1038 !wl_shm_buffer_get(es->buffer_ref.buffer->resource)) ||
1039 (es->geometry.width <= 64 && es->geometry.height <= 64))
1040 es->keep_buffer = 1;
1042 es->keep_buffer = 0;
1044 pixman_region32_init(&surface_overlap);
1045 pixman_region32_intersect(&surface_overlap, &overlap,
1046 &es->transform.boundingbox);
1049 if (pixman_region32_not_empty(&surface_overlap))
1050 next_plane = primary;
1051 if (next_plane == NULL)
1052 next_plane = drm_output_prepare_cursor_surface(output, es);
1053 if (next_plane == NULL)
1054 next_plane = drm_output_prepare_scanout_surface(output, es);
1055 if (next_plane == NULL)
1056 next_plane = drm_output_prepare_overlay_surface(output, es);
1057 if (next_plane == NULL)
1058 next_plane = primary;
1059 weston_surface_move_to_plane(es, next_plane);
1060 if (next_plane == primary)
1061 pixman_region32_union(&overlap, &overlap,
1062 &es->transform.boundingbox);
1064 pixman_region32_fini(&surface_overlap);
1066 pixman_region32_fini(&overlap);
1070 drm_output_fini_pixman(struct drm_output *output);
1073 drm_output_destroy(struct weston_output *output_base)
1075 struct drm_output *output = (struct drm_output *) output_base;
1076 struct drm_compositor *c =
1077 (struct drm_compositor *) output->base.compositor;
1078 drmModeCrtcPtr origcrtc = output->original_crtc;
1080 if (output->page_flip_pending) {
1081 output->destroy_pending = 1;
1082 weston_log("destroy output while page flip pending\n");
1086 if (output->backlight)
1087 backlight_destroy(output->backlight);
1089 drmModeFreeProperty(output->dpms_prop);
1091 /* Turn off hardware cursor */
1092 drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
1094 /* Restore original CRTC state */
1095 drmModeSetCrtc(c->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id,
1096 origcrtc->x, origcrtc->y,
1097 &output->connector_id, 1, &origcrtc->mode);
1098 drmModeFreeCrtc(origcrtc);
1100 c->crtc_allocator &= ~(1 << output->crtc_id);
1101 c->connector_allocator &= ~(1 << output->connector_id);
1103 if (c->use_pixman) {
1104 drm_output_fini_pixman(output);
1106 gl_renderer->output_destroy(output_base);
1107 gbm_surface_destroy(output->surface);
1110 weston_plane_release(&output->fb_plane);
1111 weston_plane_release(&output->cursor_plane);
1113 weston_output_destroy(&output->base);
1114 wl_list_remove(&output->base.link);
1119 static struct drm_mode *
1120 choose_mode (struct drm_output *output, struct weston_mode *target_mode)
1122 struct drm_mode *tmp_mode = NULL, *mode;
1124 if (output->base.current_mode->width == target_mode->width &&
1125 output->base.current_mode->height == target_mode->height &&
1126 (output->base.current_mode->refresh == target_mode->refresh ||
1127 target_mode->refresh == 0))
1128 return (struct drm_mode *)output->base.current_mode;
1130 wl_list_for_each(mode, &output->base.mode_list, base.link) {
1131 if (mode->mode_info.hdisplay == target_mode->width &&
1132 mode->mode_info.vdisplay == target_mode->height) {
1133 if (mode->mode_info.vrefresh == target_mode->refresh ||
1134 target_mode->refresh == 0) {
1136 } else if (!tmp_mode)
1145 drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec);
1147 drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c);
1150 drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode)
1152 struct drm_output *output;
1153 struct drm_mode *drm_mode;
1154 struct drm_compositor *ec;
1156 if (output_base == NULL) {
1157 weston_log("output is NULL.\n");
1162 weston_log("mode is NULL.\n");
1166 ec = (struct drm_compositor *)output_base->compositor;
1167 output = (struct drm_output *)output_base;
1168 drm_mode = choose_mode (output, mode);
1171 weston_log("%s, invalid resolution:%dx%d\n", __func__, mode->width, mode->height);
1175 if (&drm_mode->base == output->base.current_mode)
1178 output->base.current_mode->flags = 0;
1180 output->base.current_mode = &drm_mode->base;
1181 output->base.current_mode->flags =
1182 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
1184 /* reset rendering stuff. */
1185 drm_output_release_fb(output, output->current);
1186 drm_output_release_fb(output, output->next);
1187 output->current = output->next = NULL;
1189 if (ec->use_pixman) {
1190 drm_output_fini_pixman(output);
1191 if (drm_output_init_pixman(output, ec) < 0) {
1192 weston_log("failed to init output pixman state with "
1197 gl_renderer->output_destroy(&output->base);
1198 gbm_surface_destroy(output->surface);
1200 if (drm_output_init_egl(output, ec) < 0) {
1201 weston_log("failed to init output egl state with "
1211 on_drm_input(int fd, uint32_t mask, void *data)
1213 drmEventContext evctx;
1215 memset(&evctx, 0, sizeof evctx);
1216 evctx.version = DRM_EVENT_CONTEXT_VERSION;
1217 evctx.page_flip_handler = page_flip_handler;
1218 evctx.vblank_handler = vblank_handler;
1219 drmHandleEvent(fd, &evctx);
1225 init_drm(struct drm_compositor *ec, struct udev_device *device)
1227 const char *filename, *sysnum;
1231 sysnum = udev_device_get_sysnum(device);
1233 ec->drm.id = atoi(sysnum);
1234 if (!sysnum || ec->drm.id < 0) {
1235 weston_log("cannot get device sysnum\n");
1239 filename = udev_device_get_devnode(device);
1240 fd = weston_launcher_open(ec->base.launcher, filename, O_RDWR);
1242 /* Probably permissions error */
1243 weston_log("couldn't open %s, skipping\n",
1244 udev_device_get_devnode(device));
1248 weston_log("using %s\n", filename);
1251 ec->drm.filename = strdup(filename);
1253 ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
1254 if (ret == 0 && cap == 1)
1255 ec->clock = CLOCK_MONOTONIC;
1257 ec->clock = CLOCK_REALTIME;
1263 init_egl(struct drm_compositor *ec)
1267 gl_renderer = weston_load_module("gl-renderer.so",
1268 "gl_renderer_interface");
1272 /* GBM will load a dri driver, but even though they need symbols from
1273 * libglapi, in some version of Mesa they are not linked to it. Since
1274 * only the gl-renderer module links to it, the call above won't make
1275 * these symbols globally available, and loading the DRI driver fails.
1276 * Workaround this by dlopen()'ing libglapi with RTLD_GLOBAL. */
1277 dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL);
1279 ec->gbm = gbm_create_device(ec->drm.fd);
1284 format = ec->format;
1285 if (gl_renderer->create(&ec->base, ec->gbm,
1286 gl_renderer->opaque_attribs, &format) < 0) {
1287 gbm_device_destroy(ec->gbm);
1295 init_pixman(struct drm_compositor *ec)
1297 return pixman_renderer_init(&ec->base);
1300 static struct drm_mode *
1301 drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info)
1303 struct drm_mode *mode;
1306 mode = malloc(sizeof *mode);
1310 mode->base.flags = 0;
1311 mode->base.width = info->hdisplay;
1312 mode->base.height = info->vdisplay;
1314 /* Calculate higher precision (mHz) refresh rate */
1315 refresh = (info->clock * 1000000LL / info->htotal +
1316 info->vtotal / 2) / info->vtotal;
1318 if (info->flags & DRM_MODE_FLAG_INTERLACE)
1320 if (info->flags & DRM_MODE_FLAG_DBLSCAN)
1322 if (info->vscan > 1)
1323 refresh /= info->vscan;
1325 mode->base.refresh = refresh;
1326 mode->mode_info = *info;
1328 if (info->type & DRM_MODE_TYPE_PREFERRED)
1329 mode->base.flags |= WL_OUTPUT_MODE_PREFERRED;
1331 wl_list_insert(output->base.mode_list.prev, &mode->base.link);
1337 drm_subpixel_to_wayland(int drm_value)
1339 switch (drm_value) {
1341 case DRM_MODE_SUBPIXEL_UNKNOWN:
1342 return WL_OUTPUT_SUBPIXEL_UNKNOWN;
1343 case DRM_MODE_SUBPIXEL_NONE:
1344 return WL_OUTPUT_SUBPIXEL_NONE;
1345 case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
1346 return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
1347 case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
1348 return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
1349 case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
1350 return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
1351 case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
1352 return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
1356 /* returns a value between 0-255 range, where higher is brighter */
1358 drm_get_backlight(struct drm_output *output)
1360 long brightness, max_brightness, norm;
1362 brightness = backlight_get_brightness(output->backlight);
1363 max_brightness = backlight_get_max_brightness(output->backlight);
1365 /* convert it on a scale of 0 to 255 */
1366 norm = (brightness * 255)/(max_brightness);
1368 return (uint32_t) norm;
1371 /* values accepted are between 0-255 range */
1373 drm_set_backlight(struct weston_output *output_base, uint32_t value)
1375 struct drm_output *output = (struct drm_output *) output_base;
1376 long max_brightness, new_brightness;
1378 if (!output->backlight)
1384 max_brightness = backlight_get_max_brightness(output->backlight);
1386 /* get denormalized value */
1387 new_brightness = (value * max_brightness) / 255;
1389 backlight_set_brightness(output->backlight, new_brightness);
1392 static drmModePropertyPtr
1393 drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name)
1395 drmModePropertyPtr props;
1398 for (i = 0; i < connector->count_props; i++) {
1399 props = drmModeGetProperty(fd, connector->props[i]);
1403 if (!strcmp(props->name, name))
1406 drmModeFreeProperty(props);
1413 drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)
1415 struct drm_output *output = (struct drm_output *) output_base;
1416 struct weston_compositor *ec = output_base->compositor;
1417 struct drm_compositor *c = (struct drm_compositor *) ec;
1419 if (!output->dpms_prop)
1422 drmModeConnectorSetProperty(c->drm.fd, output->connector_id,
1423 output->dpms_prop->prop_id, level);
1426 static const char *connector_type_names[] = {
1445 find_crtc_for_connector(struct drm_compositor *ec,
1446 drmModeRes *resources, drmModeConnector *connector)
1448 drmModeEncoder *encoder;
1449 uint32_t possible_crtcs;
1452 for (j = 0; j < connector->count_encoders; j++) {
1453 encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[j]);
1454 if (encoder == NULL) {
1455 weston_log("Failed to get encoder.\n");
1458 possible_crtcs = encoder->possible_crtcs;
1459 drmModeFreeEncoder(encoder);
1461 for (i = 0; i < resources->count_crtcs; i++) {
1462 if (possible_crtcs & (1 << i) &&
1463 !(ec->crtc_allocator & (1 << resources->crtcs[i])))
1471 /* Init output state that depends on gl or gbm */
1473 drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec)
1477 output->surface = gbm_surface_create(ec->gbm,
1478 output->base.current_mode->width,
1479 output->base.current_mode->height,
1481 GBM_BO_USE_SCANOUT |
1482 GBM_BO_USE_RENDERING);
1483 if (!output->surface) {
1484 weston_log("failed to create gbm surface\n");
1488 if (gl_renderer->output_create(&output->base, output->surface) < 0) {
1489 weston_log("failed to create gl renderer output state\n");
1490 gbm_surface_destroy(output->surface);
1494 flags = GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE;
1496 for (i = 0; i < 2; i++) {
1497 if (output->cursor_bo[i])
1500 output->cursor_bo[i] =
1501 gbm_bo_create(ec->gbm, 64, 64, GBM_FORMAT_ARGB8888,
1505 if (output->cursor_bo[0] == NULL || output->cursor_bo[1] == NULL) {
1506 weston_log("cursor buffers unavailable, using gl cursors\n");
1507 ec->cursors_are_broken = 1;
1514 drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c)
1516 int w = output->base.current_mode->width;
1517 int h = output->base.current_mode->height;
1520 /* FIXME error checking */
1522 for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
1523 output->dumb[i] = drm_fb_create_dumb(c, w, h);
1524 if (!output->dumb[i])
1528 pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h,
1529 output->dumb[i]->map,
1530 output->dumb[i]->stride);
1531 if (!output->image[i])
1535 if (pixman_renderer_output_create(&output->base) < 0)
1538 pixman_region32_init_rect(&output->previous_damage,
1539 output->base.x, output->base.y, output->base.width, output->base.height);
1544 for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
1545 if (output->dumb[i])
1546 drm_fb_destroy_dumb(output->dumb[i]);
1547 if (output->image[i])
1548 pixman_image_unref(output->image[i]);
1550 output->dumb[i] = NULL;
1551 output->image[i] = NULL;
1558 drm_output_fini_pixman(struct drm_output *output)
1562 pixman_renderer_output_destroy(&output->base);
1563 pixman_region32_fini(&output->previous_damage);
1565 for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
1566 drm_fb_destroy_dumb(output->dumb[i]);
1567 pixman_image_unref(output->image[i]);
1568 output->dumb[i] = NULL;
1569 output->image[i] = NULL;
1574 edid_parse_string(const uint8_t *data, char text[])
1579 /* this is always 12 bytes, but we can't guarantee it's null
1580 * terminated or not junk. */
1581 strncpy(text, (const char *) data, 12);
1583 /* remove insane chars */
1584 for (i = 0; text[i] != '\0'; i++) {
1585 if (text[i] == '\n' ||
1592 /* ensure string is printable */
1593 for (i = 0; text[i] != '\0'; i++) {
1594 if (!isprint(text[i])) {
1600 /* if the string is random junk, ignore the string */
1605 #define EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe
1606 #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc
1607 #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff
1608 #define EDID_OFFSET_DATA_BLOCKS 0x36
1609 #define EDID_OFFSET_LAST_BLOCK 0x6c
1610 #define EDID_OFFSET_PNPID 0x08
1611 #define EDID_OFFSET_SERIAL 0x0c
1614 edid_parse(struct drm_edid *edid, const uint8_t *data, size_t length)
1617 uint32_t serial_number;
1622 if (data[0] != 0x00 || data[1] != 0xff)
1625 /* decode the PNP ID from three 5 bit words packed into 2 bytes
1630 edid->pnp_id[0] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x7c) / 4) - 1;
1631 edid->pnp_id[1] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x3) * 8) + ((data[EDID_OFFSET_PNPID + 1] & 0xe0) / 32) - 1;
1632 edid->pnp_id[2] = 'A' + (data[EDID_OFFSET_PNPID + 1] & 0x1f) - 1;
1633 edid->pnp_id[3] = '\0';
1635 /* maybe there isn't a ASCII serial number descriptor, so use this instead */
1636 serial_number = (uint32_t) data[EDID_OFFSET_SERIAL + 0];
1637 serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 1] * 0x100;
1638 serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 2] * 0x10000;
1639 serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 3] * 0x1000000;
1640 if (serial_number > 0)
1641 sprintf(edid->serial_number, "%lu", (unsigned long) serial_number);
1643 /* parse EDID data */
1644 for (i = EDID_OFFSET_DATA_BLOCKS;
1645 i <= EDID_OFFSET_LAST_BLOCK;
1647 /* ignore pixel clock data */
1653 /* any useful blocks? */
1654 if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME) {
1655 edid_parse_string(&data[i+5],
1656 edid->monitor_name);
1657 } else if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) {
1658 edid_parse_string(&data[i+5],
1659 edid->serial_number);
1660 } else if (data[i+3] == EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) {
1661 edid_parse_string(&data[i+5],
1669 find_and_parse_output_edid(struct drm_compositor *ec,
1670 struct drm_output *output,
1671 drmModeConnector *connector)
1673 drmModePropertyBlobPtr edid_blob = NULL;
1674 drmModePropertyPtr property;
1678 for (i = 0; i < connector->count_props && !edid_blob; i++) {
1679 property = drmModeGetProperty(ec->drm.fd, connector->props[i]);
1682 if ((property->flags & DRM_MODE_PROP_BLOB) &&
1683 !strcmp(property->name, "EDID")) {
1684 edid_blob = drmModeGetPropertyBlob(ec->drm.fd,
1685 connector->prop_values[i]);
1687 drmModeFreeProperty(property);
1692 rc = edid_parse(&output->edid,
1696 weston_log("EDID data '%s', '%s', '%s'\n",
1697 output->edid.pnp_id,
1698 output->edid.monitor_name,
1699 output->edid.serial_number);
1700 if (output->edid.pnp_id[0] != '\0')
1701 output->base.make = output->edid.pnp_id;
1702 if (output->edid.monitor_name[0] != '\0')
1703 output->base.model = output->edid.monitor_name;
1704 if (output->edid.serial_number[0] != '\0')
1705 output->base.serial_number = output->edid.serial_number;
1707 drmModeFreePropertyBlob(edid_blob);
1713 parse_modeline(const char *s, drmModeModeInfo *mode)
1719 mode->type = DRM_MODE_TYPE_USERDEF;
1725 if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s",
1734 &mode->vtotal, hsync, vsync) != 11)
1737 mode->clock = fclock * 1000;
1738 if (strcmp(hsync, "+hsync") == 0)
1739 mode->flags |= DRM_MODE_FLAG_PHSYNC;
1740 else if (strcmp(hsync, "-hsync") == 0)
1741 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1745 if (strcmp(vsync, "+vsync") == 0)
1746 mode->flags |= DRM_MODE_FLAG_PVSYNC;
1747 else if (strcmp(vsync, "-vsync") == 0)
1748 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1756 parse_transform(const char *transform, const char *output_name)
1758 static const struct { const char *name; uint32_t token; } names[] = {
1759 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
1760 { "90", WL_OUTPUT_TRANSFORM_90 },
1761 { "180", WL_OUTPUT_TRANSFORM_180 },
1762 { "270", WL_OUTPUT_TRANSFORM_270 },
1763 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
1764 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
1765 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
1766 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
1770 for (i = 0; i < ARRAY_LENGTH(names); i++)
1771 if (strcmp(names[i].name, transform) == 0)
1772 return names[i].token;
1774 weston_log("Invalid transform \"%s\" for output %s\n",
1775 transform, output_name);
1777 return WL_OUTPUT_TRANSFORM_NORMAL;
1781 setup_output_seat_constraint(struct drm_compositor *ec,
1782 struct weston_output *output,
1785 if (strcmp(s, "") != 0) {
1786 struct udev_seat *seat;
1788 seat = udev_seat_get_named(&ec->base, s);
1790 seat->base.output = output;
1792 if (seat && seat->base.pointer)
1793 weston_pointer_clamp(seat->base.pointer,
1794 &seat->base.pointer->x,
1795 &seat->base.pointer->y);
1800 create_output_for_connector(struct drm_compositor *ec,
1801 drmModeRes *resources,
1802 drmModeConnector *connector,
1803 int x, int y, struct udev_device *drm_device)
1805 struct drm_output *output;
1806 struct drm_mode *drm_mode, *next, *preferred, *current, *configured;
1807 struct weston_mode *m;
1808 struct weston_config_section *section;
1809 drmModeEncoder *encoder;
1810 drmModeModeInfo crtc_mode, modeline;
1812 int i, width, height, scale;
1814 const char *type_name;
1815 enum output_config config;
1818 i = find_crtc_for_connector(ec, resources, connector);
1820 weston_log("No usable crtc/encoder pair for connector.\n");
1824 output = zalloc(sizeof *output);
1828 output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);
1829 output->base.make = "unknown";
1830 output->base.model = "unknown";
1831 output->base.serial_number = "unknown";
1832 wl_list_init(&output->base.mode_list);
1834 if (connector->connector_type < ARRAY_LENGTH(connector_type_names))
1835 type_name = connector_type_names[connector->connector_type];
1837 type_name = "UNKNOWN";
1838 snprintf(name, 32, "%s%d", type_name, connector->connector_type_id);
1839 output->base.name = strdup(name);
1841 section = weston_config_get_section(ec->base.config, "output", "name",
1843 weston_config_section_get_string(section, "mode", &s, "preferred");
1844 if (strcmp(s, "off") == 0)
1845 config = OUTPUT_CONFIG_OFF;
1846 else if (strcmp(s, "preferred") == 0)
1847 config = OUTPUT_CONFIG_PREFERRED;
1848 else if (strcmp(s, "current") == 0)
1849 config = OUTPUT_CONFIG_CURRENT;
1850 else if (sscanf(s, "%dx%d", &width, &height) == 2)
1851 config = OUTPUT_CONFIG_MODE;
1852 else if (parse_modeline(s, &modeline) == 0)
1853 config = OUTPUT_CONFIG_MODELINE;
1855 weston_log("Invalid mode \"%s\" for output %s\n",
1856 s, output->base.name);
1857 config = OUTPUT_CONFIG_PREFERRED;
1861 weston_config_section_get_int(section, "scale", &scale, 1);
1862 weston_config_section_get_string(section, "transform", &s, "normal");
1863 transform = parse_transform(s, output->base.name);
1866 weston_config_section_get_string(section, "seat", &s, "");
1867 setup_output_seat_constraint(ec, &output->base, s);
1870 output->crtc_id = resources->crtcs[i];
1872 ec->crtc_allocator |= (1 << output->crtc_id);
1873 output->connector_id = connector->connector_id;
1874 ec->connector_allocator |= (1 << output->connector_id);
1876 output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id);
1877 output->dpms_prop = drm_get_prop(ec->drm.fd, connector, "DPMS");
1879 /* Get the current mode on the crtc that's currently driving
1880 * this connector. */
1881 encoder = drmModeGetEncoder(ec->drm.fd, connector->encoder_id);
1882 memset(&crtc_mode, 0, sizeof crtc_mode);
1883 if (encoder != NULL) {
1884 crtc = drmModeGetCrtc(ec->drm.fd, encoder->crtc_id);
1885 drmModeFreeEncoder(encoder);
1888 if (crtc->mode_valid)
1889 crtc_mode = crtc->mode;
1890 drmModeFreeCrtc(crtc);
1893 for (i = 0; i < connector->count_modes; i++) {
1894 drm_mode = drm_output_add_mode(output, &connector->modes[i]);
1899 if (config == OUTPUT_CONFIG_OFF) {
1900 weston_log("Disabling output %s\n", output->base.name);
1901 drmModeSetCrtc(ec->drm.fd, output->crtc_id,
1902 0, 0, 0, 0, 0, NULL);
1910 wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
1911 if (config == OUTPUT_CONFIG_MODE &&
1912 width == drm_mode->base.width &&
1913 height == drm_mode->base.height)
1914 configured = drm_mode;
1915 if (!memcmp(&crtc_mode, &drm_mode->mode_info, sizeof crtc_mode))
1917 if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED)
1918 preferred = drm_mode;
1921 if (config == OUTPUT_CONFIG_MODELINE) {
1922 configured = drm_output_add_mode(output, &modeline);
1927 if (current == NULL && crtc_mode.clock != 0) {
1928 current = drm_output_add_mode(output, &crtc_mode);
1933 if (config == OUTPUT_CONFIG_CURRENT)
1934 configured = current;
1936 if (option_current_mode && current)
1937 output->base.current_mode = ¤t->base;
1938 else if (configured)
1939 output->base.current_mode = &configured->base;
1941 output->base.current_mode = &preferred->base;
1943 output->base.current_mode = ¤t->base;
1945 if (output->base.current_mode == NULL) {
1946 weston_log("no available modes for %s\n", output->base.name);
1950 output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
1952 weston_output_init(&output->base, &ec->base, x, y,
1953 connector->mmWidth, connector->mmHeight,
1956 if (ec->use_pixman) {
1957 if (drm_output_init_pixman(output, ec) < 0) {
1958 weston_log("Failed to init output pixman state\n");
1961 } else if (drm_output_init_egl(output, ec) < 0) {
1962 weston_log("Failed to init output gl state\n");
1966 output->backlight = backlight_init(drm_device,
1967 connector->connector_type);
1968 if (output->backlight) {
1969 weston_log("Initialized backlight, device %s\n",
1970 output->backlight->path);
1971 output->base.set_backlight = drm_set_backlight;
1972 output->base.backlight_current = drm_get_backlight(output);
1974 weston_log("Failed to initialize backlight\n");
1977 wl_list_insert(ec->base.output_list.prev, &output->base.link);
1979 find_and_parse_output_edid(ec, output, connector);
1980 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
1981 output->base.connection_internal = 1;
1983 output->base.start_repaint_loop = drm_output_start_repaint_loop;
1984 output->base.repaint = drm_output_repaint;
1985 output->base.destroy = drm_output_destroy;
1986 output->base.assign_planes = drm_assign_planes;
1987 output->base.set_dpms = drm_set_dpms;
1988 output->base.switch_mode = drm_output_switch_mode;
1990 output->base.gamma_size = output->original_crtc->gamma_size;
1991 output->base.set_gamma = drm_output_set_gamma;
1993 weston_plane_init(&output->cursor_plane, 0, 0);
1994 weston_plane_init(&output->fb_plane, 0, 0);
1996 weston_compositor_stack_plane(&ec->base, &output->cursor_plane, NULL);
1997 weston_compositor_stack_plane(&ec->base, &output->fb_plane,
1998 &ec->base.primary_plane);
2000 weston_log("Output %s, (connector %d, crtc %d)\n",
2001 output->base.name, output->connector_id, output->crtc_id);
2002 wl_list_for_each(m, &output->base.mode_list, link)
2003 weston_log_continue(" mode %dx%d@%.1f%s%s%s\n",
2004 m->width, m->height, m->refresh / 1000.0,
2005 m->flags & WL_OUTPUT_MODE_PREFERRED ?
2007 m->flags & WL_OUTPUT_MODE_CURRENT ?
2009 connector->count_modes == 0 ?
2015 weston_output_destroy(&output->base);
2017 wl_list_for_each_safe(drm_mode, next, &output->base.mode_list,
2019 wl_list_remove(&drm_mode->base.link);
2023 drmModeFreeCrtc(output->original_crtc);
2024 ec->crtc_allocator &= ~(1 << output->crtc_id);
2025 ec->connector_allocator &= ~(1 << output->connector_id);
2032 create_sprites(struct drm_compositor *ec)
2034 struct drm_sprite *sprite;
2035 drmModePlaneRes *plane_res;
2036 drmModePlane *plane;
2039 plane_res = drmModeGetPlaneResources(ec->drm.fd);
2041 weston_log("failed to get plane resources: %s\n",
2046 for (i = 0; i < plane_res->count_planes; i++) {
2047 plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]);
2051 sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
2052 plane->count_formats));
2054 weston_log("%s: out of memory\n",
2060 sprite->possible_crtcs = plane->possible_crtcs;
2061 sprite->plane_id = plane->plane_id;
2062 sprite->current = NULL;
2063 sprite->next = NULL;
2064 sprite->compositor = ec;
2065 sprite->count_formats = plane->count_formats;
2066 memcpy(sprite->formats, plane->formats,
2067 plane->count_formats * sizeof(plane->formats[0]));
2068 drmModeFreePlane(plane);
2069 weston_plane_init(&sprite->plane, 0, 0);
2070 weston_compositor_stack_plane(&ec->base, &sprite->plane,
2071 &ec->base.primary_plane);
2073 wl_list_insert(&ec->sprite_list, &sprite->link);
2076 drmModeFreePlaneResources(plane_res);
2080 destroy_sprites(struct drm_compositor *compositor)
2082 struct drm_sprite *sprite, *next;
2083 struct drm_output *output;
2085 output = container_of(compositor->base.output_list.next,
2086 struct drm_output, base.link);
2088 wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) {
2089 drmModeSetPlane(compositor->drm.fd,
2091 output->crtc_id, 0, 0,
2092 0, 0, 0, 0, 0, 0, 0, 0);
2093 drm_output_release_fb(output, sprite->current);
2094 drm_output_release_fb(output, sprite->next);
2095 weston_plane_release(&sprite->plane);
2101 create_outputs(struct drm_compositor *ec, uint32_t option_connector,
2102 struct udev_device *drm_device)
2104 drmModeConnector *connector;
2105 drmModeRes *resources;
2109 resources = drmModeGetResources(ec->drm.fd);
2111 weston_log("drmModeGetResources failed\n");
2115 ec->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t));
2117 drmModeFreeResources(resources);
2121 ec->min_width = resources->min_width;
2122 ec->max_width = resources->max_width;
2123 ec->min_height = resources->min_height;
2124 ec->max_height = resources->max_height;
2126 ec->num_crtcs = resources->count_crtcs;
2127 memcpy(ec->crtcs, resources->crtcs, sizeof(uint32_t) * ec->num_crtcs);
2129 for (i = 0; i < resources->count_connectors; i++) {
2130 connector = drmModeGetConnector(ec->drm.fd,
2131 resources->connectors[i]);
2132 if (connector == NULL)
2135 if (connector->connection == DRM_MODE_CONNECTED &&
2136 (option_connector == 0 ||
2137 connector->connector_id == option_connector)) {
2138 if (create_output_for_connector(ec, resources,
2141 drmModeFreeConnector(connector);
2145 x += container_of(ec->base.output_list.prev,
2146 struct weston_output,
2150 drmModeFreeConnector(connector);
2153 if (wl_list_empty(&ec->base.output_list)) {
2154 weston_log("No currently active connector found.\n");
2155 drmModeFreeResources(resources);
2159 drmModeFreeResources(resources);
2165 update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
2167 drmModeConnector *connector;
2168 drmModeRes *resources;
2169 struct drm_output *output, *next;
2171 int x_offset = 0, y_offset = 0;
2172 uint32_t connected = 0, disconnects = 0;
2175 resources = drmModeGetResources(ec->drm.fd);
2177 weston_log("drmModeGetResources failed\n");
2181 /* collect new connects */
2182 for (i = 0; i < resources->count_connectors; i++) {
2183 int connector_id = resources->connectors[i];
2185 connector = drmModeGetConnector(ec->drm.fd, connector_id);
2186 if (connector == NULL)
2189 if (connector->connection != DRM_MODE_CONNECTED) {
2190 drmModeFreeConnector(connector);
2194 connected |= (1 << connector_id);
2196 if (!(ec->connector_allocator & (1 << connector_id))) {
2197 struct weston_output *last =
2198 container_of(ec->base.output_list.prev,
2199 struct weston_output, link);
2201 /* XXX: not yet needed, we die with 0 outputs */
2202 if (!wl_list_empty(&ec->base.output_list))
2203 x = last->x + last->width;
2207 create_output_for_connector(ec, resources,
2210 weston_log("connector %d connected\n", connector_id);
2213 drmModeFreeConnector(connector);
2215 drmModeFreeResources(resources);
2217 disconnects = ec->connector_allocator & ~connected;
2219 wl_list_for_each_safe(output, next, &ec->base.output_list,
2221 if (x_offset != 0 || y_offset != 0) {
2222 weston_output_move(&output->base,
2223 output->base.x - x_offset,
2224 output->base.y - y_offset);
2227 if (disconnects & (1 << output->connector_id)) {
2228 disconnects &= ~(1 << output->connector_id);
2229 weston_log("connector %d disconnected\n",
2230 output->connector_id);
2231 x_offset += output->base.width;
2232 drm_output_destroy(&output->base);
2237 /* FIXME: handle zero outputs, without terminating */
2238 if (ec->connector_allocator == 0)
2239 wl_display_terminate(ec->base.wl_display);
2243 udev_event_is_hotplug(struct drm_compositor *ec, struct udev_device *device)
2248 sysnum = udev_device_get_sysnum(device);
2249 if (!sysnum || atoi(sysnum) != ec->drm.id)
2252 val = udev_device_get_property_value(device, "HOTPLUG");
2256 return strcmp(val, "1") == 0;
2260 udev_drm_event(int fd, uint32_t mask, void *data)
2262 struct drm_compositor *ec = data;
2263 struct udev_device *event;
2265 event = udev_monitor_receive_device(ec->udev_monitor);
2267 if (udev_event_is_hotplug(ec, event))
2268 update_outputs(ec, event);
2270 udev_device_unref(event);
2276 drm_restore(struct weston_compositor *ec)
2278 weston_launcher_restore(ec->launcher);
2282 drm_destroy(struct weston_compositor *ec)
2284 struct drm_compositor *d = (struct drm_compositor *) ec;
2286 udev_input_destroy(&d->input);
2288 wl_event_source_remove(d->udev_drm_source);
2289 wl_event_source_remove(d->drm_source);
2293 weston_compositor_shutdown(ec);
2295 ec->renderer->destroy(ec);
2298 gbm_device_destroy(d->gbm);
2300 weston_launcher_destroy(d->base.launcher);
2308 drm_compositor_set_modes(struct drm_compositor *compositor)
2310 struct drm_output *output;
2311 struct drm_mode *drm_mode;
2314 wl_list_for_each(output, &compositor->base.output_list, base.link) {
2315 if (!output->current) {
2316 /* If something that would cause the output to
2317 * switch mode happened while in another vt, we
2318 * might not have a current drm_fb. In that case,
2319 * schedule a repaint and let drm_output_repaint
2320 * handle setting the mode. */
2321 weston_output_schedule_repaint(&output->base);
2325 drm_mode = (struct drm_mode *) output->base.current_mode;
2326 ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
2327 output->current->fb_id, 0, 0,
2328 &output->connector_id, 1,
2329 &drm_mode->mode_info);
2332 "failed to set mode %dx%d for output at %d,%d: %m\n",
2333 drm_mode->base.width, drm_mode->base.height,
2334 output->base.x, output->base.y);
2340 session_notify(struct wl_listener *listener, void *data)
2342 struct weston_compositor *compositor = data;
2343 struct drm_compositor *ec = data;
2344 struct drm_sprite *sprite;
2345 struct drm_output *output;
2347 if (ec->base.session_active) {
2348 weston_log("activating session\n");
2349 compositor->focus = 1;
2350 if (ec->base.launcher == NULL && drmSetMaster(ec->drm.fd)) {
2351 weston_log("failed to set master: %m\n");
2352 wl_display_terminate(compositor->wl_display);
2354 compositor->state = ec->prev_state;
2355 drm_compositor_set_modes(ec);
2356 weston_compositor_damage_all(compositor);
2357 udev_input_enable(&ec->input, ec->udev);
2359 weston_log("deactivating session\n");
2360 udev_input_disable(&ec->input);
2362 compositor->focus = 0;
2363 ec->prev_state = compositor->state;
2364 weston_compositor_offscreen(compositor);
2366 /* If we have a repaint scheduled (either from a
2367 * pending pageflip or the idle handler), make sure we
2368 * cancel that so we don't try to pageflip when we're
2369 * vt switched away. The OFFSCREEN state will prevent
2370 * further attemps at repainting. When we switch
2371 * back, we schedule a repaint, which will process
2372 * pending frame callbacks. */
2374 wl_list_for_each(output, &ec->base.output_list, base.link) {
2375 output->base.repaint_needed = 0;
2376 drmModeSetCursor(ec->drm.fd, output->crtc_id, 0, 0, 0);
2379 output = container_of(ec->base.output_list.next,
2380 struct drm_output, base.link);
2382 wl_list_for_each(sprite, &ec->sprite_list, link)
2383 drmModeSetPlane(ec->drm.fd,
2385 output->crtc_id, 0, 0,
2386 0, 0, 0, 0, 0, 0, 0, 0);
2388 if (ec->base.launcher == NULL && drmDropMaster(ec->drm.fd) < 0)
2389 weston_log("failed to drop master: %m\n");
2394 switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
2396 struct weston_compositor *compositor = data;
2398 weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
2403 * Some systems may have multiple DRM devices attached to a single seat. This
2404 * function loops over all devices and tries to find a PCI device with the
2405 * boot_vga sysfs attribute set to 1.
2406 * If no such device is found, the first DRM device reported by udev is used.
2408 static struct udev_device*
2409 find_primary_gpu(struct drm_compositor *ec, const char *seat)
2411 struct udev_enumerate *e;
2412 struct udev_list_entry *entry;
2413 const char *path, *device_seat, *id;
2414 struct udev_device *device, *drm_device, *pci;
2416 e = udev_enumerate_new(ec->udev);
2417 udev_enumerate_add_match_subsystem(e, "drm");
2418 udev_enumerate_add_match_sysname(e, "card[0-9]*");
2420 udev_enumerate_scan_devices(e);
2422 udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
2423 path = udev_list_entry_get_name(entry);
2424 device = udev_device_new_from_syspath(ec->udev, path);
2427 device_seat = udev_device_get_property_value(device, "ID_SEAT");
2429 device_seat = default_seat;
2430 if (strcmp(device_seat, seat)) {
2431 udev_device_unref(device);
2435 pci = udev_device_get_parent_with_subsystem_devtype(device,
2438 id = udev_device_get_sysattr_value(pci, "boot_vga");
2439 if (id && !strcmp(id, "1")) {
2441 udev_device_unref(drm_device);
2442 drm_device = device;
2448 drm_device = device;
2450 udev_device_unref(device);
2453 udev_enumerate_unref(e);
2458 planes_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
2460 struct drm_compositor *c = data;
2464 c->cursors_are_broken ^= 1;
2467 c->sprites_are_broken ^= 1;
2470 c->sprites_hidden ^= 1;
2477 #ifdef BUILD_VAAPI_RECORDER
2479 recorder_frame_notify(struct wl_listener *listener, void *data)
2481 struct drm_output *output;
2482 struct drm_compositor *c;
2485 output = container_of(listener, struct drm_output,
2486 recorder_frame_listener);
2487 c = (struct drm_compositor *) output->base.compositor;
2489 if (!output->recorder)
2492 ret = drmPrimeHandleToFD(c->drm.fd, output->current->handle,
2495 weston_log("[libva recorder] "
2496 "failed to create prime fd for front buffer\n");
2500 vaapi_recorder_frame(output->recorder, fd, output->current->stride / 4);
2504 create_recorder(struct drm_compositor *c, int width, int height,
2505 const char *filename)
2510 fd = open(c->drm.filename, O_RDWR | O_CLOEXEC);
2514 drmGetMagic(fd, &magic);
2515 drmAuthMagic(c->drm.fd, magic);
2517 return vaapi_recorder_create(fd, width, height, filename);
2521 recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2524 struct drm_compositor *c = data;
2525 struct drm_output *output;
2528 output = container_of(c->base.output_list.next,
2529 struct drm_output, base.link);
2531 if (!output->recorder) {
2532 width = output->base.current_mode->width;
2533 height = output->base.current_mode->height;
2536 create_recorder(c, width, height, "capture.h264");
2537 if (!output->recorder) {
2538 weston_log("failed to create vaapi recorder\n");
2542 output->base.disable_planes++;
2544 output->recorder_frame_listener.notify = recorder_frame_notify;
2545 wl_signal_add(&output->base.frame_signal,
2546 &output->recorder_frame_listener);
2548 weston_output_schedule_repaint(&output->base);
2550 weston_log("[libva recorder] initialized\n");
2552 vaapi_recorder_destroy(output->recorder);
2553 output->recorder = NULL;
2555 output->base.disable_planes--;
2557 wl_list_remove(&output->recorder_frame_listener.link);
2558 weston_log("[libva recorder] done\n");
2563 recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2566 weston_log("Compiled without libva support\n");
2570 static struct weston_compositor *
2571 drm_compositor_create(struct wl_display *display,
2572 int connector, const char *seat_id, int tty, int pixman,
2573 int *argc, char *argv[],
2574 struct weston_config *config)
2576 struct drm_compositor *ec;
2577 struct udev_device *drm_device;
2578 struct wl_event_loop *loop;
2582 weston_log("initializing drm backend\n");
2584 ec = zalloc(sizeof *ec);
2588 /* KMS support for sprites is not complete yet, so disable the
2589 * functionality for now. */
2590 ec->sprites_are_broken = 1;
2591 ec->format = GBM_FORMAT_XRGB8888;
2592 ec->use_pixman = pixman;
2594 if (weston_compositor_init(&ec->base, display, argc, argv,
2596 weston_log("%s failed\n", __func__);
2600 /* Check if we run drm-backend using weston-launch */
2601 ec->base.launcher = weston_launcher_connect(&ec->base, tty);
2602 if (ec->base.launcher == NULL) {
2603 weston_log("fatal: drm backend should be run "
2604 "using weston-launch binary or as root\n");
2605 goto err_compositor;
2608 ec->udev = udev_new();
2609 if (ec->udev == NULL) {
2610 weston_log("failed to initialize udev context\n");
2614 ec->base.wl_display = display;
2615 ec->session_listener.notify = session_notify;
2616 wl_signal_add(&ec->base.session_signal, &ec->session_listener);
2618 drm_device = find_primary_gpu(ec, seat_id);
2619 if (drm_device == NULL) {
2620 weston_log("no drm device found\n");
2623 path = udev_device_get_syspath(drm_device);
2625 if (init_drm(ec, drm_device) < 0) {
2626 weston_log("failed to initialize kms\n");
2630 if (ec->use_pixman) {
2631 if (init_pixman(ec) < 0) {
2632 weston_log("failed to initialize pixman renderer\n");
2636 if (init_egl(ec) < 0) {
2637 weston_log("failed to initialize egl\n");
2642 ec->base.destroy = drm_destroy;
2643 ec->base.restore = drm_restore;
2647 ec->prev_state = WESTON_COMPOSITOR_ACTIVE;
2649 for (key = KEY_F1; key < KEY_F9; key++)
2650 weston_compositor_add_key_binding(&ec->base, key,
2651 MODIFIER_CTRL | MODIFIER_ALT,
2652 switch_vt_binding, ec);
2654 wl_list_init(&ec->sprite_list);
2657 if (create_outputs(ec, connector, drm_device) < 0) {
2658 weston_log("failed to create output for %s\n", path);
2664 if (udev_input_init(&ec->input, &ec->base, ec->udev, seat_id) < 0) {
2665 weston_log("failed to create input devices\n");
2669 loop = wl_display_get_event_loop(ec->base.wl_display);
2671 wl_event_loop_add_fd(loop, ec->drm.fd,
2672 WL_EVENT_READABLE, on_drm_input, ec);
2674 ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
2675 if (ec->udev_monitor == NULL) {
2676 weston_log("failed to intialize udev monitor\n");
2677 goto err_drm_source;
2679 udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor,
2681 ec->udev_drm_source =
2682 wl_event_loop_add_fd(loop,
2683 udev_monitor_get_fd(ec->udev_monitor),
2684 WL_EVENT_READABLE, udev_drm_event, ec);
2686 if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) {
2687 weston_log("failed to enable udev-monitor receiving\n");
2688 goto err_udev_monitor;
2691 udev_device_unref(drm_device);
2693 weston_compositor_add_debug_binding(&ec->base, KEY_O,
2694 planes_binding, ec);
2695 weston_compositor_add_debug_binding(&ec->base, KEY_C,
2696 planes_binding, ec);
2697 weston_compositor_add_debug_binding(&ec->base, KEY_V,
2698 planes_binding, ec);
2699 weston_compositor_add_debug_binding(&ec->base, KEY_Q,
2700 recorder_binding, ec);
2705 wl_event_source_remove(ec->udev_drm_source);
2706 udev_monitor_unref(ec->udev_monitor);
2708 wl_event_source_remove(ec->drm_source);
2709 udev_input_destroy(&ec->input);
2711 ec->base.renderer->destroy(&ec->base);
2712 gbm_device_destroy(ec->gbm);
2713 destroy_sprites(ec);
2715 udev_device_unref(drm_device);
2717 weston_launcher_destroy(ec->base.launcher);
2719 udev_unref(ec->udev);
2721 weston_compositor_shutdown(&ec->base);
2727 WL_EXPORT struct weston_compositor *
2728 backend_init(struct wl_display *display, int *argc, char *argv[],
2729 struct weston_config *config)
2731 int connector = 0, tty = 0, use_pixman = 0;
2732 const char *seat_id = default_seat;
2734 const struct weston_option drm_options[] = {
2735 { WESTON_OPTION_INTEGER, "connector", 0, &connector },
2736 { WESTON_OPTION_STRING, "seat", 0, &seat_id },
2737 { WESTON_OPTION_INTEGER, "tty", 0, &tty },
2738 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &option_current_mode },
2739 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
2742 parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv);
2744 return drm_compositor_create(display, connector, seat_id, tty, use_pixman,
2745 argc, argv, config);