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 |
Pekka Paalanen | 925788f | 2018-04-19 14:20:01 +0300 | [diff] [blame] | 4 | * Copyright © 2017, 2018 Collabora, Ltd. |
| 5 | * Copyright © 2017, 2018 General Electric Company |
Pekka Paalanen | 62a9436 | 2018-09-26 14:33:36 +0300 | [diff] [blame] | 6 | * Copyright (c) 2018 DisplayLink (UK) Ltd. |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 7 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 8 | * Permission is hereby granted, free of charge, to any person obtaining |
| 9 | * a copy of this software and associated documentation files (the |
| 10 | * "Software"), to deal in the Software without restriction, including |
| 11 | * without limitation the rights to use, copy, modify, merge, publish, |
| 12 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 13 | * permit persons to whom the Software is furnished to do so, subject to |
| 14 | * the following conditions: |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 15 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 16 | * The above copyright notice and this permission notice (including the |
| 17 | * next paragraph) shall be included in all copies or substantial |
| 18 | * portions of the Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 24 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 25 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 26 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 | * SOFTWARE. |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 28 | */ |
| 29 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 30 | #include "config.h" |
Kristian Høgsberg | 0b9334a | 2011-04-12 11:34:32 -0400 | [diff] [blame] | 31 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 32 | #include <errno.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 33 | #include <stdint.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 34 | #include <stdlib.h> |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 35 | #include <ctype.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 36 | #include <string.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <unistd.h> |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 39 | #include <linux/input.h> |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 40 | #include <linux/vt.h> |
Ander Conselvan de Oliveira | fd1f4c6 | 2012-06-26 17:09:14 +0300 | [diff] [blame] | 41 | #include <assert.h> |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 42 | #include <sys/mman.h> |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 43 | #include <time.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 44 | |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 45 | #include <xf86drm.h> |
| 46 | #include <xf86drmMode.h> |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 47 | #include <drm_fourcc.h> |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 48 | |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 49 | #include <libudev.h> |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 50 | |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 51 | #include <libweston/libweston.h> |
Pekka Paalanen | 7571027 | 2019-03-29 16:39:12 +0200 | [diff] [blame] | 52 | #include <libweston/backend-drm.h> |
Marius Vlad | c901e89 | 2019-06-21 22:49:18 +0300 | [diff] [blame] | 53 | #include <libweston/weston-log.h> |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 54 | #include "drm-internal.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 55 | #include "shared/helpers.h" |
Mario Kleiner | f507ec3 | 2015-06-21 21:25:14 +0200 | [diff] [blame] | 56 | #include "shared/timespec-util.h" |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 57 | #include "shared/string-helpers.h" |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 58 | #include "pixman-renderer.h" |
Daniel Stone | 0b70fa4 | 2017-04-04 17:54:23 +0100 | [diff] [blame] | 59 | #include "pixel-formats.h" |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 60 | #include "libbacklight.h" |
Peter Hutterer | 823ad33 | 2014-11-26 07:06:31 +1000 | [diff] [blame] | 61 | #include "libinput-seat.h" |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 62 | #include "launcher-util.h" |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 63 | #include "vaapi-recorder.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 64 | #include "presentation-time-server-protocol.h" |
Pekka Paalanen | e4d231e | 2014-06-12 15:12:48 +0300 | [diff] [blame] | 65 | #include "linux-dmabuf.h" |
Micah Fedke | c889012 | 2017-02-01 15:28:23 -0500 | [diff] [blame] | 66 | #include "linux-dmabuf-unstable-v1-server-protocol.h" |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 67 | #include "linux-explicit-synchronization.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 68 | |
Kristian Høgsberg | 98cfea6 | 2013-02-18 16:15:53 -0500 | [diff] [blame] | 69 | static const char default_seat[] = "seat0"; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 70 | |
Daniel Stone | 087ddf0 | 2017-02-14 17:51:30 +0000 | [diff] [blame] | 71 | static void |
Marius Vlad | e83e750 | 2019-10-29 17:29:37 +0200 | [diff] [blame] | 72 | drm_backend_create_faked_zpos(struct drm_backend *b) |
| 73 | { |
| 74 | struct drm_plane *plane; |
| 75 | uint64_t zpos = 0ULL; |
| 76 | uint64_t zpos_min_primary; |
| 77 | uint64_t zpos_min_overlay; |
| 78 | uint64_t zpos_min_cursor; |
| 79 | |
| 80 | zpos_min_primary = zpos; |
| 81 | wl_list_for_each(plane, &b->plane_list, link) { |
| 82 | /* if the property is there, bail out sooner */ |
| 83 | if (plane->props[WDRM_PLANE_ZPOS].prop_id != 0) |
| 84 | return; |
| 85 | |
| 86 | if (plane->type != WDRM_PLANE_TYPE_PRIMARY) |
| 87 | continue; |
| 88 | zpos++; |
| 89 | } |
| 90 | |
| 91 | zpos_min_overlay = zpos; |
| 92 | wl_list_for_each(plane, &b->plane_list, link) { |
| 93 | if (plane->type != WDRM_PLANE_TYPE_OVERLAY) |
| 94 | continue; |
| 95 | zpos++; |
| 96 | } |
| 97 | |
| 98 | zpos_min_cursor = zpos; |
| 99 | wl_list_for_each(plane, &b->plane_list, link) { |
| 100 | if (plane->type != WDRM_PLANE_TYPE_CURSOR) |
| 101 | continue; |
| 102 | zpos++; |
| 103 | } |
| 104 | |
| 105 | drm_debug(b, "[drm-backend] zpos property not found. " |
| 106 | "Using invented immutable zpos values:\n"); |
| 107 | /* assume that invented zpos values are immutable */ |
| 108 | wl_list_for_each(plane, &b->plane_list, link) { |
| 109 | if (plane->type == WDRM_PLANE_TYPE_PRIMARY) { |
| 110 | plane->zpos_min = zpos_min_primary; |
| 111 | plane->zpos_max = zpos_min_primary; |
| 112 | } else if (plane->type == WDRM_PLANE_TYPE_OVERLAY) { |
| 113 | plane->zpos_min = zpos_min_overlay; |
| 114 | plane->zpos_max = zpos_min_overlay; |
| 115 | } else if (plane->type == WDRM_PLANE_TYPE_CURSOR) { |
| 116 | plane->zpos_min = zpos_min_cursor; |
| 117 | plane->zpos_max = zpos_min_cursor; |
| 118 | } |
| 119 | drm_debug(b, "\t[plane] %s plane %d, zpos_min %"PRIu64", " |
| 120 | "zpos_max %"PRIu64"\n", |
| 121 | drm_output_get_plane_type_name(plane), |
| 122 | plane->plane_id, plane->zpos_min, plane->zpos_max); |
| 123 | } |
| 124 | } |
| 125 | |
Emmanuel Gil Peyrot | 11ae2a3 | 2017-03-07 13:27:54 +0000 | [diff] [blame] | 126 | static int |
| 127 | pageflip_timeout(void *data) { |
| 128 | /* |
| 129 | * Our timer just went off, that means we're not receiving drm |
| 130 | * page flip events anymore for that output. Let's gracefully exit |
| 131 | * weston with a return value so devs can debug what's going on. |
| 132 | */ |
| 133 | struct drm_output *output = data; |
| 134 | struct weston_compositor *compositor = output->base.compositor; |
| 135 | |
| 136 | weston_log("Pageflip timeout reached on output %s, your " |
| 137 | "driver is probably buggy! Exiting.\n", |
| 138 | output->base.name); |
| 139 | weston_compositor_exit_with_code(compositor, EXIT_FAILURE); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /* Creates the pageflip timer. Note that it isn't armed by default */ |
| 145 | static int |
| 146 | drm_output_pageflip_timer_create(struct drm_output *output) |
| 147 | { |
| 148 | struct wl_event_loop *loop = NULL; |
| 149 | struct weston_compositor *ec = output->base.compositor; |
| 150 | |
| 151 | loop = wl_display_get_event_loop(ec->wl_display); |
| 152 | assert(loop); |
| 153 | output->pageflip_timer = wl_event_loop_add_timer(loop, |
| 154 | pageflip_timeout, |
| 155 | output); |
| 156 | |
| 157 | if (output->pageflip_timer == NULL) { |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 158 | weston_log("creating drm pageflip timer failed: %s\n", |
| 159 | strerror(errno)); |
Emmanuel Gil Peyrot | 11ae2a3 | 2017-03-07 13:27:54 +0000 | [diff] [blame] | 160 | return -1; |
| 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 166 | static void |
| 167 | drm_output_destroy(struct weston_output *output_base); |
| 168 | |
Daniel Stone | 5ff289a | 2017-10-07 12:59:02 +0100 | [diff] [blame] | 169 | /** |
| 170 | * Returns true if the plane can be used on the given output for its current |
| 171 | * repaint cycle. |
| 172 | */ |
Daniel Stone | e404b72 | 2019-06-22 18:40:31 +0100 | [diff] [blame] | 173 | bool |
Daniel Stone | 5ff289a | 2017-10-07 12:59:02 +0100 | [diff] [blame] | 174 | drm_plane_is_available(struct drm_plane *plane, struct drm_output *output) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 175 | { |
Daniel Stone | 5ff289a | 2017-10-07 12:59:02 +0100 | [diff] [blame] | 176 | assert(plane->state_cur); |
| 177 | |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 178 | if (output->virtual) |
| 179 | return false; |
| 180 | |
Daniel Stone | 5ff289a | 2017-10-07 12:59:02 +0100 | [diff] [blame] | 181 | /* The plane still has a request not yet completed by the kernel. */ |
| 182 | if (!plane->state_cur->complete) |
| 183 | return false; |
| 184 | |
| 185 | /* The plane is still active on another output. */ |
| 186 | if (plane->state_cur->output && plane->state_cur->output != output) |
| 187 | return false; |
| 188 | |
| 189 | /* Check whether the plane can be used with this CRTC; possible_crtcs |
| 190 | * is a bitmask of CRTC indices (pipe), rather than CRTC object ID. */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 191 | return !!(plane->possible_crtcs & (1 << output->crtc->pipe)); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 192 | } |
| 193 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 194 | struct drm_crtc * |
| 195 | drm_crtc_find(struct drm_backend *b, uint32_t crtc_id) |
Daniel Stone | 72c0e1b | 2017-02-09 13:49:15 +0000 | [diff] [blame] | 196 | { |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 197 | struct drm_crtc *crtc; |
Daniel Stone | 72c0e1b | 2017-02-09 13:49:15 +0000 | [diff] [blame] | 198 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 199 | wl_list_for_each(crtc, &b->crtc_list, link) { |
| 200 | if (crtc->crtc_id == crtc_id) |
| 201 | return crtc; |
Daniel Stone | 72c0e1b | 2017-02-09 13:49:15 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Daniel Stone | 72c0e1b | 2017-02-09 13:49:15 +0000 | [diff] [blame] | 204 | return NULL; |
| 205 | } |
| 206 | |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 207 | struct drm_head * |
Pekka Paalanen | 54cc47c | 2017-08-31 11:58:41 +0300 | [diff] [blame] | 208 | drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id) |
| 209 | { |
| 210 | struct weston_head *base; |
| 211 | struct drm_head *head; |
| 212 | |
| 213 | wl_list_for_each(base, |
| 214 | &backend->compositor->head_list, compositor_link) { |
| 215 | head = to_drm_head(base); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 216 | if (head->connector.connector_id == connector_id) |
Pekka Paalanen | 54cc47c | 2017-08-31 11:58:41 +0300 | [diff] [blame] | 217 | return head; |
| 218 | } |
| 219 | |
| 220 | return NULL; |
| 221 | } |
| 222 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 223 | static struct drm_writeback * |
| 224 | drm_writeback_find_by_connector(struct drm_backend *backend, uint32_t connector_id) |
| 225 | { |
| 226 | struct drm_writeback *writeback; |
| 227 | |
| 228 | wl_list_for_each(writeback, &backend->writeback_connector_list, link) { |
| 229 | if (writeback->connector.connector_id == connector_id) |
| 230 | return writeback; |
| 231 | } |
| 232 | |
| 233 | return NULL; |
| 234 | } |
| 235 | |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 236 | /** |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 237 | * Get output state to disable output |
| 238 | * |
| 239 | * Returns a pointer to an output_state object which can be used to disable |
| 240 | * an output (e.g. DPMS off). |
| 241 | * |
| 242 | * @param pending_state The pending state object owning this update |
| 243 | * @param output The output to disable |
| 244 | * @returns A drm_output_state to disable the output |
| 245 | */ |
| 246 | static struct drm_output_state * |
| 247 | drm_output_get_disable_state(struct drm_pending_state *pending_state, |
| 248 | struct drm_output *output) |
| 249 | { |
| 250 | struct drm_output_state *output_state; |
| 251 | |
| 252 | output_state = drm_output_state_duplicate(output->state_cur, |
| 253 | pending_state, |
| 254 | DRM_OUTPUT_STATE_CLEAR_PLANES); |
| 255 | output_state->dpms = WESTON_DPMS_OFF; |
| 256 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 257 | output_state->protection = WESTON_HDCP_DISABLE; |
| 258 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 259 | return output_state; |
| 260 | } |
| 261 | |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * Mark a drm_output_state (the output's last state) as complete. This handles |
| 265 | * any post-completion actions such as updating the repaint timer, disabling the |
| 266 | * output, and finally freeing the state. |
| 267 | */ |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 268 | void |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 269 | drm_output_update_complete(struct drm_output *output, uint32_t flags, |
| 270 | unsigned int sec, unsigned int usec) |
| 271 | { |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 272 | struct drm_backend *b = to_drm_backend(output->base.compositor); |
Daniel Stone | bc15f68 | 2016-11-14 16:57:01 +0000 | [diff] [blame] | 273 | struct drm_plane_state *ps; |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 274 | struct timespec ts; |
| 275 | |
| 276 | /* Stop the pageflip timer instead of rearming it here */ |
| 277 | if (output->pageflip_timer) |
| 278 | wl_event_source_timer_update(output->pageflip_timer, 0); |
| 279 | |
Daniel Stone | bc15f68 | 2016-11-14 16:57:01 +0000 | [diff] [blame] | 280 | wl_list_for_each(ps, &output->state_cur->plane_list, link) |
| 281 | ps->complete = true; |
| 282 | |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 283 | drm_output_state_free(output->state_last); |
| 284 | output->state_last = NULL; |
| 285 | |
| 286 | if (output->destroy_pending) { |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 287 | output->destroy_pending = false; |
| 288 | output->disable_pending = false; |
| 289 | output->dpms_off_pending = false; |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 290 | drm_output_destroy(&output->base); |
| 291 | return; |
| 292 | } else if (output->disable_pending) { |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 293 | output->disable_pending = false; |
| 294 | output->dpms_off_pending = false; |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 295 | weston_output_disable(&output->base); |
| 296 | return; |
| 297 | } else if (output->dpms_off_pending) { |
| 298 | struct drm_pending_state *pending = drm_pending_state_alloc(b); |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 299 | output->dpms_off_pending = false; |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 300 | drm_output_get_disable_state(pending, output); |
| 301 | drm_pending_state_apply_sync(pending); |
Michael Olbrich | d70e712 | 2020-08-06 09:57:54 +0200 | [diff] [blame] | 302 | } |
| 303 | if (output->state_cur->dpms == WESTON_DPMS_OFF && |
| 304 | output->base.repaint_status != REPAINT_AWAITING_COMPLETION) { |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 305 | /* DPMS can happen to us either in the middle of a repaint |
| 306 | * cycle (when we have painted fresh content, only to throw it |
| 307 | * away for DPMS off), or at any other random point. If the |
| 308 | * latter is true, then we cannot go through finish_frame, |
| 309 | * because the repaint machinery does not expect this. */ |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | |
| 313 | ts.tv_sec = sec; |
| 314 | ts.tv_nsec = usec * 1000; |
| 315 | weston_output_finish_frame(&output->base, &ts, flags); |
| 316 | |
| 317 | /* We can't call this from frame_notify, because the output's |
| 318 | * repaint needed flag is cleared just after that */ |
| 319 | if (output->recorder) |
| 320 | weston_output_schedule_repaint(&output->base); |
| 321 | } |
| 322 | |
Daniel Stone | 95d48a2 | 2017-04-04 17:54:30 +0100 | [diff] [blame] | 323 | static struct drm_fb * |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 324 | drm_output_render_pixman(struct drm_output_state *state, |
| 325 | pixman_region32_t *damage) |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 326 | { |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 327 | struct drm_output *output = state->output; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 328 | struct weston_compositor *ec = output->base.compositor; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 329 | |
| 330 | output->current_image ^= 1; |
| 331 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 332 | pixman_renderer_output_set_buffer(&output->base, |
| 333 | output->image[output->current_image]); |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 334 | pixman_renderer_output_set_hw_extra_damage(&output->base, |
| 335 | &output->previous_damage); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 336 | |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 337 | ec->renderer->repaint_output(&output->base, damage); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 338 | |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 339 | pixman_region32_copy(&output->previous_damage, damage); |
Daniel Stone | 95d48a2 | 2017-04-04 17:54:30 +0100 | [diff] [blame] | 340 | |
| 341 | return drm_fb_ref(output->dumb[output->current_image]); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Stefan Agner | 3654c67 | 2019-07-09 00:50:30 +0200 | [diff] [blame] | 344 | void |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 345 | drm_output_render(struct drm_output_state *state, pixman_region32_t *damage) |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 346 | { |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 347 | struct drm_output *output = state->output; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 348 | struct weston_compositor *c = output->base.compositor; |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 349 | struct drm_plane_state *scanout_state; |
Daniel Stone | e95169b | 2016-11-14 17:46:59 +0000 | [diff] [blame] | 350 | struct drm_plane *scanout_plane = output->scanout_plane; |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 351 | struct drm_property_info *damage_info = |
| 352 | &scanout_plane->props[WDRM_PLANE_FB_DAMAGE_CLIPS]; |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 353 | struct drm_backend *b = to_drm_backend(c); |
Daniel Stone | 95d48a2 | 2017-04-04 17:54:30 +0100 | [diff] [blame] | 354 | struct drm_fb *fb; |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 355 | pixman_region32_t scanout_damage; |
| 356 | pixman_box32_t *rects; |
| 357 | int n_rects; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 358 | |
Daniel Stone | 4e84f7d | 2017-04-04 17:54:29 +0100 | [diff] [blame] | 359 | /* If we already have a client buffer promoted to scanout, then we don't |
| 360 | * want to render. */ |
Leandro Ribeiro | 05cecc8 | 2020-08-13 17:34:58 -0300 | [diff] [blame] | 361 | scanout_state = drm_output_state_get_plane(state, scanout_plane); |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 362 | if (scanout_state->fb) |
Daniel Stone | 4e84f7d | 2017-04-04 17:54:29 +0100 | [diff] [blame] | 363 | return; |
| 364 | |
Daniel Stone | 98d75e1 | 2020-03-06 11:03:14 +0000 | [diff] [blame] | 365 | /* |
| 366 | * If we don't have any damage on the primary plane, and we already |
| 367 | * have a renderer buffer active, we can reuse it; else we pass |
| 368 | * the damaged region into the renderer to re-render the affected |
Pekka Paalanen | 7f1a113 | 2020-12-07 14:59:44 +0200 | [diff] [blame^] | 369 | * area. But, we still have to call the renderer anyway if any screen |
| 370 | * capture is pending, otherwise the capture will not complete. |
Daniel Stone | 98d75e1 | 2020-03-06 11:03:14 +0000 | [diff] [blame] | 371 | */ |
Daniel Stone | e95169b | 2016-11-14 17:46:59 +0000 | [diff] [blame] | 372 | if (!pixman_region32_not_empty(damage) && |
Pekka Paalanen | 7f1a113 | 2020-12-07 14:59:44 +0200 | [diff] [blame^] | 373 | wl_list_empty(&output->base.frame_signal.listener_list) && |
Daniel Stone | e95169b | 2016-11-14 17:46:59 +0000 | [diff] [blame] | 374 | scanout_plane->state_cur->fb && |
| 375 | (scanout_plane->state_cur->fb->type == BUFFER_GBM_SURFACE || |
Daniel Stone | 98d75e1 | 2020-03-06 11:03:14 +0000 | [diff] [blame] | 376 | scanout_plane->state_cur->fb->type == BUFFER_PIXMAN_DUMB)) { |
Daniel Stone | e95169b | 2016-11-14 17:46:59 +0000 | [diff] [blame] | 377 | fb = drm_fb_ref(scanout_plane->state_cur->fb); |
| 378 | } else if (b->use_pixman) { |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 379 | fb = drm_output_render_pixman(state, damage); |
Daniel Stone | e95169b | 2016-11-14 17:46:59 +0000 | [diff] [blame] | 380 | } else { |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 381 | fb = drm_output_render_gl(state, damage); |
Daniel Stone | e95169b | 2016-11-14 17:46:59 +0000 | [diff] [blame] | 382 | } |
Daniel Stone | 95d48a2 | 2017-04-04 17:54:30 +0100 | [diff] [blame] | 383 | |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 384 | if (!fb) { |
| 385 | drm_plane_state_put_back(scanout_state); |
Daniel Stone | 95d48a2 | 2017-04-04 17:54:30 +0100 | [diff] [blame] | 386 | return; |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | scanout_state->fb = fb; |
| 390 | scanout_state->output = output; |
| 391 | |
| 392 | scanout_state->src_x = 0; |
| 393 | scanout_state->src_y = 0; |
Daniel Stone | f9a6162 | 2020-03-06 11:07:15 +0000 | [diff] [blame] | 394 | scanout_state->src_w = fb->width << 16; |
| 395 | scanout_state->src_h = fb->height << 16; |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 396 | |
| 397 | scanout_state->dest_x = 0; |
| 398 | scanout_state->dest_y = 0; |
Daniel Stone | f9a6162 | 2020-03-06 11:07:15 +0000 | [diff] [blame] | 399 | scanout_state->dest_w = output->base.current_mode->width; |
| 400 | scanout_state->dest_h = output->base.current_mode->height; |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 401 | |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 402 | pixman_region32_subtract(&c->primary_plane.damage, |
| 403 | &c->primary_plane.damage, damage); |
| 404 | |
| 405 | /* Don't bother calculating plane damage if the plane doesn't support it */ |
| 406 | if (damage_info->prop_id == 0) |
| 407 | return; |
| 408 | |
| 409 | pixman_region32_init(&scanout_damage); |
| 410 | pixman_region32_copy(&scanout_damage, damage); |
| 411 | |
Deepak Rawat | 46a1c72 | 2018-07-24 14:13:34 -0700 | [diff] [blame] | 412 | if (output->base.zoom.active) { |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 413 | weston_matrix_transform_region(&scanout_damage, |
Deepak Rawat | 46a1c72 | 2018-07-24 14:13:34 -0700 | [diff] [blame] | 414 | &output->base.matrix, |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 415 | &scanout_damage); |
Deepak Rawat | 46a1c72 | 2018-07-24 14:13:34 -0700 | [diff] [blame] | 416 | } else { |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 417 | pixman_region32_translate(&scanout_damage, |
Deepak Rawat | 46a1c72 | 2018-07-24 14:13:34 -0700 | [diff] [blame] | 418 | -output->base.x, -output->base.y); |
| 419 | weston_transformed_region(output->base.width, |
| 420 | output->base.height, |
| 421 | output->base.transform, |
| 422 | output->base.current_scale, |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 423 | &scanout_damage, |
| 424 | &scanout_damage); |
Deepak Rawat | 46a1c72 | 2018-07-24 14:13:34 -0700 | [diff] [blame] | 425 | } |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 426 | |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 427 | assert(scanout_state->damage_blob_id == 0); |
| 428 | |
| 429 | rects = pixman_region32_rectangles(&scanout_damage, &n_rects); |
| 430 | |
| 431 | /* |
| 432 | * If this function fails, the blob id should still be 0. |
| 433 | * This tells the kernel there is no damage information, which means |
| 434 | * that it will consider the whole plane damaged. While this may |
| 435 | * affect efficiency, it should still produce correct results. |
| 436 | */ |
| 437 | drmModeCreatePropertyBlob(b->drm.fd, rects, |
| 438 | sizeof(*rects) * n_rects, |
| 439 | &scanout_state->damage_blob_id); |
| 440 | |
| 441 | pixman_region32_fini(&scanout_damage); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 444 | static int |
| 445 | drm_output_repaint(struct weston_output *output_base, |
| 446 | pixman_region32_t *damage, |
| 447 | void *repaint_data) |
| 448 | { |
| 449 | struct drm_pending_state *pending_state = repaint_data; |
| 450 | struct drm_output *output = to_drm_output(output_base); |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 451 | struct drm_output_state *state = NULL; |
| 452 | struct drm_plane_state *scanout_state; |
| 453 | |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 454 | assert(!output->virtual); |
| 455 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 456 | if (output->disable_pending || output->destroy_pending) |
| 457 | goto err; |
| 458 | |
| 459 | assert(!output->state_last); |
| 460 | |
| 461 | /* If planes have been disabled in the core, we might not have |
| 462 | * hit assign_planes at all, so might not have valid output state |
| 463 | * here. */ |
| 464 | state = drm_pending_state_get_output(pending_state, output); |
| 465 | if (!state) |
| 466 | state = drm_output_state_duplicate(output->state_cur, |
| 467 | pending_state, |
| 468 | DRM_OUTPUT_STATE_CLEAR_PLANES); |
| 469 | state->dpms = WESTON_DPMS_ON; |
| 470 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 471 | if (output_base->allow_protection) |
| 472 | state->protection = output_base->desired_protection; |
| 473 | else |
| 474 | state->protection = WESTON_HDCP_DISABLE; |
| 475 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 476 | drm_output_render(state, damage); |
| 477 | scanout_state = drm_output_state_get_plane(state, |
| 478 | output->scanout_plane); |
| 479 | if (!scanout_state || !scanout_state->fb) |
| 480 | goto err; |
| 481 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 482 | return 0; |
| 483 | |
| 484 | err: |
| 485 | drm_output_state_free(state); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 486 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 487 | } |
| 488 | |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 489 | /* Determine the type of vblank synchronization to use for the output. |
| 490 | * |
| 491 | * The pipe parameter indicates which CRTC is in use. Knowing this, we |
| 492 | * can determine which vblank sequence type to use for it. Traditional |
| 493 | * cards had only two CRTCs, with CRTC 0 using no special flags, and |
| 494 | * CRTC 1 using DRM_VBLANK_SECONDARY. The first bit of the pipe |
| 495 | * parameter indicates this. |
| 496 | * |
| 497 | * Bits 1-5 of the pipe parameter are 5 bit wide pipe number between |
| 498 | * 0-31. If this is non-zero it indicates we're dealing with a |
| 499 | * multi-gpu situation and we need to calculate the vblank sync |
| 500 | * using DRM_BLANK_HIGH_CRTC_MASK. |
| 501 | */ |
| 502 | static unsigned int |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 503 | drm_waitvblank_pipe(struct drm_crtc *crtc) |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 504 | { |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 505 | if (crtc->pipe > 1) |
| 506 | return (crtc->pipe << DRM_VBLANK_HIGH_CRTC_SHIFT) & |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 507 | DRM_VBLANK_HIGH_CRTC_MASK; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 508 | else if (crtc->pipe > 0) |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 509 | return DRM_VBLANK_SECONDARY; |
| 510 | else |
| 511 | return 0; |
| 512 | } |
| 513 | |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 514 | static int |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 515 | drm_output_start_repaint_loop(struct weston_output *output_base) |
| 516 | { |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 517 | struct drm_output *output = to_drm_output(output_base); |
Daniel Stone | 8747f95 | 2016-11-29 20:17:32 +0000 | [diff] [blame] | 518 | struct drm_pending_state *pending_state; |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 519 | struct drm_plane *scanout_plane = output->scanout_plane; |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 520 | struct drm_backend *backend = |
| 521 | to_drm_backend(output_base->compositor); |
Mario Kleiner | f507ec3 | 2015-06-21 21:25:14 +0200 | [diff] [blame] | 522 | struct timespec ts, tnow; |
| 523 | struct timespec vbl2now; |
| 524 | int64_t refresh_nsec; |
| 525 | int ret; |
| 526 | drmVBlank vbl = { |
| 527 | .request.type = DRM_VBLANK_RELATIVE, |
| 528 | .request.sequence = 0, |
| 529 | .request.signal = 0, |
| 530 | }; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 531 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 532 | if (output->disable_pending || output->destroy_pending) |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 533 | return 0; |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 534 | |
Leandro Ribeiro | 05cecc8 | 2020-08-13 17:34:58 -0300 | [diff] [blame] | 535 | if (!scanout_plane->state_cur->fb) { |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 536 | /* We can't page flip if there's no mode set */ |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 537 | goto finish_frame; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 538 | } |
| 539 | |
Pekka Paalanen | 6b65d8f | 2017-07-27 13:44:32 +0300 | [diff] [blame] | 540 | /* Need to smash all state in from scratch; current timings might not |
| 541 | * be what we want, page flip might not work, etc. |
| 542 | */ |
Daniel Stone | 6020f47 | 2018-02-05 15:46:20 +0000 | [diff] [blame] | 543 | if (backend->state_invalid) |
Pekka Paalanen | 6b65d8f | 2017-07-27 13:44:32 +0300 | [diff] [blame] | 544 | goto finish_frame; |
| 545 | |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 546 | assert(scanout_plane->state_cur->output == output); |
| 547 | |
Mario Kleiner | f507ec3 | 2015-06-21 21:25:14 +0200 | [diff] [blame] | 548 | /* Try to get current msc and timestamp via instant query */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 549 | vbl.request.type |= drm_waitvblank_pipe(output->crtc); |
Mario Kleiner | f507ec3 | 2015-06-21 21:25:14 +0200 | [diff] [blame] | 550 | ret = drmWaitVBlank(backend->drm.fd, &vbl); |
| 551 | |
| 552 | /* Error ret or zero timestamp means failure to get valid timestamp */ |
| 553 | if ((ret == 0) && (vbl.reply.tval_sec > 0 || vbl.reply.tval_usec > 0)) { |
| 554 | ts.tv_sec = vbl.reply.tval_sec; |
| 555 | ts.tv_nsec = vbl.reply.tval_usec * 1000; |
| 556 | |
| 557 | /* Valid timestamp for most recent vblank - not stale? |
| 558 | * Stale ts could happen on Linux 3.17+, so make sure it |
| 559 | * is not older than 1 refresh duration since now. |
| 560 | */ |
| 561 | weston_compositor_read_presentation_clock(backend->compositor, |
| 562 | &tnow); |
| 563 | timespec_sub(&vbl2now, &tnow, &ts); |
| 564 | refresh_nsec = |
| 565 | millihz_to_nsec(output->base.current_mode->refresh); |
| 566 | if (timespec_to_nsec(&vbl2now) < refresh_nsec) { |
| 567 | drm_output_update_msc(output, vbl.reply.sequence); |
| 568 | weston_output_finish_frame(output_base, &ts, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 569 | WP_PRESENTATION_FEEDBACK_INVALID); |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 570 | return 0; |
Mario Kleiner | f507ec3 | 2015-06-21 21:25:14 +0200 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
| 574 | /* Immediate query didn't provide valid timestamp. |
| 575 | * Use pageflip fallback. |
| 576 | */ |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 577 | |
Daniel Stone | 205c0a0 | 2017-04-04 17:54:33 +0100 | [diff] [blame] | 578 | assert(!output->page_flip_pending); |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 579 | assert(!output->state_last); |
| 580 | |
| 581 | pending_state = drm_pending_state_alloc(backend); |
Daniel Stone | 8747f95 | 2016-11-29 20:17:32 +0000 | [diff] [blame] | 582 | drm_output_state_duplicate(output->state_cur, pending_state, |
| 583 | DRM_OUTPUT_STATE_PRESERVE_PLANES); |
Daniel Stone | 205c0a0 | 2017-04-04 17:54:33 +0100 | [diff] [blame] | 584 | |
Daniel Stone | 8747f95 | 2016-11-29 20:17:32 +0000 | [diff] [blame] | 585 | ret = drm_pending_state_apply(pending_state); |
| 586 | if (ret != 0) { |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 587 | weston_log("applying repaint-start state failed: %s\n", |
| 588 | strerror(errno)); |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 589 | if (ret == -EACCES) |
| 590 | return -1; |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 591 | goto finish_frame; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 592 | } |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 593 | |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 594 | return 0; |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 595 | |
| 596 | finish_frame: |
| 597 | /* if we cannot page-flip, immediately finish frame */ |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 598 | weston_output_finish_frame(output_base, NULL, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 599 | WP_PRESENTATION_FEEDBACK_INVALID); |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 600 | return 0; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 603 | /** |
| 604 | * Begin a new repaint cycle |
| 605 | * |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 606 | * Called by the core compositor at the beginning of a repaint cycle. Creates |
| 607 | * a new pending_state structure to own any output state created by individual |
| 608 | * output repaint functions until the repaint is flushed or cancelled. |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 609 | */ |
| 610 | static void * |
| 611 | drm_repaint_begin(struct weston_compositor *compositor) |
| 612 | { |
| 613 | struct drm_backend *b = to_drm_backend(compositor); |
| 614 | struct drm_pending_state *ret; |
| 615 | |
| 616 | ret = drm_pending_state_alloc(b); |
| 617 | b->repaint_data = ret; |
| 618 | |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 619 | if (weston_log_scope_is_enabled(b->debug)) { |
Daniel Stone | 1cbe1f9 | 2018-07-20 10:21:28 +0100 | [diff] [blame] | 620 | char *dbg = weston_compositor_print_scene_graph(compositor); |
| 621 | drm_debug(b, "[repaint] Beginning repaint; pending_state %p\n", |
| 622 | ret); |
| 623 | drm_debug(b, "%s", dbg); |
| 624 | free(dbg); |
| 625 | } |
| 626 | |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 627 | return ret; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Flush a repaint set |
| 632 | * |
| 633 | * Called by the core compositor when a repaint cycle has been completed |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 634 | * and should be flushed. Frees the pending state, transitioning ownership |
| 635 | * of the output state from the pending state, to the update itself. When |
| 636 | * the update completes (see drm_output_update_complete), the output |
| 637 | * state will be freed. |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 638 | */ |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 639 | static int |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 640 | drm_repaint_flush(struct weston_compositor *compositor, void *repaint_data) |
| 641 | { |
| 642 | struct drm_backend *b = to_drm_backend(compositor); |
| 643 | struct drm_pending_state *pending_state = repaint_data; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 644 | int ret; |
Daniel Stone | 6020f47 | 2018-02-05 15:46:20 +0000 | [diff] [blame] | 645 | |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 646 | ret = drm_pending_state_apply(pending_state); |
| 647 | if (ret != 0) |
| 648 | weston_log("repaint-flush failed: %s\n", strerror(errno)); |
| 649 | |
Daniel Stone | 1cbe1f9 | 2018-07-20 10:21:28 +0100 | [diff] [blame] | 650 | drm_debug(b, "[repaint] flushed pending_state %p\n", pending_state); |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 651 | b->repaint_data = NULL; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 652 | |
| 653 | return (ret == -EACCES) ? -1 : 0; |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Cancel a repaint set |
| 658 | * |
| 659 | * Called by the core compositor when a repaint has finished, so the data |
| 660 | * held across the repaint cycle should be discarded. |
| 661 | */ |
| 662 | static void |
| 663 | drm_repaint_cancel(struct weston_compositor *compositor, void *repaint_data) |
| 664 | { |
| 665 | struct drm_backend *b = to_drm_backend(compositor); |
| 666 | struct drm_pending_state *pending_state = repaint_data; |
| 667 | |
| 668 | drm_pending_state_free(pending_state); |
Daniel Stone | 1cbe1f9 | 2018-07-20 10:21:28 +0100 | [diff] [blame] | 669 | drm_debug(b, "[repaint] cancel pending_state %p\n", pending_state); |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 670 | b->repaint_data = NULL; |
| 671 | } |
| 672 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 673 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 674 | drm_output_init_pixman(struct drm_output *output, struct drm_backend *b); |
Daniel Stone | 3e661f7 | 2016-11-04 17:24:06 +0000 | [diff] [blame] | 675 | static void |
| 676 | drm_output_fini_pixman(struct drm_output *output); |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 677 | |
| 678 | static int |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 679 | drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode) |
| 680 | { |
Daniel Stone | 02d487a | 2017-10-07 14:01:45 +0100 | [diff] [blame] | 681 | struct drm_output *output = to_drm_output(output_base); |
| 682 | struct drm_backend *b = to_drm_backend(output_base->compositor); |
Daniel Stone | fbe6c1d | 2019-06-17 16:04:26 +0100 | [diff] [blame] | 683 | struct drm_mode *drm_mode = drm_output_choose_mode(output, mode); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 684 | |
| 685 | if (!drm_mode) { |
Daniel Stone | 02d487a | 2017-10-07 14:01:45 +0100 | [diff] [blame] | 686 | weston_log("%s: invalid resolution %dx%d\n", |
| 687 | output_base->name, mode->width, mode->height); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 688 | return -1; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 689 | } |
| 690 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 691 | if (&drm_mode->base == output->base.current_mode) |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 692 | return 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 693 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 694 | output->base.current_mode->flags = 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 695 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 696 | output->base.current_mode = &drm_mode->base; |
| 697 | output->base.current_mode->flags = |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 698 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 699 | |
Daniel Stone | f30a18c | 2017-04-04 17:54:31 +0100 | [diff] [blame] | 700 | /* XXX: This drops our current buffer too early, before we've started |
| 701 | * displaying it. Ideally this should be much more atomic and |
| 702 | * integrated with a full repaint cycle, rather than doing a |
| 703 | * sledgehammer modeswitch first, and only later showing new |
| 704 | * content. |
| 705 | */ |
Daniel Stone | 6020f47 | 2018-02-05 15:46:20 +0000 | [diff] [blame] | 706 | b->state_invalid = true; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 707 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 708 | if (b->use_pixman) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 709 | drm_output_fini_pixman(output); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 710 | if (drm_output_init_pixman(output, b) < 0) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 711 | weston_log("failed to init output pixman state with " |
| 712 | "new mode\n"); |
| 713 | return -1; |
| 714 | } |
| 715 | } else { |
Daniel Stone | 3e661f7 | 2016-11-04 17:24:06 +0000 | [diff] [blame] | 716 | drm_output_fini_egl(output); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 717 | if (drm_output_init_egl(output, b) < 0) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 718 | weston_log("failed to init output egl state with " |
| 719 | "new mode"); |
| 720 | return -1; |
| 721 | } |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 722 | } |
| 723 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 724 | return 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 725 | } |
| 726 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 727 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 728 | init_pixman(struct drm_backend *b) |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 729 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 730 | return pixman_renderer_init(b->compositor); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 731 | } |
| 732 | |
Pekka Paalanen | 7b36b42 | 2014-06-04 14:00:53 +0300 | [diff] [blame] | 733 | /** |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 734 | * Create a drm_plane for a hardware plane |
| 735 | * |
| 736 | * Creates one drm_plane structure for a hardware plane, and initialises its |
| 737 | * properties and formats. |
| 738 | * |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 739 | * In the absence of universal plane support, where KMS does not explicitly |
| 740 | * expose the primary and cursor planes to userspace, this may also create |
| 741 | * an 'internal' plane for internal management. |
| 742 | * |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 743 | * This function does not add the plane to the list of usable planes in Weston |
| 744 | * itself; the caller is responsible for this. |
| 745 | * |
| 746 | * Call drm_plane_destroy to clean up the plane. |
| 747 | * |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 748 | * @sa drm_output_find_special_plane |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 749 | * @param b DRM compositor backend |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 750 | * @param kplane DRM plane to create, or NULL if creating internal plane |
| 751 | * @param output Output to create internal plane for, or NULL |
| 752 | * @param type Type to use when creating internal plane, or invalid |
| 753 | * @param format Format to use for internal planes, or 0 |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 754 | */ |
| 755 | static struct drm_plane * |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 756 | drm_plane_create(struct drm_backend *b, const drmModePlane *kplane, |
| 757 | struct drm_output *output, enum wdrm_plane_type type, |
| 758 | uint32_t format) |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 759 | { |
| 760 | struct drm_plane *plane; |
Pekka Paalanen | c5de57f | 2015-05-20 23:01:44 +0100 | [diff] [blame] | 761 | drmModeObjectProperties *props; |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 762 | uint64_t *zpos_range_values; |
Sergi Granell | f445622 | 2017-01-12 17:17:32 +0000 | [diff] [blame] | 763 | uint32_t num_formats = (kplane) ? kplane->count_formats : 1; |
Pekka Paalanen | c5de57f | 2015-05-20 23:01:44 +0100 | [diff] [blame] | 764 | |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 765 | plane = zalloc(sizeof(*plane) + |
Sergi Granell | f445622 | 2017-01-12 17:17:32 +0000 | [diff] [blame] | 766 | (sizeof(plane->formats[0]) * num_formats)); |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 767 | if (!plane) { |
| 768 | weston_log("%s: out of memory\n", __func__); |
| 769 | return NULL; |
| 770 | } |
| 771 | |
| 772 | plane->backend = b; |
Sergi Granell | f445622 | 2017-01-12 17:17:32 +0000 | [diff] [blame] | 773 | plane->count_formats = num_formats; |
Daniel Stone | bc15f68 | 2016-11-14 16:57:01 +0000 | [diff] [blame] | 774 | plane->state_cur = drm_plane_state_alloc(NULL, plane); |
| 775 | plane->state_cur->complete = true; |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 776 | |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 777 | if (kplane) { |
| 778 | plane->possible_crtcs = kplane->possible_crtcs; |
| 779 | plane->plane_id = kplane->plane_id; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 780 | |
| 781 | props = drmModeObjectGetProperties(b->drm.fd, kplane->plane_id, |
| 782 | DRM_MODE_OBJECT_PLANE); |
| 783 | if (!props) { |
| 784 | weston_log("couldn't get plane properties\n"); |
| 785 | goto err; |
| 786 | } |
| 787 | drm_property_info_populate(b, plane_props, plane->props, |
| 788 | WDRM_PLANE__COUNT, props); |
| 789 | plane->type = |
| 790 | drm_property_get_value(&plane->props[WDRM_PLANE_TYPE], |
| 791 | props, |
| 792 | WDRM_PLANE_TYPE__COUNT); |
Sergi Granell | f445622 | 2017-01-12 17:17:32 +0000 | [diff] [blame] | 793 | |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 794 | zpos_range_values = |
Daniel Stone | 7fa97e6 | 2020-03-06 11:03:01 +0000 | [diff] [blame] | 795 | drm_property_get_range_values(&plane->props[WDRM_PLANE_ZPOS], |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 796 | props); |
| 797 | |
| 798 | if (zpos_range_values) { |
| 799 | plane->zpos_min = zpos_range_values[0]; |
| 800 | plane->zpos_max = zpos_range_values[1]; |
| 801 | } else { |
| 802 | plane->zpos_min = DRM_PLANE_ZPOS_INVALID_PLANE; |
| 803 | plane->zpos_max = DRM_PLANE_ZPOS_INVALID_PLANE; |
| 804 | } |
| 805 | |
Stefan Agner | 465ab2c | 2020-06-17 23:36:44 +0200 | [diff] [blame] | 806 | if (drm_plane_populate_formats(plane, kplane, props, |
| 807 | b->fb_modifiers) < 0) { |
Sergi Granell | f445622 | 2017-01-12 17:17:32 +0000 | [diff] [blame] | 808 | drmModeFreeObjectProperties(props); |
| 809 | goto err; |
| 810 | } |
| 811 | |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 812 | drmModeFreeObjectProperties(props); |
Pekka Paalanen | c5de57f | 2015-05-20 23:01:44 +0100 | [diff] [blame] | 813 | } |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 814 | else { |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 815 | plane->possible_crtcs = (1 << output->crtc->pipe); |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 816 | plane->plane_id = 0; |
| 817 | plane->count_formats = 1; |
Sergi Granell | f445622 | 2017-01-12 17:17:32 +0000 | [diff] [blame] | 818 | plane->formats[0].format = format; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 819 | plane->type = type; |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 820 | plane->zpos_max = DRM_PLANE_ZPOS_INVALID_PLANE; |
| 821 | plane->zpos_min = DRM_PLANE_ZPOS_INVALID_PLANE; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | if (plane->type == WDRM_PLANE_TYPE__COUNT) |
| 825 | goto err_props; |
| 826 | |
| 827 | /* With universal planes, everything is a DRM plane; without |
| 828 | * universal planes, the only DRM planes are overlay planes. |
| 829 | * Everything else is a fake plane. */ |
| 830 | if (b->universal_planes) { |
| 831 | assert(kplane); |
| 832 | } else { |
| 833 | if (kplane) |
| 834 | assert(plane->type == WDRM_PLANE_TYPE_OVERLAY); |
| 835 | else |
| 836 | assert(plane->type != WDRM_PLANE_TYPE_OVERLAY && |
| 837 | output); |
| 838 | } |
Pekka Paalanen | c5de57f | 2015-05-20 23:01:44 +0100 | [diff] [blame] | 839 | |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 840 | weston_plane_init(&plane->base, b->compositor, 0, 0); |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 841 | wl_list_insert(&b->plane_list, &plane->link); |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 842 | |
| 843 | return plane; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 844 | |
| 845 | err_props: |
| 846 | drm_property_info_free(plane->props, WDRM_PLANE__COUNT); |
| 847 | err: |
| 848 | drm_plane_state_free(plane->state_cur, true); |
| 849 | free(plane); |
| 850 | return NULL; |
| 851 | } |
| 852 | |
| 853 | /** |
| 854 | * Find, or create, a special-purpose plane |
| 855 | * |
| 856 | * Primary and cursor planes are a special case, in that before universal |
| 857 | * planes, they are driven by non-plane API calls. Without universal plane |
| 858 | * support, the only way to configure a primary plane is via drmModeSetCrtc, |
| 859 | * and the only way to configure a cursor plane is drmModeSetCursor2. |
| 860 | * |
| 861 | * Although they may actually be regular planes in the hardware, without |
| 862 | * universal plane support, these planes are not actually exposed to |
| 863 | * userspace in the regular plane list. |
| 864 | * |
| 865 | * However, for ease of internal tracking, we want to manage all planes |
| 866 | * through the same drm_plane structures. Therefore, when we are running |
| 867 | * without universal plane support, we create fake drm_plane structures |
| 868 | * to track these planes. |
| 869 | * |
| 870 | * @param b DRM backend |
| 871 | * @param output Output to use for plane |
| 872 | * @param type Type of plane |
| 873 | */ |
| 874 | static struct drm_plane * |
| 875 | drm_output_find_special_plane(struct drm_backend *b, struct drm_output *output, |
| 876 | enum wdrm_plane_type type) |
| 877 | { |
| 878 | struct drm_plane *plane; |
| 879 | |
| 880 | if (!b->universal_planes) { |
| 881 | uint32_t format; |
| 882 | |
| 883 | switch (type) { |
| 884 | case WDRM_PLANE_TYPE_CURSOR: |
Stefan Agner | 0bfebeb | 2019-07-08 00:30:44 +0200 | [diff] [blame] | 885 | format = DRM_FORMAT_ARGB8888; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 886 | break; |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 887 | case WDRM_PLANE_TYPE_PRIMARY: |
| 888 | /* We don't know what formats the primary plane supports |
| 889 | * before universal planes, so we just assume that the |
| 890 | * GBM format works; however, this isn't set until after |
| 891 | * the output is created. */ |
| 892 | format = 0; |
| 893 | break; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 894 | default: |
| 895 | assert(!"invalid type in drm_output_find_special_plane"); |
| 896 | break; |
| 897 | } |
| 898 | |
| 899 | return drm_plane_create(b, NULL, output, type, format); |
| 900 | } |
| 901 | |
| 902 | wl_list_for_each(plane, &b->plane_list, link) { |
| 903 | struct drm_output *tmp; |
| 904 | bool found_elsewhere = false; |
| 905 | |
| 906 | if (plane->type != type) |
| 907 | continue; |
| 908 | if (!drm_plane_is_available(plane, output)) |
| 909 | continue; |
| 910 | |
| 911 | /* On some platforms, primary/cursor planes can roam |
| 912 | * between different CRTCs, so make sure we don't claim the |
| 913 | * same plane for two outputs. */ |
Leandro Ribeiro | 05cecc8 | 2020-08-13 17:34:58 -0300 | [diff] [blame] | 914 | wl_list_for_each(tmp, &b->compositor->output_list, base.link) { |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 915 | if (tmp->cursor_plane == plane || |
| 916 | tmp->scanout_plane == plane) { |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 917 | found_elsewhere = true; |
| 918 | break; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | if (found_elsewhere) |
| 923 | continue; |
| 924 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 925 | plane->possible_crtcs = (1 << output->crtc->pipe); |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 926 | return plane; |
| 927 | } |
| 928 | |
| 929 | return NULL; |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Destroy one DRM plane |
| 934 | * |
| 935 | * Destroy a DRM plane, removing it from screen and releasing its retained |
| 936 | * buffers in the process. The counterpart to drm_plane_create. |
| 937 | * |
| 938 | * @param plane Plane to deallocate (will be freed) |
| 939 | */ |
| 940 | static void |
| 941 | drm_plane_destroy(struct drm_plane *plane) |
| 942 | { |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 943 | if (plane->type == WDRM_PLANE_TYPE_OVERLAY) |
| 944 | drmModeSetPlane(plane->backend->drm.fd, plane->plane_id, |
| 945 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
Daniel Stone | bc15f68 | 2016-11-14 16:57:01 +0000 | [diff] [blame] | 946 | drm_plane_state_free(plane->state_cur, true); |
Pekka Paalanen | c5de57f | 2015-05-20 23:01:44 +0100 | [diff] [blame] | 947 | drm_property_info_free(plane->props, WDRM_PLANE__COUNT); |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 948 | weston_plane_release(&plane->base); |
| 949 | wl_list_remove(&plane->link); |
| 950 | free(plane); |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * Initialise sprites (overlay planes) |
| 955 | * |
| 956 | * Walk the list of provided DRM planes, and add overlay planes. |
| 957 | * |
| 958 | * Call destroy_sprites to free these planes. |
| 959 | * |
| 960 | * @param b DRM compositor backend |
| 961 | */ |
| 962 | static void |
| 963 | create_sprites(struct drm_backend *b) |
| 964 | { |
| 965 | drmModePlaneRes *kplane_res; |
| 966 | drmModePlane *kplane; |
| 967 | struct drm_plane *drm_plane; |
| 968 | uint32_t i; |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 969 | kplane_res = drmModeGetPlaneResources(b->drm.fd); |
| 970 | if (!kplane_res) { |
| 971 | weston_log("failed to get plane resources: %s\n", |
| 972 | strerror(errno)); |
| 973 | return; |
| 974 | } |
| 975 | |
| 976 | for (i = 0; i < kplane_res->count_planes; i++) { |
| 977 | kplane = drmModeGetPlane(b->drm.fd, kplane_res->planes[i]); |
| 978 | if (!kplane) |
| 979 | continue; |
| 980 | |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 981 | drm_plane = drm_plane_create(b, kplane, NULL, |
| 982 | WDRM_PLANE_TYPE__COUNT, 0); |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 983 | drmModeFreePlane(kplane); |
| 984 | if (!drm_plane) |
| 985 | continue; |
| 986 | |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 987 | if (drm_plane->type == WDRM_PLANE_TYPE_OVERLAY) |
| 988 | weston_compositor_stack_plane(b->compositor, |
| 989 | &drm_plane->base, |
| 990 | &b->compositor->primary_plane); |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | drmModeFreePlaneResources(kplane_res); |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * Clean up sprites (overlay planes) |
| 998 | * |
| 999 | * The counterpart to create_sprites. |
| 1000 | * |
| 1001 | * @param b DRM compositor backend |
| 1002 | */ |
| 1003 | static void |
| 1004 | destroy_sprites(struct drm_backend *b) |
| 1005 | { |
| 1006 | struct drm_plane *plane, *next; |
| 1007 | |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 1008 | wl_list_for_each_safe(plane, next, &b->plane_list, link) |
Pekka Paalanen | ec27271 | 2014-06-05 11:22:25 +0300 | [diff] [blame] | 1009 | drm_plane_destroy(plane); |
| 1010 | } |
| 1011 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1012 | /* returns a value between 0-255 range, where higher is brighter */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1013 | static uint32_t |
Pekka Paalanen | ce72424 | 2017-09-04 12:21:24 +0300 | [diff] [blame] | 1014 | drm_get_backlight(struct drm_head *head) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1015 | { |
| 1016 | long brightness, max_brightness, norm; |
| 1017 | |
Pekka Paalanen | ce72424 | 2017-09-04 12:21:24 +0300 | [diff] [blame] | 1018 | brightness = backlight_get_brightness(head->backlight); |
| 1019 | max_brightness = backlight_get_max_brightness(head->backlight); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1020 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1021 | /* convert it on a scale of 0 to 255 */ |
| 1022 | norm = (brightness * 255)/(max_brightness); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1023 | |
| 1024 | return (uint32_t) norm; |
| 1025 | } |
| 1026 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1027 | /* values accepted are between 0-255 range */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1028 | static void |
| 1029 | drm_set_backlight(struct weston_output *output_base, uint32_t value) |
| 1030 | { |
Pekka Paalanen | ecc8cce | 2017-09-12 16:14:31 +0300 | [diff] [blame] | 1031 | struct drm_output *output = to_drm_output(output_base); |
| 1032 | struct drm_head *head; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1033 | long max_brightness, new_brightness; |
| 1034 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1035 | if (value > 255) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1036 | return; |
| 1037 | |
Pekka Paalanen | ecc8cce | 2017-09-12 16:14:31 +0300 | [diff] [blame] | 1038 | wl_list_for_each(head, &output->base.head_list, base.output_link) { |
| 1039 | if (!head->backlight) |
| 1040 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1041 | |
Pekka Paalanen | ecc8cce | 2017-09-12 16:14:31 +0300 | [diff] [blame] | 1042 | max_brightness = backlight_get_max_brightness(head->backlight); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1043 | |
Pekka Paalanen | ecc8cce | 2017-09-12 16:14:31 +0300 | [diff] [blame] | 1044 | /* get denormalized value */ |
| 1045 | new_brightness = (value * max_brightness) / 255; |
| 1046 | |
| 1047 | backlight_set_brightness(head->backlight, new_brightness); |
| 1048 | } |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
Pekka Paalanen | f8b850d | 2017-11-15 12:51:01 +0200 | [diff] [blame] | 1051 | static void |
| 1052 | drm_output_init_backlight(struct drm_output *output) |
| 1053 | { |
| 1054 | struct weston_head *base; |
| 1055 | struct drm_head *head; |
| 1056 | |
| 1057 | output->base.set_backlight = NULL; |
| 1058 | |
| 1059 | wl_list_for_each(base, &output->base.head_list, output_link) { |
| 1060 | head = to_drm_head(base); |
| 1061 | |
| 1062 | if (head->backlight) { |
| 1063 | weston_log("Initialized backlight for head '%s', device %s\n", |
| 1064 | head->base.name, head->backlight->path); |
| 1065 | |
| 1066 | if (!output->base.set_backlight) { |
| 1067 | output->base.set_backlight = drm_set_backlight; |
| 1068 | output->base.backlight_current = |
| 1069 | drm_get_backlight(head); |
| 1070 | } |
| 1071 | } |
| 1072 | } |
Pekka Paalanen | f8b850d | 2017-11-15 12:51:01 +0200 | [diff] [blame] | 1073 | } |
| 1074 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1075 | /** |
| 1076 | * Power output on or off |
| 1077 | * |
| 1078 | * The DPMS/power level of an output is used to switch it on or off. This |
| 1079 | * is DRM's hook for doing so, which can called either as part of repaint, |
| 1080 | * or independently of the repaint loop. |
| 1081 | * |
| 1082 | * If we are called as part of repaint, we simply set the relevant bit in |
| 1083 | * state and return. |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 1084 | * |
| 1085 | * This function is never called on a virtual output. |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1086 | */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1087 | static void |
| 1088 | drm_set_dpms(struct weston_output *output_base, enum dpms_enum level) |
| 1089 | { |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 1090 | struct drm_output *output = to_drm_output(output_base); |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1091 | struct drm_backend *b = to_drm_backend(output_base->compositor); |
| 1092 | struct drm_pending_state *pending_state = b->repaint_data; |
| 1093 | struct drm_output_state *state; |
Daniel Stone | 36609c7 | 2015-06-18 07:49:02 +0100 | [diff] [blame] | 1094 | int ret; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1095 | |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 1096 | assert(!output->virtual); |
| 1097 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1098 | if (output->state_cur->dpms == level) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1099 | return; |
| 1100 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1101 | /* If we're being called during the repaint loop, then this is |
| 1102 | * simple: discard any previously-generated state, and create a new |
| 1103 | * state where we disable everything. When we come to flush, this |
| 1104 | * will be applied. |
| 1105 | * |
| 1106 | * However, we need to be careful: we can be called whilst another |
| 1107 | * output is in its repaint cycle (pending_state exists), but our |
| 1108 | * output still has an incomplete state application outstanding. |
| 1109 | * In that case, we need to wait until that completes. */ |
| 1110 | if (pending_state && !output->state_last) { |
| 1111 | /* The repaint loop already sets DPMS on; we don't need to |
| 1112 | * explicitly set it on here, as it will already happen |
| 1113 | * whilst applying the repaint state. */ |
| 1114 | if (level == WESTON_DPMS_ON) |
| 1115 | return; |
| 1116 | |
| 1117 | state = drm_pending_state_get_output(pending_state, output); |
| 1118 | if (state) |
| 1119 | drm_output_state_free(state); |
| 1120 | state = drm_output_get_disable_state(pending_state, output); |
Daniel Stone | 36609c7 | 2015-06-18 07:49:02 +0100 | [diff] [blame] | 1121 | return; |
| 1122 | } |
| 1123 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1124 | /* As we throw everything away when disabling, just send us back through |
| 1125 | * a repaint cycle. */ |
| 1126 | if (level == WESTON_DPMS_ON) { |
| 1127 | if (output->dpms_off_pending) |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 1128 | output->dpms_off_pending = false; |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1129 | weston_output_schedule_repaint(output_base); |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | /* If we've already got a request in the pipeline, then we need to |
| 1134 | * park our DPMS request until that request has quiesced. */ |
| 1135 | if (output->state_last) { |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 1136 | output->dpms_off_pending = true; |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1137 | return; |
| 1138 | } |
| 1139 | |
| 1140 | pending_state = drm_pending_state_alloc(b); |
| 1141 | drm_output_get_disable_state(pending_state, output); |
| 1142 | ret = drm_pending_state_apply_sync(pending_state); |
| 1143 | if (ret != 0) |
| 1144 | weston_log("drm_set_dpms: couldn't disable output?\n"); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Pekka Paalanen | 3ce6362 | 2014-06-04 16:29:49 +0300 | [diff] [blame] | 1147 | static const char * const connector_type_names[] = { |
Pekka Paalanen | 89c49b3 | 2015-08-19 15:25:57 +0300 | [diff] [blame] | 1148 | [DRM_MODE_CONNECTOR_Unknown] = "Unknown", |
| 1149 | [DRM_MODE_CONNECTOR_VGA] = "VGA", |
| 1150 | [DRM_MODE_CONNECTOR_DVII] = "DVI-I", |
| 1151 | [DRM_MODE_CONNECTOR_DVID] = "DVI-D", |
| 1152 | [DRM_MODE_CONNECTOR_DVIA] = "DVI-A", |
| 1153 | [DRM_MODE_CONNECTOR_Composite] = "Composite", |
| 1154 | [DRM_MODE_CONNECTOR_SVIDEO] = "SVIDEO", |
| 1155 | [DRM_MODE_CONNECTOR_LVDS] = "LVDS", |
| 1156 | [DRM_MODE_CONNECTOR_Component] = "Component", |
| 1157 | [DRM_MODE_CONNECTOR_9PinDIN] = "DIN", |
| 1158 | [DRM_MODE_CONNECTOR_DisplayPort] = "DP", |
| 1159 | [DRM_MODE_CONNECTOR_HDMIA] = "HDMI-A", |
| 1160 | [DRM_MODE_CONNECTOR_HDMIB] = "HDMI-B", |
| 1161 | [DRM_MODE_CONNECTOR_TV] = "TV", |
| 1162 | [DRM_MODE_CONNECTOR_eDP] = "eDP", |
| 1163 | [DRM_MODE_CONNECTOR_VIRTUAL] = "Virtual", |
| 1164 | [DRM_MODE_CONNECTOR_DSI] = "DSI", |
Stefan Agner | 30e283d | 2018-08-20 17:11:38 +0200 | [diff] [blame] | 1165 | [DRM_MODE_CONNECTOR_DPI] = "DPI", |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1166 | }; |
| 1167 | |
Pekka Paalanen | 1f21ef1 | 2017-04-03 13:33:26 +0300 | [diff] [blame] | 1168 | /** Create a name given a DRM connector |
| 1169 | * |
| 1170 | * \param con The DRM connector whose type and id form the name. |
| 1171 | * \return A newly allocate string, or NULL on error. Must be free()'d |
| 1172 | * after use. |
| 1173 | * |
| 1174 | * The name does not identify the DRM display device. |
| 1175 | */ |
Pekka Paalanen | 3ce6362 | 2014-06-04 16:29:49 +0300 | [diff] [blame] | 1176 | static char * |
| 1177 | make_connector_name(const drmModeConnector *con) |
| 1178 | { |
Pekka Paalanen | 1f21ef1 | 2017-04-03 13:33:26 +0300 | [diff] [blame] | 1179 | char *name; |
Pekka Paalanen | 89c49b3 | 2015-08-19 15:25:57 +0300 | [diff] [blame] | 1180 | const char *type_name = NULL; |
Pekka Paalanen | 1f21ef1 | 2017-04-03 13:33:26 +0300 | [diff] [blame] | 1181 | int ret; |
Pekka Paalanen | 3ce6362 | 2014-06-04 16:29:49 +0300 | [diff] [blame] | 1182 | |
| 1183 | if (con->connector_type < ARRAY_LENGTH(connector_type_names)) |
| 1184 | type_name = connector_type_names[con->connector_type]; |
Pekka Paalanen | 89c49b3 | 2015-08-19 15:25:57 +0300 | [diff] [blame] | 1185 | |
| 1186 | if (!type_name) |
| 1187 | type_name = "UNNAMED"; |
| 1188 | |
Pekka Paalanen | 1f21ef1 | 2017-04-03 13:33:26 +0300 | [diff] [blame] | 1189 | ret = asprintf(&name, "%s-%d", type_name, con->connector_type_id); |
| 1190 | if (ret < 0) |
| 1191 | return NULL; |
Pekka Paalanen | 3ce6362 | 2014-06-04 16:29:49 +0300 | [diff] [blame] | 1192 | |
Pekka Paalanen | 1f21ef1 | 2017-04-03 13:33:26 +0300 | [diff] [blame] | 1193 | return name; |
Pekka Paalanen | 3ce6362 | 2014-06-04 16:29:49 +0300 | [diff] [blame] | 1194 | } |
| 1195 | |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1196 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1197 | 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] | 1198 | { |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1199 | int w = output->base.current_mode->width; |
| 1200 | int h = output->base.current_mode->height; |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1201 | uint32_t format = output->gbm_format; |
| 1202 | uint32_t pixman_format; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1203 | unsigned int i; |
Daniel Stone | 61abf35 | 2020-03-06 12:46:30 +0000 | [diff] [blame] | 1204 | const struct pixman_renderer_output_options options = { |
| 1205 | .use_shadow = b->use_pixman_shadow, |
| 1206 | }; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1207 | |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1208 | switch (format) { |
Stefan Agner | 0bfebeb | 2019-07-08 00:30:44 +0200 | [diff] [blame] | 1209 | case DRM_FORMAT_XRGB8888: |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1210 | pixman_format = PIXMAN_x8r8g8b8; |
| 1211 | break; |
Stefan Agner | 0bfebeb | 2019-07-08 00:30:44 +0200 | [diff] [blame] | 1212 | case DRM_FORMAT_RGB565: |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1213 | pixman_format = PIXMAN_r5g6b5; |
| 1214 | break; |
| 1215 | default: |
| 1216 | weston_log("Unsupported pixman format 0x%x\n", format); |
| 1217 | return -1; |
| 1218 | } |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1219 | |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1220 | /* FIXME error checking */ |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1221 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1222 | 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] | 1223 | if (!output->dumb[i]) |
| 1224 | goto err; |
| 1225 | |
| 1226 | output->image[i] = |
Tomi Valkeinen | f8da0c2 | 2016-06-20 14:18:45 +0300 | [diff] [blame] | 1227 | pixman_image_create_bits(pixman_format, w, h, |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1228 | output->dumb[i]->map, |
Daniel Stone | 8eece0c | 2016-11-17 17:54:00 +0000 | [diff] [blame] | 1229 | output->dumb[i]->strides[0]); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1230 | if (!output->image[i]) |
| 1231 | goto err; |
| 1232 | } |
| 1233 | |
Daniel Stone | 61abf35 | 2020-03-06 12:46:30 +0000 | [diff] [blame] | 1234 | if (pixman_renderer_output_create(&output->base, &options) < 0) |
Pekka Paalanen | dee412d | 2018-04-23 11:44:58 +0200 | [diff] [blame] | 1235 | goto err; |
Ankit Nautiyal | a21c393 | 2097-03-19 00:24:57 +0530 | [diff] [blame] | 1236 | |
Pekka Paalanen | dee412d | 2018-04-23 11:44:58 +0200 | [diff] [blame] | 1237 | weston_log("DRM: output %s %s shadow framebuffer.\n", output->base.name, |
| 1238 | b->use_pixman_shadow ? "uses" : "does not use"); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1239 | |
| 1240 | pixman_region32_init_rect(&output->previous_damage, |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1241 | 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] | 1242 | |
| 1243 | return 0; |
| 1244 | |
| 1245 | err: |
| 1246 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
| 1247 | if (output->dumb[i]) |
Daniel Stone | 6e7a961 | 2017-04-04 17:54:26 +0100 | [diff] [blame] | 1248 | drm_fb_unref(output->dumb[i]); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1249 | if (output->image[i]) |
| 1250 | pixman_image_unref(output->image[i]); |
| 1251 | |
| 1252 | output->dumb[i] = NULL; |
| 1253 | output->image[i] = NULL; |
| 1254 | } |
| 1255 | |
| 1256 | return -1; |
| 1257 | } |
| 1258 | |
| 1259 | static void |
| 1260 | drm_output_fini_pixman(struct drm_output *output) |
| 1261 | { |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 1262 | struct drm_backend *b = to_drm_backend(output->base.compositor); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1263 | unsigned int i; |
| 1264 | |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 1265 | /* Destroying the Pixman surface will destroy all our buffers, |
| 1266 | * regardless of refcount. Ensure we destroy them here. */ |
| 1267 | if (!b->shutting_down && |
| 1268 | output->scanout_plane->state_cur->fb && |
| 1269 | output->scanout_plane->state_cur->fb->type == BUFFER_PIXMAN_DUMB) { |
Alexandros Frantzis | 9975134 | 2020-05-18 15:22:49 +0300 | [diff] [blame] | 1270 | drm_plane_reset_state(output->scanout_plane); |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1273 | pixman_renderer_output_destroy(&output->base); |
| 1274 | pixman_region32_fini(&output->previous_damage); |
| 1275 | |
| 1276 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1277 | pixman_image_unref(output->image[i]); |
Daniel Stone | 6e7a961 | 2017-04-04 17:54:26 +0100 | [diff] [blame] | 1278 | drm_fb_unref(output->dumb[i]); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1279 | output->dumb[i] = NULL; |
| 1280 | output->image[i] = NULL; |
| 1281 | } |
| 1282 | } |
| 1283 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 1284 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1285 | setup_output_seat_constraint(struct drm_backend *b, |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1286 | struct weston_output *output, |
| 1287 | const char *s) |
| 1288 | { |
| 1289 | if (strcmp(s, "") != 0) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1290 | struct weston_pointer *pointer; |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1291 | struct udev_seat *seat; |
| 1292 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1293 | seat = udev_seat_get_named(&b->input, s); |
Derek Foreman | 0720ea3 | 2015-07-15 13:00:35 -0500 | [diff] [blame] | 1294 | if (!seat) |
| 1295 | return; |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1296 | |
Derek Foreman | 0720ea3 | 2015-07-15 13:00:35 -0500 | [diff] [blame] | 1297 | seat->base.output = output; |
| 1298 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1299 | pointer = weston_seat_get_pointer(&seat->base); |
| 1300 | if (pointer) |
| 1301 | weston_pointer_clamp(pointer, |
| 1302 | &pointer->x, |
| 1303 | &pointer->y); |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1307 | static int |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 1308 | drm_output_attach_head(struct weston_output *output_base, |
| 1309 | struct weston_head *head_base) |
| 1310 | { |
Pekka Paalanen | d5f98d8 | 2017-12-08 14:45:00 +0200 | [diff] [blame] | 1311 | struct drm_backend *b = to_drm_backend(output_base->compositor); |
| 1312 | |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 1313 | if (wl_list_length(&output_base->head_list) >= MAX_CLONED_CONNECTORS) |
| 1314 | return -1; |
| 1315 | |
Pekka Paalanen | d5f98d8 | 2017-12-08 14:45:00 +0200 | [diff] [blame] | 1316 | if (!output_base->enabled) |
| 1317 | return 0; |
| 1318 | |
| 1319 | /* XXX: ensure the configuration will work. |
| 1320 | * This is actually impossible without major infrastructure |
| 1321 | * work. */ |
| 1322 | |
| 1323 | /* Need to go through modeset to add connectors. */ |
| 1324 | /* XXX: Ideally we'd do this per-output, not globally. */ |
| 1325 | /* XXX: Doing it globally, what guarantees another output's update |
| 1326 | * will not clear the flag before this output is updated? |
| 1327 | */ |
| 1328 | b->state_invalid = true; |
| 1329 | |
| 1330 | weston_output_schedule_repaint(output_base); |
| 1331 | |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 1332 | return 0; |
| 1333 | } |
| 1334 | |
Pekka Paalanen | 7f85379 | 2017-11-29 14:33:33 +0200 | [diff] [blame] | 1335 | static void |
| 1336 | drm_output_detach_head(struct weston_output *output_base, |
| 1337 | struct weston_head *head_base) |
| 1338 | { |
| 1339 | struct drm_backend *b = to_drm_backend(output_base->compositor); |
| 1340 | |
| 1341 | if (!output_base->enabled) |
| 1342 | return; |
| 1343 | |
| 1344 | /* Need to go through modeset to drop connectors that should no longer |
| 1345 | * be driven. */ |
| 1346 | /* XXX: Ideally we'd do this per-output, not globally. */ |
| 1347 | b->state_invalid = true; |
| 1348 | |
| 1349 | weston_output_schedule_repaint(output_base); |
| 1350 | } |
| 1351 | |
Stefan Agner | 3654c67 | 2019-07-09 00:50:30 +0200 | [diff] [blame] | 1352 | int |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 1353 | 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] | 1354 | { |
Pekka Paalanen | 62a9436 | 2018-09-26 14:33:36 +0300 | [diff] [blame] | 1355 | const struct pixel_format_info *pinfo; |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1356 | |
Pekka Paalanen | 62a9436 | 2018-09-26 14:33:36 +0300 | [diff] [blame] | 1357 | if (s == NULL) { |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 1358 | *gbm_format = default_value; |
Pekka Paalanen | 62a9436 | 2018-09-26 14:33:36 +0300 | [diff] [blame] | 1359 | |
| 1360 | return 0; |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Pekka Paalanen | 62a9436 | 2018-09-26 14:33:36 +0300 | [diff] [blame] | 1363 | pinfo = pixel_format_get_info_by_drm_name(s); |
| 1364 | if (!pinfo) { |
| 1365 | weston_log("fatal: unrecognized pixel format: %s\n", s); |
| 1366 | |
| 1367 | return -1; |
| 1368 | } |
| 1369 | |
| 1370 | /* GBM formats and DRM formats are identical. */ |
| 1371 | *gbm_format = pinfo->format; |
| 1372 | |
| 1373 | return 0; |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1376 | static int |
Pekka Paalanen | 9c03a7c | 2017-11-28 14:30:10 +0200 | [diff] [blame] | 1377 | drm_head_read_current_setup(struct drm_head *head, struct drm_backend *backend) |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1378 | { |
Pekka Paalanen | 9c03a7c | 2017-11-28 14:30:10 +0200 | [diff] [blame] | 1379 | int drm_fd = backend->drm.fd; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1380 | drmModeConnector *conn = head->connector.conn; |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1381 | drmModeEncoder *encoder; |
| 1382 | drmModeCrtc *crtc; |
| 1383 | |
| 1384 | /* Get the current mode on the crtc that's currently driving |
| 1385 | * this connector. */ |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1386 | encoder = drmModeGetEncoder(drm_fd, conn->encoder_id); |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1387 | if (encoder != NULL) { |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1388 | head->inherited_crtc_id = encoder->crtc_id; |
| 1389 | |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1390 | crtc = drmModeGetCrtc(drm_fd, encoder->crtc_id); |
| 1391 | drmModeFreeEncoder(encoder); |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1392 | |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1393 | if (crtc == NULL) |
| 1394 | return -1; |
| 1395 | if (crtc->mode_valid) |
Pekka Paalanen | 6fae2be | 2017-11-28 14:33:52 +0200 | [diff] [blame] | 1396 | head->inherited_mode = crtc->mode; |
Pekka Paalanen | eee580b | 2014-06-04 16:43:06 +0300 | [diff] [blame] | 1397 | drmModeFreeCrtc(crtc); |
| 1398 | } |
| 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1403 | static void |
| 1404 | drm_output_set_gbm_format(struct weston_output *base, |
| 1405 | const char *gbm_format) |
| 1406 | { |
| 1407 | struct drm_output *output = to_drm_output(base); |
| 1408 | struct drm_backend *b = to_drm_backend(base->compositor); |
| 1409 | |
| 1410 | if (parse_gbm_format(gbm_format, b->gbm_format, &output->gbm_format) == -1) |
| 1411 | output->gbm_format = b->gbm_format; |
| 1412 | } |
| 1413 | |
| 1414 | static void |
| 1415 | drm_output_set_seat(struct weston_output *base, |
| 1416 | const char *seat) |
| 1417 | { |
| 1418 | struct drm_output *output = to_drm_output(base); |
| 1419 | struct drm_backend *b = to_drm_backend(base->compositor); |
| 1420 | |
| 1421 | setup_output_seat_constraint(b, &output->base, |
| 1422 | seat ? seat : ""); |
| 1423 | } |
| 1424 | |
| 1425 | static int |
Pekka Paalanen | c4db6f7 | 2017-09-05 16:37:03 +0300 | [diff] [blame] | 1426 | drm_output_init_gamma_size(struct drm_output *output) |
| 1427 | { |
| 1428 | struct drm_backend *backend = to_drm_backend(output->base.compositor); |
| 1429 | drmModeCrtc *crtc; |
| 1430 | |
| 1431 | assert(output->base.compositor); |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1432 | assert(output->crtc); |
| 1433 | crtc = drmModeGetCrtc(backend->drm.fd, output->crtc->crtc_id); |
Pekka Paalanen | c4db6f7 | 2017-09-05 16:37:03 +0300 | [diff] [blame] | 1434 | if (!crtc) |
| 1435 | return -1; |
| 1436 | |
| 1437 | output->base.gamma_size = crtc->gamma_size; |
| 1438 | |
| 1439 | drmModeFreeCrtc(crtc); |
| 1440 | |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1444 | static uint32_t |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1445 | drm_connector_get_possible_crtcs_mask(struct drm_connector *connector) |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1446 | { |
| 1447 | uint32_t possible_crtcs = 0; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1448 | drmModeConnector *conn = connector->conn; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1449 | drmModeEncoder *encoder; |
| 1450 | int i; |
| 1451 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1452 | for (i = 0; i < conn->count_encoders; i++) { |
| 1453 | encoder = drmModeGetEncoder(connector->backend->drm.fd, |
| 1454 | conn->encoders[i]); |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1455 | if (!encoder) |
| 1456 | continue; |
| 1457 | |
| 1458 | possible_crtcs |= encoder->possible_crtcs; |
| 1459 | drmModeFreeEncoder(encoder); |
| 1460 | } |
| 1461 | |
| 1462 | return possible_crtcs; |
| 1463 | } |
| 1464 | |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1465 | /** Pick a CRTC that might be able to drive all attached connectors |
| 1466 | * |
| 1467 | * @param output The output whose attached heads to include. |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1468 | * @return CRTC object to pick, or NULL on failure or not found. |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1469 | */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1470 | static struct drm_crtc * |
| 1471 | drm_output_pick_crtc(struct drm_output *output) |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1472 | { |
| 1473 | struct drm_backend *backend; |
| 1474 | struct weston_head *base; |
| 1475 | struct drm_head *head; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1476 | struct drm_crtc *crtc; |
| 1477 | struct drm_crtc *best_crtc = NULL; |
| 1478 | struct drm_crtc *fallback_crtc = NULL; |
| 1479 | struct drm_crtc *existing_crtc[32]; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1480 | uint32_t possible_crtcs = 0xffffffff; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1481 | unsigned n = 0; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1482 | uint32_t crtc_id; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1483 | unsigned int i; |
Pekka Paalanen | db4c7d7 | 2017-11-28 16:11:00 +0200 | [diff] [blame] | 1484 | bool match; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1485 | |
| 1486 | backend = to_drm_backend(output->base.compositor); |
| 1487 | |
| 1488 | /* This algorithm ignores drmModeEncoder::possible_clones restriction, |
| 1489 | * because it is more often set wrong than not in the kernel. */ |
| 1490 | |
| 1491 | /* Accumulate a mask of possible crtcs and find existing routings. */ |
| 1492 | wl_list_for_each(base, &output->base.head_list, output_link) { |
| 1493 | head = to_drm_head(base); |
| 1494 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1495 | possible_crtcs &= |
| 1496 | drm_connector_get_possible_crtcs_mask(&head->connector); |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1497 | |
| 1498 | crtc_id = head->inherited_crtc_id; |
| 1499 | if (crtc_id > 0 && n < ARRAY_LENGTH(existing_crtc)) |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1500 | existing_crtc[n++] = drm_crtc_find(backend, crtc_id); |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /* Find a crtc that could drive each connector individually at least, |
| 1504 | * and prefer existing routings. */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1505 | wl_list_for_each(crtc, &backend->crtc_list, link) { |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1506 | |
| 1507 | /* Could the crtc not drive each connector? */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1508 | if (!(possible_crtcs & (1 << crtc->pipe))) |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1509 | continue; |
| 1510 | |
| 1511 | /* Is the crtc already in use? */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1512 | if (crtc->output) |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1513 | continue; |
| 1514 | |
| 1515 | /* Try to preserve the existing CRTC -> connector routing; |
| 1516 | * it makes initialisation faster, and also since we have a |
| 1517 | * very dumb picking algorithm, may preserve a better |
| 1518 | * choice. */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1519 | for (i = 0; i < n; i++) { |
| 1520 | if (existing_crtc[i] == crtc) |
| 1521 | return crtc; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1522 | } |
| 1523 | |
Pekka Paalanen | db4c7d7 | 2017-11-28 16:11:00 +0200 | [diff] [blame] | 1524 | /* Check if any other head had existing routing to this CRTC. |
| 1525 | * If they did, this is not the best CRTC as it might be needed |
| 1526 | * for another output we haven't enabled yet. */ |
| 1527 | match = false; |
| 1528 | wl_list_for_each(base, &backend->compositor->head_list, |
| 1529 | compositor_link) { |
| 1530 | head = to_drm_head(base); |
| 1531 | |
| 1532 | if (head->base.output == &output->base) |
| 1533 | continue; |
| 1534 | |
| 1535 | if (weston_head_is_enabled(&head->base)) |
| 1536 | continue; |
| 1537 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1538 | if (head->inherited_crtc_id == crtc->crtc_id) { |
Pekka Paalanen | db4c7d7 | 2017-11-28 16:11:00 +0200 | [diff] [blame] | 1539 | match = true; |
| 1540 | break; |
| 1541 | } |
| 1542 | } |
| 1543 | if (!match) |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1544 | best_crtc = crtc; |
Pekka Paalanen | db4c7d7 | 2017-11-28 16:11:00 +0200 | [diff] [blame] | 1545 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1546 | fallback_crtc = crtc; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1547 | } |
| 1548 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1549 | if (best_crtc) |
| 1550 | return best_crtc; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1551 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1552 | if (fallback_crtc) |
| 1553 | return fallback_crtc; |
Pekka Paalanen | db4c7d7 | 2017-11-28 16:11:00 +0200 | [diff] [blame] | 1554 | |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1555 | /* Likely possible_crtcs was empty due to asking for clones, |
| 1556 | * but since the DRM documentation says the kernel lies, let's |
| 1557 | * pick one crtc anyway. Trial and error is the only way to |
| 1558 | * be sure if something doesn't work. */ |
| 1559 | |
| 1560 | /* First pick any existing assignment. */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1561 | for (i = 0; i < n; i++) { |
| 1562 | crtc = existing_crtc[i]; |
| 1563 | if (!crtc->output) |
| 1564 | return crtc; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | /* Otherwise pick any available crtc. */ |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1568 | wl_list_for_each(crtc, &backend->crtc_list, link) { |
| 1569 | if (!crtc->output) |
| 1570 | return crtc; |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1571 | } |
| 1572 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1573 | return NULL; |
| 1574 | } |
| 1575 | |
| 1576 | /** Create an "empty" drm_crtc. It will only set its ID, pipe and props. After |
| 1577 | * all, it adds the object to the DRM-backend CRTC list. |
| 1578 | */ |
| 1579 | static struct drm_crtc * |
| 1580 | drm_crtc_create(struct drm_backend *b, uint32_t crtc_id, uint32_t pipe) |
| 1581 | { |
| 1582 | struct drm_crtc *crtc; |
| 1583 | drmModeObjectPropertiesPtr props; |
| 1584 | |
| 1585 | props = drmModeObjectGetProperties(b->drm.fd, crtc_id, |
| 1586 | DRM_MODE_OBJECT_CRTC); |
| 1587 | if (!props) { |
| 1588 | weston_log("failed to get CRTC properties\n"); |
| 1589 | return NULL; |
| 1590 | } |
| 1591 | |
| 1592 | crtc = zalloc(sizeof(*crtc)); |
| 1593 | if (!crtc) |
| 1594 | goto ret; |
| 1595 | |
| 1596 | drm_property_info_populate(b, crtc_props, crtc->props_crtc, |
| 1597 | WDRM_CRTC__COUNT, props); |
| 1598 | crtc->backend = b; |
| 1599 | crtc->crtc_id = crtc_id; |
| 1600 | crtc->pipe = pipe; |
| 1601 | crtc->output = NULL; |
| 1602 | |
| 1603 | /* Add it to the last position of the DRM-backend CRTC list */ |
| 1604 | wl_list_insert(b->crtc_list.prev, &crtc->link); |
| 1605 | |
| 1606 | ret: |
| 1607 | drmModeFreeObjectProperties(props); |
| 1608 | return crtc; |
| 1609 | } |
| 1610 | |
| 1611 | /** Destroy a drm_crtc object that was created with drm_crtc_create(). It will |
| 1612 | * also remove it from the DRM-backend CRTC list. |
| 1613 | */ |
| 1614 | static void |
| 1615 | drm_crtc_destroy(struct drm_crtc *crtc) |
| 1616 | { |
| 1617 | /* TODO: address the issue below to be able to remove the comment |
| 1618 | * from the assert. |
| 1619 | * |
| 1620 | * https://gitlab.freedesktop.org/wayland/weston/-/issues/421 |
| 1621 | */ |
| 1622 | |
| 1623 | //assert(!crtc->output); |
| 1624 | |
| 1625 | wl_list_remove(&crtc->link); |
| 1626 | drm_property_info_free(crtc->props_crtc, WDRM_CRTC__COUNT); |
| 1627 | free(crtc); |
| 1628 | } |
| 1629 | |
| 1630 | /** Find all CRTCs of the fd and create drm_crtc objects for them. |
| 1631 | * |
| 1632 | * The CRTCs are saved in a list of the drm_backend and will keep there until |
| 1633 | * the fd gets closed. |
| 1634 | * |
| 1635 | * @param b The DRM-backend structure. |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 1636 | * @param resources The DRM resources, it is taken with drmModeGetResources |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1637 | * @return 0 on success (at least one CRTC in the list), -1 on failure. |
| 1638 | */ |
| 1639 | static int |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 1640 | drm_backend_create_crtc_list(struct drm_backend *b, drmModeRes *resources) |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1641 | { |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1642 | struct drm_crtc *crtc, *crtc_tmp; |
| 1643 | int i; |
| 1644 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1645 | /* Iterate through all CRTCs */ |
| 1646 | for (i = 0; i < resources->count_crtcs; i++) { |
| 1647 | |
| 1648 | /* Let's create an object for the CRTC and add it to the list */ |
| 1649 | crtc = drm_crtc_create(b, resources->crtcs[i], i); |
| 1650 | if (!crtc) |
| 1651 | goto err; |
| 1652 | } |
| 1653 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1654 | return 0; |
| 1655 | |
| 1656 | err: |
| 1657 | wl_list_for_each_safe(crtc, crtc_tmp, &b->crtc_list, link) |
| 1658 | drm_crtc_destroy(crtc); |
Pekka Paalanen | 27cc481 | 2017-11-20 13:31:06 +0200 | [diff] [blame] | 1659 | return -1; |
| 1660 | } |
| 1661 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1662 | |
| 1663 | /** Populates scanout and cursor planes for the output. Also sets the topology |
| 1664 | * of the planes by adding them to the plane stacking list. |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1665 | */ |
| 1666 | static int |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1667 | drm_output_init_planes(struct drm_output *output) |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1668 | { |
| 1669 | struct drm_backend *b = to_drm_backend(output->base.compositor); |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1670 | |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1671 | output->scanout_plane = |
| 1672 | drm_output_find_special_plane(b, output, |
| 1673 | WDRM_PLANE_TYPE_PRIMARY); |
| 1674 | if (!output->scanout_plane) { |
| 1675 | weston_log("Failed to find primary plane for output %s\n", |
| 1676 | output->base.name); |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1677 | return -1; |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1678 | } |
| 1679 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1680 | weston_compositor_stack_plane(b->compositor, |
| 1681 | &output->scanout_plane->base, |
| 1682 | &b->compositor->primary_plane); |
| 1683 | |
Tomohito Esaki | 5104846 | 2020-03-30 17:10:54 +0900 | [diff] [blame] | 1684 | /* Without universal planes, we can't discover which formats are |
| 1685 | * supported by the primary plane; we just hope that the GBM format |
| 1686 | * works. */ |
| 1687 | if (!b->universal_planes) |
| 1688 | output->scanout_plane->formats[0].format = output->gbm_format; |
| 1689 | |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1690 | /* Failing to find a cursor plane is not fatal, as we'll fall back |
| 1691 | * to software cursor. */ |
| 1692 | output->cursor_plane = |
| 1693 | drm_output_find_special_plane(b, output, |
| 1694 | WDRM_PLANE_TYPE_CURSOR); |
| 1695 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1696 | if (output->cursor_plane) |
| 1697 | weston_compositor_stack_plane(b->compositor, |
| 1698 | &output->cursor_plane->base, |
| 1699 | NULL); |
| 1700 | else |
| 1701 | b->cursors_are_broken = true; |
Pekka Paalanen | 663d5e9 | 2017-09-08 13:32:40 +0300 | [diff] [blame] | 1702 | |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1703 | return 0; |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1704 | } |
| 1705 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1706 | /** The opposite of drm_output_init_planes(). First of all it removes the planes |
| 1707 | * from the plane stacking list. Then, in case we don't have support for |
| 1708 | * universal planes it destroys the planes. After all it sets the planes of the |
| 1709 | * output as NULL. |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1710 | */ |
| 1711 | static void |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1712 | drm_output_deinit_planes(struct drm_output *output) |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1713 | { |
| 1714 | struct drm_backend *b = to_drm_backend(output->base.compositor); |
| 1715 | |
Alexandros Frantzis | 53a71cb | 2020-05-18 15:26:01 +0300 | [diff] [blame] | 1716 | /* If the compositor is already shutting down, the planes have already |
| 1717 | * been destroyed. */ |
| 1718 | if (!b->shutting_down) { |
Pekka Paalanen | 3d6721e | 2020-09-16 15:04:04 +0300 | [diff] [blame] | 1719 | wl_list_remove(&output->scanout_plane->base.link); |
| 1720 | wl_list_init(&output->scanout_plane->base.link); |
| 1721 | |
| 1722 | if (output->cursor_plane) { |
| 1723 | wl_list_remove(&output->cursor_plane->base.link); |
| 1724 | wl_list_init(&output->cursor_plane->base.link); |
| 1725 | /* Turn off hardware cursor */ |
| 1726 | drmModeSetCursor(b->drm.fd, output->crtc->crtc_id, 0, 0, 0); |
| 1727 | } |
| 1728 | |
Alexandros Frantzis | 53a71cb | 2020-05-18 15:26:01 +0300 | [diff] [blame] | 1729 | if (!b->universal_planes) { |
| 1730 | /* Without universal planes, our special planes are |
| 1731 | * pseudo-planes allocated at output creation, freed at |
| 1732 | * output destruction, and not usable by other outputs. |
| 1733 | */ |
| 1734 | if (output->cursor_plane) |
| 1735 | drm_plane_destroy(output->cursor_plane); |
| 1736 | if (output->scanout_plane) |
| 1737 | drm_plane_destroy(output->scanout_plane); |
| 1738 | } else { |
| 1739 | /* With universal planes, the 'special' planes are |
| 1740 | * allocated at startup, freed at shutdown, and live on |
| 1741 | * the plane list in between. We want the planes to |
| 1742 | * continue to exist and be freed up for other outputs. |
| 1743 | */ |
| 1744 | if (output->cursor_plane) |
| 1745 | drm_plane_reset_state(output->cursor_plane); |
| 1746 | if (output->scanout_plane) |
| 1747 | drm_plane_reset_state(output->scanout_plane); |
| 1748 | } |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1749 | } |
| 1750 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1751 | output->cursor_plane = NULL; |
| 1752 | output->scanout_plane = NULL; |
| 1753 | } |
| 1754 | |
| 1755 | /** Pick a CRTC and reserve it for the output. |
| 1756 | * |
| 1757 | * On failure, the output remains without a CRTC. |
| 1758 | * |
| 1759 | * @param output The output with no CRTC associated. |
| 1760 | * @return 0 on success, -1 on failure. |
| 1761 | */ |
| 1762 | static int |
| 1763 | drm_output_attach_crtc(struct drm_output *output) |
| 1764 | { |
| 1765 | output->crtc = drm_output_pick_crtc(output); |
| 1766 | if (!output->crtc) { |
| 1767 | weston_log("Output '%s': No available CRTCs.\n", |
| 1768 | output->base.name); |
| 1769 | return -1; |
| 1770 | } |
| 1771 | |
| 1772 | /* Reserve the CRTC for the output */ |
| 1773 | output->crtc->output = output; |
| 1774 | |
| 1775 | return 0; |
| 1776 | } |
| 1777 | |
| 1778 | /** Release reservation of the CRTC. |
| 1779 | * |
| 1780 | * Make the CRTC free to be reserved and used by another output. |
| 1781 | * |
| 1782 | * @param output The output that will release its CRTC. |
| 1783 | */ |
| 1784 | static void |
| 1785 | drm_output_detach_crtc(struct drm_output *output) |
| 1786 | { |
| 1787 | struct drm_backend *b = output->backend; |
| 1788 | struct drm_crtc *crtc = output->crtc; |
Pekka Paalanen | 663d5e9 | 2017-09-08 13:32:40 +0300 | [diff] [blame] | 1789 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1790 | crtc->output = NULL; |
| 1791 | output->crtc = NULL; |
| 1792 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1793 | /* Force resetting unused CRTCs */ |
| 1794 | b->state_invalid = true; |
Pekka Paalanen | fc5f5d7 | 2017-09-05 16:11:15 +0300 | [diff] [blame] | 1795 | } |
| 1796 | |
Pekka Paalanen | c4db6f7 | 2017-09-05 16:37:03 +0300 | [diff] [blame] | 1797 | static int |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1798 | drm_output_enable(struct weston_output *base) |
| 1799 | { |
| 1800 | struct drm_output *output = to_drm_output(base); |
| 1801 | struct drm_backend *b = to_drm_backend(base->compositor); |
Pekka Paalanen | 663d5e9 | 2017-09-08 13:32:40 +0300 | [diff] [blame] | 1802 | int ret; |
| 1803 | |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 1804 | assert(!output->virtual); |
| 1805 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1806 | ret = drm_output_attach_crtc(output); |
Pekka Paalanen | 663d5e9 | 2017-09-08 13:32:40 +0300 | [diff] [blame] | 1807 | if (ret < 0) |
| 1808 | return -1; |
| 1809 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1810 | ret = drm_output_init_planes(output); |
| 1811 | if (ret < 0) |
| 1812 | goto err_crtc; |
| 1813 | |
Pekka Paalanen | 663d5e9 | 2017-09-08 13:32:40 +0300 | [diff] [blame] | 1814 | if (drm_output_init_gamma_size(output) < 0) |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1815 | goto err_planes; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1816 | |
Emmanuel Gil Peyrot | 11ae2a3 | 2017-03-07 13:27:54 +0000 | [diff] [blame] | 1817 | if (b->pageflip_timeout) |
| 1818 | drm_output_pageflip_timer_create(output); |
| 1819 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1820 | if (b->use_pixman) { |
| 1821 | if (drm_output_init_pixman(output, b) < 0) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1822 | weston_log("Failed to init output pixman state\n"); |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1823 | goto err_planes; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1824 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1825 | } else if (drm_output_init_egl(output, b) < 0) { |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1826 | weston_log("Failed to init output gl state\n"); |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1827 | goto err_planes; |
Kristian Høgsberg | 1d1e0a5 | 2012-10-21 13:29:26 -0400 | [diff] [blame] | 1828 | } |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 1829 | |
Pekka Paalanen | f8b850d | 2017-11-15 12:51:01 +0200 | [diff] [blame] | 1830 | drm_output_init_backlight(output); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1831 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 1832 | output->base.start_repaint_loop = drm_output_start_repaint_loop; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 1833 | output->base.repaint = drm_output_repaint; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1834 | output->base.assign_planes = drm_assign_planes; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1835 | output->base.set_dpms = drm_set_dpms; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1836 | output->base.switch_mode = drm_output_switch_mode; |
Richard Hughes | e729996 | 2013-05-01 21:52:12 +0100 | [diff] [blame] | 1837 | output->base.set_gamma = drm_output_set_gamma; |
| 1838 | |
Pekka Paalanen | c0eb254 | 2017-11-15 13:37:18 +0200 | [diff] [blame] | 1839 | weston_log("Output %s (crtc %d) video modes:\n", |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1840 | output->base.name, output->crtc->crtc_id); |
Pekka Paalanen | c0eb254 | 2017-11-15 13:37:18 +0200 | [diff] [blame] | 1841 | drm_output_print_modes(output); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1842 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1843 | return 0; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1844 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1845 | err_planes: |
| 1846 | drm_output_deinit_planes(output); |
| 1847 | err_crtc: |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1848 | drm_output_detach_crtc(output); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 1849 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1850 | } |
| 1851 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1852 | static void |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1853 | drm_output_deinit(struct weston_output *base) |
| 1854 | { |
| 1855 | struct drm_output *output = to_drm_output(base); |
| 1856 | struct drm_backend *b = to_drm_backend(base->compositor); |
| 1857 | |
Daniel Stone | 3e661f7 | 2016-11-04 17:24:06 +0000 | [diff] [blame] | 1858 | if (b->use_pixman) |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1859 | drm_output_fini_pixman(output); |
Daniel Stone | 3e661f7 | 2016-11-04 17:24:06 +0000 | [diff] [blame] | 1860 | else |
| 1861 | drm_output_fini_egl(output); |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1862 | |
Leandro Ribeiro | 3be23ef | 2020-08-13 16:44:02 -0300 | [diff] [blame] | 1863 | drm_output_deinit_planes(output); |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 1864 | drm_output_detach_crtc(output); |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | static void |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 1868 | drm_head_destroy(struct drm_head *head); |
| 1869 | |
| 1870 | static void |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1871 | drm_output_destroy(struct weston_output *base) |
| 1872 | { |
| 1873 | struct drm_output *output = to_drm_output(base); |
| 1874 | struct drm_backend *b = to_drm_backend(base->compositor); |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1875 | |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 1876 | assert(!output->virtual); |
| 1877 | |
Daniel Stone | 31838bf | 2019-06-17 11:23:25 +0100 | [diff] [blame] | 1878 | if (output->page_flip_pending || output->atomic_complete_pending) { |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 1879 | output->destroy_pending = true; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1880 | weston_log("destroy output while page flip pending\n"); |
| 1881 | return; |
| 1882 | } |
| 1883 | |
| 1884 | if (output->base.enabled) |
| 1885 | drm_output_deinit(&output->base); |
| 1886 | |
Pekka Paalanen | 383b3af | 2017-09-11 14:40:48 +0300 | [diff] [blame] | 1887 | drm_mode_list_destroy(b, &output->base.mode_list); |
Armin Krezović | 445b41b | 2016-10-09 23:48:16 +0200 | [diff] [blame] | 1888 | |
Emmanuel Gil Peyrot | 11ae2a3 | 2017-03-07 13:27:54 +0000 | [diff] [blame] | 1889 | if (output->pageflip_timer) |
| 1890 | wl_event_source_remove(output->pageflip_timer); |
| 1891 | |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 1892 | weston_output_release(&output->base); |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1893 | |
Daniel Stone | 7b2ddac | 2016-11-11 19:11:49 +0000 | [diff] [blame] | 1894 | assert(!output->state_last); |
| 1895 | drm_output_state_free(output->state_cur); |
| 1896 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1897 | free(output); |
| 1898 | } |
| 1899 | |
| 1900 | static int |
| 1901 | drm_output_disable(struct weston_output *base) |
| 1902 | { |
| 1903 | struct drm_output *output = to_drm_output(base); |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1904 | |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 1905 | assert(!output->virtual); |
| 1906 | |
Daniel Stone | 31838bf | 2019-06-17 11:23:25 +0100 | [diff] [blame] | 1907 | if (output->page_flip_pending || output->atomic_complete_pending) { |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 1908 | output->disable_pending = true; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1909 | return -1; |
| 1910 | } |
| 1911 | |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1912 | weston_log("Disabling output %s\n", output->base.name); |
Daniel Stone | a08512f | 2016-11-08 17:46:10 +0000 | [diff] [blame] | 1913 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1914 | if (output->base.enabled) |
| 1915 | drm_output_deinit(&output->base); |
| 1916 | |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 1917 | output->disable_pending = false; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1918 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 1919 | return 0; |
| 1920 | } |
| 1921 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1922 | /* |
| 1923 | * This function converts the protection status from drm values to |
| 1924 | * weston_hdcp_protection status. The drm values as read from the connector |
| 1925 | * properties "Content Protection" and "HDCP Content Type" need to be converted |
| 1926 | * to appropriate weston values, that can be sent to a client application. |
| 1927 | */ |
| 1928 | static int |
| 1929 | get_weston_protection_from_drm(enum wdrm_content_protection_state protection, |
| 1930 | enum wdrm_hdcp_content_type type, |
| 1931 | enum weston_hdcp_protection *weston_protection) |
| 1932 | |
| 1933 | { |
| 1934 | if (protection >= WDRM_CONTENT_PROTECTION__COUNT) |
| 1935 | return -1; |
| 1936 | if (protection == WDRM_CONTENT_PROTECTION_DESIRED || |
| 1937 | protection == WDRM_CONTENT_PROTECTION_UNDESIRED) { |
| 1938 | *weston_protection = WESTON_HDCP_DISABLE; |
| 1939 | return 0; |
| 1940 | } |
| 1941 | if (type >= WDRM_HDCP_CONTENT_TYPE__COUNT) |
| 1942 | return -1; |
| 1943 | if (type == WDRM_HDCP_CONTENT_TYPE0) { |
| 1944 | *weston_protection = WESTON_HDCP_ENABLE_TYPE_0; |
| 1945 | return 0; |
| 1946 | } |
| 1947 | if (type == WDRM_HDCP_CONTENT_TYPE1) { |
| 1948 | *weston_protection = WESTON_HDCP_ENABLE_TYPE_1; |
| 1949 | return 0; |
| 1950 | } |
| 1951 | return -1; |
| 1952 | } |
| 1953 | |
| 1954 | /** |
| 1955 | * Get current content-protection status for a given head. |
| 1956 | * |
| 1957 | * @param head drm_head, whose protection is to be retrieved |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1958 | * @return protection status in case of success, -1 otherwise |
| 1959 | */ |
| 1960 | static enum weston_hdcp_protection |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 1961 | drm_head_get_current_protection(struct drm_head *head) |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1962 | { |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 1963 | drmModeObjectProperties *props = head->connector.props_drm; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1964 | struct drm_property_info *info; |
| 1965 | enum wdrm_content_protection_state protection; |
| 1966 | enum wdrm_hdcp_content_type type; |
| 1967 | enum weston_hdcp_protection weston_hdcp = WESTON_HDCP_DISABLE; |
| 1968 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1969 | info = &head->connector.props[WDRM_CONNECTOR_CONTENT_PROTECTION]; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1970 | protection = drm_property_get_value(info, props, |
| 1971 | WDRM_CONTENT_PROTECTION__COUNT); |
| 1972 | |
| 1973 | if (protection == WDRM_CONTENT_PROTECTION__COUNT) |
| 1974 | return WESTON_HDCP_DISABLE; |
| 1975 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1976 | info = &head->connector.props[WDRM_CONNECTOR_HDCP_CONTENT_TYPE]; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1977 | type = drm_property_get_value(info, props, |
| 1978 | WDRM_HDCP_CONTENT_TYPE__COUNT); |
| 1979 | |
| 1980 | /* |
| 1981 | * In case of platforms supporting HDCP1.4, only property |
| 1982 | * 'Content Protection' is exposed and not the 'HDCP Content Type' |
| 1983 | * for such cases HDCP Type 0 should be considered as the content-type. |
| 1984 | */ |
| 1985 | |
| 1986 | if (type == WDRM_HDCP_CONTENT_TYPE__COUNT) |
| 1987 | type = WDRM_HDCP_CONTENT_TYPE0; |
| 1988 | |
| 1989 | if (get_weston_protection_from_drm(protection, type, |
| 1990 | &weston_hdcp) == -1) { |
| 1991 | weston_log("Invalid drm protection:%d type:%d, for head:%s connector-id:%d\n", |
| 1992 | protection, type, head->base.name, |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 1993 | head->connector.connector_id); |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 1994 | return WESTON_HDCP_DISABLE; |
| 1995 | } |
| 1996 | |
| 1997 | return weston_hdcp; |
| 1998 | } |
| 1999 | |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2000 | static int |
| 2001 | drm_connector_update_properties(struct drm_connector *connector) |
| 2002 | { |
| 2003 | drmModeObjectProperties *props; |
| 2004 | |
| 2005 | props = drmModeObjectGetProperties(connector->backend->drm.fd, |
| 2006 | connector->connector_id, |
| 2007 | DRM_MODE_OBJECT_CONNECTOR); |
| 2008 | if (!props) { |
| 2009 | weston_log("Error: failed to get connector properties\n"); |
| 2010 | return -1; |
| 2011 | } |
| 2012 | |
| 2013 | if (connector->props_drm) |
| 2014 | drmModeFreeObjectProperties(connector->props_drm); |
| 2015 | connector->props_drm = props; |
| 2016 | |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2020 | /** Replace connector data and monitor information |
| 2021 | * |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2022 | * @param connector The drm_connector object to be updated. |
| 2023 | * @param conn The connector data to be owned by the drm_connector, must match |
| 2024 | * the current drm_connector ID. |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2025 | * @return 0 on success, -1 on failure. |
| 2026 | * |
| 2027 | * Takes ownership of @c connector on success, not on failure. |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2028 | */ |
| 2029 | static int |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2030 | drm_connector_assign_connector_info(struct drm_connector *connector, |
| 2031 | drmModeConnector *conn) |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2032 | { |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2033 | assert(connector->conn != conn); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2034 | assert(connector->connector_id == conn->connector_id); |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2035 | |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2036 | if (drm_connector_update_properties(connector) < 0) |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2037 | return -1; |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2038 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2039 | if (connector->conn) |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2040 | drmModeFreeConnector(connector->conn); |
| 2041 | connector->conn = conn; |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2042 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2043 | drm_property_info_free(connector->props, WDRM_CONNECTOR__COUNT); |
| 2044 | drm_property_info_populate(connector->backend, connector_props, |
| 2045 | connector->props, |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2046 | WDRM_CONNECTOR__COUNT, connector->props_drm); |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2047 | return 0; |
| 2048 | } |
| 2049 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2050 | static void |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2051 | drm_connector_init(struct drm_backend *b, struct drm_connector *connector, |
| 2052 | uint32_t connector_id) |
| 2053 | { |
| 2054 | connector->backend = b; |
| 2055 | connector->connector_id = connector_id; |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2056 | connector->conn = NULL; |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2057 | connector->props_drm = NULL; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | static void |
| 2061 | drm_connector_fini(struct drm_connector *connector) |
| 2062 | { |
| 2063 | drmModeFreeConnector(connector->conn); |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2064 | drmModeFreeObjectProperties(connector->props_drm); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2065 | drm_property_info_free(connector->props, WDRM_CONNECTOR__COUNT); |
| 2066 | } |
| 2067 | |
Pekka Paalanen | 456dc73 | 2017-11-09 15:10:11 +0200 | [diff] [blame] | 2068 | static void |
| 2069 | drm_head_log_info(struct drm_head *head, const char *msg) |
| 2070 | { |
| 2071 | if (head->base.connected) { |
| 2072 | weston_log("DRM: head '%s' %s, connector %d is connected, " |
| 2073 | "EDID make '%s', model '%s', serial '%s'\n", |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2074 | head->base.name, msg, head->connector.connector_id, |
Pekka Paalanen | 456dc73 | 2017-11-09 15:10:11 +0200 | [diff] [blame] | 2075 | head->base.make, head->base.model, |
| 2076 | head->base.serial_number ?: ""); |
| 2077 | } else { |
| 2078 | weston_log("DRM: head '%s' %s, connector %d is disconnected.\n", |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2079 | head->base.name, msg, head->connector.connector_id); |
Pekka Paalanen | 456dc73 | 2017-11-09 15:10:11 +0200 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2083 | /** Update connector and monitor information |
| 2084 | * |
| 2085 | * @param head The head to update. |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2086 | * @param conn The DRM connector object. |
| 2087 | * @returns 0 on success, -1 on failure. |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2088 | * |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2089 | * Updates monitor information and connection status. This may schedule a |
| 2090 | * heads changed call to the user. |
Leandro Ribeiro | 4a5b67a | 2020-09-15 15:30:35 -0300 | [diff] [blame] | 2091 | * |
| 2092 | * Takes ownership of @c connector on success, not on failure. |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2093 | */ |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2094 | static int |
| 2095 | drm_head_update_info(struct drm_head *head, drmModeConnector *conn) |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2096 | { |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2097 | int ret; |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2098 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2099 | ret = drm_connector_assign_connector_info(&head->connector, conn); |
Pekka Paalanen | 456dc73 | 2017-11-09 15:10:11 +0200 | [diff] [blame] | 2100 | |
Leandro Ribeiro | 6794164 | 2020-09-15 00:11:02 -0300 | [diff] [blame] | 2101 | update_head_from_connector(head); |
| 2102 | weston_head_set_content_protection_status(&head->base, |
| 2103 | drm_head_get_current_protection(head)); |
| 2104 | |
Pekka Paalanen | 456dc73 | 2017-11-09 15:10:11 +0200 | [diff] [blame] | 2105 | if (head->base.device_changed) |
| 2106 | drm_head_log_info(head, "updated"); |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2107 | |
| 2108 | return ret; |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2109 | } |
| 2110 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2111 | /** Update writeback connector |
| 2112 | * |
| 2113 | * @param writeback The writeback to update. |
| 2114 | * @param conn DRM connector object. |
| 2115 | * @returns 0 on success, -1 on failure. |
| 2116 | * |
| 2117 | * Takes ownership of @c connector on success, not on failure. |
| 2118 | */ |
| 2119 | static int |
| 2120 | drm_writeback_update_info(struct drm_writeback *writeback, drmModeConnector *conn) |
| 2121 | { |
| 2122 | int ret; |
| 2123 | |
| 2124 | ret = drm_connector_assign_connector_info(&writeback->connector, conn); |
| 2125 | |
| 2126 | return ret; |
| 2127 | } |
| 2128 | |
Daniel Stone | 087ddf0 | 2017-02-14 17:51:30 +0000 | [diff] [blame] | 2129 | /** |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2130 | * Create a Weston head for a connector |
| 2131 | * |
| 2132 | * Given a DRM connector, create a matching drm_head structure and add it |
| 2133 | * to Weston's head list. |
| 2134 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 2135 | * @param backend Weston backend structure |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2136 | * @param conn DRM connector object |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2137 | * @param drm_device udev device pointer |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2138 | * @returns 0 on success, -1 on failure |
Leandro Ribeiro | 4a5b67a | 2020-09-15 15:30:35 -0300 | [diff] [blame] | 2139 | * |
| 2140 | * Takes ownership of @c connector on success, not on failure. |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2141 | */ |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2142 | static int |
| 2143 | drm_head_create(struct drm_backend *backend, drmModeConnector *conn, |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2144 | struct udev_device *drm_device) |
| 2145 | { |
| 2146 | struct drm_head *head; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2147 | char *name; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2148 | int ret; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2149 | |
| 2150 | head = zalloc(sizeof *head); |
| 2151 | if (!head) |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2152 | return -1; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2153 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2154 | head->backend = backend; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2155 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2156 | drm_connector_init(backend, &head->connector, conn->connector_id); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2157 | |
| 2158 | name = make_connector_name(conn); |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2159 | if (!name) |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2160 | goto err; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2161 | |
| 2162 | weston_head_init(&head->base, name); |
| 2163 | free(name); |
| 2164 | |
Leandro Ribeiro | 6794164 | 2020-09-15 00:11:02 -0300 | [diff] [blame] | 2165 | ret = drm_head_update_info(head, conn); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2166 | if (ret < 0) |
Leandro Ribeiro | 6794164 | 2020-09-15 00:11:02 -0300 | [diff] [blame] | 2167 | goto err_update; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2168 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2169 | head->backlight = backlight_init(drm_device, conn->connector_type); |
Pekka Paalanen | ce72424 | 2017-09-04 12:21:24 +0300 | [diff] [blame] | 2170 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2171 | if (conn->connector_type == DRM_MODE_CONNECTOR_LVDS || |
| 2172 | conn->connector_type == DRM_MODE_CONNECTOR_eDP) |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2173 | weston_head_set_internal(&head->base); |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2174 | |
Pekka Paalanen | 9c03a7c | 2017-11-28 14:30:10 +0200 | [diff] [blame] | 2175 | if (drm_head_read_current_setup(head, backend) < 0) { |
Pekka Paalanen | 13d233e | 2017-09-11 14:06:11 +0300 | [diff] [blame] | 2176 | weston_log("Failed to retrieve current mode from connector %d.\n", |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2177 | head->connector.connector_id); |
Pekka Paalanen | 6fae2be | 2017-11-28 14:33:52 +0200 | [diff] [blame] | 2178 | /* Not fatal. */ |
Pekka Paalanen | 13d233e | 2017-09-11 14:06:11 +0300 | [diff] [blame] | 2179 | } |
| 2180 | |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2181 | weston_compositor_add_head(backend->compositor, &head->base); |
Pekka Paalanen | 456dc73 | 2017-11-09 15:10:11 +0200 | [diff] [blame] | 2182 | drm_head_log_info(head, "found"); |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2183 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2184 | return 0; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2185 | |
Leandro Ribeiro | 6794164 | 2020-09-15 00:11:02 -0300 | [diff] [blame] | 2186 | err_update: |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2187 | weston_head_release(&head->base); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2188 | err: |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2189 | drm_connector_fini(&head->connector); |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2190 | free(head); |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2191 | return -1; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | static void |
| 2195 | drm_head_destroy(struct drm_head *head) |
| 2196 | { |
| 2197 | weston_head_release(&head->base); |
Pekka Paalanen | ce72424 | 2017-09-04 12:21:24 +0300 | [diff] [blame] | 2198 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2199 | drm_connector_fini(&head->connector); |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2200 | |
Pekka Paalanen | ce72424 | 2017-09-04 12:21:24 +0300 | [diff] [blame] | 2201 | if (head->backlight) |
| 2202 | backlight_destroy(head->backlight); |
| 2203 | |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2204 | free(head); |
| 2205 | } |
| 2206 | |
| 2207 | /** |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2208 | * Create a Weston output structure |
| 2209 | * |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2210 | * Create an "empty" drm_output. This is the implementation of |
| 2211 | * weston_backend::create_output. |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2212 | * |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2213 | * Creating an output is usually followed by drm_output_attach_head() |
| 2214 | * and drm_output_enable() to make use of it. |
| 2215 | * |
| 2216 | * @param compositor The compositor instance. |
| 2217 | * @param name Name for the new output. |
| 2218 | * @returns The output, or NULL on failure. |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2219 | */ |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2220 | static struct weston_output * |
| 2221 | drm_output_create(struct weston_compositor *compositor, const char *name) |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2222 | { |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2223 | struct drm_backend *b = to_drm_backend(compositor); |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2224 | struct drm_output *output; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2225 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2226 | output = zalloc(sizeof *output); |
| 2227 | if (output == NULL) |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2228 | return NULL; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2229 | |
Daniel Stone | 64dbbee | 2018-07-20 19:00:06 +0100 | [diff] [blame] | 2230 | output->backend = b; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2231 | output->crtc = NULL; |
| 2232 | |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 2233 | #ifdef BUILD_DRM_GBM |
Tomohito Esaki | 718a40b | 2018-01-31 17:50:15 +0900 | [diff] [blame] | 2234 | output->gbm_bo_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 2235 | #endif |
Daniel Stone | 64dbbee | 2018-07-20 19:00:06 +0100 | [diff] [blame] | 2236 | |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2237 | weston_output_init(&output->base, compositor, name); |
Pekka Paalanen | c1e89ba | 2017-08-31 16:18:48 +0300 | [diff] [blame] | 2238 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2239 | output->base.enable = drm_output_enable; |
| 2240 | output->base.destroy = drm_output_destroy; |
| 2241 | output->base.disable = drm_output_disable; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2242 | output->base.attach_head = drm_output_attach_head; |
Pekka Paalanen | 7f85379 | 2017-11-29 14:33:33 +0200 | [diff] [blame] | 2243 | output->base.detach_head = drm_output_detach_head; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2244 | |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 2245 | output->destroy_pending = false; |
| 2246 | output->disable_pending = false; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2247 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 2248 | output->state_cur = drm_output_state_alloc(output, NULL); |
Pekka Paalanen | a0bfedc | 2017-04-03 14:42:51 +0300 | [diff] [blame] | 2249 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2250 | weston_compositor_add_pending_output(&output->base, b->compositor); |
| 2251 | |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2252 | return &output->base; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2253 | } |
| 2254 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2255 | /** |
| 2256 | * Create a Weston writeback for a writeback connector |
Leandro Ribeiro | 7243022 | 2020-09-14 17:41:41 -0300 | [diff] [blame] | 2257 | * |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2258 | * Given a DRM connector of type writeback, create a matching drm_writeback |
| 2259 | * structure and add it to Weston's writeback list. |
| 2260 | * |
| 2261 | * @param b Weston backend structure |
| 2262 | * @param conn DRM connector object of type writeback |
| 2263 | * @returns 0 on success, -1 on failure |
| 2264 | * |
| 2265 | * Takes ownership of @c connector on success, not on failure. |
| 2266 | */ |
| 2267 | static int |
| 2268 | drm_writeback_create(struct drm_backend *b, drmModeConnector *conn) |
| 2269 | { |
| 2270 | struct drm_writeback *writeback; |
| 2271 | int ret; |
| 2272 | |
| 2273 | writeback = zalloc(sizeof *writeback); |
| 2274 | assert(writeback); |
| 2275 | |
| 2276 | writeback->backend = b; |
| 2277 | |
| 2278 | drm_connector_init(b, &writeback->connector, conn->connector_id); |
| 2279 | |
| 2280 | ret = drm_writeback_update_info(writeback, conn); |
| 2281 | if (ret < 0) |
| 2282 | goto err; |
| 2283 | |
| 2284 | wl_list_insert(&b->writeback_connector_list, &writeback->link); |
| 2285 | return 0; |
| 2286 | |
| 2287 | err: |
| 2288 | drm_connector_fini(&writeback->connector); |
| 2289 | free(writeback); |
| 2290 | return -1; |
| 2291 | } |
| 2292 | |
| 2293 | static void |
| 2294 | drm_writeback_destroy(struct drm_writeback *writeback) |
| 2295 | { |
| 2296 | drm_connector_fini(&writeback->connector); |
| 2297 | wl_list_remove(&writeback->link); |
| 2298 | |
| 2299 | free(writeback); |
| 2300 | } |
| 2301 | |
| 2302 | /** Given the DRM connector object of a connector, create drm_head or |
| 2303 | * drm_writeback object (depending on the type of connector) for it. |
| 2304 | * |
| 2305 | * The object is then added to the DRM-backend list of heads or writebacks. |
Leandro Ribeiro | 7243022 | 2020-09-14 17:41:41 -0300 | [diff] [blame] | 2306 | * |
| 2307 | * @param b The DRM-backend structure |
| 2308 | * @param conn The DRM connector object |
| 2309 | * @param drm_device udev device pointer |
| 2310 | * @return 0 on success, -1 on failure |
| 2311 | */ |
| 2312 | static int |
| 2313 | drm_backend_add_connector(struct drm_backend *b, drmModeConnector *conn, |
| 2314 | struct udev_device *drm_device) |
| 2315 | { |
| 2316 | int ret; |
| 2317 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2318 | if (conn->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) { |
| 2319 | ret = drm_writeback_create(b, conn); |
| 2320 | if (ret < 0) |
| 2321 | weston_log("DRM: failed to create writeback for connector %d.\n", |
| 2322 | conn->connector_id); |
| 2323 | } else { |
| 2324 | ret = drm_head_create(b, conn, drm_device); |
| 2325 | if (ret < 0) |
| 2326 | weston_log("DRM: failed to create head for connector %d.\n", |
| 2327 | conn->connector_id); |
| 2328 | } |
Leandro Ribeiro | 7243022 | 2020-09-14 17:41:41 -0300 | [diff] [blame] | 2329 | |
| 2330 | return ret; |
| 2331 | } |
| 2332 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2333 | /** Find all connectors of the fd and create drm_head or drm_writeback objects |
| 2334 | * (depending on the type of connector they are) for each of them |
| 2335 | * |
| 2336 | * These objects are added to the DRM-backend lists of heads and writebacks. |
| 2337 | * |
| 2338 | * @param b The DRM-backend structure |
| 2339 | * @param drm_device udev device pointer |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 2340 | * @param resources The DRM resources, it is taken with drmModeGetResources |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2341 | * @return 0 on success, -1 on failure |
| 2342 | */ |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2343 | static int |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 2344 | drm_backend_discover_connectors(struct drm_backend *b, struct udev_device *drm_device, |
| 2345 | drmModeRes *resources) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2346 | { |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2347 | drmModeConnector *conn; |
| 2348 | int i, ret; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2349 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2350 | b->min_width = resources->min_width; |
| 2351 | b->max_width = resources->max_width; |
| 2352 | b->min_height = resources->min_height; |
| 2353 | b->max_height = resources->max_height; |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 2354 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2355 | for (i = 0; i < resources->count_connectors; i++) { |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2356 | uint32_t connector_id = resources->connectors[i]; |
Daniel Stone | 02cf466 | 2017-03-03 16:19:39 +0000 | [diff] [blame] | 2357 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2358 | conn = drmModeGetConnector(b->drm.fd, connector_id); |
| 2359 | if (!conn) |
| 2360 | continue; |
| 2361 | |
Leandro Ribeiro | 7243022 | 2020-09-14 17:41:41 -0300 | [diff] [blame] | 2362 | ret = drm_backend_add_connector(b, conn, drm_device); |
| 2363 | if (ret < 0) |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2364 | drmModeFreeConnector(conn); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2365 | } |
| 2366 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2367 | return 0; |
| 2368 | } |
| 2369 | |
Leandro Ribeiro | 99611c8 | 2020-09-14 17:19:12 -0300 | [diff] [blame] | 2370 | static bool |
| 2371 | resources_has_connector(drmModeRes *resources, uint32_t connector_id) |
| 2372 | { |
| 2373 | for (int i = 0; i < resources->count_connectors; i++) { |
| 2374 | if (resources->connectors[i] == connector_id) |
| 2375 | return true; |
| 2376 | } |
| 2377 | |
| 2378 | return false; |
| 2379 | } |
| 2380 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2381 | static void |
Leandro Ribeiro | 993920d | 2020-09-14 17:01:01 -0300 | [diff] [blame] | 2382 | drm_backend_update_connectors(struct drm_backend *b, struct udev_device *drm_device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2383 | { |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2384 | drmModeRes *resources; |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2385 | drmModeConnector *conn; |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2386 | struct weston_head *base, *base_next; |
Pekka Paalanen | a0a3746 | 2017-08-31 15:41:57 +0300 | [diff] [blame] | 2387 | struct drm_head *head; |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2388 | struct drm_writeback *writeback, *writeback_next; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2389 | uint32_t connector_id; |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2390 | int i, ret; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2391 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2392 | resources = drmModeGetResources(b->drm.fd); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2393 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2394 | weston_log("drmModeGetResources failed\n"); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2395 | return; |
| 2396 | } |
| 2397 | |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2398 | /* collect new connectors that have appeared, e.g. MST */ |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2399 | for (i = 0; i < resources->count_connectors; i++) { |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2400 | connector_id = resources->connectors[i]; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2401 | |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2402 | conn = drmModeGetConnector(b->drm.fd, connector_id); |
| 2403 | if (!conn) |
| 2404 | continue; |
| 2405 | |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2406 | head = drm_head_find_by_connector(b, connector_id); |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2407 | writeback = drm_writeback_find_by_connector(b, connector_id); |
| 2408 | |
| 2409 | /* Connector can't be owned by both a head and a writeback, so |
| 2410 | * one of the searches must fail. */ |
| 2411 | assert(head == NULL || writeback == NULL); |
| 2412 | |
Leandro Ribeiro | 7243022 | 2020-09-14 17:41:41 -0300 | [diff] [blame] | 2413 | if (head) |
Leandro Ribeiro | 7086396 | 2020-09-09 13:12:35 -0300 | [diff] [blame] | 2414 | ret = drm_head_update_info(head, conn); |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2415 | else if (writeback) |
| 2416 | ret = drm_writeback_update_info(writeback, conn); |
Leandro Ribeiro | 7243022 | 2020-09-14 17:41:41 -0300 | [diff] [blame] | 2417 | else |
| 2418 | ret = drm_backend_add_connector(b, conn, drm_device); |
| 2419 | |
| 2420 | if (ret < 0) |
| 2421 | drmModeFreeConnector(conn); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2422 | } |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2423 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2424 | /* Destroy head objects of connectors (except writeback connectors) that |
| 2425 | * have disappeared. */ |
| 2426 | wl_list_for_each_safe(base, base_next, |
Pekka Paalanen | a0a3746 | 2017-08-31 15:41:57 +0300 | [diff] [blame] | 2427 | &b->compositor->head_list, compositor_link) { |
Pekka Paalanen | a0a3746 | 2017-08-31 15:41:57 +0300 | [diff] [blame] | 2428 | head = to_drm_head(base); |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2429 | connector_id = head->connector.connector_id; |
Pekka Paalanen | a0a3746 | 2017-08-31 15:41:57 +0300 | [diff] [blame] | 2430 | |
Leandro Ribeiro | 99611c8 | 2020-09-14 17:19:12 -0300 | [diff] [blame] | 2431 | if (resources_has_connector(resources, connector_id)) |
Daniel Stone | efc2b1d | 2017-02-09 14:06:31 +0000 | [diff] [blame] | 2432 | continue; |
| 2433 | |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2434 | weston_log("DRM: head '%s' (connector %d) disappeared.\n", |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2435 | head->base.name, connector_id); |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 2436 | drm_head_destroy(head); |
Daniel Stone | efc2b1d | 2017-02-09 14:06:31 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2439 | /* Destroy writeback objects of writeback connectors that have |
| 2440 | * disappeared. */ |
| 2441 | wl_list_for_each_safe(writeback, writeback_next, |
| 2442 | &b->writeback_connector_list, link) { |
| 2443 | connector_id = writeback->connector.connector_id; |
| 2444 | |
| 2445 | if (resources_has_connector(resources, connector_id)) |
| 2446 | continue; |
| 2447 | |
| 2448 | weston_log("DRM: writeback connector (connector %d) disappeared.\n", |
| 2449 | connector_id); |
| 2450 | drm_writeback_destroy(writeback); |
| 2451 | } |
| 2452 | |
Daniel Stone | efc2b1d | 2017-02-09 14:06:31 +0000 | [diff] [blame] | 2453 | drmModeFreeResources(resources); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2454 | } |
| 2455 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2456 | static enum wdrm_connector_property |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2457 | drm_connector_find_property_by_id(struct drm_connector *connector, |
| 2458 | uint32_t property_id) |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2459 | { |
| 2460 | int i; |
| 2461 | enum wdrm_connector_property prop = WDRM_CONNECTOR__COUNT; |
| 2462 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2463 | if (!connector || !property_id) |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2464 | return WDRM_CONNECTOR__COUNT; |
| 2465 | |
| 2466 | for (i = 0; i < WDRM_CONNECTOR__COUNT; i++) |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2467 | if (connector->props[i].prop_id == property_id) { |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2468 | prop = (enum wdrm_connector_property) i; |
| 2469 | break; |
| 2470 | } |
| 2471 | return prop; |
| 2472 | } |
| 2473 | |
| 2474 | static void |
| 2475 | drm_backend_update_conn_props(struct drm_backend *b, |
| 2476 | uint32_t connector_id, |
| 2477 | uint32_t property_id) |
| 2478 | { |
| 2479 | struct drm_head *head; |
| 2480 | enum wdrm_connector_property conn_prop; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2481 | |
| 2482 | head = drm_head_find_by_connector(b, connector_id); |
| 2483 | if (!head) { |
| 2484 | weston_log("DRM: failed to find head for connector id: %d.\n", |
| 2485 | connector_id); |
| 2486 | return; |
| 2487 | } |
| 2488 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 2489 | conn_prop = drm_connector_find_property_by_id(&head->connector, property_id); |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2490 | if (conn_prop >= WDRM_CONNECTOR__COUNT) |
| 2491 | return; |
| 2492 | |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2493 | if (drm_connector_update_properties(&head->connector) < 0) |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2494 | return; |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2495 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2496 | if (conn_prop == WDRM_CONNECTOR_CONTENT_PROTECTION) { |
| 2497 | weston_head_set_content_protection_status(&head->base, |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 2498 | drm_head_get_current_protection(head)); |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2499 | } |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2500 | } |
| 2501 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2502 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2503 | udev_event_is_hotplug(struct drm_backend *b, struct udev_device *device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2504 | { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2505 | const char *sysnum; |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2506 | const char *val; |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2507 | |
| 2508 | sysnum = udev_device_get_sysnum(device); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2509 | if (!sysnum || atoi(sysnum) != b->drm.id) |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2510 | return 0; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2511 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2512 | val = udev_device_get_property_value(device, "HOTPLUG"); |
| 2513 | if (!val) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2514 | return 0; |
| 2515 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2516 | return strcmp(val, "1") == 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2517 | } |
| 2518 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2519 | static int |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2520 | udev_event_is_conn_prop_change(struct drm_backend *b, |
| 2521 | struct udev_device *device, |
| 2522 | uint32_t *connector_id, |
| 2523 | uint32_t *property_id) |
| 2524 | |
| 2525 | { |
| 2526 | const char *val; |
| 2527 | int id; |
| 2528 | |
| 2529 | val = udev_device_get_property_value(device, "CONNECTOR"); |
| 2530 | if (!val || !safe_strtoint(val, &id)) |
| 2531 | return 0; |
| 2532 | else |
| 2533 | *connector_id = id; |
| 2534 | |
| 2535 | val = udev_device_get_property_value(device, "PROPERTY"); |
| 2536 | if (!val || !safe_strtoint(val, &id)) |
| 2537 | return 0; |
| 2538 | else |
| 2539 | *property_id = id; |
| 2540 | |
| 2541 | return 1; |
| 2542 | } |
| 2543 | |
| 2544 | static int |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2545 | udev_drm_event(int fd, uint32_t mask, void *data) |
| 2546 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2547 | struct drm_backend *b = data; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2548 | struct udev_device *event; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2549 | uint32_t conn_id, prop_id; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2550 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2551 | event = udev_monitor_receive_device(b->udev_monitor); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2552 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2553 | if (udev_event_is_hotplug(b, event)) { |
| 2554 | if (udev_event_is_conn_prop_change(b, event, &conn_id, &prop_id)) |
| 2555 | drm_backend_update_conn_props(b, conn_id, prop_id); |
| 2556 | else |
Leandro Ribeiro | 993920d | 2020-09-14 17:01:01 -0300 | [diff] [blame] | 2557 | drm_backend_update_connectors(b, event); |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 2558 | } |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2559 | |
| 2560 | udev_device_unref(event); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2561 | |
| 2562 | return 1; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2563 | } |
| 2564 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2565 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2566 | drm_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2567 | { |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 2568 | struct drm_backend *b = to_drm_backend(ec); |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2569 | struct weston_head *base, *next; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2570 | struct drm_crtc *crtc, *crtc_tmp; |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2571 | struct drm_writeback *writeback, *writeback_tmp; |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2572 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2573 | udev_input_destroy(&b->input); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 2574 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2575 | wl_event_source_remove(b->udev_drm_source); |
| 2576 | wl_event_source_remove(b->drm_source); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 2577 | |
Daniel Stone | b57c6a0 | 2017-10-05 16:27:21 +0100 | [diff] [blame] | 2578 | b->shutting_down = true; |
| 2579 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2580 | destroy_sprites(b); |
Kristian Høgsberg | 3d64a3e | 2013-05-10 12:36:04 -0400 | [diff] [blame] | 2581 | |
Leandro Ribeiro | f014964 | 2019-12-18 15:52:18 -0300 | [diff] [blame] | 2582 | weston_log_scope_destroy(b->debug); |
Daniel Stone | 1cbe1f9 | 2018-07-20 10:21:28 +0100 | [diff] [blame] | 2583 | b->debug = NULL; |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 2584 | weston_compositor_shutdown(ec); |
| 2585 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2586 | wl_list_for_each_safe(crtc, crtc_tmp, &b->crtc_list, link) |
| 2587 | drm_crtc_destroy(crtc); |
| 2588 | |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 2589 | wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) |
| 2590 | drm_head_destroy(to_drm_head(base)); |
| 2591 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 2592 | wl_list_for_each_safe(writeback, writeback_tmp, |
| 2593 | &b->writeback_connector_list, link) |
| 2594 | drm_writeback_destroy(writeback); |
| 2595 | |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 2596 | #ifdef BUILD_DRM_GBM |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2597 | if (b->gbm) |
| 2598 | gbm_device_destroy(b->gbm); |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 2599 | #endif |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2600 | |
Pekka Paalanen | 5b0aa55 | 2017-12-07 16:06:05 +0200 | [diff] [blame] | 2601 | udev_monitor_unref(b->udev_monitor); |
Pekka Paalanen | 2a0c6c3 | 2017-09-13 16:48:01 +0300 | [diff] [blame] | 2602 | udev_unref(b->udev); |
| 2603 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2604 | weston_launcher_destroy(ec->launcher); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2605 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2606 | close(b->drm.fd); |
Pekka Paalanen | 9bf4f37 | 2017-12-07 16:05:29 +0200 | [diff] [blame] | 2607 | free(b->drm.filename); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2608 | free(b); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2609 | } |
| 2610 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2611 | static void |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2612 | session_notify(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2613 | { |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2614 | struct weston_compositor *compositor = data; |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 2615 | struct drm_backend *b = to_drm_backend(compositor); |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 2616 | struct drm_plane *plane; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2617 | struct drm_output *output; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2618 | struct drm_crtc *crtc; |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2619 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2620 | if (compositor->session_active) { |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2621 | weston_log("activating session\n"); |
Daniel Stone | f33e104 | 2016-11-05 08:10:13 +0000 | [diff] [blame] | 2622 | weston_compositor_wake(compositor); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2623 | weston_compositor_damage_all(compositor); |
Daniel Stone | 6020f47 | 2018-02-05 15:46:20 +0000 | [diff] [blame] | 2624 | b->state_invalid = true; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2625 | udev_input_enable(&b->input); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2626 | } else { |
| 2627 | weston_log("deactivating session\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2628 | udev_input_disable(&b->input); |
Kristian Høgsberg | 4014a6b | 2012-04-10 00:08:45 -0400 | [diff] [blame] | 2629 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2630 | weston_compositor_offscreen(compositor); |
Kristian Høgsberg | d8e181b | 2011-05-06 15:38:28 -0400 | [diff] [blame] | 2631 | |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2632 | /* If we have a repaint scheduled (either from a |
| 2633 | * pending pageflip or the idle handler), make sure we |
| 2634 | * 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] | 2635 | * vt switched away. The OFFSCREEN state will prevent |
Abdur Rehman | 4dca0e1 | 2017-01-01 19:46:35 +0500 | [diff] [blame] | 2636 | * further attempts at repainting. When we switch |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2637 | * back, we schedule a repaint, which will process |
| 2638 | * pending frame callbacks. */ |
| 2639 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2640 | wl_list_for_each(output, &compositor->output_list, base.link) { |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2641 | crtc = output->crtc; |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2642 | output->base.repaint_needed = false; |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 2643 | if (output->cursor_plane) |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2644 | drmModeSetCursor(b->drm.fd, crtc->crtc_id, |
Daniel Stone | 2ba17f4 | 2015-05-19 20:02:41 +0100 | [diff] [blame] | 2645 | 0, 0, 0); |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2646 | } |
| 2647 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2648 | output = container_of(compositor->output_list.next, |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2649 | struct drm_output, base.link); |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2650 | crtc = output->crtc; |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2651 | |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 2652 | wl_list_for_each(plane, &b->plane_list, link) { |
| 2653 | if (plane->type != WDRM_PLANE_TYPE_OVERLAY) |
| 2654 | continue; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 2655 | drmModeSetPlane(b->drm.fd, plane->plane_id, crtc->crtc_id, |
| 2656 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 2657 | } |
| 2658 | } |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2659 | } |
| 2660 | |
Robert Beckett | 8d23ab7 | 2019-06-13 16:55:44 +0100 | [diff] [blame] | 2661 | |
| 2662 | /** |
| 2663 | * Handle KMS GPU being added/removed |
| 2664 | * |
| 2665 | * If the device being added/removed is the KMS device, we activate/deactivate |
| 2666 | * the compositor session. |
| 2667 | * |
| 2668 | * @param compositor The compositor instance. |
| 2669 | * @param device The device being added/removed. |
| 2670 | * @param added Whether the device is being added (or removed) |
| 2671 | */ |
| 2672 | static void |
| 2673 | drm_device_changed(struct weston_compositor *compositor, |
| 2674 | dev_t device, bool added) |
| 2675 | { |
| 2676 | struct drm_backend *b = to_drm_backend(compositor); |
| 2677 | |
Robert Beckett | 49dc320 | 2019-07-02 16:31:22 +0100 | [diff] [blame] | 2678 | if (b->drm.fd < 0 || b->drm.devnum != device || |
| 2679 | compositor->session_active == added) |
Robert Beckett | 8d23ab7 | 2019-06-13 16:55:44 +0100 | [diff] [blame] | 2680 | return; |
| 2681 | |
| 2682 | compositor->session_active = added; |
| 2683 | wl_signal_emit(&compositor->session_signal, compositor); |
| 2684 | } |
| 2685 | |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2686 | /** |
| 2687 | * Determines whether or not a device is capable of modesetting. If successful, |
| 2688 | * sets b->drm.fd and b->drm.filename to the opened device. |
| 2689 | */ |
| 2690 | static bool |
| 2691 | drm_device_is_kms(struct drm_backend *b, struct udev_device *device) |
| 2692 | { |
| 2693 | const char *filename = udev_device_get_devnode(device); |
| 2694 | const char *sysnum = udev_device_get_sysnum(device); |
Robert Beckett | 8d23ab7 | 2019-06-13 16:55:44 +0100 | [diff] [blame] | 2695 | dev_t devnum = udev_device_get_devnum(device); |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2696 | drmModeRes *res; |
Marius Vlad | 7d070ca | 2018-11-23 14:02:07 +0200 | [diff] [blame] | 2697 | int id = -1, fd; |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2698 | |
| 2699 | if (!filename) |
| 2700 | return false; |
| 2701 | |
| 2702 | fd = weston_launcher_open(b->compositor->launcher, filename, O_RDWR); |
| 2703 | if (fd < 0) |
| 2704 | return false; |
| 2705 | |
| 2706 | res = drmModeGetResources(fd); |
| 2707 | if (!res) |
| 2708 | goto out_fd; |
| 2709 | |
| 2710 | if (res->count_crtcs <= 0 || res->count_connectors <= 0 || |
| 2711 | res->count_encoders <= 0) |
| 2712 | goto out_res; |
| 2713 | |
| 2714 | if (sysnum) |
| 2715 | id = atoi(sysnum); |
| 2716 | if (!sysnum || id < 0) { |
| 2717 | weston_log("couldn't get sysnum for device %s\n", filename); |
| 2718 | goto out_res; |
| 2719 | } |
| 2720 | |
| 2721 | /* We can be called successfully on multiple devices; if we have, |
| 2722 | * clean up old entries. */ |
| 2723 | if (b->drm.fd >= 0) |
| 2724 | weston_launcher_close(b->compositor->launcher, b->drm.fd); |
| 2725 | free(b->drm.filename); |
| 2726 | |
| 2727 | b->drm.fd = fd; |
| 2728 | b->drm.id = id; |
| 2729 | b->drm.filename = strdup(filename); |
Robert Beckett | 8d23ab7 | 2019-06-13 16:55:44 +0100 | [diff] [blame] | 2730 | b->drm.devnum = devnum; |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2731 | |
Sergi Granell | ceb5981 | 2017-03-28 12:44:04 +0200 | [diff] [blame] | 2732 | drmModeFreeResources(res); |
| 2733 | |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2734 | return true; |
| 2735 | |
| 2736 | out_res: |
| 2737 | drmModeFreeResources(res); |
| 2738 | out_fd: |
| 2739 | weston_launcher_close(b->compositor->launcher, fd); |
| 2740 | return false; |
| 2741 | } |
| 2742 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2743 | /* |
| 2744 | * Find primary GPU |
| 2745 | * Some systems may have multiple DRM devices attached to a single seat. This |
| 2746 | * function loops over all devices and tries to find a PCI device with the |
| 2747 | * boot_vga sysfs attribute set to 1. |
| 2748 | * 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] | 2749 | * Devices are also vetted to make sure they are are capable of modesetting, |
| 2750 | * rather than pure render nodes (GPU with no display), or pure |
| 2751 | * memory-allocation devices (VGEM). |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2752 | */ |
| 2753 | static struct udev_device* |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2754 | find_primary_gpu(struct drm_backend *b, const char *seat) |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2755 | { |
| 2756 | struct udev_enumerate *e; |
| 2757 | struct udev_list_entry *entry; |
| 2758 | const char *path, *device_seat, *id; |
| 2759 | struct udev_device *device, *drm_device, *pci; |
| 2760 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2761 | e = udev_enumerate_new(b->udev); |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2762 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 2763 | udev_enumerate_add_match_sysname(e, "card[0-9]*"); |
| 2764 | |
| 2765 | udev_enumerate_scan_devices(e); |
| 2766 | drm_device = NULL; |
| 2767 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2768 | bool is_boot_vga = false; |
| 2769 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2770 | path = udev_list_entry_get_name(entry); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2771 | device = udev_device_new_from_syspath(b->udev, path); |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2772 | if (!device) |
| 2773 | continue; |
| 2774 | device_seat = udev_device_get_property_value(device, "ID_SEAT"); |
| 2775 | if (!device_seat) |
| 2776 | device_seat = default_seat; |
| 2777 | if (strcmp(device_seat, seat)) { |
| 2778 | udev_device_unref(device); |
| 2779 | continue; |
| 2780 | } |
| 2781 | |
| 2782 | pci = udev_device_get_parent_with_subsystem_devtype(device, |
| 2783 | "pci", NULL); |
| 2784 | if (pci) { |
| 2785 | id = udev_device_get_sysattr_value(pci, "boot_vga"); |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2786 | if (id && !strcmp(id, "1")) |
| 2787 | is_boot_vga = true; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2788 | } |
| 2789 | |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2790 | /* If we already have a modesetting-capable device, and this |
| 2791 | * device isn't our boot-VGA device, we aren't going to use |
| 2792 | * it. */ |
| 2793 | if (!is_boot_vga && drm_device) { |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2794 | udev_device_unref(device); |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2795 | continue; |
| 2796 | } |
| 2797 | |
| 2798 | /* Make sure this device is actually capable of modesetting; |
| 2799 | * if this call succeeds, b->drm.{fd,filename} will be set, |
| 2800 | * and any old values freed. */ |
| 2801 | if (!drm_device_is_kms(b, device)) { |
| 2802 | udev_device_unref(device); |
| 2803 | continue; |
| 2804 | } |
| 2805 | |
| 2806 | /* There can only be one boot_vga device, and we try to use it |
| 2807 | * at all costs. */ |
| 2808 | if (is_boot_vga) { |
| 2809 | if (drm_device) |
| 2810 | udev_device_unref(drm_device); |
| 2811 | drm_device = device; |
| 2812 | break; |
| 2813 | } |
| 2814 | |
| 2815 | /* Per the (!is_boot_vga && drm_device) test above, we only |
| 2816 | * trump existing saved devices with boot-VGA devices, so if |
| 2817 | * we end up here, this must be the first device we've seen. */ |
| 2818 | assert(!drm_device); |
| 2819 | drm_device = device; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2820 | } |
| 2821 | |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 2822 | /* If we're returning a device to use, we must have an open FD for |
| 2823 | * it. */ |
| 2824 | assert(!!drm_device == (b->drm.fd >= 0)); |
| 2825 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2826 | udev_enumerate_unref(e); |
| 2827 | return drm_device; |
| 2828 | } |
| 2829 | |
Pekka Paalanen | b45ed8b | 2017-03-28 18:04:27 +0300 | [diff] [blame] | 2830 | static struct udev_device * |
| 2831 | open_specific_drm_device(struct drm_backend *b, const char *name) |
| 2832 | { |
| 2833 | struct udev_device *device; |
| 2834 | |
| 2835 | device = udev_device_new_from_subsystem_sysname(b->udev, "drm", name); |
| 2836 | if (!device) { |
| 2837 | weston_log("ERROR: could not open DRM device '%s'\n", name); |
| 2838 | return NULL; |
| 2839 | } |
| 2840 | |
| 2841 | if (!drm_device_is_kms(b, device)) { |
| 2842 | udev_device_unref(device); |
| 2843 | weston_log("ERROR: DRM device '%s' is not a KMS device.\n", name); |
| 2844 | return NULL; |
| 2845 | } |
| 2846 | |
| 2847 | /* If we're returning a device to use, we must have an open FD for |
| 2848 | * it. */ |
| 2849 | assert(b->drm.fd >= 0); |
| 2850 | |
| 2851 | return device; |
| 2852 | } |
| 2853 | |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2854 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 2855 | planes_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
| 2856 | uint32_t key, void *data) |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2857 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2858 | struct drm_backend *b = data; |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2859 | |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2860 | switch (key) { |
| 2861 | case KEY_C: |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 2862 | b->cursors_are_broken ^= true; |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2863 | break; |
| 2864 | case KEY_V: |
Daniel Stone | 87fab1c | 2019-06-17 11:13:20 +0100 | [diff] [blame] | 2865 | /* We don't support overlay-plane usage with legacy KMS. */ |
| 2866 | if (b->atomic_modeset) |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 2867 | b->sprites_are_broken ^= true; |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2868 | break; |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2869 | default: |
| 2870 | break; |
| 2871 | } |
Ander Conselvan de Oliveira | 180f42a | 2012-11-21 15:11:37 +0200 | [diff] [blame] | 2872 | } |
| 2873 | |
Kristian Høgsberg | 0eac34a | 2013-08-30 14:28:22 -0700 | [diff] [blame] | 2874 | #ifdef BUILD_VAAPI_RECORDER |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2875 | static void |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2876 | recorder_destroy(struct drm_output *output) |
| 2877 | { |
| 2878 | vaapi_recorder_destroy(output->recorder); |
| 2879 | output->recorder = NULL; |
| 2880 | |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 2881 | weston_output_disable_planes_decr(&output->base); |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2882 | |
| 2883 | wl_list_remove(&output->recorder_frame_listener.link); |
| 2884 | weston_log("[libva recorder] done\n"); |
| 2885 | } |
| 2886 | |
| 2887 | static void |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2888 | recorder_frame_notify(struct wl_listener *listener, void *data) |
| 2889 | { |
| 2890 | struct drm_output *output; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2891 | struct drm_backend *b; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2892 | int fd, ret; |
| 2893 | |
| 2894 | output = container_of(listener, struct drm_output, |
| 2895 | recorder_frame_listener); |
Armin Krezović | 545dba6 | 2016-08-05 15:54:18 +0200 | [diff] [blame] | 2896 | b = to_drm_backend(output->base.compositor); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2897 | |
| 2898 | if (!output->recorder) |
| 2899 | return; |
| 2900 | |
Daniel Stone | e2e8013 | 2018-01-16 15:37:33 +0000 | [diff] [blame] | 2901 | ret = drmPrimeHandleToFD(b->drm.fd, |
Daniel Stone | 8eece0c | 2016-11-17 17:54:00 +0000 | [diff] [blame] | 2902 | output->scanout_plane->state_cur->fb->handles[0], |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2903 | DRM_CLOEXEC, &fd); |
| 2904 | if (ret) { |
| 2905 | weston_log("[libva recorder] " |
| 2906 | "failed to create prime fd for front buffer\n"); |
| 2907 | return; |
| 2908 | } |
| 2909 | |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2910 | ret = vaapi_recorder_frame(output->recorder, fd, |
Daniel Stone | 8eece0c | 2016-11-17 17:54:00 +0000 | [diff] [blame] | 2911 | output->scanout_plane->state_cur->fb->strides[0]); |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2912 | if (ret < 0) { |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 2913 | weston_log("[libva recorder] aborted: %s\n", strerror(errno)); |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2914 | recorder_destroy(output); |
| 2915 | } |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | static void * |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2919 | create_recorder(struct drm_backend *b, int width, int height, |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2920 | const char *filename) |
| 2921 | { |
| 2922 | int fd; |
| 2923 | drm_magic_t magic; |
| 2924 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2925 | fd = open(b->drm.filename, O_RDWR | O_CLOEXEC); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2926 | if (fd < 0) |
| 2927 | return NULL; |
| 2928 | |
| 2929 | drmGetMagic(fd, &magic); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2930 | drmAuthMagic(b->drm.fd, magic); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2931 | |
| 2932 | return vaapi_recorder_create(fd, width, height, filename); |
| 2933 | } |
| 2934 | |
| 2935 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 2936 | recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
| 2937 | uint32_t key, void *data) |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2938 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2939 | struct drm_backend *b = data; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2940 | struct drm_output *output; |
| 2941 | int width, height; |
| 2942 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2943 | output = container_of(b->compositor->output_list.next, |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2944 | struct drm_output, base.link); |
| 2945 | |
| 2946 | if (!output->recorder) { |
Stefan Agner | 4a18f30 | 2019-10-20 18:25:42 +0200 | [diff] [blame] | 2947 | if (output->gbm_format != DRM_FORMAT_XRGB8888) { |
Ander Conselvan de Oliveira | 2ef1cd1 | 2014-05-06 16:49:06 +0300 | [diff] [blame] | 2948 | weston_log("failed to start vaapi recorder: " |
| 2949 | "output format not supported\n"); |
| 2950 | return; |
| 2951 | } |
| 2952 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2953 | width = output->base.current_mode->width; |
| 2954 | height = output->base.current_mode->height; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2955 | |
| 2956 | output->recorder = |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2957 | create_recorder(b, width, height, "capture.h264"); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2958 | if (!output->recorder) { |
| 2959 | weston_log("failed to create vaapi recorder\n"); |
| 2960 | return; |
| 2961 | } |
| 2962 | |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 2963 | weston_output_disable_planes_incr(&output->base); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2964 | |
| 2965 | output->recorder_frame_listener.notify = recorder_frame_notify; |
| 2966 | wl_signal_add(&output->base.frame_signal, |
| 2967 | &output->recorder_frame_listener); |
| 2968 | |
| 2969 | weston_output_schedule_repaint(&output->base); |
| 2970 | |
| 2971 | weston_log("[libva recorder] initialized\n"); |
| 2972 | } else { |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2973 | recorder_destroy(output); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | #else |
| 2977 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 2978 | recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
| 2979 | uint32_t key, void *data) |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2980 | { |
| 2981 | weston_log("Compiled without libva support\n"); |
| 2982 | } |
| 2983 | #endif |
| 2984 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 2985 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 2986 | static const struct weston_drm_output_api api = { |
| 2987 | drm_output_set_mode, |
| 2988 | drm_output_set_gbm_format, |
| 2989 | drm_output_set_seat, |
| 2990 | }; |
| 2991 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2992 | static struct drm_backend * |
| 2993 | drm_backend_create(struct weston_compositor *compositor, |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 2994 | struct weston_drm_backend_config *config) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2995 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2996 | struct drm_backend *b; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2997 | struct udev_device *drm_device; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2998 | struct wl_event_loop *loop; |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 2999 | const char *seat_id = default_seat; |
nerdopolis | b16c4ac | 2018-06-29 08:17:46 -0400 | [diff] [blame] | 3000 | const char *session_seat; |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 3001 | drmModeRes *res; |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 3002 | int ret; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 3003 | |
nerdopolis | b16c4ac | 2018-06-29 08:17:46 -0400 | [diff] [blame] | 3004 | session_seat = getenv("XDG_SEAT"); |
| 3005 | if (session_seat) |
| 3006 | seat_id = session_seat; |
| 3007 | |
| 3008 | if (config->seat_id) |
| 3009 | seat_id = config->seat_id; |
| 3010 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3011 | weston_log("initializing drm backend\n"); |
| 3012 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3013 | b = zalloc(sizeof *b); |
| 3014 | if (b == NULL) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3015 | return NULL; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3016 | |
Daniel Stone | 6020f47 | 2018-02-05 15:46:20 +0000 | [diff] [blame] | 3017 | b->state_invalid = true; |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 3018 | b->drm.fd = -1; |
| 3019 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3020 | b->compositor = compositor; |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3021 | b->use_pixman = config->use_pixman; |
Emmanuel Gil Peyrot | 11ae2a3 | 2017-03-07 13:27:54 +0000 | [diff] [blame] | 3022 | b->pageflip_timeout = config->pageflip_timeout; |
Pekka Paalanen | dee412d | 2018-04-23 11:44:58 +0200 | [diff] [blame] | 3023 | b->use_pixman_shadow = config->use_pixman_shadow; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 3024 | |
Leandro Ribeiro | 172afc2 | 2019-12-26 16:23:43 -0300 | [diff] [blame] | 3025 | b->debug = weston_compositor_add_log_scope(compositor, "drm-backend", |
| 3026 | "Debug messages from DRM/KMS backend\n", |
| 3027 | NULL, NULL, NULL); |
Daniel Stone | 1cbe1f9 | 2018-07-20 10:21:28 +0100 | [diff] [blame] | 3028 | |
Pekka Paalanen | 7da9a38 | 2017-08-30 11:29:49 +0300 | [diff] [blame] | 3029 | compositor->backend = &b->base; |
| 3030 | |
Stefan Agner | 0bfebeb | 2019-07-08 00:30:44 +0200 | [diff] [blame] | 3031 | if (parse_gbm_format(config->gbm_format, DRM_FORMAT_XRGB8888, &b->gbm_format) < 0) |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3032 | goto err_compositor; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 3033 | |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 3034 | /* Check if we run drm-backend using weston-launch */ |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3035 | compositor->launcher = weston_launcher_connect(compositor, config->tty, |
| 3036 | seat_id, true); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3037 | if (compositor->launcher == NULL) { |
Pekka Paalanen | a453f4d | 2017-10-31 10:19:48 +0200 | [diff] [blame] | 3038 | weston_log("fatal: drm backend should be run using " |
| 3039 | "weston-launch binary, or your system should " |
| 3040 | "provide the logind D-Bus API.\n"); |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 3041 | goto err_compositor; |
| 3042 | } |
| 3043 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3044 | b->udev = udev_new(); |
| 3045 | if (b->udev == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3046 | weston_log("failed to initialize udev context\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 3047 | goto err_launcher; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 3048 | } |
| 3049 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3050 | b->session_listener.notify = session_notify; |
| 3051 | wl_signal_add(&compositor->session_signal, &b->session_listener); |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 3052 | |
Pekka Paalanen | b45ed8b | 2017-03-28 18:04:27 +0300 | [diff] [blame] | 3053 | if (config->specific_device) |
| 3054 | drm_device = open_specific_drm_device(b, config->specific_device); |
| 3055 | else |
| 3056 | drm_device = find_primary_gpu(b, seat_id); |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 3057 | if (drm_device == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3058 | weston_log("no drm device found\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 3059 | goto err_udev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3060 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 3061 | |
Daniel Stone | efa504f | 2016-12-19 16:48:20 +0000 | [diff] [blame] | 3062 | if (init_kms_caps(b) < 0) { |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 3063 | weston_log("failed to initialize kms\n"); |
| 3064 | goto err_udev_dev; |
| 3065 | } |
| 3066 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3067 | if (b->use_pixman) { |
| 3068 | if (init_pixman(b) < 0) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 3069 | weston_log("failed to initialize pixman renderer\n"); |
| 3070 | goto err_udev_dev; |
| 3071 | } |
| 3072 | } else { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3073 | if (init_egl(b) < 0) { |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 3074 | weston_log("failed to initialize egl\n"); |
| 3075 | goto err_udev_dev; |
| 3076 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3077 | } |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 3078 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3079 | b->base.destroy = drm_destroy; |
Daniel Stone | eedf84c | 2017-02-10 18:06:04 +0000 | [diff] [blame] | 3080 | b->base.repaint_begin = drm_repaint_begin; |
| 3081 | b->base.repaint_flush = drm_repaint_flush; |
| 3082 | b->base.repaint_cancel = drm_repaint_cancel; |
Pekka Paalanen | c112f00 | 2017-08-28 16:27:20 +0300 | [diff] [blame] | 3083 | b->base.create_output = drm_output_create; |
Robert Beckett | 8d23ab7 | 2019-06-13 16:55:44 +0100 | [diff] [blame] | 3084 | b->base.device_changed = drm_device_changed; |
Marius Vlad | 81bada5 | 2019-11-11 00:27:17 +0200 | [diff] [blame] | 3085 | b->base.can_scanout_dmabuf = drm_can_scanout_dmabuf; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 3086 | |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame] | 3087 | weston_setup_vt_switch_bindings(compositor); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 3088 | |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 3089 | res = drmModeGetResources(b->drm.fd); |
| 3090 | if (!res) { |
| 3091 | weston_log("Failed to get drmModeRes\n"); |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 3092 | goto err_udev_dev; |
| 3093 | } |
| 3094 | |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 3095 | wl_list_init(&b->crtc_list); |
| 3096 | if (drm_backend_create_crtc_list(b, res) == -1) { |
| 3097 | weston_log("Failed to create CRTC list for DRM-backend\n"); |
| 3098 | goto err_create_crtc_list; |
| 3099 | } |
| 3100 | |
Daniel Stone | 085d2b9 | 2015-05-21 00:00:57 +0100 | [diff] [blame] | 3101 | wl_list_init(&b->plane_list); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3102 | create_sprites(b); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 3103 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3104 | if (udev_input_init(&b->input, |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 3105 | compositor, b->udev, seat_id, |
| 3106 | config->configure_device) < 0) { |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 3107 | weston_log("failed to create input devices\n"); |
| 3108 | goto err_sprite; |
| 3109 | } |
| 3110 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 3111 | wl_list_init(&b->writeback_connector_list); |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 3112 | if (drm_backend_discover_connectors(b, drm_device, res) < 0) { |
Pekka Paalanen | d2e6242 | 2017-09-08 15:48:07 +0300 | [diff] [blame] | 3113 | weston_log("Failed to create heads for %s\n", b->drm.filename); |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 3114 | goto err_udev_input; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3115 | } |
| 3116 | |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 3117 | drmModeFreeResources(res); |
| 3118 | |
Marius Vlad | e83e750 | 2019-10-29 17:29:37 +0200 | [diff] [blame] | 3119 | /* 'compute' faked zpos values in case HW doesn't expose any */ |
| 3120 | drm_backend_create_faked_zpos(b); |
| 3121 | |
Jason Ekstrand | 9fc7151 | 2014-04-02 19:53:46 -0500 | [diff] [blame] | 3122 | /* A this point we have some idea of whether or not we have a working |
| 3123 | * cursor plane. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3124 | if (!b->cursors_are_broken) |
| 3125 | compositor->capabilities |= WESTON_CAP_CURSOR_PLANE; |
Jason Ekstrand | 9fc7151 | 2014-04-02 19:53:46 -0500 | [diff] [blame] | 3126 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3127 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 3128 | b->drm_source = |
| 3129 | wl_event_loop_add_fd(loop, b->drm.fd, |
| 3130 | WL_EVENT_READABLE, on_drm_input, b); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3131 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3132 | b->udev_monitor = udev_monitor_new_from_netlink(b->udev, "udev"); |
| 3133 | if (b->udev_monitor == NULL) { |
Abdur Rehman | 4dca0e1 | 2017-01-01 19:46:35 +0500 | [diff] [blame] | 3134 | weston_log("failed to initialize udev monitor\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3135 | goto err_drm_source; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3136 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3137 | udev_monitor_filter_add_match_subsystem_devtype(b->udev_monitor, |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3138 | "drm", NULL); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3139 | b->udev_drm_source = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 3140 | wl_event_loop_add_fd(loop, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3141 | udev_monitor_get_fd(b->udev_monitor), |
| 3142 | WL_EVENT_READABLE, udev_drm_event, b); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3143 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3144 | if (udev_monitor_enable_receiving(b->udev_monitor) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3145 | weston_log("failed to enable udev-monitor receiving\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3146 | goto err_udev_monitor; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3147 | } |
| 3148 | |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3149 | udev_device_unref(drm_device); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3150 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3151 | weston_compositor_add_debug_binding(compositor, KEY_O, |
| 3152 | planes_binding, b); |
| 3153 | weston_compositor_add_debug_binding(compositor, KEY_C, |
| 3154 | planes_binding, b); |
| 3155 | weston_compositor_add_debug_binding(compositor, KEY_V, |
| 3156 | planes_binding, b); |
| 3157 | weston_compositor_add_debug_binding(compositor, KEY_Q, |
| 3158 | recorder_binding, b); |
| 3159 | weston_compositor_add_debug_binding(compositor, KEY_W, |
| 3160 | renderer_switch_binding, b); |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 3161 | |
Pekka Paalanen | e4d231e | 2014-06-12 15:12:48 +0300 | [diff] [blame] | 3162 | if (compositor->renderer->import_dmabuf) { |
| 3163 | if (linux_dmabuf_setup(compositor) < 0) |
| 3164 | weston_log("Error: initializing dmabuf " |
| 3165 | "support failed.\n"); |
Marius Vlad | ebd10e5 | 2019-11-16 19:22:48 +0200 | [diff] [blame] | 3166 | if (weston_direct_display_setup(compositor) < 0) |
| 3167 | weston_log("Error: initializing direct-display " |
| 3168 | "support failed.\n"); |
Pekka Paalanen | e4d231e | 2014-06-12 15:12:48 +0300 | [diff] [blame] | 3169 | } |
| 3170 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3171 | if (compositor->capabilities & WESTON_CAP_EXPLICIT_SYNC) { |
| 3172 | if (linux_explicit_synchronization_setup(compositor) < 0) |
| 3173 | weston_log("Error: initializing explicit " |
| 3174 | " synchronization support failed.\n"); |
| 3175 | } |
| 3176 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 3177 | if (b->atomic_modeset) |
| 3178 | if (weston_compositor_enable_content_protection(compositor) < 0) |
| 3179 | weston_log("Error: initializing content-protection " |
| 3180 | "support failed.\n"); |
| 3181 | |
Armin Krezović | 0836813 | 2016-09-30 14:11:05 +0200 | [diff] [blame] | 3182 | ret = weston_plugin_api_register(compositor, WESTON_DRM_OUTPUT_API_NAME, |
| 3183 | &api, sizeof(api)); |
| 3184 | |
| 3185 | if (ret < 0) { |
| 3186 | weston_log("Failed to register output API.\n"); |
| 3187 | goto err_udev_monitor; |
| 3188 | } |
| 3189 | |
Stefan Agner | 3654c67 | 2019-07-09 00:50:30 +0200 | [diff] [blame] | 3190 | ret = drm_backend_init_virtual_output_api(compositor); |
Tomohito Esaki | b1fb00d | 2018-01-31 17:50:48 +0900 | [diff] [blame] | 3191 | if (ret < 0) { |
| 3192 | weston_log("Failed to register virtual output API.\n"); |
| 3193 | goto err_udev_monitor; |
| 3194 | } |
| 3195 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3196 | return b; |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3197 | |
| 3198 | err_udev_monitor: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3199 | wl_event_source_remove(b->udev_drm_source); |
| 3200 | udev_monitor_unref(b->udev_monitor); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3201 | err_drm_source: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3202 | wl_event_source_remove(b->drm_source); |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 3203 | err_udev_input: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3204 | udev_input_destroy(&b->input); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 3205 | err_sprite: |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 3206 | #ifdef BUILD_DRM_GBM |
Emmanuel Gil Peyrot | b8347e3 | 2016-05-02 22:40:13 +0100 | [diff] [blame] | 3207 | if (b->gbm) |
| 3208 | gbm_device_destroy(b->gbm); |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 3209 | #endif |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3210 | destroy_sprites(b); |
Igor Matheus Andrade Torrente | 6354455 | 2020-10-13 11:25:20 -0300 | [diff] [blame] | 3211 | err_create_crtc_list: |
| 3212 | drmModeFreeResources(res); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3213 | err_udev_dev: |
| 3214 | udev_device_unref(drm_device); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3215 | err_udev: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3216 | udev_unref(b->udev); |
Marius Vlad | 5130a8c | 2020-07-30 14:47:32 +0300 | [diff] [blame] | 3217 | err_launcher: |
| 3218 | weston_launcher_destroy(compositor->launcher); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3219 | err_compositor: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3220 | weston_compositor_shutdown(compositor); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3221 | free(b); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 3222 | return NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 3223 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3224 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3225 | static void |
| 3226 | config_init_to_defaults(struct weston_drm_backend_config *config) |
| 3227 | { |
Pekka Paalanen | dee412d | 2018-04-23 11:44:58 +0200 | [diff] [blame] | 3228 | config->use_pixman_shadow = true; |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3231 | WL_EXPORT int |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 3232 | weston_backend_init(struct weston_compositor *compositor, |
| 3233 | struct weston_backend_config *config_base) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3234 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3235 | struct drm_backend *b; |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3236 | struct weston_drm_backend_config config = {{ 0, }}; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3237 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3238 | if (config_base == NULL || |
| 3239 | config_base->struct_version != WESTON_DRM_BACKEND_CONFIG_VERSION || |
| 3240 | config_base->struct_size > sizeof(struct weston_drm_backend_config)) { |
| 3241 | weston_log("drm backend config structure is invalid\n"); |
| 3242 | return -1; |
| 3243 | } |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 3244 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3245 | config_init_to_defaults(&config); |
| 3246 | memcpy(&config, config_base, config_base->struct_size); |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 3247 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3248 | b = drm_backend_create(compositor, &config); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3249 | if (b == NULL) |
| 3250 | return -1; |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 3251 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 3252 | return 0; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3253 | } |