blob: b55061ab65d7f837f777ac25c3bc77c3dd61a8e1 [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
75/**
76 * A small wrapper to print information into the 'drm-backend' debug scope.
77 *
78 * The following conventions are used to print variables:
79 *
80 * - fixed uint32_t values, including Weston object IDs such as weston_output
81 * IDs, DRM object IDs such as CRTCs or properties, and GBM/DRM formats:
82 * "%lu (0x%lx)" (unsigned long) value, (unsigned long) value
83 *
84 * - fixed uint64_t values, such as DRM property values (including object IDs
85 * when used as a value):
86 * "%llu (0x%llx)" (unsigned long long) value, (unsigned long long) value
87 *
88 * - non-fixed-width signed int:
89 * "%d" value
90 *
91 * - non-fixed-width unsigned int:
92 * "%u (0x%x)" value, value
93 *
94 * - non-fixed-width unsigned long:
95 * "%lu (0x%lx)" value, value
96 *
97 * Either the integer or hexadecimal forms may be omitted if it is known that
98 * one representation is not useful (e.g. width/height in hex are rarely what
99 * you want).
100 *
101 * This is to avoid implicit widening or narrowing when we use fixed-size
102 * types: uint32_t can be resolved by either unsigned int or unsigned long
103 * on a 32-bit system but only unsigned int on a 64-bit system, with uint64_t
104 * being unsigned long long on a 32-bit system and unsigned long on a 64-bit
105 * system. To avoid confusing side effects, we explicitly cast to the widest
106 * possible type and use a matching format specifier.
107 */
108#define drm_debug(b, ...) \
109 weston_log_scope_printf((b)->debug, __VA_ARGS__)
110
111#define MAX_CLONED_CONNECTORS 4
112
113/**
114 * aspect ratio info taken from the drmModeModeInfo flag bits 19-22,
115 * which should be used to fill the aspect ratio field in weston_mode.
116 */
117#define DRM_MODE_FLAG_PIC_AR_BITS_POS 19
118#ifndef DRM_MODE_FLAG_PIC_AR_MASK
119#define DRM_MODE_FLAG_PIC_AR_MASK (0xF << DRM_MODE_FLAG_PIC_AR_BITS_POS)
120#endif
121
122/**
123 * Represents the values of an enum-type KMS property
124 */
125struct drm_property_enum_info {
126 const char *name; /**< name as string (static, not freed) */
127 bool valid; /**< true if value is supported; ignore if false */
128 uint64_t value; /**< raw value */
129};
130
131/**
132 * Holds information on a DRM property, including its ID and the enum
133 * values it holds.
134 *
135 * DRM properties are allocated dynamically, and maintained as DRM objects
136 * within the normal object ID space; they thus do not have a stable ID
137 * to refer to. This includes enum values, which must be referred to by
138 * integer values, but these are not stable.
139 *
140 * drm_property_info allows a cache to be maintained where Weston can use
141 * enum values internally to refer to properties, with the mapping to DRM
142 * ID values being maintained internally.
143 */
144struct drm_property_info {
145 const char *name; /**< name as string (static, not freed) */
146 uint32_t prop_id; /**< KMS property object ID */
147 unsigned int num_enum_values; /**< number of enum values */
148 struct drm_property_enum_info *enum_values; /**< array of enum values */
149};
150
151/**
152 * List of properties attached to DRM planes
153 */
154enum wdrm_plane_property {
155 WDRM_PLANE_TYPE = 0,
156 WDRM_PLANE_SRC_X,
157 WDRM_PLANE_SRC_Y,
158 WDRM_PLANE_SRC_W,
159 WDRM_PLANE_SRC_H,
160 WDRM_PLANE_CRTC_X,
161 WDRM_PLANE_CRTC_Y,
162 WDRM_PLANE_CRTC_W,
163 WDRM_PLANE_CRTC_H,
164 WDRM_PLANE_FB_ID,
165 WDRM_PLANE_CRTC_ID,
166 WDRM_PLANE_IN_FORMATS,
167 WDRM_PLANE_IN_FENCE_FD,
168 WDRM_PLANE_FB_DAMAGE_CLIPS,
169 WDRM_PLANE__COUNT
170};
171
172/**
173 * Possible values for the WDRM_PLANE_TYPE property.
174 */
175enum 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 */
185enum wdrm_connector_property {
186 WDRM_CONNECTOR_EDID = 0,
187 WDRM_CONNECTOR_DPMS,
188 WDRM_CONNECTOR_CRTC_ID,
189 WDRM_CONNECTOR_NON_DESKTOP,
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530190 WDRM_CONNECTOR_CONTENT_PROTECTION,
191 WDRM_CONNECTOR_HDCP_CONTENT_TYPE,
Daniel Stonedd1bc502019-06-17 12:13:46 +0100192 WDRM_CONNECTOR__COUNT
193};
194
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530195enum wdrm_content_protection_state {
196 WDRM_CONTENT_PROTECTION_UNDESIRED = 0,
197 WDRM_CONTENT_PROTECTION_DESIRED,
198 WDRM_CONTENT_PROTECTION_ENABLED,
199 WDRM_CONTENT_PROTECTION__COUNT
200};
201
202enum wdrm_hdcp_content_type {
203 WDRM_HDCP_CONTENT_TYPE0 = 0,
204 WDRM_HDCP_CONTENT_TYPE1,
205 WDRM_HDCP_CONTENT_TYPE__COUNT
206};
207
Daniel Stonedd1bc502019-06-17 12:13:46 +0100208enum wdrm_dpms_state {
209 WDRM_DPMS_STATE_OFF = 0,
210 WDRM_DPMS_STATE_ON,
211 WDRM_DPMS_STATE_STANDBY, /* unused */
212 WDRM_DPMS_STATE_SUSPEND, /* unused */
213 WDRM_DPMS_STATE__COUNT
214};
215
216/**
217 * List of properties attached to DRM CRTCs
218 */
219enum wdrm_crtc_property {
220 WDRM_CRTC_MODE_ID = 0,
221 WDRM_CRTC_ACTIVE,
222 WDRM_CRTC__COUNT
223};
224
225struct drm_backend {
226 struct weston_backend base;
227 struct weston_compositor *compositor;
228
229 struct udev *udev;
230 struct wl_event_source *drm_source;
231
232 struct udev_monitor *udev_monitor;
233 struct wl_event_source *udev_drm_source;
234
235 struct {
236 int id;
237 int fd;
238 char *filename;
239 dev_t devnum;
240 } drm;
241 struct gbm_device *gbm;
242 struct wl_listener session_listener;
243 uint32_t gbm_format;
244
245 /* we need these parameters in order to not fail drmModeAddFB2()
246 * due to out of bounds dimensions, and then mistakenly set
247 * sprites_are_broken:
248 */
249 int min_width, max_width;
250 int min_height, max_height;
251
252 struct wl_list plane_list;
253 int sprites_are_broken;
254 int sprites_hidden;
255
256 void *repaint_data;
257
258 bool state_invalid;
259
260 /* CRTC IDs not used by any enabled output. */
261 struct wl_array unused_crtcs;
262
263 int cursors_are_broken;
264
265 bool universal_planes;
266 bool atomic_modeset;
267
268 bool use_pixman;
269 bool use_pixman_shadow;
270
271 struct udev_input input;
272
273 int32_t cursor_width;
274 int32_t cursor_height;
275
276 uint32_t pageflip_timeout;
277
278 bool shutting_down;
279
280 bool aspect_ratio_supported;
281
282 bool fb_modifiers;
283
284 struct weston_log_scope *debug;
285};
286
287struct drm_mode {
288 struct weston_mode base;
289 drmModeModeInfo mode_info;
290 uint32_t blob_id;
291};
292
293enum drm_fb_type {
294 BUFFER_INVALID = 0, /**< never used */
295 BUFFER_CLIENT, /**< directly sourced from client */
296 BUFFER_DMABUF, /**< imported from linux_dmabuf client */
297 BUFFER_PIXMAN_DUMB, /**< internal Pixman rendering */
298 BUFFER_GBM_SURFACE, /**< internal EGL rendering */
299 BUFFER_CURSOR, /**< internal cursor buffer */
300};
301
302struct drm_fb {
303 enum drm_fb_type type;
304
305 int refcnt;
306
307 uint32_t fb_id, size;
308 uint32_t handles[4];
309 uint32_t strides[4];
310 uint32_t offsets[4];
311 int num_planes;
312 const struct pixel_format_info *format;
313 uint64_t modifier;
314 int width, height;
315 int fd;
316 struct weston_buffer_reference buffer_ref;
317 struct weston_buffer_release_reference buffer_release_ref;
318
319 /* Used by gbm fbs */
320 struct gbm_bo *bo;
321 struct gbm_surface *gbm_surface;
322
323 /* Used by dumb fbs */
324 void *map;
325};
326
327struct drm_edid {
328 char eisa_id[13];
329 char monitor_name[13];
330 char pnp_id[5];
331 char serial_number[13];
332};
333
334/**
335 * Pending state holds one or more drm_output_state structures, collected from
336 * performing repaint. This pending state is transient, and only lives between
337 * beginning a repaint group and flushing the results: after flush, each
338 * output state will complete and be retired separately.
339 */
340struct drm_pending_state {
341 struct drm_backend *backend;
342 struct wl_list output_list;
343};
344
345/*
346 * Output state holds the dynamic state for one Weston output, i.e. a KMS CRTC,
347 * plus >= 1 each of encoder/connector/plane. Since everything but the planes
348 * is currently statically assigned per-output, we mainly use this to track
349 * plane state.
350 *
351 * pending_state is set when the output state is owned by a pending_state,
352 * i.e. when it is being constructed and has not yet been applied. When the
353 * output state has been applied, the owning pending_state is freed.
354 */
355struct drm_output_state {
356 struct drm_pending_state *pending_state;
357 struct drm_output *output;
358 struct wl_list link;
359 enum dpms_enum dpms;
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530360 enum weston_hdcp_protection protection;
Daniel Stonedd1bc502019-06-17 12:13:46 +0100361 struct wl_list plane_list;
362};
363
364/**
365 * Plane state holds the dynamic state for a plane: where it is positioned,
366 * and which buffer it is currently displaying.
367 *
368 * The plane state is owned by an output state, except when setting an initial
369 * state. See drm_output_state for notes on state object lifetime.
370 */
371struct drm_plane_state {
372 struct drm_plane *plane;
373 struct drm_output *output;
374 struct drm_output_state *output_state;
375
376 struct drm_fb *fb;
377
378 struct weston_view *ev; /**< maintained for drm_assign_planes only */
379
380 int32_t src_x, src_y;
381 uint32_t src_w, src_h;
382 int32_t dest_x, dest_y;
383 uint32_t dest_w, dest_h;
384
385 bool complete;
386
387 /* We don't own the fd, so we shouldn't close it */
388 int in_fence_fd;
389
390 pixman_region32_t damage; /* damage to kernel */
391
392 struct wl_list link; /* drm_output_state::plane_list */
393};
394
395/**
396 * A plane represents one buffer, positioned within a CRTC, and stacked
397 * relative to other planes on the same CRTC.
398 *
399 * Each CRTC has a 'primary plane', which use used to display the classic
400 * framebuffer contents, as accessed through the legacy drmModeSetCrtc
401 * call (which combines setting the CRTC's actual physical mode, and the
402 * properties of the primary plane).
403 *
404 * The cursor plane also has its own alternate legacy API.
405 *
406 * Other planes are used opportunistically to display content we do not
407 * wish to blit into the primary plane. These non-primary/cursor planes
408 * are referred to as 'sprites'.
409 */
410struct drm_plane {
411 struct weston_plane base;
412
413 struct drm_backend *backend;
414
415 enum wdrm_plane_type type;
416
417 uint32_t possible_crtcs;
418 uint32_t plane_id;
419 uint32_t count_formats;
420
421 struct drm_property_info props[WDRM_PLANE__COUNT];
422
423 /* The last state submitted to the kernel for this plane. */
424 struct drm_plane_state *state_cur;
425
426 struct wl_list link;
427
428 struct {
429 uint32_t format;
430 uint32_t count_modifiers;
431 uint64_t *modifiers;
432 } formats[];
433};
434
435struct drm_head {
436 struct weston_head base;
437 struct drm_backend *backend;
438
439 drmModeConnector *connector;
440 uint32_t connector_id;
441 struct drm_edid edid;
442
443 /* Holds the properties for the connector */
444 struct drm_property_info props_conn[WDRM_CONNECTOR__COUNT];
445
446 struct backlight *backlight;
447
448 drmModeModeInfo inherited_mode; /**< Original mode on the connector */
449 uint32_t inherited_crtc_id; /**< Original CRTC assignment */
450};
451
452struct drm_output {
453 struct weston_output base;
454 struct drm_backend *backend;
455
456 uint32_t crtc_id; /* object ID to pass to DRM functions */
457 int pipe; /* index of CRTC in resource array / bitmasks */
458
459 /* Holds the properties for the CRTC */
460 struct drm_property_info props_crtc[WDRM_CRTC__COUNT];
461
462 int page_flip_pending;
463 int atomic_complete_pending;
464 int destroy_pending;
465 int disable_pending;
466 int dpms_off_pending;
467
Stefan Agner974390a2019-07-08 00:42:05 +0200468 uint32_t gbm_cursor_handle[2];
Daniel Stonedd1bc502019-06-17 12:13:46 +0100469 struct drm_fb *gbm_cursor_fb[2];
470 struct drm_plane *cursor_plane;
471 struct weston_view *cursor_view;
472 int current_cursor;
473
474 struct gbm_surface *gbm_surface;
475 uint32_t gbm_format;
476 uint32_t gbm_bo_flags;
477
478 /* Plane being displayed directly on the CRTC */
479 struct drm_plane *scanout_plane;
480
481 /* The last state submitted to the kernel for this CRTC. */
482 struct drm_output_state *state_cur;
483 /* The previously-submitted state, where the hardware has not
484 * yet acknowledged completion of state_cur. */
485 struct drm_output_state *state_last;
486
487 struct drm_fb *dumb[2];
488 pixman_image_t *image[2];
489 int current_image;
490 pixman_region32_t previous_damage;
491
492 struct vaapi_recorder *recorder;
493 struct wl_listener recorder_frame_listener;
494
495 struct wl_event_source *pageflip_timer;
496
497 bool virtual;
498
499 submit_frame_cb virtual_submit_frame;
500};
501
502static inline struct drm_head *
503to_drm_head(struct weston_head *base)
504{
505 return container_of(base, struct drm_head, base);
506}
507
508static inline struct drm_output *
509to_drm_output(struct weston_output *base)
510{
511 return container_of(base, struct drm_output, base);
512}
513
514static inline struct drm_backend *
515to_drm_backend(struct weston_compositor *base)
516{
517 return container_of(base->backend, struct drm_backend, base);
518}
519
520static inline struct drm_mode *
521to_drm_mode(struct weston_mode *base)
522{
523 return container_of(base, struct drm_mode, base);
524}
Daniel Stonefbe6c1d2019-06-17 16:04:26 +0100525
Daniel Stone4c2fc702019-06-18 11:12:07 +0100526struct drm_output *
527drm_output_find_by_crtc(struct drm_backend *b, uint32_t crtc_id);
528
529struct drm_head *
530drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id);
531
Daniel Stone7580b3c2019-06-18 11:16:53 +0100532static inline bool
533drm_view_transform_supported(struct weston_view *ev, struct weston_output *output)
534{
535 struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
536
537 /* This will incorrectly disallow cases where the combination of
538 * buffer and view transformations match the output transform.
539 * Fixing this requires a full analysis of the transformation
540 * chain. */
541 if (ev->transform.enabled &&
542 ev->transform.matrix.type >= WESTON_MATRIX_TRANSFORM_ROTATE)
543 return false;
544
545 if (viewport->buffer.transform != output->transform)
546 return false;
547
548 return true;
549}
550
Daniel Stonefbe6c1d2019-06-17 16:04:26 +0100551int
552drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode);
553
554struct drm_mode *
555drm_output_choose_mode(struct drm_output *output,
556 struct weston_mode *target_mode);
557void
558update_head_from_connector(struct drm_head *head,
559 drmModeObjectProperties *props);
560
561void
562drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list);
563
564void
565drm_output_print_modes(struct drm_output *output);
566
567int
568drm_output_set_mode(struct weston_output *base,
569 enum weston_drm_backend_output_mode mode,
570 const char *modeline);
571
Daniel Stone4c2fc702019-06-18 11:12:07 +0100572void
573drm_property_info_populate(struct drm_backend *b,
574 const struct drm_property_info *src,
575 struct drm_property_info *info,
576 unsigned int num_infos,
577 drmModeObjectProperties *props);
Daniel Stonefbe6c1d2019-06-17 16:04:26 +0100578uint64_t
579drm_property_get_value(struct drm_property_info *info,
580 const drmModeObjectProperties *props,
581 uint64_t def);
Daniel Stone4c2fc702019-06-18 11:12:07 +0100582int
583drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane,
584 const drmModeObjectProperties *props);
585void
586drm_property_info_free(struct drm_property_info *info, int num_props);
587
588extern struct drm_property_enum_info plane_type_enums[];
589extern const struct drm_property_info plane_props[];
590extern struct drm_property_enum_info dpms_state_enums[];
Ankit Nautiyala344fe32019-05-14 18:36:08 +0530591extern struct drm_property_enum_info content_protection_enums[];
592extern struct drm_property_enum_info hdcp_content_type_enums[];
Daniel Stone4c2fc702019-06-18 11:12:07 +0100593extern const struct drm_property_info connector_props[];
594extern const struct drm_property_info crtc_props[];
595
596int
597init_kms_caps(struct drm_backend *b);
598
599int
600drm_pending_state_test(struct drm_pending_state *pending_state);
601int
602drm_pending_state_apply(struct drm_pending_state *pending_state);
603int
604drm_pending_state_apply_sync(struct drm_pending_state *pending_state);
605
606void
607drm_output_set_gamma(struct weston_output *output_base,
608 uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
609
610void
611drm_output_update_msc(struct drm_output *output, unsigned int seq);
612void
613drm_output_update_complete(struct drm_output *output, uint32_t flags,
614 unsigned int sec, unsigned int usec);
615int
616on_drm_input(int fd, uint32_t mask, void *data);
617
618struct drm_plane_state *
619drm_output_state_get_existing_plane(struct drm_output_state *state_output,
620 struct drm_plane *plane);
621void
622drm_plane_state_free(struct drm_plane_state *state, bool force);
623void
624drm_output_state_free(struct drm_output_state *state);
625void
626drm_pending_state_free(struct drm_pending_state *pending_state);
Daniel Stone7580b3c2019-06-18 11:16:53 +0100627
628struct drm_fb *
629drm_fb_ref(struct drm_fb *fb);
630void
631drm_fb_unref(struct drm_fb *fb);
632
633struct drm_fb *
634drm_fb_create_dumb(struct drm_backend *b, int width, int height,
635 uint32_t format);
636struct drm_fb *
637drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
638 bool is_opaque, enum drm_fb_type type);
Daniel Stone6b466f22019-06-18 11:30:54 +0100639
Stefan Agnerccf24072019-07-09 22:02:00 +0200640#ifdef BUILD_DRM_GBM
641extern struct drm_fb *
642drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev);
643#else
644static inline struct drm_fb *
645drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
646{
647 return NULL;
648}
649#endif
Daniel Stone6b466f22019-06-18 11:30:54 +0100650
651struct drm_pending_state *
652drm_pending_state_alloc(struct drm_backend *backend);
653void
654drm_pending_state_free(struct drm_pending_state *pending_state);
655struct drm_output_state *
656drm_pending_state_get_output(struct drm_pending_state *pending_state,
657 struct drm_output *output);
658
659
660/**
661 * Mode for drm_output_state_duplicate.
662 */
663enum drm_output_state_duplicate_mode {
664 DRM_OUTPUT_STATE_CLEAR_PLANES, /**< reset all planes to off */
665 DRM_OUTPUT_STATE_PRESERVE_PLANES, /**< preserve plane state */
666};
667
668struct drm_output_state *
669drm_output_state_alloc(struct drm_output *output,
670 struct drm_pending_state *pending_state);
671struct drm_output_state *
672drm_output_state_duplicate(struct drm_output_state *src,
673 struct drm_pending_state *pending_state,
674 enum drm_output_state_duplicate_mode plane_mode);
675void
676drm_output_state_free(struct drm_output_state *state);
677struct drm_plane_state *
678drm_output_state_get_plane(struct drm_output_state *state_output,
679 struct drm_plane *plane);
680struct drm_plane_state *
681drm_output_state_get_existing_plane(struct drm_output_state *state_output,
682 struct drm_plane *plane);
683
684
685
686struct drm_plane_state *
687drm_plane_state_alloc(struct drm_output_state *state_output,
688 struct drm_plane *plane);
689struct drm_plane_state *
690drm_plane_state_duplicate(struct drm_output_state *state_output,
691 struct drm_plane_state *src);
692void
693drm_plane_state_free(struct drm_plane_state *state, bool force);
694void
695drm_plane_state_put_back(struct drm_plane_state *state);
696bool
697drm_plane_state_coords_for_view(struct drm_plane_state *state,
Daniel Stone2cb926c2019-11-11 16:48:54 +0000698 struct weston_view *ev);
Daniel Stonee404b722019-06-22 18:40:31 +0100699
700void
701drm_assign_planes(struct weston_output *output_base, void *repaint_data);
702
703bool
704drm_plane_is_available(struct drm_plane *plane, struct drm_output *output);
Stefan Agner3654c672019-07-09 00:50:30 +0200705
706void
707drm_output_render(struct drm_output_state *state, pixman_region32_t *damage);
708
709int
710parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format);
711
712extern struct gl_renderer_interface *gl_renderer;
713
714#ifdef BUILD_DRM_VIRTUAL
715extern int
716drm_backend_init_virtual_output_api(struct weston_compositor *compositor);
717#else
718inline static int
719drm_backend_init_virtual_output_api(struct weston_compositor *compositor)
720{
721 return 0;
722}
723#endif
724
Stefan Agnerccf24072019-07-09 22:02:00 +0200725#ifdef BUILD_DRM_GBM
726int
727init_egl(struct drm_backend *b);
728
Stefan Agner3654c672019-07-09 00:50:30 +0200729int
730drm_output_init_egl(struct drm_output *output, struct drm_backend *b);
Stefan Agnerccf24072019-07-09 22:02:00 +0200731
Stefan Agner3654c672019-07-09 00:50:30 +0200732void
733drm_output_fini_egl(struct drm_output *output);
734
Stefan Agnerccf24072019-07-09 22:02:00 +0200735struct drm_fb *
736drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage);
737
738void
739renderer_switch_binding(struct weston_keyboard *keyboard,
740 const struct timespec *time, uint32_t key, void *data);
741#else
742inline static int
743init_egl(struct drm_backend *b)
744{
745 weston_log("Compiled without GBM/EGL support\n");
746 return -1;
747}
748
749inline static int
750drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
751{
752 return -1;
753}
754
755inline static void
756drm_output_fini_egl(struct drm_output *output)
757{
758}
759
760inline static struct drm_fb *
761drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
762{
763 return NULL;
764}
765
766inline static void
767renderer_switch_binding(struct weston_keyboard *keyboard,
768 const struct timespec *time, uint32_t key, void *data)
769{
770 weston_log("Compiled without GBM/EGL support\n");
771}
772#endif