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