blob: b0c5af86a0c417d511c604e61ba64896f047aa12 [file] [log] [blame]
Daniel Stonedd1bc502019-06-17 12:13:46 +01001/*
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>
48#include <drm_fourcc.h>
49
Stefan Agnerccf24072019-07-09 22:02:00 +020050#ifdef BUILD_DRM_GBM
Daniel Stonedd1bc502019-06-17 12:13:46 +010051#include <gbm.h>
Stefan Agnerccf24072019-07-09 22:02:00 +020052#endif
Daniel Stonedd1bc502019-06-17 12:13:46 +010053#include <libudev.h>
54
55#include <libweston/libweston.h>
56#include <libweston/backend-drm.h>
Marius Vladc901e892019-06-21 22:49:18 +030057#include <libweston/weston-log.h>
Daniel Stonedd1bc502019-06-17 12:13:46 +010058#include "shared/helpers.h"
59#include "libinput-seat.h"
Marius Vlade41c1bf2019-07-16 23:11:25 +030060#include "backend.h"
Marius Vlada72e3712019-07-10 13:46:39 +030061#include "libweston-internal.h"
Daniel Stonedd1bc502019-06-17 12:13:46 +010062
63#ifndef DRM_CLIENT_CAP_ASPECT_RATIO
64#define DRM_CLIENT_CAP_ASPECT_RATIO 4
65#endif
66
67#ifndef GBM_BO_USE_CURSOR
68#define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64
69#endif
70
71#ifndef GBM_BO_USE_LINEAR
72#define GBM_BO_USE_LINEAR (1 << 4)
73#endif
74
Marius Vladcdd6fa22019-08-29 20:42:00 +030075#ifndef DRM_PLANE_ZPOS_INVALID_PLANE
76#define DRM_PLANE_ZPOS_INVALID_PLANE 0xffffffffffffffffULL
77#endif
78
Daniel Stonedd1bc502019-06-17 12:13:46 +010079/**
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 Agner723c6a12019-12-09 13:06:36 +0100117#ifndef DRM_MODE_PICTURE_ASPECT_64_27
118#define DRM_MODE_PICTURE_ASPECT_64_27 3
119#define DRM_MODE_FLAG_PIC_AR_64_27 \
120 (DRM_MODE_PICTURE_ASPECT_64_27<<19)
121#endif
122#ifndef DRM_MODE_PICTURE_ASPECT_256_135
123#define DRM_MODE_PICTURE_ASPECT_256_135 4
124#define DRM_MODE_FLAG_PIC_AR_256_135 \
125 (DRM_MODE_PICTURE_ASPECT_256_135<<19)
126#endif
127
128
Daniel Stonedd1bc502019-06-17 12:13:46 +0100129/**
Daniel Stonedd1bc502019-06-17 12:13:46 +0100130 * Represents the values of an enum-type KMS property
131 */
132struct drm_property_enum_info {
133 const char *name; /**< name as string (static, not freed) */
134 bool valid; /**< true if value is supported; ignore if false */
135 uint64_t value; /**< raw value */
136};
137
138/**
139 * Holds information on a DRM property, including its ID and the enum
140 * values it holds.
141 *
142 * DRM properties are allocated dynamically, and maintained as DRM objects
143 * within the normal object ID space; they thus do not have a stable ID
144 * to refer to. This includes enum values, which must be referred to by
145 * integer values, but these are not stable.
146 *
147 * drm_property_info allows a cache to be maintained where Weston can use
148 * enum values internally to refer to properties, with the mapping to DRM
149 * ID values being maintained internally.
150 */
151struct drm_property_info {
152 const char *name; /**< name as string (static, not freed) */
153 uint32_t prop_id; /**< KMS property object ID */
Marius Vlad1accffe2019-11-01 12:00:09 +0200154 uint32_t flags;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100155 unsigned int num_enum_values; /**< number of enum values */
156 struct drm_property_enum_info *enum_values; /**< array of enum values */
Marius Vlad1accffe2019-11-01 12:00:09 +0200157 unsigned int num_range_values;
158 uint64_t range_values[2];
Daniel Stonedd1bc502019-06-17 12:13:46 +0100159};
160
161/**
162 * List of properties attached to DRM planes
163 */
164enum wdrm_plane_property {
165 WDRM_PLANE_TYPE = 0,
166 WDRM_PLANE_SRC_X,
167 WDRM_PLANE_SRC_Y,
168 WDRM_PLANE_SRC_W,
169 WDRM_PLANE_SRC_H,
170 WDRM_PLANE_CRTC_X,
171 WDRM_PLANE_CRTC_Y,
172 WDRM_PLANE_CRTC_W,
173 WDRM_PLANE_CRTC_H,
174 WDRM_PLANE_FB_ID,
175 WDRM_PLANE_CRTC_ID,
176 WDRM_PLANE_IN_FORMATS,
177 WDRM_PLANE_IN_FENCE_FD,
178 WDRM_PLANE_FB_DAMAGE_CLIPS,
Marius Vladcdd6fa22019-08-29 20:42:00 +0300179 WDRM_PLANE_ZPOS,
Daniel Stonedd1bc502019-06-17 12:13:46 +0100180 WDRM_PLANE__COUNT
181};
182
183/**
184 * Possible values for the WDRM_PLANE_TYPE property.
185 */
186enum wdrm_plane_type {
187 WDRM_PLANE_TYPE_PRIMARY = 0,
188 WDRM_PLANE_TYPE_CURSOR,
189 WDRM_PLANE_TYPE_OVERLAY,
190 WDRM_PLANE_TYPE__COUNT
191};
192
193/**
194 * List of properties attached to a DRM connector
195 */
196enum wdrm_connector_property {
197 WDRM_CONNECTOR_EDID = 0,
198 WDRM_CONNECTOR_DPMS,
199 WDRM_CONNECTOR_CRTC_ID,
200 WDRM_CONNECTOR_NON_DESKTOP,
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530201 WDRM_CONNECTOR_CONTENT_PROTECTION,
202 WDRM_CONNECTOR_HDCP_CONTENT_TYPE,
Lucas Stach72e7a1e2019-11-25 23:31:57 +0000203 WDRM_CONNECTOR_PANEL_ORIENTATION,
Daniel Stonedd1bc502019-06-17 12:13:46 +0100204 WDRM_CONNECTOR__COUNT
205};
206
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530207enum wdrm_content_protection_state {
208 WDRM_CONTENT_PROTECTION_UNDESIRED = 0,
209 WDRM_CONTENT_PROTECTION_DESIRED,
210 WDRM_CONTENT_PROTECTION_ENABLED,
211 WDRM_CONTENT_PROTECTION__COUNT
212};
213
214enum wdrm_hdcp_content_type {
215 WDRM_HDCP_CONTENT_TYPE0 = 0,
216 WDRM_HDCP_CONTENT_TYPE1,
217 WDRM_HDCP_CONTENT_TYPE__COUNT
218};
219
Daniel Stonedd1bc502019-06-17 12:13:46 +0100220enum wdrm_dpms_state {
221 WDRM_DPMS_STATE_OFF = 0,
222 WDRM_DPMS_STATE_ON,
223 WDRM_DPMS_STATE_STANDBY, /* unused */
224 WDRM_DPMS_STATE_SUSPEND, /* unused */
225 WDRM_DPMS_STATE__COUNT
226};
227
Lucas Stach72e7a1e2019-11-25 23:31:57 +0000228enum wdrm_panel_orientation {
229 WDRM_PANEL_ORIENTATION_NORMAL = 0,
230 WDRM_PANEL_ORIENTATION_UPSIDE_DOWN,
231 WDRM_PANEL_ORIENTATION_LEFT_SIDE_UP,
232 WDRM_PANEL_ORIENTATION_RIGHT_SIDE_UP,
233 WDRM_PANEL_ORIENTATION__COUNT
234};
235
Daniel Stonedd1bc502019-06-17 12:13:46 +0100236/**
237 * List of properties attached to DRM CRTCs
238 */
239enum wdrm_crtc_property {
240 WDRM_CRTC_MODE_ID = 0,
241 WDRM_CRTC_ACTIVE,
242 WDRM_CRTC__COUNT
243};
244
245struct drm_backend {
246 struct weston_backend base;
247 struct weston_compositor *compositor;
248
249 struct udev *udev;
250 struct wl_event_source *drm_source;
251
252 struct udev_monitor *udev_monitor;
253 struct wl_event_source *udev_drm_source;
254
255 struct {
256 int id;
257 int fd;
258 char *filename;
259 dev_t devnum;
260 } drm;
261 struct gbm_device *gbm;
262 struct wl_listener session_listener;
263 uint32_t gbm_format;
264
265 /* we need these parameters in order to not fail drmModeAddFB2()
266 * due to out of bounds dimensions, and then mistakenly set
267 * sprites_are_broken:
268 */
269 int min_width, max_width;
270 int min_height, max_height;
271
272 struct wl_list plane_list;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100273
274 void *repaint_data;
275
276 bool state_invalid;
277
Leandro Ribeirob00d1a22020-08-13 14:12:28 -0300278 /* drm_crtc::link */
279 struct wl_list crtc_list;
280
Daniel Stonedd1bc502019-06-17 12:13:46 +0100281 /* CRTC IDs not used by any enabled output. */
282 struct wl_array unused_crtcs;
283
Emmanuel Gil Peyrot1b3ad092019-12-09 02:50:55 +0100284 bool sprites_are_broken;
285 bool cursors_are_broken;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100286
287 bool universal_planes;
288 bool atomic_modeset;
289
290 bool use_pixman;
291 bool use_pixman_shadow;
292
293 struct udev_input input;
294
295 int32_t cursor_width;
296 int32_t cursor_height;
297
298 uint32_t pageflip_timeout;
299
300 bool shutting_down;
301
302 bool aspect_ratio_supported;
303
304 bool fb_modifiers;
305
306 struct weston_log_scope *debug;
307};
308
309struct drm_mode {
310 struct weston_mode base;
311 drmModeModeInfo mode_info;
312 uint32_t blob_id;
313};
314
315enum drm_fb_type {
316 BUFFER_INVALID = 0, /**< never used */
317 BUFFER_CLIENT, /**< directly sourced from client */
318 BUFFER_DMABUF, /**< imported from linux_dmabuf client */
319 BUFFER_PIXMAN_DUMB, /**< internal Pixman rendering */
320 BUFFER_GBM_SURFACE, /**< internal EGL rendering */
321 BUFFER_CURSOR, /**< internal cursor buffer */
322};
323
324struct drm_fb {
325 enum drm_fb_type type;
326
327 int refcnt;
328
329 uint32_t fb_id, size;
330 uint32_t handles[4];
331 uint32_t strides[4];
332 uint32_t offsets[4];
333 int num_planes;
334 const struct pixel_format_info *format;
335 uint64_t modifier;
336 int width, height;
337 int fd;
338 struct weston_buffer_reference buffer_ref;
339 struct weston_buffer_release_reference buffer_release_ref;
340
341 /* Used by gbm fbs */
342 struct gbm_bo *bo;
343 struct gbm_surface *gbm_surface;
344
345 /* Used by dumb fbs */
346 void *map;
347};
348
349struct drm_edid {
350 char eisa_id[13];
351 char monitor_name[13];
352 char pnp_id[5];
353 char serial_number[13];
354};
355
356/**
357 * Pending state holds one or more drm_output_state structures, collected from
358 * performing repaint. This pending state is transient, and only lives between
359 * beginning a repaint group and flushing the results: after flush, each
360 * output state will complete and be retired separately.
361 */
362struct drm_pending_state {
363 struct drm_backend *backend;
364 struct wl_list output_list;
365};
366
367/*
368 * Output state holds the dynamic state for one Weston output, i.e. a KMS CRTC,
369 * plus >= 1 each of encoder/connector/plane. Since everything but the planes
370 * is currently statically assigned per-output, we mainly use this to track
371 * plane state.
372 *
373 * pending_state is set when the output state is owned by a pending_state,
374 * i.e. when it is being constructed and has not yet been applied. When the
375 * output state has been applied, the owning pending_state is freed.
376 */
377struct drm_output_state {
378 struct drm_pending_state *pending_state;
379 struct drm_output *output;
380 struct wl_list link;
381 enum dpms_enum dpms;
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530382 enum weston_hdcp_protection protection;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100383 struct wl_list plane_list;
384};
385
386/**
Marius Vlad2538aac2019-10-14 11:05:30 +0300387 * An instance of this class is created each time we believe we have a plane
388 * suitable to be used by a view as a direct scan-out. The list is initalized
389 * and populated locally.
390 */
391struct drm_plane_zpos {
392 struct drm_plane *plane;
393 struct wl_list link; /**< :candidate_plane_zpos_list */
394};
395
396/**
Daniel Stonedd1bc502019-06-17 12:13:46 +0100397 * Plane state holds the dynamic state for a plane: where it is positioned,
398 * and which buffer it is currently displaying.
399 *
400 * The plane state is owned by an output state, except when setting an initial
401 * state. See drm_output_state for notes on state object lifetime.
402 */
403struct drm_plane_state {
404 struct drm_plane *plane;
405 struct drm_output *output;
406 struct drm_output_state *output_state;
407
408 struct drm_fb *fb;
409
410 struct weston_view *ev; /**< maintained for drm_assign_planes only */
411
412 int32_t src_x, src_y;
413 uint32_t src_w, src_h;
414 int32_t dest_x, dest_y;
415 uint32_t dest_w, dest_h;
416
Marius Vladcdd6fa22019-08-29 20:42:00 +0300417 uint64_t zpos;
418
Daniel Stonedd1bc502019-06-17 12:13:46 +0100419 bool complete;
420
421 /* We don't own the fd, so we shouldn't close it */
422 int in_fence_fd;
423
Scott Anderson15c603c2020-06-02 17:39:43 +1200424 uint32_t damage_blob_id; /* damage to kernel */
Daniel Stonedd1bc502019-06-17 12:13:46 +0100425
426 struct wl_list link; /* drm_output_state::plane_list */
427};
428
429/**
430 * A plane represents one buffer, positioned within a CRTC, and stacked
431 * relative to other planes on the same CRTC.
432 *
433 * Each CRTC has a 'primary plane', which use used to display the classic
434 * framebuffer contents, as accessed through the legacy drmModeSetCrtc
435 * call (which combines setting the CRTC's actual physical mode, and the
436 * properties of the primary plane).
437 *
438 * The cursor plane also has its own alternate legacy API.
439 *
440 * Other planes are used opportunistically to display content we do not
441 * wish to blit into the primary plane. These non-primary/cursor planes
442 * are referred to as 'sprites'.
443 */
444struct drm_plane {
445 struct weston_plane base;
446
447 struct drm_backend *backend;
448
449 enum wdrm_plane_type type;
450
451 uint32_t possible_crtcs;
452 uint32_t plane_id;
453 uint32_t count_formats;
454
455 struct drm_property_info props[WDRM_PLANE__COUNT];
456
457 /* The last state submitted to the kernel for this plane. */
458 struct drm_plane_state *state_cur;
459
Marius Vladcdd6fa22019-08-29 20:42:00 +0300460 uint64_t zpos_min;
461 uint64_t zpos_max;
462
Daniel Stonedd1bc502019-06-17 12:13:46 +0100463 struct wl_list link;
464
465 struct {
466 uint32_t format;
467 uint32_t count_modifiers;
468 uint64_t *modifiers;
469 } formats[];
470};
471
472struct drm_head {
473 struct weston_head base;
474 struct drm_backend *backend;
475
476 drmModeConnector *connector;
477 uint32_t connector_id;
478 struct drm_edid edid;
479
480 /* Holds the properties for the connector */
481 struct drm_property_info props_conn[WDRM_CONNECTOR__COUNT];
482
483 struct backlight *backlight;
484
485 drmModeModeInfo inherited_mode; /**< Original mode on the connector */
486 uint32_t inherited_crtc_id; /**< Original CRTC assignment */
487};
488
Leandro Ribeirob00d1a22020-08-13 14:12:28 -0300489struct drm_crtc {
490 /* drm_backend::crtc_list */
491 struct wl_list link;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100492 struct drm_backend *backend;
493
Leandro Ribeirob00d1a22020-08-13 14:12:28 -0300494 /* The output driven by the CRTC */
495 struct drm_output *output;
496
Daniel Stonedd1bc502019-06-17 12:13:46 +0100497 uint32_t crtc_id; /* object ID to pass to DRM functions */
498 int pipe; /* index of CRTC in resource array / bitmasks */
499
500 /* Holds the properties for the CRTC */
501 struct drm_property_info props_crtc[WDRM_CRTC__COUNT];
Leandro Ribeirob00d1a22020-08-13 14:12:28 -0300502};
503
504struct drm_output {
505 struct weston_output base;
506 struct drm_backend *backend;
507 struct drm_crtc *crtc;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100508
Emmanuel Gil Peyrot1b3ad092019-12-09 02:50:55 +0100509 bool page_flip_pending;
510 bool atomic_complete_pending;
511 bool destroy_pending;
512 bool disable_pending;
513 bool dpms_off_pending;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100514
Stefan Agner974390a2019-07-08 00:42:05 +0200515 uint32_t gbm_cursor_handle[2];
Daniel Stonedd1bc502019-06-17 12:13:46 +0100516 struct drm_fb *gbm_cursor_fb[2];
517 struct drm_plane *cursor_plane;
518 struct weston_view *cursor_view;
519 int current_cursor;
520
521 struct gbm_surface *gbm_surface;
522 uint32_t gbm_format;
523 uint32_t gbm_bo_flags;
524
525 /* Plane being displayed directly on the CRTC */
526 struct drm_plane *scanout_plane;
527
528 /* The last state submitted to the kernel for this CRTC. */
529 struct drm_output_state *state_cur;
530 /* The previously-submitted state, where the hardware has not
531 * yet acknowledged completion of state_cur. */
532 struct drm_output_state *state_last;
533
534 struct drm_fb *dumb[2];
535 pixman_image_t *image[2];
536 int current_image;
537 pixman_region32_t previous_damage;
538
539 struct vaapi_recorder *recorder;
540 struct wl_listener recorder_frame_listener;
541
542 struct wl_event_source *pageflip_timer;
543
544 bool virtual;
545
546 submit_frame_cb virtual_submit_frame;
547};
548
549static inline struct drm_head *
550to_drm_head(struct weston_head *base)
551{
552 return container_of(base, struct drm_head, base);
553}
554
555static inline struct drm_output *
556to_drm_output(struct weston_output *base)
557{
558 return container_of(base, struct drm_output, base);
559}
560
561static inline struct drm_backend *
562to_drm_backend(struct weston_compositor *base)
563{
564 return container_of(base->backend, struct drm_backend, base);
565}
566
567static inline struct drm_mode *
568to_drm_mode(struct weston_mode *base)
569{
570 return container_of(base, struct drm_mode, base);
571}
Daniel Stonefbe6c1d2019-06-17 16:04:26 +0100572
Marius Vlad3dea57a2019-09-27 20:45:41 +0300573static inline const char *
574drm_output_get_plane_type_name(struct drm_plane *p)
575{
576 switch (p->type) {
577 case WDRM_PLANE_TYPE_PRIMARY:
578 return "primary";
579 case WDRM_PLANE_TYPE_CURSOR:
580 return "cursor";
581 case WDRM_PLANE_TYPE_OVERLAY:
582 return "overlay";
583 default:
584 assert(0);
585 break;
586 }
587}
588
Leandro Ribeirob00d1a22020-08-13 14:12:28 -0300589struct drm_crtc *
590drm_crtc_find(struct drm_backend *b, uint32_t crtc_id);
Daniel Stone4c2fc702019-06-18 11:12:07 +0100591
592struct drm_head *
593drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id);
594
Daniel Stone7580b3c2019-06-18 11:16:53 +0100595static inline bool
596drm_view_transform_supported(struct weston_view *ev, struct weston_output *output)
597{
598 struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
599
600 /* This will incorrectly disallow cases where the combination of
601 * buffer and view transformations match the output transform.
602 * Fixing this requires a full analysis of the transformation
603 * chain. */
604 if (ev->transform.enabled &&
605 ev->transform.matrix.type >= WESTON_MATRIX_TRANSFORM_ROTATE)
606 return false;
607
608 if (viewport->buffer.transform != output->transform)
609 return false;
610
611 return true;
612}
613
Daniel Stonefbe6c1d2019-06-17 16:04:26 +0100614int
615drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode);
616
617struct drm_mode *
618drm_output_choose_mode(struct drm_output *output,
619 struct weston_mode *target_mode);
620void
621update_head_from_connector(struct drm_head *head,
622 drmModeObjectProperties *props);
623
624void
625drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list);
626
627void
628drm_output_print_modes(struct drm_output *output);
629
630int
631drm_output_set_mode(struct weston_output *base,
632 enum weston_drm_backend_output_mode mode,
633 const char *modeline);
634
Daniel Stone4c2fc702019-06-18 11:12:07 +0100635void
636drm_property_info_populate(struct drm_backend *b,
637 const struct drm_property_info *src,
638 struct drm_property_info *info,
639 unsigned int num_infos,
640 drmModeObjectProperties *props);
Daniel Stonefbe6c1d2019-06-17 16:04:26 +0100641uint64_t
642drm_property_get_value(struct drm_property_info *info,
643 const drmModeObjectProperties *props,
644 uint64_t def);
Marius Vlad1accffe2019-11-01 12:00:09 +0200645uint64_t *
646drm_property_get_range_values(struct drm_property_info *info,
647 const drmModeObjectProperties *props);
Daniel Stone4c2fc702019-06-18 11:12:07 +0100648int
649drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane,
Stefan Agner465ab2c2020-06-17 23:36:44 +0200650 const drmModeObjectProperties *props,
651 const bool use_modifiers);
Daniel Stone4c2fc702019-06-18 11:12:07 +0100652void
653drm_property_info_free(struct drm_property_info *info, int num_props);
654
655extern struct drm_property_enum_info plane_type_enums[];
656extern const struct drm_property_info plane_props[];
657extern struct drm_property_enum_info dpms_state_enums[];
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530658extern struct drm_property_enum_info content_protection_enums[];
659extern struct drm_property_enum_info hdcp_content_type_enums[];
Daniel Stone4c2fc702019-06-18 11:12:07 +0100660extern const struct drm_property_info connector_props[];
661extern const struct drm_property_info crtc_props[];
662
663int
664init_kms_caps(struct drm_backend *b);
665
666int
667drm_pending_state_test(struct drm_pending_state *pending_state);
668int
669drm_pending_state_apply(struct drm_pending_state *pending_state);
670int
671drm_pending_state_apply_sync(struct drm_pending_state *pending_state);
672
673void
674drm_output_set_gamma(struct weston_output *output_base,
675 uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
676
677void
678drm_output_update_msc(struct drm_output *output, unsigned int seq);
679void
680drm_output_update_complete(struct drm_output *output, uint32_t flags,
681 unsigned int sec, unsigned int usec);
682int
683on_drm_input(int fd, uint32_t mask, void *data);
684
Daniel Stone7580b3c2019-06-18 11:16:53 +0100685struct drm_fb *
686drm_fb_ref(struct drm_fb *fb);
687void
688drm_fb_unref(struct drm_fb *fb);
689
690struct drm_fb *
691drm_fb_create_dumb(struct drm_backend *b, int width, int height,
692 uint32_t format);
693struct drm_fb *
694drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
695 bool is_opaque, enum drm_fb_type type);
Daniel Stone6b466f22019-06-18 11:30:54 +0100696
Stefan Agnerccf24072019-07-09 22:02:00 +0200697#ifdef BUILD_DRM_GBM
698extern struct drm_fb *
699drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev);
Marius Vlad81bada52019-11-11 00:27:17 +0200700extern bool
701drm_can_scanout_dmabuf(struct weston_compositor *ec,
702 struct linux_dmabuf_buffer *dmabuf);
Stefan Agnerccf24072019-07-09 22:02:00 +0200703#else
704static inline struct drm_fb *
705drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
706{
707 return NULL;
708}
Marius Vlad81bada52019-11-11 00:27:17 +0200709static inline bool
710drm_can_scanout_dmabuf(struct weston_compositor *ec,
711 struct linux_dmabuf_buffer *dmabuf)
712{
713 return false;
714}
Stefan Agnerccf24072019-07-09 22:02:00 +0200715#endif
Daniel Stone6b466f22019-06-18 11:30:54 +0100716
717struct drm_pending_state *
718drm_pending_state_alloc(struct drm_backend *backend);
719void
720drm_pending_state_free(struct drm_pending_state *pending_state);
721struct drm_output_state *
722drm_pending_state_get_output(struct drm_pending_state *pending_state,
723 struct drm_output *output);
724
725
726/**
727 * Mode for drm_output_state_duplicate.
728 */
729enum drm_output_state_duplicate_mode {
730 DRM_OUTPUT_STATE_CLEAR_PLANES, /**< reset all planes to off */
731 DRM_OUTPUT_STATE_PRESERVE_PLANES, /**< preserve plane state */
732};
733
734struct drm_output_state *
735drm_output_state_alloc(struct drm_output *output,
736 struct drm_pending_state *pending_state);
737struct drm_output_state *
738drm_output_state_duplicate(struct drm_output_state *src,
739 struct drm_pending_state *pending_state,
740 enum drm_output_state_duplicate_mode plane_mode);
741void
742drm_output_state_free(struct drm_output_state *state);
743struct drm_plane_state *
744drm_output_state_get_plane(struct drm_output_state *state_output,
745 struct drm_plane *plane);
746struct drm_plane_state *
747drm_output_state_get_existing_plane(struct drm_output_state *state_output,
748 struct drm_plane *plane);
749
750
751
752struct drm_plane_state *
753drm_plane_state_alloc(struct drm_output_state *state_output,
754 struct drm_plane *plane);
755struct drm_plane_state *
756drm_plane_state_duplicate(struct drm_output_state *state_output,
757 struct drm_plane_state *src);
758void
759drm_plane_state_free(struct drm_plane_state *state, bool force);
760void
761drm_plane_state_put_back(struct drm_plane_state *state);
762bool
763drm_plane_state_coords_for_view(struct drm_plane_state *state,
Marius Vlad2538aac2019-10-14 11:05:30 +0300764 struct weston_view *ev, uint64_t zpos);
Alexandros Frantzis99751342020-05-18 15:22:49 +0300765void
766drm_plane_reset_state(struct drm_plane *plane);
Daniel Stonee404b722019-06-22 18:40:31 +0100767
768void
769drm_assign_planes(struct weston_output *output_base, void *repaint_data);
770
771bool
772drm_plane_is_available(struct drm_plane *plane, struct drm_output *output);
Stefan Agner3654c672019-07-09 00:50:30 +0200773
774void
775drm_output_render(struct drm_output_state *state, pixman_region32_t *damage);
776
777int
778parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format);
779
780extern struct gl_renderer_interface *gl_renderer;
781
782#ifdef BUILD_DRM_VIRTUAL
783extern int
784drm_backend_init_virtual_output_api(struct weston_compositor *compositor);
785#else
786inline static int
787drm_backend_init_virtual_output_api(struct weston_compositor *compositor)
788{
789 return 0;
790}
791#endif
792
Stefan Agnerccf24072019-07-09 22:02:00 +0200793#ifdef BUILD_DRM_GBM
794int
795init_egl(struct drm_backend *b);
796
Stefan Agner3654c672019-07-09 00:50:30 +0200797int
798drm_output_init_egl(struct drm_output *output, struct drm_backend *b);
Stefan Agnerccf24072019-07-09 22:02:00 +0200799
Stefan Agner3654c672019-07-09 00:50:30 +0200800void
801drm_output_fini_egl(struct drm_output *output);
802
Stefan Agnerccf24072019-07-09 22:02:00 +0200803struct drm_fb *
804drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage);
805
806void
807renderer_switch_binding(struct weston_keyboard *keyboard,
808 const struct timespec *time, uint32_t key, void *data);
809#else
810inline static int
811init_egl(struct drm_backend *b)
812{
813 weston_log("Compiled without GBM/EGL support\n");
814 return -1;
815}
816
817inline static int
818drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
819{
820 return -1;
821}
822
823inline static void
824drm_output_fini_egl(struct drm_output *output)
825{
826}
827
828inline static struct drm_fb *
829drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
830{
831 return NULL;
832}
833
834inline static void
835renderer_switch_binding(struct weston_keyboard *keyboard,
836 const struct timespec *time, uint32_t key, void *data)
837{
838 weston_log("Compiled without GBM/EGL support\n");
839}
840#endif