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