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