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