Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2008-2011 Kristian Høgsberg |
| 3 | * Copyright © 2011 Intel Corporation |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 4 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 14 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Kristian Høgsberg | 0b9334a | 2011-04-12 11:34:32 -0400 | [diff] [blame] | 24 | #define _GNU_SOURCE |
| 25 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 26 | #include <errno.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <unistd.h> |
| 32 | |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 33 | #include <xf86drm.h> |
| 34 | #include <xf86drmMode.h> |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 35 | #include <drm_fourcc.h> |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 36 | |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 37 | #include <gbm.h> |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 38 | #include <libbacklight.h> |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 39 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 40 | #include "compositor.h" |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 41 | #include "evdev.h" |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 42 | #include "launcher-util.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 43 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 44 | struct drm_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 45 | struct weston_compositor base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 46 | |
| 47 | struct udev *udev; |
| 48 | struct wl_event_source *drm_source; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 49 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 50 | struct udev_monitor *udev_monitor; |
| 51 | struct wl_event_source *udev_drm_source; |
| 52 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 53 | struct { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 54 | int id; |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 55 | int fd; |
| 56 | } drm; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 57 | struct gbm_device *gbm; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 58 | uint32_t *crtcs; |
| 59 | int num_crtcs; |
Marty Jack | 13d9db2 | 2011-02-09 19:01:42 -0500 | [diff] [blame] | 60 | uint32_t crtc_allocator; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 61 | uint32_t connector_allocator; |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 62 | struct tty *tty; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 63 | |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 64 | struct gbm_surface *dummy_surface; |
| 65 | EGLSurface dummy_egl_surface; |
| 66 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 67 | struct wl_list sprite_list; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 68 | int sprites_are_broken; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 69 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 70 | uint32_t prev_state; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 71 | }; |
| 72 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 73 | struct drm_mode { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 74 | struct weston_mode base; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 75 | drmModeModeInfo mode_info; |
| 76 | }; |
| 77 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 78 | struct drm_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 79 | struct weston_output base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 80 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 81 | uint32_t crtc_id; |
| 82 | uint32_t connector_id; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 83 | drmModeCrtcPtr original_crtc; |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 84 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 85 | struct gbm_surface *surface; |
| 86 | EGLSurface egl_surface; |
| 87 | uint32_t current_fb_id; |
| 88 | uint32_t next_fb_id; |
| 89 | struct gbm_bo *current_bo; |
| 90 | struct gbm_bo *next_bo; |
| 91 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 92 | struct wl_buffer *scanout_buffer; |
| 93 | struct wl_listener scanout_buffer_destroy_listener; |
| 94 | struct wl_buffer *pending_scanout_buffer; |
| 95 | struct wl_listener pending_scanout_buffer_destroy_listener; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 96 | struct backlight *backlight; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 97 | }; |
| 98 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 99 | /* |
| 100 | * An output has a primary display plane plus zero or more sprites for |
| 101 | * blending display contents. |
| 102 | */ |
| 103 | struct drm_sprite { |
| 104 | struct wl_list link; |
| 105 | |
| 106 | uint32_t fb_id; |
| 107 | uint32_t pending_fb_id; |
| 108 | struct weston_surface *surface; |
| 109 | struct weston_surface *pending_surface; |
| 110 | |
| 111 | struct drm_compositor *compositor; |
| 112 | |
| 113 | struct wl_listener destroy_listener; |
| 114 | struct wl_listener pending_destroy_listener; |
| 115 | |
| 116 | uint32_t possible_crtcs; |
| 117 | uint32_t plane_id; |
| 118 | uint32_t count_formats; |
| 119 | |
| 120 | int32_t src_x, src_y; |
| 121 | uint32_t src_w, src_h; |
| 122 | uint32_t dest_x, dest_y; |
| 123 | uint32_t dest_w, dest_h; |
| 124 | |
| 125 | uint32_t formats[]; |
| 126 | }; |
| 127 | |
| 128 | static int |
| 129 | surface_is_primary(struct weston_compositor *ec, struct weston_surface *es) |
| 130 | { |
| 131 | struct weston_surface *primary; |
| 132 | |
| 133 | primary = container_of(ec->surface_list.next, struct weston_surface, |
| 134 | link); |
| 135 | if (es == primary) |
| 136 | return -1; |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static int |
| 141 | drm_sprite_crtc_supported(struct weston_output *output_base, uint32_t supported) |
| 142 | { |
| 143 | struct weston_compositor *ec = output_base->compositor; |
| 144 | struct drm_compositor *c =(struct drm_compositor *) ec; |
| 145 | struct drm_output *output = (struct drm_output *) output_base; |
| 146 | int crtc; |
| 147 | |
| 148 | for (crtc = 0; crtc < c->num_crtcs; crtc++) { |
| 149 | if (c->crtcs[crtc] != output->crtc_id) |
| 150 | continue; |
| 151 | |
| 152 | if (supported & (1 << crtc)) |
| 153 | return -1; |
| 154 | } |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 159 | static int |
| 160 | drm_output_prepare_scanout_surface(struct drm_output *output) |
| 161 | { |
| 162 | struct drm_compositor *c = |
| 163 | (struct drm_compositor *) output->base.compositor; |
| 164 | struct weston_surface *es; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 165 | |
| 166 | es = container_of(c->base.surface_list.next, |
| 167 | struct weston_surface, link); |
| 168 | |
Kristian Høgsberg | 101cb65 | 2012-02-17 10:45:16 -0500 | [diff] [blame] | 169 | /* Need to verify output->region contained in surface opaque |
| 170 | * region. Or maybe just that format doesn't have alpha. */ |
| 171 | return -1; |
| 172 | |
| 173 | if (es->geometry.x != output->base.x || |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 174 | es->geometry.y != output->base.y || |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 175 | es->geometry.width != output->base.current->width || |
| 176 | es->geometry.height != output->base.current->height || |
Pekka Paalanen | f1f5b36 | 2012-01-25 14:33:33 +0200 | [diff] [blame] | 177 | es->transform.enabled || |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 178 | es->image == EGL_NO_IMAGE_KHR) |
| 179 | return -1; |
| 180 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 181 | output->next_bo = |
| 182 | gbm_bo_create_from_egl_image(c->gbm, |
| 183 | c->base.display, es->image, |
| 184 | es->geometry.width, |
| 185 | es->geometry.height, |
| 186 | GBM_BO_USE_SCANOUT); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 187 | |
| 188 | /* assert output->pending_scanout_buffer == NULL */ |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 189 | output->pending_scanout_buffer = es->buffer; |
| 190 | output->pending_scanout_buffer->busy_count++; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 191 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 192 | wl_list_insert(output->pending_scanout_buffer->resource.destroy_listener_list.prev, |
| 193 | &output->pending_scanout_buffer_destroy_listener.link); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 194 | |
| 195 | pixman_region32_fini(&es->damage); |
| 196 | pixman_region32_init(&es->damage); |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 201 | static void |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 202 | drm_output_render(struct drm_output *output, pixman_region32_t *damage) |
| 203 | { |
| 204 | struct drm_compositor *compositor = |
| 205 | (struct drm_compositor *) output->base.compositor; |
| 206 | struct weston_surface *surface; |
| 207 | |
| 208 | if (!eglMakeCurrent(compositor->base.display, output->egl_surface, |
| 209 | output->egl_surface, compositor->base.context)) { |
| 210 | fprintf(stderr, "failed to make current\n"); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | wl_list_for_each_reverse(surface, &compositor->base.surface_list, link) |
| 215 | weston_surface_draw(surface, &output->base, damage); |
| 216 | |
| 217 | eglSwapBuffers(compositor->base.display, output->egl_surface); |
| 218 | output->next_bo = gbm_surface_lock_front_buffer(output->surface); |
| 219 | if (!output->next_bo) { |
| 220 | fprintf(stderr, "failed to lock front buffer: %m\n"); |
| 221 | return; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | static void |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 226 | drm_output_repaint(struct weston_output *output_base, |
| 227 | pixman_region32_t *damage) |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 228 | { |
| 229 | struct drm_output *output = (struct drm_output *) output_base; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 230 | struct drm_compositor *compositor = |
| 231 | (struct drm_compositor *) output->base.compositor; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 232 | struct drm_sprite *s; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 233 | struct drm_mode *mode; |
| 234 | uint32_t stride, handle; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 235 | int ret = 0; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 236 | |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 237 | drm_output_prepare_scanout_surface(output); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 238 | if (!output->next_bo) |
| 239 | drm_output_render(output, damage); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 240 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 241 | stride = gbm_bo_get_pitch(output->next_bo); |
| 242 | handle = gbm_bo_get_handle(output->next_bo).u32; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 243 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 244 | /* Destroy and set to NULL now so we don't try to |
| 245 | * gbm_surface_release_buffer() a client buffer in the |
| 246 | * page_flip_handler. */ |
| 247 | if (output->pending_scanout_buffer) { |
| 248 | gbm_bo_destroy(output->next_bo); |
| 249 | output->next_bo = NULL; |
| 250 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 251 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 252 | ret = drmModeAddFB(compositor->drm.fd, |
| 253 | output->base.current->width, |
| 254 | output->base.current->height, |
| 255 | 24, 32, stride, handle, &output->next_fb_id); |
| 256 | if (ret) { |
| 257 | fprintf(stderr, "failed to create kms fb: %m\n"); |
| 258 | gbm_surface_release_buffer(output->surface, output->next_bo); |
| 259 | output->next_bo = NULL; |
| 260 | return; |
| 261 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 262 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 263 | mode = container_of(output->base.current, struct drm_mode, base); |
| 264 | if (output->current_fb_id == 0) { |
| 265 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
| 266 | output->next_fb_id, 0, 0, |
| 267 | &output->connector_id, 1, |
| 268 | &mode->mode_info); |
| 269 | if (ret) { |
| 270 | fprintf(stderr, "set mode failed: %m\n"); |
| 271 | return; |
| 272 | } |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 275 | if (drmModePageFlip(compositor->drm.fd, output->crtc_id, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 276 | output->next_fb_id, |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 277 | DRM_MODE_PAGE_FLIP_EVENT, output) < 0) { |
| 278 | fprintf(stderr, "queueing pageflip failed: %m\n"); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 279 | return; |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 280 | } |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 281 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 282 | /* |
| 283 | * Now, update all the sprite surfaces |
| 284 | */ |
| 285 | wl_list_for_each(s, &compositor->sprite_list, link) { |
| 286 | uint32_t flags = 0; |
| 287 | drmVBlank vbl = { |
| 288 | .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT, |
| 289 | .request.sequence = 1, |
| 290 | }; |
| 291 | |
| 292 | if (!drm_sprite_crtc_supported(output_base, s->possible_crtcs)) |
| 293 | continue; |
| 294 | |
| 295 | ret = drmModeSetPlane(compositor->drm.fd, s->plane_id, |
| 296 | output->crtc_id, s->pending_fb_id, flags, |
| 297 | s->dest_x, s->dest_y, |
| 298 | s->dest_w, s->dest_h, |
| 299 | s->src_x, s->src_y, |
| 300 | s->src_w, s->src_h); |
| 301 | if (ret) |
| 302 | fprintf(stderr, "setplane failed: %d: %s\n", |
| 303 | ret, strerror(errno)); |
| 304 | |
| 305 | /* |
| 306 | * Queue a vblank signal so we know when the surface |
| 307 | * becomes active on the display or has been replaced. |
| 308 | */ |
| 309 | vbl.request.signal = (unsigned long)s; |
| 310 | ret = drmWaitVBlank(compositor->drm.fd, &vbl); |
| 311 | if (ret) { |
| 312 | fprintf(stderr, "vblank event request failed: %d: %s\n", |
| 313 | ret, strerror(errno)); |
| 314 | } |
| 315 | } |
| 316 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 317 | return; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static void |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 321 | vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, |
| 322 | void *data) |
| 323 | { |
| 324 | struct drm_sprite *s = (struct drm_sprite *)data; |
| 325 | struct drm_compositor *c = s->compositor; |
| 326 | |
| 327 | if (s->surface) { |
| 328 | weston_buffer_post_release(s->surface->buffer); |
| 329 | wl_list_remove(&s->destroy_listener.link); |
| 330 | s->surface = NULL; |
| 331 | drmModeRmFB(c->drm.fd, s->fb_id); |
| 332 | s->fb_id = 0; |
| 333 | } |
| 334 | |
| 335 | if (s->pending_surface) { |
| 336 | wl_list_remove(&s->pending_destroy_listener.link); |
| 337 | wl_list_insert(s->pending_surface->buffer->resource.destroy_listener_list.prev, |
| 338 | &s->destroy_listener.link); |
| 339 | s->surface = s->pending_surface; |
| 340 | s->pending_surface = NULL; |
| 341 | s->fb_id = s->pending_fb_id; |
| 342 | s->pending_fb_id = 0; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | static void |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 347 | page_flip_handler(int fd, unsigned int frame, |
| 348 | unsigned int sec, unsigned int usec, void *data) |
| 349 | { |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 350 | struct drm_output *output = (struct drm_output *) data; |
| 351 | struct drm_compositor *c = |
| 352 | (struct drm_compositor *) output->base.compositor; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 353 | uint32_t msecs; |
| 354 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 355 | if (output->current_fb_id) |
| 356 | drmModeRmFB(c->drm.fd, output->current_fb_id); |
| 357 | output->current_fb_id = output->next_fb_id; |
| 358 | output->next_fb_id = 0; |
| 359 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 360 | if (output->scanout_buffer) { |
| 361 | weston_buffer_post_release(output->scanout_buffer); |
| 362 | wl_list_remove(&output->scanout_buffer_destroy_listener.link); |
| 363 | output->scanout_buffer = NULL; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 364 | } else if (output->current_bo) { |
| 365 | gbm_surface_release_buffer(output->surface, |
| 366 | output->current_bo); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 367 | } |
| 368 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 369 | output->current_bo = output->next_bo; |
| 370 | output->next_bo = NULL; |
| 371 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 372 | if (output->pending_scanout_buffer) { |
| 373 | output->scanout_buffer = output->pending_scanout_buffer; |
| 374 | wl_list_remove(&output->pending_scanout_buffer_destroy_listener.link); |
| 375 | wl_list_insert(output->scanout_buffer->resource.destroy_listener_list.prev, |
| 376 | &output->scanout_buffer_destroy_listener.link); |
| 377 | output->pending_scanout_buffer = NULL; |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 378 | } |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 379 | msecs = sec * 1000 + usec / 1000; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 380 | weston_output_finish_frame(&output->base, msecs); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static int |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 384 | drm_surface_format_supported(struct drm_sprite *s, uint32_t format) |
| 385 | { |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 386 | uint32_t i; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 387 | |
| 388 | for (i = 0; i < s->count_formats; i++) |
| 389 | if (s->formats[i] == format) |
| 390 | return 1; |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static int |
| 396 | drm_surface_transform_supported(struct weston_surface *es) |
| 397 | { |
| 398 | if (es->transform.enabled) |
| 399 | return 0; |
| 400 | |
| 401 | return 1; |
| 402 | } |
| 403 | |
| 404 | static int |
| 405 | drm_surface_overlap_supported(struct weston_output *output_base, |
| 406 | pixman_region32_t *overlap) |
| 407 | { |
| 408 | /* We could potentially use a color key here if the surface left |
| 409 | * to display has rectangular regions |
| 410 | */ |
| 411 | if (pixman_region32_not_empty(overlap)) |
| 412 | return 0; |
| 413 | return 1; |
| 414 | } |
| 415 | |
| 416 | static void |
| 417 | drm_disable_unused_sprites(struct weston_output *output_base) |
| 418 | { |
| 419 | struct weston_compositor *ec = output_base->compositor; |
| 420 | struct drm_compositor *c =(struct drm_compositor *) ec; |
| 421 | struct drm_output *output = (struct drm_output *) output_base; |
| 422 | struct drm_sprite *s; |
| 423 | int ret; |
| 424 | |
| 425 | wl_list_for_each(s, &c->sprite_list, link) { |
| 426 | if (s->pending_fb_id) |
| 427 | continue; |
| 428 | |
| 429 | ret = drmModeSetPlane(c->drm.fd, s->plane_id, |
| 430 | output->crtc_id, 0, 0, |
| 431 | 0, 0, 0, 0, 0, 0, 0, 0); |
| 432 | if (ret) |
| 433 | fprintf(stderr, |
| 434 | "failed to disable plane: %d: %s\n", |
| 435 | ret, strerror(errno)); |
| 436 | drmModeRmFB(c->drm.fd, s->fb_id); |
| 437 | s->surface = NULL; |
| 438 | s->pending_surface = NULL; |
| 439 | s->fb_id = 0; |
| 440 | s->pending_fb_id = 0; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | /* |
| 445 | * This function must take care to damage any previously assigned surface |
| 446 | * if the sprite ends up binding to a different surface than in the |
| 447 | * previous frame. |
| 448 | */ |
| 449 | static int |
| 450 | drm_output_prepare_overlay_surface(struct weston_output *output_base, |
| 451 | struct weston_surface *es, |
| 452 | pixman_region32_t *overlap) |
| 453 | { |
| 454 | struct weston_compositor *ec = output_base->compositor; |
| 455 | struct drm_compositor *c =(struct drm_compositor *) ec; |
| 456 | struct drm_sprite *s; |
| 457 | int found = 0; |
| 458 | EGLint handle, stride; |
| 459 | struct gbm_bo *bo; |
| 460 | uint32_t fb_id = 0; |
| 461 | uint32_t handles[4], pitches[4], offsets[4]; |
| 462 | int ret = 0; |
| 463 | pixman_region32_t dest_rect, src_rect; |
| 464 | pixman_box32_t *box; |
| 465 | uint32_t format; |
| 466 | |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 467 | if (c->sprites_are_broken) |
| 468 | return -1; |
| 469 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 470 | if (surface_is_primary(ec, es)) |
| 471 | return -1; |
| 472 | |
Kristian Høgsberg | 7a011ea | 2012-03-26 11:48:55 -0400 | [diff] [blame] | 473 | if (es->image == EGL_NO_IMAGE_KHR) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 474 | return -1; |
| 475 | |
| 476 | if (!drm_surface_transform_supported(es)) |
| 477 | return -1; |
| 478 | |
| 479 | if (!drm_surface_overlap_supported(output_base, overlap)) |
| 480 | return -1; |
| 481 | |
| 482 | wl_list_for_each(s, &c->sprite_list, link) { |
| 483 | if (!drm_sprite_crtc_supported(output_base, s->possible_crtcs)) |
| 484 | continue; |
| 485 | |
| 486 | if (!s->pending_fb_id) { |
| 487 | found = 1; |
| 488 | break; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* No sprites available */ |
| 493 | if (!found) |
| 494 | return -1; |
| 495 | |
| 496 | bo = gbm_bo_create_from_egl_image(c->gbm, c->base.display, es->image, |
| 497 | es->geometry.width, es->geometry.height, |
| 498 | GBM_BO_USE_SCANOUT); |
| 499 | format = gbm_bo_get_format(bo); |
| 500 | handle = gbm_bo_get_handle(bo).s32; |
| 501 | stride = gbm_bo_get_pitch(bo); |
| 502 | |
| 503 | gbm_bo_destroy(bo); |
| 504 | |
| 505 | if (!drm_surface_format_supported(s, format)) |
| 506 | return -1; |
| 507 | |
| 508 | if (!handle) |
| 509 | return -1; |
| 510 | |
| 511 | handles[0] = handle; |
| 512 | pitches[0] = stride; |
| 513 | offsets[0] = 0; |
| 514 | |
| 515 | ret = drmModeAddFB2(c->drm.fd, es->geometry.width, es->geometry.height, |
| 516 | format, handles, pitches, offsets, |
| 517 | &fb_id, 0); |
| 518 | if (ret) { |
| 519 | fprintf(stderr, "addfb2 failed: %d\n", ret); |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 520 | c->sprites_are_broken = 1; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 521 | return -1; |
| 522 | } |
| 523 | |
| 524 | if (s->surface && s->surface != es) { |
| 525 | struct weston_surface *old_surf = s->surface; |
| 526 | pixman_region32_fini(&old_surf->damage); |
| 527 | pixman_region32_init_rect(&old_surf->damage, |
| 528 | old_surf->geometry.x, old_surf->geometry.y, |
| 529 | old_surf->geometry.width, old_surf->geometry.height); |
| 530 | } |
| 531 | |
| 532 | s->pending_fb_id = fb_id; |
| 533 | s->pending_surface = es; |
| 534 | es->buffer->busy_count++; |
| 535 | |
| 536 | /* |
| 537 | * Calculate the source & dest rects properly based on actual |
| 538 | * postion (note the caller has called weston_surface_update_transform() |
| 539 | * for us already). |
| 540 | */ |
| 541 | pixman_region32_init(&dest_rect); |
| 542 | pixman_region32_intersect(&dest_rect, &es->transform.boundingbox, |
| 543 | &output_base->region); |
| 544 | pixman_region32_translate(&dest_rect, -output_base->x, -output_base->y); |
| 545 | box = pixman_region32_extents(&dest_rect); |
| 546 | s->dest_x = box->x1; |
| 547 | s->dest_y = box->y1; |
| 548 | s->dest_w = box->x2 - box->x1; |
| 549 | s->dest_h = box->y2 - box->y1; |
| 550 | pixman_region32_fini(&dest_rect); |
| 551 | |
| 552 | pixman_region32_init(&src_rect); |
| 553 | pixman_region32_intersect(&src_rect, &es->transform.boundingbox, |
| 554 | &output_base->region); |
| 555 | pixman_region32_translate(&src_rect, -es->geometry.x, -es->geometry.y); |
| 556 | box = pixman_region32_extents(&src_rect); |
Rob Clark | 3c97b90 | 2012-03-11 19:48:43 -0500 | [diff] [blame] | 557 | s->src_x = box->x1 << 16; |
| 558 | s->src_y = box->y1 << 16; |
| 559 | s->src_w = (box->x2 - box->x1) << 16; |
| 560 | s->src_h = (box->y2 - box->y1) << 16; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 561 | pixman_region32_fini(&src_rect); |
| 562 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 563 | wl_list_insert(es->buffer->resource.destroy_listener_list.prev, |
| 564 | &s->pending_destroy_listener.link); |
| 565 | return 0; |
| 566 | } |
| 567 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 568 | static int |
| 569 | drm_output_set_cursor(struct weston_output *output_base, |
| 570 | struct weston_input_device *eid); |
| 571 | |
| 572 | static void |
| 573 | weston_output_set_cursor(struct weston_output *output, |
| 574 | struct weston_input_device *device, |
| 575 | pixman_region32_t *overlap) |
| 576 | { |
| 577 | pixman_region32_t cursor_region; |
| 578 | int prior_was_hardware; |
| 579 | |
| 580 | if (device->sprite == NULL) |
| 581 | return; |
| 582 | |
| 583 | pixman_region32_init(&cursor_region); |
| 584 | pixman_region32_intersect(&cursor_region, |
| 585 | &device->sprite->transform.boundingbox, |
| 586 | &output->region); |
| 587 | |
| 588 | if (!pixman_region32_not_empty(&cursor_region)) { |
| 589 | drm_output_set_cursor(output, NULL); |
| 590 | goto out; |
| 591 | } |
| 592 | |
| 593 | prior_was_hardware = device->hw_cursor; |
| 594 | if (pixman_region32_not_empty(overlap) || |
| 595 | drm_output_set_cursor(output, device) < 0) { |
| 596 | if (prior_was_hardware) { |
| 597 | weston_surface_damage(device->sprite); |
| 598 | drm_output_set_cursor(output, NULL); |
| 599 | } |
| 600 | device->hw_cursor = 0; |
| 601 | } else { |
| 602 | if (!prior_was_hardware) |
| 603 | weston_surface_damage_below(device->sprite); |
| 604 | pixman_region32_fini(&device->sprite->damage); |
| 605 | pixman_region32_init(&device->sprite->damage); |
| 606 | device->hw_cursor = 1; |
| 607 | } |
| 608 | |
| 609 | out: |
| 610 | pixman_region32_fini(&cursor_region); |
| 611 | } |
| 612 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 613 | static void |
| 614 | drm_assign_planes(struct weston_output *output) |
| 615 | { |
| 616 | struct weston_compositor *ec = output->compositor; |
| 617 | struct weston_surface *es; |
| 618 | pixman_region32_t overlap, surface_overlap; |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 619 | struct weston_input_device *device; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 620 | |
| 621 | /* |
| 622 | * Find a surface for each sprite in the output using some heuristics: |
| 623 | * 1) size |
| 624 | * 2) frequency of update |
| 625 | * 3) opacity (though some hw might support alpha blending) |
| 626 | * 4) clipping (this can be fixed with color keys) |
| 627 | * |
| 628 | * The idea is to save on blitting since this should save power. |
| 629 | * If we can get a large video surface on the sprite for example, |
| 630 | * the main display surface may not need to update at all, and |
| 631 | * the client buffer can be used directly for the sprite surface |
| 632 | * as we do for flipping full screen surfaces. |
| 633 | */ |
| 634 | pixman_region32_init(&overlap); |
| 635 | wl_list_for_each(es, &ec->surface_list, link) { |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 636 | /* |
| 637 | * FIXME: try to assign hw cursors here too, they're just |
| 638 | * special overlays |
| 639 | */ |
| 640 | pixman_region32_init(&surface_overlap); |
| 641 | pixman_region32_intersect(&surface_overlap, &overlap, |
| 642 | &es->transform.boundingbox); |
| 643 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 644 | device = (struct weston_input_device *) ec->input_device; |
| 645 | if (es == device->sprite) { |
| 646 | weston_output_set_cursor(output, device, |
| 647 | &surface_overlap); |
| 648 | |
| 649 | if (!device->hw_cursor) |
| 650 | pixman_region32_union(&overlap, &overlap, |
| 651 | &es->transform.boundingbox); |
| 652 | } else if (!drm_output_prepare_overlay_surface(output, es, |
| 653 | &surface_overlap)) { |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 654 | pixman_region32_fini(&es->damage); |
| 655 | pixman_region32_init(&es->damage); |
| 656 | } else { |
| 657 | pixman_region32_union(&overlap, &overlap, |
| 658 | &es->transform.boundingbox); |
| 659 | } |
| 660 | pixman_region32_fini(&surface_overlap); |
| 661 | } |
| 662 | pixman_region32_fini(&overlap); |
| 663 | |
| 664 | drm_disable_unused_sprites(output); |
| 665 | } |
| 666 | |
| 667 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 668 | drm_output_set_cursor(struct weston_output *output_base, |
| 669 | struct weston_input_device *eid) |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 670 | { |
| 671 | struct drm_output *output = (struct drm_output *) output_base; |
| 672 | struct drm_compositor *c = |
| 673 | (struct drm_compositor *) output->base.compositor; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 674 | EGLint handle, stride; |
| 675 | int ret = -1; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 676 | struct gbm_bo *bo; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 677 | |
Kristian Høgsberg | e4c40a4 | 2011-05-06 14:04:21 -0400 | [diff] [blame] | 678 | if (eid == NULL) { |
| 679 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
| 680 | return 0; |
| 681 | } |
| 682 | |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 683 | if (eid->sprite->image == EGL_NO_IMAGE_KHR) |
| 684 | goto out; |
| 685 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 686 | if (eid->sprite->geometry.width > 64 || |
| 687 | eid->sprite->geometry.height > 64) |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 688 | goto out; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 689 | |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 690 | bo = gbm_bo_create_from_egl_image(c->gbm, |
| 691 | c->base.display, |
| 692 | eid->sprite->image, 64, 64, |
| 693 | GBM_BO_USE_CURSOR_64X64); |
Kristian Høgsberg | 6916d9c | 2012-01-18 15:11:07 -0500 | [diff] [blame] | 694 | /* Not suitable for hw cursor, fall back */ |
| 695 | if (bo == NULL) |
| 696 | goto out; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 697 | |
| 698 | handle = gbm_bo_get_handle(bo).s32; |
| 699 | stride = gbm_bo_get_pitch(bo); |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 700 | gbm_bo_destroy(bo); |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 701 | |
Kristian Høgsberg | 6916d9c | 2012-01-18 15:11:07 -0500 | [diff] [blame] | 702 | /* gbm_bo_create_from_egl_image() didn't always validate the usage |
| 703 | * flags, and in that case we might end up with a bad stride. */ |
| 704 | if (stride != 64 * 4) |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 705 | goto out; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 706 | |
| 707 | ret = drmModeSetCursor(c->drm.fd, output->crtc_id, handle, 64, 64); |
| 708 | if (ret) { |
| 709 | fprintf(stderr, "failed to set cursor: %s\n", strerror(-ret)); |
| 710 | goto out; |
| 711 | } |
| 712 | |
| 713 | ret = drmModeMoveCursor(c->drm.fd, output->crtc_id, |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 714 | eid->sprite->geometry.x - output->base.x, |
| 715 | eid->sprite->geometry.y - output->base.y); |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 716 | if (ret) { |
| 717 | fprintf(stderr, "failed to move cursor: %s\n", strerror(-ret)); |
| 718 | goto out; |
| 719 | } |
| 720 | |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 721 | out: |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 722 | if (ret) |
| 723 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
| 724 | return ret; |
| 725 | } |
| 726 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 727 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 728 | drm_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 729 | { |
| 730 | struct drm_output *output = (struct drm_output *) output_base; |
| 731 | struct drm_compositor *c = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 732 | (struct drm_compositor *) output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 733 | drmModeCrtcPtr origcrtc = output->original_crtc; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 734 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 735 | if (output->backlight) |
| 736 | backlight_destroy(output->backlight); |
| 737 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 738 | /* Turn off hardware cursor */ |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 739 | drm_output_set_cursor(&output->base, NULL); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 740 | |
| 741 | /* Restore original CRTC state */ |
| 742 | drmModeSetCrtc(c->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id, |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 743 | origcrtc->x, origcrtc->y, |
| 744 | &output->connector_id, 1, &origcrtc->mode); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 745 | drmModeFreeCrtc(origcrtc); |
| 746 | |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 747 | c->crtc_allocator &= ~(1 << output->crtc_id); |
| 748 | c->connector_allocator &= ~(1 << output->connector_id); |
| 749 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 750 | eglDestroySurface(c->base.display, output->egl_surface); |
| 751 | gbm_surface_destroy(output->surface); |
| 752 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 753 | weston_output_destroy(&output->base); |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 754 | wl_list_remove(&output->base.link); |
| 755 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 756 | free(output); |
| 757 | } |
| 758 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 759 | static int |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 760 | on_drm_input(int fd, uint32_t mask, void *data) |
| 761 | { |
| 762 | drmEventContext evctx; |
| 763 | |
| 764 | memset(&evctx, 0, sizeof evctx); |
| 765 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 766 | evctx.page_flip_handler = page_flip_handler; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 767 | evctx.vblank_handler = vblank_handler; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 768 | drmHandleEvent(fd, &evctx); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 769 | |
| 770 | return 1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 774 | init_egl(struct drm_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 775 | { |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 776 | EGLint major, minor, n; |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 777 | const char *filename, *sysnum; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 778 | int fd; |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 779 | static const EGLint context_attribs[] = { |
| 780 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 781 | EGL_NONE |
| 782 | }; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 783 | |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 784 | sysnum = udev_device_get_sysnum(device); |
| 785 | if (sysnum) |
| 786 | ec->drm.id = atoi(sysnum); |
| 787 | if (!sysnum || ec->drm.id < 0) { |
| 788 | fprintf(stderr, "cannot get device sysnum\n"); |
| 789 | return -1; |
| 790 | } |
| 791 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 792 | static const EGLint config_attribs[] = { |
| 793 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 794 | EGL_RED_SIZE, 1, |
| 795 | EGL_GREEN_SIZE, 1, |
| 796 | EGL_BLUE_SIZE, 1, |
| 797 | EGL_ALPHA_SIZE, 0, |
| 798 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 799 | EGL_NONE |
| 800 | }; |
| 801 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 802 | filename = udev_device_get_devnode(device); |
David Herrmann | 63ff706 | 2011-11-05 18:46:01 +0100 | [diff] [blame] | 803 | fd = open(filename, O_RDWR | O_CLOEXEC); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 804 | if (fd < 0) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 805 | /* Probably permissions error */ |
| 806 | fprintf(stderr, "couldn't open %s, skipping\n", |
| 807 | udev_device_get_devnode(device)); |
| 808 | return -1; |
| 809 | } |
| 810 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 811 | ec->drm.fd = fd; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 812 | ec->gbm = gbm_create_device(ec->drm.fd); |
| 813 | ec->base.display = eglGetDisplay(ec->gbm); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 814 | if (ec->base.display == NULL) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 815 | fprintf(stderr, "failed to create display\n"); |
| 816 | return -1; |
| 817 | } |
| 818 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 819 | if (!eglInitialize(ec->base.display, &major, &minor)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 820 | fprintf(stderr, "failed to initialize display\n"); |
| 821 | return -1; |
| 822 | } |
| 823 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 824 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
| 825 | fprintf(stderr, "failed to bind api EGL_OPENGL_ES_API\n"); |
| 826 | return -1; |
| 827 | } |
| 828 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 829 | if (!eglChooseConfig(ec->base.display, config_attribs, |
| 830 | &ec->base.config, 1, &n) || n != 1) { |
| 831 | fprintf(stderr, "failed to choose config: %d\n", n); |
| 832 | return -1; |
| 833 | } |
| 834 | |
| 835 | ec->base.context = eglCreateContext(ec->base.display, ec->base.config, |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 836 | EGL_NO_CONTEXT, context_attribs); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 837 | if (ec->base.context == NULL) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 838 | fprintf(stderr, "failed to create context\n"); |
| 839 | return -1; |
| 840 | } |
| 841 | |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 842 | ec->dummy_surface = gbm_surface_create(ec->gbm, 10, 10, |
| 843 | GBM_FORMAT_XRGB8888, |
| 844 | GBM_BO_USE_RENDERING); |
| 845 | if (!ec->dummy_surface) { |
| 846 | fprintf(stderr, "failed to create dummy gbm surface\n"); |
| 847 | return -1; |
| 848 | } |
| 849 | |
| 850 | ec->dummy_egl_surface = |
| 851 | eglCreateWindowSurface(ec->base.display, ec->base.config, |
| 852 | ec->dummy_surface, NULL); |
| 853 | if (ec->dummy_egl_surface == EGL_NO_SURFACE) { |
| 854 | fprintf(stderr, "failed to create egl surface\n"); |
| 855 | return -1; |
| 856 | } |
| 857 | |
| 858 | if (!eglMakeCurrent(ec->base.display, ec->dummy_egl_surface, |
| 859 | ec->dummy_egl_surface, ec->base.context)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 860 | fprintf(stderr, "failed to make context current\n"); |
| 861 | return -1; |
| 862 | } |
| 863 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | static drmModeModeInfo builtin_1024x768 = { |
| 868 | 63500, /* clock */ |
| 869 | 1024, 1072, 1176, 1328, 0, |
| 870 | 768, 771, 775, 798, 0, |
| 871 | 59920, |
| 872 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, |
| 873 | 0, |
| 874 | "1024x768" |
| 875 | }; |
| 876 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 877 | |
| 878 | static int |
| 879 | drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info) |
| 880 | { |
| 881 | struct drm_mode *mode; |
| 882 | |
| 883 | mode = malloc(sizeof *mode); |
| 884 | if (mode == NULL) |
| 885 | return -1; |
| 886 | |
| 887 | mode->base.flags = 0; |
| 888 | mode->base.width = info->hdisplay; |
| 889 | mode->base.height = info->vdisplay; |
| 890 | mode->base.refresh = info->vrefresh; |
| 891 | mode->mode_info = *info; |
| 892 | wl_list_insert(output->base.mode_list.prev, &mode->base.link); |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | static int |
| 898 | drm_subpixel_to_wayland(int drm_value) |
| 899 | { |
| 900 | switch (drm_value) { |
| 901 | default: |
| 902 | case DRM_MODE_SUBPIXEL_UNKNOWN: |
| 903 | return WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 904 | case DRM_MODE_SUBPIXEL_NONE: |
| 905 | return WL_OUTPUT_SUBPIXEL_NONE; |
| 906 | case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB: |
| 907 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB; |
| 908 | case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR: |
| 909 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR; |
| 910 | case DRM_MODE_SUBPIXEL_VERTICAL_RGB: |
| 911 | return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB; |
| 912 | case DRM_MODE_SUBPIXEL_VERTICAL_BGR: |
| 913 | return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR; |
| 914 | } |
| 915 | } |
| 916 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 917 | static void |
| 918 | output_handle_scanout_buffer_destroy(struct wl_listener *listener, |
| 919 | struct wl_resource *resource, |
| 920 | uint32_t time) |
| 921 | { |
| 922 | struct drm_output *output = |
| 923 | container_of(listener, struct drm_output, |
| 924 | scanout_buffer_destroy_listener); |
| 925 | |
| 926 | output->scanout_buffer = NULL; |
| 927 | |
| 928 | if (!output->pending_scanout_buffer) |
| 929 | weston_compositor_schedule_repaint(output->base.compositor); |
| 930 | } |
| 931 | |
| 932 | static void |
| 933 | output_handle_pending_scanout_buffer_destroy(struct wl_listener *listener, |
| 934 | struct wl_resource *resource, |
| 935 | uint32_t time) |
| 936 | { |
| 937 | struct drm_output *output = |
| 938 | container_of(listener, struct drm_output, |
| 939 | pending_scanout_buffer_destroy_listener); |
| 940 | |
| 941 | output->pending_scanout_buffer = NULL; |
| 942 | |
| 943 | weston_compositor_schedule_repaint(output->base.compositor); |
| 944 | } |
| 945 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 946 | static void |
| 947 | sprite_handle_buffer_destroy(struct wl_listener *listener, |
| 948 | struct wl_resource *resource, |
| 949 | uint32_t time) |
| 950 | { |
| 951 | struct drm_sprite *sprite = |
| 952 | container_of(listener, struct drm_sprite, |
| 953 | destroy_listener); |
| 954 | |
| 955 | sprite->surface = NULL; |
| 956 | } |
| 957 | |
| 958 | static void |
| 959 | sprite_handle_pending_buffer_destroy(struct wl_listener *listener, |
| 960 | struct wl_resource *resource, |
| 961 | uint32_t time) |
| 962 | { |
| 963 | struct drm_sprite *sprite = |
| 964 | container_of(listener, struct drm_sprite, |
| 965 | pending_destroy_listener); |
| 966 | |
| 967 | sprite->pending_surface = NULL; |
| 968 | } |
| 969 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 970 | /* returns a value between 0-255 range, where higher is brighter */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 971 | static uint32_t |
| 972 | drm_get_backlight(struct drm_output *output) |
| 973 | { |
| 974 | long brightness, max_brightness, norm; |
| 975 | |
| 976 | brightness = backlight_get_brightness(output->backlight); |
| 977 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 978 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 979 | /* convert it on a scale of 0 to 255 */ |
| 980 | norm = (brightness * 255)/(max_brightness); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 981 | |
| 982 | return (uint32_t) norm; |
| 983 | } |
| 984 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 985 | /* values accepted are between 0-255 range */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 986 | static void |
| 987 | drm_set_backlight(struct weston_output *output_base, uint32_t value) |
| 988 | { |
| 989 | struct drm_output *output = (struct drm_output *) output_base; |
| 990 | long max_brightness, new_brightness; |
| 991 | |
| 992 | if (!output->backlight) |
| 993 | return; |
| 994 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 995 | if (value > 255) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 996 | return; |
| 997 | |
| 998 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 999 | |
| 1000 | /* get denormalized value */ |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1001 | new_brightness = (value * max_brightness) / 255; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1002 | |
| 1003 | backlight_set_brightness(output->backlight, new_brightness); |
| 1004 | } |
| 1005 | |
| 1006 | static drmModePropertyPtr |
| 1007 | drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name) |
| 1008 | { |
| 1009 | drmModePropertyPtr props; |
| 1010 | int i; |
| 1011 | |
| 1012 | for (i = 0; i < connector->count_props; i++) { |
| 1013 | props = drmModeGetProperty(fd, connector->props[i]); |
| 1014 | if (!props) |
| 1015 | continue; |
| 1016 | |
| 1017 | if (!strcmp(props->name, name)) |
| 1018 | return props; |
| 1019 | |
| 1020 | drmModeFreeProperty(props); |
| 1021 | } |
| 1022 | |
| 1023 | return NULL; |
| 1024 | } |
| 1025 | |
| 1026 | static void |
| 1027 | drm_set_dpms(struct weston_output *output_base, enum dpms_enum level) |
| 1028 | { |
| 1029 | struct drm_output *output = (struct drm_output *) output_base; |
| 1030 | struct weston_compositor *ec = output_base->compositor; |
| 1031 | struct drm_compositor *c = (struct drm_compositor *) ec; |
| 1032 | drmModeConnectorPtr connector; |
| 1033 | drmModePropertyPtr prop; |
| 1034 | |
| 1035 | connector = drmModeGetConnector(c->drm.fd, output->connector_id); |
| 1036 | if (!connector) |
| 1037 | return; |
| 1038 | |
| 1039 | prop = drm_get_prop(c->drm.fd, connector, "DPMS"); |
| 1040 | if (!prop) { |
| 1041 | drmModeFreeConnector(connector); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | drmModeConnectorSetProperty(c->drm.fd, connector->connector_id, |
| 1046 | prop->prop_id, level); |
| 1047 | drmModeFreeProperty(prop); |
| 1048 | drmModeFreeConnector(connector); |
| 1049 | } |
| 1050 | |
Scott Moreau | 80d27b7 | 2012-04-04 11:49:21 -0600 | [diff] [blame] | 1051 | static void |
| 1052 | drm_output_read_pixels(struct weston_output *output_base, void *data) |
| 1053 | { |
| 1054 | struct drm_output *output = (struct drm_output *) output_base; |
| 1055 | struct drm_compositor *compositor = |
| 1056 | (struct drm_compositor *) output->base.compositor; |
| 1057 | |
| 1058 | eglMakeCurrent(compositor->base.display, output->egl_surface, |
| 1059 | output->egl_surface, compositor->base.context); |
| 1060 | |
| 1061 | glReadPixels(0, 0, output_base->current->width, output_base->current->height, |
| 1062 | GL_BGRA_EXT, GL_UNSIGNED_BYTE, data); |
| 1063 | } |
| 1064 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1065 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1066 | create_output_for_connector(struct drm_compositor *ec, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1067 | drmModeRes *resources, |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1068 | drmModeConnector *connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1069 | int x, int y, struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1070 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1071 | struct drm_output *output; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1072 | struct drm_mode *drm_mode, *next; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1073 | drmModeEncoder *encoder; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1074 | int i, ret; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1075 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1076 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[0]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1077 | if (encoder == NULL) { |
| 1078 | fprintf(stderr, "No encoder for connector.\n"); |
| 1079 | return -1; |
| 1080 | } |
| 1081 | |
| 1082 | for (i = 0; i < resources->count_crtcs; i++) { |
Marty Jack | 13d9db2 | 2011-02-09 19:01:42 -0500 | [diff] [blame] | 1083 | if (encoder->possible_crtcs & (1 << i) && |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1084 | !(ec->crtc_allocator & (1 << resources->crtcs[i]))) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1085 | break; |
| 1086 | } |
| 1087 | if (i == resources->count_crtcs) { |
| 1088 | fprintf(stderr, "No usable crtc for encoder.\n"); |
David Herrmann | eb8bed5 | 2011-12-08 17:05:44 +0100 | [diff] [blame] | 1089 | drmModeFreeEncoder(encoder); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1090 | return -1; |
| 1091 | } |
| 1092 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1093 | output = malloc(sizeof *output); |
David Herrmann | eb8bed5 | 2011-12-08 17:05:44 +0100 | [diff] [blame] | 1094 | if (output == NULL) { |
| 1095 | drmModeFreeEncoder(encoder); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1096 | return -1; |
David Herrmann | eb8bed5 | 2011-12-08 17:05:44 +0100 | [diff] [blame] | 1097 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1098 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1099 | memset(output, 0, sizeof *output); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1100 | output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel); |
| 1101 | output->base.make = "unknown"; |
| 1102 | output->base.model = "unknown"; |
| 1103 | wl_list_init(&output->base.mode_list); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1104 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1105 | output->crtc_id = resources->crtcs[i]; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1106 | ec->crtc_allocator |= (1 << output->crtc_id); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1107 | output->connector_id = connector->connector_id; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1108 | ec->connector_allocator |= (1 << output->connector_id); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1109 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1110 | output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1111 | drmModeFreeEncoder(encoder); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1112 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1113 | for (i = 0; i < connector->count_modes; i++) { |
| 1114 | ret = drm_output_add_mode(output, &connector->modes[i]); |
| 1115 | if (ret) |
| 1116 | goto err_free; |
| 1117 | } |
| 1118 | |
| 1119 | if (connector->count_modes == 0) { |
| 1120 | ret = drm_output_add_mode(output, &builtin_1024x768); |
| 1121 | if (ret) |
| 1122 | goto err_free; |
| 1123 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1124 | |
| 1125 | drm_mode = container_of(output->base.mode_list.next, |
| 1126 | struct drm_mode, base.link); |
| 1127 | output->base.current = &drm_mode->base; |
| 1128 | drm_mode->base.flags = |
| 1129 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 1130 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1131 | output->surface = gbm_surface_create(ec->gbm, |
| 1132 | output->base.current->width, |
| 1133 | output->base.current->height, |
| 1134 | GBM_FORMAT_XRGB8888, |
| 1135 | GBM_BO_USE_SCANOUT | |
| 1136 | GBM_BO_USE_RENDERING); |
| 1137 | if (!output->surface) { |
| 1138 | fprintf(stderr, "failed to create gbm surface\n"); |
| 1139 | goto err_free; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1142 | output->egl_surface = |
| 1143 | eglCreateWindowSurface(ec->base.display, ec->base.config, |
| 1144 | output->surface, NULL); |
| 1145 | if (output->egl_surface == EGL_NO_SURFACE) { |
| 1146 | fprintf(stderr, "failed to create egl surface\n"); |
| 1147 | goto err_surface; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1150 | output->backlight = backlight_init(drm_device, |
| 1151 | connector->connector_type); |
| 1152 | if (output->backlight) { |
| 1153 | output->base.set_backlight = drm_set_backlight; |
| 1154 | output->base.backlight_current = drm_get_backlight(output); |
| 1155 | } |
| 1156 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1157 | weston_output_init(&output->base, &ec->base, x, y, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1158 | connector->mmWidth, connector->mmHeight, |
| 1159 | WL_OUTPUT_FLIPPED); |
Kristian Høgsberg | a4b7e20 | 2011-10-24 13:26:32 -0400 | [diff] [blame] | 1160 | |
| 1161 | wl_list_insert(ec->base.output_list.prev, &output->base.link); |
| 1162 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 1163 | output->scanout_buffer_destroy_listener.func = |
| 1164 | output_handle_scanout_buffer_destroy; |
| 1165 | output->pending_scanout_buffer_destroy_listener.func = |
| 1166 | output_handle_pending_scanout_buffer_destroy; |
| 1167 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1168 | output->next_fb_id = 0; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 1169 | output->base.repaint = drm_output_repaint; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1170 | output->base.destroy = drm_output_destroy; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1171 | output->base.assign_planes = drm_assign_planes; |
Scott Moreau | 80d27b7 | 2012-04-04 11:49:21 -0600 | [diff] [blame] | 1172 | output->base.read_pixels = drm_output_read_pixels; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1173 | output->base.set_dpms = drm_set_dpms; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1174 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1175 | return 0; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1176 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1177 | eglDestroySurface(ec->base.display, output->egl_surface); |
| 1178 | err_surface: |
| 1179 | gbm_surface_destroy(output->surface); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1180 | err_free: |
| 1181 | wl_list_for_each_safe(drm_mode, next, &output->base.mode_list, |
| 1182 | base.link) { |
| 1183 | wl_list_remove(&drm_mode->base.link); |
| 1184 | free(drm_mode); |
| 1185 | } |
| 1186 | |
| 1187 | drmModeFreeCrtc(output->original_crtc); |
| 1188 | ec->crtc_allocator &= ~(1 << output->crtc_id); |
| 1189 | ec->connector_allocator &= ~(1 << output->connector_id); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1190 | free(output); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1191 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1192 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1195 | static void |
| 1196 | create_sprites(struct drm_compositor *ec) |
| 1197 | { |
| 1198 | struct drm_sprite *sprite; |
| 1199 | drmModePlaneRes *plane_res; |
| 1200 | drmModePlane *plane; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1201 | uint32_t i; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1202 | |
| 1203 | plane_res = drmModeGetPlaneResources(ec->drm.fd); |
| 1204 | if (!plane_res) { |
| 1205 | fprintf(stderr, "failed to get plane resources: %s\n", |
| 1206 | strerror(errno)); |
| 1207 | return; |
| 1208 | } |
| 1209 | |
| 1210 | for (i = 0; i < plane_res->count_planes; i++) { |
| 1211 | plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]); |
| 1212 | if (!plane) |
| 1213 | continue; |
| 1214 | |
| 1215 | sprite = malloc(sizeof(*sprite) + ((sizeof(uint32_t)) * |
| 1216 | plane->count_formats)); |
| 1217 | if (!sprite) { |
| 1218 | fprintf(stderr, "%s: out of memory\n", |
| 1219 | __func__); |
| 1220 | free(plane); |
| 1221 | continue; |
| 1222 | } |
| 1223 | |
| 1224 | memset(sprite, 0, sizeof *sprite); |
| 1225 | |
| 1226 | sprite->possible_crtcs = plane->possible_crtcs; |
| 1227 | sprite->plane_id = plane->plane_id; |
| 1228 | sprite->surface = NULL; |
| 1229 | sprite->pending_surface = NULL; |
| 1230 | sprite->fb_id = 0; |
| 1231 | sprite->pending_fb_id = 0; |
| 1232 | sprite->destroy_listener.func = sprite_handle_buffer_destroy; |
| 1233 | sprite->pending_destroy_listener.func = |
| 1234 | sprite_handle_pending_buffer_destroy; |
| 1235 | sprite->compositor = ec; |
| 1236 | sprite->count_formats = plane->count_formats; |
| 1237 | memcpy(sprite->formats, plane->formats, |
Rob Clark | 8efbc8e | 2012-03-11 19:48:44 -0500 | [diff] [blame] | 1238 | plane->count_formats * sizeof(plane->formats[0])); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1239 | drmModeFreePlane(plane); |
| 1240 | |
| 1241 | wl_list_insert(&ec->sprite_list, &sprite->link); |
| 1242 | } |
| 1243 | |
| 1244 | free(plane_res->planes); |
| 1245 | free(plane_res); |
| 1246 | } |
| 1247 | |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1248 | static void |
| 1249 | destroy_sprites(struct drm_compositor *compositor) |
| 1250 | { |
| 1251 | struct drm_sprite *sprite, *next; |
| 1252 | struct drm_output *output; |
| 1253 | |
| 1254 | output = container_of(compositor->base.output_list.next, |
| 1255 | struct drm_output, base.link); |
| 1256 | |
| 1257 | wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) { |
| 1258 | drmModeSetPlane(compositor->drm.fd, |
| 1259 | sprite->plane_id, |
| 1260 | output->crtc_id, 0, 0, |
| 1261 | 0, 0, 0, 0, 0, 0, 0, 0); |
| 1262 | drmModeRmFB(compositor->drm.fd, sprite->fb_id); |
| 1263 | free(sprite); |
| 1264 | } |
| 1265 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1266 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1267 | static int |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1268 | create_outputs(struct drm_compositor *ec, uint32_t option_connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1269 | struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1270 | { |
| 1271 | drmModeConnector *connector; |
| 1272 | drmModeRes *resources; |
| 1273 | int i; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1274 | int x = 0, y = 0; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1275 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1276 | resources = drmModeGetResources(ec->drm.fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1277 | if (!resources) { |
| 1278 | fprintf(stderr, "drmModeGetResources failed\n"); |
| 1279 | return -1; |
| 1280 | } |
| 1281 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1282 | ec->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t)); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 1283 | if (!ec->crtcs) { |
| 1284 | drmModeFreeResources(resources); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1285 | return -1; |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 1286 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1287 | |
| 1288 | ec->num_crtcs = resources->count_crtcs; |
| 1289 | memcpy(ec->crtcs, resources->crtcs, sizeof(uint32_t) * ec->num_crtcs); |
| 1290 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1291 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1292 | connector = drmModeGetConnector(ec->drm.fd, |
| 1293 | resources->connectors[i]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1294 | if (connector == NULL) |
| 1295 | continue; |
| 1296 | |
| 1297 | if (connector->connection == DRM_MODE_CONNECTED && |
| 1298 | (option_connector == 0 || |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 1299 | connector->connector_id == option_connector)) { |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1300 | if (create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1301 | connector, x, y, |
| 1302 | drm_device) < 0) { |
Benjamin Franzke | 439d986 | 2011-10-07 08:20:53 +0200 | [diff] [blame] | 1303 | drmModeFreeConnector(connector); |
| 1304 | continue; |
| 1305 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1306 | |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 1307 | x += container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1308 | struct weston_output, |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 1309 | link)->current->width; |
| 1310 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1311 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1312 | drmModeFreeConnector(connector); |
| 1313 | } |
| 1314 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1315 | if (wl_list_empty(&ec->base.output_list)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1316 | fprintf(stderr, "No currently active connector found.\n"); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 1317 | drmModeFreeResources(resources); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1318 | return -1; |
| 1319 | } |
| 1320 | |
| 1321 | drmModeFreeResources(resources); |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1326 | static void |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1327 | update_outputs(struct drm_compositor *ec, struct udev_device *drm_device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1328 | { |
| 1329 | drmModeConnector *connector; |
| 1330 | drmModeRes *resources; |
| 1331 | struct drm_output *output, *next; |
| 1332 | int x = 0, y = 0; |
| 1333 | int x_offset = 0, y_offset = 0; |
| 1334 | uint32_t connected = 0, disconnects = 0; |
| 1335 | int i; |
| 1336 | |
| 1337 | resources = drmModeGetResources(ec->drm.fd); |
| 1338 | if (!resources) { |
| 1339 | fprintf(stderr, "drmModeGetResources failed\n"); |
| 1340 | return; |
| 1341 | } |
| 1342 | |
| 1343 | /* collect new connects */ |
| 1344 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1345 | int connector_id = resources->connectors[i]; |
| 1346 | |
| 1347 | connector = drmModeGetConnector(ec->drm.fd, connector_id); |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 1348 | if (connector == NULL) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1349 | continue; |
| 1350 | |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 1351 | if (connector->connection != DRM_MODE_CONNECTED) { |
| 1352 | drmModeFreeConnector(connector); |
| 1353 | continue; |
| 1354 | } |
| 1355 | |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1356 | connected |= (1 << connector_id); |
| 1357 | |
| 1358 | if (!(ec->connector_allocator & (1 << connector_id))) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1359 | struct weston_output *last = |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1360 | container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1361 | struct weston_output, link); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1362 | |
| 1363 | /* XXX: not yet needed, we die with 0 outputs */ |
| 1364 | if (!wl_list_empty(&ec->base.output_list)) |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1365 | x = last->x + last->current->width; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1366 | else |
| 1367 | x = 0; |
| 1368 | y = 0; |
| 1369 | create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1370 | connector, x, y, |
| 1371 | drm_device); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1372 | printf("connector %d connected\n", connector_id); |
| 1373 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1374 | } |
| 1375 | drmModeFreeConnector(connector); |
| 1376 | } |
| 1377 | drmModeFreeResources(resources); |
| 1378 | |
| 1379 | disconnects = ec->connector_allocator & ~connected; |
| 1380 | if (disconnects) { |
| 1381 | wl_list_for_each_safe(output, next, &ec->base.output_list, |
| 1382 | base.link) { |
| 1383 | if (x_offset != 0 || y_offset != 0) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1384 | weston_output_move(&output->base, |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1385 | output->base.x - x_offset, |
| 1386 | output->base.y - y_offset); |
| 1387 | } |
| 1388 | |
| 1389 | if (disconnects & (1 << output->connector_id)) { |
| 1390 | disconnects &= ~(1 << output->connector_id); |
| 1391 | printf("connector %d disconnected\n", |
| 1392 | output->connector_id); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1393 | x_offset += output->base.current->width; |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 1394 | drm_output_destroy(&output->base); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | /* FIXME: handle zero outputs, without terminating */ |
| 1400 | if (ec->connector_allocator == 0) |
| 1401 | wl_display_terminate(ec->base.wl_display); |
| 1402 | } |
| 1403 | |
| 1404 | static int |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1405 | udev_event_is_hotplug(struct drm_compositor *ec, struct udev_device *device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1406 | { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1407 | const char *sysnum; |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 1408 | const char *val; |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1409 | |
| 1410 | sysnum = udev_device_get_sysnum(device); |
| 1411 | if (!sysnum || atoi(sysnum) != ec->drm.id) |
| 1412 | return 0; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1413 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 1414 | val = udev_device_get_property_value(device, "HOTPLUG"); |
| 1415 | if (!val) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1416 | return 0; |
| 1417 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 1418 | return strcmp(val, "1") == 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1419 | } |
| 1420 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1421 | static int |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1422 | udev_drm_event(int fd, uint32_t mask, void *data) |
| 1423 | { |
| 1424 | struct drm_compositor *ec = data; |
| 1425 | struct udev_device *event; |
| 1426 | |
| 1427 | event = udev_monitor_receive_device(ec->udev_monitor); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1428 | |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1429 | if (udev_event_is_hotplug(ec, event)) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1430 | update_outputs(ec, event); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1431 | |
| 1432 | udev_device_unref(event); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1433 | |
| 1434 | return 1; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1437 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1438 | drm_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1439 | { |
| 1440 | struct drm_compositor *d = (struct drm_compositor *) ec; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1441 | struct weston_input_device *input, *next; |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1442 | |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 1443 | wl_list_for_each_safe(input, next, &ec->input_device_list, link) |
| 1444 | evdev_input_destroy(input); |
| 1445 | |
| 1446 | wl_event_source_remove(d->udev_drm_source); |
| 1447 | wl_event_source_remove(d->drm_source); |
| 1448 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1449 | weston_compositor_shutdown(ec); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 1450 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1451 | gbm_device_destroy(d->gbm); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1452 | destroy_sprites(d); |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 1453 | if (weston_launcher_drm_set_master(&d->base, d->drm.fd, 0) < 0) |
| 1454 | fprintf(stderr, "failed to drop master: %m\n"); |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 1455 | tty_destroy(d->tty); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1456 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 1457 | free(d); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1458 | } |
| 1459 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1460 | static void |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 1461 | drm_compositor_set_modes(struct drm_compositor *compositor) |
| 1462 | { |
| 1463 | struct drm_output *output; |
| 1464 | struct drm_mode *drm_mode; |
| 1465 | int ret; |
| 1466 | |
| 1467 | wl_list_for_each(output, &compositor->base.output_list, base.link) { |
| 1468 | drm_mode = (struct drm_mode *) output->base.current; |
| 1469 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1470 | output->current_fb_id, 0, 0, |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 1471 | &output->connector_id, 1, |
| 1472 | &drm_mode->mode_info); |
| 1473 | if (ret < 0) { |
| 1474 | fprintf(stderr, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1475 | "failed to set mode %dx%d for output at %d,%d: %m\n", |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 1476 | drm_mode->base.width, drm_mode->base.height, |
| 1477 | output->base.x, output->base.y); |
| 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1483 | vt_func(struct weston_compositor *compositor, int event) |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1484 | { |
| 1485 | struct drm_compositor *ec = (struct drm_compositor *) compositor; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1486 | struct weston_output *output; |
| 1487 | struct weston_input_device *input; |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1488 | struct drm_sprite *sprite; |
| 1489 | struct drm_output *drm_output; |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1490 | |
| 1491 | switch (event) { |
| 1492 | case TTY_ENTER_VT: |
| 1493 | compositor->focus = 1; |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 1494 | if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 1)) { |
Kristian Høgsberg | a018fb0 | 2012-01-16 10:52:52 -0500 | [diff] [blame] | 1495 | fprintf(stderr, "failed to set master: %m\n"); |
| 1496 | wl_display_terminate(compositor->wl_display); |
| 1497 | } |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1498 | compositor->state = ec->prev_state; |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 1499 | drm_compositor_set_modes(ec); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1500 | weston_compositor_damage_all(compositor); |
Benjamin Franzke | 78d3afe | 2012-04-09 18:14:58 +0200 | [diff] [blame] | 1501 | wl_list_for_each(input, &compositor->input_device_list, link) { |
Tiago Vignatti | 6e2d5f1 | 2011-12-19 00:32:48 +0200 | [diff] [blame] | 1502 | evdev_add_devices(ec->udev, input); |
Benjamin Franzke | 78d3afe | 2012-04-09 18:14:58 +0200 | [diff] [blame] | 1503 | evdev_enable_udev_monitor(ec->udev, input); |
| 1504 | } |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1505 | break; |
| 1506 | case TTY_LEAVE_VT: |
Kristian Høgsberg | 4014a6b | 2012-04-10 00:08:45 -0400 | [diff] [blame^] | 1507 | wl_list_for_each(input, &compositor->input_device_list, link) { |
| 1508 | evdev_disable_udev_monitor(input); |
| 1509 | evdev_remove_devices(input); |
| 1510 | } |
| 1511 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1512 | compositor->focus = 0; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1513 | ec->prev_state = compositor->state; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1514 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
Kristian Høgsberg | d8e181b | 2011-05-06 15:38:28 -0400 | [diff] [blame] | 1515 | |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 1516 | /* If we have a repaint scheduled (either from a |
| 1517 | * pending pageflip or the idle handler), make sure we |
| 1518 | * cancel that so we don't try to pageflip when we're |
| 1519 | * vt switched away. The SLEEPING state will prevent |
| 1520 | * further attemps at repainting. When we switch |
| 1521 | * back, we schedule a repaint, which will process |
| 1522 | * pending frame callbacks. */ |
| 1523 | |
| 1524 | wl_list_for_each(output, &ec->base.output_list, link) { |
| 1525 | output->repaint_needed = 0; |
| 1526 | drm_output_set_cursor(output, NULL); |
| 1527 | } |
| 1528 | |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1529 | drm_output = container_of(ec->base.output_list.next, |
| 1530 | struct drm_output, base.link); |
| 1531 | |
| 1532 | wl_list_for_each(sprite, &ec->sprite_list, link) |
| 1533 | drmModeSetPlane(ec->drm.fd, |
| 1534 | sprite->plane_id, |
| 1535 | drm_output->crtc_id, 0, 0, |
| 1536 | 0, 0, 0, 0, 0, 0, 0, 0); |
| 1537 | |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 1538 | if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 0) < 0) |
Kristian Høgsberg | a018fb0 | 2012-01-16 10:52:52 -0500 | [diff] [blame] | 1539 | fprintf(stderr, "failed to drop master: %m\n"); |
| 1540 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1541 | break; |
| 1542 | }; |
| 1543 | } |
| 1544 | |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1545 | static const char default_seat[] = "seat0"; |
| 1546 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1547 | static struct weston_compositor * |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1548 | drm_compositor_create(struct wl_display *display, |
Tiago Vignatti | faee801 | 2011-09-01 15:58:17 -0400 | [diff] [blame] | 1549 | int connector, const char *seat, int tty) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1550 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1551 | struct drm_compositor *ec; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1552 | struct udev_enumerate *e; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1553 | struct udev_list_entry *entry; |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1554 | struct udev_device *device, *drm_device; |
| 1555 | const char *path, *device_seat; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1556 | struct wl_event_loop *loop; |
| 1557 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1558 | ec = malloc(sizeof *ec); |
| 1559 | if (ec == NULL) |
| 1560 | return NULL; |
| 1561 | |
| 1562 | memset(ec, 0, sizeof *ec); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1563 | ec->udev = udev_new(); |
| 1564 | if (ec->udev == NULL) { |
| 1565 | fprintf(stderr, "failed to initialize udev context\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1566 | return NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1567 | } |
| 1568 | |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 1569 | ec->base.wl_display = display; |
| 1570 | ec->tty = tty_create(&ec->base, vt_func, tty); |
| 1571 | if (!ec->tty) { |
| 1572 | fprintf(stderr, "failed to initialize tty\n"); |
| 1573 | free(ec); |
| 1574 | return NULL; |
| 1575 | } |
| 1576 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1577 | e = udev_enumerate_new(ec->udev); |
| 1578 | udev_enumerate_add_match_subsystem(e, "drm"); |
Benjamin Franzke | a764ee5 | 2011-10-07 08:23:22 +0200 | [diff] [blame] | 1579 | udev_enumerate_add_match_sysname(e, "card[0-9]*"); |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1580 | |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1581 | udev_enumerate_scan_devices(e); |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1582 | drm_device = NULL; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1583 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1584 | path = udev_list_entry_get_name(entry); |
| 1585 | device = udev_device_new_from_syspath(ec->udev, path); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1586 | device_seat = |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1587 | udev_device_get_property_value(device, "ID_SEAT"); |
| 1588 | if (!device_seat) |
| 1589 | device_seat = default_seat; |
| 1590 | if (strcmp(device_seat, seat) == 0) { |
| 1591 | drm_device = device; |
| 1592 | break; |
| 1593 | } |
| 1594 | udev_device_unref(device); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1595 | } |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1596 | |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1597 | if (drm_device == NULL) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1598 | fprintf(stderr, "no drm device found\n"); |
| 1599 | return NULL; |
| 1600 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1601 | |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 1602 | if (init_egl(ec, drm_device) < 0) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1603 | fprintf(stderr, "failed to initialize egl\n"); |
| 1604 | return NULL; |
| 1605 | } |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 1606 | |
| 1607 | ec->base.destroy = drm_destroy; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 1608 | |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 1609 | ec->base.focus = 1; |
| 1610 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1611 | ec->prev_state = WESTON_COMPOSITOR_ACTIVE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1612 | |
Benjamin Franzke | d59eb1c | 2011-04-29 22:14:54 +0200 | [diff] [blame] | 1613 | /* Can't init base class until we have a current egl context */ |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1614 | if (weston_compositor_init(&ec->base, display) < 0) |
Benjamin Franzke | d59eb1c | 2011-04-29 22:14:54 +0200 | [diff] [blame] | 1615 | return NULL; |
| 1616 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1617 | wl_list_init(&ec->sprite_list); |
| 1618 | create_sprites(ec); |
| 1619 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1620 | if (create_outputs(ec, connector, drm_device) < 0) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1621 | fprintf(stderr, "failed to create output for %s\n", path); |
| 1622 | return NULL; |
| 1623 | } |
| 1624 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1625 | udev_device_unref(drm_device); |
Benjamin Franzke | 02dee2c | 2011-10-07 08:27:26 +0200 | [diff] [blame] | 1626 | udev_enumerate_unref(e); |
| 1627 | path = NULL; |
| 1628 | |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 1629 | evdev_input_create(&ec->base, ec->udev, seat); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1630 | |
| 1631 | loop = wl_display_get_event_loop(ec->base.wl_display); |
| 1632 | ec->drm_source = |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1633 | wl_event_loop_add_fd(loop, ec->drm.fd, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1634 | WL_EVENT_READABLE, on_drm_input, ec); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1635 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1636 | ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev"); |
| 1637 | if (ec->udev_monitor == NULL) { |
| 1638 | fprintf(stderr, "failed to intialize udev monitor\n"); |
| 1639 | return NULL; |
| 1640 | } |
| 1641 | udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor, |
| 1642 | "drm", NULL); |
| 1643 | ec->udev_drm_source = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1644 | wl_event_loop_add_fd(loop, |
| 1645 | udev_monitor_get_fd(ec->udev_monitor), |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1646 | WL_EVENT_READABLE, udev_drm_event, ec); |
| 1647 | |
| 1648 | if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) { |
| 1649 | fprintf(stderr, "failed to enable udev-monitor receiving\n"); |
| 1650 | return NULL; |
| 1651 | } |
| 1652 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1653 | return &ec->base; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1654 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1655 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1656 | WL_EXPORT struct weston_compositor * |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1657 | backend_init(struct wl_display *display, int argc, char *argv[]) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1658 | { |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1659 | int connector = 0, tty = 0; |
| 1660 | const char *seat = default_seat; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1661 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1662 | const struct weston_option drm_options[] = { |
| 1663 | { WESTON_OPTION_INTEGER, "connector", 0, &connector }, |
| 1664 | { WESTON_OPTION_STRING, "seat", 0, &seat }, |
| 1665 | { WESTON_OPTION_INTEGER, "tty", 0, &tty }, |
| 1666 | }; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1667 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1668 | parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1669 | |
Tiago Vignatti | faee801 | 2011-09-01 15:58:17 -0400 | [diff] [blame] | 1670 | return drm_compositor_create(display, connector, seat, tty); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1671 | } |