Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008-2011 Kristian Høgsberg |
| 3 | * Copyright © 2011 Intel Corporation |
| 4 | * Copyright © 2017, 2018 Collabora, Ltd. |
| 5 | * Copyright © 2017, 2018 General Electric Company |
| 6 | * Copyright (c) 2018 DisplayLink (UK) Ltd. |
| 7 | * |
| 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: |
| 15 | * |
| 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. |
| 28 | */ |
| 29 | |
| 30 | #include "config.h" |
| 31 | |
| 32 | #include <errno.h> |
| 33 | #include <stdint.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <ctype.h> |
| 36 | #include <string.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <unistd.h> |
| 39 | #include <linux/input.h> |
| 40 | #include <linux/vt.h> |
| 41 | #include <assert.h> |
| 42 | #include <sys/mman.h> |
| 43 | #include <time.h> |
| 44 | |
| 45 | |
| 46 | #include <xf86drm.h> |
| 47 | #include <xf86drmMode.h> |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 48 | |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 49 | #ifdef BUILD_DRM_GBM |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 50 | #include <gbm.h> |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 51 | #endif |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 52 | #include <libudev.h> |
| 53 | |
| 54 | #include <libweston/libweston.h> |
| 55 | #include <libweston/backend-drm.h> |
Marius Vlad | c901e89 | 2019-06-21 22:49:18 +0300 | [diff] [blame] | 56 | #include <libweston/weston-log.h> |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 57 | #include "shared/helpers.h" |
Pekka Paalanen | 4b301fe | 2021-02-04 17:39:45 +0200 | [diff] [blame] | 58 | #include "shared/weston-drm-fourcc.h" |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 59 | #include "libinput-seat.h" |
Marius Vlad | e41c1bf | 2019-07-16 23:11:25 +0300 | [diff] [blame] | 60 | #include "backend.h" |
Marius Vlad | a72e371 | 2019-07-10 13:46:39 +0300 | [diff] [blame] | 61 | #include "libweston-internal.h" |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 62 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 63 | #ifndef GBM_BO_USE_CURSOR |
| 64 | #define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64 |
| 65 | #endif |
| 66 | |
| 67 | #ifndef GBM_BO_USE_LINEAR |
| 68 | #define GBM_BO_USE_LINEAR (1 << 4) |
| 69 | #endif |
| 70 | |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 71 | #ifndef DRM_PLANE_ZPOS_INVALID_PLANE |
| 72 | #define DRM_PLANE_ZPOS_INVALID_PLANE 0xffffffffffffffffULL |
| 73 | #endif |
| 74 | |
limin.tian | 85cd246 | 2024-08-12 08:04:12 +0000 | [diff] [blame^] | 75 | #ifndef DEFAULT_OSD_PLANE_ZPOS |
| 76 | #define DEFAULT_OSD_PLANE_ZPOS 65 |
| 77 | #endif |
| 78 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 79 | /** |
| 80 | * A small wrapper to print information into the 'drm-backend' debug scope. |
| 81 | * |
| 82 | * The following conventions are used to print variables: |
| 83 | * |
| 84 | * - fixed uint32_t values, including Weston object IDs such as weston_output |
| 85 | * IDs, DRM object IDs such as CRTCs or properties, and GBM/DRM formats: |
| 86 | * "%lu (0x%lx)" (unsigned long) value, (unsigned long) value |
| 87 | * |
| 88 | * - fixed uint64_t values, such as DRM property values (including object IDs |
| 89 | * when used as a value): |
| 90 | * "%llu (0x%llx)" (unsigned long long) value, (unsigned long long) value |
| 91 | * |
| 92 | * - non-fixed-width signed int: |
| 93 | * "%d" value |
| 94 | * |
| 95 | * - non-fixed-width unsigned int: |
| 96 | * "%u (0x%x)" value, value |
| 97 | * |
| 98 | * - non-fixed-width unsigned long: |
| 99 | * "%lu (0x%lx)" value, value |
| 100 | * |
| 101 | * Either the integer or hexadecimal forms may be omitted if it is known that |
| 102 | * one representation is not useful (e.g. width/height in hex are rarely what |
| 103 | * you want). |
| 104 | * |
| 105 | * This is to avoid implicit widening or narrowing when we use fixed-size |
| 106 | * types: uint32_t can be resolved by either unsigned int or unsigned long |
| 107 | * on a 32-bit system but only unsigned int on a 64-bit system, with uint64_t |
| 108 | * being unsigned long long on a 32-bit system and unsigned long on a 64-bit |
| 109 | * system. To avoid confusing side effects, we explicitly cast to the widest |
| 110 | * possible type and use a matching format specifier. |
| 111 | */ |
| 112 | #define drm_debug(b, ...) \ |
| 113 | weston_log_scope_printf((b)->debug, __VA_ARGS__) |
| 114 | |
| 115 | #define MAX_CLONED_CONNECTORS 4 |
| 116 | |
Stefan Agner | 723c6a1 | 2019-12-09 13:06:36 +0100 | [diff] [blame] | 117 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 118 | /** |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 119 | * Represents the values of an enum-type KMS property |
| 120 | */ |
| 121 | struct drm_property_enum_info { |
| 122 | const char *name; /**< name as string (static, not freed) */ |
| 123 | bool valid; /**< true if value is supported; ignore if false */ |
| 124 | uint64_t value; /**< raw value */ |
| 125 | }; |
| 126 | |
| 127 | /** |
| 128 | * Holds information on a DRM property, including its ID and the enum |
| 129 | * values it holds. |
| 130 | * |
| 131 | * DRM properties are allocated dynamically, and maintained as DRM objects |
| 132 | * within the normal object ID space; they thus do not have a stable ID |
| 133 | * to refer to. This includes enum values, which must be referred to by |
| 134 | * integer values, but these are not stable. |
| 135 | * |
| 136 | * drm_property_info allows a cache to be maintained where Weston can use |
| 137 | * enum values internally to refer to properties, with the mapping to DRM |
| 138 | * ID values being maintained internally. |
| 139 | */ |
| 140 | struct drm_property_info { |
| 141 | const char *name; /**< name as string (static, not freed) */ |
| 142 | uint32_t prop_id; /**< KMS property object ID */ |
Marius Vlad | 1accffe | 2019-11-01 12:00:09 +0200 | [diff] [blame] | 143 | uint32_t flags; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 144 | unsigned int num_enum_values; /**< number of enum values */ |
| 145 | struct drm_property_enum_info *enum_values; /**< array of enum values */ |
Marius Vlad | 1accffe | 2019-11-01 12:00:09 +0200 | [diff] [blame] | 146 | unsigned int num_range_values; |
| 147 | uint64_t range_values[2]; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /** |
| 151 | * List of properties attached to DRM planes |
| 152 | */ |
| 153 | enum wdrm_plane_property { |
| 154 | WDRM_PLANE_TYPE = 0, |
| 155 | WDRM_PLANE_SRC_X, |
| 156 | WDRM_PLANE_SRC_Y, |
| 157 | WDRM_PLANE_SRC_W, |
| 158 | WDRM_PLANE_SRC_H, |
| 159 | WDRM_PLANE_CRTC_X, |
| 160 | WDRM_PLANE_CRTC_Y, |
| 161 | WDRM_PLANE_CRTC_W, |
| 162 | WDRM_PLANE_CRTC_H, |
| 163 | WDRM_PLANE_FB_ID, |
| 164 | WDRM_PLANE_CRTC_ID, |
| 165 | WDRM_PLANE_IN_FORMATS, |
| 166 | WDRM_PLANE_IN_FENCE_FD, |
| 167 | WDRM_PLANE_FB_DAMAGE_CLIPS, |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 168 | WDRM_PLANE_ZPOS, |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 169 | WDRM_PLANE__COUNT |
| 170 | }; |
| 171 | |
| 172 | /** |
| 173 | * Possible values for the WDRM_PLANE_TYPE property. |
| 174 | */ |
| 175 | enum wdrm_plane_type { |
| 176 | WDRM_PLANE_TYPE_PRIMARY = 0, |
| 177 | WDRM_PLANE_TYPE_CURSOR, |
| 178 | WDRM_PLANE_TYPE_OVERLAY, |
| 179 | WDRM_PLANE_TYPE__COUNT |
| 180 | }; |
| 181 | |
| 182 | /** |
| 183 | * List of properties attached to a DRM connector |
| 184 | */ |
| 185 | enum wdrm_connector_property { |
| 186 | WDRM_CONNECTOR_EDID = 0, |
| 187 | WDRM_CONNECTOR_DPMS, |
| 188 | WDRM_CONNECTOR_CRTC_ID, |
| 189 | WDRM_CONNECTOR_NON_DESKTOP, |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 190 | WDRM_CONNECTOR_CONTENT_PROTECTION, |
| 191 | WDRM_CONNECTOR_HDCP_CONTENT_TYPE, |
Lucas Stach | 72e7a1e | 2019-11-25 23:31:57 +0000 | [diff] [blame] | 192 | WDRM_CONNECTOR_PANEL_ORIENTATION, |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 193 | WDRM_CONNECTOR__COUNT |
| 194 | }; |
| 195 | |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 196 | enum wdrm_content_protection_state { |
| 197 | WDRM_CONTENT_PROTECTION_UNDESIRED = 0, |
| 198 | WDRM_CONTENT_PROTECTION_DESIRED, |
| 199 | WDRM_CONTENT_PROTECTION_ENABLED, |
| 200 | WDRM_CONTENT_PROTECTION__COUNT |
| 201 | }; |
| 202 | |
| 203 | enum wdrm_hdcp_content_type { |
| 204 | WDRM_HDCP_CONTENT_TYPE0 = 0, |
| 205 | WDRM_HDCP_CONTENT_TYPE1, |
| 206 | WDRM_HDCP_CONTENT_TYPE__COUNT |
| 207 | }; |
| 208 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 209 | enum wdrm_dpms_state { |
| 210 | WDRM_DPMS_STATE_OFF = 0, |
| 211 | WDRM_DPMS_STATE_ON, |
| 212 | WDRM_DPMS_STATE_STANDBY, /* unused */ |
| 213 | WDRM_DPMS_STATE_SUSPEND, /* unused */ |
| 214 | WDRM_DPMS_STATE__COUNT |
| 215 | }; |
| 216 | |
Lucas Stach | 72e7a1e | 2019-11-25 23:31:57 +0000 | [diff] [blame] | 217 | enum wdrm_panel_orientation { |
| 218 | WDRM_PANEL_ORIENTATION_NORMAL = 0, |
| 219 | WDRM_PANEL_ORIENTATION_UPSIDE_DOWN, |
| 220 | WDRM_PANEL_ORIENTATION_LEFT_SIDE_UP, |
| 221 | WDRM_PANEL_ORIENTATION_RIGHT_SIDE_UP, |
| 222 | WDRM_PANEL_ORIENTATION__COUNT |
| 223 | }; |
| 224 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 225 | /** |
| 226 | * List of properties attached to DRM CRTCs |
| 227 | */ |
| 228 | enum wdrm_crtc_property { |
| 229 | WDRM_CRTC_MODE_ID = 0, |
| 230 | WDRM_CRTC_ACTIVE, |
| 231 | WDRM_CRTC__COUNT |
| 232 | }; |
| 233 | |
Leandro Ribeiro | 0a7034c | 2021-09-13 14:52:53 -0300 | [diff] [blame] | 234 | /** |
| 235 | * Reasons why placing a view on a plane failed. Needed by the dma-buf feedback. |
| 236 | */ |
| 237 | enum try_view_on_plane_failure_reasons { |
| 238 | FAILURE_REASONS_NONE = 0, |
| 239 | FAILURE_REASONS_FORCE_RENDERER = (1 << 0), |
| 240 | FAILURE_REASONS_FB_FORMAT_INCOMPATIBLE = (1 << 1), |
| 241 | FAILURE_REASONS_DMABUF_MODIFIER_INVALID = (1 << 2), |
| 242 | FAILURE_REASONS_ADD_FB_FAILED = (1 << 3), |
| 243 | }; |
| 244 | |
Leandro Ribeiro | 5429302 | 2021-10-12 14:48:36 -0300 | [diff] [blame] | 245 | /** |
| 246 | * We use this to keep track of actions we need to do with the dma-buf feedback |
| 247 | * in order to keep it up-to-date with the info we get from the DRM-backend. |
| 248 | */ |
| 249 | enum actions_needed_dmabuf_feedback { |
| 250 | ACTION_NEEDED_NONE = 0, |
| 251 | ACTION_NEEDED_ADD_SCANOUT_TRANCHE = (1 << 0), |
| 252 | ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE = (1 << 1), |
| 253 | }; |
| 254 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 255 | struct drm_backend { |
| 256 | struct weston_backend base; |
| 257 | struct weston_compositor *compositor; |
| 258 | |
| 259 | struct udev *udev; |
| 260 | struct wl_event_source *drm_source; |
| 261 | |
| 262 | struct udev_monitor *udev_monitor; |
| 263 | struct wl_event_source *udev_drm_source; |
| 264 | |
| 265 | struct { |
| 266 | int id; |
| 267 | int fd; |
| 268 | char *filename; |
| 269 | dev_t devnum; |
| 270 | } drm; |
| 271 | struct gbm_device *gbm; |
| 272 | struct wl_listener session_listener; |
| 273 | uint32_t gbm_format; |
| 274 | |
| 275 | /* we need these parameters in order to not fail drmModeAddFB2() |
| 276 | * due to out of bounds dimensions, and then mistakenly set |
| 277 | * sprites_are_broken: |
| 278 | */ |
| 279 | int min_width, max_width; |
| 280 | int min_height, max_height; |
| 281 | |
| 282 | struct wl_list plane_list; |
Daniel Stone | 57d609a | 2021-11-16 18:56:09 +0000 | [diff] [blame] | 283 | uint32_t next_plane_idx; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 284 | |
| 285 | void *repaint_data; |
| 286 | |
| 287 | bool state_invalid; |
| 288 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 289 | /* drm_crtc::link */ |
| 290 | struct wl_list crtc_list; |
| 291 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 292 | /* drm_writeback::link */ |
| 293 | struct wl_list writeback_connector_list; |
| 294 | |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 295 | bool sprites_are_broken; |
| 296 | bool cursors_are_broken; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 297 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 298 | bool atomic_modeset; |
| 299 | |
| 300 | bool use_pixman; |
| 301 | bool use_pixman_shadow; |
| 302 | |
| 303 | struct udev_input input; |
| 304 | |
| 305 | int32_t cursor_width; |
| 306 | int32_t cursor_height; |
| 307 | |
| 308 | uint32_t pageflip_timeout; |
| 309 | |
| 310 | bool shutting_down; |
| 311 | |
| 312 | bool aspect_ratio_supported; |
| 313 | |
| 314 | bool fb_modifiers; |
| 315 | |
| 316 | struct weston_log_scope *debug; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 317 | |
| 318 | #ifdef MESON_DRM_FIX_UI_SIZE |
| 319 | /** Set the logic window size |
| 320 | * the current_mode 's w/h will not equal real display mode size any more |
| 321 | * after enable fixed ui size. */ |
| 322 | struct weston_size fixed_ui_size; |
| 323 | #endif |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 324 | int vdin_detect_fd; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 325 | bool allow_modeset; |
leng.fang | 9cf09e2 | 2024-07-17 20:01:11 +0800 | [diff] [blame] | 326 | int display_enable; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | struct drm_mode { |
| 330 | struct weston_mode base; |
| 331 | drmModeModeInfo mode_info; |
| 332 | uint32_t blob_id; |
| 333 | }; |
| 334 | |
| 335 | enum drm_fb_type { |
| 336 | BUFFER_INVALID = 0, /**< never used */ |
| 337 | BUFFER_CLIENT, /**< directly sourced from client */ |
| 338 | BUFFER_DMABUF, /**< imported from linux_dmabuf client */ |
| 339 | BUFFER_PIXMAN_DUMB, /**< internal Pixman rendering */ |
| 340 | BUFFER_GBM_SURFACE, /**< internal EGL rendering */ |
| 341 | BUFFER_CURSOR, /**< internal cursor buffer */ |
| 342 | }; |
| 343 | |
| 344 | struct drm_fb { |
| 345 | enum drm_fb_type type; |
| 346 | |
| 347 | int refcnt; |
| 348 | |
| 349 | uint32_t fb_id, size; |
| 350 | uint32_t handles[4]; |
| 351 | uint32_t strides[4]; |
| 352 | uint32_t offsets[4]; |
| 353 | int num_planes; |
| 354 | const struct pixel_format_info *format; |
| 355 | uint64_t modifier; |
| 356 | int width, height; |
| 357 | int fd; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 358 | |
Daniel Stone | 57d609a | 2021-11-16 18:56:09 +0000 | [diff] [blame] | 359 | uint32_t plane_mask; |
| 360 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 361 | /* Used by gbm fbs */ |
| 362 | struct gbm_bo *bo; |
| 363 | struct gbm_surface *gbm_surface; |
| 364 | |
| 365 | /* Used by dumb fbs */ |
| 366 | void *map; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 367 | struct drm_plane *plane; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 368 | }; |
| 369 | |
Daniel Stone | 7d27df4 | 2021-11-18 16:01:03 +0000 | [diff] [blame] | 370 | struct drm_buffer_fb { |
| 371 | struct drm_fb *fb; |
| 372 | enum try_view_on_plane_failure_reasons failure_reasons; |
| 373 | struct wl_listener buffer_destroy_listener; |
| 374 | }; |
| 375 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 376 | struct drm_edid { |
| 377 | char eisa_id[13]; |
| 378 | char monitor_name[13]; |
| 379 | char pnp_id[5]; |
| 380 | char serial_number[13]; |
| 381 | }; |
| 382 | |
| 383 | /** |
| 384 | * Pending state holds one or more drm_output_state structures, collected from |
| 385 | * performing repaint. This pending state is transient, and only lives between |
| 386 | * beginning a repaint group and flushing the results: after flush, each |
| 387 | * output state will complete and be retired separately. |
| 388 | */ |
| 389 | struct drm_pending_state { |
| 390 | struct drm_backend *backend; |
| 391 | struct wl_list output_list; |
| 392 | }; |
| 393 | |
| 394 | /* |
| 395 | * Output state holds the dynamic state for one Weston output, i.e. a KMS CRTC, |
| 396 | * plus >= 1 each of encoder/connector/plane. Since everything but the planes |
| 397 | * is currently statically assigned per-output, we mainly use this to track |
| 398 | * plane state. |
| 399 | * |
| 400 | * pending_state is set when the output state is owned by a pending_state, |
| 401 | * i.e. when it is being constructed and has not yet been applied. When the |
| 402 | * output state has been applied, the owning pending_state is freed. |
| 403 | */ |
| 404 | struct drm_output_state { |
| 405 | struct drm_pending_state *pending_state; |
| 406 | struct drm_output *output; |
| 407 | struct wl_list link; |
| 408 | enum dpms_enum dpms; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 409 | enum weston_hdcp_protection protection; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 410 | struct wl_list plane_list; |
| 411 | }; |
| 412 | |
| 413 | /** |
Marius Vlad | 2538aac | 2019-10-14 11:05:30 +0300 | [diff] [blame] | 414 | * An instance of this class is created each time we believe we have a plane |
Maxime Roussin-Bélanger | 35e3450 | 2020-12-17 17:08:56 -0500 | [diff] [blame] | 415 | * suitable to be used by a view as a direct scan-out. The list is initialized |
Marius Vlad | 2538aac | 2019-10-14 11:05:30 +0300 | [diff] [blame] | 416 | * and populated locally. |
| 417 | */ |
| 418 | struct drm_plane_zpos { |
| 419 | struct drm_plane *plane; |
| 420 | struct wl_list link; /**< :candidate_plane_zpos_list */ |
| 421 | }; |
| 422 | |
| 423 | /** |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 424 | * Plane state holds the dynamic state for a plane: where it is positioned, |
| 425 | * and which buffer it is currently displaying. |
| 426 | * |
| 427 | * The plane state is owned by an output state, except when setting an initial |
| 428 | * state. See drm_output_state for notes on state object lifetime. |
| 429 | */ |
| 430 | struct drm_plane_state { |
| 431 | struct drm_plane *plane; |
| 432 | struct drm_output *output; |
| 433 | struct drm_output_state *output_state; |
| 434 | |
| 435 | struct drm_fb *fb; |
Daniel Stone | 2ecc38b | 2021-11-18 15:33:17 +0000 | [diff] [blame] | 436 | struct { |
| 437 | struct weston_buffer_reference buffer; |
| 438 | struct weston_buffer_release_reference release; |
| 439 | } fb_ref; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 440 | |
| 441 | struct weston_view *ev; /**< maintained for drm_assign_planes only */ |
| 442 | |
| 443 | int32_t src_x, src_y; |
| 444 | uint32_t src_w, src_h; |
| 445 | int32_t dest_x, dest_y; |
| 446 | uint32_t dest_w, dest_h; |
| 447 | |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 448 | uint64_t zpos; |
| 449 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 450 | bool complete; |
| 451 | |
| 452 | /* We don't own the fd, so we shouldn't close it */ |
| 453 | int in_fence_fd; |
| 454 | |
Scott Anderson | 15c603c | 2020-06-02 17:39:43 +1200 | [diff] [blame] | 455 | uint32_t damage_blob_id; /* damage to kernel */ |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 456 | |
| 457 | struct wl_list link; /* drm_output_state::plane_list */ |
| 458 | }; |
| 459 | |
| 460 | /** |
| 461 | * A plane represents one buffer, positioned within a CRTC, and stacked |
| 462 | * relative to other planes on the same CRTC. |
| 463 | * |
| 464 | * Each CRTC has a 'primary plane', which use used to display the classic |
| 465 | * framebuffer contents, as accessed through the legacy drmModeSetCrtc |
| 466 | * call (which combines setting the CRTC's actual physical mode, and the |
| 467 | * properties of the primary plane). |
| 468 | * |
| 469 | * The cursor plane also has its own alternate legacy API. |
| 470 | * |
| 471 | * Other planes are used opportunistically to display content we do not |
| 472 | * wish to blit into the primary plane. These non-primary/cursor planes |
| 473 | * are referred to as 'sprites'. |
| 474 | */ |
| 475 | struct drm_plane { |
| 476 | struct weston_plane base; |
| 477 | |
| 478 | struct drm_backend *backend; |
| 479 | |
| 480 | enum wdrm_plane_type type; |
| 481 | |
| 482 | uint32_t possible_crtcs; |
| 483 | uint32_t plane_id; |
Daniel Stone | 57d609a | 2021-11-16 18:56:09 +0000 | [diff] [blame] | 484 | uint32_t plane_idx; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 485 | |
| 486 | struct drm_property_info props[WDRM_PLANE__COUNT]; |
| 487 | |
| 488 | /* The last state submitted to the kernel for this plane. */ |
| 489 | struct drm_plane_state *state_cur; |
| 490 | |
Marius Vlad | cdd6fa2 | 2019-08-29 20:42:00 +0300 | [diff] [blame] | 491 | uint64_t zpos_min; |
| 492 | uint64_t zpos_max; |
| 493 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 494 | struct wl_list link; |
| 495 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 496 | bool is_video_plane; |
| 497 | int video_plane; |
| 498 | bool keep_last_frame; |
| 499 | uint32_t last_fb_id; |
| 500 | struct drm_crtc *crtc; |
| 501 | |
Scott Anderson | 7466309 | 2021-02-01 15:46:33 -0300 | [diff] [blame] | 502 | struct weston_drm_format_array formats; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 503 | }; |
| 504 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 505 | struct drm_connector { |
| 506 | struct drm_backend *backend; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 507 | |
| 508 | drmModeConnector *conn; |
| 509 | uint32_t connector_id; |
| 510 | |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 511 | drmModeObjectProperties *props_drm; |
| 512 | |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 513 | /* Holds the properties for the connector */ |
| 514 | struct drm_property_info props[WDRM_CONNECTOR__COUNT]; |
| 515 | }; |
| 516 | |
Leandro Ribeiro | 96bef05 | 2020-09-09 15:23:49 -0300 | [diff] [blame] | 517 | struct drm_writeback { |
| 518 | /* drm_backend::writeback_connector_list */ |
| 519 | struct wl_list link; |
| 520 | |
| 521 | struct drm_backend *backend; |
| 522 | struct drm_connector connector; |
| 523 | }; |
| 524 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 525 | struct drm_head { |
| 526 | struct weston_head base; |
| 527 | struct drm_backend *backend; |
Leandro Ribeiro | e636990 | 2020-06-17 11:09:47 -0300 | [diff] [blame] | 528 | struct drm_connector connector; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 529 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 530 | struct drm_edid edid; |
| 531 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 532 | struct backlight *backlight; |
| 533 | |
| 534 | drmModeModeInfo inherited_mode; /**< Original mode on the connector */ |
| 535 | uint32_t inherited_crtc_id; /**< Original CRTC assignment */ |
| 536 | }; |
| 537 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 538 | struct drm_crtc { |
| 539 | /* drm_backend::crtc_list */ |
| 540 | struct wl_list link; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 541 | struct drm_backend *backend; |
| 542 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 543 | /* The output driven by the CRTC */ |
| 544 | struct drm_output *output; |
| 545 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 546 | uint32_t crtc_id; /* object ID to pass to DRM functions */ |
| 547 | int pipe; /* index of CRTC in resource array / bitmasks */ |
| 548 | |
| 549 | /* Holds the properties for the CRTC */ |
| 550 | struct drm_property_info props_crtc[WDRM_CRTC__COUNT]; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 551 | bool output_change; |
| 552 | struct drm_output *disable_output; |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | struct drm_output { |
| 556 | struct weston_output base; |
| 557 | struct drm_backend *backend; |
| 558 | struct drm_crtc *crtc; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 559 | |
Emmanuel Gil Peyrot | 1b3ad09 | 2019-12-09 02:50:55 +0100 | [diff] [blame] | 560 | bool page_flip_pending; |
| 561 | bool atomic_complete_pending; |
| 562 | bool destroy_pending; |
| 563 | bool disable_pending; |
| 564 | bool dpms_off_pending; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 565 | |
Stefan Agner | 974390a | 2019-07-08 00:42:05 +0200 | [diff] [blame] | 566 | uint32_t gbm_cursor_handle[2]; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 567 | struct drm_fb *gbm_cursor_fb[2]; |
| 568 | struct drm_plane *cursor_plane; |
| 569 | struct weston_view *cursor_view; |
Alexandros Frantzis | 10937fe | 2021-06-14 13:09:44 +0300 | [diff] [blame] | 570 | struct wl_listener cursor_view_destroy_listener; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 571 | int current_cursor; |
| 572 | |
| 573 | struct gbm_surface *gbm_surface; |
| 574 | uint32_t gbm_format; |
| 575 | uint32_t gbm_bo_flags; |
| 576 | |
| 577 | /* Plane being displayed directly on the CRTC */ |
| 578 | struct drm_plane *scanout_plane; |
| 579 | |
| 580 | /* The last state submitted to the kernel for this CRTC. */ |
| 581 | struct drm_output_state *state_cur; |
| 582 | /* The previously-submitted state, where the hardware has not |
| 583 | * yet acknowledged completion of state_cur. */ |
| 584 | struct drm_output_state *state_last; |
| 585 | |
| 586 | struct drm_fb *dumb[2]; |
| 587 | pixman_image_t *image[2]; |
| 588 | int current_image; |
| 589 | pixman_region32_t previous_damage; |
| 590 | |
| 591 | struct vaapi_recorder *recorder; |
| 592 | struct wl_listener recorder_frame_listener; |
| 593 | |
| 594 | struct wl_event_source *pageflip_timer; |
| 595 | |
| 596 | bool virtual; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 597 | int video_plane_count; |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 598 | |
| 599 | submit_frame_cb virtual_submit_frame; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 600 | |
| 601 | #ifdef MESON_DRM_FIX_UI_SIZE |
| 602 | bool current_mode_need_restore; |
| 603 | |
| 604 | /* the real display mode size will saved out of the current mode */ |
| 605 | struct weston_size display_size; |
| 606 | #endif |
| 607 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 608 | }; |
| 609 | |
| 610 | static inline struct drm_head * |
| 611 | to_drm_head(struct weston_head *base) |
| 612 | { |
| 613 | return container_of(base, struct drm_head, base); |
| 614 | } |
| 615 | |
| 616 | static inline struct drm_output * |
| 617 | to_drm_output(struct weston_output *base) |
| 618 | { |
| 619 | return container_of(base, struct drm_output, base); |
| 620 | } |
| 621 | |
| 622 | static inline struct drm_backend * |
| 623 | to_drm_backend(struct weston_compositor *base) |
| 624 | { |
| 625 | return container_of(base->backend, struct drm_backend, base); |
| 626 | } |
| 627 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 628 | static inline struct drm_plane * |
| 629 | to_drm_plane(struct weston_plane *base) |
| 630 | { |
| 631 | return container_of(base, struct drm_plane, base); |
| 632 | } |
| 633 | |
Daniel Stone | dd1bc50 | 2019-06-17 12:13:46 +0100 | [diff] [blame] | 634 | static inline struct drm_mode * |
| 635 | to_drm_mode(struct weston_mode *base) |
| 636 | { |
| 637 | return container_of(base, struct drm_mode, base); |
| 638 | } |
Daniel Stone | fbe6c1d | 2019-06-17 16:04:26 +0100 | [diff] [blame] | 639 | |
Marius Vlad | 3dea57a | 2019-09-27 20:45:41 +0300 | [diff] [blame] | 640 | static inline const char * |
| 641 | drm_output_get_plane_type_name(struct drm_plane *p) |
| 642 | { |
| 643 | switch (p->type) { |
| 644 | case WDRM_PLANE_TYPE_PRIMARY: |
| 645 | return "primary"; |
| 646 | case WDRM_PLANE_TYPE_CURSOR: |
| 647 | return "cursor"; |
| 648 | case WDRM_PLANE_TYPE_OVERLAY: |
| 649 | return "overlay"; |
| 650 | default: |
| 651 | assert(0); |
| 652 | break; |
| 653 | } |
| 654 | } |
| 655 | |
Leandro Ribeiro | b00d1a2 | 2020-08-13 14:12:28 -0300 | [diff] [blame] | 656 | struct drm_crtc * |
| 657 | drm_crtc_find(struct drm_backend *b, uint32_t crtc_id); |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 658 | |
| 659 | struct drm_head * |
| 660 | drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id); |
| 661 | |
Daniel Stone | 7580b3c | 2019-06-18 11:16:53 +0100 | [diff] [blame] | 662 | static inline bool |
| 663 | drm_view_transform_supported(struct weston_view *ev, struct weston_output *output) |
| 664 | { |
| 665 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
| 666 | |
| 667 | /* This will incorrectly disallow cases where the combination of |
| 668 | * buffer and view transformations match the output transform. |
| 669 | * Fixing this requires a full analysis of the transformation |
| 670 | * chain. */ |
| 671 | if (ev->transform.enabled && |
| 672 | ev->transform.matrix.type >= WESTON_MATRIX_TRANSFORM_ROTATE) |
| 673 | return false; |
| 674 | |
| 675 | if (viewport->buffer.transform != output->transform) |
| 676 | return false; |
| 677 | |
| 678 | return true; |
| 679 | } |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 680 | struct weston_plane * |
| 681 | drm_get_weston_plane(struct drm_backend *backend, struct drm_plane* drm_plane); |
Daniel Stone | 7580b3c | 2019-06-18 11:16:53 +0100 | [diff] [blame] | 682 | |
Daniel Stone | fbe6c1d | 2019-06-17 16:04:26 +0100 | [diff] [blame] | 683 | int |
| 684 | drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode); |
| 685 | |
| 686 | struct drm_mode * |
| 687 | drm_output_choose_mode(struct drm_output *output, |
| 688 | struct weston_mode *target_mode); |
| 689 | void |
Leandro Ribeiro | 702fbf7 | 2020-08-18 17:35:05 -0300 | [diff] [blame] | 690 | update_head_from_connector(struct drm_head *head); |
Daniel Stone | fbe6c1d | 2019-06-17 16:04:26 +0100 | [diff] [blame] | 691 | |
| 692 | void |
| 693 | drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list); |
| 694 | |
| 695 | void |
| 696 | drm_output_print_modes(struct drm_output *output); |
| 697 | |
| 698 | int |
| 699 | drm_output_set_mode(struct weston_output *base, |
| 700 | enum weston_drm_backend_output_mode mode, |
| 701 | const char *modeline); |
| 702 | |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 703 | void |
| 704 | drm_property_info_populate(struct drm_backend *b, |
| 705 | const struct drm_property_info *src, |
| 706 | struct drm_property_info *info, |
| 707 | unsigned int num_infos, |
| 708 | drmModeObjectProperties *props); |
Daniel Stone | fbe6c1d | 2019-06-17 16:04:26 +0100 | [diff] [blame] | 709 | uint64_t |
| 710 | drm_property_get_value(struct drm_property_info *info, |
| 711 | const drmModeObjectProperties *props, |
| 712 | uint64_t def); |
Marius Vlad | 1accffe | 2019-11-01 12:00:09 +0200 | [diff] [blame] | 713 | uint64_t * |
| 714 | drm_property_get_range_values(struct drm_property_info *info, |
| 715 | const drmModeObjectProperties *props); |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 716 | int |
| 717 | drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane, |
Stefan Agner | 465ab2c | 2020-06-17 23:36:44 +0200 | [diff] [blame] | 718 | const drmModeObjectProperties *props, |
| 719 | const bool use_modifiers); |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 720 | void |
| 721 | drm_property_info_free(struct drm_property_info *info, int num_props); |
| 722 | |
| 723 | extern struct drm_property_enum_info plane_type_enums[]; |
| 724 | extern const struct drm_property_info plane_props[]; |
| 725 | extern struct drm_property_enum_info dpms_state_enums[]; |
Ankit Nautiyal | a344fe3 | 2019-05-14 18:36:08 +0530 | [diff] [blame] | 726 | extern struct drm_property_enum_info content_protection_enums[]; |
| 727 | extern struct drm_property_enum_info hdcp_content_type_enums[]; |
Daniel Stone | 4c2fc70 | 2019-06-18 11:12:07 +0100 | [diff] [blame] | 728 | extern const struct drm_property_info connector_props[]; |
| 729 | extern const struct drm_property_info crtc_props[]; |
| 730 | |
| 731 | int |
| 732 | init_kms_caps(struct drm_backend *b); |
| 733 | |
| 734 | int |
| 735 | drm_pending_state_test(struct drm_pending_state *pending_state); |
| 736 | int |
| 737 | drm_pending_state_apply(struct drm_pending_state *pending_state); |
| 738 | int |
| 739 | drm_pending_state_apply_sync(struct drm_pending_state *pending_state); |
| 740 | |
| 741 | void |
| 742 | drm_output_set_gamma(struct weston_output *output_base, |
| 743 | uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); |
| 744 | |
| 745 | void |
| 746 | drm_output_update_msc(struct drm_output *output, unsigned int seq); |
| 747 | void |
| 748 | drm_output_update_complete(struct drm_output *output, uint32_t flags, |
| 749 | unsigned int sec, unsigned int usec); |
| 750 | int |
| 751 | on_drm_input(int fd, uint32_t mask, void *data); |
| 752 | |
Daniel Stone | 7580b3c | 2019-06-18 11:16:53 +0100 | [diff] [blame] | 753 | struct drm_fb * |
| 754 | drm_fb_ref(struct drm_fb *fb); |
| 755 | void |
| 756 | drm_fb_unref(struct drm_fb *fb); |
| 757 | |
| 758 | struct drm_fb * |
| 759 | drm_fb_create_dumb(struct drm_backend *b, int width, int height, |
| 760 | uint32_t format); |
| 761 | struct drm_fb * |
| 762 | drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend, |
| 763 | bool is_opaque, enum drm_fb_type type); |
Daniel Stone | 6b466f2 | 2019-06-18 11:30:54 +0100 | [diff] [blame] | 764 | |
Alexandros Frantzis | 10937fe | 2021-06-14 13:09:44 +0300 | [diff] [blame] | 765 | void |
| 766 | drm_output_set_cursor_view(struct drm_output *output, struct weston_view *ev); |
| 767 | |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 768 | #ifdef BUILD_DRM_GBM |
| 769 | extern struct drm_fb * |
Leandro Ribeiro | 0a7034c | 2021-09-13 14:52:53 -0300 | [diff] [blame] | 770 | drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev, |
| 771 | uint32_t *try_view_on_plane_failure_reasons); |
Marius Vlad | 81bada5 | 2019-11-11 00:27:17 +0200 | [diff] [blame] | 772 | extern bool |
| 773 | drm_can_scanout_dmabuf(struct weston_compositor *ec, |
| 774 | struct linux_dmabuf_buffer *dmabuf); |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 775 | #else |
| 776 | static inline struct drm_fb * |
Leandro Ribeiro | 0a7034c | 2021-09-13 14:52:53 -0300 | [diff] [blame] | 777 | drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev, |
| 778 | uint32_t *try_view_on_plane_failure_reasons) |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 779 | { |
| 780 | return NULL; |
| 781 | } |
Marius Vlad | 81bada5 | 2019-11-11 00:27:17 +0200 | [diff] [blame] | 782 | static inline bool |
| 783 | drm_can_scanout_dmabuf(struct weston_compositor *ec, |
| 784 | struct linux_dmabuf_buffer *dmabuf) |
| 785 | { |
| 786 | return false; |
| 787 | } |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 788 | #endif |
Daniel Stone | 6b466f2 | 2019-06-18 11:30:54 +0100 | [diff] [blame] | 789 | |
| 790 | struct drm_pending_state * |
| 791 | drm_pending_state_alloc(struct drm_backend *backend); |
| 792 | void |
| 793 | drm_pending_state_free(struct drm_pending_state *pending_state); |
| 794 | struct drm_output_state * |
| 795 | drm_pending_state_get_output(struct drm_pending_state *pending_state, |
| 796 | struct drm_output *output); |
| 797 | |
| 798 | |
| 799 | /** |
| 800 | * Mode for drm_output_state_duplicate. |
| 801 | */ |
| 802 | enum drm_output_state_duplicate_mode { |
| 803 | DRM_OUTPUT_STATE_CLEAR_PLANES, /**< reset all planes to off */ |
| 804 | DRM_OUTPUT_STATE_PRESERVE_PLANES, /**< preserve plane state */ |
| 805 | }; |
| 806 | |
| 807 | struct drm_output_state * |
| 808 | drm_output_state_alloc(struct drm_output *output, |
| 809 | struct drm_pending_state *pending_state); |
| 810 | struct drm_output_state * |
| 811 | drm_output_state_duplicate(struct drm_output_state *src, |
| 812 | struct drm_pending_state *pending_state, |
| 813 | enum drm_output_state_duplicate_mode plane_mode); |
| 814 | void |
| 815 | drm_output_state_free(struct drm_output_state *state); |
| 816 | struct drm_plane_state * |
| 817 | drm_output_state_get_plane(struct drm_output_state *state_output, |
| 818 | struct drm_plane *plane); |
| 819 | struct drm_plane_state * |
| 820 | drm_output_state_get_existing_plane(struct drm_output_state *state_output, |
| 821 | struct drm_plane *plane); |
| 822 | |
| 823 | |
| 824 | |
| 825 | struct drm_plane_state * |
| 826 | drm_plane_state_alloc(struct drm_output_state *state_output, |
| 827 | struct drm_plane *plane); |
| 828 | struct drm_plane_state * |
| 829 | drm_plane_state_duplicate(struct drm_output_state *state_output, |
| 830 | struct drm_plane_state *src); |
| 831 | void |
| 832 | drm_plane_state_free(struct drm_plane_state *state, bool force); |
| 833 | void |
| 834 | drm_plane_state_put_back(struct drm_plane_state *state); |
| 835 | bool |
| 836 | drm_plane_state_coords_for_view(struct drm_plane_state *state, |
Marius Vlad | 2538aac | 2019-10-14 11:05:30 +0300 | [diff] [blame] | 837 | struct weston_view *ev, uint64_t zpos); |
Alexandros Frantzis | 9975134 | 2020-05-18 15:22:49 +0300 | [diff] [blame] | 838 | void |
| 839 | drm_plane_reset_state(struct drm_plane *plane); |
Daniel Stone | e404b72 | 2019-06-22 18:40:31 +0100 | [diff] [blame] | 840 | |
| 841 | void |
| 842 | drm_assign_planes(struct weston_output *output_base, void *repaint_data); |
| 843 | |
| 844 | bool |
| 845 | drm_plane_is_available(struct drm_plane *plane, struct drm_output *output); |
Stefan Agner | 3654c67 | 2019-07-09 00:50:30 +0200 | [diff] [blame] | 846 | |
| 847 | void |
| 848 | drm_output_render(struct drm_output_state *state, pixman_region32_t *damage); |
| 849 | |
| 850 | int |
| 851 | parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format); |
| 852 | |
| 853 | extern struct gl_renderer_interface *gl_renderer; |
| 854 | |
| 855 | #ifdef BUILD_DRM_VIRTUAL |
| 856 | extern int |
| 857 | drm_backend_init_virtual_output_api(struct weston_compositor *compositor); |
| 858 | #else |
| 859 | inline static int |
| 860 | drm_backend_init_virtual_output_api(struct weston_compositor *compositor) |
| 861 | { |
| 862 | return 0; |
| 863 | } |
| 864 | #endif |
| 865 | |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 866 | #ifdef BUILD_DRM_GBM |
| 867 | int |
| 868 | init_egl(struct drm_backend *b); |
| 869 | |
Stefan Agner | 3654c67 | 2019-07-09 00:50:30 +0200 | [diff] [blame] | 870 | int |
| 871 | drm_output_init_egl(struct drm_output *output, struct drm_backend *b); |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 872 | |
Stefan Agner | 3654c67 | 2019-07-09 00:50:30 +0200 | [diff] [blame] | 873 | void |
| 874 | drm_output_fini_egl(struct drm_output *output); |
| 875 | |
Stefan Agner | ccf2407 | 2019-07-09 22:02:00 +0200 | [diff] [blame] | 876 | struct drm_fb * |
| 877 | drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage); |
| 878 | |
| 879 | void |
| 880 | renderer_switch_binding(struct weston_keyboard *keyboard, |
| 881 | const struct timespec *time, uint32_t key, void *data); |
| 882 | #else |
| 883 | inline static int |
| 884 | init_egl(struct drm_backend *b) |
| 885 | { |
| 886 | weston_log("Compiled without GBM/EGL support\n"); |
| 887 | return -1; |
| 888 | } |
| 889 | |
| 890 | inline static int |
| 891 | drm_output_init_egl(struct drm_output *output, struct drm_backend *b) |
| 892 | { |
| 893 | return -1; |
| 894 | } |
| 895 | |
| 896 | inline static void |
| 897 | drm_output_fini_egl(struct drm_output *output) |
| 898 | { |
| 899 | } |
| 900 | |
| 901 | inline static struct drm_fb * |
| 902 | drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage) |
| 903 | { |
| 904 | return NULL; |
| 905 | } |
| 906 | |
| 907 | inline static void |
| 908 | renderer_switch_binding(struct weston_keyboard *keyboard, |
| 909 | const struct timespec *time, uint32_t key, void *data) |
| 910 | { |
| 911 | weston_log("Compiled without GBM/EGL support\n"); |
| 912 | } |
| 913 | #endif |