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