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