Commit graph

582 commits

Author SHA1 Message Date
Kenny Levinsen
8dec0f6174 backend/drm: Remove erroneous free
init_plane tries to free a single plane on error, but this is an element
in a calloc'd array by the caller that we should not touch.
2024-02-22 00:41:00 +01:00
Kenny Levinsen
153dea9c28 backend/drm: Free current_modeinfo on error 2024-02-22 00:40:54 +01:00
Simon Ser
0d9ffef774 backend/drm: don't destroy previous DRM master blobs
On startup, we fetch the previous MODE_ID blob ID so that
compositors can keep using the previous mode if they want to.
However, that blob doesn't belong to us, it belongs to the
previous DRM master. As a result, we get an error when trying to
destroy it.

Fix this by tracking whether the blob belongs to us or not.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3811
2024-02-21 15:10:44 +00:00
Simon Ser
842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Simon Ser
17fe87af5e backend/drm: skip reset after VT switch if possible
If all connectors and planes already have the right CRTC set, or
are disabled, we can skip the device-wide reset after a VT switch.

I've contemplated using a more fine-grained logic to only reset
the connectors, CRTCs and planes that need to be migrated. However,
writing a correct algorithm for this would be quite involved, and it
doesn't seem worth the trouble anyways.

Closes: https://github.com/swaywm/sway/issues/7956
2024-02-15 09:56:33 +01:00
Simon Ser
653e28d2a3 backend/drm: fix typo in restore_drm_device() comment 2024-02-15 09:53:13 +01:00
Simon Ser
d2acd4c362 backend/drm: move restore logic to drm.c
We'll need to use a bunch of internal functions from that file in
the next commits.
2024-02-15 09:37:46 +01:00
Simon Ser
836cb820d0 backend/drm: call get_drm_connector_props() when creating connector
This function fetches property IDs. These don't change for the
lifetime of the connector. Instead of refreshing the property IDs
on hotplug (and leaving property IDs unset for disconnected
connectors), only fetch the property IDs when we create the
connector.
2024-02-14 19:12:14 +01:00
Simon Ser
76ed82c101 backend/drm: add drm_page_flip_create() 2024-02-14 17:13:25 +01:00
Simon Ser
6ad9e89a34 backend/drm: drop unnecessary _XOPEN_SOURCE
We only need base POSIX here.
2024-02-12 19:45:49 +01:00
Kirill Primak
92ff86db23 backend/drm: use wlr_drm_backend.name for fd cloning
This also fixes a memleak.
2024-01-31 11:10:55 +03:00
Simon Ser
00b869c1a9 backend/drm: add support for atomic tearing page-flips
The kernel patches [1] have been merged.

[1]: https://patchwork.freedesktop.org/series/120103/
2024-01-27 13:37:43 +01:00
Simon Ser
54f9944b48 backend/drm: drop wl_display argument
We can grab the event loop from the wlr_session instead.
2024-01-25 15:05:36 +00:00
Simon Ser
3cc4374542 backend: stop calling wl_display_terminate()
Leave it up to the compositor to decide what to do when a backend
becomes unavailable.
2024-01-25 14:58:00 +03:00
Simon Ser
f81c3d93cd backend/drm: save current refresh rate
wlr_output.refresh is populated by core wlr_output, and thus will
be zero for a custom mode with an unset refresh rate.

Save the refresh rate from the drmModeModeInfo in wlr_drm_connector
instead.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3791
2023-12-30 20:06:33 +01:00
Simon Ser
f935ff0ef6 backend/drm: move drm_plane_finish_surface() to drm.c
This function touches queued_fb/current_fb, which the renderer has
nothing to do with.
2023-11-30 14:44:46 +00:00
Simon Ser
260dbdf704 backend/drm: split wlr_drm_fb related functions into separate file 2023-11-30 14:44:46 +00:00
Simon Ser
56ec13596a Cleanup wlr_matrix.h includes
Many files used to require wlr_matrix but no longer do.
2023-11-25 08:37:43 +01:00
Simon Ser
d61ec694b3 output: take wl_event_loop in wlr_output_init()
We don't need the whole wl_display here anymore. The wl_event_loop
is enough.
2023-11-23 11:39:25 +00:00
Simon Ser
9e702e9cfe util/transform: move over wl_output_transform helpers
These aren't really tied to wlr_output.
2023-11-23 11:03:57 +01:00
Simon Ser
8c44e86077 backend/drm: add wlr_drm_connector_state.nonblock
Instead of having this condition checked in multiple places,
centralize it so that they don't go out-of-sync.
2023-11-19 15:32:30 +01:00
Simon Ser
f47b6e3fce backend/drm: fix pending page-flip check
This chunk of code was moved by mistake.

Fixes: 3b53d1cbf1 ("backend/drm: introduce page-flip tracking struct")
2023-11-19 15:14:22 +01:00
Alexander Orzechowski
b06d58fa8b backend/drm: Destroy page flips on backend destroy
When we destroy the backend, page flips will no longer be invoked meaning
those won't clean up the page flips for us.
2023-11-17 14:34:32 -05:00
Alexander Orzechowski
3aed24b8d4 backend/drm: Track page flips in list 2023-11-17 13:49:18 -05:00
Simon Ser
3b53d1cbf1 backend/drm: introduce page-flip tracking struct
Introduce a per-page-flip tracking struct passed to the kernel
when we request a page-flip event for an atomic commit. The kernel
will pass us back this pointer when delivering the event.

This eliminates any risk of mixing up events together. In particular,
if two events are pending, or if the CRTC of a connector is swapped,
we no longer blow up in the page-flip event handler.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3753
2023-11-17 16:59:04 +00:00
Simon Ser
4932e0d347 backend/drm: ensure plane surfaces are cleaned up on shutdown
Right now this is done "by chance" because we disable all CRTCs
on shutdown. However, we'll stop doing this. Plus, if disabling
a CRTC fails, we don't cleanup properly.
2023-11-15 01:37:59 +00:00
Simon Ser
1c24b1182b backend: drop wlr_backend_get_presentation_clock()
We can just assume CLOCK_MONOTONIC everywhere.

Simplifies the backend API, and fixes clock mismatches when multiple
backends are used together with different clocks.
2023-10-30 18:39:39 +01:00
Kenny Levinsen
2cf78f4c5b output: allow_artifacts -> allow_reconfiguration
The name "allow_artifacts" and associated description is very vague, and
theoretically allow for tearing behavior. Clarify that we only intend to
mean artifacts related to output configuration (e.g., modesets).

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3740
2023-10-09 08:31:35 +00:00
Simon Ser
a1679c92ce backend/drm: restore pending page-flip check when tearing
DRM_MODE_PAGE_FLIP_ASYNC doesn't allow user-space to submit new
buffers before waiting for the uevent: the kernel will return EBUSY
in that case.

Fixes: c2aa7fd965 ("backend/drm: Add async page flip support to legacy")
2023-10-02 10:26:47 +02:00
vaxerski
c2aa7fd965 backend/drm: Add async page flip support to legacy
Atomic doesn't support such flags yet.
2023-09-28 16:53:08 +00:00
Alexander Orzechowski
9be72ec4ca backend/drm: Compute custom mode correctly 2023-09-07 01:56:32 +00:00
Simon Ser
717ded9bb0 backend/drm: drop no-op shortcut
Since e5fc8cd4c7 ("output: trigger frame/present events on all
commits on enabled output"), any commit on an enabled output is
supposed to trigger frame/present events.

The DRM backend was skipping the commit completely for no-op
commits. Stop doing so.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3719
2023-08-25 17:16:05 +02:00
Simon Ser
e5fc8cd4c7 output: trigger frame/present events on all commits on enabled output
Up until now, frame/present events were only triggered when the
user submitted a buffer. Change the wlr_output API so that these
events are triggered when any commit is applied on an enabled
output.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3708
2023-08-23 15:42:22 +00:00
Rose Hudson
fc81d06add backend/drm: report !presented if session is inactive 2023-08-23 16:36:43 +02:00
Rose Hudson
f7afef0b1f backend/drm: don't set frame_pending on modeset
https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3664#note_2020392
we're gonna have to trust Simon on this one 🤞
2023-08-23 16:36:43 +02:00
Alexander Orzechowski
8f0d4c9332 backend/drm: Use output state to set init mode 2023-08-16 18:37:40 +02:00
Alexander Orzechowski
a34d349963 backend/drm: Move output variable up in connect_drm_connector 2023-08-16 11:46:27 -04:00
Alexander Orzechowski
6cda3e251c output: Add initialization state to wlr_output_init 2023-08-16 11:46:27 -04:00
Simon Ser
37ef9d7356 backend/drm: stop checking for wlr_client_buffer
wlr_client_buffer is a bad indicator for direct scan-out.
Compositors might use the underlying wlr_buffer instead.
2023-07-14 15:20:35 +02:00
Simon Ser
fe06e5f49a Use wl_container_of() instead of casts
This slightly improves type safety.

The culprits were found with:

    git grep -E '\([a-z0-9_ ]+ \*\)\W?[a-z]'
2023-07-11 20:16:17 +02:00
Simon Ser
7a9f8d8d6b Use struct initializers instead of memset()
This is a bit more type-safe.
2023-07-07 17:31:11 +02:00
Clayton Craft
aca48124ad
backend/drm: use panel_orientation if it is set
This fixes an issue where the panel_orientation parameter was set but wlroots was ignoring it and
returning OUTPUT_TRANSFORM_NORMAL.

Fixes 2e12de96
2023-06-30 09:34:28 -07:00
Alexander Orzechowski
8243399385 output: Set output mode during main commit
Removes duplication across all the backends to finally apply the mode
to the output.
2023-06-27 11:47:58 -04:00
Alexander Orzechowski
5567aefb1c backend/drm: Don't add pollute fixed modes list with custom modes
Nobody remembers why this is done and it isn't that great if people
use a lot of custom modes.
2023-06-27 11:14:55 -04:00
Simon Ser
cbcd99435f backend/drm: remove duplicate needs_frame() in set_cursor()
wlr_output_update_needs_frame() is called unconditionally at the
end of the function already.
2023-06-26 11:49:38 +02:00
Simon Ser
be05097968 output: add wlr_output_state_init()
This changes the semantics of wlr_output_state. Instead of having
fields with uninitialized memory when missing from the committed
bitflag, all fields are always initialized (and maybe NULL/empty),
just like we do in wlr_surface_state. This reduces the chances of
footguns when reading a field, and removes the need to check for
the committed bitfield everywhere.

A new wlr_output_state_init() function takes care of initializing
the Pixman region.
2023-06-23 18:07:26 +00:00
Simon Ser
fffa1908af backend/drm: fix libliftoff_plane double-free
Destroying the liftoff_device invalidates all of the liftoff_planes.
Destroy the liftoff_planes before the liftoff_device to fix this.
2023-06-22 18:00:34 +00:00
Alexander Orzechowski
ecbe48f3bc backend/drm: Fix typo 2023-06-21 10:23:56 +02:00
Simon Ser
30aca4df0d backend/drm: introduce wlr_drm_mode_get_info()
This allows compositors to get back the raw drmModeModeInfo and
look at DRM-specific fields and flags.
2023-05-31 22:37:12 +00:00
Alexander Orzechowski
90d08f8f1c wlr_drm_format: Rework wlr_drm_format_intersect
Now it takes a reference to a destination format
2023-05-11 18:24:43 +02:00