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 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 24 | #include "config.h" |
Kristian Høgsberg | 0b9334a | 2011-04-12 11:34:32 -0400 | [diff] [blame] | 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> |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 28 | #include <ctype.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 33 | #include <linux/vt.h> |
Ander Conselvan de Oliveira | fd1f4c6 | 2012-06-26 17:09:14 +0300 | [diff] [blame] | 34 | #include <assert.h> |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 35 | #include <sys/mman.h> |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 36 | #include <dlfcn.h> |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 37 | #include <time.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 38 | |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 39 | #include <xf86drm.h> |
| 40 | #include <xf86drmMode.h> |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 41 | #include <drm_fourcc.h> |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 42 | |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 43 | #include <gbm.h> |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 44 | #include <libudev.h> |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 45 | |
Kristian Høgsberg | 36d5fac | 2014-01-27 23:02:35 -0800 | [diff] [blame] | 46 | #include "libbacklight.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 47 | #include "compositor.h" |
John Kåre Alsaker | 30d2b1f | 2012-11-13 19:10:28 +0100 | [diff] [blame] | 48 | #include "gl-renderer.h" |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 49 | #include "pixman-renderer.h" |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 50 | #include "udev-input.h" |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 51 | #include "launcher-util.h" |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 52 | #include "vaapi-recorder.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 53 | |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 54 | #ifndef DRM_CAP_TIMESTAMP_MONOTONIC |
| 55 | #define DRM_CAP_TIMESTAMP_MONOTONIC 0x6 |
| 56 | #endif |
| 57 | |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 58 | #ifndef DRM_CAP_CURSOR_WIDTH |
| 59 | #define DRM_CAP_CURSOR_WIDTH 0x8 |
| 60 | #endif |
| 61 | |
| 62 | #ifndef DRM_CAP_CURSOR_HEIGHT |
| 63 | #define DRM_CAP_CURSOR_HEIGHT 0x9 |
| 64 | #endif |
| 65 | |
| 66 | #ifndef GBM_BO_USE_CURSOR |
| 67 | #define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64 |
| 68 | #endif |
| 69 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 70 | static int option_current_mode = 0; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 71 | |
| 72 | enum output_config { |
| 73 | OUTPUT_CONFIG_INVALID = 0, |
| 74 | OUTPUT_CONFIG_OFF, |
| 75 | OUTPUT_CONFIG_PREFERRED, |
| 76 | OUTPUT_CONFIG_CURRENT, |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 77 | OUTPUT_CONFIG_MODE, |
| 78 | OUTPUT_CONFIG_MODELINE |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 79 | }; |
| 80 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 81 | struct drm_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 82 | struct weston_compositor base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 83 | |
| 84 | struct udev *udev; |
| 85 | struct wl_event_source *drm_source; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 86 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 87 | struct udev_monitor *udev_monitor; |
| 88 | struct wl_event_source *udev_drm_source; |
| 89 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 90 | struct { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 91 | int id; |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 92 | int fd; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 93 | char *filename; |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 94 | } drm; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 95 | struct gbm_device *gbm; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 96 | uint32_t *crtcs; |
| 97 | int num_crtcs; |
Marty Jack | 13d9db2 | 2011-02-09 19:01:42 -0500 | [diff] [blame] | 98 | uint32_t crtc_allocator; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 99 | uint32_t connector_allocator; |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 100 | struct wl_listener session_listener; |
Kristian Høgsberg | c3ea26c | 2013-09-25 15:46:42 -0700 | [diff] [blame] | 101 | uint32_t format; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 102 | |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 103 | /* we need these parameters in order to not fail drmModeAddFB2() |
| 104 | * due to out of bounds dimensions, and then mistakenly set |
| 105 | * sprites_are_broken: |
| 106 | */ |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 107 | uint32_t min_width, max_width; |
| 108 | uint32_t min_height, max_height; |
| 109 | int no_addfb2; |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 110 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 111 | struct wl_list sprite_list; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 112 | int sprites_are_broken; |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 113 | int sprites_hidden; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 114 | |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 115 | int cursors_are_broken; |
| 116 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 117 | int use_pixman; |
| 118 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 119 | uint32_t prev_state; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 120 | |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 121 | struct udev_input input; |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 122 | |
| 123 | uint32_t cursor_width; |
| 124 | uint32_t cursor_height; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 125 | }; |
| 126 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 127 | struct drm_mode { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 128 | struct weston_mode base; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 129 | drmModeModeInfo mode_info; |
| 130 | }; |
| 131 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 132 | struct drm_output; |
| 133 | |
| 134 | struct drm_fb { |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 135 | struct drm_output *output; |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 136 | uint32_t fb_id, stride, handle, size; |
| 137 | int fd; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 138 | int is_client_buffer; |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 139 | struct weston_buffer_reference buffer_ref; |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 140 | |
| 141 | /* Used by gbm fbs */ |
| 142 | struct gbm_bo *bo; |
| 143 | |
| 144 | /* Used by dumb fbs */ |
| 145 | void *map; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 146 | }; |
| 147 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 148 | struct drm_edid { |
| 149 | char eisa_id[13]; |
| 150 | char monitor_name[13]; |
| 151 | char pnp_id[5]; |
| 152 | char serial_number[13]; |
| 153 | }; |
| 154 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 155 | struct drm_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 156 | struct weston_output base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 157 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 158 | uint32_t crtc_id; |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 159 | int pipe; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 160 | uint32_t connector_id; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 161 | drmModeCrtcPtr original_crtc; |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 162 | struct drm_edid edid; |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 163 | drmModePropertyPtr dpms_prop; |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 164 | uint32_t format; |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 165 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 166 | int vblank_pending; |
| 167 | int page_flip_pending; |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 168 | int destroy_pending; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 169 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 170 | struct gbm_surface *surface; |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 171 | struct gbm_bo *cursor_bo[2]; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 172 | struct weston_plane cursor_plane; |
| 173 | struct weston_plane fb_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 174 | struct weston_view *cursor_view; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 175 | int current_cursor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 176 | struct drm_fb *current, *next; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 177 | struct backlight *backlight; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 178 | |
| 179 | struct drm_fb *dumb[2]; |
| 180 | pixman_image_t *image[2]; |
| 181 | int current_image; |
| 182 | pixman_region32_t previous_damage; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 183 | |
| 184 | struct vaapi_recorder *recorder; |
| 185 | struct wl_listener recorder_frame_listener; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 186 | }; |
| 187 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 188 | /* |
| 189 | * An output has a primary display plane plus zero or more sprites for |
| 190 | * blending display contents. |
| 191 | */ |
| 192 | struct drm_sprite { |
| 193 | struct wl_list link; |
| 194 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 195 | struct weston_plane plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 196 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 197 | struct drm_fb *current, *next; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 198 | struct drm_output *output; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 199 | struct drm_compositor *compositor; |
| 200 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 201 | uint32_t possible_crtcs; |
| 202 | uint32_t plane_id; |
| 203 | uint32_t count_formats; |
| 204 | |
| 205 | int32_t src_x, src_y; |
| 206 | uint32_t src_w, src_h; |
| 207 | uint32_t dest_x, dest_y; |
| 208 | uint32_t dest_w, dest_h; |
| 209 | |
| 210 | uint32_t formats[]; |
| 211 | }; |
| 212 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 213 | struct drm_parameters { |
| 214 | int connector; |
| 215 | int tty; |
| 216 | int use_pixman; |
| 217 | const char *seat_id; |
| 218 | }; |
| 219 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 220 | static struct gl_renderer_interface *gl_renderer; |
| 221 | |
Kristian Høgsberg | 98cfea6 | 2013-02-18 16:15:53 -0500 | [diff] [blame] | 222 | static const char default_seat[] = "seat0"; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 223 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 224 | static void |
| 225 | drm_output_set_cursor(struct drm_output *output); |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 226 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 227 | static int |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 228 | drm_sprite_crtc_supported(struct weston_output *output_base, uint32_t supported) |
| 229 | { |
| 230 | struct weston_compositor *ec = output_base->compositor; |
| 231 | struct drm_compositor *c =(struct drm_compositor *) ec; |
| 232 | struct drm_output *output = (struct drm_output *) output_base; |
| 233 | int crtc; |
| 234 | |
| 235 | for (crtc = 0; crtc < c->num_crtcs; crtc++) { |
| 236 | if (c->crtcs[crtc] != output->crtc_id) |
| 237 | continue; |
| 238 | |
| 239 | if (supported & (1 << crtc)) |
| 240 | return -1; |
| 241 | } |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 246 | static void |
| 247 | drm_fb_destroy_callback(struct gbm_bo *bo, void *data) |
| 248 | { |
| 249 | struct drm_fb *fb = data; |
| 250 | struct gbm_device *gbm = gbm_bo_get_device(bo); |
| 251 | |
| 252 | if (fb->fb_id) |
| 253 | drmModeRmFB(gbm_device_get_fd(gbm), fb->fb_id); |
| 254 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 255 | weston_buffer_reference(&fb->buffer_ref, NULL); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 256 | |
| 257 | free(data); |
| 258 | } |
| 259 | |
| 260 | static struct drm_fb * |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 261 | drm_fb_create_dumb(struct drm_compositor *ec, unsigned width, unsigned height) |
| 262 | { |
| 263 | struct drm_fb *fb; |
| 264 | int ret; |
| 265 | |
| 266 | struct drm_mode_create_dumb create_arg; |
| 267 | struct drm_mode_destroy_dumb destroy_arg; |
| 268 | struct drm_mode_map_dumb map_arg; |
| 269 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 270 | fb = zalloc(sizeof *fb); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 271 | if (!fb) |
| 272 | return NULL; |
| 273 | |
Kristian Høgsberg | ac6104e | 2013-08-21 22:14:14 -0700 | [diff] [blame] | 274 | memset(&create_arg, 0, sizeof create_arg); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 275 | create_arg.bpp = 32; |
| 276 | create_arg.width = width; |
| 277 | create_arg.height = height; |
| 278 | |
| 279 | ret = drmIoctl(ec->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg); |
| 280 | if (ret) |
| 281 | goto err_fb; |
| 282 | |
| 283 | fb->handle = create_arg.handle; |
| 284 | fb->stride = create_arg.pitch; |
| 285 | fb->size = create_arg.size; |
| 286 | fb->fd = ec->drm.fd; |
| 287 | |
| 288 | ret = drmModeAddFB(ec->drm.fd, width, height, 24, 32, |
| 289 | fb->stride, fb->handle, &fb->fb_id); |
| 290 | if (ret) |
| 291 | goto err_bo; |
| 292 | |
Kristian Høgsberg | ac6104e | 2013-08-21 22:14:14 -0700 | [diff] [blame] | 293 | memset(&map_arg, 0, sizeof map_arg); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 294 | map_arg.handle = fb->handle; |
Chris Michael | eb2074a | 2013-05-01 21:26:02 -0400 | [diff] [blame] | 295 | ret = drmIoctl(fb->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 296 | if (ret) |
| 297 | goto err_add_fb; |
| 298 | |
| 299 | fb->map = mmap(0, fb->size, PROT_WRITE, |
| 300 | MAP_SHARED, ec->drm.fd, map_arg.offset); |
| 301 | if (fb->map == MAP_FAILED) |
| 302 | goto err_add_fb; |
| 303 | |
| 304 | return fb; |
| 305 | |
| 306 | err_add_fb: |
| 307 | drmModeRmFB(ec->drm.fd, fb->fb_id); |
| 308 | err_bo: |
| 309 | memset(&destroy_arg, 0, sizeof(destroy_arg)); |
| 310 | destroy_arg.handle = create_arg.handle; |
| 311 | drmIoctl(ec->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg); |
| 312 | err_fb: |
| 313 | free(fb); |
| 314 | return NULL; |
| 315 | } |
| 316 | |
| 317 | static void |
| 318 | drm_fb_destroy_dumb(struct drm_fb *fb) |
| 319 | { |
| 320 | struct drm_mode_destroy_dumb destroy_arg; |
| 321 | |
| 322 | if (!fb->map) |
| 323 | return; |
| 324 | |
| 325 | if (fb->fb_id) |
| 326 | drmModeRmFB(fb->fd, fb->fb_id); |
| 327 | |
| 328 | weston_buffer_reference(&fb->buffer_ref, NULL); |
| 329 | |
| 330 | munmap(fb->map, fb->size); |
| 331 | |
| 332 | memset(&destroy_arg, 0, sizeof(destroy_arg)); |
| 333 | destroy_arg.handle = fb->handle; |
| 334 | drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg); |
| 335 | |
| 336 | free(fb); |
| 337 | } |
| 338 | |
| 339 | static struct drm_fb * |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 340 | drm_fb_get_from_bo(struct gbm_bo *bo, |
| 341 | struct drm_compositor *compositor, uint32_t format) |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 342 | { |
| 343 | struct drm_fb *fb = gbm_bo_get_user_data(bo); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 344 | uint32_t width, height; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 345 | uint32_t handles[4], pitches[4], offsets[4]; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 346 | int ret; |
| 347 | |
| 348 | if (fb) |
| 349 | return fb; |
| 350 | |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 351 | fb = calloc(1, sizeof *fb); |
| 352 | if (!fb) |
| 353 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 354 | |
| 355 | fb->bo = bo; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 356 | |
| 357 | width = gbm_bo_get_width(bo); |
| 358 | height = gbm_bo_get_height(bo); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 359 | fb->stride = gbm_bo_get_stride(bo); |
| 360 | fb->handle = gbm_bo_get_handle(bo).u32; |
| 361 | fb->size = fb->stride * height; |
| 362 | fb->fd = compositor->drm.fd; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 363 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 364 | if (compositor->min_width > width || width > compositor->max_width || |
| 365 | compositor->min_height > height || |
| 366 | height > compositor->max_height) { |
| 367 | weston_log("bo geometry out of bounds\n"); |
| 368 | goto err_free; |
| 369 | } |
| 370 | |
| 371 | ret = -1; |
| 372 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 373 | if (format && !compositor->no_addfb2) { |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 374 | handles[0] = fb->handle; |
| 375 | pitches[0] = fb->stride; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 376 | offsets[0] = 0; |
| 377 | |
| 378 | ret = drmModeAddFB2(compositor->drm.fd, width, height, |
| 379 | format, handles, pitches, offsets, |
| 380 | &fb->fb_id, 0); |
| 381 | if (ret) { |
| 382 | weston_log("addfb2 failed: %m\n"); |
| 383 | compositor->no_addfb2 = 1; |
| 384 | compositor->sprites_are_broken = 1; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (ret) |
| 389 | ret = drmModeAddFB(compositor->drm.fd, width, height, 24, 32, |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 390 | fb->stride, fb->handle, &fb->fb_id); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 391 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 392 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 393 | weston_log("failed to create kms fb: %m\n"); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 394 | goto err_free; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback); |
| 398 | |
| 399 | return fb; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 400 | |
| 401 | err_free: |
| 402 | free(fb); |
| 403 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 407 | drm_fb_set_buffer(struct drm_fb *fb, struct weston_buffer *buffer) |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 408 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 409 | assert(fb->buffer_ref.buffer == NULL); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 410 | |
| 411 | fb->is_client_buffer = 1; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 412 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 413 | weston_buffer_reference(&fb->buffer_ref, buffer); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 416 | static void |
| 417 | drm_output_release_fb(struct drm_output *output, struct drm_fb *fb) |
| 418 | { |
| 419 | if (!fb) |
| 420 | return; |
| 421 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 422 | if (fb->map && |
| 423 | (fb != output->dumb[0] && fb != output->dumb[1])) { |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 424 | drm_fb_destroy_dumb(fb); |
| 425 | } else if (fb->bo) { |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 426 | if (fb->is_client_buffer) |
| 427 | gbm_bo_destroy(fb->bo); |
| 428 | else |
| 429 | gbm_surface_release_buffer(output->surface, |
Jason Ekstrand | 3ec57f5 | 2013-11-14 20:52:35 -0600 | [diff] [blame] | 430 | fb->bo); |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 434 | static uint32_t |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 435 | drm_output_check_scanout_format(struct drm_output *output, |
| 436 | struct weston_surface *es, struct gbm_bo *bo) |
| 437 | { |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 438 | uint32_t format; |
| 439 | pixman_region32_t r; |
| 440 | |
| 441 | format = gbm_bo_get_format(bo); |
| 442 | |
Kristian Høgsberg | 3f97b34 | 2013-10-16 16:08:57 -0700 | [diff] [blame] | 443 | if (format == GBM_FORMAT_ARGB8888) { |
| 444 | /* We can scanout an ARGB buffer if the surface's |
| 445 | * opaque region covers the whole output, but we have |
| 446 | * to use XRGB as the KMS format code. */ |
Kristian Høgsberg | 1be87e3 | 2014-01-17 14:22:41 -0800 | [diff] [blame] | 447 | pixman_region32_init_rect(&r, 0, 0, |
| 448 | output->base.width, |
| 449 | output->base.height); |
| 450 | pixman_region32_subtract(&r, &r, &es->opaque); |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 451 | |
| 452 | if (!pixman_region32_not_empty(&r)) |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 453 | format = GBM_FORMAT_XRGB8888; |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 454 | |
| 455 | pixman_region32_fini(&r); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 456 | } |
Kristian Høgsberg | 3f97b34 | 2013-10-16 16:08:57 -0700 | [diff] [blame] | 457 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 458 | if (output->format == format) |
Kristian Høgsberg | 3f97b34 | 2013-10-16 16:08:57 -0700 | [diff] [blame] | 459 | return format; |
| 460 | |
| 461 | return 0; |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 464 | static struct weston_plane * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 465 | drm_output_prepare_scanout_view(struct weston_output *_output, |
| 466 | struct weston_view *ev) |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 467 | { |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 468 | struct drm_output *output = (struct drm_output *) _output; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 469 | struct drm_compositor *c = |
| 470 | (struct drm_compositor *) output->base.compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 471 | struct weston_buffer *buffer = ev->surface->buffer_ref.buffer; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 472 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 473 | struct gbm_bo *bo; |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 474 | uint32_t format; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 475 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 476 | if (ev->geometry.x != output->base.x || |
| 477 | ev->geometry.y != output->base.y || |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 478 | buffer == NULL || c->gbm == NULL || |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 479 | buffer->width != output->base.current_mode->width || |
| 480 | buffer->height != output->base.current_mode->height || |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 481 | output->base.transform != viewport->buffer.transform || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 482 | ev->transform.enabled) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 483 | return NULL; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 484 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 485 | bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER, |
Kristian Høgsberg | 6399646 | 2013-09-03 22:27:08 -0700 | [diff] [blame] | 486 | buffer->resource, GBM_BO_USE_SCANOUT); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 487 | |
Rob Bradford | 9b10187 | 2012-09-14 23:25:41 +0100 | [diff] [blame] | 488 | /* Unable to use the buffer for scanout */ |
| 489 | if (!bo) |
| 490 | return NULL; |
| 491 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 492 | format = drm_output_check_scanout_format(output, ev->surface, bo); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 493 | if (format == 0) { |
Ander Conselvan de Oliveira | a64b15d | 2012-05-02 16:42:22 +0300 | [diff] [blame] | 494 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 495 | return NULL; |
Ander Conselvan de Oliveira | a64b15d | 2012-05-02 16:42:22 +0300 | [diff] [blame] | 496 | } |
| 497 | |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 498 | output->next = drm_fb_get_from_bo(bo, c, format); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 499 | if (!output->next) { |
| 500 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 501 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 502 | } |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 503 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 504 | drm_fb_set_buffer(output->next, buffer); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 505 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 506 | return &output->fb_plane; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 507 | } |
| 508 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 509 | static void |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 510 | drm_output_render_gl(struct drm_output *output, pixman_region32_t *damage) |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 511 | { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 512 | struct drm_compositor *c = |
| 513 | (struct drm_compositor *) output->base.compositor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 514 | struct gbm_bo *bo; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 515 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 516 | c->base.renderer->repaint_output(&output->base, damage); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 517 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 518 | bo = gbm_surface_lock_front_buffer(output->surface); |
| 519 | if (!bo) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 520 | weston_log("failed to lock front buffer: %m\n"); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 521 | return; |
| 522 | } |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 523 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 524 | output->next = drm_fb_get_from_bo(bo, c, output->format); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 525 | if (!output->next) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 526 | weston_log("failed to get drm_fb for bo\n"); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 527 | gbm_surface_release_buffer(output->surface, bo); |
| 528 | return; |
| 529 | } |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static void |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 533 | drm_output_render_pixman(struct drm_output *output, pixman_region32_t *damage) |
| 534 | { |
| 535 | struct weston_compositor *ec = output->base.compositor; |
| 536 | pixman_region32_t total_damage, previous_damage; |
| 537 | |
| 538 | pixman_region32_init(&total_damage); |
| 539 | pixman_region32_init(&previous_damage); |
| 540 | |
| 541 | pixman_region32_copy(&previous_damage, damage); |
| 542 | |
| 543 | pixman_region32_union(&total_damage, damage, &output->previous_damage); |
| 544 | pixman_region32_copy(&output->previous_damage, &previous_damage); |
| 545 | |
| 546 | output->current_image ^= 1; |
| 547 | |
| 548 | output->next = output->dumb[output->current_image]; |
| 549 | pixman_renderer_output_set_buffer(&output->base, |
| 550 | output->image[output->current_image]); |
| 551 | |
| 552 | ec->renderer->repaint_output(&output->base, &total_damage); |
| 553 | |
| 554 | pixman_region32_fini(&total_damage); |
| 555 | pixman_region32_fini(&previous_damage); |
| 556 | } |
| 557 | |
| 558 | static void |
| 559 | drm_output_render(struct drm_output *output, pixman_region32_t *damage) |
| 560 | { |
| 561 | struct drm_compositor *c = |
| 562 | (struct drm_compositor *) output->base.compositor; |
| 563 | |
| 564 | if (c->use_pixman) |
| 565 | drm_output_render_pixman(output, damage); |
| 566 | else |
| 567 | drm_output_render_gl(output, damage); |
| 568 | |
| 569 | pixman_region32_subtract(&c->base.primary_plane.damage, |
| 570 | &c->base.primary_plane.damage, damage); |
| 571 | } |
| 572 | |
| 573 | static void |
Richard Hughes | e729996 | 2013-05-01 21:52:12 +0100 | [diff] [blame] | 574 | drm_output_set_gamma(struct weston_output *output_base, |
| 575 | uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) |
| 576 | { |
| 577 | int rc; |
| 578 | struct drm_output *output = (struct drm_output *) output_base; |
| 579 | struct drm_compositor *compositor = (struct drm_compositor *) output->base.compositor; |
| 580 | |
| 581 | /* check */ |
| 582 | if (output_base->gamma_size != size) |
| 583 | return; |
| 584 | if (!output->original_crtc) |
| 585 | return; |
| 586 | |
| 587 | rc = drmModeCrtcSetGamma(compositor->drm.fd, |
| 588 | output->crtc_id, |
| 589 | size, r, g, b); |
| 590 | if (rc) |
| 591 | weston_log("set gamma failed: %m\n"); |
| 592 | } |
| 593 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 594 | static int |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 595 | drm_output_repaint(struct weston_output *output_base, |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 596 | pixman_region32_t *damage) |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 597 | { |
| 598 | struct drm_output *output = (struct drm_output *) output_base; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 599 | struct drm_compositor *compositor = |
| 600 | (struct drm_compositor *) output->base.compositor; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 601 | struct drm_sprite *s; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 602 | struct drm_mode *mode; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 603 | int ret = 0; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 604 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 605 | if (output->destroy_pending) |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 606 | return -1; |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 607 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 608 | if (!output->next) |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 609 | drm_output_render(output, damage); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 610 | if (!output->next) |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 611 | return -1; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 612 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 613 | mode = container_of(output->base.current_mode, struct drm_mode, base); |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 614 | if (!output->current || |
| 615 | output->current->stride != output->next->stride) { |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 616 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 617 | output->next->fb_id, 0, 0, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 618 | &output->connector_id, 1, |
| 619 | &mode->mode_info); |
| 620 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 621 | weston_log("set mode failed: %m\n"); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 622 | goto err_pageflip; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 623 | } |
Ander Conselvan de Oliveira | 722a2d5 | 2013-06-04 16:24:05 +0300 | [diff] [blame] | 624 | output_base->set_dpms(output_base, WESTON_DPMS_ON); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 625 | } |
| 626 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 627 | if (drmModePageFlip(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 628 | output->next->fb_id, |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 629 | DRM_MODE_PAGE_FLIP_EVENT, output) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 630 | weston_log("queueing pageflip failed: %m\n"); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 631 | goto err_pageflip; |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 632 | } |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 633 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 634 | output->page_flip_pending = 1; |
| 635 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 636 | drm_output_set_cursor(output); |
| 637 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 638 | /* |
| 639 | * Now, update all the sprite surfaces |
| 640 | */ |
| 641 | wl_list_for_each(s, &compositor->sprite_list, link) { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 642 | uint32_t flags = 0, fb_id = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 643 | drmVBlank vbl = { |
| 644 | .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT, |
| 645 | .request.sequence = 1, |
| 646 | }; |
| 647 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 648 | if ((!s->current && !s->next) || |
Ander Conselvan de Oliveira | 2f7a30b | 2012-11-09 14:19:03 +0200 | [diff] [blame] | 649 | !drm_sprite_crtc_supported(output_base, s->possible_crtcs)) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 650 | continue; |
| 651 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 652 | if (s->next && !compositor->sprites_hidden) |
| 653 | fb_id = s->next->fb_id; |
| 654 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 655 | ret = drmModeSetPlane(compositor->drm.fd, s->plane_id, |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 656 | output->crtc_id, fb_id, flags, |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 657 | s->dest_x, s->dest_y, |
| 658 | s->dest_w, s->dest_h, |
| 659 | s->src_x, s->src_y, |
| 660 | s->src_w, s->src_h); |
| 661 | if (ret) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 662 | weston_log("setplane failed: %d: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 663 | ret, strerror(errno)); |
| 664 | |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 665 | if (output->pipe > 0) |
| 666 | vbl.request.type |= DRM_VBLANK_SECONDARY; |
| 667 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 668 | /* |
| 669 | * Queue a vblank signal so we know when the surface |
| 670 | * becomes active on the display or has been replaced. |
| 671 | */ |
| 672 | vbl.request.signal = (unsigned long)s; |
| 673 | ret = drmWaitVBlank(compositor->drm.fd, &vbl); |
| 674 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 675 | weston_log("vblank event request failed: %d: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 676 | ret, strerror(errno)); |
| 677 | } |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 678 | |
| 679 | s->output = output; |
| 680 | output->vblank_pending = 1; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 681 | } |
| 682 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 683 | return 0; |
| 684 | |
| 685 | err_pageflip: |
Kristian Høgsberg | b3955b0 | 2014-01-23 16:25:06 -0800 | [diff] [blame] | 686 | output->cursor_view = NULL; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 687 | if (output->next) { |
| 688 | drm_output_release_fb(output, output->next); |
| 689 | output->next = NULL; |
| 690 | } |
| 691 | |
| 692 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 696 | drm_output_start_repaint_loop(struct weston_output *output_base) |
| 697 | { |
| 698 | struct drm_output *output = (struct drm_output *) output_base; |
| 699 | struct drm_compositor *compositor = (struct drm_compositor *) |
| 700 | output_base->compositor; |
| 701 | uint32_t fb_id; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 702 | struct timespec ts; |
| 703 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 704 | if (output->destroy_pending) |
| 705 | return; |
| 706 | |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 707 | if (!output->current) { |
| 708 | /* We can't page flip if there's no mode set */ |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 709 | goto finish_frame; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | fb_id = output->current->fb_id; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 713 | |
| 714 | if (drmModePageFlip(compositor->drm.fd, output->crtc_id, fb_id, |
| 715 | DRM_MODE_PAGE_FLIP_EVENT, output) < 0) { |
| 716 | weston_log("queueing pageflip failed: %m\n"); |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 717 | goto finish_frame; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 718 | } |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 719 | |
| 720 | return; |
| 721 | |
| 722 | finish_frame: |
| 723 | /* if we cannot page-flip, immediately finish frame */ |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 724 | clock_gettime(compositor->base.presentation_clock, &ts); |
| 725 | weston_output_finish_frame(output_base, &ts); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static void |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 729 | vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, |
| 730 | void *data) |
| 731 | { |
| 732 | struct drm_sprite *s = (struct drm_sprite *)data; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 733 | struct drm_output *output = s->output; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 734 | struct timespec ts; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 735 | |
| 736 | output->vblank_pending = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 737 | |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 738 | drm_output_release_fb(output, s->current); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 739 | s->current = s->next; |
| 740 | s->next = NULL; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 741 | |
| 742 | if (!output->page_flip_pending) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 743 | ts.tv_sec = sec; |
| 744 | ts.tv_nsec = usec * 1000; |
| 745 | weston_output_finish_frame(&output->base, &ts); |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 746 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | static void |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 750 | drm_output_destroy(struct weston_output *output_base); |
| 751 | |
| 752 | static void |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 753 | page_flip_handler(int fd, unsigned int frame, |
| 754 | unsigned int sec, unsigned int usec, void *data) |
| 755 | { |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 756 | struct drm_output *output = (struct drm_output *) data; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 757 | struct timespec ts; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 758 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 759 | /* We don't set page_flip_pending on start_repaint_loop, in that case |
| 760 | * we just want to page flip to the current buffer to get an accurate |
| 761 | * timestamp */ |
| 762 | if (output->page_flip_pending) { |
| 763 | drm_output_release_fb(output, output->current); |
| 764 | output->current = output->next; |
| 765 | output->next = NULL; |
| 766 | } |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 767 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 768 | output->page_flip_pending = 0; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 769 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 770 | if (output->destroy_pending) |
| 771 | drm_output_destroy(&output->base); |
| 772 | else if (!output->vblank_pending) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 773 | ts.tv_sec = sec; |
| 774 | ts.tv_nsec = usec * 1000; |
| 775 | weston_output_finish_frame(&output->base, &ts); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 776 | |
| 777 | /* We can't call this from frame_notify, because the output's |
| 778 | * repaint needed flag is cleared just after that */ |
| 779 | if (output->recorder) |
| 780 | weston_output_schedule_repaint(&output->base); |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 781 | } |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 782 | } |
| 783 | |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 784 | static uint32_t |
| 785 | drm_output_check_sprite_format(struct drm_sprite *s, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 786 | struct weston_view *ev, struct gbm_bo *bo) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 787 | { |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 788 | uint32_t i, format; |
| 789 | |
| 790 | format = gbm_bo_get_format(bo); |
| 791 | |
| 792 | if (format == GBM_FORMAT_ARGB8888) { |
| 793 | pixman_region32_t r; |
| 794 | |
Kristian Høgsberg | 63093a3 | 2013-03-01 14:29:16 -0500 | [diff] [blame] | 795 | pixman_region32_init_rect(&r, 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 796 | ev->surface->width, |
| 797 | ev->surface->height); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 798 | pixman_region32_subtract(&r, &r, &ev->surface->opaque); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 799 | |
| 800 | if (!pixman_region32_not_empty(&r)) |
| 801 | format = GBM_FORMAT_XRGB8888; |
| 802 | |
| 803 | pixman_region32_fini(&r); |
| 804 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 805 | |
| 806 | for (i = 0; i < s->count_formats; i++) |
| 807 | if (s->formats[i] == format) |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 808 | return format; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 814 | drm_view_transform_supported(struct weston_view *ev) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 815 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 816 | return !ev->transform.enabled || |
| 817 | (ev->transform.matrix.type < WESTON_MATRIX_TRANSFORM_ROTATE); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 818 | } |
| 819 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 820 | static struct weston_plane * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 821 | drm_output_prepare_overlay_view(struct weston_output *output_base, |
| 822 | struct weston_view *ev) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 823 | { |
| 824 | struct weston_compositor *ec = output_base->compositor; |
| 825 | struct drm_compositor *c =(struct drm_compositor *) ec; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 826 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 827 | struct drm_sprite *s; |
| 828 | int found = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 829 | struct gbm_bo *bo; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 830 | pixman_region32_t dest_rect, src_rect; |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 831 | pixman_box32_t *box, tbox; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 832 | uint32_t format; |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 833 | wl_fixed_t sx1, sy1, sx2, sy2; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 834 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 835 | if (c->gbm == NULL) |
| 836 | return NULL; |
| 837 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 838 | if (viewport->buffer.transform != output_base->transform) |
Ander Conselvan de Oliveira | 2908a3d | 2012-11-27 17:03:43 +0200 | [diff] [blame] | 839 | return NULL; |
| 840 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 841 | if (viewport->buffer.scale != output_base->current_scale) |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 842 | return NULL; |
| 843 | |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 844 | if (c->sprites_are_broken) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 845 | return NULL; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 846 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 847 | if (ev->output_mask != (1u << output_base->id)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 848 | return NULL; |
Ander Conselvan de Oliveira | d450b19 | 2012-06-26 17:09:12 +0300 | [diff] [blame] | 849 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 850 | if (ev->surface->buffer_ref.buffer == NULL) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 851 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 852 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 853 | if (ev->alpha != 1.0f) |
Ville Syrjälä | 5a84f31 | 2012-11-16 11:48:46 +0200 | [diff] [blame] | 854 | return NULL; |
| 855 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 856 | if (wl_shm_buffer_get(ev->surface->buffer_ref.buffer->resource)) |
Rob Clark | 702ffae | 2012-08-09 14:18:27 -0500 | [diff] [blame] | 857 | return NULL; |
| 858 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 859 | if (!drm_view_transform_supported(ev)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 860 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 861 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 862 | wl_list_for_each(s, &c->sprite_list, link) { |
| 863 | if (!drm_sprite_crtc_supported(output_base, s->possible_crtcs)) |
| 864 | continue; |
| 865 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 866 | if (!s->next) { |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 867 | found = 1; |
| 868 | break; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /* No sprites available */ |
| 873 | if (!found) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 874 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 875 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 876 | bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 877 | ev->surface->buffer_ref.buffer->resource, |
Kristian Høgsberg | 6399646 | 2013-09-03 22:27:08 -0700 | [diff] [blame] | 878 | GBM_BO_USE_SCANOUT); |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 879 | if (!bo) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 880 | return NULL; |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 881 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 882 | format = drm_output_check_sprite_format(s, ev, bo); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 883 | if (format == 0) { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 884 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 885 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 886 | } |
| 887 | |
Ander Conselvan de Oliveira | ca5c6ae | 2012-12-07 13:18:11 +0200 | [diff] [blame] | 888 | s->next = drm_fb_get_from_bo(bo, c, format); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 889 | if (!s->next) { |
| 890 | gbm_bo_destroy(bo); |
| 891 | return NULL; |
| 892 | } |
| 893 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 894 | drm_fb_set_buffer(s->next, ev->surface->buffer_ref.buffer); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 895 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 896 | box = pixman_region32_extents(&ev->transform.boundingbox); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 897 | s->plane.x = box->x1; |
| 898 | s->plane.y = box->y1; |
| 899 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 900 | /* |
| 901 | * Calculate the source & dest rects properly based on actual |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 902 | * position (note the caller has called weston_view_update_transform() |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 903 | * for us already). |
| 904 | */ |
| 905 | pixman_region32_init(&dest_rect); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 906 | pixman_region32_intersect(&dest_rect, &ev->transform.boundingbox, |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 907 | &output_base->region); |
| 908 | pixman_region32_translate(&dest_rect, -output_base->x, -output_base->y); |
| 909 | box = pixman_region32_extents(&dest_rect); |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 910 | tbox = weston_transformed_rect(output_base->width, |
| 911 | output_base->height, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 912 | output_base->transform, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 913 | output_base->current_scale, |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 914 | *box); |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 915 | s->dest_x = tbox.x1; |
| 916 | s->dest_y = tbox.y1; |
| 917 | s->dest_w = tbox.x2 - tbox.x1; |
| 918 | s->dest_h = tbox.y2 - tbox.y1; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 919 | pixman_region32_fini(&dest_rect); |
| 920 | |
| 921 | pixman_region32_init(&src_rect); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 922 | pixman_region32_intersect(&src_rect, &ev->transform.boundingbox, |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 923 | &output_base->region); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 924 | box = pixman_region32_extents(&src_rect); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 925 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 926 | weston_view_from_global_fixed(ev, |
| 927 | wl_fixed_from_int(box->x1), |
| 928 | wl_fixed_from_int(box->y1), |
| 929 | &sx1, &sy1); |
| 930 | weston_view_from_global_fixed(ev, |
| 931 | wl_fixed_from_int(box->x2), |
| 932 | wl_fixed_from_int(box->y2), |
| 933 | &sx2, &sy2); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 934 | |
| 935 | if (sx1 < 0) |
| 936 | sx1 = 0; |
| 937 | if (sy1 < 0) |
| 938 | sy1 = 0; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 939 | if (sx2 > wl_fixed_from_int(ev->surface->width)) |
| 940 | sx2 = wl_fixed_from_int(ev->surface->width); |
| 941 | if (sy2 > wl_fixed_from_int(ev->surface->height)) |
| 942 | sy2 = wl_fixed_from_int(ev->surface->height); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 943 | |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 944 | tbox.x1 = sx1; |
| 945 | tbox.y1 = sy1; |
| 946 | tbox.x2 = sx2; |
| 947 | tbox.y2 = sy2; |
| 948 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 949 | tbox = weston_transformed_rect(wl_fixed_from_int(ev->surface->width), |
| 950 | wl_fixed_from_int(ev->surface->height), |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 951 | viewport->buffer.transform, |
| 952 | viewport->buffer.scale, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 953 | tbox); |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 954 | |
| 955 | s->src_x = tbox.x1 << 8; |
| 956 | s->src_y = tbox.y1 << 8; |
| 957 | s->src_w = (tbox.x2 - tbox.x1) << 8; |
| 958 | s->src_h = (tbox.y2 - tbox.y1) << 8; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 959 | pixman_region32_fini(&src_rect); |
| 960 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 961 | return &s->plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 962 | } |
| 963 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 964 | static struct weston_plane * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 965 | drm_output_prepare_cursor_view(struct weston_output *output_base, |
| 966 | struct weston_view *ev) |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 967 | { |
Kristian Høgsberg | 8a01580 | 2012-08-09 17:19:23 -0400 | [diff] [blame] | 968 | struct drm_compositor *c = |
| 969 | (struct drm_compositor *) output_base->compositor; |
Neil Roberts | f37f82c | 2014-05-01 18:00:41 +0100 | [diff] [blame] | 970 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 971 | struct drm_output *output = (struct drm_output *) output_base; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 972 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 973 | if (c->gbm == NULL) |
| 974 | return NULL; |
Ander Conselvan de Oliveira | 2908a3d | 2012-11-27 17:03:43 +0200 | [diff] [blame] | 975 | if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL) |
| 976 | return NULL; |
Neil Roberts | f37f82c | 2014-05-01 18:00:41 +0100 | [diff] [blame] | 977 | if (viewport->buffer.scale != output_base->current_scale) |
| 978 | return NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 979 | if (output->cursor_view) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 980 | return NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 981 | if (ev->output_mask != (1u << output_base->id)) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 982 | return NULL; |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 983 | if (c->cursors_are_broken) |
Kristian Høgsberg | 8a01580 | 2012-08-09 17:19:23 -0400 | [diff] [blame] | 984 | return NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 985 | if (ev->surface->buffer_ref.buffer == NULL || |
| 986 | !wl_shm_buffer_get(ev->surface->buffer_ref.buffer->resource) || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 987 | ev->surface->width > 64 || ev->surface->height > 64) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 988 | return NULL; |
| 989 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 990 | output->cursor_view = ev; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 991 | |
| 992 | return &output->cursor_plane; |
| 993 | } |
| 994 | |
| 995 | static void |
| 996 | drm_output_set_cursor(struct drm_output *output) |
| 997 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 998 | struct weston_view *ev = output->cursor_view; |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 999 | struct weston_buffer *buffer; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1000 | struct drm_compositor *c = |
| 1001 | (struct drm_compositor *) output->base.compositor; |
| 1002 | EGLint handle, stride; |
| 1003 | struct gbm_bo *bo; |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1004 | uint32_t buf[c->cursor_width * c->cursor_height]; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1005 | unsigned char *s; |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 1006 | int i, x, y; |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1007 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1008 | output->cursor_view = NULL; |
| 1009 | if (ev == NULL) { |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1010 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
| 1011 | return; |
| 1012 | } |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1013 | |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1014 | buffer = ev->surface->buffer_ref.buffer; |
| 1015 | |
| 1016 | if (buffer && |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1017 | pixman_region32_not_empty(&output->cursor_plane.damage)) { |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1018 | pixman_region32_fini(&output->cursor_plane.damage); |
| 1019 | pixman_region32_init(&output->cursor_plane.damage); |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 1020 | output->current_cursor ^= 1; |
| 1021 | bo = output->cursor_bo[output->current_cursor]; |
| 1022 | memset(buf, 0, sizeof buf); |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1023 | stride = wl_shm_buffer_get_stride(buffer->shm_buffer); |
| 1024 | s = wl_shm_buffer_get_data(buffer->shm_buffer); |
| 1025 | wl_shm_buffer_begin_access(buffer->shm_buffer); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1026 | for (i = 0; i < ev->surface->height; i++) |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1027 | memcpy(buf + i * c->cursor_width, s + i * stride, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1028 | ev->surface->width * 4); |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1029 | wl_shm_buffer_end_access(buffer->shm_buffer); |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1030 | |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 1031 | if (gbm_bo_write(bo, buf, sizeof buf) < 0) |
Pekka Paalanen | ae29da2 | 2012-08-06 14:57:05 +0300 | [diff] [blame] | 1032 | weston_log("failed update cursor: %m\n"); |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1033 | |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 1034 | handle = gbm_bo_get_handle(bo).s32; |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1035 | if (drmModeSetCursor(c->drm.fd, output->crtc_id, handle, |
| 1036 | c->cursor_width, c->cursor_height)) { |
Pekka Paalanen | ae29da2 | 2012-08-06 14:57:05 +0300 | [diff] [blame] | 1037 | weston_log("failed to set cursor: %m\n"); |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1038 | c->cursors_are_broken = 1; |
| 1039 | } |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1042 | x = (ev->geometry.x - output->base.x) * output->base.current_scale; |
| 1043 | y = (ev->geometry.y - output->base.y) * output->base.current_scale; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1044 | if (output->cursor_plane.x != x || output->cursor_plane.y != y) { |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1045 | if (drmModeMoveCursor(c->drm.fd, output->crtc_id, x, y)) { |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 1046 | weston_log("failed to move cursor: %m\n"); |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1047 | c->cursors_are_broken = 1; |
| 1048 | } |
| 1049 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1050 | output->cursor_plane.x = x; |
| 1051 | output->cursor_plane.y = y; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1052 | } |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1053 | } |
| 1054 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1055 | static void |
| 1056 | drm_assign_planes(struct weston_output *output) |
| 1057 | { |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1058 | struct drm_compositor *c = |
| 1059 | (struct drm_compositor *) output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1060 | struct weston_view *ev, *next; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1061 | pixman_region32_t overlap, surface_overlap; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1062 | struct weston_plane *primary, *next_plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1063 | |
| 1064 | /* |
| 1065 | * Find a surface for each sprite in the output using some heuristics: |
| 1066 | * 1) size |
| 1067 | * 2) frequency of update |
| 1068 | * 3) opacity (though some hw might support alpha blending) |
| 1069 | * 4) clipping (this can be fixed with color keys) |
| 1070 | * |
| 1071 | * The idea is to save on blitting since this should save power. |
| 1072 | * If we can get a large video surface on the sprite for example, |
| 1073 | * the main display surface may not need to update at all, and |
| 1074 | * the client buffer can be used directly for the sprite surface |
| 1075 | * as we do for flipping full screen surfaces. |
| 1076 | */ |
| 1077 | pixman_region32_init(&overlap); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1078 | primary = &c->base.primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1079 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1080 | wl_list_for_each_safe(ev, next, &c->base.view_list, link) { |
Ander Conselvan de Oliveira | 895b1fd | 2013-11-19 15:22:05 +0200 | [diff] [blame] | 1081 | struct weston_surface *es = ev->surface; |
| 1082 | |
| 1083 | /* Test whether this buffer can ever go into a plane: |
| 1084 | * non-shm, or small enough to be a cursor. |
| 1085 | * |
| 1086 | * Also, keep a reference when using the pixman renderer. |
| 1087 | * That makes it possible to do a seamless switch to the GL |
| 1088 | * renderer and since the pixman renderer keeps a reference |
| 1089 | * to the buffer anyway, there is no side effects. |
Pekka Paalanen | ccfeae2 | 2012-12-04 15:58:14 +0200 | [diff] [blame] | 1090 | */ |
Ander Conselvan de Oliveira | 895b1fd | 2013-11-19 15:22:05 +0200 | [diff] [blame] | 1091 | if (c->use_pixman || |
| 1092 | (es->buffer_ref.buffer && |
| 1093 | (!wl_shm_buffer_get(es->buffer_ref.buffer->resource) || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1094 | (ev->surface->width <= 64 && ev->surface->height <= 64)))) |
Ander Conselvan de Oliveira | 895b1fd | 2013-11-19 15:22:05 +0200 | [diff] [blame] | 1095 | es->keep_buffer = 1; |
| 1096 | else |
| 1097 | es->keep_buffer = 0; |
Pekka Paalanen | ccfeae2 | 2012-12-04 15:58:14 +0200 | [diff] [blame] | 1098 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1099 | pixman_region32_init(&surface_overlap); |
| 1100 | pixman_region32_intersect(&surface_overlap, &overlap, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1101 | &ev->transform.boundingbox); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1102 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1103 | next_plane = NULL; |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 1104 | if (pixman_region32_not_empty(&surface_overlap)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1105 | next_plane = primary; |
| 1106 | if (next_plane == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1107 | next_plane = drm_output_prepare_cursor_view(output, ev); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1108 | if (next_plane == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1109 | next_plane = drm_output_prepare_scanout_view(output, ev); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1110 | if (next_plane == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1111 | next_plane = drm_output_prepare_overlay_view(output, ev); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1112 | if (next_plane == NULL) |
| 1113 | next_plane = primary; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1114 | weston_view_move_to_plane(ev, next_plane); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1115 | if (next_plane == primary) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1116 | pixman_region32_union(&overlap, &overlap, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1117 | &ev->transform.boundingbox); |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 1118 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1119 | pixman_region32_fini(&surface_overlap); |
| 1120 | } |
| 1121 | pixman_region32_fini(&overlap); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1122 | } |
| 1123 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1124 | static void |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1125 | drm_output_fini_pixman(struct drm_output *output); |
| 1126 | |
| 1127 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1128 | drm_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1129 | { |
| 1130 | struct drm_output *output = (struct drm_output *) output_base; |
| 1131 | struct drm_compositor *c = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1132 | (struct drm_compositor *) output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1133 | drmModeCrtcPtr origcrtc = output->original_crtc; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1134 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 1135 | if (output->page_flip_pending) { |
| 1136 | output->destroy_pending = 1; |
| 1137 | weston_log("destroy output while page flip pending\n"); |
| 1138 | return; |
| 1139 | } |
| 1140 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1141 | if (output->backlight) |
| 1142 | backlight_destroy(output->backlight); |
| 1143 | |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 1144 | drmModeFreeProperty(output->dpms_prop); |
| 1145 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1146 | /* Turn off hardware cursor */ |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1147 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1148 | |
| 1149 | /* Restore original CRTC state */ |
| 1150 | drmModeSetCrtc(c->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id, |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1151 | origcrtc->x, origcrtc->y, |
| 1152 | &output->connector_id, 1, &origcrtc->mode); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1153 | drmModeFreeCrtc(origcrtc); |
| 1154 | |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 1155 | c->crtc_allocator &= ~(1 << output->crtc_id); |
| 1156 | c->connector_allocator &= ~(1 << output->connector_id); |
| 1157 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1158 | if (c->use_pixman) { |
| 1159 | drm_output_fini_pixman(output); |
| 1160 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1161 | gl_renderer->output_destroy(output_base); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1162 | gbm_surface_destroy(output->surface); |
| 1163 | } |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1164 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1165 | weston_plane_release(&output->fb_plane); |
| 1166 | weston_plane_release(&output->cursor_plane); |
| 1167 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1168 | weston_output_destroy(&output->base); |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 1169 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1170 | free(output); |
| 1171 | } |
| 1172 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1173 | static struct drm_mode * |
| 1174 | choose_mode (struct drm_output *output, struct weston_mode *target_mode) |
| 1175 | { |
| 1176 | struct drm_mode *tmp_mode = NULL, *mode; |
| 1177 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1178 | if (output->base.current_mode->width == target_mode->width && |
| 1179 | output->base.current_mode->height == target_mode->height && |
| 1180 | (output->base.current_mode->refresh == target_mode->refresh || |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1181 | target_mode->refresh == 0)) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1182 | return (struct drm_mode *)output->base.current_mode; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1183 | |
| 1184 | wl_list_for_each(mode, &output->base.mode_list, base.link) { |
| 1185 | if (mode->mode_info.hdisplay == target_mode->width && |
| 1186 | mode->mode_info.vdisplay == target_mode->height) { |
| 1187 | if (mode->mode_info.vrefresh == target_mode->refresh || |
| 1188 | target_mode->refresh == 0) { |
| 1189 | return mode; |
| 1190 | } else if (!tmp_mode) |
| 1191 | tmp_mode = mode; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | return tmp_mode; |
| 1196 | } |
| 1197 | |
| 1198 | static int |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1199 | drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1200 | static int |
| 1201 | drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c); |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1202 | |
| 1203 | static int |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1204 | drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode) |
| 1205 | { |
| 1206 | struct drm_output *output; |
| 1207 | struct drm_mode *drm_mode; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1208 | struct drm_compositor *ec; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1209 | |
| 1210 | if (output_base == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1211 | weston_log("output is NULL.\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1212 | return -1; |
| 1213 | } |
| 1214 | |
| 1215 | if (mode == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1216 | weston_log("mode is NULL.\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1217 | return -1; |
| 1218 | } |
| 1219 | |
| 1220 | ec = (struct drm_compositor *)output_base->compositor; |
| 1221 | output = (struct drm_output *)output_base; |
| 1222 | drm_mode = choose_mode (output, mode); |
| 1223 | |
| 1224 | if (!drm_mode) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1225 | 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] | 1226 | return -1; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1229 | if (&drm_mode->base == output->base.current_mode) |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1230 | return 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1231 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1232 | output->base.current_mode->flags = 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1233 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1234 | output->base.current_mode = &drm_mode->base; |
| 1235 | output->base.current_mode->flags = |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1236 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 1237 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1238 | /* reset rendering stuff. */ |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 1239 | drm_output_release_fb(output, output->current); |
| 1240 | drm_output_release_fb(output, output->next); |
| 1241 | output->current = output->next = NULL; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1242 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1243 | if (ec->use_pixman) { |
| 1244 | drm_output_fini_pixman(output); |
| 1245 | if (drm_output_init_pixman(output, ec) < 0) { |
| 1246 | weston_log("failed to init output pixman state with " |
| 1247 | "new mode\n"); |
| 1248 | return -1; |
| 1249 | } |
| 1250 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1251 | gl_renderer->output_destroy(&output->base); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1252 | gbm_surface_destroy(output->surface); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1253 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1254 | if (drm_output_init_egl(output, ec) < 0) { |
| 1255 | weston_log("failed to init output egl state with " |
| 1256 | "new mode"); |
| 1257 | return -1; |
| 1258 | } |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1259 | } |
| 1260 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1261 | return 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1264 | static int |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1265 | on_drm_input(int fd, uint32_t mask, void *data) |
| 1266 | { |
| 1267 | drmEventContext evctx; |
| 1268 | |
| 1269 | memset(&evctx, 0, sizeof evctx); |
| 1270 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 1271 | evctx.page_flip_handler = page_flip_handler; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1272 | evctx.vblank_handler = vblank_handler; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1273 | drmHandleEvent(fd, &evctx); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1274 | |
| 1275 | return 1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | static int |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1279 | init_drm(struct drm_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1280 | { |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 1281 | const char *filename, *sysnum; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 1282 | uint64_t cap; |
| 1283 | int fd, ret; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 1284 | clockid_t clk_id; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1285 | |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1286 | sysnum = udev_device_get_sysnum(device); |
| 1287 | if (sysnum) |
| 1288 | ec->drm.id = atoi(sysnum); |
| 1289 | if (!sysnum || ec->drm.id < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1290 | weston_log("cannot get device sysnum\n"); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1291 | return -1; |
| 1292 | } |
| 1293 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1294 | filename = udev_device_get_devnode(device); |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 1295 | fd = weston_launcher_open(ec->base.launcher, filename, O_RDWR); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1296 | if (fd < 0) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1297 | /* Probably permissions error */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1298 | weston_log("couldn't open %s, skipping\n", |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1299 | udev_device_get_devnode(device)); |
| 1300 | return -1; |
| 1301 | } |
| 1302 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1303 | weston_log("using %s\n", filename); |
| 1304 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1305 | ec->drm.fd = fd; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 1306 | ec->drm.filename = strdup(filename); |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1307 | |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 1308 | ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap); |
| 1309 | if (ret == 0 && cap == 1) |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 1310 | clk_id = CLOCK_MONOTONIC; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 1311 | else |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame^] | 1312 | clk_id = CLOCK_REALTIME; |
| 1313 | |
| 1314 | if (weston_compositor_set_presentation_clock(&ec->base, clk_id) < 0) { |
| 1315 | weston_log("Error: failed to set presentation clock %d.\n", |
| 1316 | clk_id); |
| 1317 | return -1; |
| 1318 | } |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 1319 | |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1320 | ret = drmGetCap(fd, DRM_CAP_CURSOR_WIDTH, &cap); |
| 1321 | if (ret == 0) |
| 1322 | ec->cursor_width = cap; |
| 1323 | else |
| 1324 | ec->cursor_width = 64; |
| 1325 | |
| 1326 | ret = drmGetCap(fd, DRM_CAP_CURSOR_HEIGHT, &cap); |
| 1327 | if (ret == 0) |
| 1328 | ec->cursor_height = cap; |
| 1329 | else |
| 1330 | ec->cursor_height = 64; |
| 1331 | |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1332 | return 0; |
| 1333 | } |
| 1334 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1335 | static struct gbm_device * |
| 1336 | create_gbm_device(int fd) |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1337 | { |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1338 | struct gbm_device *gbm; |
Alexandru DAMIAN | be0ac5b | 2013-10-02 17:51:05 +0100 | [diff] [blame] | 1339 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1340 | gl_renderer = weston_load_module("gl-renderer.so", |
| 1341 | "gl_renderer_interface"); |
| 1342 | if (!gl_renderer) |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1343 | return NULL; |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1344 | |
| 1345 | /* GBM will load a dri driver, but even though they need symbols from |
| 1346 | * libglapi, in some version of Mesa they are not linked to it. Since |
| 1347 | * only the gl-renderer module links to it, the call above won't make |
| 1348 | * these symbols globally available, and loading the DRI driver fails. |
| 1349 | * Workaround this by dlopen()'ing libglapi with RTLD_GLOBAL. */ |
| 1350 | dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL); |
| 1351 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1352 | gbm = gbm_create_device(fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1353 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1354 | return gbm; |
| 1355 | } |
| 1356 | |
| 1357 | static int |
| 1358 | drm_compositor_create_gl_renderer(struct drm_compositor *ec) |
| 1359 | { |
| 1360 | EGLint format; |
John Kåre Alsaker | ef591aa | 2013-03-02 12:27:39 +0100 | [diff] [blame] | 1361 | |
Alexandru DAMIAN | be0ac5b | 2013-10-02 17:51:05 +0100 | [diff] [blame] | 1362 | format = ec->format; |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1363 | if (gl_renderer->create(&ec->base, ec->gbm, |
| 1364 | gl_renderer->opaque_attribs, &format) < 0) { |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1365 | return -1; |
| 1366 | } |
| 1367 | |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | static int |
| 1372 | init_egl(struct drm_compositor *ec) |
| 1373 | { |
| 1374 | ec->gbm = create_gbm_device(ec->drm.fd); |
| 1375 | |
| 1376 | if (!ec->gbm) |
| 1377 | return -1; |
| 1378 | |
| 1379 | if (drm_compositor_create_gl_renderer(ec) < 0) { |
John Kåre Alsaker | 1b7ad16 | 2012-11-13 19:10:19 +0100 | [diff] [blame] | 1380 | gbm_device_destroy(ec->gbm); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1381 | return -1; |
| 1382 | } |
| 1383 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1384 | return 0; |
| 1385 | } |
| 1386 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1387 | static int |
| 1388 | init_pixman(struct drm_compositor *ec) |
| 1389 | { |
| 1390 | return pixman_renderer_init(&ec->base); |
| 1391 | } |
| 1392 | |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1393 | static struct drm_mode * |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1394 | drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info) |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1395 | { |
| 1396 | struct drm_mode *mode; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 1397 | uint64_t refresh; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1398 | |
| 1399 | mode = malloc(sizeof *mode); |
| 1400 | if (mode == NULL) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1401 | return NULL; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1402 | |
| 1403 | mode->base.flags = 0; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1404 | mode->base.width = info->hdisplay; |
| 1405 | mode->base.height = info->vdisplay; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 1406 | |
| 1407 | /* Calculate higher precision (mHz) refresh rate */ |
| 1408 | refresh = (info->clock * 1000000LL / info->htotal + |
| 1409 | info->vtotal / 2) / info->vtotal; |
| 1410 | |
| 1411 | if (info->flags & DRM_MODE_FLAG_INTERLACE) |
| 1412 | refresh *= 2; |
| 1413 | if (info->flags & DRM_MODE_FLAG_DBLSCAN) |
| 1414 | refresh /= 2; |
| 1415 | if (info->vscan > 1) |
| 1416 | refresh /= info->vscan; |
| 1417 | |
| 1418 | mode->base.refresh = refresh; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1419 | mode->mode_info = *info; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1420 | |
| 1421 | if (info->type & DRM_MODE_TYPE_PREFERRED) |
| 1422 | mode->base.flags |= WL_OUTPUT_MODE_PREFERRED; |
| 1423 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1424 | wl_list_insert(output->base.mode_list.prev, &mode->base.link); |
| 1425 | |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1426 | return mode; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | static int |
| 1430 | drm_subpixel_to_wayland(int drm_value) |
| 1431 | { |
| 1432 | switch (drm_value) { |
| 1433 | default: |
| 1434 | case DRM_MODE_SUBPIXEL_UNKNOWN: |
| 1435 | return WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 1436 | case DRM_MODE_SUBPIXEL_NONE: |
| 1437 | return WL_OUTPUT_SUBPIXEL_NONE; |
| 1438 | case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB: |
| 1439 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB; |
| 1440 | case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR: |
| 1441 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR; |
| 1442 | case DRM_MODE_SUBPIXEL_VERTICAL_RGB: |
| 1443 | return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB; |
| 1444 | case DRM_MODE_SUBPIXEL_VERTICAL_BGR: |
| 1445 | return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR; |
| 1446 | } |
| 1447 | } |
| 1448 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1449 | /* returns a value between 0-255 range, where higher is brighter */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1450 | static uint32_t |
| 1451 | drm_get_backlight(struct drm_output *output) |
| 1452 | { |
| 1453 | long brightness, max_brightness, norm; |
| 1454 | |
| 1455 | brightness = backlight_get_brightness(output->backlight); |
| 1456 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 1457 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1458 | /* convert it on a scale of 0 to 255 */ |
| 1459 | norm = (brightness * 255)/(max_brightness); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1460 | |
| 1461 | return (uint32_t) norm; |
| 1462 | } |
| 1463 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1464 | /* values accepted are between 0-255 range */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1465 | static void |
| 1466 | drm_set_backlight(struct weston_output *output_base, uint32_t value) |
| 1467 | { |
| 1468 | struct drm_output *output = (struct drm_output *) output_base; |
| 1469 | long max_brightness, new_brightness; |
| 1470 | |
| 1471 | if (!output->backlight) |
| 1472 | return; |
| 1473 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1474 | if (value > 255) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1475 | return; |
| 1476 | |
| 1477 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 1478 | |
| 1479 | /* get denormalized value */ |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1480 | new_brightness = (value * max_brightness) / 255; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1481 | |
| 1482 | backlight_set_brightness(output->backlight, new_brightness); |
| 1483 | } |
| 1484 | |
| 1485 | static drmModePropertyPtr |
| 1486 | drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name) |
| 1487 | { |
| 1488 | drmModePropertyPtr props; |
| 1489 | int i; |
| 1490 | |
| 1491 | for (i = 0; i < connector->count_props; i++) { |
| 1492 | props = drmModeGetProperty(fd, connector->props[i]); |
| 1493 | if (!props) |
| 1494 | continue; |
| 1495 | |
| 1496 | if (!strcmp(props->name, name)) |
| 1497 | return props; |
| 1498 | |
| 1499 | drmModeFreeProperty(props); |
| 1500 | } |
| 1501 | |
| 1502 | return NULL; |
| 1503 | } |
| 1504 | |
| 1505 | static void |
| 1506 | drm_set_dpms(struct weston_output *output_base, enum dpms_enum level) |
| 1507 | { |
| 1508 | struct drm_output *output = (struct drm_output *) output_base; |
| 1509 | struct weston_compositor *ec = output_base->compositor; |
| 1510 | struct drm_compositor *c = (struct drm_compositor *) ec; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1511 | |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 1512 | if (!output->dpms_prop) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1513 | return; |
| 1514 | |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 1515 | drmModeConnectorSetProperty(c->drm.fd, output->connector_id, |
| 1516 | output->dpms_prop->prop_id, level); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1517 | } |
| 1518 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1519 | static const char *connector_type_names[] = { |
| 1520 | "None", |
| 1521 | "VGA", |
| 1522 | "DVI", |
| 1523 | "DVI", |
| 1524 | "DVI", |
| 1525 | "Composite", |
| 1526 | "TV", |
| 1527 | "LVDS", |
| 1528 | "CTV", |
| 1529 | "DIN", |
| 1530 | "DP", |
| 1531 | "HDMI", |
| 1532 | "HDMI", |
| 1533 | "TV", |
| 1534 | "eDP", |
| 1535 | }; |
| 1536 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1537 | static int |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1538 | find_crtc_for_connector(struct drm_compositor *ec, |
| 1539 | drmModeRes *resources, drmModeConnector *connector) |
| 1540 | { |
| 1541 | drmModeEncoder *encoder; |
| 1542 | uint32_t possible_crtcs; |
| 1543 | int i, j; |
| 1544 | |
| 1545 | for (j = 0; j < connector->count_encoders; j++) { |
| 1546 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[j]); |
| 1547 | if (encoder == NULL) { |
| 1548 | weston_log("Failed to get encoder.\n"); |
| 1549 | return -1; |
| 1550 | } |
| 1551 | possible_crtcs = encoder->possible_crtcs; |
| 1552 | drmModeFreeEncoder(encoder); |
| 1553 | |
| 1554 | for (i = 0; i < resources->count_crtcs; i++) { |
| 1555 | if (possible_crtcs & (1 << i) && |
| 1556 | !(ec->crtc_allocator & (1 << resources->crtcs[i]))) |
| 1557 | return i; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | return -1; |
| 1562 | } |
| 1563 | |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1564 | /* Init output state that depends on gl or gbm */ |
| 1565 | static int |
| 1566 | drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec) |
| 1567 | { |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1568 | EGLint format = output->format; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1569 | int i, flags; |
| 1570 | |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1571 | output->surface = gbm_surface_create(ec->gbm, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1572 | output->base.current_mode->width, |
| 1573 | output->base.current_mode->height, |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1574 | format, |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1575 | GBM_BO_USE_SCANOUT | |
| 1576 | GBM_BO_USE_RENDERING); |
| 1577 | if (!output->surface) { |
| 1578 | weston_log("failed to create gbm surface\n"); |
| 1579 | return -1; |
| 1580 | } |
| 1581 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1582 | if (gl_renderer->output_create(&output->base, output->surface, |
| 1583 | gl_renderer->opaque_attribs, |
| 1584 | &format) < 0) { |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1585 | weston_log("failed to create gl renderer output state\n"); |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1586 | gbm_surface_destroy(output->surface); |
| 1587 | return -1; |
| 1588 | } |
| 1589 | |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1590 | flags = GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1591 | |
| 1592 | for (i = 0; i < 2; i++) { |
| 1593 | if (output->cursor_bo[i]) |
| 1594 | continue; |
| 1595 | |
| 1596 | output->cursor_bo[i] = |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1597 | gbm_bo_create(ec->gbm, ec->cursor_width, ec->cursor_height, |
| 1598 | GBM_FORMAT_ARGB8888, flags); |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1599 | } |
| 1600 | |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1601 | if (output->cursor_bo[0] == NULL || output->cursor_bo[1] == NULL) { |
| 1602 | weston_log("cursor buffers unavailable, using gl cursors\n"); |
| 1603 | ec->cursors_are_broken = 1; |
| 1604 | } |
| 1605 | |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1609 | static int |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1610 | drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c) |
| 1611 | { |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1612 | int w = output->base.current_mode->width; |
| 1613 | int h = output->base.current_mode->height; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1614 | unsigned int i; |
| 1615 | |
| 1616 | /* FIXME error checking */ |
| 1617 | |
| 1618 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1619 | output->dumb[i] = drm_fb_create_dumb(c, w, h); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1620 | if (!output->dumb[i]) |
| 1621 | goto err; |
| 1622 | |
| 1623 | output->image[i] = |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1624 | pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1625 | output->dumb[i]->map, |
| 1626 | output->dumb[i]->stride); |
| 1627 | if (!output->image[i]) |
| 1628 | goto err; |
| 1629 | } |
| 1630 | |
| 1631 | if (pixman_renderer_output_create(&output->base) < 0) |
| 1632 | goto err; |
| 1633 | |
| 1634 | pixman_region32_init_rect(&output->previous_damage, |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1635 | output->base.x, output->base.y, output->base.width, output->base.height); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1636 | |
| 1637 | return 0; |
| 1638 | |
| 1639 | err: |
| 1640 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
| 1641 | if (output->dumb[i]) |
| 1642 | drm_fb_destroy_dumb(output->dumb[i]); |
| 1643 | if (output->image[i]) |
| 1644 | pixman_image_unref(output->image[i]); |
| 1645 | |
| 1646 | output->dumb[i] = NULL; |
| 1647 | output->image[i] = NULL; |
| 1648 | } |
| 1649 | |
| 1650 | return -1; |
| 1651 | } |
| 1652 | |
| 1653 | static void |
| 1654 | drm_output_fini_pixman(struct drm_output *output) |
| 1655 | { |
| 1656 | unsigned int i; |
| 1657 | |
| 1658 | pixman_renderer_output_destroy(&output->base); |
| 1659 | pixman_region32_fini(&output->previous_damage); |
| 1660 | |
| 1661 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
| 1662 | drm_fb_destroy_dumb(output->dumb[i]); |
| 1663 | pixman_image_unref(output->image[i]); |
| 1664 | output->dumb[i] = NULL; |
| 1665 | output->image[i] = NULL; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 1669 | static void |
| 1670 | edid_parse_string(const uint8_t *data, char text[]) |
| 1671 | { |
| 1672 | int i; |
| 1673 | int replaced = 0; |
| 1674 | |
| 1675 | /* this is always 12 bytes, but we can't guarantee it's null |
| 1676 | * terminated or not junk. */ |
| 1677 | strncpy(text, (const char *) data, 12); |
| 1678 | |
| 1679 | /* remove insane chars */ |
| 1680 | for (i = 0; text[i] != '\0'; i++) { |
| 1681 | if (text[i] == '\n' || |
| 1682 | text[i] == '\r') { |
| 1683 | text[i] = '\0'; |
| 1684 | break; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | /* ensure string is printable */ |
| 1689 | for (i = 0; text[i] != '\0'; i++) { |
| 1690 | if (!isprint(text[i])) { |
| 1691 | text[i] = '-'; |
| 1692 | replaced++; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | /* if the string is random junk, ignore the string */ |
| 1697 | if (replaced > 4) |
| 1698 | text[0] = '\0'; |
| 1699 | } |
| 1700 | |
| 1701 | #define EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe |
| 1702 | #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc |
| 1703 | #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff |
| 1704 | #define EDID_OFFSET_DATA_BLOCKS 0x36 |
| 1705 | #define EDID_OFFSET_LAST_BLOCK 0x6c |
| 1706 | #define EDID_OFFSET_PNPID 0x08 |
| 1707 | #define EDID_OFFSET_SERIAL 0x0c |
| 1708 | |
| 1709 | static int |
| 1710 | edid_parse(struct drm_edid *edid, const uint8_t *data, size_t length) |
| 1711 | { |
| 1712 | int i; |
| 1713 | uint32_t serial_number; |
| 1714 | |
| 1715 | /* check header */ |
| 1716 | if (length < 128) |
| 1717 | return -1; |
| 1718 | if (data[0] != 0x00 || data[1] != 0xff) |
| 1719 | return -1; |
| 1720 | |
| 1721 | /* decode the PNP ID from three 5 bit words packed into 2 bytes |
| 1722 | * /--08--\/--09--\ |
| 1723 | * 7654321076543210 |
| 1724 | * |\---/\---/\---/ |
| 1725 | * R C1 C2 C3 */ |
| 1726 | edid->pnp_id[0] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x7c) / 4) - 1; |
| 1727 | edid->pnp_id[1] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x3) * 8) + ((data[EDID_OFFSET_PNPID + 1] & 0xe0) / 32) - 1; |
| 1728 | edid->pnp_id[2] = 'A' + (data[EDID_OFFSET_PNPID + 1] & 0x1f) - 1; |
| 1729 | edid->pnp_id[3] = '\0'; |
| 1730 | |
| 1731 | /* maybe there isn't a ASCII serial number descriptor, so use this instead */ |
| 1732 | serial_number = (uint32_t) data[EDID_OFFSET_SERIAL + 0]; |
| 1733 | serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 1] * 0x100; |
| 1734 | serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 2] * 0x10000; |
| 1735 | serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 3] * 0x1000000; |
| 1736 | if (serial_number > 0) |
| 1737 | sprintf(edid->serial_number, "%lu", (unsigned long) serial_number); |
| 1738 | |
| 1739 | /* parse EDID data */ |
| 1740 | for (i = EDID_OFFSET_DATA_BLOCKS; |
| 1741 | i <= EDID_OFFSET_LAST_BLOCK; |
| 1742 | i += 18) { |
| 1743 | /* ignore pixel clock data */ |
| 1744 | if (data[i] != 0) |
| 1745 | continue; |
| 1746 | if (data[i+2] != 0) |
| 1747 | continue; |
| 1748 | |
| 1749 | /* any useful blocks? */ |
| 1750 | if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME) { |
| 1751 | edid_parse_string(&data[i+5], |
| 1752 | edid->monitor_name); |
| 1753 | } else if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) { |
| 1754 | edid_parse_string(&data[i+5], |
| 1755 | edid->serial_number); |
| 1756 | } else if (data[i+3] == EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) { |
| 1757 | edid_parse_string(&data[i+5], |
| 1758 | edid->eisa_id); |
| 1759 | } |
| 1760 | } |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static void |
| 1765 | find_and_parse_output_edid(struct drm_compositor *ec, |
| 1766 | struct drm_output *output, |
| 1767 | drmModeConnector *connector) |
| 1768 | { |
| 1769 | drmModePropertyBlobPtr edid_blob = NULL; |
| 1770 | drmModePropertyPtr property; |
| 1771 | int i; |
| 1772 | int rc; |
| 1773 | |
| 1774 | for (i = 0; i < connector->count_props && !edid_blob; i++) { |
| 1775 | property = drmModeGetProperty(ec->drm.fd, connector->props[i]); |
| 1776 | if (!property) |
| 1777 | continue; |
| 1778 | if ((property->flags & DRM_MODE_PROP_BLOB) && |
| 1779 | !strcmp(property->name, "EDID")) { |
| 1780 | edid_blob = drmModeGetPropertyBlob(ec->drm.fd, |
| 1781 | connector->prop_values[i]); |
| 1782 | } |
| 1783 | drmModeFreeProperty(property); |
| 1784 | } |
| 1785 | if (!edid_blob) |
| 1786 | return; |
| 1787 | |
| 1788 | rc = edid_parse(&output->edid, |
| 1789 | edid_blob->data, |
| 1790 | edid_blob->length); |
| 1791 | if (!rc) { |
| 1792 | weston_log("EDID data '%s', '%s', '%s'\n", |
| 1793 | output->edid.pnp_id, |
| 1794 | output->edid.monitor_name, |
| 1795 | output->edid.serial_number); |
| 1796 | if (output->edid.pnp_id[0] != '\0') |
| 1797 | output->base.make = output->edid.pnp_id; |
| 1798 | if (output->edid.monitor_name[0] != '\0') |
| 1799 | output->base.model = output->edid.monitor_name; |
| 1800 | if (output->edid.serial_number[0] != '\0') |
| 1801 | output->base.serial_number = output->edid.serial_number; |
| 1802 | } |
| 1803 | drmModeFreePropertyBlob(edid_blob); |
| 1804 | } |
| 1805 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1806 | |
| 1807 | |
| 1808 | static int |
| 1809 | parse_modeline(const char *s, drmModeModeInfo *mode) |
| 1810 | { |
| 1811 | char hsync[16]; |
| 1812 | char vsync[16]; |
| 1813 | float fclock; |
| 1814 | |
| 1815 | mode->type = DRM_MODE_TYPE_USERDEF; |
| 1816 | mode->hskew = 0; |
| 1817 | mode->vscan = 0; |
| 1818 | mode->vrefresh = 0; |
| 1819 | mode->flags = 0; |
| 1820 | |
Rob Bradford | 307e09e | 2013-07-26 16:29:40 +0100 | [diff] [blame] | 1821 | if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s", |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1822 | &fclock, |
| 1823 | &mode->hdisplay, |
| 1824 | &mode->hsync_start, |
| 1825 | &mode->hsync_end, |
| 1826 | &mode->htotal, |
| 1827 | &mode->vdisplay, |
| 1828 | &mode->vsync_start, |
| 1829 | &mode->vsync_end, |
| 1830 | &mode->vtotal, hsync, vsync) != 11) |
| 1831 | return -1; |
| 1832 | |
| 1833 | mode->clock = fclock * 1000; |
| 1834 | if (strcmp(hsync, "+hsync") == 0) |
| 1835 | mode->flags |= DRM_MODE_FLAG_PHSYNC; |
| 1836 | else if (strcmp(hsync, "-hsync") == 0) |
| 1837 | mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 1838 | else |
| 1839 | return -1; |
| 1840 | |
| 1841 | if (strcmp(vsync, "+vsync") == 0) |
| 1842 | mode->flags |= DRM_MODE_FLAG_PVSYNC; |
| 1843 | else if (strcmp(vsync, "-vsync") == 0) |
| 1844 | mode->flags |= DRM_MODE_FLAG_NVSYNC; |
| 1845 | else |
| 1846 | return -1; |
| 1847 | |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
| 1851 | static uint32_t |
| 1852 | parse_transform(const char *transform, const char *output_name) |
| 1853 | { |
| 1854 | static const struct { const char *name; uint32_t token; } names[] = { |
| 1855 | { "normal", WL_OUTPUT_TRANSFORM_NORMAL }, |
| 1856 | { "90", WL_OUTPUT_TRANSFORM_90 }, |
| 1857 | { "180", WL_OUTPUT_TRANSFORM_180 }, |
| 1858 | { "270", WL_OUTPUT_TRANSFORM_270 }, |
| 1859 | { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED }, |
| 1860 | { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 }, |
| 1861 | { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 }, |
| 1862 | { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 }, |
| 1863 | }; |
| 1864 | unsigned int i; |
| 1865 | |
| 1866 | for (i = 0; i < ARRAY_LENGTH(names); i++) |
| 1867 | if (strcmp(names[i].name, transform) == 0) |
| 1868 | return names[i].token; |
| 1869 | |
| 1870 | weston_log("Invalid transform \"%s\" for output %s\n", |
| 1871 | transform, output_name); |
| 1872 | |
| 1873 | return WL_OUTPUT_TRANSFORM_NORMAL; |
| 1874 | } |
| 1875 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1876 | static void |
| 1877 | setup_output_seat_constraint(struct drm_compositor *ec, |
| 1878 | struct weston_output *output, |
| 1879 | const char *s) |
| 1880 | { |
| 1881 | if (strcmp(s, "") != 0) { |
| 1882 | struct udev_seat *seat; |
| 1883 | |
Jonas Ådahl | 58e1586 | 2014-03-12 22:08:40 +0100 | [diff] [blame] | 1884 | seat = udev_seat_get_named(&ec->input, s); |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1885 | if (seat) |
| 1886 | seat->base.output = output; |
| 1887 | |
| 1888 | if (seat && seat->base.pointer) |
| 1889 | weston_pointer_clamp(seat->base.pointer, |
| 1890 | &seat->base.pointer->x, |
| 1891 | &seat->base.pointer->y); |
| 1892 | } |
| 1893 | } |
| 1894 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1895 | static int |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1896 | get_gbm_format_from_section(struct weston_config_section *section, |
| 1897 | uint32_t default_value, |
| 1898 | uint32_t *format) |
| 1899 | { |
| 1900 | char *s; |
| 1901 | int ret = 0; |
| 1902 | |
| 1903 | weston_config_section_get_string(section, |
| 1904 | "gbm-format", &s, NULL); |
| 1905 | |
| 1906 | if (s == NULL) |
| 1907 | *format = default_value; |
| 1908 | else if (strcmp(s, "xrgb8888") == 0) |
| 1909 | *format = GBM_FORMAT_XRGB8888; |
| 1910 | else if (strcmp(s, "rgb565") == 0) |
| 1911 | *format = GBM_FORMAT_RGB565; |
| 1912 | else if (strcmp(s, "xrgb2101010") == 0) |
| 1913 | *format = GBM_FORMAT_XRGB2101010; |
| 1914 | else { |
| 1915 | weston_log("fatal: unrecognized pixel format: %s\n", s); |
| 1916 | ret = -1; |
| 1917 | } |
| 1918 | |
| 1919 | free(s); |
| 1920 | |
| 1921 | return ret; |
| 1922 | } |
| 1923 | |
| 1924 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1925 | create_output_for_connector(struct drm_compositor *ec, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1926 | drmModeRes *resources, |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1927 | drmModeConnector *connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1928 | int x, int y, struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1929 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1930 | struct drm_output *output; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 1931 | struct drm_mode *drm_mode, *next, *preferred, *current, *configured, *best; |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1932 | struct weston_mode *m; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1933 | struct weston_config_section *section; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1934 | drmModeEncoder *encoder; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1935 | drmModeModeInfo crtc_mode, modeline; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1936 | drmModeCrtc *crtc; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1937 | int i, width, height, scale; |
| 1938 | char name[32], *s; |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1939 | const char *type_name; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1940 | enum output_config config; |
| 1941 | uint32_t transform; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1942 | |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1943 | i = find_crtc_for_connector(ec, resources, connector); |
| 1944 | if (i < 0) { |
| 1945 | weston_log("No usable crtc/encoder pair for connector.\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1946 | return -1; |
| 1947 | } |
| 1948 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1949 | output = zalloc(sizeof *output); |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1950 | if (output == NULL) |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1951 | return -1; |
| 1952 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1953 | output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel); |
| 1954 | output->base.make = "unknown"; |
| 1955 | output->base.model = "unknown"; |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 1956 | output->base.serial_number = "unknown"; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1957 | wl_list_init(&output->base.mode_list); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1958 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1959 | if (connector->connector_type < ARRAY_LENGTH(connector_type_names)) |
| 1960 | type_name = connector_type_names[connector->connector_type]; |
| 1961 | else |
| 1962 | type_name = "UNKNOWN"; |
| 1963 | snprintf(name, 32, "%s%d", type_name, connector->connector_type_id); |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 1964 | output->base.name = strdup(name); |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1965 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1966 | section = weston_config_get_section(ec->base.config, "output", "name", |
| 1967 | output->base.name); |
| 1968 | weston_config_section_get_string(section, "mode", &s, "preferred"); |
| 1969 | if (strcmp(s, "off") == 0) |
| 1970 | config = OUTPUT_CONFIG_OFF; |
| 1971 | else if (strcmp(s, "preferred") == 0) |
| 1972 | config = OUTPUT_CONFIG_PREFERRED; |
| 1973 | else if (strcmp(s, "current") == 0) |
| 1974 | config = OUTPUT_CONFIG_CURRENT; |
| 1975 | else if (sscanf(s, "%dx%d", &width, &height) == 2) |
| 1976 | config = OUTPUT_CONFIG_MODE; |
| 1977 | else if (parse_modeline(s, &modeline) == 0) |
| 1978 | config = OUTPUT_CONFIG_MODELINE; |
| 1979 | else { |
| 1980 | weston_log("Invalid mode \"%s\" for output %s\n", |
| 1981 | s, output->base.name); |
| 1982 | config = OUTPUT_CONFIG_PREFERRED; |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 1983 | } |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1984 | free(s); |
| 1985 | |
| 1986 | weston_config_section_get_int(section, "scale", &scale, 1); |
| 1987 | weston_config_section_get_string(section, "transform", &s, "normal"); |
| 1988 | transform = parse_transform(s, output->base.name); |
| 1989 | free(s); |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 1990 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1991 | if (get_gbm_format_from_section(section, |
| 1992 | ec->format, |
| 1993 | &output->format) == -1) |
| 1994 | output->format = ec->format; |
| 1995 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1996 | weston_config_section_get_string(section, "seat", &s, ""); |
| 1997 | setup_output_seat_constraint(ec, &output->base, s); |
| 1998 | free(s); |
| 1999 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2000 | output->crtc_id = resources->crtcs[i]; |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 2001 | output->pipe = i; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2002 | ec->crtc_allocator |= (1 << output->crtc_id); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2003 | output->connector_id = connector->connector_id; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2004 | ec->connector_allocator |= (1 << output->connector_id); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2005 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2006 | output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id); |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 2007 | output->dpms_prop = drm_get_prop(ec->drm.fd, connector, "DPMS"); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2008 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2009 | /* Get the current mode on the crtc that's currently driving |
| 2010 | * this connector. */ |
| 2011 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoder_id); |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2012 | memset(&crtc_mode, 0, sizeof crtc_mode); |
| 2013 | if (encoder != NULL) { |
| 2014 | crtc = drmModeGetCrtc(ec->drm.fd, encoder->crtc_id); |
| 2015 | drmModeFreeEncoder(encoder); |
| 2016 | if (crtc == NULL) |
| 2017 | goto err_free; |
| 2018 | if (crtc->mode_valid) |
| 2019 | crtc_mode = crtc->mode; |
| 2020 | drmModeFreeCrtc(crtc); |
| 2021 | } |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2022 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2023 | for (i = 0; i < connector->count_modes; i++) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2024 | drm_mode = drm_output_add_mode(output, &connector->modes[i]); |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2025 | if (!drm_mode) |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2026 | goto err_free; |
| 2027 | } |
| 2028 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2029 | if (config == OUTPUT_CONFIG_OFF) { |
| 2030 | weston_log("Disabling output %s\n", output->base.name); |
| 2031 | drmModeSetCrtc(ec->drm.fd, output->crtc_id, |
| 2032 | 0, 0, 0, 0, 0, NULL); |
| 2033 | goto err_free; |
| 2034 | } |
| 2035 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2036 | preferred = NULL; |
| 2037 | current = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2038 | configured = NULL; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 2039 | best = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2040 | |
Giulio Camuffo | c0b9487 | 2013-06-19 15:19:19 +0200 | [diff] [blame] | 2041 | wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) { |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2042 | if (config == OUTPUT_CONFIG_MODE && |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2043 | width == drm_mode->base.width && |
| 2044 | height == drm_mode->base.height) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2045 | configured = drm_mode; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2046 | 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] | 2047 | current = drm_mode; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2048 | if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2049 | preferred = drm_mode; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 2050 | best = drm_mode; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2051 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2052 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2053 | if (config == OUTPUT_CONFIG_MODELINE) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2054 | configured = drm_output_add_mode(output, &modeline); |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2055 | if (!configured) |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 2056 | goto err_free; |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 2057 | } |
| 2058 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2059 | if (current == NULL && crtc_mode.clock != 0) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2060 | current = drm_output_add_mode(output, &crtc_mode); |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2061 | if (!current) |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2062 | goto err_free; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2065 | if (config == OUTPUT_CONFIG_CURRENT) |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2066 | configured = current; |
| 2067 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2068 | if (option_current_mode && current) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2069 | output->base.current_mode = ¤t->base; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2070 | else if (configured) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2071 | output->base.current_mode = &configured->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2072 | else if (preferred) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2073 | output->base.current_mode = &preferred->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2074 | else if (current) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2075 | output->base.current_mode = ¤t->base; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 2076 | else if (best) |
| 2077 | output->base.current_mode = &best->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2078 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2079 | if (output->base.current_mode == NULL) { |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 2080 | weston_log("no available modes for %s\n", output->base.name); |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2081 | goto err_free; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2082 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2083 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2084 | output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2085 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2086 | weston_output_init(&output->base, &ec->base, x, y, |
| 2087 | connector->mmWidth, connector->mmHeight, |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2088 | transform, scale); |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2089 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2090 | if (ec->use_pixman) { |
| 2091 | if (drm_output_init_pixman(output, ec) < 0) { |
| 2092 | weston_log("Failed to init output pixman state\n"); |
| 2093 | goto err_output; |
| 2094 | } |
| 2095 | } else if (drm_output_init_egl(output, ec) < 0) { |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 2096 | weston_log("Failed to init output gl state\n"); |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2097 | goto err_output; |
Kristian Høgsberg | 1d1e0a5 | 2012-10-21 13:29:26 -0400 | [diff] [blame] | 2098 | } |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 2099 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2100 | output->backlight = backlight_init(drm_device, |
| 2101 | connector->connector_type); |
| 2102 | if (output->backlight) { |
Kristian Høgsberg | 220819f | 2013-05-23 20:29:40 -0400 | [diff] [blame] | 2103 | weston_log("Initialized backlight, device %s\n", |
| 2104 | output->backlight->path); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2105 | output->base.set_backlight = drm_set_backlight; |
| 2106 | output->base.backlight_current = drm_get_backlight(output); |
Kristian Høgsberg | 220819f | 2013-05-23 20:29:40 -0400 | [diff] [blame] | 2107 | } else { |
| 2108 | weston_log("Failed to initialize backlight\n"); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
Kristian Høgsberg | a4b7e20 | 2011-10-24 13:26:32 -0400 | [diff] [blame] | 2111 | wl_list_insert(ec->base.output_list.prev, &output->base.link); |
| 2112 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 2113 | find_and_parse_output_edid(ec, output, connector); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 2114 | if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) |
| 2115 | output->base.connection_internal = 1; |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 2116 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2117 | output->base.start_repaint_loop = drm_output_start_repaint_loop; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 2118 | output->base.repaint = drm_output_repaint; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2119 | output->base.destroy = drm_output_destroy; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2120 | output->base.assign_planes = drm_assign_planes; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2121 | output->base.set_dpms = drm_set_dpms; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 2122 | output->base.switch_mode = drm_output_switch_mode; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2123 | |
Richard Hughes | e729996 | 2013-05-01 21:52:12 +0100 | [diff] [blame] | 2124 | output->base.gamma_size = output->original_crtc->gamma_size; |
| 2125 | output->base.set_gamma = drm_output_set_gamma; |
| 2126 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2127 | weston_plane_init(&output->cursor_plane, &ec->base, 0, 0); |
| 2128 | weston_plane_init(&output->fb_plane, &ec->base, 0, 0); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2129 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2130 | weston_compositor_stack_plane(&ec->base, &output->cursor_plane, NULL); |
| 2131 | weston_compositor_stack_plane(&ec->base, &output->fb_plane, |
| 2132 | &ec->base.primary_plane); |
| 2133 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 2134 | weston_log("Output %s, (connector %d, crtc %d)\n", |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 2135 | output->base.name, output->connector_id, output->crtc_id); |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2136 | wl_list_for_each(m, &output->base.mode_list, link) |
U. Artie Eoff | d3ed6cb | 2014-01-10 10:15:17 -0800 | [diff] [blame] | 2137 | weston_log_continue(STAMP_SPACE "mode %dx%d@%.1f%s%s%s\n", |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2138 | m->width, m->height, m->refresh / 1000.0, |
| 2139 | m->flags & WL_OUTPUT_MODE_PREFERRED ? |
| 2140 | ", preferred" : "", |
| 2141 | m->flags & WL_OUTPUT_MODE_CURRENT ? |
| 2142 | ", current" : "", |
| 2143 | connector->count_modes == 0 ? |
| 2144 | ", built-in" : ""); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2145 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2146 | return 0; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2147 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2148 | err_output: |
| 2149 | weston_output_destroy(&output->base); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2150 | err_free: |
| 2151 | wl_list_for_each_safe(drm_mode, next, &output->base.mode_list, |
| 2152 | base.link) { |
| 2153 | wl_list_remove(&drm_mode->base.link); |
| 2154 | free(drm_mode); |
| 2155 | } |
| 2156 | |
| 2157 | drmModeFreeCrtc(output->original_crtc); |
| 2158 | ec->crtc_allocator &= ~(1 << output->crtc_id); |
| 2159 | ec->connector_allocator &= ~(1 << output->connector_id); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2160 | free(output); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 2161 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2162 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2163 | } |
| 2164 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2165 | static void |
| 2166 | create_sprites(struct drm_compositor *ec) |
| 2167 | { |
| 2168 | struct drm_sprite *sprite; |
| 2169 | drmModePlaneRes *plane_res; |
| 2170 | drmModePlane *plane; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2171 | uint32_t i; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2172 | |
| 2173 | plane_res = drmModeGetPlaneResources(ec->drm.fd); |
| 2174 | if (!plane_res) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2175 | weston_log("failed to get plane resources: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2176 | strerror(errno)); |
| 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | for (i = 0; i < plane_res->count_planes; i++) { |
| 2181 | plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]); |
| 2182 | if (!plane) |
| 2183 | continue; |
| 2184 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2185 | sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) * |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2186 | plane->count_formats)); |
| 2187 | if (!sprite) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2188 | weston_log("%s: out of memory\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2189 | __func__); |
Chris Michael | 8b37687 | 2014-01-02 11:39:40 +0000 | [diff] [blame] | 2190 | drmModeFreePlane(plane); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2191 | continue; |
| 2192 | } |
| 2193 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2194 | sprite->possible_crtcs = plane->possible_crtcs; |
| 2195 | sprite->plane_id = plane->plane_id; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 2196 | sprite->current = NULL; |
| 2197 | sprite->next = NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2198 | sprite->compositor = ec; |
| 2199 | sprite->count_formats = plane->count_formats; |
| 2200 | memcpy(sprite->formats, plane->formats, |
Rob Clark | 8efbc8e | 2012-03-11 19:48:44 -0500 | [diff] [blame] | 2201 | plane->count_formats * sizeof(plane->formats[0])); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2202 | drmModeFreePlane(plane); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2203 | weston_plane_init(&sprite->plane, &ec->base, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2204 | weston_compositor_stack_plane(&ec->base, &sprite->plane, |
| 2205 | &ec->base.primary_plane); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2206 | |
| 2207 | wl_list_insert(&ec->sprite_list, &sprite->link); |
| 2208 | } |
| 2209 | |
Samuel Iglesias Gonsalvez | de46673 | 2013-06-13 10:03:33 +0200 | [diff] [blame] | 2210 | drmModeFreePlaneResources(plane_res); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2211 | } |
| 2212 | |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2213 | static void |
| 2214 | destroy_sprites(struct drm_compositor *compositor) |
| 2215 | { |
| 2216 | struct drm_sprite *sprite, *next; |
| 2217 | struct drm_output *output; |
| 2218 | |
| 2219 | output = container_of(compositor->base.output_list.next, |
| 2220 | struct drm_output, base.link); |
| 2221 | |
| 2222 | wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) { |
| 2223 | drmModeSetPlane(compositor->drm.fd, |
| 2224 | sprite->plane_id, |
| 2225 | output->crtc_id, 0, 0, |
| 2226 | 0, 0, 0, 0, 0, 0, 0, 0); |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 2227 | drm_output_release_fb(output, sprite->current); |
| 2228 | drm_output_release_fb(output, sprite->next); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2229 | weston_plane_release(&sprite->plane); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2230 | free(sprite); |
| 2231 | } |
| 2232 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2233 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2234 | static int |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2235 | create_outputs(struct drm_compositor *ec, uint32_t option_connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2236 | struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2237 | { |
| 2238 | drmModeConnector *connector; |
| 2239 | drmModeRes *resources; |
| 2240 | int i; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2241 | int x = 0, y = 0; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2242 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 2243 | resources = drmModeGetResources(ec->drm.fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2244 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2245 | weston_log("drmModeGetResources failed\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2246 | return -1; |
| 2247 | } |
| 2248 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2249 | ec->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t)); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 2250 | if (!ec->crtcs) { |
| 2251 | drmModeFreeResources(resources); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2252 | return -1; |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 2253 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2254 | |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 2255 | ec->min_width = resources->min_width; |
| 2256 | ec->max_width = resources->max_width; |
| 2257 | ec->min_height = resources->min_height; |
| 2258 | ec->max_height = resources->max_height; |
| 2259 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2260 | ec->num_crtcs = resources->count_crtcs; |
| 2261 | memcpy(ec->crtcs, resources->crtcs, sizeof(uint32_t) * ec->num_crtcs); |
| 2262 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2263 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2264 | connector = drmModeGetConnector(ec->drm.fd, |
| 2265 | resources->connectors[i]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2266 | if (connector == NULL) |
| 2267 | continue; |
| 2268 | |
| 2269 | if (connector->connection == DRM_MODE_CONNECTED && |
| 2270 | (option_connector == 0 || |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 2271 | connector->connector_id == option_connector)) { |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2272 | if (create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2273 | connector, x, y, |
| 2274 | drm_device) < 0) { |
Benjamin Franzke | 439d986 | 2011-10-07 08:20:53 +0200 | [diff] [blame] | 2275 | drmModeFreeConnector(connector); |
| 2276 | continue; |
| 2277 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2278 | |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 2279 | x += container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2280 | struct weston_output, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2281 | link)->width; |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 2282 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2283 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2284 | drmModeFreeConnector(connector); |
| 2285 | } |
| 2286 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2287 | if (wl_list_empty(&ec->base.output_list)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2288 | weston_log("No currently active connector found.\n"); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 2289 | drmModeFreeResources(resources); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2290 | return -1; |
| 2291 | } |
| 2292 | |
| 2293 | drmModeFreeResources(resources); |
| 2294 | |
| 2295 | return 0; |
| 2296 | } |
| 2297 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2298 | static void |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2299 | update_outputs(struct drm_compositor *ec, struct udev_device *drm_device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2300 | { |
| 2301 | drmModeConnector *connector; |
| 2302 | drmModeRes *resources; |
| 2303 | struct drm_output *output, *next; |
| 2304 | int x = 0, y = 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2305 | uint32_t connected = 0, disconnects = 0; |
| 2306 | int i; |
| 2307 | |
| 2308 | resources = drmModeGetResources(ec->drm.fd); |
| 2309 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2310 | weston_log("drmModeGetResources failed\n"); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2311 | return; |
| 2312 | } |
| 2313 | |
| 2314 | /* collect new connects */ |
| 2315 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2316 | int connector_id = resources->connectors[i]; |
| 2317 | |
| 2318 | connector = drmModeGetConnector(ec->drm.fd, connector_id); |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 2319 | if (connector == NULL) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2320 | continue; |
| 2321 | |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 2322 | if (connector->connection != DRM_MODE_CONNECTED) { |
| 2323 | drmModeFreeConnector(connector); |
| 2324 | continue; |
| 2325 | } |
| 2326 | |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2327 | connected |= (1 << connector_id); |
| 2328 | |
| 2329 | if (!(ec->connector_allocator & (1 << connector_id))) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2330 | struct weston_output *last = |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2331 | container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2332 | struct weston_output, link); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2333 | |
| 2334 | /* XXX: not yet needed, we die with 0 outputs */ |
| 2335 | if (!wl_list_empty(&ec->base.output_list)) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2336 | x = last->x + last->width; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2337 | else |
| 2338 | x = 0; |
| 2339 | y = 0; |
| 2340 | create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2341 | connector, x, y, |
| 2342 | drm_device); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2343 | weston_log("connector %d connected\n", connector_id); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2344 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2345 | } |
| 2346 | drmModeFreeConnector(connector); |
| 2347 | } |
| 2348 | drmModeFreeResources(resources); |
| 2349 | |
| 2350 | disconnects = ec->connector_allocator & ~connected; |
| 2351 | if (disconnects) { |
| 2352 | wl_list_for_each_safe(output, next, &ec->base.output_list, |
| 2353 | base.link) { |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2354 | if (disconnects & (1 << output->connector_id)) { |
| 2355 | disconnects &= ~(1 << output->connector_id); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2356 | weston_log("connector %d disconnected\n", |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2357 | output->connector_id); |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 2358 | drm_output_destroy(&output->base); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | /* FIXME: handle zero outputs, without terminating */ |
| 2364 | if (ec->connector_allocator == 0) |
| 2365 | wl_display_terminate(ec->base.wl_display); |
| 2366 | } |
| 2367 | |
| 2368 | static int |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2369 | udev_event_is_hotplug(struct drm_compositor *ec, struct udev_device *device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2370 | { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2371 | const char *sysnum; |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2372 | const char *val; |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2373 | |
| 2374 | sysnum = udev_device_get_sysnum(device); |
| 2375 | if (!sysnum || atoi(sysnum) != ec->drm.id) |
| 2376 | return 0; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2377 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2378 | val = udev_device_get_property_value(device, "HOTPLUG"); |
| 2379 | if (!val) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2380 | return 0; |
| 2381 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2382 | return strcmp(val, "1") == 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2385 | static int |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2386 | udev_drm_event(int fd, uint32_t mask, void *data) |
| 2387 | { |
| 2388 | struct drm_compositor *ec = data; |
| 2389 | struct udev_device *event; |
| 2390 | |
| 2391 | event = udev_monitor_receive_device(ec->udev_monitor); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2392 | |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2393 | if (udev_event_is_hotplug(ec, event)) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2394 | update_outputs(ec, event); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2395 | |
| 2396 | udev_device_unref(event); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2397 | |
| 2398 | return 1; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2399 | } |
| 2400 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2401 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2402 | drm_restore(struct weston_compositor *ec) |
| 2403 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2404 | weston_launcher_restore(ec->launcher); |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2408 | drm_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2409 | { |
| 2410 | struct drm_compositor *d = (struct drm_compositor *) ec; |
| 2411 | |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 2412 | udev_input_destroy(&d->input); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 2413 | |
| 2414 | wl_event_source_remove(d->udev_drm_source); |
| 2415 | wl_event_source_remove(d->drm_source); |
| 2416 | |
Kristian Høgsberg | 3d64a3e | 2013-05-10 12:36:04 -0400 | [diff] [blame] | 2417 | destroy_sprites(d); |
| 2418 | |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 2419 | weston_compositor_shutdown(ec); |
| 2420 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2421 | if (d->gbm) |
| 2422 | gbm_device_destroy(d->gbm); |
| 2423 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2424 | weston_launcher_destroy(d->base.launcher); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2425 | |
Rob Bradford | 45c15b8 | 2013-07-26 16:29:35 +0100 | [diff] [blame] | 2426 | close(d->drm.fd); |
| 2427 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 2428 | free(d); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2429 | } |
| 2430 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2431 | static void |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2432 | drm_compositor_set_modes(struct drm_compositor *compositor) |
| 2433 | { |
| 2434 | struct drm_output *output; |
| 2435 | struct drm_mode *drm_mode; |
| 2436 | int ret; |
| 2437 | |
| 2438 | wl_list_for_each(output, &compositor->base.output_list, base.link) { |
Ander Conselvan de Oliveira | 2002f88 | 2013-02-26 13:44:58 +0200 | [diff] [blame] | 2439 | if (!output->current) { |
| 2440 | /* If something that would cause the output to |
| 2441 | * switch mode happened while in another vt, we |
| 2442 | * might not have a current drm_fb. In that case, |
| 2443 | * schedule a repaint and let drm_output_repaint |
| 2444 | * handle setting the mode. */ |
| 2445 | weston_output_schedule_repaint(&output->base); |
| 2446 | continue; |
| 2447 | } |
| 2448 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2449 | drm_mode = (struct drm_mode *) output->base.current_mode; |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2450 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 2451 | output->current->fb_id, 0, 0, |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2452 | &output->connector_id, 1, |
| 2453 | &drm_mode->mode_info); |
| 2454 | if (ret < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2455 | weston_log( |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 2456 | "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] | 2457 | drm_mode->base.width, drm_mode->base.height, |
| 2458 | output->base.x, output->base.y); |
| 2459 | } |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | static void |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2464 | session_notify(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2465 | { |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2466 | struct weston_compositor *compositor = data; |
| 2467 | struct drm_compositor *ec = data; |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2468 | struct drm_sprite *sprite; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2469 | struct drm_output *output; |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2470 | |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2471 | if (ec->base.session_active) { |
| 2472 | weston_log("activating session\n"); |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2473 | compositor->state = ec->prev_state; |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2474 | drm_compositor_set_modes(ec); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2475 | weston_compositor_damage_all(compositor); |
Jonas Ådahl | 0feb32e | 2014-03-12 22:08:41 +0100 | [diff] [blame] | 2476 | udev_input_enable(&ec->input); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2477 | } else { |
| 2478 | weston_log("deactivating session\n"); |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 2479 | udev_input_disable(&ec->input); |
Kristian Høgsberg | 4014a6b | 2012-04-10 00:08:45 -0400 | [diff] [blame] | 2480 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2481 | ec->prev_state = compositor->state; |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2482 | weston_compositor_offscreen(compositor); |
Kristian Høgsberg | d8e181b | 2011-05-06 15:38:28 -0400 | [diff] [blame] | 2483 | |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2484 | /* If we have a repaint scheduled (either from a |
| 2485 | * pending pageflip or the idle handler), make sure we |
| 2486 | * cancel that so we don't try to pageflip when we're |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2487 | * vt switched away. The OFFSCREEN state will prevent |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2488 | * further attemps at repainting. When we switch |
| 2489 | * back, we schedule a repaint, which will process |
| 2490 | * pending frame callbacks. */ |
| 2491 | |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2492 | wl_list_for_each(output, &ec->base.output_list, base.link) { |
| 2493 | output->base.repaint_needed = 0; |
| 2494 | drmModeSetCursor(ec->drm.fd, output->crtc_id, 0, 0, 0); |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2495 | } |
| 2496 | |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2497 | output = container_of(ec->base.output_list.next, |
| 2498 | struct drm_output, base.link); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2499 | |
| 2500 | wl_list_for_each(sprite, &ec->sprite_list, link) |
| 2501 | drmModeSetPlane(ec->drm.fd, |
| 2502 | sprite->plane_id, |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2503 | output->crtc_id, 0, 0, |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2504 | 0, 0, 0, 0, 0, 0, 0, 0); |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2505 | }; |
| 2506 | } |
| 2507 | |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2508 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2509 | switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2510 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2511 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2512 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2513 | weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2516 | /* |
| 2517 | * Find primary GPU |
| 2518 | * Some systems may have multiple DRM devices attached to a single seat. This |
| 2519 | * function loops over all devices and tries to find a PCI device with the |
| 2520 | * boot_vga sysfs attribute set to 1. |
| 2521 | * If no such device is found, the first DRM device reported by udev is used. |
| 2522 | */ |
| 2523 | static struct udev_device* |
| 2524 | find_primary_gpu(struct drm_compositor *ec, const char *seat) |
| 2525 | { |
| 2526 | struct udev_enumerate *e; |
| 2527 | struct udev_list_entry *entry; |
| 2528 | const char *path, *device_seat, *id; |
| 2529 | struct udev_device *device, *drm_device, *pci; |
| 2530 | |
| 2531 | e = udev_enumerate_new(ec->udev); |
| 2532 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 2533 | udev_enumerate_add_match_sysname(e, "card[0-9]*"); |
| 2534 | |
| 2535 | udev_enumerate_scan_devices(e); |
| 2536 | drm_device = NULL; |
| 2537 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 2538 | path = udev_list_entry_get_name(entry); |
| 2539 | device = udev_device_new_from_syspath(ec->udev, path); |
| 2540 | if (!device) |
| 2541 | continue; |
| 2542 | device_seat = udev_device_get_property_value(device, "ID_SEAT"); |
| 2543 | if (!device_seat) |
| 2544 | device_seat = default_seat; |
| 2545 | if (strcmp(device_seat, seat)) { |
| 2546 | udev_device_unref(device); |
| 2547 | continue; |
| 2548 | } |
| 2549 | |
| 2550 | pci = udev_device_get_parent_with_subsystem_devtype(device, |
| 2551 | "pci", NULL); |
| 2552 | if (pci) { |
| 2553 | id = udev_device_get_sysattr_value(pci, "boot_vga"); |
| 2554 | if (id && !strcmp(id, "1")) { |
| 2555 | if (drm_device) |
| 2556 | udev_device_unref(drm_device); |
| 2557 | drm_device = device; |
| 2558 | break; |
| 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | if (!drm_device) |
| 2563 | drm_device = device; |
| 2564 | else |
| 2565 | udev_device_unref(device); |
| 2566 | } |
| 2567 | |
| 2568 | udev_enumerate_unref(e); |
| 2569 | return drm_device; |
| 2570 | } |
| 2571 | |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2572 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2573 | planes_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2574 | { |
| 2575 | struct drm_compositor *c = data; |
| 2576 | |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2577 | switch (key) { |
| 2578 | case KEY_C: |
| 2579 | c->cursors_are_broken ^= 1; |
| 2580 | break; |
| 2581 | case KEY_V: |
| 2582 | c->sprites_are_broken ^= 1; |
| 2583 | break; |
| 2584 | case KEY_O: |
| 2585 | c->sprites_hidden ^= 1; |
| 2586 | break; |
| 2587 | default: |
| 2588 | break; |
| 2589 | } |
Ander Conselvan de Oliveira | 180f42a | 2012-11-21 15:11:37 +0200 | [diff] [blame] | 2590 | } |
| 2591 | |
Kristian Høgsberg | 0eac34a | 2013-08-30 14:28:22 -0700 | [diff] [blame] | 2592 | #ifdef BUILD_VAAPI_RECORDER |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2593 | static void |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2594 | recorder_destroy(struct drm_output *output) |
| 2595 | { |
| 2596 | vaapi_recorder_destroy(output->recorder); |
| 2597 | output->recorder = NULL; |
| 2598 | |
| 2599 | output->base.disable_planes--; |
| 2600 | |
| 2601 | wl_list_remove(&output->recorder_frame_listener.link); |
| 2602 | weston_log("[libva recorder] done\n"); |
| 2603 | } |
| 2604 | |
| 2605 | static void |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2606 | recorder_frame_notify(struct wl_listener *listener, void *data) |
| 2607 | { |
| 2608 | struct drm_output *output; |
| 2609 | struct drm_compositor *c; |
| 2610 | int fd, ret; |
| 2611 | |
| 2612 | output = container_of(listener, struct drm_output, |
| 2613 | recorder_frame_listener); |
| 2614 | c = (struct drm_compositor *) output->base.compositor; |
| 2615 | |
| 2616 | if (!output->recorder) |
| 2617 | return; |
| 2618 | |
| 2619 | ret = drmPrimeHandleToFD(c->drm.fd, output->current->handle, |
| 2620 | DRM_CLOEXEC, &fd); |
| 2621 | if (ret) { |
| 2622 | weston_log("[libva recorder] " |
| 2623 | "failed to create prime fd for front buffer\n"); |
| 2624 | return; |
| 2625 | } |
| 2626 | |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2627 | ret = vaapi_recorder_frame(output->recorder, fd, |
| 2628 | output->current->stride); |
| 2629 | if (ret < 0) { |
| 2630 | weston_log("[libva recorder] aborted: %m\n"); |
| 2631 | recorder_destroy(output); |
| 2632 | } |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | static void * |
| 2636 | create_recorder(struct drm_compositor *c, int width, int height, |
| 2637 | const char *filename) |
| 2638 | { |
| 2639 | int fd; |
| 2640 | drm_magic_t magic; |
| 2641 | |
| 2642 | fd = open(c->drm.filename, O_RDWR | O_CLOEXEC); |
| 2643 | if (fd < 0) |
| 2644 | return NULL; |
| 2645 | |
| 2646 | drmGetMagic(fd, &magic); |
| 2647 | drmAuthMagic(c->drm.fd, magic); |
| 2648 | |
| 2649 | return vaapi_recorder_create(fd, width, height, filename); |
| 2650 | } |
| 2651 | |
| 2652 | static void |
| 2653 | recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 2654 | void *data) |
| 2655 | { |
| 2656 | struct drm_compositor *c = data; |
| 2657 | struct drm_output *output; |
| 2658 | int width, height; |
| 2659 | |
| 2660 | output = container_of(c->base.output_list.next, |
| 2661 | struct drm_output, base.link); |
| 2662 | |
| 2663 | if (!output->recorder) { |
Ander Conselvan de Oliveira | 2ef1cd1 | 2014-05-06 16:49:06 +0300 | [diff] [blame] | 2664 | if (output->format != GBM_FORMAT_XRGB8888) { |
| 2665 | weston_log("failed to start vaapi recorder: " |
| 2666 | "output format not supported\n"); |
| 2667 | return; |
| 2668 | } |
| 2669 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2670 | width = output->base.current_mode->width; |
| 2671 | height = output->base.current_mode->height; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2672 | |
| 2673 | output->recorder = |
| 2674 | create_recorder(c, width, height, "capture.h264"); |
| 2675 | if (!output->recorder) { |
| 2676 | weston_log("failed to create vaapi recorder\n"); |
| 2677 | return; |
| 2678 | } |
| 2679 | |
| 2680 | output->base.disable_planes++; |
| 2681 | |
| 2682 | output->recorder_frame_listener.notify = recorder_frame_notify; |
| 2683 | wl_signal_add(&output->base.frame_signal, |
| 2684 | &output->recorder_frame_listener); |
| 2685 | |
| 2686 | weston_output_schedule_repaint(&output->base); |
| 2687 | |
| 2688 | weston_log("[libva recorder] initialized\n"); |
| 2689 | } else { |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2690 | recorder_destroy(output); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | #else |
| 2694 | static void |
| 2695 | recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 2696 | void *data) |
| 2697 | { |
| 2698 | weston_log("Compiled without libva support\n"); |
| 2699 | } |
| 2700 | #endif |
| 2701 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 2702 | static void |
| 2703 | switch_to_gl_renderer(struct drm_compositor *c) |
| 2704 | { |
| 2705 | struct drm_output *output; |
| 2706 | |
| 2707 | if (!c->use_pixman) |
| 2708 | return; |
| 2709 | |
| 2710 | weston_log("Switching to GL renderer\n"); |
| 2711 | |
| 2712 | c->gbm = create_gbm_device(c->drm.fd); |
| 2713 | if (!c->gbm) { |
| 2714 | weston_log("Failed to create gbm device. " |
| 2715 | "Aborting renderer switch\n"); |
| 2716 | return; |
| 2717 | } |
| 2718 | |
| 2719 | wl_list_for_each(output, &c->base.output_list, base.link) |
| 2720 | pixman_renderer_output_destroy(&output->base); |
| 2721 | |
| 2722 | c->base.renderer->destroy(&c->base); |
| 2723 | |
| 2724 | if (drm_compositor_create_gl_renderer(c) < 0) { |
| 2725 | gbm_device_destroy(c->gbm); |
| 2726 | weston_log("Failed to create GL renderer. Quitting.\n"); |
| 2727 | /* FIXME: we need a function to shutdown cleanly */ |
| 2728 | assert(0); |
| 2729 | } |
| 2730 | |
| 2731 | wl_list_for_each(output, &c->base.output_list, base.link) |
| 2732 | drm_output_init_egl(output, c); |
| 2733 | |
| 2734 | c->use_pixman = 0; |
| 2735 | } |
| 2736 | |
| 2737 | static void |
| 2738 | renderer_switch_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 2739 | void *data) |
| 2740 | { |
| 2741 | struct drm_compositor *c = (struct drm_compositor *) seat->compositor; |
| 2742 | |
| 2743 | switch_to_gl_renderer(c); |
| 2744 | } |
| 2745 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2746 | static struct weston_compositor * |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2747 | drm_compositor_create(struct wl_display *display, |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2748 | struct drm_parameters *param, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2749 | int *argc, char *argv[], |
| 2750 | struct weston_config *config) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2751 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2752 | struct drm_compositor *ec; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2753 | struct weston_config_section *section; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2754 | struct udev_device *drm_device; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2755 | struct wl_event_loop *loop; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2756 | const char *path; |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2757 | uint32_t key; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2758 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2759 | weston_log("initializing drm backend\n"); |
| 2760 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2761 | ec = zalloc(sizeof *ec); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2762 | if (ec == NULL) |
| 2763 | return NULL; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2764 | |
Kristian Høgsberg | de37d67 | 2012-11-02 10:14:40 -0400 | [diff] [blame] | 2765 | /* KMS support for sprites is not complete yet, so disable the |
| 2766 | * functionality for now. */ |
| 2767 | ec->sprites_are_broken = 1; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2768 | |
| 2769 | section = weston_config_get_section(config, "core", NULL, NULL); |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 2770 | if (get_gbm_format_from_section(section, |
| 2771 | GBM_FORMAT_XRGB8888, |
| 2772 | &ec->format) == -1) |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2773 | goto err_base; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2774 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2775 | ec->use_pixman = param->use_pixman; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2776 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2777 | if (weston_compositor_init(&ec->base, display, argc, argv, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2778 | config) < 0) { |
Scott Moreau | 8eb6748 | 2013-02-23 12:04:56 -0700 | [diff] [blame] | 2779 | weston_log("%s failed\n", __func__); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2780 | goto err_base; |
| 2781 | } |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2782 | |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 2783 | /* Check if we run drm-backend using weston-launch */ |
David Herrmann | cc5b2ed | 2013-10-22 00:28:09 +0200 | [diff] [blame] | 2784 | ec->base.launcher = weston_launcher_connect(&ec->base, param->tty, |
| 2785 | param->seat_id); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2786 | if (ec->base.launcher == NULL) { |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 2787 | weston_log("fatal: drm backend should be run " |
Kristian Høgsberg | b76237e | 2013-04-04 21:36:20 -0400 | [diff] [blame] | 2788 | "using weston-launch binary or as root\n"); |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 2789 | goto err_compositor; |
| 2790 | } |
| 2791 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2792 | ec->udev = udev_new(); |
| 2793 | if (ec->udev == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2794 | weston_log("failed to initialize udev context\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2795 | goto err_launcher; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2796 | } |
| 2797 | |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 2798 | ec->base.wl_display = display; |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2799 | ec->session_listener.notify = session_notify; |
| 2800 | wl_signal_add(&ec->base.session_signal, &ec->session_listener); |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 2801 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2802 | drm_device = find_primary_gpu(ec, param->seat_id); |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2803 | if (drm_device == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2804 | weston_log("no drm device found\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2805 | goto err_udev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2806 | } |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2807 | path = udev_device_get_syspath(drm_device); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2808 | |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 2809 | if (init_drm(ec, drm_device) < 0) { |
| 2810 | weston_log("failed to initialize kms\n"); |
| 2811 | goto err_udev_dev; |
| 2812 | } |
| 2813 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2814 | if (ec->use_pixman) { |
| 2815 | if (init_pixman(ec) < 0) { |
| 2816 | weston_log("failed to initialize pixman renderer\n"); |
| 2817 | goto err_udev_dev; |
| 2818 | } |
| 2819 | } else { |
| 2820 | if (init_egl(ec) < 0) { |
| 2821 | weston_log("failed to initialize egl\n"); |
| 2822 | goto err_udev_dev; |
| 2823 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2824 | } |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 2825 | |
| 2826 | ec->base.destroy = drm_destroy; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2827 | ec->base.restore = drm_restore; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 2828 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2829 | ec->prev_state = WESTON_COMPOSITOR_ACTIVE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2830 | |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2831 | for (key = KEY_F1; key < KEY_F9; key++) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2832 | weston_compositor_add_key_binding(&ec->base, key, |
| 2833 | MODIFIER_CTRL | MODIFIER_ALT, |
| 2834 | switch_vt_binding, ec); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2835 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2836 | wl_list_init(&ec->sprite_list); |
| 2837 | create_sprites(ec); |
| 2838 | |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 2839 | if (udev_input_init(&ec->input, |
| 2840 | &ec->base, ec->udev, param->seat_id) < 0) { |
| 2841 | weston_log("failed to create input devices\n"); |
| 2842 | goto err_sprite; |
| 2843 | } |
| 2844 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2845 | if (create_outputs(ec, param->connector, drm_device) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2846 | weston_log("failed to create output for %s\n", path); |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 2847 | goto err_udev_input; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2848 | } |
| 2849 | |
Jason Ekstrand | 9fc7151 | 2014-04-02 19:53:46 -0500 | [diff] [blame] | 2850 | /* A this point we have some idea of whether or not we have a working |
| 2851 | * cursor plane. */ |
| 2852 | if (!ec->cursors_are_broken) |
| 2853 | ec->base.capabilities |= WESTON_CAP_CURSOR_PLANE; |
| 2854 | |
Benjamin Franzke | 02dee2c | 2011-10-07 08:27:26 +0200 | [diff] [blame] | 2855 | path = NULL; |
| 2856 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2857 | loop = wl_display_get_event_loop(ec->base.wl_display); |
| 2858 | ec->drm_source = |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 2859 | wl_event_loop_add_fd(loop, ec->drm.fd, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2860 | WL_EVENT_READABLE, on_drm_input, ec); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2861 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2862 | ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev"); |
| 2863 | if (ec->udev_monitor == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2864 | weston_log("failed to intialize udev monitor\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2865 | goto err_drm_source; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2866 | } |
| 2867 | udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor, |
| 2868 | "drm", NULL); |
| 2869 | ec->udev_drm_source = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2870 | wl_event_loop_add_fd(loop, |
| 2871 | udev_monitor_get_fd(ec->udev_monitor), |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2872 | WL_EVENT_READABLE, udev_drm_event, ec); |
| 2873 | |
| 2874 | if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2875 | weston_log("failed to enable udev-monitor receiving\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2876 | goto err_udev_monitor; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2877 | } |
| 2878 | |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2879 | udev_device_unref(drm_device); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2880 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 2881 | weston_compositor_add_debug_binding(&ec->base, KEY_O, |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2882 | planes_binding, ec); |
Ander Conselvan de Oliveira | 180f42a | 2012-11-21 15:11:37 +0200 | [diff] [blame] | 2883 | weston_compositor_add_debug_binding(&ec->base, KEY_C, |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2884 | planes_binding, ec); |
| 2885 | weston_compositor_add_debug_binding(&ec->base, KEY_V, |
| 2886 | planes_binding, ec); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2887 | weston_compositor_add_debug_binding(&ec->base, KEY_Q, |
| 2888 | recorder_binding, ec); |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 2889 | weston_compositor_add_debug_binding(&ec->base, KEY_W, |
| 2890 | renderer_switch_binding, ec); |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2891 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2892 | return &ec->base; |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2893 | |
| 2894 | err_udev_monitor: |
| 2895 | wl_event_source_remove(ec->udev_drm_source); |
| 2896 | udev_monitor_unref(ec->udev_monitor); |
| 2897 | err_drm_source: |
| 2898 | wl_event_source_remove(ec->drm_source); |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 2899 | err_udev_input: |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 2900 | udev_input_destroy(&ec->input); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 2901 | err_sprite: |
Vasily Khoruzhick | 52cfd61 | 2013-01-08 19:09:01 +0300 | [diff] [blame] | 2902 | ec->base.renderer->destroy(&ec->base); |
John Kåre Alsaker | 1b7ad16 | 2012-11-13 19:10:19 +0100 | [diff] [blame] | 2903 | gbm_device_destroy(ec->gbm); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 2904 | destroy_sprites(ec); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2905 | err_udev_dev: |
| 2906 | udev_device_unref(drm_device); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2907 | err_launcher: |
| 2908 | weston_launcher_destroy(ec->base.launcher); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2909 | err_udev: |
| 2910 | udev_unref(ec->udev); |
| 2911 | err_compositor: |
| 2912 | weston_compositor_shutdown(&ec->base); |
| 2913 | err_base: |
| 2914 | free(ec); |
| 2915 | return NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2916 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2917 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2918 | WL_EXPORT struct weston_compositor * |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 2919 | backend_init(struct wl_display *display, int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2920 | struct weston_config *config) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2921 | { |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2922 | struct drm_parameters param = { 0, }; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2923 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2924 | const struct weston_option drm_options[] = { |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2925 | { WESTON_OPTION_INTEGER, "connector", 0, ¶m.connector }, |
| 2926 | { WESTON_OPTION_STRING, "seat", 0, ¶m.seat_id }, |
| 2927 | { WESTON_OPTION_INTEGER, "tty", 0, ¶m.tty }, |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2928 | { WESTON_OPTION_BOOLEAN, "current-mode", 0, &option_current_mode }, |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2929 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, ¶m.use_pixman }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2930 | }; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2931 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2932 | param.seat_id = default_seat; |
| 2933 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2934 | parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2935 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2936 | return drm_compositor_create(display, ¶m, argc, argv, config); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2937 | } |