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> |
Ander Conselvan de Oliveira | fd1f4c6 | 2012-06-26 17:09:14 +0300 | [diff] [blame] | 32 | #include <assert.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 33 | |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 34 | #include <xf86drm.h> |
| 35 | #include <xf86drmMode.h> |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 36 | #include <drm_fourcc.h> |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 37 | |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 38 | #include <gbm.h> |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 39 | #include <libbacklight.h> |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 40 | #include <libudev.h> |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 41 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 42 | #include "compositor.h" |
John Kåre Alsaker | 30d2b1f | 2012-11-13 19:10:28 +0100 | [diff] [blame^] | 43 | #include "gl-renderer.h" |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 44 | #include "evdev.h" |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 45 | #include "launcher-util.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 46 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 47 | static int option_current_mode = 0; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 48 | static char *output_name; |
| 49 | static char *output_mode; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 50 | static char *output_transform; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 51 | static struct wl_list configured_output_list; |
| 52 | |
| 53 | enum output_config { |
| 54 | OUTPUT_CONFIG_INVALID = 0, |
| 55 | OUTPUT_CONFIG_OFF, |
| 56 | OUTPUT_CONFIG_PREFERRED, |
| 57 | OUTPUT_CONFIG_CURRENT, |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 58 | OUTPUT_CONFIG_MODE, |
| 59 | OUTPUT_CONFIG_MODELINE |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct drm_configured_output { |
| 63 | char *name; |
| 64 | char *mode; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 65 | uint32_t transform; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 66 | int32_t width, height; |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 67 | drmModeModeInfo crtc_mode; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 68 | enum output_config config; |
| 69 | struct wl_list link; |
| 70 | }; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 71 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 72 | struct drm_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 73 | struct weston_compositor base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 74 | |
| 75 | struct udev *udev; |
| 76 | struct wl_event_source *drm_source; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 77 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 78 | struct udev_monitor *udev_monitor; |
| 79 | struct wl_event_source *udev_drm_source; |
| 80 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 81 | struct { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 82 | int id; |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 83 | int fd; |
| 84 | } drm; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 85 | struct gbm_device *gbm; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 86 | uint32_t *crtcs; |
| 87 | int num_crtcs; |
Marty Jack | 13d9db2 | 2011-02-09 19:01:42 -0500 | [diff] [blame] | 88 | uint32_t crtc_allocator; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 89 | uint32_t connector_allocator; |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 90 | struct tty *tty; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 91 | |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 92 | /* we need these parameters in order to not fail drmModeAddFB2() |
| 93 | * due to out of bounds dimensions, and then mistakenly set |
| 94 | * sprites_are_broken: |
| 95 | */ |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 96 | uint32_t min_width, max_width; |
| 97 | uint32_t min_height, max_height; |
| 98 | int no_addfb2; |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 99 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 100 | struct wl_list sprite_list; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 101 | int sprites_are_broken; |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 102 | int sprites_hidden; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 103 | |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 104 | int cursors_are_broken; |
| 105 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 106 | uint32_t prev_state; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 107 | }; |
| 108 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 109 | struct drm_mode { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 110 | struct weston_mode base; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 111 | drmModeModeInfo mode_info; |
| 112 | }; |
| 113 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 114 | struct drm_output; |
| 115 | |
| 116 | struct drm_fb { |
| 117 | struct gbm_bo *bo; |
| 118 | struct drm_output *output; |
| 119 | uint32_t fb_id; |
| 120 | int is_client_buffer; |
| 121 | struct wl_buffer *buffer; |
| 122 | struct wl_listener buffer_destroy_listener; |
| 123 | }; |
| 124 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 125 | struct drm_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 126 | struct weston_output base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 127 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 128 | char *name; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 129 | uint32_t crtc_id; |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 130 | int pipe; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 131 | uint32_t connector_id; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 132 | drmModeCrtcPtr original_crtc; |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 133 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 134 | int vblank_pending; |
| 135 | int page_flip_pending; |
| 136 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 137 | struct gbm_surface *surface; |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 138 | struct gbm_bo *cursor_bo[2]; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 139 | struct weston_plane cursor_plane; |
| 140 | struct weston_plane fb_plane; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 141 | struct weston_surface *cursor_surface; |
| 142 | int current_cursor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 143 | struct drm_fb *current, *next; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 144 | struct backlight *backlight; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 145 | }; |
| 146 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 147 | /* |
| 148 | * An output has a primary display plane plus zero or more sprites for |
| 149 | * blending display contents. |
| 150 | */ |
| 151 | struct drm_sprite { |
| 152 | struct wl_list link; |
| 153 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 154 | struct weston_plane plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 155 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 156 | struct drm_fb *current, *next; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 157 | struct drm_output *output; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 158 | struct drm_compositor *compositor; |
| 159 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 160 | uint32_t possible_crtcs; |
| 161 | uint32_t plane_id; |
| 162 | uint32_t count_formats; |
| 163 | |
| 164 | int32_t src_x, src_y; |
| 165 | uint32_t src_w, src_h; |
| 166 | uint32_t dest_x, dest_y; |
| 167 | uint32_t dest_w, dest_h; |
| 168 | |
| 169 | uint32_t formats[]; |
| 170 | }; |
| 171 | |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 172 | struct drm_seat { |
| 173 | struct weston_seat base; |
| 174 | struct wl_list devices_list; |
| 175 | struct udev_monitor *udev_monitor; |
| 176 | struct wl_event_source *udev_monitor_source; |
| 177 | char *seat_id; |
| 178 | }; |
| 179 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 180 | static void |
| 181 | drm_output_set_cursor(struct drm_output *output); |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 182 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 183 | static int |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 184 | drm_sprite_crtc_supported(struct weston_output *output_base, uint32_t supported) |
| 185 | { |
| 186 | struct weston_compositor *ec = output_base->compositor; |
| 187 | struct drm_compositor *c =(struct drm_compositor *) ec; |
| 188 | struct drm_output *output = (struct drm_output *) output_base; |
| 189 | int crtc; |
| 190 | |
| 191 | for (crtc = 0; crtc < c->num_crtcs; crtc++) { |
| 192 | if (c->crtcs[crtc] != output->crtc_id) |
| 193 | continue; |
| 194 | |
| 195 | if (supported & (1 << crtc)) |
| 196 | return -1; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 202 | static void |
| 203 | drm_fb_destroy_callback(struct gbm_bo *bo, void *data) |
| 204 | { |
| 205 | struct drm_fb *fb = data; |
| 206 | struct gbm_device *gbm = gbm_bo_get_device(bo); |
| 207 | |
| 208 | if (fb->fb_id) |
| 209 | drmModeRmFB(gbm_device_get_fd(gbm), fb->fb_id); |
| 210 | |
| 211 | if (fb->buffer) { |
| 212 | weston_buffer_post_release(fb->buffer); |
| 213 | wl_list_remove(&fb->buffer_destroy_listener.link); |
| 214 | } |
| 215 | |
| 216 | free(data); |
| 217 | } |
| 218 | |
| 219 | static struct drm_fb * |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 220 | drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_compositor *compositor) |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 221 | { |
| 222 | struct drm_fb *fb = gbm_bo_get_user_data(bo); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 223 | uint32_t width, height, stride, handle, format; |
| 224 | uint32_t handles[4], pitches[4], offsets[4]; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 225 | int ret; |
| 226 | |
| 227 | if (fb) |
| 228 | return fb; |
| 229 | |
| 230 | fb = malloc(sizeof *fb); |
| 231 | |
| 232 | fb->bo = bo; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 233 | fb->is_client_buffer = 0; |
| 234 | fb->buffer = NULL; |
| 235 | |
| 236 | width = gbm_bo_get_width(bo); |
| 237 | height = gbm_bo_get_height(bo); |
Kristian Høgsberg | 270a7cb | 2012-07-16 16:44:16 -0400 | [diff] [blame] | 238 | stride = gbm_bo_get_stride(bo); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 239 | handle = gbm_bo_get_handle(bo).u32; |
| 240 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 241 | if (compositor->min_width > width || width > compositor->max_width || |
| 242 | compositor->min_height > height || |
| 243 | height > compositor->max_height) { |
| 244 | weston_log("bo geometry out of bounds\n"); |
| 245 | goto err_free; |
| 246 | } |
| 247 | |
| 248 | ret = -1; |
| 249 | |
| 250 | format = gbm_bo_get_format(bo); |
| 251 | |
| 252 | if (format && !compositor->no_addfb2) { |
| 253 | handles[0] = handle; |
| 254 | pitches[0] = stride; |
| 255 | offsets[0] = 0; |
| 256 | |
| 257 | ret = drmModeAddFB2(compositor->drm.fd, width, height, |
| 258 | format, handles, pitches, offsets, |
| 259 | &fb->fb_id, 0); |
| 260 | if (ret) { |
| 261 | weston_log("addfb2 failed: %m\n"); |
| 262 | compositor->no_addfb2 = 1; |
| 263 | compositor->sprites_are_broken = 1; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | if (ret) |
| 268 | ret = drmModeAddFB(compositor->drm.fd, width, height, 24, 32, |
| 269 | stride, handle, &fb->fb_id); |
| 270 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 271 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 272 | weston_log("failed to create kms fb: %m\n"); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 273 | goto err_free; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback); |
| 277 | |
| 278 | return fb; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 279 | |
| 280 | err_free: |
| 281 | free(fb); |
| 282 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static void |
| 286 | fb_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 287 | { |
| 288 | struct drm_fb *fb = container_of(listener, struct drm_fb, |
| 289 | buffer_destroy_listener); |
| 290 | |
| 291 | fb->buffer = NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 292 | } |
| 293 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 294 | static void |
| 295 | drm_fb_set_buffer(struct drm_fb *fb, struct wl_buffer *buffer) |
| 296 | { |
| 297 | assert(fb->buffer == NULL); |
| 298 | |
| 299 | fb->is_client_buffer = 1; |
| 300 | fb->buffer = buffer; |
| 301 | fb->buffer->busy_count++; |
| 302 | fb->buffer_destroy_listener.notify = fb_handle_buffer_destroy; |
| 303 | |
| 304 | wl_signal_add(&fb->buffer->resource.destroy_signal, |
| 305 | &fb->buffer_destroy_listener); |
| 306 | } |
| 307 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 308 | static struct weston_plane * |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 309 | drm_output_prepare_scanout_surface(struct weston_output *_output, |
| 310 | struct weston_surface *es) |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 311 | { |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 312 | struct drm_output *output = (struct drm_output *) _output; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 313 | struct drm_compositor *c = |
| 314 | (struct drm_compositor *) output->base.compositor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 315 | struct gbm_bo *bo; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 316 | |
Kristian Høgsberg | 101cb65 | 2012-02-17 10:45:16 -0500 | [diff] [blame] | 317 | if (es->geometry.x != output->base.x || |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 318 | es->geometry.y != output->base.y || |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 319 | es->geometry.width != output->base.current->width || |
| 320 | es->geometry.height != output->base.current->height || |
Pekka Paalanen | f1f5b36 | 2012-01-25 14:33:33 +0200 | [diff] [blame] | 321 | es->transform.enabled || |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 322 | es->buffer == NULL) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 323 | return NULL; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 324 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 325 | bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER, |
| 326 | es->buffer, GBM_BO_USE_SCANOUT); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 327 | |
Rob Bradford | 9b10187 | 2012-09-14 23:25:41 +0100 | [diff] [blame] | 328 | /* Unable to use the buffer for scanout */ |
| 329 | if (!bo) |
| 330 | return NULL; |
| 331 | |
Ander Conselvan de Oliveira | a64b15d | 2012-05-02 16:42:22 +0300 | [diff] [blame] | 332 | /* Need to verify output->region contained in surface opaque |
| 333 | * region. Or maybe just that format doesn't have alpha. |
| 334 | * For now, scanout only if format is XRGB8888. */ |
| 335 | if (gbm_bo_get_format(bo) != GBM_FORMAT_XRGB8888) { |
| 336 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 337 | return NULL; |
Ander Conselvan de Oliveira | a64b15d | 2012-05-02 16:42:22 +0300 | [diff] [blame] | 338 | } |
| 339 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 340 | output->next = drm_fb_get_from_bo(bo, c); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 341 | if (!output->next) { |
| 342 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 343 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 344 | } |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 345 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 346 | drm_fb_set_buffer(output->next, es->buffer); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 347 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 348 | return &output->fb_plane; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 349 | } |
| 350 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 351 | static void |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 352 | drm_output_render(struct drm_output *output, pixman_region32_t *damage) |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 353 | { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 354 | struct drm_compositor *c = |
| 355 | (struct drm_compositor *) output->base.compositor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 356 | struct gbm_bo *bo; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 357 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 358 | c->base.renderer->repaint_output(&output->base, damage); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 359 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 360 | bo = gbm_surface_lock_front_buffer(output->surface); |
| 361 | if (!bo) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 362 | weston_log("failed to lock front buffer: %m\n"); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 363 | return; |
| 364 | } |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 365 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 366 | output->next = drm_fb_get_from_bo(bo, c); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 367 | if (!output->next) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 368 | weston_log("failed to get drm_fb for bo\n"); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 369 | gbm_surface_release_buffer(output->surface, bo); |
| 370 | return; |
| 371 | } |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static void |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 375 | drm_output_repaint(struct weston_output *output_base, |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 376 | pixman_region32_t *damage) |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 377 | { |
| 378 | struct drm_output *output = (struct drm_output *) output_base; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 379 | struct drm_compositor *compositor = |
| 380 | (struct drm_compositor *) output->base.compositor; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 381 | struct drm_sprite *s; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 382 | struct drm_mode *mode; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 383 | int ret = 0; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 384 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 385 | if (!output->next) |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 386 | drm_output_render(output, damage); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 387 | if (!output->next) |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 388 | return; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 389 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 390 | mode = container_of(output->base.current, struct drm_mode, base); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 391 | if (!output->current) { |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 392 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 393 | output->next->fb_id, 0, 0, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 394 | &output->connector_id, 1, |
| 395 | &mode->mode_info); |
| 396 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 397 | weston_log("set mode failed: %m\n"); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 398 | return; |
| 399 | } |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 402 | if (drmModePageFlip(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 403 | output->next->fb_id, |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 404 | DRM_MODE_PAGE_FLIP_EVENT, output) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 405 | weston_log("queueing pageflip failed: %m\n"); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 406 | return; |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 407 | } |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 408 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 409 | output->page_flip_pending = 1; |
| 410 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 411 | drm_output_set_cursor(output); |
| 412 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 413 | /* |
| 414 | * Now, update all the sprite surfaces |
| 415 | */ |
| 416 | wl_list_for_each(s, &compositor->sprite_list, link) { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 417 | uint32_t flags = 0, fb_id = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 418 | drmVBlank vbl = { |
| 419 | .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT, |
| 420 | .request.sequence = 1, |
| 421 | }; |
| 422 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 423 | if ((!s->current && !s->next) || |
Ander Conselvan de Oliveira | 2f7a30b | 2012-11-09 14:19:03 +0200 | [diff] [blame] | 424 | !drm_sprite_crtc_supported(output_base, s->possible_crtcs)) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 425 | continue; |
| 426 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 427 | if (s->next && !compositor->sprites_hidden) |
| 428 | fb_id = s->next->fb_id; |
| 429 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 430 | ret = drmModeSetPlane(compositor->drm.fd, s->plane_id, |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 431 | output->crtc_id, fb_id, flags, |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 432 | s->dest_x, s->dest_y, |
| 433 | s->dest_w, s->dest_h, |
| 434 | s->src_x, s->src_y, |
| 435 | s->src_w, s->src_h); |
| 436 | if (ret) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 437 | weston_log("setplane failed: %d: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 438 | ret, strerror(errno)); |
| 439 | |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 440 | if (output->pipe > 0) |
| 441 | vbl.request.type |= DRM_VBLANK_SECONDARY; |
| 442 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 443 | /* |
| 444 | * Queue a vblank signal so we know when the surface |
| 445 | * becomes active on the display or has been replaced. |
| 446 | */ |
| 447 | vbl.request.signal = (unsigned long)s; |
| 448 | ret = drmWaitVBlank(compositor->drm.fd, &vbl); |
| 449 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 450 | weston_log("vblank event request failed: %d: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 451 | ret, strerror(errno)); |
| 452 | } |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 453 | |
| 454 | s->output = output; |
| 455 | output->vblank_pending = 1; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 456 | } |
| 457 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 458 | return; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 462 | vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, |
| 463 | void *data) |
| 464 | { |
| 465 | struct drm_sprite *s = (struct drm_sprite *)data; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 466 | struct drm_output *output = s->output; |
| 467 | uint32_t msecs; |
| 468 | |
| 469 | output->vblank_pending = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 470 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 471 | if (s->current) |
| 472 | gbm_bo_destroy(s->current->bo); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 473 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 474 | s->current = s->next; |
| 475 | s->next = NULL; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 476 | |
| 477 | if (!output->page_flip_pending) { |
| 478 | msecs = sec * 1000 + usec / 1000; |
| 479 | weston_output_finish_frame(&output->base, msecs); |
| 480 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static void |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 484 | page_flip_handler(int fd, unsigned int frame, |
| 485 | unsigned int sec, unsigned int usec, void *data) |
| 486 | { |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 487 | struct drm_output *output = (struct drm_output *) data; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 488 | uint32_t msecs; |
| 489 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 490 | output->page_flip_pending = 0; |
| 491 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 492 | if (output->current) { |
| 493 | if (output->current->is_client_buffer) |
| 494 | gbm_bo_destroy(output->current->bo); |
| 495 | else |
| 496 | gbm_surface_release_buffer(output->surface, |
| 497 | output->current->bo); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 498 | } |
| 499 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 500 | output->current = output->next; |
| 501 | output->next = NULL; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 502 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 503 | if (!output->vblank_pending) { |
| 504 | msecs = sec * 1000 + usec / 1000; |
| 505 | weston_output_finish_frame(&output->base, msecs); |
| 506 | } |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static int |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 510 | drm_surface_format_supported(struct drm_sprite *s, uint32_t format) |
| 511 | { |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 512 | uint32_t i; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 513 | |
| 514 | for (i = 0; i < s->count_formats; i++) |
| 515 | if (s->formats[i] == format) |
| 516 | return 1; |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | static int |
| 522 | drm_surface_transform_supported(struct weston_surface *es) |
| 523 | { |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 524 | struct weston_matrix *matrix = &es->transform.matrix; |
| 525 | int i; |
| 526 | |
| 527 | if (!es->transform.enabled) |
| 528 | return 1; |
| 529 | |
| 530 | for (i = 0; i < 16; i++) { |
| 531 | switch (i) { |
| 532 | case 10: |
| 533 | case 15: |
| 534 | if (matrix->d[i] != 1.0) |
| 535 | return 0; |
| 536 | break; |
| 537 | case 0: |
| 538 | case 5: |
| 539 | case 12: |
| 540 | case 13: |
| 541 | break; |
| 542 | default: |
| 543 | if (matrix->d[i] != 0.0) |
| 544 | return 0; |
| 545 | break; |
| 546 | } |
| 547 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 548 | |
| 549 | return 1; |
| 550 | } |
| 551 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 552 | static struct weston_plane * |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 553 | drm_output_prepare_overlay_surface(struct weston_output *output_base, |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 554 | struct weston_surface *es) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 555 | { |
| 556 | struct weston_compositor *ec = output_base->compositor; |
| 557 | struct drm_compositor *c =(struct drm_compositor *) ec; |
| 558 | struct drm_sprite *s; |
| 559 | int found = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 560 | struct gbm_bo *bo; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 561 | pixman_region32_t dest_rect, src_rect; |
| 562 | pixman_box32_t *box; |
| 563 | uint32_t format; |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 564 | wl_fixed_t sx1, sy1, sx2, sy2; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 565 | |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 566 | if (c->sprites_are_broken) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 567 | return NULL; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 568 | |
Ander Conselvan de Oliveira | d450b19 | 2012-06-26 17:09:12 +0300 | [diff] [blame] | 569 | if (es->output_mask != (1u << output_base->id)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 570 | return NULL; |
Ander Conselvan de Oliveira | d450b19 | 2012-06-26 17:09:12 +0300 | [diff] [blame] | 571 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 572 | if (es->buffer == NULL) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 573 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 574 | |
Rob Clark | 702ffae | 2012-08-09 14:18:27 -0500 | [diff] [blame] | 575 | if (wl_buffer_is_shm(es->buffer)) |
| 576 | return NULL; |
| 577 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 578 | if (!drm_surface_transform_supported(es)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 579 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 580 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 581 | wl_list_for_each(s, &c->sprite_list, link) { |
| 582 | if (!drm_sprite_crtc_supported(output_base, s->possible_crtcs)) |
| 583 | continue; |
| 584 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 585 | if (!s->next) { |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 586 | found = 1; |
| 587 | break; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /* No sprites available */ |
| 592 | if (!found) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 593 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 594 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 595 | bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER, |
| 596 | es->buffer, GBM_BO_USE_SCANOUT); |
| 597 | if (!bo) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 598 | return NULL; |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 599 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 600 | format = gbm_bo_get_format(bo); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 601 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 602 | if (!drm_surface_format_supported(s, format)) { |
| 603 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 604 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 605 | } |
| 606 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 607 | s->next = drm_fb_get_from_bo(bo, c); |
| 608 | if (!s->next) { |
| 609 | gbm_bo_destroy(bo); |
| 610 | return NULL; |
| 611 | } |
| 612 | |
| 613 | drm_fb_set_buffer(s->next, es->buffer); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 614 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 615 | box = pixman_region32_extents(&es->transform.boundingbox); |
| 616 | s->plane.x = box->x1; |
| 617 | s->plane.y = box->y1; |
| 618 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 619 | /* |
| 620 | * Calculate the source & dest rects properly based on actual |
Martin Olsson | 3b132e3 | 2012-09-29 15:13:56 +0200 | [diff] [blame] | 621 | * position (note the caller has called weston_surface_update_transform() |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 622 | * for us already). |
| 623 | */ |
| 624 | pixman_region32_init(&dest_rect); |
| 625 | pixman_region32_intersect(&dest_rect, &es->transform.boundingbox, |
| 626 | &output_base->region); |
| 627 | pixman_region32_translate(&dest_rect, -output_base->x, -output_base->y); |
| 628 | box = pixman_region32_extents(&dest_rect); |
| 629 | s->dest_x = box->x1; |
| 630 | s->dest_y = box->y1; |
| 631 | s->dest_w = box->x2 - box->x1; |
| 632 | s->dest_h = box->y2 - box->y1; |
| 633 | pixman_region32_fini(&dest_rect); |
| 634 | |
| 635 | pixman_region32_init(&src_rect); |
| 636 | pixman_region32_intersect(&src_rect, &es->transform.boundingbox, |
| 637 | &output_base->region); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 638 | box = pixman_region32_extents(&src_rect); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 639 | |
| 640 | weston_surface_from_global_fixed(es, |
| 641 | wl_fixed_from_int(box->x1), |
| 642 | wl_fixed_from_int(box->y1), |
| 643 | &sx1, &sy1); |
| 644 | weston_surface_from_global_fixed(es, |
| 645 | wl_fixed_from_int(box->x2), |
| 646 | wl_fixed_from_int(box->y2), |
| 647 | &sx2, &sy2); |
| 648 | |
| 649 | if (sx1 < 0) |
| 650 | sx1 = 0; |
| 651 | if (sy1 < 0) |
| 652 | sy1 = 0; |
| 653 | if (sx2 > wl_fixed_from_int(es->geometry.width)) |
| 654 | sx2 = wl_fixed_from_int(es->geometry.width); |
| 655 | if (sy2 > wl_fixed_from_int(es->geometry.height)) |
| 656 | sy2 = wl_fixed_from_int(es->geometry.height); |
| 657 | |
| 658 | s->src_x = sx1 << 8; |
| 659 | s->src_y = sy1 << 8; |
| 660 | s->src_w = (sx2 - sx1) << 8; |
| 661 | s->src_h = (sy2 - sy1) << 8; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 662 | pixman_region32_fini(&src_rect); |
| 663 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 664 | return &s->plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 665 | } |
| 666 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 667 | static struct weston_plane * |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 668 | drm_output_prepare_cursor_surface(struct weston_output *output_base, |
| 669 | struct weston_surface *es) |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 670 | { |
Kristian Høgsberg | 8a01580 | 2012-08-09 17:19:23 -0400 | [diff] [blame] | 671 | struct drm_compositor *c = |
| 672 | (struct drm_compositor *) output_base->compositor; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 673 | struct drm_output *output = (struct drm_output *) output_base; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 674 | |
| 675 | if (output->cursor_surface) |
| 676 | return NULL; |
| 677 | if (es->output_mask != (1u << output_base->id)) |
| 678 | return NULL; |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 679 | if (c->cursors_are_broken) |
Kristian Høgsberg | 8a01580 | 2012-08-09 17:19:23 -0400 | [diff] [blame] | 680 | return NULL; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 681 | if (es->buffer == NULL || !wl_buffer_is_shm(es->buffer) || |
| 682 | es->geometry.width > 64 || es->geometry.height > 64) |
| 683 | return NULL; |
| 684 | |
| 685 | output->cursor_surface = es; |
| 686 | |
| 687 | return &output->cursor_plane; |
| 688 | } |
| 689 | |
| 690 | static void |
| 691 | drm_output_set_cursor(struct drm_output *output) |
| 692 | { |
| 693 | struct weston_surface *es = output->cursor_surface; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 694 | struct drm_compositor *c = |
| 695 | (struct drm_compositor *) output->base.compositor; |
| 696 | EGLint handle, stride; |
| 697 | struct gbm_bo *bo; |
| 698 | uint32_t buf[64 * 64]; |
| 699 | unsigned char *s; |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 700 | int i, x, y; |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 701 | |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 702 | output->cursor_surface = NULL; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 703 | if (es == NULL) { |
| 704 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
| 705 | return; |
| 706 | } |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 707 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 708 | if (es->buffer && pixman_region32_not_empty(&output->cursor_plane.damage)) { |
| 709 | pixman_region32_fini(&output->cursor_plane.damage); |
| 710 | pixman_region32_init(&output->cursor_plane.damage); |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 711 | output->current_cursor ^= 1; |
| 712 | bo = output->cursor_bo[output->current_cursor]; |
| 713 | memset(buf, 0, sizeof buf); |
| 714 | stride = wl_shm_buffer_get_stride(es->buffer); |
| 715 | s = wl_shm_buffer_get_data(es->buffer); |
| 716 | for (i = 0; i < es->geometry.height; i++) |
| 717 | memcpy(buf + i * 64, s + i * stride, |
| 718 | es->geometry.width * 4); |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 719 | |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 720 | if (gbm_bo_write(bo, buf, sizeof buf) < 0) |
Pekka Paalanen | ae29da2 | 2012-08-06 14:57:05 +0300 | [diff] [blame] | 721 | weston_log("failed update cursor: %m\n"); |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 722 | |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 723 | handle = gbm_bo_get_handle(bo).s32; |
| 724 | if (drmModeSetCursor(c->drm.fd, |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 725 | output->crtc_id, handle, 64, 64)) { |
Pekka Paalanen | ae29da2 | 2012-08-06 14:57:05 +0300 | [diff] [blame] | 726 | weston_log("failed to set cursor: %m\n"); |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 727 | c->cursors_are_broken = 1; |
| 728 | } |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 731 | x = es->geometry.x - output->base.x; |
| 732 | y = es->geometry.y - output->base.y; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 733 | if (output->cursor_plane.x != x || output->cursor_plane.y != y) { |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 734 | if (drmModeMoveCursor(c->drm.fd, output->crtc_id, x, y)) { |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 735 | weston_log("failed to move cursor: %m\n"); |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 736 | c->cursors_are_broken = 1; |
| 737 | } |
| 738 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 739 | output->cursor_plane.x = x; |
| 740 | output->cursor_plane.y = y; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 741 | } |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 742 | } |
| 743 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 744 | static void |
| 745 | drm_assign_planes(struct weston_output *output) |
| 746 | { |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 747 | struct drm_compositor *c = |
| 748 | (struct drm_compositor *) output->compositor; |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 749 | struct drm_output *drm_output = (struct drm_output *) output; |
| 750 | struct drm_sprite *s; |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 751 | struct weston_surface *es, *next; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 752 | pixman_region32_t overlap, surface_overlap; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 753 | struct weston_plane *primary, *next_plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 754 | |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 755 | /* Reset the opaque region of the planes */ |
| 756 | pixman_region32_fini(&drm_output->cursor_plane.opaque); |
| 757 | pixman_region32_init(&drm_output->cursor_plane.opaque); |
| 758 | pixman_region32_fini(&drm_output->fb_plane.opaque); |
| 759 | pixman_region32_init(&drm_output->fb_plane.opaque); |
| 760 | |
| 761 | wl_list_for_each (s, &c->sprite_list, link) { |
| 762 | if (!drm_sprite_crtc_supported(output, s->possible_crtcs)) |
| 763 | continue; |
| 764 | |
| 765 | pixman_region32_fini(&s->plane.opaque); |
| 766 | pixman_region32_init(&s->plane.opaque); |
| 767 | } |
| 768 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 769 | /* |
| 770 | * Find a surface for each sprite in the output using some heuristics: |
| 771 | * 1) size |
| 772 | * 2) frequency of update |
| 773 | * 3) opacity (though some hw might support alpha blending) |
| 774 | * 4) clipping (this can be fixed with color keys) |
| 775 | * |
| 776 | * The idea is to save on blitting since this should save power. |
| 777 | * If we can get a large video surface on the sprite for example, |
| 778 | * the main display surface may not need to update at all, and |
| 779 | * the client buffer can be used directly for the sprite surface |
| 780 | * as we do for flipping full screen surfaces. |
| 781 | */ |
| 782 | pixman_region32_init(&overlap); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 783 | primary = &c->base.primary_plane; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 784 | wl_list_for_each_safe(es, next, &c->base.surface_list, link) { |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 785 | pixman_region32_init(&surface_overlap); |
| 786 | pixman_region32_intersect(&surface_overlap, &overlap, |
| 787 | &es->transform.boundingbox); |
| 788 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 789 | next_plane = NULL; |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 790 | if (pixman_region32_not_empty(&surface_overlap)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 791 | next_plane = primary; |
| 792 | if (next_plane == NULL) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 793 | next_plane = drm_output_prepare_cursor_surface(output, es); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 794 | if (next_plane == NULL) |
| 795 | next_plane = drm_output_prepare_scanout_surface(output, es); |
| 796 | if (next_plane == NULL) |
| 797 | next_plane = drm_output_prepare_overlay_surface(output, es); |
| 798 | if (next_plane == NULL) |
| 799 | next_plane = primary; |
| 800 | weston_surface_move_to_plane(es, next_plane); |
| 801 | if (next_plane == primary) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 802 | pixman_region32_union(&overlap, &overlap, |
| 803 | &es->transform.boundingbox); |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 804 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 805 | pixman_region32_fini(&surface_overlap); |
| 806 | } |
| 807 | pixman_region32_fini(&overlap); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 808 | } |
| 809 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 810 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 811 | drm_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 812 | { |
| 813 | struct drm_output *output = (struct drm_output *) output_base; |
| 814 | struct drm_compositor *c = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 815 | (struct drm_compositor *) output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 816 | drmModeCrtcPtr origcrtc = output->original_crtc; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 817 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 818 | if (output->backlight) |
| 819 | backlight_destroy(output->backlight); |
| 820 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 821 | /* Turn off hardware cursor */ |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 822 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 823 | |
| 824 | /* Restore original CRTC state */ |
| 825 | drmModeSetCrtc(c->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id, |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 826 | origcrtc->x, origcrtc->y, |
| 827 | &output->connector_id, 1, &origcrtc->mode); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 828 | drmModeFreeCrtc(origcrtc); |
| 829 | |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 830 | c->crtc_allocator &= ~(1 << output->crtc_id); |
| 831 | c->connector_allocator &= ~(1 << output->connector_id); |
| 832 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 833 | gles2_renderer_output_destroy(output_base); |
| 834 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 835 | gbm_surface_destroy(output->surface); |
| 836 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 837 | weston_plane_release(&output->fb_plane); |
| 838 | weston_plane_release(&output->cursor_plane); |
| 839 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 840 | weston_output_destroy(&output->base); |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 841 | wl_list_remove(&output->base.link); |
| 842 | |
Kristian Høgsberg | 148ef01 | 2012-07-26 23:03:57 -0400 | [diff] [blame] | 843 | free(output->name); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 844 | free(output); |
| 845 | } |
| 846 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 847 | static struct drm_mode * |
| 848 | choose_mode (struct drm_output *output, struct weston_mode *target_mode) |
| 849 | { |
| 850 | struct drm_mode *tmp_mode = NULL, *mode; |
| 851 | |
| 852 | if (output->base.current->width == target_mode->width && |
| 853 | output->base.current->height == target_mode->height && |
| 854 | (output->base.current->refresh == target_mode->refresh || |
| 855 | target_mode->refresh == 0)) |
| 856 | return (struct drm_mode *)output->base.current; |
| 857 | |
| 858 | wl_list_for_each(mode, &output->base.mode_list, base.link) { |
| 859 | if (mode->mode_info.hdisplay == target_mode->width && |
| 860 | mode->mode_info.vdisplay == target_mode->height) { |
| 861 | if (mode->mode_info.vrefresh == target_mode->refresh || |
| 862 | target_mode->refresh == 0) { |
| 863 | return mode; |
| 864 | } else if (!tmp_mode) |
| 865 | tmp_mode = mode; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | return tmp_mode; |
| 870 | } |
| 871 | |
| 872 | static int |
| 873 | drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode) |
| 874 | { |
| 875 | struct drm_output *output; |
| 876 | struct drm_mode *drm_mode; |
| 877 | int ret; |
| 878 | struct drm_compositor *ec; |
| 879 | struct gbm_surface *surface; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 880 | |
| 881 | if (output_base == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 882 | weston_log("output is NULL.\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 883 | return -1; |
| 884 | } |
| 885 | |
| 886 | if (mode == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 887 | weston_log("mode is NULL.\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 888 | return -1; |
| 889 | } |
| 890 | |
| 891 | ec = (struct drm_compositor *)output_base->compositor; |
| 892 | output = (struct drm_output *)output_base; |
| 893 | drm_mode = choose_mode (output, mode); |
| 894 | |
| 895 | if (!drm_mode) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 896 | 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] | 897 | return -1; |
| 898 | } else if (&drm_mode->base == output->base.current) { |
| 899 | return 0; |
| 900 | } else if (drm_mode->base.width == output->base.current->width && |
| 901 | drm_mode->base.height == output->base.current->height) { |
| 902 | /* only change refresh value */ |
| 903 | ret = drmModeSetCrtc(ec->drm.fd, |
| 904 | output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 905 | output->current->fb_id, 0, 0, |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 906 | &output->connector_id, 1, &drm_mode->mode_info); |
| 907 | |
| 908 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 909 | weston_log("failed to set mode (%dx%d) %u Hz\n", |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 910 | drm_mode->base.width, |
| 911 | drm_mode->base.height, |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 912 | drm_mode->base.refresh / 1000); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 913 | ret = -1; |
| 914 | } else { |
| 915 | output->base.current->flags = 0; |
| 916 | output->base.current = &drm_mode->base; |
| 917 | drm_mode->base.flags = |
| 918 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 919 | ret = 0; |
| 920 | } |
| 921 | |
| 922 | return ret; |
| 923 | } |
| 924 | |
| 925 | drm_mode->base.flags = |
| 926 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 927 | |
| 928 | surface = gbm_surface_create(ec->gbm, |
| 929 | drm_mode->base.width, |
| 930 | drm_mode->base.height, |
| 931 | GBM_FORMAT_XRGB8888, |
| 932 | GBM_BO_USE_SCANOUT | |
| 933 | GBM_BO_USE_RENDERING); |
| 934 | if (!surface) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 935 | weston_log("failed to create gbm surface\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 936 | return -1; |
| 937 | } |
| 938 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 939 | gles2_renderer_output_destroy(&output->base); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 940 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 941 | if (!gles2_renderer_output_create(&output->base, surface)) { |
| 942 | weston_log("failed to create renderer output\n"); |
| 943 | goto err_gbm; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | ret = drmModeSetCrtc(ec->drm.fd, |
| 947 | output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 948 | output->current->fb_id, 0, 0, |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 949 | &output->connector_id, 1, &drm_mode->mode_info); |
| 950 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 951 | weston_log("failed to set mode\n"); |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 952 | goto err_gles2; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | /* reset rendering stuff. */ |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 956 | if (output->current) { |
| 957 | if (output->current->is_client_buffer) |
| 958 | gbm_bo_destroy(output->current->bo); |
| 959 | else |
| 960 | gbm_surface_release_buffer(output->surface, |
| 961 | output->current->bo); |
| 962 | } |
| 963 | output->current = NULL; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 964 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 965 | if (output->next) { |
| 966 | if (output->next->is_client_buffer) |
| 967 | gbm_bo_destroy(output->next->bo); |
| 968 | else |
| 969 | gbm_surface_release_buffer(output->surface, |
| 970 | output->next->bo); |
| 971 | } |
| 972 | output->next = NULL; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 973 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 974 | gbm_surface_destroy(output->surface); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 975 | output->surface = surface; |
| 976 | |
| 977 | /*update output*/ |
| 978 | output->base.current = &drm_mode->base; |
| 979 | output->base.dirty = 1; |
| 980 | weston_output_move(&output->base, output->base.x, output->base.y); |
| 981 | return 0; |
| 982 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 983 | err_gles2: |
| 984 | gles2_renderer_output_destroy(&output->base); |
| 985 | err_gbm: |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 986 | gbm_surface_destroy(surface); |
| 987 | return -1; |
| 988 | } |
| 989 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 990 | static int |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 991 | on_drm_input(int fd, uint32_t mask, void *data) |
| 992 | { |
| 993 | drmEventContext evctx; |
| 994 | |
| 995 | memset(&evctx, 0, sizeof evctx); |
| 996 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 997 | evctx.page_flip_handler = page_flip_handler; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 998 | evctx.vblank_handler = vblank_handler; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 999 | drmHandleEvent(fd, &evctx); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1000 | |
| 1001 | return 1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1005 | init_egl(struct drm_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1006 | { |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 1007 | const char *filename, *sysnum; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1008 | int fd; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1009 | |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1010 | sysnum = udev_device_get_sysnum(device); |
| 1011 | if (sysnum) |
| 1012 | ec->drm.id = atoi(sysnum); |
| 1013 | if (!sysnum || ec->drm.id < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1014 | weston_log("cannot get device sysnum\n"); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1015 | return -1; |
| 1016 | } |
| 1017 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1018 | filename = udev_device_get_devnode(device); |
David Herrmann | 63ff706 | 2011-11-05 18:46:01 +0100 | [diff] [blame] | 1019 | fd = open(filename, O_RDWR | O_CLOEXEC); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1020 | if (fd < 0) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1021 | /* Probably permissions error */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1022 | weston_log("couldn't open %s, skipping\n", |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1023 | udev_device_get_devnode(device)); |
| 1024 | return -1; |
| 1025 | } |
| 1026 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1027 | weston_log("using %s\n", filename); |
| 1028 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1029 | ec->drm.fd = fd; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 1030 | ec->gbm = gbm_create_device(ec->drm.fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1031 | |
John Kåre Alsaker | 1b7ad16 | 2012-11-13 19:10:19 +0100 | [diff] [blame] | 1032 | if (gles2_renderer_create(&ec->base, ec->gbm, gles2_renderer_opaque_attribs, |
| 1033 | NULL) < 0) { |
| 1034 | gbm_device_destroy(ec->gbm); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1035 | return -1; |
| 1036 | } |
| 1037 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1041 | static struct drm_mode * |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1042 | drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info) |
| 1043 | { |
| 1044 | struct drm_mode *mode; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 1045 | uint64_t refresh; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1046 | |
| 1047 | mode = malloc(sizeof *mode); |
| 1048 | if (mode == NULL) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1049 | return NULL; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1050 | |
| 1051 | mode->base.flags = 0; |
| 1052 | mode->base.width = info->hdisplay; |
| 1053 | mode->base.height = info->vdisplay; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 1054 | |
| 1055 | /* Calculate higher precision (mHz) refresh rate */ |
| 1056 | refresh = (info->clock * 1000000LL / info->htotal + |
| 1057 | info->vtotal / 2) / info->vtotal; |
| 1058 | |
| 1059 | if (info->flags & DRM_MODE_FLAG_INTERLACE) |
| 1060 | refresh *= 2; |
| 1061 | if (info->flags & DRM_MODE_FLAG_DBLSCAN) |
| 1062 | refresh /= 2; |
| 1063 | if (info->vscan > 1) |
| 1064 | refresh /= info->vscan; |
| 1065 | |
| 1066 | mode->base.refresh = refresh; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1067 | mode->mode_info = *info; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1068 | |
| 1069 | if (info->type & DRM_MODE_TYPE_PREFERRED) |
| 1070 | mode->base.flags |= WL_OUTPUT_MODE_PREFERRED; |
| 1071 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1072 | wl_list_insert(output->base.mode_list.prev, &mode->base.link); |
| 1073 | |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1074 | return mode; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static int |
| 1078 | drm_subpixel_to_wayland(int drm_value) |
| 1079 | { |
| 1080 | switch (drm_value) { |
| 1081 | default: |
| 1082 | case DRM_MODE_SUBPIXEL_UNKNOWN: |
| 1083 | return WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 1084 | case DRM_MODE_SUBPIXEL_NONE: |
| 1085 | return WL_OUTPUT_SUBPIXEL_NONE; |
| 1086 | case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB: |
| 1087 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB; |
| 1088 | case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR: |
| 1089 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR; |
| 1090 | case DRM_MODE_SUBPIXEL_VERTICAL_RGB: |
| 1091 | return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB; |
| 1092 | case DRM_MODE_SUBPIXEL_VERTICAL_BGR: |
| 1093 | return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1097 | /* returns a value between 0-255 range, where higher is brighter */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1098 | static uint32_t |
| 1099 | drm_get_backlight(struct drm_output *output) |
| 1100 | { |
| 1101 | long brightness, max_brightness, norm; |
| 1102 | |
| 1103 | brightness = backlight_get_brightness(output->backlight); |
| 1104 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 1105 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1106 | /* convert it on a scale of 0 to 255 */ |
| 1107 | norm = (brightness * 255)/(max_brightness); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1108 | |
| 1109 | return (uint32_t) norm; |
| 1110 | } |
| 1111 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1112 | /* values accepted are between 0-255 range */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1113 | static void |
| 1114 | drm_set_backlight(struct weston_output *output_base, uint32_t value) |
| 1115 | { |
| 1116 | struct drm_output *output = (struct drm_output *) output_base; |
| 1117 | long max_brightness, new_brightness; |
| 1118 | |
| 1119 | if (!output->backlight) |
| 1120 | return; |
| 1121 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1122 | if (value > 255) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1123 | return; |
| 1124 | |
| 1125 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 1126 | |
| 1127 | /* get denormalized value */ |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1128 | new_brightness = (value * max_brightness) / 255; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1129 | |
| 1130 | backlight_set_brightness(output->backlight, new_brightness); |
| 1131 | } |
| 1132 | |
| 1133 | static drmModePropertyPtr |
| 1134 | drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name) |
| 1135 | { |
| 1136 | drmModePropertyPtr props; |
| 1137 | int i; |
| 1138 | |
| 1139 | for (i = 0; i < connector->count_props; i++) { |
| 1140 | props = drmModeGetProperty(fd, connector->props[i]); |
| 1141 | if (!props) |
| 1142 | continue; |
| 1143 | |
| 1144 | if (!strcmp(props->name, name)) |
| 1145 | return props; |
| 1146 | |
| 1147 | drmModeFreeProperty(props); |
| 1148 | } |
| 1149 | |
| 1150 | return NULL; |
| 1151 | } |
| 1152 | |
| 1153 | static void |
| 1154 | drm_set_dpms(struct weston_output *output_base, enum dpms_enum level) |
| 1155 | { |
| 1156 | struct drm_output *output = (struct drm_output *) output_base; |
| 1157 | struct weston_compositor *ec = output_base->compositor; |
| 1158 | struct drm_compositor *c = (struct drm_compositor *) ec; |
| 1159 | drmModeConnectorPtr connector; |
| 1160 | drmModePropertyPtr prop; |
| 1161 | |
| 1162 | connector = drmModeGetConnector(c->drm.fd, output->connector_id); |
| 1163 | if (!connector) |
| 1164 | return; |
| 1165 | |
| 1166 | prop = drm_get_prop(c->drm.fd, connector, "DPMS"); |
| 1167 | if (!prop) { |
| 1168 | drmModeFreeConnector(connector); |
| 1169 | return; |
| 1170 | } |
| 1171 | |
| 1172 | drmModeConnectorSetProperty(c->drm.fd, connector->connector_id, |
| 1173 | prop->prop_id, level); |
| 1174 | drmModeFreeProperty(prop); |
| 1175 | drmModeFreeConnector(connector); |
| 1176 | } |
| 1177 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1178 | static const char *connector_type_names[] = { |
| 1179 | "None", |
| 1180 | "VGA", |
| 1181 | "DVI", |
| 1182 | "DVI", |
| 1183 | "DVI", |
| 1184 | "Composite", |
| 1185 | "TV", |
| 1186 | "LVDS", |
| 1187 | "CTV", |
| 1188 | "DIN", |
| 1189 | "DP", |
| 1190 | "HDMI", |
| 1191 | "HDMI", |
| 1192 | "TV", |
| 1193 | "eDP", |
| 1194 | }; |
| 1195 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1196 | static int |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1197 | find_crtc_for_connector(struct drm_compositor *ec, |
| 1198 | drmModeRes *resources, drmModeConnector *connector) |
| 1199 | { |
| 1200 | drmModeEncoder *encoder; |
| 1201 | uint32_t possible_crtcs; |
| 1202 | int i, j; |
| 1203 | |
| 1204 | for (j = 0; j < connector->count_encoders; j++) { |
| 1205 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[j]); |
| 1206 | if (encoder == NULL) { |
| 1207 | weston_log("Failed to get encoder.\n"); |
| 1208 | return -1; |
| 1209 | } |
| 1210 | possible_crtcs = encoder->possible_crtcs; |
| 1211 | drmModeFreeEncoder(encoder); |
| 1212 | |
| 1213 | for (i = 0; i < resources->count_crtcs; i++) { |
| 1214 | if (possible_crtcs & (1 << i) && |
| 1215 | !(ec->crtc_allocator & (1 << resources->crtcs[i]))) |
| 1216 | return i; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | return -1; |
| 1221 | } |
| 1222 | |
| 1223 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1224 | create_output_for_connector(struct drm_compositor *ec, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1225 | drmModeRes *resources, |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1226 | drmModeConnector *connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1227 | int x, int y, struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1228 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1229 | struct drm_output *output; |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1230 | struct drm_mode *drm_mode, *next, *preferred, *current, *configured; |
| 1231 | struct weston_mode *m; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1232 | struct drm_configured_output *o = NULL, *temp; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1233 | drmModeEncoder *encoder; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1234 | drmModeModeInfo crtc_mode; |
| 1235 | drmModeCrtc *crtc; |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1236 | int i; |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1237 | char name[32]; |
| 1238 | const char *type_name; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1239 | |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1240 | i = find_crtc_for_connector(ec, resources, connector); |
| 1241 | if (i < 0) { |
| 1242 | weston_log("No usable crtc/encoder pair for connector.\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1243 | return -1; |
| 1244 | } |
| 1245 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1246 | output = malloc(sizeof *output); |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1247 | if (output == NULL) |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1248 | return -1; |
| 1249 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1250 | memset(output, 0, sizeof *output); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1251 | output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel); |
| 1252 | output->base.make = "unknown"; |
| 1253 | output->base.model = "unknown"; |
| 1254 | wl_list_init(&output->base.mode_list); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1255 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1256 | if (connector->connector_type < ARRAY_LENGTH(connector_type_names)) |
| 1257 | type_name = connector_type_names[connector->connector_type]; |
| 1258 | else |
| 1259 | type_name = "UNKNOWN"; |
| 1260 | snprintf(name, 32, "%s%d", type_name, connector->connector_type_id); |
| 1261 | output->name = strdup(name); |
| 1262 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1263 | output->crtc_id = resources->crtcs[i]; |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 1264 | output->pipe = i; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1265 | ec->crtc_allocator |= (1 << output->crtc_id); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1266 | output->connector_id = connector->connector_id; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1267 | ec->connector_allocator |= (1 << output->connector_id); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1268 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1269 | output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id); |
| 1270 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1271 | /* Get the current mode on the crtc that's currently driving |
| 1272 | * this connector. */ |
| 1273 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoder_id); |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1274 | memset(&crtc_mode, 0, sizeof crtc_mode); |
| 1275 | if (encoder != NULL) { |
| 1276 | crtc = drmModeGetCrtc(ec->drm.fd, encoder->crtc_id); |
| 1277 | drmModeFreeEncoder(encoder); |
| 1278 | if (crtc == NULL) |
| 1279 | goto err_free; |
| 1280 | if (crtc->mode_valid) |
| 1281 | crtc_mode = crtc->mode; |
| 1282 | drmModeFreeCrtc(crtc); |
| 1283 | } |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1284 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1285 | for (i = 0; i < connector->count_modes; i++) { |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1286 | drm_mode = drm_output_add_mode(output, &connector->modes[i]); |
| 1287 | if (!drm_mode) |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1288 | goto err_free; |
| 1289 | } |
| 1290 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1291 | preferred = NULL; |
| 1292 | current = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1293 | configured = NULL; |
| 1294 | |
| 1295 | wl_list_for_each(temp, &configured_output_list, link) { |
| 1296 | if (strcmp(temp->name, output->name) == 0) { |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1297 | if (temp->mode) |
| 1298 | weston_log("%s mode \"%s\" in config\n", |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1299 | temp->name, temp->mode); |
| 1300 | o = temp; |
| 1301 | break; |
| 1302 | } |
| 1303 | } |
| 1304 | |
Ander Conselvan de Oliveira | dc79e6d | 2012-08-09 16:45:01 +0300 | [diff] [blame] | 1305 | if (o && o->config == OUTPUT_CONFIG_OFF) { |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1306 | weston_log("Disabling output %s\n", o->name); |
| 1307 | |
| 1308 | drmModeSetCrtc(ec->drm.fd, output->crtc_id, |
| 1309 | 0, 0, 0, 0, 0, NULL); |
| 1310 | goto err_free; |
| 1311 | } |
| 1312 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1313 | wl_list_for_each(drm_mode, &output->base.mode_list, base.link) { |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1314 | if (o && o->config == OUTPUT_CONFIG_MODE && |
| 1315 | o->width == drm_mode->base.width && |
| 1316 | o->height == drm_mode->base.height) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1317 | configured = drm_mode; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1318 | if (!memcmp(&crtc_mode, &drm_mode->mode_info, sizeof crtc_mode)) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1319 | current = drm_mode; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1320 | if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1321 | preferred = drm_mode; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1322 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1323 | |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 1324 | if (o && o->config == OUTPUT_CONFIG_MODELINE) { |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1325 | configured = drm_output_add_mode(output, &o->crtc_mode); |
| 1326 | if (!configured) |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 1327 | goto err_free; |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 1328 | current = configured; |
| 1329 | } |
| 1330 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1331 | if (current == NULL && crtc_mode.clock != 0) { |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1332 | current = drm_output_add_mode(output, &crtc_mode); |
| 1333 | if (!current) |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1334 | goto err_free; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1335 | } |
| 1336 | |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1337 | if (o && o->config == OUTPUT_CONFIG_CURRENT) |
| 1338 | configured = current; |
| 1339 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1340 | if (option_current_mode && current) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1341 | output->base.current = ¤t->base; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1342 | else if (configured) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1343 | output->base.current = &configured->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1344 | else if (preferred) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1345 | output->base.current = &preferred->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1346 | else if (current) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1347 | output->base.current = ¤t->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1348 | |
| 1349 | if (output->base.current == NULL) { |
| 1350 | weston_log("no available modes for %s\n", output->name); |
| 1351 | goto err_free; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1352 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1353 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 1354 | output->base.current->flags |= WL_OUTPUT_MODE_CURRENT; |
| 1355 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1356 | output->surface = gbm_surface_create(ec->gbm, |
| 1357 | output->base.current->width, |
| 1358 | output->base.current->height, |
| 1359 | GBM_FORMAT_XRGB8888, |
| 1360 | GBM_BO_USE_SCANOUT | |
| 1361 | GBM_BO_USE_RENDERING); |
| 1362 | if (!output->surface) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1363 | weston_log("failed to create gbm surface\n"); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1364 | goto err_free; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 1367 | weston_output_init(&output->base, &ec->base, x, y, |
| 1368 | connector->mmWidth, connector->mmHeight, |
| 1369 | o ? o->transform : WL_OUTPUT_TRANSFORM_NORMAL); |
| 1370 | |
| 1371 | if (gles2_renderer_output_create(&output->base, output->surface) < 0) |
| 1372 | goto err_output; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1373 | |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 1374 | output->cursor_bo[0] = |
| 1375 | gbm_bo_create(ec->gbm, 64, 64, GBM_FORMAT_ARGB8888, |
| 1376 | GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE); |
| 1377 | output->cursor_bo[1] = |
| 1378 | gbm_bo_create(ec->gbm, 64, 64, GBM_FORMAT_ARGB8888, |
| 1379 | GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE); |
Kristian Høgsberg | 1d1e0a5 | 2012-10-21 13:29:26 -0400 | [diff] [blame] | 1380 | if (output->cursor_bo[0] == NULL || output->cursor_bo[1] == NULL) { |
| 1381 | weston_log("cursor buffers unavailable, using gl cursors\n"); |
| 1382 | ec->cursors_are_broken = 1; |
| 1383 | } |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 1384 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1385 | output->backlight = backlight_init(drm_device, |
| 1386 | connector->connector_type); |
| 1387 | if (output->backlight) { |
| 1388 | output->base.set_backlight = drm_set_backlight; |
| 1389 | output->base.backlight_current = drm_get_backlight(output); |
| 1390 | } |
| 1391 | |
Kristian Høgsberg | a4b7e20 | 2011-10-24 13:26:32 -0400 | [diff] [blame] | 1392 | wl_list_insert(ec->base.output_list.prev, &output->base.link); |
| 1393 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1394 | output->base.origin = output->base.current; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 1395 | output->base.repaint = drm_output_repaint; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1396 | output->base.destroy = drm_output_destroy; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1397 | output->base.assign_planes = drm_assign_planes; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1398 | output->base.set_dpms = drm_set_dpms; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1399 | output->base.switch_mode = drm_output_switch_mode; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1400 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1401 | weston_plane_init(&output->cursor_plane, 0, 0); |
| 1402 | weston_plane_init(&output->fb_plane, 0, 0); |
| 1403 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1404 | weston_log("Output %s, (connector %d, crtc %d)\n", |
| 1405 | output->name, output->connector_id, output->crtc_id); |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1406 | wl_list_for_each(m, &output->base.mode_list, link) |
| 1407 | weston_log_continue(" mode %dx%d@%.1f%s%s%s\n", |
| 1408 | m->width, m->height, m->refresh / 1000.0, |
| 1409 | m->flags & WL_OUTPUT_MODE_PREFERRED ? |
| 1410 | ", preferred" : "", |
| 1411 | m->flags & WL_OUTPUT_MODE_CURRENT ? |
| 1412 | ", current" : "", |
| 1413 | connector->count_modes == 0 ? |
| 1414 | ", built-in" : ""); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1415 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1416 | return 0; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1417 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 1418 | err_output: |
| 1419 | weston_output_destroy(&output->base); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1420 | gbm_surface_destroy(output->surface); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1421 | err_free: |
| 1422 | wl_list_for_each_safe(drm_mode, next, &output->base.mode_list, |
| 1423 | base.link) { |
| 1424 | wl_list_remove(&drm_mode->base.link); |
| 1425 | free(drm_mode); |
| 1426 | } |
| 1427 | |
| 1428 | drmModeFreeCrtc(output->original_crtc); |
| 1429 | ec->crtc_allocator &= ~(1 << output->crtc_id); |
| 1430 | ec->connector_allocator &= ~(1 << output->connector_id); |
Kristian Høgsberg | 148ef01 | 2012-07-26 23:03:57 -0400 | [diff] [blame] | 1431 | free(output->name); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1432 | free(output); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1433 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1434 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1437 | static void |
| 1438 | create_sprites(struct drm_compositor *ec) |
| 1439 | { |
| 1440 | struct drm_sprite *sprite; |
| 1441 | drmModePlaneRes *plane_res; |
| 1442 | drmModePlane *plane; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1443 | uint32_t i; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1444 | |
| 1445 | plane_res = drmModeGetPlaneResources(ec->drm.fd); |
| 1446 | if (!plane_res) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1447 | weston_log("failed to get plane resources: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1448 | strerror(errno)); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
| 1452 | for (i = 0; i < plane_res->count_planes; i++) { |
| 1453 | plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]); |
| 1454 | if (!plane) |
| 1455 | continue; |
| 1456 | |
| 1457 | sprite = malloc(sizeof(*sprite) + ((sizeof(uint32_t)) * |
| 1458 | plane->count_formats)); |
| 1459 | if (!sprite) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1460 | weston_log("%s: out of memory\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1461 | __func__); |
| 1462 | free(plane); |
| 1463 | continue; |
| 1464 | } |
| 1465 | |
| 1466 | memset(sprite, 0, sizeof *sprite); |
| 1467 | |
| 1468 | sprite->possible_crtcs = plane->possible_crtcs; |
| 1469 | sprite->plane_id = plane->plane_id; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 1470 | sprite->current = NULL; |
| 1471 | sprite->next = NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1472 | sprite->compositor = ec; |
| 1473 | sprite->count_formats = plane->count_formats; |
| 1474 | memcpy(sprite->formats, plane->formats, |
Rob Clark | 8efbc8e | 2012-03-11 19:48:44 -0500 | [diff] [blame] | 1475 | plane->count_formats * sizeof(plane->formats[0])); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1476 | drmModeFreePlane(plane); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1477 | weston_plane_init(&sprite->plane, 0, 0); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1478 | |
| 1479 | wl_list_insert(&ec->sprite_list, &sprite->link); |
| 1480 | } |
| 1481 | |
| 1482 | free(plane_res->planes); |
| 1483 | free(plane_res); |
| 1484 | } |
| 1485 | |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1486 | static void |
| 1487 | destroy_sprites(struct drm_compositor *compositor) |
| 1488 | { |
| 1489 | struct drm_sprite *sprite, *next; |
| 1490 | struct drm_output *output; |
| 1491 | |
| 1492 | output = container_of(compositor->base.output_list.next, |
| 1493 | struct drm_output, base.link); |
| 1494 | |
| 1495 | wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) { |
| 1496 | drmModeSetPlane(compositor->drm.fd, |
| 1497 | sprite->plane_id, |
| 1498 | output->crtc_id, 0, 0, |
| 1499 | 0, 0, 0, 0, 0, 0, 0, 0); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 1500 | if (sprite->current) |
| 1501 | gbm_bo_destroy(sprite->current->bo); |
| 1502 | if (sprite->next) |
| 1503 | gbm_bo_destroy(sprite->next->bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1504 | weston_plane_release(&sprite->plane); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1505 | free(sprite); |
| 1506 | } |
| 1507 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1508 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1509 | static int |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1510 | create_outputs(struct drm_compositor *ec, uint32_t option_connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1511 | struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1512 | { |
| 1513 | drmModeConnector *connector; |
| 1514 | drmModeRes *resources; |
| 1515 | int i; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1516 | int x = 0, y = 0; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1517 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1518 | resources = drmModeGetResources(ec->drm.fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1519 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1520 | weston_log("drmModeGetResources failed\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1521 | return -1; |
| 1522 | } |
| 1523 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1524 | ec->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t)); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 1525 | if (!ec->crtcs) { |
| 1526 | drmModeFreeResources(resources); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1527 | return -1; |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 1528 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1529 | |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 1530 | ec->min_width = resources->min_width; |
| 1531 | ec->max_width = resources->max_width; |
| 1532 | ec->min_height = resources->min_height; |
| 1533 | ec->max_height = resources->max_height; |
| 1534 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1535 | ec->num_crtcs = resources->count_crtcs; |
| 1536 | memcpy(ec->crtcs, resources->crtcs, sizeof(uint32_t) * ec->num_crtcs); |
| 1537 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1538 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1539 | connector = drmModeGetConnector(ec->drm.fd, |
| 1540 | resources->connectors[i]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1541 | if (connector == NULL) |
| 1542 | continue; |
| 1543 | |
| 1544 | if (connector->connection == DRM_MODE_CONNECTED && |
| 1545 | (option_connector == 0 || |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 1546 | connector->connector_id == option_connector)) { |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1547 | if (create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1548 | connector, x, y, |
| 1549 | drm_device) < 0) { |
Benjamin Franzke | 439d986 | 2011-10-07 08:20:53 +0200 | [diff] [blame] | 1550 | drmModeFreeConnector(connector); |
| 1551 | continue; |
| 1552 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1553 | |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 1554 | x += container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1555 | struct weston_output, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1556 | link)->width; |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 1557 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1558 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1559 | drmModeFreeConnector(connector); |
| 1560 | } |
| 1561 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1562 | if (wl_list_empty(&ec->base.output_list)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1563 | weston_log("No currently active connector found.\n"); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 1564 | drmModeFreeResources(resources); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1565 | return -1; |
| 1566 | } |
| 1567 | |
| 1568 | drmModeFreeResources(resources); |
| 1569 | |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1573 | static void |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1574 | update_outputs(struct drm_compositor *ec, struct udev_device *drm_device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1575 | { |
| 1576 | drmModeConnector *connector; |
| 1577 | drmModeRes *resources; |
| 1578 | struct drm_output *output, *next; |
| 1579 | int x = 0, y = 0; |
| 1580 | int x_offset = 0, y_offset = 0; |
| 1581 | uint32_t connected = 0, disconnects = 0; |
| 1582 | int i; |
| 1583 | |
| 1584 | resources = drmModeGetResources(ec->drm.fd); |
| 1585 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1586 | weston_log("drmModeGetResources failed\n"); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1587 | return; |
| 1588 | } |
| 1589 | |
| 1590 | /* collect new connects */ |
| 1591 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1592 | int connector_id = resources->connectors[i]; |
| 1593 | |
| 1594 | connector = drmModeGetConnector(ec->drm.fd, connector_id); |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 1595 | if (connector == NULL) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1596 | continue; |
| 1597 | |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 1598 | if (connector->connection != DRM_MODE_CONNECTED) { |
| 1599 | drmModeFreeConnector(connector); |
| 1600 | continue; |
| 1601 | } |
| 1602 | |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1603 | connected |= (1 << connector_id); |
| 1604 | |
| 1605 | if (!(ec->connector_allocator & (1 << connector_id))) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1606 | struct weston_output *last = |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1607 | container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1608 | struct weston_output, link); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1609 | |
| 1610 | /* XXX: not yet needed, we die with 0 outputs */ |
| 1611 | if (!wl_list_empty(&ec->base.output_list)) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1612 | x = last->x + last->width; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1613 | else |
| 1614 | x = 0; |
| 1615 | y = 0; |
| 1616 | create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1617 | connector, x, y, |
| 1618 | drm_device); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1619 | weston_log("connector %d connected\n", connector_id); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1620 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1621 | } |
| 1622 | drmModeFreeConnector(connector); |
| 1623 | } |
| 1624 | drmModeFreeResources(resources); |
| 1625 | |
| 1626 | disconnects = ec->connector_allocator & ~connected; |
| 1627 | if (disconnects) { |
| 1628 | wl_list_for_each_safe(output, next, &ec->base.output_list, |
| 1629 | base.link) { |
| 1630 | if (x_offset != 0 || y_offset != 0) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1631 | weston_output_move(&output->base, |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1632 | output->base.x - x_offset, |
| 1633 | output->base.y - y_offset); |
| 1634 | } |
| 1635 | |
| 1636 | if (disconnects & (1 << output->connector_id)) { |
| 1637 | disconnects &= ~(1 << output->connector_id); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1638 | weston_log("connector %d disconnected\n", |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1639 | output->connector_id); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1640 | x_offset += output->base.width; |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 1641 | drm_output_destroy(&output->base); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | /* FIXME: handle zero outputs, without terminating */ |
| 1647 | if (ec->connector_allocator == 0) |
| 1648 | wl_display_terminate(ec->base.wl_display); |
| 1649 | } |
| 1650 | |
| 1651 | static int |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1652 | udev_event_is_hotplug(struct drm_compositor *ec, struct udev_device *device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1653 | { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1654 | const char *sysnum; |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 1655 | const char *val; |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1656 | |
| 1657 | sysnum = udev_device_get_sysnum(device); |
| 1658 | if (!sysnum || atoi(sysnum) != ec->drm.id) |
| 1659 | return 0; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1660 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 1661 | val = udev_device_get_property_value(device, "HOTPLUG"); |
| 1662 | if (!val) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1663 | return 0; |
| 1664 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 1665 | return strcmp(val, "1") == 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1666 | } |
| 1667 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1668 | static int |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1669 | udev_drm_event(int fd, uint32_t mask, void *data) |
| 1670 | { |
| 1671 | struct drm_compositor *ec = data; |
| 1672 | struct udev_device *event; |
| 1673 | |
| 1674 | event = udev_monitor_receive_device(ec->udev_monitor); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1675 | |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 1676 | if (udev_event_is_hotplug(ec, event)) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1677 | update_outputs(ec, event); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1678 | |
| 1679 | udev_device_unref(event); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1680 | |
| 1681 | return 1; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1684 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1685 | drm_restore(struct weston_compositor *ec) |
| 1686 | { |
| 1687 | struct drm_compositor *d = (struct drm_compositor *) ec; |
| 1688 | |
| 1689 | if (weston_launcher_drm_set_master(&d->base, d->drm.fd, 0) < 0) |
| 1690 | weston_log("failed to drop master: %m\n"); |
| 1691 | tty_reset(d->tty); |
| 1692 | } |
| 1693 | |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1694 | static const char default_seat[] = "seat0"; |
| 1695 | |
| 1696 | static void |
| 1697 | device_added(struct udev_device *udev_device, struct drm_seat *master) |
| 1698 | { |
| 1699 | struct weston_compositor *c; |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1700 | struct evdev_device *device; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1701 | const char *devnode; |
| 1702 | const char *device_seat; |
| 1703 | int fd; |
| 1704 | |
| 1705 | device_seat = udev_device_get_property_value(udev_device, "ID_SEAT"); |
| 1706 | if (!device_seat) |
| 1707 | device_seat = default_seat; |
| 1708 | |
| 1709 | if (strcmp(device_seat, master->seat_id)) |
| 1710 | return; |
| 1711 | |
| 1712 | c = master->base.compositor; |
| 1713 | devnode = udev_device_get_devnode(udev_device); |
| 1714 | |
| 1715 | /* Use non-blocking mode so that we can loop on read on |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1716 | * evdev_device_data() until all events on the fd are |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1717 | * read. mtdev_get() also expects this. */ |
| 1718 | fd = weston_launcher_open(c, devnode, O_RDWR | O_NONBLOCK); |
| 1719 | if (fd < 0) { |
| 1720 | weston_log("opening input device '%s' failed.\n", devnode); |
| 1721 | return; |
| 1722 | } |
| 1723 | |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1724 | device = evdev_device_create(&master->base, devnode, fd); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1725 | if (!device) { |
| 1726 | close(fd); |
| 1727 | weston_log("not using input device '%s'.\n", devnode); |
| 1728 | return; |
| 1729 | } |
| 1730 | |
| 1731 | wl_list_insert(master->devices_list.prev, &device->link); |
| 1732 | } |
| 1733 | |
| 1734 | static void |
| 1735 | evdev_add_devices(struct udev *udev, struct weston_seat *seat_base) |
| 1736 | { |
| 1737 | struct drm_seat *seat = (struct drm_seat *) seat_base; |
| 1738 | struct udev_enumerate *e; |
| 1739 | struct udev_list_entry *entry; |
| 1740 | struct udev_device *device; |
| 1741 | const char *path, *sysname; |
| 1742 | |
| 1743 | e = udev_enumerate_new(udev); |
| 1744 | udev_enumerate_add_match_subsystem(e, "input"); |
| 1745 | udev_enumerate_scan_devices(e); |
| 1746 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 1747 | path = udev_list_entry_get_name(entry); |
| 1748 | device = udev_device_new_from_syspath(udev, path); |
| 1749 | |
| 1750 | sysname = udev_device_get_sysname(device); |
| 1751 | if (strncmp("event", sysname, 5) != 0) { |
| 1752 | udev_device_unref(device); |
| 1753 | continue; |
| 1754 | } |
| 1755 | |
| 1756 | device_added(device, seat); |
| 1757 | |
| 1758 | udev_device_unref(device); |
| 1759 | } |
| 1760 | udev_enumerate_unref(e); |
| 1761 | |
| 1762 | evdev_notify_keyboard_focus(&seat->base, &seat->devices_list); |
| 1763 | |
| 1764 | if (wl_list_empty(&seat->devices_list)) { |
| 1765 | weston_log( |
| 1766 | "warning: no input devices on entering Weston. " |
| 1767 | "Possible causes:\n" |
| 1768 | "\t- no permissions to read /dev/input/event*\n" |
| 1769 | "\t- seats misconfigured " |
| 1770 | "(Weston backend option 'seat', " |
| 1771 | "udev device property ID_SEAT)\n"); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | static int |
| 1776 | evdev_udev_handler(int fd, uint32_t mask, void *data) |
| 1777 | { |
Pekka Paalanen | d2e69c2 | 2012-08-03 14:39:08 +0300 | [diff] [blame] | 1778 | struct drm_seat *seat = data; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1779 | struct udev_device *udev_device; |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1780 | struct evdev_device *device, *next; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1781 | const char *action; |
| 1782 | const char *devnode; |
| 1783 | |
Pekka Paalanen | d2e69c2 | 2012-08-03 14:39:08 +0300 | [diff] [blame] | 1784 | udev_device = udev_monitor_receive_device(seat->udev_monitor); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1785 | if (!udev_device) |
| 1786 | return 1; |
| 1787 | |
| 1788 | action = udev_device_get_action(udev_device); |
Pekka Paalanen | d2e69c2 | 2012-08-03 14:39:08 +0300 | [diff] [blame] | 1789 | if (!action) |
| 1790 | goto out; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1791 | |
Pekka Paalanen | d2e69c2 | 2012-08-03 14:39:08 +0300 | [diff] [blame] | 1792 | if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0) |
| 1793 | goto out; |
| 1794 | |
| 1795 | if (!strcmp(action, "add")) { |
| 1796 | device_added(udev_device, seat); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1797 | } |
Pekka Paalanen | d2e69c2 | 2012-08-03 14:39:08 +0300 | [diff] [blame] | 1798 | else if (!strcmp(action, "remove")) { |
| 1799 | devnode = udev_device_get_devnode(udev_device); |
| 1800 | wl_list_for_each_safe(device, next, &seat->devices_list, link) |
| 1801 | if (!strcmp(device->devnode, devnode)) { |
Pekka Paalanen | 42b3f6a | 2012-08-03 14:39:09 +0300 | [diff] [blame] | 1802 | weston_log("input device %s, %s removed\n", |
| 1803 | device->devname, device->devnode); |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1804 | evdev_device_destroy(device); |
Pekka Paalanen | d2e69c2 | 2012-08-03 14:39:08 +0300 | [diff] [blame] | 1805 | break; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | out: |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1810 | udev_device_unref(udev_device); |
| 1811 | |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
| 1815 | static int |
| 1816 | evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base) |
| 1817 | { |
| 1818 | struct drm_seat *master = (struct drm_seat *) seat_base; |
| 1819 | struct wl_event_loop *loop; |
| 1820 | struct weston_compositor *c = master->base.compositor; |
| 1821 | int fd; |
| 1822 | |
| 1823 | master->udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); |
| 1824 | if (!master->udev_monitor) { |
| 1825 | weston_log("udev: failed to create the udev monitor\n"); |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
| 1829 | udev_monitor_filter_add_match_subsystem_devtype(master->udev_monitor, |
| 1830 | "input", NULL); |
| 1831 | |
| 1832 | if (udev_monitor_enable_receiving(master->udev_monitor)) { |
| 1833 | weston_log("udev: failed to bind the udev monitor\n"); |
| 1834 | udev_monitor_unref(master->udev_monitor); |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
| 1838 | loop = wl_display_get_event_loop(c->wl_display); |
| 1839 | fd = udev_monitor_get_fd(master->udev_monitor); |
| 1840 | master->udev_monitor_source = |
| 1841 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 1842 | evdev_udev_handler, master); |
| 1843 | if (!master->udev_monitor_source) { |
| 1844 | udev_monitor_unref(master->udev_monitor); |
| 1845 | return 0; |
| 1846 | } |
| 1847 | |
| 1848 | return 1; |
| 1849 | } |
| 1850 | |
| 1851 | static void |
| 1852 | evdev_disable_udev_monitor(struct weston_seat *seat_base) |
| 1853 | { |
| 1854 | struct drm_seat *seat = (struct drm_seat *) seat_base; |
| 1855 | |
| 1856 | if (!seat->udev_monitor) |
| 1857 | return; |
| 1858 | |
| 1859 | udev_monitor_unref(seat->udev_monitor); |
| 1860 | seat->udev_monitor = NULL; |
| 1861 | wl_event_source_remove(seat->udev_monitor_source); |
| 1862 | seat->udev_monitor_source = NULL; |
| 1863 | } |
| 1864 | |
| 1865 | static void |
| 1866 | drm_led_update(struct weston_seat *seat_base, enum weston_led leds) |
| 1867 | { |
| 1868 | struct drm_seat *seat = (struct drm_seat *) seat_base; |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1869 | struct evdev_device *device; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1870 | |
Pekka Paalanen | b9d38f4 | 2012-08-06 14:57:07 +0300 | [diff] [blame] | 1871 | wl_list_for_each(device, &seat->devices_list, link) |
| 1872 | evdev_led_update(device, leds); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | static void |
| 1876 | evdev_input_create(struct weston_compositor *c, struct udev *udev, |
| 1877 | const char *seat_id) |
| 1878 | { |
| 1879 | struct drm_seat *seat; |
| 1880 | |
| 1881 | seat = malloc(sizeof *seat); |
| 1882 | if (seat == NULL) |
| 1883 | return; |
| 1884 | |
| 1885 | memset(seat, 0, sizeof *seat); |
| 1886 | weston_seat_init(&seat->base, c); |
| 1887 | seat->base.led_update = drm_led_update; |
| 1888 | |
| 1889 | wl_list_init(&seat->devices_list); |
| 1890 | seat->seat_id = strdup(seat_id); |
| 1891 | if (!evdev_enable_udev_monitor(udev, &seat->base)) { |
| 1892 | free(seat->seat_id); |
| 1893 | free(seat); |
| 1894 | return; |
| 1895 | } |
| 1896 | |
| 1897 | evdev_add_devices(udev, &seat->base); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | static void |
| 1901 | evdev_remove_devices(struct weston_seat *seat_base) |
| 1902 | { |
| 1903 | struct drm_seat *seat = (struct drm_seat *) seat_base; |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1904 | struct evdev_device *device, *next; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1905 | |
| 1906 | wl_list_for_each_safe(device, next, &seat->devices_list, link) |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 1907 | evdev_device_destroy(device); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1908 | |
Pekka Paalanen | d858351 | 2012-08-03 14:39:11 +0300 | [diff] [blame] | 1909 | if (seat->base.seat.keyboard) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1910 | notify_keyboard_focus_out(&seat->base); |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | static void |
| 1914 | evdev_input_destroy(struct weston_seat *seat_base) |
| 1915 | { |
| 1916 | struct drm_seat *seat = (struct drm_seat *) seat_base; |
| 1917 | |
| 1918 | evdev_remove_devices(seat_base); |
| 1919 | evdev_disable_udev_monitor(&seat->base); |
| 1920 | |
| 1921 | weston_seat_release(seat_base); |
| 1922 | free(seat->seat_id); |
| 1923 | free(seat); |
| 1924 | } |
| 1925 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1926 | static void |
Scott Moreau | c50645c | 2012-07-31 22:29:56 -0600 | [diff] [blame] | 1927 | drm_free_configured_output(struct drm_configured_output *output) |
| 1928 | { |
| 1929 | free(output->name); |
| 1930 | free(output->mode); |
| 1931 | free(output); |
| 1932 | } |
| 1933 | |
| 1934 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1935 | drm_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1936 | { |
| 1937 | struct drm_compositor *d = (struct drm_compositor *) ec; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1938 | struct weston_seat *seat, *next; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1939 | struct drm_configured_output *o, *n; |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1940 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1941 | wl_list_for_each_safe(seat, next, &ec->seat_list, link) |
| 1942 | evdev_input_destroy(seat); |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 1943 | wl_list_for_each_safe(o, n, &configured_output_list, link) |
Scott Moreau | c50645c | 2012-07-31 22:29:56 -0600 | [diff] [blame] | 1944 | drm_free_configured_output(o); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 1945 | |
| 1946 | wl_event_source_remove(d->udev_drm_source); |
| 1947 | wl_event_source_remove(d->drm_source); |
| 1948 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1949 | weston_compositor_shutdown(ec); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 1950 | |
Kristian Høgsberg | 3a0de88 | 2012-09-06 21:44:24 -0400 | [diff] [blame] | 1951 | gles2_renderer_destroy(ec); |
| 1952 | |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1953 | destroy_sprites(d); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 1954 | gbm_device_destroy(d->gbm); |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 1955 | 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] | 1956 | weston_log("failed to drop master: %m\n"); |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 1957 | tty_destroy(d->tty); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1958 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 1959 | free(d); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1960 | } |
| 1961 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1962 | static void |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 1963 | drm_compositor_set_modes(struct drm_compositor *compositor) |
| 1964 | { |
| 1965 | struct drm_output *output; |
| 1966 | struct drm_mode *drm_mode; |
| 1967 | int ret; |
| 1968 | |
| 1969 | wl_list_for_each(output, &compositor->base.output_list, base.link) { |
| 1970 | drm_mode = (struct drm_mode *) output->base.current; |
| 1971 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 1972 | output->current->fb_id, 0, 0, |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 1973 | &output->connector_id, 1, |
| 1974 | &drm_mode->mode_info); |
| 1975 | if (ret < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1976 | weston_log( |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1977 | "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] | 1978 | drm_mode->base.width, drm_mode->base.height, |
| 1979 | output->base.x, output->base.y); |
| 1980 | } |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1985 | vt_func(struct weston_compositor *compositor, int event) |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1986 | { |
| 1987 | struct drm_compositor *ec = (struct drm_compositor *) compositor; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1988 | struct weston_seat *seat; |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 1989 | struct drm_sprite *sprite; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1990 | struct drm_output *output; |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1991 | |
| 1992 | switch (event) { |
| 1993 | case TTY_ENTER_VT: |
Pekka Paalanen | 81a13a3 | 2012-08-03 14:39:10 +0300 | [diff] [blame] | 1994 | weston_log("entering VT\n"); |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 1995 | compositor->focus = 1; |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 1996 | if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 1)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1997 | weston_log("failed to set master: %m\n"); |
Kristian Høgsberg | a018fb0 | 2012-01-16 10:52:52 -0500 | [diff] [blame] | 1998 | wl_display_terminate(compositor->wl_display); |
| 1999 | } |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2000 | compositor->state = ec->prev_state; |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2001 | drm_compositor_set_modes(ec); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2002 | weston_compositor_damage_all(compositor); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2003 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2004 | evdev_add_devices(ec->udev, seat); |
| 2005 | evdev_enable_udev_monitor(ec->udev, seat); |
Benjamin Franzke | 78d3afe | 2012-04-09 18:14:58 +0200 | [diff] [blame] | 2006 | } |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2007 | break; |
| 2008 | case TTY_LEAVE_VT: |
Pekka Paalanen | 81a13a3 | 2012-08-03 14:39:10 +0300 | [diff] [blame] | 2009 | weston_log("leaving VT\n"); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2010 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2011 | evdev_disable_udev_monitor(seat); |
| 2012 | evdev_remove_devices(seat); |
Kristian Høgsberg | 4014a6b | 2012-04-10 00:08:45 -0400 | [diff] [blame] | 2013 | } |
| 2014 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2015 | compositor->focus = 0; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2016 | ec->prev_state = compositor->state; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2017 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
Kristian Høgsberg | d8e181b | 2011-05-06 15:38:28 -0400 | [diff] [blame] | 2018 | |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2019 | /* If we have a repaint scheduled (either from a |
| 2020 | * pending pageflip or the idle handler), make sure we |
| 2021 | * cancel that so we don't try to pageflip when we're |
| 2022 | * vt switched away. The SLEEPING state will prevent |
| 2023 | * further attemps at repainting. When we switch |
| 2024 | * back, we schedule a repaint, which will process |
| 2025 | * pending frame callbacks. */ |
| 2026 | |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2027 | wl_list_for_each(output, &ec->base.output_list, base.link) { |
| 2028 | output->base.repaint_needed = 0; |
| 2029 | drmModeSetCursor(ec->drm.fd, output->crtc_id, 0, 0, 0); |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2030 | } |
| 2031 | |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2032 | output = container_of(ec->base.output_list.next, |
| 2033 | struct drm_output, base.link); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2034 | |
| 2035 | wl_list_for_each(sprite, &ec->sprite_list, link) |
| 2036 | drmModeSetPlane(ec->drm.fd, |
| 2037 | sprite->plane_id, |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2038 | output->crtc_id, 0, 0, |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2039 | 0, 0, 0, 0, 0, 0, 0, 0); |
| 2040 | |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 2041 | 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] | 2042 | weston_log("failed to drop master: %m\n"); |
Kristian Høgsberg | a018fb0 | 2012-01-16 10:52:52 -0500 | [diff] [blame] | 2043 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2044 | break; |
| 2045 | }; |
| 2046 | } |
| 2047 | |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2048 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2049 | 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] | 2050 | { |
| 2051 | struct drm_compositor *ec = data; |
| 2052 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2053 | tty_activate_vt(ec->tty, key - KEY_F1 + 1); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2054 | } |
| 2055 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2056 | /* |
| 2057 | * Find primary GPU |
| 2058 | * Some systems may have multiple DRM devices attached to a single seat. This |
| 2059 | * function loops over all devices and tries to find a PCI device with the |
| 2060 | * boot_vga sysfs attribute set to 1. |
| 2061 | * If no such device is found, the first DRM device reported by udev is used. |
| 2062 | */ |
| 2063 | static struct udev_device* |
| 2064 | find_primary_gpu(struct drm_compositor *ec, const char *seat) |
| 2065 | { |
| 2066 | struct udev_enumerate *e; |
| 2067 | struct udev_list_entry *entry; |
| 2068 | const char *path, *device_seat, *id; |
| 2069 | struct udev_device *device, *drm_device, *pci; |
| 2070 | |
| 2071 | e = udev_enumerate_new(ec->udev); |
| 2072 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 2073 | udev_enumerate_add_match_sysname(e, "card[0-9]*"); |
| 2074 | |
| 2075 | udev_enumerate_scan_devices(e); |
| 2076 | drm_device = NULL; |
| 2077 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 2078 | path = udev_list_entry_get_name(entry); |
| 2079 | device = udev_device_new_from_syspath(ec->udev, path); |
| 2080 | if (!device) |
| 2081 | continue; |
| 2082 | device_seat = udev_device_get_property_value(device, "ID_SEAT"); |
| 2083 | if (!device_seat) |
| 2084 | device_seat = default_seat; |
| 2085 | if (strcmp(device_seat, seat)) { |
| 2086 | udev_device_unref(device); |
| 2087 | continue; |
| 2088 | } |
| 2089 | |
| 2090 | pci = udev_device_get_parent_with_subsystem_devtype(device, |
| 2091 | "pci", NULL); |
| 2092 | if (pci) { |
| 2093 | id = udev_device_get_sysattr_value(pci, "boot_vga"); |
| 2094 | if (id && !strcmp(id, "1")) { |
| 2095 | if (drm_device) |
| 2096 | udev_device_unref(drm_device); |
| 2097 | drm_device = device; |
| 2098 | break; |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | if (!drm_device) |
| 2103 | drm_device = device; |
| 2104 | else |
| 2105 | udev_device_unref(device); |
| 2106 | } |
| 2107 | |
| 2108 | udev_enumerate_unref(e); |
| 2109 | return drm_device; |
| 2110 | } |
| 2111 | |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2112 | static void |
| 2113 | hide_sprites_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2114 | void *data) |
| 2115 | { |
| 2116 | struct drm_compositor *c = data; |
| 2117 | |
| 2118 | c->sprites_hidden ^= 1; |
| 2119 | } |
| 2120 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2121 | static struct weston_compositor * |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2122 | drm_compositor_create(struct wl_display *display, |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 2123 | int connector, const char *seat, int tty, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 2124 | int argc, char *argv[], const char *config_file) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2125 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2126 | struct drm_compositor *ec; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2127 | struct udev_device *drm_device; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2128 | struct wl_event_loop *loop; |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2129 | struct weston_seat *weston_seat, *next; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2130 | const char *path; |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2131 | uint32_t key; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2132 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2133 | weston_log("initializing drm backend\n"); |
| 2134 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2135 | ec = malloc(sizeof *ec); |
| 2136 | if (ec == NULL) |
| 2137 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2138 | memset(ec, 0, sizeof *ec); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2139 | |
Kristian Høgsberg | de37d67 | 2012-11-02 10:14:40 -0400 | [diff] [blame] | 2140 | /* KMS support for sprites is not complete yet, so disable the |
| 2141 | * functionality for now. */ |
| 2142 | ec->sprites_are_broken = 1; |
| 2143 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2144 | if (weston_compositor_init(&ec->base, display, argc, argv, |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2145 | config_file) < 0) { |
| 2146 | weston_log("weston_compositor_init failed\n"); |
| 2147 | goto err_base; |
| 2148 | } |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2149 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2150 | ec->udev = udev_new(); |
| 2151 | if (ec->udev == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2152 | weston_log("failed to initialize udev context\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2153 | goto err_compositor; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 2156 | ec->base.wl_display = display; |
| 2157 | ec->tty = tty_create(&ec->base, vt_func, tty); |
| 2158 | if (!ec->tty) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2159 | weston_log("failed to initialize tty\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2160 | goto err_udev; |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 2161 | } |
| 2162 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2163 | drm_device = find_primary_gpu(ec, seat); |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2164 | if (drm_device == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2165 | weston_log("no drm device found\n"); |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2166 | goto err_tty; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2167 | } |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2168 | path = udev_device_get_syspath(drm_device); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2169 | |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2170 | if (init_egl(ec, drm_device) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2171 | weston_log("failed to initialize egl\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2172 | goto err_udev_dev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2173 | } |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 2174 | |
| 2175 | ec->base.destroy = drm_destroy; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2176 | ec->base.restore = drm_restore; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 2177 | |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 2178 | ec->base.focus = 1; |
| 2179 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2180 | ec->prev_state = WESTON_COMPOSITOR_ACTIVE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2181 | |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2182 | for (key = KEY_F1; key < KEY_F9; key++) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2183 | weston_compositor_add_key_binding(&ec->base, key, |
| 2184 | MODIFIER_CTRL | MODIFIER_ALT, |
| 2185 | switch_vt_binding, ec); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2186 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2187 | wl_list_init(&ec->sprite_list); |
| 2188 | create_sprites(ec); |
| 2189 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2190 | if (create_outputs(ec, connector, drm_device) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2191 | weston_log("failed to create output for %s\n", path); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2192 | goto err_sprite; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2193 | } |
| 2194 | |
Benjamin Franzke | 02dee2c | 2011-10-07 08:27:26 +0200 | [diff] [blame] | 2195 | path = NULL; |
| 2196 | |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 2197 | evdev_input_create(&ec->base, ec->udev, seat); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2198 | |
| 2199 | loop = wl_display_get_event_loop(ec->base.wl_display); |
| 2200 | ec->drm_source = |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 2201 | wl_event_loop_add_fd(loop, ec->drm.fd, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2202 | WL_EVENT_READABLE, on_drm_input, ec); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2203 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2204 | ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev"); |
| 2205 | if (ec->udev_monitor == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2206 | weston_log("failed to intialize udev monitor\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2207 | goto err_drm_source; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2208 | } |
| 2209 | udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor, |
| 2210 | "drm", NULL); |
| 2211 | ec->udev_drm_source = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2212 | wl_event_loop_add_fd(loop, |
| 2213 | udev_monitor_get_fd(ec->udev_monitor), |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2214 | WL_EVENT_READABLE, udev_drm_event, ec); |
| 2215 | |
| 2216 | if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2217 | weston_log("failed to enable udev-monitor receiving\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2218 | goto err_udev_monitor; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2219 | } |
| 2220 | |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2221 | udev_device_unref(drm_device); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2222 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 2223 | weston_compositor_add_debug_binding(&ec->base, KEY_O, |
| 2224 | hide_sprites_binding, ec); |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2225 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2226 | return &ec->base; |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2227 | |
| 2228 | err_udev_monitor: |
| 2229 | wl_event_source_remove(ec->udev_drm_source); |
| 2230 | udev_monitor_unref(ec->udev_monitor); |
| 2231 | err_drm_source: |
| 2232 | wl_event_source_remove(ec->drm_source); |
| 2233 | wl_list_for_each_safe(weston_seat, next, &ec->base.seat_list, link) |
| 2234 | evdev_input_destroy(weston_seat); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 2235 | err_sprite: |
John Kåre Alsaker | 1b7ad16 | 2012-11-13 19:10:19 +0100 | [diff] [blame] | 2236 | gles2_renderer_destroy(&ec->base); |
| 2237 | gbm_device_destroy(ec->gbm); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 2238 | destroy_sprites(ec); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2239 | err_udev_dev: |
| 2240 | udev_device_unref(drm_device); |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2241 | err_tty: |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2242 | tty_destroy(ec->tty); |
| 2243 | err_udev: |
| 2244 | udev_unref(ec->udev); |
| 2245 | err_compositor: |
| 2246 | weston_compositor_shutdown(&ec->base); |
| 2247 | err_base: |
| 2248 | free(ec); |
| 2249 | return NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2250 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2251 | |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 2252 | static int |
| 2253 | set_sync_flags(drmModeModeInfo *mode, char *hsync, char *vsync) |
| 2254 | { |
| 2255 | mode->flags = 0; |
| 2256 | |
| 2257 | if (strcmp(hsync, "+hsync") == 0) |
| 2258 | mode->flags |= DRM_MODE_FLAG_PHSYNC; |
| 2259 | else if (strcmp(hsync, "-hsync") == 0) |
| 2260 | mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 2261 | else |
| 2262 | return -1; |
| 2263 | |
| 2264 | if (strcmp(vsync, "+vsync") == 0) |
| 2265 | mode->flags |= DRM_MODE_FLAG_PVSYNC; |
| 2266 | else if (strcmp(vsync, "-vsync") == 0) |
| 2267 | mode->flags |= DRM_MODE_FLAG_NVSYNC; |
| 2268 | else |
| 2269 | return -1; |
| 2270 | |
| 2271 | return 0; |
| 2272 | } |
| 2273 | |
| 2274 | static int |
| 2275 | check_for_modeline(struct drm_configured_output *output) |
| 2276 | { |
| 2277 | drmModeModeInfo mode; |
| 2278 | char hsync[16]; |
| 2279 | char vsync[16]; |
| 2280 | char mode_name[16]; |
| 2281 | float fclock; |
| 2282 | |
| 2283 | mode.type = DRM_MODE_TYPE_USERDEF; |
| 2284 | mode.hskew = 0; |
| 2285 | mode.vscan = 0; |
| 2286 | mode.vrefresh = 0; |
| 2287 | |
| 2288 | if (sscanf(output_mode, "%f %hd %hd %hd %hd %hd %hd %hd %hd %s %s", |
| 2289 | &fclock, &mode.hdisplay, |
| 2290 | &mode.hsync_start, |
| 2291 | &mode.hsync_end, &mode.htotal, |
| 2292 | &mode.vdisplay, |
| 2293 | &mode.vsync_start, |
| 2294 | &mode.vsync_end, &mode.vtotal, |
| 2295 | hsync, vsync) == 11) { |
| 2296 | if (set_sync_flags(&mode, hsync, vsync)) |
| 2297 | return -1; |
| 2298 | |
| 2299 | sprintf(mode_name, "%dx%d", mode.hdisplay, mode.vdisplay); |
| 2300 | strcpy(mode.name, mode_name); |
| 2301 | |
| 2302 | mode.clock = fclock * 1000; |
| 2303 | } else |
| 2304 | return -1; |
| 2305 | |
| 2306 | output->crtc_mode = mode; |
| 2307 | |
| 2308 | return 0; |
| 2309 | } |
| 2310 | |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2311 | static void |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2312 | drm_output_set_transform(struct drm_configured_output *output) |
| 2313 | { |
| 2314 | if (!output_transform) { |
| 2315 | output->transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 2316 | return; |
| 2317 | } |
| 2318 | |
| 2319 | if (!strcmp(output_transform, "normal")) |
| 2320 | output->transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 2321 | else if (!strcmp(output_transform, "90")) |
| 2322 | output->transform = WL_OUTPUT_TRANSFORM_90; |
| 2323 | else if (!strcmp(output_transform, "180")) |
| 2324 | output->transform = WL_OUTPUT_TRANSFORM_180; |
| 2325 | else if (!strcmp(output_transform, "270")) |
| 2326 | output->transform = WL_OUTPUT_TRANSFORM_270; |
| 2327 | else if (!strcmp(output_transform, "flipped")) |
| 2328 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED; |
| 2329 | else if (!strcmp(output_transform, "flipped-90")) |
| 2330 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_90; |
| 2331 | else if (!strcmp(output_transform, "flipped-180")) |
| 2332 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_180; |
| 2333 | else if (!strcmp(output_transform, "flipped-270")) |
| 2334 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_270; |
| 2335 | else { |
| 2336 | weston_log("Invalid transform \"%s\" for output %s\n", |
| 2337 | output_transform, output_name); |
| 2338 | output->transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 2339 | } |
| 2340 | |
| 2341 | free(output_transform); |
| 2342 | output_transform = NULL; |
| 2343 | } |
| 2344 | |
| 2345 | static void |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2346 | output_section_done(void *data) |
| 2347 | { |
| 2348 | struct drm_configured_output *output; |
| 2349 | |
| 2350 | output = malloc(sizeof *output); |
| 2351 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2352 | if (!output || !output_name || (output_name[0] == 'X') || |
| 2353 | (!output_mode && !output_transform)) { |
Kristian Høgsberg | 8ff6915 | 2012-07-31 22:18:28 -0400 | [diff] [blame] | 2354 | free(output_name); |
Kristian Høgsberg | 8ff6915 | 2012-07-31 22:18:28 -0400 | [diff] [blame] | 2355 | free(output_mode); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2356 | free(output_transform); |
Rob Bradford | 6b6795f | 2012-10-09 18:44:35 +0100 | [diff] [blame] | 2357 | free(output); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2358 | output_name = NULL; |
Kristian Høgsberg | 8ff6915 | 2012-07-31 22:18:28 -0400 | [diff] [blame] | 2359 | output_mode = NULL; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2360 | output_transform = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2361 | return; |
Kristian Høgsberg | 8ff6915 | 2012-07-31 22:18:28 -0400 | [diff] [blame] | 2362 | } |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2363 | |
| 2364 | output->config = OUTPUT_CONFIG_INVALID; |
| 2365 | output->name = output_name; |
| 2366 | output->mode = output_mode; |
| 2367 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2368 | if (output_mode) { |
| 2369 | if (strcmp(output_mode, "off") == 0) |
| 2370 | output->config = OUTPUT_CONFIG_OFF; |
| 2371 | else if (strcmp(output_mode, "preferred") == 0) |
| 2372 | output->config = OUTPUT_CONFIG_PREFERRED; |
| 2373 | else if (strcmp(output_mode, "current") == 0) |
| 2374 | output->config = OUTPUT_CONFIG_CURRENT; |
| 2375 | else if (sscanf(output_mode, "%dx%d", |
| 2376 | &output->width, &output->height) == 2) |
| 2377 | output->config = OUTPUT_CONFIG_MODE; |
| 2378 | else if (check_for_modeline(output) == 0) |
| 2379 | output->config = OUTPUT_CONFIG_MODELINE; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2380 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2381 | if (output->config == OUTPUT_CONFIG_INVALID) |
| 2382 | weston_log("Invalid mode \"%s\" for output %s\n", |
| 2383 | output_mode, output_name); |
| 2384 | output_mode = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2385 | } |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2386 | |
| 2387 | drm_output_set_transform(output); |
| 2388 | |
| 2389 | wl_list_insert(&configured_output_list, &output->link); |
| 2390 | |
| 2391 | if (output_transform) |
| 2392 | free(output_transform); |
| 2393 | output_transform = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2394 | } |
| 2395 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2396 | WL_EXPORT struct weston_compositor * |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 2397 | backend_init(struct wl_display *display, int argc, char *argv[], |
| 2398 | const char *config_file) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2399 | { |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2400 | int connector = 0, tty = 0; |
| 2401 | const char *seat = default_seat; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2402 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2403 | const struct weston_option drm_options[] = { |
| 2404 | { WESTON_OPTION_INTEGER, "connector", 0, &connector }, |
| 2405 | { WESTON_OPTION_STRING, "seat", 0, &seat }, |
| 2406 | { WESTON_OPTION_INTEGER, "tty", 0, &tty }, |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2407 | { WESTON_OPTION_BOOLEAN, "current-mode", 0, &option_current_mode }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2408 | }; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2409 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2410 | parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2411 | |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2412 | wl_list_init(&configured_output_list); |
| 2413 | |
| 2414 | const struct config_key drm_config_keys[] = { |
| 2415 | { "name", CONFIG_KEY_STRING, &output_name }, |
| 2416 | { "mode", CONFIG_KEY_STRING, &output_mode }, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2417 | { "transform", CONFIG_KEY_STRING, &output_transform }, |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2418 | }; |
| 2419 | |
| 2420 | const struct config_section config_section[] = { |
| 2421 | { "output", drm_config_keys, |
| 2422 | ARRAY_LENGTH(drm_config_keys), output_section_done }, |
| 2423 | }; |
| 2424 | |
| 2425 | parse_config_file(config_file, config_section, |
| 2426 | ARRAY_LENGTH(config_section), NULL); |
| 2427 | |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 2428 | return drm_compositor_create(display, connector, seat, tty, argc, argv, |
| 2429 | config_file); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2430 | } |