Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 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 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <unistd.h> |
| 24 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 25 | #define GL_GLEXT_PROTOTYPES |
| 26 | #define EGL_EGLEXT_PROTOTYPES |
| 27 | #include <GLES2/gl2.h> |
| 28 | #include <GLES2/gl2ext.h> |
| 29 | #include <EGL/egl.h> |
| 30 | #include <EGL/eglext.h> |
| 31 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 32 | #include "compositor.h" |
| 33 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 34 | struct drm_compositor { |
| 35 | struct wlsc_compositor base; |
| 36 | |
| 37 | struct udev *udev; |
| 38 | struct wl_event_source *drm_source; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 39 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame^] | 40 | struct tty *tty; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct drm_output { |
| 44 | struct wlsc_output base; |
| 45 | |
| 46 | drmModeModeInfo mode; |
| 47 | uint32_t crtc_id; |
| 48 | uint32_t connector_id; |
| 49 | GLuint rbo[2]; |
| 50 | uint32_t fb_id[2]; |
| 51 | EGLImageKHR image[2]; |
| 52 | uint32_t current; |
| 53 | }; |
| 54 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 55 | static void |
| 56 | drm_compositor_present(struct wlsc_compositor *ec) |
| 57 | { |
| 58 | struct drm_compositor *c = (struct drm_compositor *) ec; |
| 59 | struct drm_output *output; |
| 60 | |
| 61 | wl_list_for_each(output, &ec->output_list, base.link) { |
| 62 | output->current ^= 1; |
| 63 | |
| 64 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, |
| 65 | GL_COLOR_ATTACHMENT0, |
| 66 | GL_RENDERBUFFER, |
| 67 | output->rbo[output->current]); |
| 68 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 69 | drmModePageFlip(c->base.drm.fd, output->crtc_id, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 70 | output->fb_id[output->current ^ 1], |
| 71 | DRM_MODE_PAGE_FLIP_EVENT, output); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static void |
| 76 | page_flip_handler(int fd, unsigned int frame, |
| 77 | unsigned int sec, unsigned int usec, void *data) |
| 78 | { |
| 79 | struct wlsc_output *output = data; |
| 80 | struct wlsc_compositor *compositor = output->compositor; |
| 81 | uint32_t msecs; |
| 82 | |
| 83 | msecs = sec * 1000 + usec / 1000; |
| 84 | wlsc_compositor_finish_frame(compositor, msecs); |
| 85 | } |
| 86 | |
| 87 | static void |
| 88 | on_drm_input(int fd, uint32_t mask, void *data) |
| 89 | { |
| 90 | drmEventContext evctx; |
| 91 | |
| 92 | memset(&evctx, 0, sizeof evctx); |
| 93 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 94 | evctx.page_flip_handler = page_flip_handler; |
| 95 | drmHandleEvent(fd, &evctx); |
| 96 | } |
| 97 | |
| 98 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 99 | init_egl(struct drm_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 100 | { |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 101 | EGLint major, minor; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 102 | const char *extensions, *filename; |
| 103 | int fd; |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 104 | static const EGLint context_attribs[] = { |
| 105 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 106 | EGL_NONE |
| 107 | }; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 108 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 109 | filename = udev_device_get_devnode(device); |
| 110 | fd = open(filename, O_RDWR); |
| 111 | if (fd < 0) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 112 | /* Probably permissions error */ |
| 113 | fprintf(stderr, "couldn't open %s, skipping\n", |
| 114 | udev_device_get_devnode(device)); |
| 115 | return -1; |
| 116 | } |
| 117 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 118 | wlsc_drm_init(&ec->base, fd, filename); |
| 119 | |
| 120 | ec->base.display = eglGetDRMDisplayMESA(ec->base.drm.fd); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 121 | if (ec->base.display == NULL) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 122 | fprintf(stderr, "failed to create display\n"); |
| 123 | return -1; |
| 124 | } |
| 125 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 126 | if (!eglInitialize(ec->base.display, &major, &minor)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 127 | fprintf(stderr, "failed to initialize display\n"); |
| 128 | return -1; |
| 129 | } |
| 130 | |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 131 | extensions = eglQueryString(ec->base.display, EGL_EXTENSIONS); |
| 132 | if (!strstr(extensions, "EGL_KHR_surfaceless_opengl")) { |
| 133 | fprintf(stderr, "EGL_KHR_surfaceless_opengl not available\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 134 | return -1; |
| 135 | } |
| 136 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 137 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
| 138 | fprintf(stderr, "failed to bind api EGL_OPENGL_ES_API\n"); |
| 139 | return -1; |
| 140 | } |
| 141 | |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 142 | ec->base.context = eglCreateContext(ec->base.display, NULL, |
| 143 | EGL_NO_CONTEXT, context_attribs); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 144 | if (ec->base.context == NULL) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 145 | fprintf(stderr, "failed to create context\n"); |
| 146 | return -1; |
| 147 | } |
| 148 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 149 | if (!eglMakeCurrent(ec->base.display, EGL_NO_SURFACE, |
| 150 | EGL_NO_SURFACE, ec->base.context)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 151 | fprintf(stderr, "failed to make context current\n"); |
| 152 | return -1; |
| 153 | } |
| 154 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static drmModeModeInfo builtin_1024x768 = { |
| 159 | 63500, /* clock */ |
| 160 | 1024, 1072, 1176, 1328, 0, |
| 161 | 768, 771, 775, 798, 0, |
| 162 | 59920, |
| 163 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, |
| 164 | 0, |
| 165 | "1024x768" |
| 166 | }; |
| 167 | |
| 168 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 169 | create_output_for_connector(struct drm_compositor *ec, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 170 | drmModeRes *resources, |
| 171 | drmModeConnector *connector) |
| 172 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 173 | struct drm_output *output; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 174 | drmModeEncoder *encoder; |
| 175 | drmModeModeInfo *mode; |
| 176 | int i, ret; |
| 177 | EGLint handle, stride, attribs[] = { |
| 178 | EGL_WIDTH, 0, |
| 179 | EGL_HEIGHT, 0, |
Kristian Høgsberg | b12fcce | 2010-08-24 17:34:23 -0400 | [diff] [blame] | 180 | EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
| 181 | EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 182 | EGL_NONE |
| 183 | }; |
| 184 | |
| 185 | output = malloc(sizeof *output); |
| 186 | if (output == NULL) |
| 187 | return -1; |
| 188 | |
| 189 | if (connector->count_modes > 0) |
| 190 | mode = &connector->modes[0]; |
| 191 | else |
| 192 | mode = &builtin_1024x768; |
| 193 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 194 | encoder = drmModeGetEncoder(ec->base.drm.fd, connector->encoders[0]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 195 | if (encoder == NULL) { |
| 196 | fprintf(stderr, "No encoder for connector.\n"); |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | for (i = 0; i < resources->count_crtcs; i++) { |
| 201 | if (encoder->possible_crtcs & (1 << i)) |
| 202 | break; |
| 203 | } |
| 204 | if (i == resources->count_crtcs) { |
| 205 | fprintf(stderr, "No usable crtc for encoder.\n"); |
| 206 | return -1; |
| 207 | } |
| 208 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 209 | memset(output, 0, sizeof *output); |
| 210 | wlsc_output_init(&output->base, &ec->base, 0, 0, |
| 211 | mode->hdisplay, mode->vdisplay); |
| 212 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 213 | output->crtc_id = resources->crtcs[i]; |
| 214 | output->connector_id = connector->connector_id; |
| 215 | output->mode = *mode; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 216 | |
| 217 | drmModeFreeEncoder(encoder); |
| 218 | |
| 219 | glGenRenderbuffers(2, output->rbo); |
| 220 | for (i = 0; i < 2; i++) { |
| 221 | glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]); |
| 222 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 223 | attribs[1] = output->base.width; |
| 224 | attribs[3] = output->base.height; |
| 225 | output->image[i] = |
| 226 | eglCreateDRMImageMESA(ec->base.display, attribs); |
| 227 | glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, |
| 228 | output->image[i]); |
| 229 | eglExportDRMImageMESA(ec->base.display, output->image[i], |
| 230 | NULL, &handle, &stride); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 231 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 232 | ret = drmModeAddFB(ec->base.drm.fd, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 233 | output->base.width, output->base.height, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 234 | 32, 32, stride, handle, &output->fb_id[i]); |
| 235 | if (ret) { |
| 236 | fprintf(stderr, "failed to add fb %d: %m\n", i); |
| 237 | return -1; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | output->current = 0; |
| 242 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, |
| 243 | GL_COLOR_ATTACHMENT0, |
| 244 | GL_RENDERBUFFER, |
| 245 | output->rbo[output->current]); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 246 | ret = drmModeSetCrtc(ec->base.drm.fd, output->crtc_id, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 247 | output->fb_id[output->current ^ 1], 0, 0, |
| 248 | &output->connector_id, 1, &output->mode); |
| 249 | if (ret) { |
| 250 | fprintf(stderr, "failed to set mode: %m\n"); |
| 251 | return -1; |
| 252 | } |
| 253 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 254 | wl_list_insert(ec->base.output_list.prev, &output->base.link); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | static int |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 260 | create_outputs(struct drm_compositor *ec, int option_connector) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 261 | { |
| 262 | drmModeConnector *connector; |
| 263 | drmModeRes *resources; |
| 264 | int i; |
| 265 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 266 | resources = drmModeGetResources(ec->base.drm.fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 267 | if (!resources) { |
| 268 | fprintf(stderr, "drmModeGetResources failed\n"); |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | for (i = 0; i < resources->count_connectors; i++) { |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 273 | connector = drmModeGetConnector(ec->base.drm.fd, resources->connectors[i]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 274 | if (connector == NULL) |
| 275 | continue; |
| 276 | |
| 277 | if (connector->connection == DRM_MODE_CONNECTED && |
| 278 | (option_connector == 0 || |
| 279 | connector->connector_id == option_connector)) |
| 280 | if (create_output_for_connector(ec, resources, connector) < 0) |
| 281 | return -1; |
| 282 | |
| 283 | drmModeFreeConnector(connector); |
| 284 | } |
| 285 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 286 | if (wl_list_empty(&ec->base.output_list)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 287 | fprintf(stderr, "No currently active connector found.\n"); |
| 288 | return -1; |
| 289 | } |
| 290 | |
| 291 | drmModeFreeResources(resources); |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
Kristian Høgsberg | 640609a | 2010-08-09 22:11:47 -0400 | [diff] [blame] | 296 | static int |
| 297 | drm_authenticate(struct wlsc_compositor *c, uint32_t id) |
| 298 | { |
| 299 | struct drm_compositor *ec = (struct drm_compositor *) c; |
| 300 | |
| 301 | return drmAuthMagic(ec->base.drm.fd, id); |
| 302 | } |
| 303 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 304 | static void |
| 305 | drm_destroy(struct wlsc_compositor *ec) |
| 306 | { |
| 307 | struct drm_compositor *d = (struct drm_compositor *) ec; |
| 308 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame^] | 309 | tty_destroy(d->tty); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 310 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame^] | 311 | free(d); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 312 | } |
| 313 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 314 | struct wlsc_compositor * |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 315 | drm_compositor_create(struct wl_display *display, int connector) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 316 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 317 | struct drm_compositor *ec; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 318 | struct udev_enumerate *e; |
| 319 | struct udev_list_entry *entry; |
| 320 | struct udev_device *device; |
| 321 | const char *path; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 322 | struct wl_event_loop *loop; |
| 323 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 324 | ec = malloc(sizeof *ec); |
| 325 | if (ec == NULL) |
| 326 | return NULL; |
| 327 | |
| 328 | memset(ec, 0, sizeof *ec); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 329 | ec->udev = udev_new(); |
| 330 | if (ec->udev == NULL) { |
| 331 | fprintf(stderr, "failed to initialize udev context\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 332 | return NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 335 | e = udev_enumerate_new(ec->udev); |
| 336 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 337 | udev_enumerate_add_match_property(e, "WAYLAND_SEAT", "1"); |
| 338 | udev_enumerate_scan_devices(e); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 339 | device = NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 340 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 341 | path = udev_list_entry_get_name(entry); |
| 342 | device = udev_device_new_from_syspath(ec->udev, path); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 343 | break; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 344 | } |
| 345 | udev_enumerate_unref(e); |
| 346 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 347 | if (device == NULL) { |
| 348 | fprintf(stderr, "no drm device found\n"); |
| 349 | return NULL; |
| 350 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 351 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 352 | ec->base.wl_display = display; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 353 | if (init_egl(ec, device) < 0) { |
| 354 | fprintf(stderr, "failed to initialize egl\n"); |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | /* Can't init base class until we have a current egl context */ |
Kristian Høgsberg | a946821 | 2010-06-14 21:03:11 -0400 | [diff] [blame] | 359 | if (wlsc_compositor_init(&ec->base, display) < 0) |
| 360 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 361 | |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 362 | if (create_outputs(ec, connector) < 0) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 363 | fprintf(stderr, "failed to create output for %s\n", path); |
| 364 | return NULL; |
| 365 | } |
| 366 | |
Kristian Høgsberg | 43db401 | 2011-01-14 14:45:42 -0500 | [diff] [blame] | 367 | evdev_input_add_devices(&ec->base, ec->udev); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 368 | |
| 369 | loop = wl_display_get_event_loop(ec->base.wl_display); |
| 370 | ec->drm_source = |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 371 | wl_event_loop_add_fd(loop, ec->base.drm.fd, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 372 | WL_EVENT_READABLE, on_drm_input, ec); |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame^] | 373 | ec->tty = tty_create(&ec->base); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 374 | ec->base.destroy = drm_destroy; |
Kristian Høgsberg | 640609a | 2010-08-09 22:11:47 -0400 | [diff] [blame] | 375 | ec->base.authenticate = drm_authenticate; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 376 | ec->base.present = drm_compositor_present; |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 377 | ec->base.focus = 1; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 378 | |
| 379 | return &ec->base; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 380 | } |