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