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