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