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