Commit Graph

1698 Commits

Author SHA1 Message Date
Simon Ser c6d8a11d2c backend/drm: fetch current CRTC once on startup
Once we are DRM master, the CRTC cannot be changed behind our back
except during a VT switch.

After a VT switch, we try to restore whatever KMS state we had last
programmed. Reloading the current CRTC from KMS breaks this and
can result in a modeset without a FB.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3432
2022-10-19 00:23:18 +00:00
Simon Ser b475190327 backend/drm: log failures in drm_surface_blit()
Can make issues like [1] easier to debug.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3451
2022-10-18 16:39:22 +02:00
Simon Ser a2063c93ea backend/drm: drop drm_crtc_page_flip()
Inline it in drm_connector_commit_state(). Brings us a step closer
to unifying the test code-path and the commit code-path.
2022-10-17 17:39:41 +02:00
Simon Ser 0c962c98cc backend/drm: log when restoring mode after VT switch fails
Can make it easier to track down issues.
2022-10-17 15:14:02 +00:00
Simon Ser 98a83ce14c backend/drm: fix EINVAL atomic commits after VT switch
The drm_connector_commit_state() call in handle_session_active()
was not resulting in any atomic commit, because it didn't match any
of the if branches: active = true, no new buffer was committed,
and adaptive sync/gamma LUT were unchanged. Thus the commit was a
no-op.

Later on, when the compositor performs regular page-flips, the
kernel would return EINVAL indicating that a modeset was needed.

Rework the logic to use a non-blocking page-flip commit if a buffer
was committed, and use a blocking commit if the connector is on or
is being disabled. The only case where we should skip the atomic
commit is when disabling (active = false) an already-disabled
connector (conn->crtc == NULL).

Note, 6936e163b5 ("backend/drm: short-circuit no-op commits")
has introduced early returns for other situations where we don't
need to perform an atomic commit (e.g. updating scale or transform
of an output).

Fixes: f216e97983 ("backend/drm: drop drm_connector_set_mode()")
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3432
2022-10-17 15:14:02 +00:00
Simon Ser ca432ea539 backend/drm: extract current mode logic into separate function
Extract the logic to fetch the current mode to a separate function
to make it more readable. Stop dying in an assert when
get_drm_prop_blob() fails. Always make it so the drmModeModeInfo
pointer is allocated so that we can free() it unconditionally.
2022-10-17 11:36:58 +02:00
Simon Ser eeb7a81138 backend/drm: extract connect_drm_connector() logic
We already have disconnect_drm_connector() to handle the
CONNECTED → DISCONNECTED transition. Let's add
connect_drm_connector() to handle DISCONNECTED → CONNECTED. This
makes scan_drm_connectors() shorter and easier to follow.

No functional change, literally just moving code around.
2022-10-15 12:20:55 +02:00
Simon Ser 9560a7eefd backend/drm: use atomic API to fetch current connector's CRTC
We were using the legacy API (with a detour through drmModeEncoder)
to find out the current CRTC for a connector. Use the atomic API
when available.

Also extract the whole logic into a separate function for better
readability, and better handle errors.
2022-10-14 15:13:14 +00:00
Simon Ser 0c0cea0258 backend/drm: use wl_container_of() instead of casts for wlr_drm_mode
Instead of casting a wlr_output_mode to wlr_drm_mode, use
wl_container_of() for slightly better type safety.
2022-10-13 16:11:39 +00:00
Alexander Orzechowski ada6f104e6 backend/drm/legacy: Fix whitespace
This confused me while reading through.
2022-10-13 10:51:11 -04:00
Simon Ser a28caf08e3 backend: use global output name counters
The output names must be globally unique per the Wayland spec, even
if the compositor creates multiple backends of the same kind.
2022-10-13 13:12:43 +02:00
Simon Ser f216e97983 backend/drm: drop drm_connector_set_mode()
Instead of special-casing modesets, we can just cut the wrapper
and directly call drm_crtc_page_flip(). drm_connector_test() should
already have the checks previously done in drm_connector_set_mode(),
all we need to do is update enabled/mode after a successful atomic
commit.
2022-10-10 07:48:25 +00:00
Simon Zeni 694e9bbb9d backend/drm: allocate connector CRTC on lease creation
This was leading to crash in compositors if the wanted connector had no CRTC
2022-10-07 15:54:51 -04:00
Simon Ser f4cf0a8d86 backend/drm: nuke wlr_drm_connector.desired_enabled
This field becomes stale too easily: for instance, see 6adca4089c
("backend/drm: don't unconditionally set desired_enabled").
Additionally, drm_connector_alloc_crtc() needs to do some weird
dance, restoring its previous value.

Instead, add a connector arg to realloc_crtcs() to indicate a new
connector we want to enable.
2022-10-07 16:28:36 +00:00
Simon Ser 5a207aea72 backend/drm: drop unnecessary wlr_drm_connector.crtc checks
drm_connector_alloc_crtc() already checks this.
2022-10-07 16:09:05 +00:00
Simon Ser 6832ae14aa render: drop wlr_renderer_read_pixels() flags
These are unused.
2022-10-04 09:15:19 +02:00
Simon Ser 0613fb0159 backend/drm: remove outdated TODO
This has been addressed in 8795dde94e ("Initialize connectors
current mode to the mode used by KMS on startup.").
2022-10-03 12:07:10 +02:00
Simon Ser 6adca4089c backend/drm: don't unconditionally set desired_enabled
We were unconditonally setting desired_enabled = true for all
connected connectors. This makes realloc_crtcs() always keep a CRTC
active for these, even if the user doesn't want to enable them.
2022-10-03 12:04:12 +02:00
Simon Ser 651c876e79 backend/drm: fix missing wlr_output_state.allow_artifacts
Without allow_artifacts, applying the new state will fail because
it requires ALLOW_MODESET.

Fixes VT switch and disabling CRTCs.
2022-09-30 13:35:07 +02:00
Simon Ser a0345f2854 output: add wlr_output_state.allow_artifacts
When starting up, the compositor might call wlr_output_set_mode()
with a mode which is already the current one. wlroots will detect
this and make the wlr_output_set_mode() call a no-op. During the
next wlr_output_commit() call, wlroots will perform an atomic
commit without the ALLOW_MODESET flag.

This is an issue, because some drivers need ALLOW_MODESET even if
the mode is the same. For instance, if the FB stride or modifier
changed, some drivers require a modeset.

Add a new flag "allow_artifacts" which is set when the compositor
calls mode-setting functions. Use this flag to figure out whether
we want to perform atomic commits with ALLOW_MODESET.

(The name "allow_artifacts" is picked because ALLOW_MODESET is a
misnomer, see [1].)

[1]: https://patchwork.freedesktop.org/patch/505107/

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3499
2022-09-30 10:58:17 +00:00
John Lindgren 2b767fe743 backend/libinput: Fix SIGSEGV found in low-memory fuzzing
Stack trace:

    #0  0x00007f17081f5b99 in wl_list_insert (list=list@entry=0x2d8, elm=elm@entry=0x7ffe7f7e85d0)
        at ../wayland-1.21.0/src/wayland-util.c:48
    #1  0x00007f17081f5f2e in wl_signal_emit_mutable (signal=signal@entry=0x2d8, data=data@entry=0x7ffe7f7e8660)
        at ../wayland-1.21.0/src/wayland-server.c:2167
    #2  0x00007f170815a971 in handle_switch_toggle (wlr_switch=0x2a0, event=0x55d5ba13dc00)
        at ../backend/libinput/switch.c:50
    #3  handle_libinput_event (event=0x55d5ba13dc00, backend=0x55d5b975d740) at ../backend/libinput/events.c:234
    #4  handle_libinput_readable (fd=<optimized out>, mask=<optimized out>, _backend=<optimized out>)
        at ../backend/libinput/backend.c:58
    #5  handle_libinput_readable (fd=fd@entry=34, mask=mask@entry=1, _backend=_backend@entry=0x55d5b975d740)
        at ../backend/libinput/backend.c:48
    #6  0x00007f170815c110 in backend_start (wlr_backend=0x55d5b975d740) at ../backend/libinput/backend.c:109
    #7  0x00007f1708160996 in multi_backend_start (wlr_backend=0x55d5b97583d0) at ../backend/multi/backend.c:32
2022-09-22 13:37:32 -04:00
Simon Ser 0cabc83046 backend/drm: pass through mode picture aspect ratio 2022-09-22 09:38:27 +02:00
Simon Ser 800ea7d52d backend/drm: de-duplicate wlr_drm_mode creation
Introduce a function to convert a drmModeModeInfo into a new
wlr_drm_mode.
2022-09-21 01:35:30 +00:00
vanfanel 4ffc97d134 Only set max_bpc when full modesetting is being done. 2022-09-16 14:15:58 +00:00
vanfanel 8795dde94e Initialize connectors current mode to the mode used by KMS on startup. 2022-09-16 14:15:58 +00:00
Simon Ser 4cc5bdc4d1 backend/wayland: drop output_set_custom_mode()
It's an unnecessary wrapper.
2022-09-08 14:18:40 +02:00
Isaac Freund 135e60ff82 backend/x11: report adaptive sync as enabled
All we can do to influence adaptive sync on the X11 backend is set the
_VARIABLE_REFRESH window property like mesa automatically does. We don't
have any control beyond that, so we set the state to enabled on creating
the output and never allow changing it (just like the Wayland backend).
2022-08-30 17:53:50 +00:00
Isaac Freund 2ec27d23e0 backend/wayland: report adaptive sync as enabled
Adaptive sync is effectively always enabled when using the Wayland
backend. This is not something we have control over, so we set the
state to enabled on creating the output and never allow changing it.
2022-08-30 17:53:50 +00:00
Simon Ser 8c70245d5f output: fail commits if adaptive sync cannot be enabled
Previously, adaptive sync was just a hint and wouldn't make any
atomic commit fail if the backend didn't support it. The main reason
is wlr_output_test wasn't supported at the time.

Now that we have a way for compositors to test whether a change can
work, let's remove the exception for adaptive sync and convert it to
a regular output state field.
2022-08-30 17:53:50 +00:00
Alexander Orzechowski 8bd7170fd9 Use env helpers 2022-08-22 10:18:52 -04:00
Alexander Orzechowski ef4baea0e2 Use wl_signal_emit_mutable 2022-08-18 07:16:16 -04:00
Simon Ser 8c3c6987db backend/wayland: fix touch device not added on startup
We were firing the new_input signal on backend initialization,
before the compositor had the chance to add a listener for it.

Mimick what's done for wl_keyboard: if the backend hasn't been
started, delay wl_touch initialization.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3473
2022-08-11 09:13:08 +02:00
Simon Ser f244094682 backend/drm: drop enum wlr_drm_connector_status
We can just use libdrm's drmModeConnection enum instead.
2022-08-10 14:19:58 +00:00
Simon Ser 08973d2430 backend/drm: drop WLR_DRM_CONN_NEEDS_MODESET
- Add wlr_output.enabled checks to CONNECTED checks
- Replace NEEDS_MODESET with CONNECTED
2022-08-10 14:19:58 +00:00
Simon Ser 7b5e890e61 backend/drm: use drmModeConnectorGetPossibleCrtcs
This function has been merged in libdrm.

References: 3ee004ef52
2022-07-25 17:28:33 +00:00
Simon Ser bd587a7f43 backend/drm: use drmModeGetConnectorTypeName
No need to manually maintain this table now.

The wlroots names and the libdrm (= kernel) names all match.

References: 50f8d51773
2022-07-25 17:28:33 +00:00
José Expósito 11f49b6b6a backend/wayland: handle high-res scroll events
Receive high-resolution scroll events from the parent compositor using
a Wayland listiner and emit the appropiate wlr_pointer signal.
2022-07-11 11:01:35 +02:00
José Expósito e00f042f80 backend/libinput: code style consistency
Reduce a level of identation in "handle_pointer_axis" to keep the
consistency with "handle_pointer_axis_value120".
2022-07-11 11:01:35 +02:00
José Expósito c6032d6b1c backend/libinput: handle high-res scroll events
On newer versions of libinput, the event LIBINPUT_EVENT_POINTER_AXIS
has been deprecated in favour of LIBINPUT_EVENT_POINTER_SCROLL_WHEEL,
LIBINPUT_EVENT_POINTER_SCROLL_FINGER and
LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS.

Where new events are provided by the backend, ignore
LIBINPUT_EVENT_POINTER_AXIS, receive high-resolution scroll events from
libinput and emit the appropiate wlr_pointer signal.
2022-07-11 11:01:35 +02:00
José Expósito 65c436407f pointer: transform low-res to high-res axis events
Currently, the "wlr_event_pointer_axis" event stores low-resolution
values in its "delta_discrete" field. Low-resolution values are always
multiples of one, i.e., 1 for one wheel detent, 2 for two wheel
detents, etc.

In order to simplify internal handling of events, always transform in
the backend from the low-resolution value into the high-resolution
value.

The transformation is performed by multiplying by 120. The 120 magic
number is used by the kernel and it is exposed to clients in the
"WLR_POINTER_AXIS_DISCRETE_STEP" constant.
2022-07-11 11:01:35 +02:00
José Expósito c84cc660f0 build: check if libinput supports high-res scroll
Starting with Linux Kernel v5.0 two new axes are available for
mice that support high-resolution wheel scrolling: REL_WHEEL_HI_RES and
REL_HWHEEL_HI_RES.

Both axes send data in fractions of 120 where each multiple of 120
amounts to one logical scroll event. Fractions of 120 indicate a wheel
movement less than one detent.

Three new events are now available on libinput:
LIBINPUT_EVENT_POINTER_SCROLL_WHEEL,
LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and
LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS.
These events replace the LIBINPUT_EVENT_POINTER_AXIS event, so new
clients should simply ignore that event.

Also, two new APIs are available to access the high-resolution data:
libinput_event_pointer_get_scroll_value() and
libinput_event_pointer_get_scroll_value_v120().

Add a project argument (LIBINPUT_HAS_SCROLL_VALUE120) to allow
building against old versions of libinput or, where high-resolution
scroll is available, support it.
2022-07-11 11:01:35 +02:00
Isaac Freund 91943a68a6 wlr_input_device: remove anon union field
This union is unnecessary since the recent input device refactor and can
now be replaced by wlr_*_from_input_device() functions.
2022-06-21 18:42:07 +00:00
Simon Ser 1d581656c7 backend/drm: set "max bpc" to the max
"max bpc" is a maximum value, the driver is free to choose a
smaller value depending on the bandwidth available.

Some faulty monitors misbehave with higher bpc values. We'll add
a workaround if users get hit by these in practice.

References: https://gitlab.freedesktop.org/wayland/weston/-/issues/612
2022-06-19 16:55:36 +00:00
Simon Ser 1f1c0275be backend/drm: remove unused CRTC count check
drmIsKMS already checks for this.
2022-06-19 16:48:44 +00:00
Isaac Freund 5cca72958a
backend/drm: fix NULL pointer deference due to typo 2022-06-07 17:08:08 +02:00
Simon Ser 1f96f388e9 backend/drm: make serial optional
The EDID 1.4 spec says that the serial number is optional:

> If this field is not used, then enter “00h, 00h, 00h, 00h”.

Leave the wlr_output.serial field NULL in that case, and hide it
from the output description.
2022-06-07 13:27:18 +00:00
Simon Ser 1b27d537d1 backend/drm: unconditionally set "content type" to graphics
CTA-861-G says that "graphics" is used to indicate non-analog (ie,
digital) content. With that bit set, the sink should turn off analog
reconstruction and other related filtering.
2022-06-07 13:21:21 +00:00
Isaac Freund 2b10ae62ad
backend/drm: fix check for no-op commits
Since 6936e163b, we short-circut no-op commits as an optimization.
However, the logic in the check was slightly off.
2022-06-02 20:18:16 +02:00
Simon Ser 6936e163b5 backend/drm: short-circuit no-op commits
Some output commits (changing e.g. the output scale or transform)
don't require any change in the KMS state. Instead of going through
a KMS commit, return early. Blocking KMS commits can be expensive.
2022-06-02 11:46:31 +00:00
Simon Ser acc6d94db0 backend/drm: make commits without a buffer blocking
The wlr_output API requires compositors to wait for wlr_output.frame
before submitting a new buffer. However, compositors can perform a
commit which doesn't involve a buffer anytime.

If the commit is a modeset, we set DRM_MODE_ATOMIC_ALLOW_MODESET and
block until the commit is done. If it isn't, we currently always
perform a non-blocking commit. This is an issue because a previous
page-flip might still be in flight kernel-side, returning EBUSY.

Fix this by using blocking commits when a buffer isn't submitted by
the compositor.

Closes: https://github.com/swaywm/sway/issues/6962
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/2239
2022-06-01 21:16:02 +02:00
Simon Ser 2563b79dc2 backend/drm: improve atomic commit flag logging
We weren't logging all of the flags, which made debugging more
difficult.
2022-05-31 09:31:16 +02:00
Simon Ser 25dd3cc0cd output: pass wlr_output_state to backend
Groundwork for the following commits. The goal is to allow users
to specify their own wlr_output_state instead of wlr_output.pending.
2022-05-30 11:34:57 +02:00
Simon Ser 4f5d6e4746 backend/x11: fix output model strdup call
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3434#note_1401193
Fixes: be86145322 ("output: turn make/model/serial into char *")
2022-05-27 13:21:50 +00:00
vaxerski d0d480b91a backend/drm: fix crash with null serial
backend/drm: use serial_str instead
2022-05-26 18:16:29 +02:00
Simon Ser be86145322 output: turn make/model/serial into char *
This allows the make/model/serial to be NULL when unset, and allows
them to be longer than the hardcoded array length.

This is a breaking change: compositors need to handle the new NULL
case, and we stop setting make/model to useless "headless" or
"wayland" strings.
2022-05-26 13:36:06 +00:00
Simon Ser 2e69eb1030 backend/drm: fix crash in init_drm_surface
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3434
2022-05-26 09:38:48 +02:00
Simon Ser f91f38b79a backend/drm: remove wlr_drm_surface.{width,height}
This information is stored in wlr_swapchain, no need to duplicate
it.
2022-05-25 15:55:41 +02:00
Simon Ser e59f4d4ffa backend/drm: allow non-linear modifiers for multi-GPU
Prior to [1], if an entry in a DRM format set was different than a
single LINEAR modifier, implicit modifiers were always allowed. This
has changed and now implicit modifiers are only allowed if INVALID
is in the list of modifiers.

So now we can safely enable explicit modifiers for cross-GPU imports,
without risking receiving buffers with an implicit modifier. This
should improve perf a bit on setups where two GPUs from the same vendor
are used.

This fixes the first bullet point from [2].

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3231
[2]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3331
2022-05-24 20:45:55 +00:00
Simon Ser e646d882cf backend/drm: fetch EDID manufacturer from udev_hwdb
Maintaining our internal table up-to-date is tedious: one needs to
manually go through the PnP ID registry [1] and check whether we're
missing any entry.

udev_hwdb already has an API to fetch a manufacturer name from its
PnP ID. Use that instead.

[1]: https://uefi.org/pnp_id_list
2022-05-11 14:06:11 +00:00
Simon Ser 7b7562eb65 backend/headless: allow variable refresh rate
Instead of waking up each 16ms to emit a frame event, arm the timer
when the output is committed. This allows the headless backend to
idle when nothing changes on screen, and behaves similarly to the
other backends.
2022-05-10 16:37:21 +00:00
Kirill Primak bc4350c976 backend/wayland: reset active pointer on destroy 2022-04-29 21:55:04 +03:00
Simon Ser a1e1e9aba8 Revert "backend/wayland: zero out finished input devices"
This reverts commit 03c88b07ba.

init functions now zero out the structs.
2022-04-28 10:09:50 +02:00
Simon Ser 6c350799b2 Zero-initialize structs in init functions
Ensures there is no field left to its previous undefined value after
calling an init function.
2022-04-28 10:09:50 +02:00
Kirill Primak 03c88b07ba backend/wayland: zero out finished input devices 2022-04-22 17:51:24 +00:00
Kirill Primak a43d105a50 backend/wayland/pointer: fix indentation 2022-04-22 17:51:24 +00:00
Alexander Orzechowski 2ce0305483 seat: Don't finish wlr_keyboard if server was never started 2022-04-22 01:49:58 +00:00
Simon Zeni aaf787ee56 types/wlr_touch: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni e732c5c895 types/wlr_tablet_tool: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni d1f543a9d8 types/wlr_tablet_pad: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni 13d7fa2f03 types/wlr_switch: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni 9a17200446 types/wlr_keyboard: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni bd6c000d14 types/wlr_pointer: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni 96ccc50c57 types/wlr_input_device: move width_mm and height_mm fields to wlr_tablet and wlr_touch 2022-03-17 13:44:19 -04:00
Simon Zeni a92e5f8d46 types/wlr_input_device: move output_name field to wlr_pointer and wlr_touch 2022-03-17 13:44:18 -04:00
Simon Zeni 2001441a37 backend/wayland: remove wl_seat_listener from public API 2022-03-17 17:16:47 +00:00
Simon Zeni b7e9ad7989 backend/wayland: remove wlr_wl_input_device 2022-03-17 17:16:47 +00:00
Simon Zeni 56f7c000b5 backend/wayland/tablet_v2: give wlr_tablet_* ownership to wlr_wl_seat 2022-03-17 17:16:47 +00:00
Simon Zeni d3fb44314c backend/wayland: give wlr_touch ownership to wlr_wl_seat 2022-03-17 17:16:47 +00:00
Simon Zeni e723dd928b backend/wayland: drop wlr_switch support 2022-03-17 17:16:47 +00:00
Simon Zeni be8527bd36 backend/wayland: give wlr_pointer ownership to wlr_wl_seat
All the code logic related to the pointer has been moved to its own file.

The seat is responsible for the lifetime of its wlr_wl_pointer(s), and assigning
them to the relevant wlr_wl_output. The wlr_wl_pointer becomes a simple helper
to manager the wlr_pointer associated to the seat's wl_pointer and its lifetime.
2022-03-17 17:16:47 +00:00
Simon Zeni f9b6aa3079 backend/wayland: give wlr_keyboard ownership to wlr_wl_seat 2022-03-17 17:16:47 +00:00
Samuel Čavoj 5c17452ae0
Pass O_CLOEXEC to drmModeCreateLease calls
The lease_fd is currently being leaked to child processes

Link: https://github.com/swaywm/sway/issues/4286#issuecomment-1065987957
2022-03-13 13:28:48 +01:00
David96 7a2c96dcbd types/wlr_tablet_tool: remove name ambiguity
It wasn't clear in the backend whether to use name or base.name, change
it so base.name has to be used.

Fixes https://github.com/swaywm/sway/issues/6884
2022-03-11 11:49:41 +01:00
Simon Zeni cfed039c9a types/wlr_input_device: move init and finish function to private API 2022-03-07 16:37:41 +00:00
Simon Zeni 1bb2631c5c types/wlr_input_device: remove wlr_input_device_destroy 2022-03-07 16:37:41 +00:00
Simon Zeni 10cbb9fbe1 interface/wlr_touch: rework destroy sequence
The destroy callback in wlr_touch_impl has been removed. The function
`wlr_touch_finish` has been introduced to clean up the resources owned by a
wlr_touch.

`wlr_input_device_destroy` no longer destroys the wlr_touch, attempting to
destroy a wlr_touch will result in a no-op.

The field `name` has been added to the wlr_touch_impl to be able to identify
a given wlr_touch device.
2022-03-07 16:37:41 +00:00
Simon Zeni 8d3cb94b41 interface/wlr_tablet_tool: rework destroy sequence
The destroy callback in wlr_tablet_tool_impl has been removed. The function
`wlr_tablet_tool_finish` has been introduced to clean up the resources owned by
a wlr_tablet_tool.

`wlr_input_device_destroy` no longer destroys the wlr_tablet_tool, attempting to
destroy a wlr_tablet_tool will result in a no-op.

The field `name` has been added to the wlr_tablet_tool_impl to be able to
identify a given wlr_tablet_tool device.
2022-03-07 16:37:41 +00:00
Simon Zeni a5b032cb1e interface/wlr_tablet_pad: rework destroy sequence
The destroy callback in wlr_tablet_pad_impl has been removed. The function
`wlr_tablet_pad_finish` has been introduced to clean up the resources owned by a
wlr_tablet_pad.

`wlr_input_device_destroy` no longer destroys the wlr_tablet_pad, attempting to
destroy a wlr_tablet_pad will result in a no-op.

The field `name` has been added to the wlr_tablet_pad_impl to be able to identify
a given wlr_tablet_pad device.
2022-03-07 16:37:41 +00:00
Simon Zeni 0d2be496a8 interface/wlr_switch: rework destroy sequence
The destroy callback in wlr_switch_impl has been removed. The function
`wlr_switch_finish` has been introduced to clean up the resources owned by a
wlr_switch.

`wlr_input_device_destroy` no longer destroys the wlr_switch, attempting to
destroy a wlr_switch will result in a no-op.

The field `name` has been added to the wlr_switch_impl to be able to identify
a given wlr_switch device.
2022-03-07 16:37:41 +00:00
Simon Zeni 51cd3c0726 interface/wlr_pointer: rework destroy sequence
The destroy callback in wlr_pointer_impl has been removed. The function
`wlr_pointer_finish` has been introduced to clean up the resources owned by a
wlr_pointer.

`wlr_input_device_destroy` no longer destroys the wlr_pointer, attempting to
destroy a wlr_pointer will result in a no-op.

The field `name` has been added to the wlr_pointer_impl to be able to identify
a given wlr_pointer device.
2022-03-07 16:37:41 +00:00
Simon Zeni 7dc4a3ecd7 interface/wlr_keyboard: rework destroy sequence
The destroy member in wlr_keyboard_impl has been removed. The function
`wlr_keyboard_finish` has been introduce to clean up the resources owned by a
wlr_keyboard.

`wlr_input_device_destroy` no longer destroys the wlr_keyboard, attempting to
destroy a wlr_keyboard will result in a no-op.

The field `name` has been added to the wlr_keyboard_impl to be able to identify
a given wlr_keyboard device.
2022-03-07 16:37:41 +00:00
Simon Zeni d0718a9b32 backend/libinput: public API cleanup 2022-03-02 18:18:05 +00:00
Simon Zeni 0d21496e53 backend/libinput: rework tablet_pad interface
The wlr_libinput_input_device now owns its wlr_tablet_pad, instead of creating
a new wlr_libinput_input_device for it.
2022-03-02 18:18:05 +00:00
Simon Zeni c8456086a1 backend/libinput: rework tablet interface
The wlr_libinput_device owns its wlr_tablet and its associated wlr_tablet_tools
2022-03-02 18:18:05 +00:00
Simon Zeni 4f4dd95223 backend/libinput: rework touch interface
The wlr_libinput_input_device now owns its wlr_touch, instead of creating
a new wlr_libinput_input_device for it.
2022-03-02 18:18:05 +00:00
Simon Zeni d750c5ac67 backend/libinput: rework switch interface
The wlr_libinput_input_device now owns its wlr_switch, instead of creating
a new wlr_libinput_input_device for it.
2022-03-02 18:18:05 +00:00
Simon Zeni d60cdad3ea backend/libinput: rework pointer interface
The wlr_libinput_input_device now owns its wlr_pointer, instead of creating
a new wlr_libinput_input_device for it
2022-03-02 18:18:05 +00:00
Simon Zeni 5eefda1ffe backend/libinput: rework keyboard interface
The wlr_libinput_input_device now owns its wlr_keyboard, instead of creating
a new wlr_libinput_input_device for it.
2022-03-02 18:18:05 +00:00
Simon Zeni 9dd6e2b905 backend/libinput: add devices wl_list
This commit prepares the ground for a wlr_libinput_input_device refactoring.
2022-03-02 18:18:05 +00:00
Simon Zeni e279266f71 interfaces: remove wlr_input_device_impl 2022-02-22 14:23:46 -05:00
Simon Zeni 91ba28e020 backend/libinput: remove wlr_input_device_impl 2022-02-21 16:48:43 -05:00
Simon Zeni 887516d004 backend/wayland: remove wlr_input_device_impl 2022-02-21 16:48:43 -05:00
Simon Zeni 19f7e5d2b4 backend/x11: remove wlr_input_device_impl 2022-02-21 13:53:40 -05:00
Simon Zeni edfb332b24 types/wlr_touch: add base wlr_input_device
wlr_touch now owns its wlr_input_device. It will be initialized when the
tablet tool is initialized, and finished when the touch is destroyed.
2022-02-21 17:11:32 +00:00
Simon Zeni 7dfee50350 types/wlr_tablet_tool: add base wlr_input_device
wlr_tablet_tool owns its wlr_input_device. It will be initialized when the
tablet tool is initialized, and finished when the tablet tool is destroyed.
2022-02-21 17:11:32 +00:00
Simon Zeni a662743610 types/wlr_tablet_pad: add base wlr_input_device
wlr_tablet_pad owns its wlr_input_device. It will be initialized when the
tablet pad is initialized, and finished when the tablet pad is destroyed.
2022-02-21 17:11:32 +00:00
Simon Zeni 0f3b38365d types/wlr_switch: add base wlr_input_device
wlr_switch owns its wlr_input_device. It will be initialized when the
switch is initialized, and finished when the switch is destroyed.
2022-02-21 17:11:32 +00:00
Simon Zeni d5480efc7a types/wlr_pointer: add base wlr_input_device
wlr_pointer owns its wlr_input_device. It will be initialized when the
pointer is initialized, and finished when the pointer is destroyed.
2022-02-21 17:11:32 +00:00
Simon Zeni a1978b1299 types/wlr_keyboard: add base wlr_input_device
wlr_keyboard owns its base wlr_input_device. It will be initialized when the
keyboard is initialized, and finished when the keyboard is destroyed.
2022-02-21 17:11:32 +00:00
Simon Zeni 71577e351e types/wlr_input_device: default vendor and product id to 0
vendor and product id are set when needed by the libinput backend
2022-02-21 17:11:32 +00:00
Simon Zeni 7d560df90e backend/headless: remove unused wlr_headless_input_device 2022-02-21 17:11:32 +00:00
Simon Ser ec28457508 backend: error out in autocreate without libinput support
The libinput backend is now optional. However, this means that a
user building wlroots without the correct libinput dependencies
will end up with a compositor which doesn't respond to input events.

wlr_backend_autocreate is supposed to return a sensible setup, so in
this case let's just error out and explain what happened. Users can
suppress the check by setting WLR_LIBINPUT_NO_DEVICES=1 (already used
to suppress the zero input device case inside the libinput backend).

Compositors which really want to create a bare DRM backend can easily
create it manually instead of using wlr_backend_autocreate.
2021-12-20 13:56:09 +00:00
Simon Ser b5a019d575 build: simplify Meson subproject fallbacks
All of these projects use meson.override_dependency() so we can
stop referencing their internal variable name to grab the
depndencies we need.
2021-12-19 18:12:16 +00:00
Simon Ser 9f41627aa1 backend/wayland: add basic linux-dmabuf feedback support
This patch makes it so we bind to zwp_linux_dmabuf_v1 version 4 and
we use it to grab the main device. v4 sends supported formats via a
table so we need to handle this as well.

v4 allows wlroots to remove the requirement for Mesa's internal
wl_drm interface.
2021-12-15 14:34:08 +00:00
Simon Ser bedfec94bb backend/drm: use drmCloseBufferHandle
This has been added in [1] and allows us to close buffer handles
without manually calling drmIoctl.

[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/192
2021-12-14 14:33:00 +01:00
Simon Ser a15c327718 backend/drm: use drmModeFormatModifierBlobIterNext
This avoids open-coding our own logic. The resulting code is more
readable.

References: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/146
2021-12-14 13:21:09 +00:00
Chris Chamberlain d8ca494558 backend/drm: add wlr_drm_backend_monitor
This helper is responsible for listening for new DRM devices and
create new child DRM backends as necessary.
2021-12-13 14:55:16 +01:00
Chris Chamberlain f6d3efbf4b backend: fix return value of attempt_drm_backend
The multi backend was returned instead of the primary DRM backend.
2021-12-13 14:53:41 +01:00
Simon Ser 818fc4a87b Fix incorrect %zd formatting directives
%zd is for ssize_t. For size_t we should use %zu.
2021-12-09 16:42:04 +01:00
Simon Ser 36a2b19485 output: introduce wlr_output_set_name
wlroots picks names for all outputs, but it might be desirable for
compositor to override it.

For instance, Sway will use a headless output as a fallback in
case no outputs are connected. Sway wants to clearly label the
fallback output as such and label "real" headless outputs starting
from HEADLESS-1.
2021-12-09 15:46:46 +01:00
Simon Ser ad28490cf4 build: move wayland-client dep to backend/wayland/
wayland-client isn't really used by wlroots core, so let's move the
dep to where it's needed in the Wayland backend.
2021-12-07 16:11:29 +01:00
Quantum 812ab2e716 Fix uninitialized variable errors in release mode
When using `meson --buildtype=release`, `-Wextra -Werror` is passed.
This includes `-Werror=maybe-uninitialized`, which complains about
the instances fixed in this commit.
2021-12-01 02:39:14 -05:00
Moon Sungjoon 611b9ca843 backend/wayland: improve wayland input device name
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3332
This makes input device names include it's type name
2021-11-30 22:06:14 +00:00
Simon Ser fbaefd90fc backend/drm: poison buffers which cannot be scanned out
Rather than repeatedly trying to import DMA-BUFs which cannot be
scanned out, mark the failed ones with a special "poison" marker.
Inspired from [1].

[1]: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/731
2021-11-29 14:32:29 +00:00
Simon Ser ef1669d33e backend/drm: always add LINEAR to supported modifiers 2021-11-26 16:40:53 +00:00
Simon Ser e163a7cf48 backend/drm: fail on explicit modifier in drmModeAddFB2
drmModeAddFB2 doesn't support explicit modifiers. Only accept INVALID
which indicates an implicit modifier and LINEAR which may indicate
that GBM_BO_USE_LINEAR has been used.
2021-11-26 16:40:53 +00:00
Simon Ser affe9eda57 Require INVALID for implicit format modifiers
See [1] for the motivation.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/75
2021-11-26 16:40:53 +00:00
Simon Zeni 1d3dd7fc08 backend: remove noop backend 2021-11-25 16:49:05 +00:00
Simon Ser b234edcf58 backend/headless: drop wlr_headless_backend_create_with_renderer
The headless backend no longer needs a parent renderer: it no longer
needs to return it in wlr_backend_impl.get_renderer, nor does it
need to return its DRM FD in wlr_backend_impl.get_drm_fd. Drop this
function altogether since it now behaves exactly like
wlr_headless_backend_create.
2021-11-25 16:16:04 +01:00
Simon Ser f29abe4c77 backend/headless: stop picking a DRM FD
Sometimes the headless backend is used standalone with the Pixman
renderer, sometimes it's used together with another backend which
has already picked a DRM FD. In both of these cases it doesn't make
sense to pick a DRM FD.

Broadly speaking the headless backend doesn't really care which DRM
device is used for the buffers it receives. So it doesn't really
make sense to tie it to a particular DRM device.

Let the backend users (e.g. wlr_renderer_autocreate) open an arbitrary
DRM FD as needed instead.
2021-11-25 15:12:32 +00:00
Simon Ser 1d9c1bcea6 input-device: remove wlr_input_device.link
This field's ownership is unclear: it's in wlr_input_device, but
it's not managed by the common code, it's up to each individual
backend to use it and clean it up.

Since this is a backend implementation detail, move it to the
backend-specific structs.
2021-11-23 14:14:18 +00:00
Simon Ser 3b93da70a0 backend/wayland: report parent presentation clock
There's no guarantee that the parent Wayland compositor uses
CLOCK_MONOTONIC for reporting presentation timestamps, they could
be using e.g. CLOCK_MONOTONIC_RAW or another system-specific clock.

Forward the value via wlr_backend_impl.get_presentation_clock.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3254#note_1143061
2021-11-22 19:31:59 +01:00
Simon Ser e656697a7d backend/drm: scan leases on uevent
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3181
2021-11-19 16:06:07 +00:00
Simon Ser 86f5ecf468 backend/drm: introduce wlr_drm_lease
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3183
2021-11-19 16:06:07 +00:00
Simon Ser a37f538ca0 Introduce WLR_DEVICE_LEASE events
This will allow the DRM backend to reload its lessee list.
2021-11-19 16:06:07 +00:00
Manuel Stoeckl 3d7d6ec06f output: use XRGB8888 format instead of ARGB8888
Most (and possibly all) compositors using wlroots only ever render
fully opaque content. To provide better performance, this change
switches the default format used by wlr_output buffers from
ARGB8888 to the opaque XRGB8888.

Compositors like mutter, kwin, and weston already default to
XRGB8888, so this change is unlikely to expose any new bugs in
underlying drivers and hardware.

This does not affect the hardware cursor's buffer format, which is
still ARGB8888 by default.

As part of this change, the X11 backend (which does not support
changing format at runtime) now picks a true color, 24 bit depth
visual (i.e. XRGB8888) instead of a 32 bit depth (ARGB8888) one.
2021-11-19 15:51:46 +00:00
Simon Zeni c0fd60be63 backend: fix attempt_backend_by_name multi backend self insertion 2021-11-19 10:44:51 -05:00
Simon Zeni 25bb92faee backend/multi: add asserts in wlr_multi_backend_add 2021-11-19 10:44:45 -05:00
Simon Zeni fdf3169b41 backend: remove wlr_backend_get_renderer 2021-11-18 09:37:57 -05:00
Simon Zeni d1ebd52ab2 backend/multi: remove backend_get_renderer 2021-11-18 09:37:57 -05:00
Simon Zeni 42549a1c9a backend/drm: stop initializing backend renderer 2021-11-18 09:37:57 -05:00
Simon Zeni a143093339 backend/headless: don't store the parent renderer 2021-11-18 09:37:57 -05:00
Simon Zeni 5f11198605 backend/x11: get renderer from wlr_x11_output 2021-11-18 09:37:57 -05:00
Simon Zeni 6dc6af1534 backend: remove backend_get_allocator 2021-11-18 09:37:57 -05:00
Simon Zeni 0c76aef202 backend: remove backend ensure renderer and allocator check 2021-11-18 09:37:57 -05:00
Simon Ser a04cfca4da Remove support for DMA-BUF flags
They are never used in practice, which makes all of our flag
handling effectively dead code. Also, APIs such as KMS don't
provide a good way to deal with the flags. Let's just fail the
DMA-BUF import when clients provide flags.
2021-11-17 16:12:59 +00:00
Roman Gilg 8274c85d21 backend/headless: unlink input device on destroy
Removing an input device requires unlinking it from the list of all headless
input devices. For that implement a destroy function.
2021-11-15 12:49:26 +01:00
Simon Ser e13f3f8608 backend/drm: handle per-connector hotplug events
When a connector ID is specified in a hotplug event, don't scan all
connectors. Only scan the connector that has changed.
2021-11-02 13:36:43 +01:00
Simon Ser 2ff4e113e2 backend/session: introduce wlr_device_change_event
This struct contains additional information for session device
change events, such as the DRM connector ID that has changed.
2021-11-02 13:30:51 +01:00
Ronan Pigott 8e225261f0 backend/wayland: use xdga client activation 2021-10-31 10:33:14 +01:00
Simon Ser 83090de034 backend/drm: avoid creating empty FB_DAMAGE_CLIPS prop
drmModeCreatePropertyBlob cannot create zero-sized blobs, that
fails with EINVAL.

Closes: https://github.com/swaywm/wlroots/issues/3297
2021-10-29 15:03:17 +02:00
Simon Ser 0817c52a21 backend/drm: get rid of BO handle table
The BO handle table exists to avoid double-closing a BO handle,
which aren't reference-counted by the kernel. But if we can
guarantee that there is only ever a single ref for each BO handle,
then we don't need the BO handle table anymore.

This is possible if we create the handle right before the ADDFB2
IOCTL, and close the handle right after. The handles are very
short-lived and we don't need to track their lifetime.

Because of multi-planar FBs, we need to be a bit careful: some
FB planes might share the same handle. But with a small check, it's
easy to avoid double-closing the same handle (which wouldn't be a
big deal anyways).

There's one gotcha though: drmModeSetCursor2 takes a BO handle as
input. Saving the handles until drmModeSetCursor2 time would require
us to track BO handle lifetimes, so we wouldn't be able to get rid
of the BO handle table. As a workaround, use drmModeGetFB to turn the
FB ID back to a BO handle, call drmModeSetCursor2 and then immediately
close the BO handle. The overhead should be minimal since these IOCTLs
are pretty cheap.

Closes: https://github.com/swaywm/wlroots/issues/3164
2021-10-29 11:38:37 +02:00
Haelwenn (lanodan) Monnier a92293a15a backend/drm/legacy.c: Fix memory leak in drm_legacy_crtc_set_gamma
Found via scan-build
2021-10-27 07:30:36 -06:00
MarkusVolk ebe3cfaceb backend.c: do not try to explicitly clean up the libinput backend
Since libinput is an optional dependency the libinput backend is possibly undeclared.
wlr_backend_destroy(backend) below will clean up the child libinput backend if any.
2021-10-27 14:54:01 +02:00
Simon Ser cbedbd0fc0 backend/x11: fix code style in get_touchpoint_from_x11_touch_id 2021-10-27 12:08:09 +02:00
Simon Ser 5619cf368b backend/drm: add entry for Valve EDID vendor
As found in e.g. the Steam Deck.
2021-10-26 08:45:30 -06:00
Simon Zeni 70e8277175 backend/multi: implement get_buffer_caps 2021-10-22 22:19:47 +02:00
Anthony Super e22a386319 Add error handling to backend creation
This commit adds two error-handling cases to the function
attempt_dmr_backend. Specifically:

- In the case where the number of found GPUs is zero, we now
  print a log message indicating this and return a NULL pointer
- In the case where we could not successfully create a backend
  on any GPU, we now log a message indicating this and return
  a NULL pointer

This allows us to provide more descriptive error messages,
as well as avoid a SEGFAULT (the function
`ensure_primary_backend_renderer_and_allocator` dereferences the pointer
given, which could be NULL until this patch) when these cases arise.
2021-10-18 14:36:04 +02:00
Kirill Primak 2af8cc769a output: add presented flag to presentation event 2021-10-15 09:38:58 +02:00
Kirill Primak 1089b7b8d6 output: disallow NULL event for wlr_output_send_present() 2021-10-15 09:38:58 +02:00
Jan Beich 31af2b67b0 backend: drop unconditional and unused <libinput.h>
After 70fb21c35b made libinput optional the include prevents
building without libinput package installed.

backend/backend.c:4:10: fatal error: 'libinput.h' file not found
 #include <libinput.h>
          ^~~~~~~~~~~~
2021-10-05 09:11:44 +02:00
Elyes HAOUAS dc3d1530bf Fix spelling errors
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2021-10-02 10:22:13 +02:00
Simon Ser 1d7e438d8a Revert "Require INVALID for implicit format modifiers"
This reverts commit ea7357b703.
2021-10-01 09:26:05 -06:00
Simon Ser 61b83441a1 Revert "backend/drm: fail on explicit modifier in drmModeAddFB2"
This reverts commit d6be1d68b7.
2021-10-01 09:26:05 -06:00
Simon Ser d6be1d68b7 backend/drm: fail on explicit modifier in drmModeAddFB2
drmModeAddFB2 doesn't support explicit modifiers. Only accept INVALID
which indicates an implicit modifier and LINEAR which may indicate
that GBM_BO_USE_LINEAR has been used.
2021-10-01 09:21:50 -06:00
Simon Ser ea7357b703 Require INVALID for implicit format modifiers
See [1] for the motivation.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/75
2021-10-01 09:21:50 -06:00
Simon Ser 3d0848daae backend: create renderer and allocator in wlr_backend_autocreate
Instead of ensuring the renderer and allocator are initialized in each
backend, do it in wlr_backend_autocreate. This allows compositors to
create backends without any renderer/allocator if they side-step
wlr_backend_autocreate.

Since the wlr_backend_get_renderer and backend_get_allocator end up
calling wlr_renderer_autocreate and wlr_allocator_autocreate, it sounds
like a good idea to centralize all of the opimionated bits in one place.
2021-09-30 08:50:43 -06:00
José Expósito 62e62b6942 backend/wayland: send hold gesture events
Receive hold gesture events using a Wayland listiner and emit the
appropiate wlr_pointer signal.
2021-09-27 15:30:31 +02:00
José Expósito 52d2491931 backend/libinput: send hold gesture events
Receive hold gesture events from libinput and emit the appropiate
wlr_pointer signal.
2021-09-27 15:30:31 +02:00
José Expósito 95970b3619 build: check if libinput supports hold gestures
Add a project argument (LIBINPUT_HAS_HOLD_GESTURES) to allow building
against old versions of libinput.
2021-09-27 15:30:31 +02:00
Simon Ser 2e12de96ca backend/drm: add support for panel orientation
Expose the panel orientation with wlr_drm_connector_get_panel_orientation.
Leave it to the compositor to consume this information and configure the
output accordingly.

Closes: https://github.com/swaywm/wlroots/issues/1581
2021-09-21 11:40:37 -06:00
Simon Zeni 94ed8f9496 backend/drm: introduce wlr_drm_backend_get_non_master_fd 2021-09-08 11:09:07 +02:00
Simon Zeni e5a949a955 backend/drm: implement drm lease function 2021-09-08 11:09:07 +02:00
Simon Ser 42dba9dc90 backend/drm: drop wlr_drm_connector.desired_mode
Previously used by attempt_enable_needs_modeset, but this has been
dropped in the previous commit.
2021-09-07 22:33:40 +02:00
Simon Ser b01d97a38f backend/drm: drop attempt_enable_needs_modeset
Modesets require a buffer. The DRM backend tried to auto-enable
outputs when a CRTC becomes available in the past, but now that
fails because no buffer is available.

Instead of having this magic inside the DRM backend, a better
approach is to do it in the compositor or in an optional helper.
2021-09-07 22:33:40 +02:00
muradm 35f0a0d570 backend: wait for session to become active 2021-09-07 20:28:02 +02:00
Simon Ser 0c8fba1a2f backend/drm: drop drm_connector_init_renderer
drm_connector_set_pending_fb already takes care of this.
2021-09-07 15:16:30 +02:00
Simon Ser de1c73021c backend/drm: drop unused arg from get_possible_crtcs
Constify drmModeConnector while at it.
2021-09-07 08:45:08 -04:00
Simon Ser 274c8189d4 backend/drm: fix crash on VT switch
Don't set the MODE flag when disabling a CRTC. This fixes a NULL
pointer dereference in drm_connector_state_init.
2021-09-07 11:34:53 +02:00
Simon Ser 3c74bd0c91 backend/drm: introduce wlr_drm_connector_state
Previously, we were copying wlr_output_state on the stack and
patching it up to be guaranteed to have a proper drmModeModeInfo
stored in it (and not a custom mode). Also, we had a bunch of
helpers deriving DRM-specific information from the generic
wlr_output_state.

Copying the wlr_output_state worked fine so far, but with output
layers we'll be getting a wl_list in there. An empty wl_list stores
two pointers to itself, copying it on the stack blindly results in
infinite loops in wl_list_for_each.

To fix this, rework our DRM backend to stop copying wlr_output_state,
instead add a new struct wlr_drm_connector_state which holds both
the wlr_output_state and additional DRM-specific information.
2021-09-07 11:18:18 +02:00
Simon Ser 3fbf6e02a3 backend/drm: rename enum wlr_drm_connector_state to status
"state" is easily confused with wlr_output_state.
2021-09-07 11:18:18 +02:00
Simon Ser 5aa5137fae backend/drm: handle drm_surface_blit errors
drm_surface_blit returns NULL on error. This can happen e.g. when
the source buffer cannot be imported into EGL.

Closes: https://github.com/swaywm/wlroots/issues/3154
2021-09-03 17:57:38 +02:00
Simon Ser 5dfaf5ea9c backend/drm: introduce wlr_drm_bo_handle_table
Using GBM to import DRM dumb buffers tends to not work well. By
using GBM we're calling some driver-specific functions in Mesa.
These functions check whether Mesa can work with the buffer.
Sometimes Mesa has requirements which differ from DRM dumb buffers
and the GBM import will fail (e.g. on amdgpu).

Instead, drop GBM and use drmPrimeFDToHandle directly. But there's
a twist: BO handles are not ref'counted by the kernel and need to
be ref'counted in user-space [1]. libdrm usually performs this
bookkeeping and is used under-the-hood by Mesa.

We can't re-use libdrm for this task without using driver-specific
APIs. So let's just re-implement the ref'counting logic in wlroots.
The wlroots implementation is inspired from amdgpu's in libdrm [2].

Closes: https://github.com/swaywm/wlroots/issues/2916

[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
[2]: 1a4c0ec9ae/amdgpu/handle_table.c
2021-08-25 10:05:37 -04:00
Simon Ser 3ce2ea9e16 Move allocator stuff into new directory
Add render/allocator/ and include/render/allocator/ to hold
everything allocator-related.
2021-08-25 09:57:20 -04:00
Simon Ser 65c0ab00b6 backend/drm: generate CVT reduced modes
The Coordinated Video Timings (CVT) spec [1] defines two types of
timings: the "CVT standard CRT" timings and the "CVT reduced blanking"
timings (see section 3.6).

The standard CRT timings include pauses in the video stream to allow
CRT displays to reposition their electron beam at the end of each
horizontal scan line [2]. While this was desirable a few decades ago,
nowadays we can just generate a CVT reduced blanking timing by default.
wlroots users can still set full custom DRM modes via
wlr_drm_connector_add_mode.

[1]: https://glenwing.github.io/docs/VESA-CVT-1.2.pdf
[2]: https://en.wikipedia.org/wiki/Coordinated_Video_Timings#Reduced_blanking
2021-08-25 08:37:35 +02:00
Rouven Czerwinski 9b7803a9b3 backend/drm: try to allocate crtc for formats
To retrieve the formats, an allocated crtc is required. If there is no
currently no crtc available, try to allocate it. This reproducable by
having a disabled output and going through a suspend cycle with amdgpu.
On start CRTCs look like this:

  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1099] Reallocating CRTCs
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1110] State before reallocation:
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-1' crtc=0 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-2' crtc=1 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1167] State after reallocation:
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-1' crtc=0 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-2' crtc=1 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0

where DP-1 is than disabled. After suspend/resume, allocation turns into:

  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1099] Reallocating CRTCs
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1110] State before reallocation:
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-1' crtc=-1 state=1 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-2' crtc=1 state=3 desired_enabled=1
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1167] State after reallocation:
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-1' crtc=-1 state=1 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-2' crtc=1 state=3 desired_enabled=1
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0

where the crtc for DP-1 is now NULL. Trying to enable the output results
in:

  10:43:36.906 [DEBUG] [sway/config/output.c:351] Turning on output DP-1
  10:43:36.906 [DEBUG] [sway/config/output.c:360] Set preferred mode
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [sway/config/output.c:366] Preferred mode rejected, falling back to another mode
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [sway/config/output.c:400] Auto-detected output scale: 1.000000
  10:43:36.907 [DEBUG] [sway/config/output.c:430] Committing output DP-1
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [ERROR] [sway/config/output.c:435] Failed to commit output DP-1

where the primary format can't be queried since there is no crtc
allocated for the connector. Allocating the connector inside
drm_connector_get_primary_formats() fixes this issue. This is possible
since the only user of get_primary_formats() is the swapchain allocation
function, which is only called on output enable. Do the same thing for
the cursor formats in case the user queries them before the output is
enabled.
2021-08-20 10:24:30 +02:00
Simon Ser 18c2dce65e backend: unify startup messages 2021-08-19 20:47:36 +02:00
Simon Ser 46c42e55c6 backend/drm: add support for FB_DAMAGE_CLIPS
This allows the kernel to access our buffer damage. Some drivers
can take advantage of this, e.g. for PSR2 panels (Panel Self
Refresh) or for transfer over USB.

Closes: https://github.com/swaywm/wlroots/issues/1267
2021-08-18 20:59:25 +02:00
Rouven Czerwinski cdd9a60f72 Revert "backend/drm: Check if output is enabled before sending frame event"
This reverts commit 85757665e6.

We now check if the output is enabled within wlr_output_send_frame, no
need to handle this explicitly in the DRM backend. This also fixes a
race which was introduced with this commit: if we schedule the flip,
disable and commit the output before the flip happens,
output.frame_pending will not be reset to false. We than always fail to
enable the output subsequently:

      00:07:13.276 [INFO] [sway/commands.c:257] Handling command 'output DP-2 enable'
      00:07:13.276 [DEBUG] [sway/commands.c:428] Subcommand: enable
      00:07:13.276 [DEBUG] [sway/config/output.c:204] Merging on top of existing output config
      00:07:13.276 [DEBUG] [sway/config/output.c:227] Config stored for output DP-2 (enabled: 1) (-1x-1@-1.000000Hz position 0,0 scale -1.000000 subpixel unknown transform -1) (bg /home/phoenix/Pictures/Wallpapers/mine/oper.jpg fill) (dpms 1) (max render time: -1)
      00:07:13.276 [DEBUG] [sway/config/output.c:351] Turning on output DP-2
      00:07:13.276 [DEBUG] [sway/config/output.c:360] Set preferred mode
      00:07:13.276 [DEBUG] [wlr] [backend/drm/drm.c:465] connector DP-2: Can't enable an output without a buffer
      00:07:13.276 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
      00:07:13.277 [DEBUG] [sway/config/output.c:329] Output DPI: 162.560000x161.364706
      00:07:13.277 [DEBUG] [sway/config/output.c:400] Auto-detected output scale: 1.000000
      00:07:13.277 [DEBUG] [sway/config/output.c:430] Committing output DP-2
      00:07:13.277 [DEBUG] [wlr] [types/wlr_output.c:729] Tried to commit a buffer while a frame is pending

since the basic_output_test will always fail.
Reset frame_pending to false even if the output has been disabled in the
meantime.

Fixes https://github.com/swaywm/wlroots/issues/3109
2021-08-17 21:07:43 +02:00
Rouven Czerwinski 59b292b691 backend/drm: return true on test if no crtc
This should fix the following backtrace, seen on my desktop with one
output disabled:

  #0  atomic_crtc_commit (conn=0x270f5c0, state=0x270f6d0, flags=0, test_only=<optimized out>) at ../backend/drm/atomic.c:178
          drm = 0x1ae9c10
          output = 0x270f5c0
          crtc = 0x0
          modeset = false
          active = false
          mode_id = 43989232
          gamma_lut = 0
          prev_vrr_enabled = <optimized out>
          vrr_enabled = <optimized out>
          atom = {req = 0x270f5c0, failed = 48}
          ok = <optimized out>
  #1  0x00007f1104f33128 in drm_crtc_commit (conn=conn@entry=0x270f5c0, state=state@entry=0x270f6d0, flags=flags@entry=0, test_only=test_only@entry=true) at ../backend/drm/drm.c:339
          __PRETTY_FUNCTION__ = "drm_crtc_commit"
          drm = <optimized out>
          crtc = 0x0
          ok = <optimized out>
  #2  0x00007f1104f34e6c in drm_connector_test (output=output@entry=0x270f5c0) at ../backend/drm/drm.c:488
          conn = 0x270f5c0
          unsupported = <optimized out>
  #3  0x00007f1104f35424 in drm_connector_commit (output=0x270f5c0) at ../backend/drm/drm.c:578
          conn = 0x270f5c0
  #4  0x00007f1104f600b7 in wlr_output_commit (output=output@entry=0x270f5c0) at ../types/wlr_output.c:837
          now = {tv_sec = 7732, tv_nsec = 623813006}
          pre_event = {output = 0x270f5c0, when = 0x7ffecc1be570}
          back_buffer = 0x0
          scale_updated = <optimized out>
          geometry_updated = <optimized out>
          committed = <optimized out>
          event = {output = 0x0, committed = 4401048, when = 0x29f38f0}
  #5  0x0000000000433047 in apply_output_config (oc=oc@entry=0x29f38f0, output=output@entry=0x2710720) at ../sway/config/output.c:431
          wlr_output = 0x270f5c0
          output_box = <optimized out>
  #6  0x0000000000433aaf in apply_output_config_to_outputs (oc=0x2308400) at ../sway/config/output.c:649
          current = 0x29f38f0
          name = <optimized out>
          wildcard = true
          id = "Dell Inc. DELL U2410 F525M9AK0MML\000\060\060\060ACD7\000\000\000\000\000\000\000\220\063\240\002\000\000\000\000L5C\000\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000\000\000\000\355\240E\000\000\000\000\000\377\377\377\377\000\000\000\000@\206+\002\000\000\000\000`\260.\002\000\000\000"
          sway_output = 0x2710720
          tmp = 0x2242030
          seat = <optimized out>
  #7  0x000000000043df6b in cmd_output (argc=<optimized out>, argv=0x2a03390) at ../sway/commands/output.c:108
          error = <optimized out>
          output = <optimized out>
          background = false
  #8  0x0000000000410304 in execute_command (_exec=_exec@entry=0x2975d20 "output * dpms off", seat=0x22a3280, seat@entry=0x0, con=con@entry=0x0) at ../sway/commands.c:291
          res = <optimized out>
          argc = 4
          argv = 0x2a03370
          handler = 0x479230 <handlers+560>
          cmd = <optimized out>
          matched_delim = 0 '\000'
          containers = 0x0
          using_criteria = false
          __PRETTY_FUNCTION__ = "execute_command"
          exec = 0x28f63c0 "output * dpms off"
          head = 0x0
          res_list = 0x2a2e9d0
  #9  0x0000000000418b65 in ipc_client_handle_command (client=client@entry=0x2a6ac80, payload_length=<optimized out>, payload_type=IPC_COMMAND) at ../sway/ipc-server.c:645
          line = <optimized out>
          res_list = <optimized out>
          json = <optimized out>
          length = <optimized out>
          __PRETTY_FUNCTION__ = "ipc_client_handle_command"
          buf = 0x2975d20 "output * dpms off"
  #10 0x000000000041964c in ipc_client_handle_readable (client_fd=<optimized out>, mask=<optimized out>, data=0x2a6ac80) at ../sway/ipc-server.c:267
          pending_length = <optimized out>
          pending_type = <optimized out>
          client = 0x2a6ac80
          read_available = 31
          buf = "i3-ipc\021\000\000\000\000\000\000"
          received = 14
  #11 0x00007f1104fc3492 in wl_event_loop_dispatch () from /nix/store/ridk7k2ka6dbk4ly7qqjgmc523s4fj89-wayland-1.19.0/lib/libwayland-server.so.0
  No symbol table info available.
  #12 0x00007f1104fc1135 in wl_display_run () from /nix/store/ridk7k2ka6dbk4ly7qqjgmc523s4fj89-wayland-1.19.0/lib/libwayland-server.so.0
  No symbol table info available.
  #13 0x000000000041ac10 in server_run (server=server@entry=0x47b0c0 <server>) at ../sway/server.c:261
  No locals.
  #14 0x000000000041a3fc in main (argc=<optimized out>, argv=0x7ffecc1bec68) at ../sway/main.c:395
          verbose = 0
          debug = 0
          validate = 0
          allow_unsupported_gpu = 0
          long_options = {{name = 0x45b516 "help", has_arg = 0, flag = 0x0, val = 104}, {name = 0x45ee69 "config", has_arg = 1, flag = 0x0, val = 99}, {name = 0x45b51b "validate", has_arg = 0, flag = 0x0, val = 67}, {
              name = 0x45b524 "debug", has_arg = 0, flag = 0x0, val = 100}, {name = 0x45b3ac "version", has_arg = 0, flag = 0x0, val = 118}, {name = 0x45a55c "verbose", has_arg = 0, flag = 0x0, val = 86}, {name = 0x45b52a "get-socketpath",
              has_arg = 0, flag = 0x0, val = 112}, {name = 0x45b539 "unsupported-gpu", has_arg = 0, flag = 0x0, val = 117}, {name = 0x45b549 "my-next-gpu-wont-be-nvidia", has_arg = 0, flag = 0x0, val = 117}, {name = 0x0, has_arg = 0,
              flag = 0x0, val = 0}}
          config_path = 0x0
          usage = 0x45b830 "Usage: sway [options] [command]\n\n  -h, --help", ' ' <repeats 13 times>, "Show help message and quit.\n  -c, --config <config>  Specify a config file.\n  -C, --validate         Check the validity of the config file, th"...
          c = <optimized out>

where the second output is not enabled:

  (gdb) frame 4
  #4  0x00007f1104f600b7 in wlr_output_commit (output=output@entry=0x270f5c0) at ../types/wlr_output.c:837
  837	in ../types/wlr_output.c
  (gdb) p output->enabled
  $3 = false
  (gdb)

The culprit being that since 604674dc54 we
always try to perform a commit, even on a disabled output.
2021-08-17 14:07:51 +02:00
Simon Ser 7544b7abf9 backend/drm: use addon for wlr_drm_fb 2021-08-17 11:08:45 +02:00
Tudor Brindus 0c19a28266 input/tablet: fix `wl_array_for_each` usage on tablet proximity
Looks like this instance was missed in
e035f2b9c4.

Fixes #3110.
2021-08-15 23:26:51 +02:00
Simon Ser 604674dc54 backend/drm: always perform a test commit in drm_connector_test
This allows callers to use wlr_output_test to check whether a mode
can be enabled, for instance.

Closes: https://github.com/swaywm/wlroots/issues/2250
2021-08-10 16:38:22 +02:00
Simon Ser eb0ce659cf backend/drm: add proper error handling to wlr_drm_backend_create
Some listeners weren't removed and caused a use-after-free with
e.g. vkms when used as a secondary GPU.
2021-08-10 15:42:36 +02:00
Simon Ser 1936e136df backend/drm: require buffer on modeset in drm_connector_test
When testing a modeset, make sure the caller has also provided a
buffer. This allows df0e75ba05 ("output: try skipping buffer
allocation if the backend allows it") to work as expected with the
DRM backend.

Closes: https://github.com/swaywm/wlroots/issues/3086
2021-08-04 22:51:40 +02:00
Simon Ser 923258b0be backend/drm: preserve mode order from kernel
The kernel orders the mode list from highest to lowest. Preserve
this ordering in the wlr_output.modes list.
2021-08-02 09:28:21 -04:00
Simon Ser 3132c0ab10 output: drop wlr_output_state.buffer_type
This is now unconditionally set to WLR_OUTPUT_STATE_BUFFER_SCANOUT.
2021-07-29 09:48:33 -04:00
Simon Ser d17a009062 backend/noop: drop attach_render/rollback_render
We no longer require wlr_output_impl.{attach,rollback}_render to
be populated.
2021-07-29 09:48:33 -04:00
Simon Ser 55ac7e335a backend/drm: fix wrong type for get_cursor_format return values
These are bools but should be pointers.
2021-07-28 16:59:21 -04:00
Simon Ser c55f70c8b7 backend/drm: stop initializing renderer for parent backend
Unless we're dealing with a multi-GPU setup and the backend being
initialized is secondary, we don't need a renderer nor an allocator.
Stop initializing these.
2021-07-28 22:52:35 +02:00
Simon Ser c74dc45bb6 backend/drm: drop get_renderer implementation
We can now just rely on the common code for this.
2021-07-28 22:52:35 +02:00
Simon Ser 9b99570869 backend/drm: drop drm_surface_{make,unset}_current 2021-07-28 22:52:35 +02:00
Simon Ser ebb661532c backend/drm: remove SCANOUT check in drm_connector_test
We only accept SCANOUT, the buffer type should never be set to RENDER.
2021-07-28 22:52:35 +02:00
Simon Ser f5900c1f00 backend/drm: remove primary swapchain
We can't nuke it completely, we still need it for multi-GPU.
2021-07-28 22:52:35 +02:00
Simon Ser 85d7ad2eef backend/drm: allow legacy scan-out if FB props match
Historically we haven't allowed direct scan-out for legacy KMS,
because legacy misses the functionality to make sure a buffer can
be scanned out. However with renderer v6 the backend can't figure
out anymore whether the buffer comes from its internal swap-chain,
because the backend doesn't have an internal swap-chain.

The legacy KMS API guarantees that the driver won't reject a buffer
as long as it's been allocated with the same parameters as the
previous one. Let's check this in legacy_crtc_test.
2021-07-28 22:52:35 +02:00
Simon Ser d6f0fc251e backend/drm: implement get_primary_formats 2021-07-28 22:52:35 +02:00
Simon Zeni 04d4fb536d render/wlr_texture: put wlr_texture_from_buffer into the public API 2021-07-22 22:28:24 +02:00
ayaka 70fb21c35b backend: make DRM and libinput backends optional
Co-authored-by: Simon Ser <contact@emersion.fr>
2021-07-22 09:56:38 -04:00
Simon Ser 66c42f4fcb backend/drm: add DRM_MODE_CONNECTOR_USB to conn_get_name
See 757e26712337 ("drm/uapi: Add USB connector type") in the kernel
tree.
2021-07-21 08:47:35 +02:00
Simon Ser cc8bc0db20 backend/drm: stop restoring CRTCs on exit
This is the cause of the spurious "drmHandleEvent failed" messages
at exit. restore_drm_outputs calls handle_drm_event in a loop without
checking whether the FD is readable, so drmHandleEvent ends up with a
short read (0 bytes) and returns an error.

The loop's goal is to wait for all queued page-flip events to complete,
to allow drmModeSetCrtc calls to succeed without EBUSY. The
drmModeSetCrtc calls are supposed to restore whatever KMS state we were
started with. But it's not clear from my PoV that restoring the KMS
state on exit is desirable.

KMS clients are supposed to save and restore the (full) KMS state on VT
switch, but not on exit. Leaving our KMS state on exit avoids unnecessary
modesets and allows flicker-free transitions between clients. See [1]
for more details, and note that with Pekka we've concluded that a new
flag to reset some KMS props to their default value on compositor
start-up is the best way forward. As a side note, Weston doesn't restore
the CRTC by does disable the cursor plane on exit (see
drm_output_deinit_planes, I still think disabling the cursor plane
shouldn't be necessary on exit).

Additionally, restore_drm_outputs only a subset of the KMS state.
Gamma and other atomic properties aren't accounted for. If the previous
KMS client had some outputs disabled, restore_drm_outputs would restore
a garbage mode.

[1]: https://blog.ffwll.ch/2016/01/vt-switching-with-atomic-modeset.html
2021-07-20 15:33:26 +02:00
Simon Ser f94eb174c7 backend/drm: fix NULL data in handle_drm_event
wl_event_loop_add_fd was called with a NULL data argument, but the
function expects the data argument to be set to the wlr_drm_backend.

Fixes: 053ebe7c27 ("backend/drm: terminate display on drmHandleEvent failure")
2021-07-19 09:01:21 -04:00
Simon Ser a47f89cf7c backend/wayland: properly cleanup wlr_wl_pointer
We were missing destroy calls for gestures, and we were only
destroying the relative pointer on output destroy.
2021-07-13 09:20:25 -04:00
Simon Ser 709190c4c8 backend/drm: remove wlr_output_impl.export_dmabuf
This is now provided by the generic wlr_output implementation.
2021-07-12 13:29:03 -04:00
Simon Ser aec062d0d3 backend/headless: remove wlr_output_impl.export_dmabuf
This is now provided by the generic wlr_output implementation.
2021-07-12 13:29:03 -04:00
Simon Ser f67cfb2ce2 backend/drm: remove backend arg from wlr_drm_interface.crtc_commit
The callee can just get it from the wlr_drm_connector.
2021-07-09 15:31:19 -04:00
Simon Ser fde56c20b4 backend/drm: move legacy-specific checks to legacy.c
Now that we have a test_only arg in crtc_commit, we can move the
legacy checks to legacy.c.
2021-07-09 15:31:19 -04:00
Simon Ser 017555651b backend/drm: add test_only arg to wlr_drm_interface.crtc_commit
Right now callers of drm_crtc_commit need to check whether the
interface is legacy or atomic before passing the TEST_ONLY flag.
Additionally, the fallbacks for legacy are in-place in the common
code.

Add a test_only arg to the crtc_commit hook. This way, there's no
risk to pass atomic-only flags to the legacy function (add an assert
to ensure this) and all of the legacy-specific logic can be put back
into legacy.c (done in next commit).
2021-07-09 15:31:19 -04:00
Simon Ser c1b27cc499 backend/drm: stop using drm_surface_make_current in drm_surface_blit
drm_surface_make_current and drm_surface_unset_current set implicit
state and are an unnecessary mid-layer. Prefer to use directly
wlr_renderer_begin_with_buffer, which automatically unsets the back
buffer on wlr_renderer_end.

I'd like to get rid of drm_surface_make_current once we stop using
it for the primary swapchain.
2021-07-08 14:44:42 -04:00
Simon Ser d71ed635b9 backend/drm: force linear layout for multi-GPU buffers
Some buffers need to be copied across GPUs. Such buffers need to be
allocated with a format and modifier suitable for both the source
and the destination.

When explicit modifiers aren't supported, we were forcing the buffers
to be allocated with a linear layout, because implicit modifiers
aren't portable across GPUs. All is well with this case.

When explicit modifiers are supported, we were advertising the whole
list of destination modifiers, in the hope that the source might
have some in common and might be able to allocate a buffer with a
more optimized layout. This works well if the source supports explicit
modifiers. However, if the source doesn't, then wlr_drm_format_intersect
will fallback to implicit modifiers, and everything goes boom: the
source uses a GPU-specific tiling and the destination interprets it
as linear.

To avoid this, just force linear unconditionally. We'll be able to
revert this once we have a good way to indicate that an implicit modifier
isn't supported in wlr_drm_format_set, see [1].

[1]: https://github.com/swaywm/wlroots/pull/2815

Closes: https://github.com/swaywm/wlroots/issues/3030
2021-07-08 17:06:20 +02:00
Simon Ser e035f2b9c4 Fix invalid uses of wl_array_for_each
[1] and [2] have introduced new wl_array usage in wlroots, but
contains a mistake: wl_array_for_each iterates over pointers to
the wl_array entries, not over entries themselves.

Fix all wl_array_for_each call sites. Name the variables "ptr"
to avoid confusion.

Found via ASan:

    ==148752==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x602000214111 in thread T0
        #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
        #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24
        #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51
        #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306
        #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57
        #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57
        #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124
        #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e)
        #8 0x55cd1a77c9e5 in server_fini ../sway/server.c:218
        #9 0x55cd1a77893f in main ../sway/main.c:400
        #10 0x7f6ff04bdb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
        #11 0x55cd1a73a7ad in _start (/home/simon/src/sway/build/sway/sway+0x33a7ad)

    0x602000214111 is located 1 bytes inside of 16-byte region [0x602000214110,0x602000214120)
    freed by thread T0 here:
        #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
        #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24
        #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51
        #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306
        #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57
        #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57
        #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124
        #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e)

    previously allocated by thread T0 here:
        #0 0x7f6ff2236279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
        #1 0x7f6ff1066d03 in wl_array_add (/usr/lib/libwayland-server.so.0+0xdd03)

[1]: https://github.com/swaywm/wlroots/pull/3002
[2]: https://github.com/swaywm/wlroots/pull/3004
2021-07-08 10:08:47 -04:00
Simon Ser c1902cdb3f backend/x11: send touch frame events 2021-07-08 09:12:17 +02:00
Simon Ser 8eef6a8843 backend/wayland: send touch frame events 2021-07-08 09:12:17 +02:00
Simon Ser 2d36d7fb67 backend/libinput: send touch frame events 2021-07-08 09:12:17 +02:00
Simon Zeni e192d87731 move wlr_box from /types to /util 2021-07-06 21:43:17 +02:00
Simon Ser 4dee7a2f6f backend/drm: don't clear pending cursor FB on failed commit
The previous fix tried to side-step cursor->pending_fb completely.
However that messes up our buffer locking mechanism.

Instead, stop clearing the pending cursor FB on a failed commit. The
pending cursor FB will remain for the next commit.

Fixes: 6c3d080e25 ("backend/drm: populate cursor plane's current_fb")
2021-07-05 10:55:41 -04:00
Simon Ser 5f26360bd8 Revert "backend/drm: populate cursor plane's current_fb"
This reverts commit 6c3d080e25.

Populating wlr_drm_plane.current_fb messes up the buffer's locking.
The previous buffer is released while it's still being displayed
on-screen.
2021-07-05 10:55:41 -04:00
Simon Ser 0a522cb798 backend/libinput: use wl_array for wlr_libinput_tablet.tools
Instead of using a single-field wl_list, let's just use a wl_array.
2021-07-05 10:05:06 +02:00
Simon Ser a38baec1f8 buffer: make enum wlr_buffer_cap public
Custom backends and renderers need to implement
wlr_backend_impl.get_buffer_caps and
wlr_renderer_impl.get_render_buffer_caps. They can't if enum
wlr_buffer_cap isn't made public.
2021-07-01 16:40:19 -04:00
Simon Ser 5888c96da8 tablet: stop using wlr_list 2021-07-01 10:35:39 -04:00
Simon Ser e6cb11d882 backend/libinput: stop using wlr_list internally 2021-07-01 10:35:39 -04:00
Simon Ser dbb0e2f75b Remove unused wlr_list.h includes 2021-07-01 10:35:39 -04:00
Simon Ser 264d4e2bce backend/drm: rename page_flip_handler to handle_page_flip
This is more consistent with the rest of the wlroots naming.
2021-06-24 11:56:45 +02:00
Simon Ser 2f615468b6 backend: add output state allow-lists
Right now, when a new output state field is added, all backends by
default won't reject it. This means we need to add new checks to
each and every backend when we introduce a new state field.

Instead, introduce a bitmask of supported output state fields in
each backend, and error out if the user has submitted an unknown
field.

Some fields don't need any backend involvment to work. These are
listed in WLR_OUTPUT_STATE_BACKEND_OPTIONAL as a convenience.
2021-06-20 23:17:08 +02:00
Simon Ser 72ee196efa backend/session: use DRM_PRIMARY_MINOR_NAME
Instead of hardcoding the string "card", use DRM_PRIMARY_MINOR_NAME.
Some systems may use another prefix, e.g. OpenBSD uses "drm" instead.
2021-06-17 00:28:04 +02:00
Simon Ser fb933d3204 backend/session: use drmIsKMS
This moves the magic incantation into libdrm and is clearer. See
[1] for details.

While at it, fixup the doc comment and improve logging.

[1]: 523b3658aa
2021-06-17 00:27:12 +02:00
Simon Ser 6c3d080e25 backend/drm: populate cursor plane's current_fb
The set_cursor() hook is a little bit special: it's not really
synchronized to commit() or test(). Once set_cursor() returns true,
the new cursor is part of the current state.

This fixes a state where wlr_drm_connector.cursor_enabled is true
but there is no FB available. This is triggered by set_cursor()
followed by a failed commit(), which resets pending_fb.

We should definitely fix the output interface to make the cursor part
of the pending state, but that's a more involved change.
2021-06-17 00:25:27 +02:00
Simon Ser 3345eaca89 backend/drm: remove test_buffer
Instead, call drm_connector_set_pending_fb.
2021-06-13 10:57:17 +02:00
Simon Ser eca5d2f37f backend/drm: move session check from test_buffer to drm_connector_test
The other caller (drm_connector_commit_state) already checks this.
2021-06-13 10:57:17 +02:00
Simon Ser 758f117442 backend/drm: move drm_connector_set_pending_fb up
This will be used in drm_connector_test shortly.
2021-06-13 10:57:17 +02:00
Simon Ser f55b43ddd6 backend/drm: allocate a CRTC in drm_connector_test
We can't perform a test-only atomic commit if the connector is
missing a CRTC.
2021-06-13 10:57:17 +02:00
Simon Ser cb378600e4 backend/drm: allocate a CRTC in drm_connector_commit_state
drm_connector_set_pending_fb needs a CRTC to import the buffer.
2021-06-13 10:57:17 +02:00
Simon Ser b180d3482f backend/drm: introduce drm_connector_alloc_crtc
This function allocates a CRTC for a connector if necessary.
2021-06-13 10:57:17 +02:00
Simon Ser 63f891e393 backend/drm: allow committing a buffer and a mode together
Set the plane's pending FB before calling drm_connector_set_mode.
2021-06-13 10:57:17 +02:00
Simon Ser e89cf5f047 backend/drm: use atomic test-only commits for modifier fallback
Instead of trying to perform a real modeset in init_renderer,
perform an atomic test-only commit to find out whether disabling
modifiers is necessary because of bandwidth limitations.

This decouples init_renderer from the actual commit, making it
possible to modeset an output with a user-supplied buffer instead
of a black frame.

We loose the ability to make sure the buffers coming from the
swapchain will work fine when using the legacy interface. This
can break i915 when atomic is disabled and modifiers enabled.
But i915 always has atomic (so the user must explicitly disable it
to run into potential bandwidth limitations) and is the only known
problematic driver.
2021-06-13 10:57:17 +02:00
Simon Ser b2f6db3533 render: drop wlr_ prefix from wlr_renderer_bind_buffer
Make it clear this function is a private wlroots API and will stay
that way.
2021-06-09 10:26:09 +02:00
Simon Ser c87c849ec6 backend/x11: use wlr_renderer_begin_with_buffer for cursor 2021-06-09 10:26:09 +02:00
Simon Ser 543f5b35d0 backend/wayland: remove swapchain
Rely on wlr_output's generic swapchain handling.
2021-06-07 15:42:38 +02:00
Simon Ser 5f8092b045 backend/wayland: implement get_dmabuf_primary_formats 2021-06-07 15:42:38 +02:00
Simon Ser a670ee7940 backend/x11: remove swapchain
Rely on wlr_output's generic swapchain handling.

We still need a renderer for cursor readback, sadly.
2021-06-07 15:42:38 +02:00
Simon Ser 68c4f15958 backend/x11: implement get_dmabuf_primary_formats 2021-06-07 15:42:38 +02:00
Simon Ser 44feb832f9 backend/headless: remove swapchain
Rely on wlr_output's generic swapchain support instead of creating our
own. The headless output now simply keeps a reference to the front buffer
and does nothing else.
2021-06-07 15:42:38 +02:00
Simon Ser b86a0c8d8f backend/drm: move cursor fields to wlr_drm_connector
Doesn't make a lot of sense to split the cursor fields between
wlr_drm_plane and wlr_drm_connector. Let's just move everything to
wlr_drm_connector.
2021-06-02 11:08:52 +02:00
Simon Ser 2b0a1aeed5 output: take a wlr_buffer in set_cursor
Instead of passing a wlr_texture to the backend, directly pass a
wlr_buffer. Use get_cursor_size and get_cursor_formats to create
a wlr_buffer that can be used as a cursor.

We don't want to pass a wlr_texture because we want to remove as
many rendering bits from the backend as possible.
2021-06-02 11:08:52 +02:00
Simon Ser 01e0f51fad backend/drm: introduce drm_plane_pick_render_format
This is a new helper function to pick a render format suitable for
a plane.

The next commit will use it to initialize the cursor multi-GPU
surface.
2021-06-02 11:08:52 +02:00
Simon Ser e06ea4e84a backend/drm: remove format arg from drm_plane_init_surface
This was always set to ARGB8888.
2021-06-02 11:08:52 +02:00
Simon Ser 9e9be83a58 backend/drm: implement get_cursor_formats and get_cursor_size 2021-06-02 11:08:52 +02:00
Simon Ser de51df2770 backend/wayland: implement get_cursor_formats 2021-06-02 11:08:52 +02:00
Simon Ser ce3e819b33 backend: stop using renderer to get the buffer type
When picking a format, the backend needs to know whether the
buffers allocated by the allocator will be DMA-BUFs or shared
memory. So far, the backend used the renderer's supported
buffer types to guess this information.

This is pretty fragile: renderers in general don't care about the
SHM cap (they only care about the DATA_PTR one). Additionally,
nothing stops a renderer from supporting both DMA-BUFs and shared
memory, but this would break the backend's guess.

Instead, use wlr_allocator.buffer_caps. This is more reliable since
the buffers created with the allocator are guaranteed to have these
caps.
2021-05-31 15:50:13 -04:00
Simon Ser fd2b1f018e backend/x11: use common renderer and allocator
Instead of managing our own renderer and allocator, let the common
code do it.
2021-05-21 22:13:54 +02:00
Simon Ser c82f37542d backend/headless: use common renderer and allocator
Instead of managing our own renderer and allocator, let the common
code do it.

Because wlr_headless_backend_create_with_renderer needs to re-use
the parent renderer, we have to hand-roll some of the renderer
initialization.
2021-05-21 22:13:54 +02:00
Simon Ser 349553d011 backend/wayland: use common renderer and allocator
Instead of managing our own renderer and allocator, let the common
code do it.
2021-05-21 22:13:54 +02:00
Simon Ser 4dae12890f backend: automatically create allocator
Introduce a new backend_get_allocator function that automatically
creates an allocator for the backend if the backend has a renderer.
2021-05-21 22:13:54 +02:00
Simon Ser bcabe34a2e backend: automatically create renderer
If a backend accepts buffers (as indicated by get_buffer_caps) but
doesn't implement get_renderer, automatically create a renderer.
2021-05-21 22:13:54 +02:00
Simon Ser 7ec5bf6b10 backend: introduce wlr_backend_finish
This new functions cleans up the common backend state. While this
currently only emits the destroy signal, this will also clean up
the renderer and allocator in upcoming patches.
2021-05-21 22:13:54 +02:00
Simon Ser 9ca743f9fd backend/drm: use wlr_texture_from_buffer 2021-05-17 16:22:43 +02:00
Kenny Levinsen 2603a5dee7 backend/drm: Do not require mode commit on enable
If a mode is not provided, use the current mode intead.

Closes: https://github.com/swaywm/wlroots/issues/2904
2021-04-30 21:33:28 +02:00
Simon Ser c85789a3a9 backend/headless: dup DRM FD in wlr_headless_backend_create_with_renderer
We were not dup'ing the DRM FD coming from wlr_renderer_get_drm_fd,
resulting in a double-close on backend destroy.
2021-04-29 19:59:42 +02:00
Simon Ser a1e8a639b3 backend/drm: introduce drm_connector_commit_state
Backend-initiated mode changes can use this function instead of
going through drm_connector_set_mode. drm_connector_set_mode becomes
a mere drm_connector_commit_state helper.
2021-04-29 19:51:57 +02:00
Simon Ser e543e26206 backend/drm: take a wlr_drm_connector instead of a wlr_output
No need to take a generic wlr_output, we already know the output
comes from the DRM backend at that point.
2021-04-29 19:51:57 +02:00
Simon Ser e06c62af77 backend/drm: take output state arg in drm_connector_commit_buffer
This will allow a whole state to be applied at once, instead of
individually applying the buffer and the mode.
2021-04-29 19:51:57 +02:00
Simon Ser 218955ce95 backend/drm: remove mode arg from drm_connector_set_mode
All of the information is in wlr_output_state.
2021-04-29 19:51:57 +02:00
Simon Ser 7aba881c47 backend/drm: remove mode arg from drm_connector_init_renderer
This is now unused.
2021-04-29 19:51:57 +02:00
Simon Ser 31082a0554 backend/drm: remove wlr_drm_crtc_state.mode
Replace it with drm_connector_state_mode, which computes the mode
from the wlr_output_state to be applied.
2021-04-29 19:51:57 +02:00
Simon Ser dfea0ff31d backend/drm: remove wlr_drm_crtc_state.active
Replace it with drm_connector_state_active, which figures out
whether the connector is active depending on the wlr_output_state
to be applied.
2021-04-29 19:51:57 +02:00
Simon Ser 485ecc11a6 backend/drm: remove wlr_drm_crtc.pending_modeset
Replace it with a new drm_connector_state_is_modeset function that
decides whether a modeset is necessary directly from the
wlr_output_state which is going to be applied.
2021-04-29 19:51:57 +02:00
Simon Ser c9c2d7539c backend/drm: fill scratch wlr_output_state for set_mode
Populate the wlr_output_state when setting a mode. This will allow
drm_connector_set_mode to stop relying on ephemeral fields in
wlr_drm_crtc. Also drm_connector_set_mode will be able to apply
both a new buffer and a new mode atomically.
2021-04-29 19:51:57 +02:00
Simon Ser 1a9701cd7c backend/drm: take wlr_output_state as arg in commit callers
Instead of relying on wlr_output.pending to be empty when performing
backend-initiated CRTC commits, use a zero wlr_output_state.
2021-04-29 19:51:57 +02:00
Simon Ser 8f90d7f8f5 backend/drm: take wlr_output_state as arg in crtc_commit
Stop assuming that the state to be applied is in output->pending in
crtc_commit. This will allow us to remove ephemeral fields in
wlr_drm_crtc, which are used scratch fields to stash temporary
per-commit data.
2021-04-29 19:51:57 +02:00
Simon Ser e7f68ba081 backend/drm: fix allocator DRM FD on multi-GPU setups
On multi-GPU setups, there is a primary DRM backend and secondary
DRM backends. wlr_backend_get_drm_fd will always return the parent
DRM FD even on secondary backends, so that users always use the
primary device for rendering.

However, for our internal rendering we want to use the secondary
device. Use allocator_autocreate_with_drm_fd to make sure the
allocator will create buffers on the secondary device.

We do something similar to ensure our internal rendering will
happen on the secondary device with renderer_autocreate_with_drm_fd.

Fixes: cc1b66364c ("backend: use wlr_allocator_autocreate")
2021-04-29 15:58:56 +02:00
Simon Ser 619a975025 render: remove wlr_ prefix from wlr_renderer_autocreate_with_drm_fd
This function is only required because the DRM backend still needs
to perform multi-GPU magic under-the-hood. Remove the wlr_ prefix
to make it clear it's not a candidate for being made public.
2021-04-29 09:46:34 +02:00
Simon Ser 6bf2406dbf backend/drm: reword wlr_renderer failure message
Remove the assumption about EGL.
2021-04-29 09:38:10 +02:00
Simon Ser 1c1ef69326 Log when WLR_BACKENDS/WLR_RENDERER is set
Makes it easier to figure out why a backend/renderer is picked.
2021-04-28 21:06:41 +02:00
Simon Zeni cc1b66364c backend: use wlr_allocator_autocreate 2021-04-28 20:55:57 +02:00
Simon Zeni 144189674e backend: introduce backend_get_buffer_caps 2021-04-28 20:55:57 +02:00
Simon Zeni a8c91fbac9 render/shm_allocator: make wlr_shm_allocator_create return a wlr_allocator 2021-04-28 20:55:57 +02:00
Simon Zeni c75aa71816 render/gbm_allocator: make wlr_gbm_allocator_create return a wlr_allocator 2021-04-28 20:55:57 +02:00
Simon Ser 0411dc0663 Revert "backend/drm: fail instead of stripping a modifier"
This reverts commit f9f90b4173.

gbm_bo_get_modifier may return a modifier in these cases:

- The kernel doesn't support modifiers but Mesa does
- WLR_DRM_NO_MODIFIERS=1 is set

However, in both of these cases, the gbm_bo has been allocated
without modifiers.

There is already a check in drm_fb_create for modifiers:
wlr_drm_format_set_has will make sure buffers with an explicit
modifier will be rejected if the DRM backend doesn't support them.
So no need for an additional check in get_fb_for_bo.

Closes: https://github.com/swaywm/wlroots/issues/2896
2021-04-27 15:38:10 +02:00
Simon Ser 4839664a92 backend/drm: carry on when disabling a CRTC fails
On GPU unplug, disabling a CRTC can fail with EPERM.

References: https://github.com/swaywm/wlroots/pull/2575#issuecomment-761771264
2021-04-27 09:11:44 +02:00
Simon Ser 9b0e0970f9 backend/drm: destroy backend on udev remove event
Any use of the DRM FD after the remove event results in a "Permission
denied" error.
2021-04-27 09:11:44 +02:00
Simon Ser 5597776914 backend/session: add wlr_device.events.remove 2021-04-27 09:11:44 +02:00
Simon Ser c49ea9ef4f backend/drm: destroy when parent is destroyed 2021-04-27 09:11:44 +02:00
Simon Ser e804de923d backend/drm: clarify error message on drmModeAddFB fallback
The previous code would always print "falling back to legacy method",
even if the format wasn't ARGB8888.

Drop get_fb_for_bo_legacy, since the code can just be inlined without
hurting readability.

Ideally we should only fallback to drmModeAddFB if the error code
indicates the BE failure, but the original PR [1] doesn't say what
error code is returned by the kernel.

[1]: https://github.com/swaywm/wlroots/pull/2569
2021-04-26 23:12:53 +02:00
Simon Ser f9f90b4173 backend/drm: fail instead of stripping a modifier
We shouldn't strip a modifiers from buffers, because the will make
the kernel re-interpret the data as LINEAR on most drivers,
resulting in an incorrect output on screen.
2021-04-26 23:12:53 +02:00
Simon Ser 5c699f09cb Log drmGetDevices2 error code 2021-04-26 16:27:24 +02:00
Tadeo Kondrak 014c59aa40 backend/x11: add support for shm buffers 2021-04-20 20:27:25 +02:00
tomKPZ 7c9b61b18c Fix stuck keys on X11 backend 2021-04-20 08:19:48 +02:00
Kenny Levinsen 3432ab2ba7 backend/session: Close remaining devices on destroy 2021-04-18 18:32:24 +02:00
Kenny Levinsen e7515529ce backend/session: Close fd in wlr_session_close_file
This was lost in the session_impl removal refactor.
2021-04-18 18:32:24 +02:00
Simon Ser 9de93a866f backend/wayland: fallback to wl_shm on missing render node 2021-04-17 09:54:39 +02:00
Simon Ser 80865351bd backend/wayland: add support for wl_shm buffers 2021-04-17 09:54:39 +02:00