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