compositor: Scanout client buffers even if they're not map_fullscreen
[profile/ivi/weston.git] / compositor / compositor-drm.c
1 /*
2  * Copyright © 2008-2010 Kristian Høgsberg
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 #define _GNU_SOURCE
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26
27 #include <xf86drm.h>
28 #include <xf86drmMode.h>
29
30 #include "compositor.h"
31
32 struct drm_compositor {
33         struct wlsc_compositor base;
34
35         struct udev *udev;
36         struct wl_event_source *drm_source;
37
38         struct udev_monitor *udev_monitor;
39         struct wl_event_source *udev_drm_source;
40
41         struct {
42                 int fd;
43         } drm;
44         uint32_t crtc_allocator;
45         uint32_t connector_allocator;
46         struct tty *tty;
47
48         PFNEGLCREATEDRMIMAGEMESA create_drm_image;
49         PFNEGLEXPORTDRMIMAGEMESA export_drm_image;
50 };
51
52 struct drm_output {
53         struct wlsc_output   base;
54
55         drmModeModeInfo mode;
56         uint32_t crtc_id;
57         uint32_t connector_id;
58         GLuint rbo[2];
59         uint32_t fb_id[2];
60         EGLImageKHR image[2];
61         uint32_t current;       
62
63         struct wlsc_surface *scanout_surface;
64
65         uint32_t fs_surf_fb_id;
66         uint32_t pending_fs_surf_fb_id;
67 };
68
69 static int
70 drm_output_prepare_render(struct wlsc_output *output_base)
71 {
72         struct drm_output *output = (struct drm_output *) output_base;
73
74         glFramebufferRenderbuffer(GL_FRAMEBUFFER,
75                                   GL_COLOR_ATTACHMENT0,
76                                   GL_RENDERBUFFER,
77                                   output->rbo[output->current]);
78
79         if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
80                 return -1;
81
82         return 0;
83 }
84
85 static int
86 drm_output_present(struct wlsc_output *output_base)
87 {
88         struct drm_output *output = (struct drm_output *) output_base;
89         struct drm_compositor *c =
90                 (struct drm_compositor *) output->base.compositor;
91         uint32_t fb_id = 0;
92
93         if (drm_output_prepare_render(&output->base))
94                 return -1;
95         glFlush();
96
97         output->current ^= 1;
98
99         if (output->scanout_surface != NULL) {
100                 output->scanout_surface = NULL;
101                 fb_id = output->fs_surf_fb_id;
102         } else {
103                 fb_id = output->fb_id[output->current ^ 1];
104         }
105
106         drmModePageFlip(c->drm.fd, output->crtc_id,
107                         fb_id,
108                         DRM_MODE_PAGE_FLIP_EVENT, output);
109
110         return 0;
111 }
112
113 static void
114 page_flip_handler(int fd, unsigned int frame,
115                   unsigned int sec, unsigned int usec, void *data)
116 {
117         struct drm_output *output = (struct drm_output *) data;
118         struct drm_compositor *c =
119                 (struct drm_compositor *) output->base.compositor;
120         uint32_t msecs;
121
122         if (output->pending_fs_surf_fb_id) {
123                 drmModeRmFB(c->drm.fd, output->pending_fs_surf_fb_id);
124                 output->pending_fs_surf_fb_id = 0;
125         }
126
127         if (output->fs_surf_fb_id) {
128                 output->pending_fs_surf_fb_id = output->fs_surf_fb_id;
129                 output->fs_surf_fb_id = 0;
130         }
131
132         msecs = sec * 1000 + usec / 1000;
133         wlsc_output_finish_frame(&output->base, msecs);
134 }
135
136 static int
137 drm_output_prepare_scanout_surface(struct wlsc_output *output_base,
138                                    struct wlsc_surface *es)
139 {
140         struct drm_output *output = (struct drm_output *) output_base;
141         struct drm_compositor *c =
142                 (struct drm_compositor *) output->base.compositor;
143         EGLint handle, stride;
144         int ret;
145         uint32_t fb_id = 0;
146
147         if (es->x != output->base.x ||
148             es->y != output->base.y ||
149             es->width != output->base.width ||
150             es->height != output->base.height ||
151             es->image == EGL_NO_IMAGE_KHR)
152                 return -1;
153
154         c->export_drm_image(c->base.display,
155                             es->image, NULL, &handle, &stride);
156
157         if (handle == 0)
158                 return -1;
159
160         ret = drmModeAddFB(c->drm.fd,
161                            output->base.width, output->base.height,
162                            32, 32, stride, handle, &fb_id);
163
164         if (ret)
165                 return -1;
166
167         output->fs_surf_fb_id = fb_id;
168         output->scanout_surface = es;
169
170         return 0;
171 }
172
173 static int
174 drm_output_set_cursor(struct wlsc_output *output_base,
175                       struct wl_input_device *input)
176 {
177         struct drm_output *output = (struct drm_output *) output_base;
178         struct drm_compositor *c =
179                 (struct drm_compositor *) output->base.compositor;
180         struct wlsc_input_device *eid = (struct wlsc_input_device *) input;
181         EGLint handle, stride;
182         int ret = -1;
183         pixman_region32_t cursor_region;
184
185         pixman_region32_init_rect(&cursor_region,
186                                   eid->sprite->x, eid->sprite->y,
187                                   eid->sprite->width, eid->sprite->height);
188
189         pixman_region32_intersect_rect(&cursor_region, &cursor_region,
190                                        output->base.x, output->base.y,
191                                        output->base.width, output->base.height);
192
193         if (!pixman_region32_not_empty(&cursor_region)) {
194                 ret = 0;
195                 goto out;
196         }
197
198         if (eid->sprite->image == EGL_NO_IMAGE_KHR)
199                 goto out;
200
201         if (eid->sprite->width > 64 || eid->sprite->height > 64)
202                 goto out;
203         
204         c->export_drm_image(c->base.display, eid->sprite->image,
205                             NULL, &handle, &stride);
206
207         if (stride != 64 * 4) {
208                 fprintf(stderr, "info: cursor stride is != 64\n");
209                 goto out;
210         }
211
212         ret = drmModeSetCursor(c->drm.fd, output->crtc_id, handle, 64, 64);
213         if (ret) {
214                 fprintf(stderr, "failed to set cursor: %s\n", strerror(-ret));
215                 goto out;
216         }
217
218         ret = drmModeMoveCursor(c->drm.fd, output->crtc_id,
219                                 eid->sprite->x - output->base.x,
220                                 eid->sprite->y - output->base.y);
221         if (ret) {
222                 fprintf(stderr, "failed to move cursor: %s\n", strerror(-ret));
223                 goto out;
224         }
225
226         printf("info: set hardware cursor\n");
227
228 out:
229         pixman_region32_fini(&cursor_region);
230         if (ret)
231                 drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
232         return ret;
233 }
234
235 static int
236 on_drm_input(int fd, uint32_t mask, void *data)
237 {
238         drmEventContext evctx;
239
240         memset(&evctx, 0, sizeof evctx);
241         evctx.version = DRM_EVENT_CONTEXT_VERSION;
242         evctx.page_flip_handler = page_flip_handler;
243         drmHandleEvent(fd, &evctx);
244
245         return 1;
246 }
247
248 static int
249 init_egl(struct drm_compositor *ec, struct udev_device *device)
250 {
251         EGLint major, minor;
252         const char *extensions, *filename;
253         int fd;
254         static const EGLint context_attribs[] = {
255                 EGL_CONTEXT_CLIENT_VERSION, 2,
256                 EGL_NONE
257         };
258
259         filename = udev_device_get_devnode(device);
260         fd = open(filename, O_RDWR, O_CLOEXEC);
261         if (fd < 0) {
262                 /* Probably permissions error */
263                 fprintf(stderr, "couldn't open %s, skipping\n",
264                         udev_device_get_devnode(device));
265                 return -1;
266         }
267
268         ec->drm.fd = fd;
269         ec->base.display = eglGetDisplay(FD_TO_EGL_NATIVE_DPY(ec->drm.fd));
270         if (ec->base.display == NULL) {
271                 fprintf(stderr, "failed to create display\n");
272                 return -1;
273         }
274
275         if (!eglInitialize(ec->base.display, &major, &minor)) {
276                 fprintf(stderr, "failed to initialize display\n");
277                 return -1;
278         }
279
280         extensions = eglQueryString(ec->base.display, EGL_EXTENSIONS);
281         if (!strstr(extensions, "EGL_KHR_surfaceless_opengl")) {
282                 fprintf(stderr, "EGL_KHR_surfaceless_opengl not available\n");
283                 return -1;
284         }
285
286         if (!eglBindAPI(EGL_OPENGL_ES_API)) {
287                 fprintf(stderr, "failed to bind api EGL_OPENGL_ES_API\n");
288                 return -1;
289         }
290
291         ec->base.context = eglCreateContext(ec->base.display, NULL,
292                                             EGL_NO_CONTEXT, context_attribs);
293         if (ec->base.context == NULL) {
294                 fprintf(stderr, "failed to create context\n");
295                 return -1;
296         }
297
298         if (!eglMakeCurrent(ec->base.display, EGL_NO_SURFACE,
299                             EGL_NO_SURFACE, ec->base.context)) {
300                 fprintf(stderr, "failed to make context current\n");
301                 return -1;
302         }
303
304         return 0;
305 }
306
307 static drmModeModeInfo builtin_1024x768 = {
308         63500,                  /* clock */
309         1024, 1072, 1176, 1328, 0,
310         768, 771, 775, 798, 0,
311         59920,
312         DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC,
313         0,
314         "1024x768"
315 };
316
317 static int
318 create_output_for_connector(struct drm_compositor *ec,
319                             drmModeRes *resources,
320                             drmModeConnector *connector,
321                             int x, int y)
322 {
323         struct drm_output *output;
324         drmModeEncoder *encoder;
325         drmModeModeInfo *mode;
326         int i, ret;
327         EGLint handle, stride, attribs[] = {
328                 EGL_WIDTH,              0,
329                 EGL_HEIGHT,             0,
330                 EGL_DRM_BUFFER_FORMAT_MESA,     EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
331                 EGL_DRM_BUFFER_USE_MESA,        EGL_DRM_BUFFER_USE_SCANOUT_MESA,
332                 EGL_NONE
333         };
334
335         output = malloc(sizeof *output);
336         if (output == NULL)
337                 return -1;
338
339         if (connector->count_modes > 0) 
340                 mode = &connector->modes[0];
341         else
342                 mode = &builtin_1024x768;
343
344         encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[0]);
345         if (encoder == NULL) {
346                 fprintf(stderr, "No encoder for connector.\n");
347                 return -1;
348         }
349
350         for (i = 0; i < resources->count_crtcs; i++) {
351                 if (encoder->possible_crtcs & (1 << i) &&
352                     !(ec->crtc_allocator & (1 << resources->crtcs[i])))
353                         break;
354         }
355         if (i == resources->count_crtcs) {
356                 fprintf(stderr, "No usable crtc for encoder.\n");
357                 return -1;
358         }
359
360         memset(output, 0, sizeof *output);
361         wlsc_output_init(&output->base, &ec->base, x, y,
362                          mode->hdisplay, mode->vdisplay, 0);
363
364         output->crtc_id = resources->crtcs[i];
365         ec->crtc_allocator |= (1 << output->crtc_id);
366
367         output->connector_id = connector->connector_id;
368         ec->connector_allocator |= (1 << output->connector_id);
369         output->mode = *mode;
370
371         drmModeFreeEncoder(encoder);
372
373         glGenRenderbuffers(2, output->rbo);
374         for (i = 0; i < 2; i++) {
375                 glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]);
376
377                 attribs[1] = output->base.width;
378                 attribs[3] = output->base.height;
379                 output->image[i] =
380                         ec->create_drm_image(ec->base.display, attribs);
381                 ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
382                                                            output->image[i]);
383                 ec->export_drm_image(ec->base.display, output->image[i],
384                                      NULL, &handle, &stride);
385
386                 ret = drmModeAddFB(ec->drm.fd,
387                                    output->base.width, output->base.height,
388                                    32, 32, stride, handle, &output->fb_id[i]);
389                 if (ret) {
390                         fprintf(stderr, "failed to add fb %d: %m\n", i);
391                         return -1;
392                 }
393         }
394
395         output->current = 0;
396         glFramebufferRenderbuffer(GL_FRAMEBUFFER,
397                                   GL_COLOR_ATTACHMENT0,
398                                   GL_RENDERBUFFER,
399                                   output->rbo[output->current]);
400         ret = drmModeSetCrtc(ec->drm.fd, output->crtc_id,
401                              output->fb_id[output->current ^ 1], 0, 0,
402                              &output->connector_id, 1, &output->mode);
403         if (ret) {
404                 fprintf(stderr, "failed to set mode: %m\n");
405                 return -1;
406         }
407
408         output->scanout_surface = NULL;
409         output->base.prepare_render = drm_output_prepare_render;
410         output->base.present = drm_output_present;
411         output->base.prepare_scanout_surface =
412                 drm_output_prepare_scanout_surface;
413         output->base.set_hardware_cursor = drm_output_set_cursor;
414
415         wl_list_insert(ec->base.output_list.prev, &output->base.link);
416
417         return 0;
418 }
419
420 static int
421 create_outputs(struct drm_compositor *ec, int option_connector)
422 {
423         drmModeConnector *connector;
424         drmModeRes *resources;
425         int i;
426         int x = 0, y = 0;
427
428         resources = drmModeGetResources(ec->drm.fd);
429         if (!resources) {
430                 fprintf(stderr, "drmModeGetResources failed\n");
431                 return -1;
432         }
433
434         for (i = 0; i < resources->count_connectors; i++) {
435                 connector = drmModeGetConnector(ec->drm.fd, resources->connectors[i]);
436                 if (connector == NULL)
437                         continue;
438
439                 if (connector->connection == DRM_MODE_CONNECTED &&
440                     (option_connector == 0 ||
441                      connector->connector_id == option_connector))
442                         if (create_output_for_connector(ec, resources,
443                                                         connector, x, y) < 0)
444                                 return -1;
445
446                 x += container_of(ec->base.output_list.prev, struct wlsc_output,
447                                   link)->width;
448
449                 drmModeFreeConnector(connector);
450         }
451
452         if (wl_list_empty(&ec->base.output_list)) {
453                 fprintf(stderr, "No currently active connector found.\n");
454                 return -1;
455         }
456
457         drmModeFreeResources(resources);
458
459         return 0;
460 }
461
462 static int
463 destroy_output(struct drm_output *output)
464 {
465         struct drm_compositor *ec =
466                 (struct drm_compositor *) output->base.compositor;
467         int i;
468
469         glFramebufferRenderbuffer(GL_FRAMEBUFFER,
470                                   GL_COLOR_ATTACHMENT0,
471                                   GL_RENDERBUFFER,
472                                   0);
473
474         glBindRenderbuffer(GL_RENDERBUFFER, 0);
475         glDeleteRenderbuffers(2, output->rbo);
476
477         for (i = 0; i < 2; i++) {
478                 ec->base.destroy_image(ec->base.display, output->image[i]);
479                 drmModeRmFB(ec->drm.fd, output->fb_id[i]);
480         }
481         
482         ec->crtc_allocator &= ~(1 << output->crtc_id);
483         ec->connector_allocator &= ~(1 << output->connector_id);
484
485         wlsc_output_destroy(&output->base);
486         wl_list_remove(&output->base.link);
487
488         free(output);
489
490         return 0;
491 }
492
493 static void
494 update_outputs(struct drm_compositor *ec)
495 {
496         drmModeConnector *connector;
497         drmModeRes *resources;
498         struct drm_output *output, *next;
499         int x = 0, y = 0;
500         int x_offset = 0, y_offset = 0;
501         uint32_t connected = 0, disconnects = 0;
502         int i;
503
504         resources = drmModeGetResources(ec->drm.fd);
505         if (!resources) {
506                 fprintf(stderr, "drmModeGetResources failed\n");
507                 return;
508         }
509
510         /* collect new connects */
511         for (i = 0; i < resources->count_connectors; i++) {
512                 connector =
513                         drmModeGetConnector(ec->drm.fd,
514                                             resources->connectors[i]);
515                 if (connector == NULL ||
516                     connector->connection != DRM_MODE_CONNECTED)
517                         continue;
518
519                 connected |= (1 << connector->connector_id);
520                 
521                 if (!(ec->connector_allocator & (1 << connector->connector_id))) {
522                         struct wlsc_output *last_output =
523                                 container_of(ec->base.output_list.prev,
524                                              struct wlsc_output, link);
525
526                         /* XXX: not yet needed, we die with 0 outputs */
527                         if (!wl_list_empty(&ec->base.output_list))
528                                 x = last_output->x + last_output->width;
529                         else
530                                 x = 0;
531                         y = 0;
532                         create_output_for_connector(ec, resources,
533                                                     connector, x, y);
534                         printf("connector %d connected\n",
535                                connector->connector_id);
536                                 
537                 }
538                 drmModeFreeConnector(connector);
539         }
540         drmModeFreeResources(resources);
541
542         disconnects = ec->connector_allocator & ~connected;
543         if (disconnects) {
544                 wl_list_for_each_safe(output, next, &ec->base.output_list,
545                                       base.link) {
546                         if (x_offset != 0 || y_offset != 0) {
547                                 wlsc_output_move(&output->base,
548                                                  output->base.x - x_offset,
549                                                  output->base.y - y_offset);
550                         }
551
552                         if (disconnects & (1 << output->connector_id)) {
553                                 disconnects &= ~(1 << output->connector_id);
554                                 printf("connector %d disconnected\n",
555                                        output->connector_id);
556                                 x_offset += output->base.width;
557                                 destroy_output(output);
558                         }
559                 }
560         }
561
562         /* FIXME: handle zero outputs, without terminating */   
563         if (ec->connector_allocator == 0)
564                 wl_display_terminate(ec->base.wl_display);
565 }
566
567 static int
568 udev_event_is_hotplug(struct udev_device *device)
569 {
570         struct udev_list_entry *list, *hotplug_entry;
571         
572         list = udev_device_get_properties_list_entry(device);
573
574         hotplug_entry = udev_list_entry_get_by_name(list, "HOTPLUG");
575         if (hotplug_entry == NULL)
576                 return 0;
577
578         return strcmp(udev_list_entry_get_value(hotplug_entry), "1") == 0;
579 }
580
581 static int
582 udev_drm_event(int fd, uint32_t mask, void *data)
583 {
584         struct drm_compositor *ec = data;
585         struct udev_device *event;
586
587         event = udev_monitor_receive_device(ec->udev_monitor);
588         
589         if (udev_event_is_hotplug(event))
590                 update_outputs(ec);
591
592         udev_device_unref(event);
593
594         return 1;
595 }
596
597 static EGLImageKHR
598 drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
599                                    int32_t width, int32_t height)
600 {
601         static const EGLint image_attribs[] = {
602                 EGL_WIDTH, 64,
603                 EGL_HEIGHT, 64,
604                 EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
605                 EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_CURSOR_MESA,
606                 EGL_NONE
607         };
608         struct drm_compositor *c = (struct drm_compositor *) ec;
609
610         if (width > 64 || height > 64)
611                 return EGL_NO_IMAGE_KHR;
612
613         return c->create_drm_image(ec->display, image_attribs);
614 }
615
616 static void
617 drm_destroy(struct wlsc_compositor *ec)
618 {
619         struct drm_compositor *d = (struct drm_compositor *) ec;
620
621         tty_destroy(d->tty);
622
623         free(d);
624 }
625
626 struct wlsc_compositor *
627 drm_compositor_create(struct wl_display *display, int connector)
628 {
629         struct drm_compositor *ec;
630         struct udev_enumerate *e;
631         struct udev_list_entry *entry;
632         struct udev_device *device;
633         const char *path;
634         struct wl_event_loop *loop;
635
636         ec = malloc(sizeof *ec);
637         if (ec == NULL)
638                 return NULL;
639
640         memset(ec, 0, sizeof *ec);
641         ec->udev = udev_new();
642         if (ec->udev == NULL) {
643                 fprintf(stderr, "failed to initialize udev context\n");
644                 return NULL;
645         }
646
647         e = udev_enumerate_new(ec->udev);
648         udev_enumerate_add_match_subsystem(e, "drm");
649         udev_enumerate_add_match_property(e, "WAYLAND_SEAT", "1");
650         udev_enumerate_scan_devices(e);
651         device = NULL;
652         udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
653                 path = udev_list_entry_get_name(entry);
654                 device = udev_device_new_from_syspath(ec->udev, path);
655                 break;
656         }
657         udev_enumerate_unref(e);
658
659         if (device == NULL) {
660                 fprintf(stderr, "no drm device found\n");
661                 return NULL;
662         }
663
664         ec->base.wl_display = display;
665         if (init_egl(ec, device) < 0) {
666                 fprintf(stderr, "failed to initialize egl\n");
667                 return NULL;
668         }
669
670         ec->base.destroy = drm_destroy;
671         ec->base.create_cursor_image = drm_compositor_create_cursor_image;
672
673         ec->base.focus = 1;
674
675         glGenFramebuffers(1, &ec->base.fbo);
676         glBindFramebuffer(GL_FRAMEBUFFER, ec->base.fbo);
677
678         ec->create_drm_image =
679                 (void *) eglGetProcAddress("eglCreateDRMImageMESA");
680         ec->export_drm_image =
681                 (void *) eglGetProcAddress("eglExportDRMImageMESA");
682
683         /* Can't init base class until we have a current egl context */
684         if (wlsc_compositor_init(&ec->base, display) < 0)
685                 return NULL;
686
687         if (create_outputs(ec, connector) < 0) {
688                 fprintf(stderr, "failed to create output for %s\n", path);
689                 return NULL;
690         }
691
692         evdev_input_add_devices(&ec->base, ec->udev);
693
694         loop = wl_display_get_event_loop(ec->base.wl_display);
695         ec->drm_source =
696                 wl_event_loop_add_fd(loop, ec->drm.fd,
697                                      WL_EVENT_READABLE, on_drm_input, ec);
698         ec->tty = tty_create(&ec->base);
699
700         ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
701         if (ec->udev_monitor == NULL) {
702                 fprintf(stderr, "failed to intialize udev monitor\n");
703                 return NULL;
704         }
705         udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor,
706                                                         "drm", NULL);
707         ec->udev_drm_source =
708                 wl_event_loop_add_fd(loop, udev_monitor_get_fd(ec->udev_monitor),
709                                      WL_EVENT_READABLE, udev_drm_event, ec);
710
711         if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) {
712                 fprintf(stderr, "failed to enable udev-monitor receiving\n");
713                 return NULL;
714         }
715
716         return &ec->base;
717 }
718
719 struct wlsc_compositor *
720 backend_init(struct wl_display *display, char *options)
721 {
722         int connector = 0, i;
723         char *p, *value;
724
725         static char * const tokens[] = { "connector", NULL };
726         
727         p = options;
728         while (i = getsubopt(&p, tokens, &value), i != -1) {
729                 switch (i) {
730                 case 0:
731                         connector = strtol(value, NULL, 0);
732                         break;
733                 }
734         }
735
736         return drm_compositor_create(display, connector);
737 }