Commit Graph

1679 Commits

Author SHA1 Message Date
Simon Ser f5e8fa48f3 backend/libinput: 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 682dbf36e5 backend/headless: take wl_event_loop instead of wl_display 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 4ad6e6c298 backend: destroy multi backend when primary backend is
This makes it easy for compositors to handle situations where the
DRM or libinput backend becomes unavailable. Compositors can listen
the destroy event of the multi backend returned by
wlr_backend_autocreate() and decide what to do.
2024-01-25 14:58:00 +03:00
Simon Ser be0b7845f7 backend: make attempt_drm_backend() return the primary backend
We'll need this in the next commit.
2024-01-25 12:12:13 +01:00
Simon Ser a82fc4cb8f backend/multi: emit destroy signal before destroying child backends
Some users might want to destroy the multi backend when a child
backend is being destroyed. However, they can't destroy the multi
backend if it's already in the process of being destroyed.

The destroy signal was changed to be emitted after destroying child
backends in babdd6ccf7 ("backend: fix use-after-free when destroying
backends"). However, this was done to accomodate for an old
"output_remove" event on backends, which has long been dropped in
favor of wlr_output.events.destroy.

This patch follows the same principle as 5d639394f3
("types/output: emit destroy event before destroying global").
2024-01-25 12:12:13 +01:00
Simon Ser 98c708618e backend/wayland: populate pointer axis relative direction 2024-01-23 08:37:29 +00:00
Simon Ser 7a58f41416 backend/libinput: populate pointer axis relative direction 2024-01-23 08:37:29 +00:00
Kirill Primak db69dcf767 backend/x11: handle touchpoint allocation failure 2024-01-17 15:44:37 +00:00
Simon Ser a0b1329ee6 Fix bool return types
This makes wlroots build in C23 mode.

C23 is more strict and rejects implicit conversions from bool to a
pointer.
2024-01-04 22:24:06 +01: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
Sergei Trofimovich f3e1f7b2a7 backend: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`)
`gcc-14` added a new `-Wcalloc-transposed-args` warning recently. It
detected minor infelicity in `calloc()` API usage in `wlroots`:

    ../backend/libinput/tablet_pad.c: In function 'add_pad_group_from_libinput':
    ../backend/libinput/tablet_pad.c:36:38: error: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
       36 |         group->rings = calloc(sizeof(unsigned int), group->ring_count);
          |                                      ^~~~~~~~
    ../backend/libinput/tablet_pad.c:36:38: note: earlier argument should specify number of elements, later size of each element
2023-12-21 21:06:20 +00:00
Simon Ser d8c0707e27 backend/drm: return secondary backend DRM FD
It can be useful for compositors to get the real DRM FD instead of
the one from the parent compositor. For instance, some compositors
might want to perform some DRM IOCTLs there to check the driver
name, fetch some DRM resources, etc. This will also be a requirement
for direct scanout on secondary GPUs.
2023-12-12 14:42:52 +00:00
Simon Ser fc7a0b93dd backend/drm: add wlr_drm_backend_get_parent()
Allows compositors to figure out whether a DRM backend is
secondary on a multi-GPU setup.
2023-12-12 14:42:52 +00:00
Alexander Orzechowski 8ac5139007 backend/x11: Use wlr_texture_read_pixels 2023-11-30 20:01:12 -05:00
Simon Ser 67c77fdbdc backend/drm: remove wlr_drm_renderer.backend
This is unused.
2023-11-30 14:44:46 +00: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 ae3d7a697c backend/drm: use DRM_IOCTL_MODE_CLOSEFB instead of RMFB
RMFB implicitly performs a modeset to turn off any CRTC which is
using the FB. This prevents seamless transitions between two DRM
masters from working.

Use the new CLOSEFB IOCTL which doesn't turn off anything and leave
it up to the compositor to turn off outputs on shutdown if it wants
to.
2023-11-28 13:18:39 +00:00
Kirill Primak 4990ed99eb backend/x11: don't send ConfigureRequest with the same size
Under X11, ConfigureNotify means that the window has already been resized.
Sending ConfigureRequest with the received size is not only useless, but also
can confuse the window manager, which will probably reply with the current
(i.e. *old*) size causing a configure loop.

Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3769
2023-11-27 09:46:11 +00:00
Kirill Primak 4102b722d9 backend/x11: check buffer format in output_test() 2023-11-26 23:11:28 +03: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 63792b38e4 backend/session: take wl_event_loop instead of wl_display
wl_display holds a lot more than wlr_session needs: wlr_session
only needs to wait for a FD to become readable, but wl_display
provides full access to the Wayland client and protocol objects.

Switch to wl_event_loop to better reflect the above.
2023-11-23 11:15:07 +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 bd18d5ccfc backend/drm: drop unnecessary flags in legacy interface
drm_crtc_commit() already ensures that atomic-only flags are
disallowed.
2023-11-19 15:32:30 +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
sunzhguy c9c9dd6a5b backend/drm: free fb later
since 4932e0d347f("backend/drm: ensure plane surfaces are cleaned up on shutdown")
at finish_drm_resources called drm_plane_finsh_surface has already free the fb

Signed-off-by: zhoulei zhoulei@kylinos.cn
Signed-off-by: sunzhguy <sunzhigang1@kylinos.cn>
2023-11-17 12:38:21 +08:00
Simon Ser b0bd86285f backend/drm: leave CRTCs on when shutting down
This avoids a black screen during multiple seconds on shutdown.
To fully allow for flicker-free transitions between DRM masters,
we will also need [1].

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4394

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3497
2023-11-15 01:37:59 +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
JiDe Zhang b560f36207 Fix output layers order error on wayland backend 2023-10-16 11:14:44 +00:00
Simon Ser b82a53a918 Revert "backend/drm: Automatic non-blocking commits"
This reverts commit 45ba35719e.

Sadly, this causes regressions on amdgpu [1] and even with these
fixed, there are fundamental issues with non-blocking modesets [2].

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3745
[2]: https://oftc.irclog.whitequark.org/dri-devel/2023-10-11#1697031838-1697036920;
2023-10-12 16:31:33 +00:00
Kenny Levinsen 45ba35719e backend/drm: Automatic non-blocking commits
We currently only perform non-blocking commits for non-modeset commits
with a buffer attached.

Perform non-blocking commits whenever there is no pending pageflip
event. If a non-blocking modeset commit fails, which can happen if the
driver implicitly added more CRTCs to the commit that we did not know we
had to wait for, retry with a blocking commit.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/2239
2023-10-10 12:44:59 +00: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
Alexander Orzechowski 1b0694b794 treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical 2023-10-03 01:51:07 -04:00
Kirill Primak a09d649439 docs: replace the less commonly used "::" with "." 2023-10-02 22:10:16 +03:00
Rose Hudson 83af3202f9 output: defer fake present events until after commit
Since headless and wayland-without-presentation-feedback were firing
present inside their commit impls, present was getting fired before
commit, which is cursed. Defer this with an idle timer so that commit
handlers can run before present handlers.
2023-10-02 12:34:06 +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
Simon Ser 6c1a2a6657 backend/headless: fix broken output frame events
frame_delay was set to 0.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3712
2023-08-21 16:18:26 +02:00
Simon Ser 22b6581a18 backend/wayland: wait for xdg_surface.configure explicitly
We were assuming a roundtrip was enough to get an
xdg_surface.configure event. That's not the case, the protocol
spec doesn't make such a guarantee.
2023-08-16 22:09:01 +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 a60361050e backend/headless: Use output state to set init custom mode 2023-08-16 11:46:27 -04:00
Alexander Orzechowski 83d9764ed8 backend/wayland: Use output state to set init custom mode 2023-08-16 11:46:27 -04:00
Alexander Orzechowski 869b0f14bc backend/x11: Use output state to set init custom mode 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 8678633fc9 backend/wayland: add wlr_wl_output_create_from_surface()
By using this function, a compositor can display a wlroots
compositor in a sub-surface, for instance.
2023-08-16 16:39:52 +02:00
Simon Ser 4f88886199 backend/wayland: tag wl_surface
When integrating wlroots with another toolkit, wlroots may receive
wl_pointer.enter events for surfaces not backed by a wlr_output.
Ignore such surfaces by tagging the ones we're aware of with
wl_proxy_set_tag().
2023-08-16 16:38:53 +02:00
Simon Ser dd24991c9e backend/wayland: take existing wl_display in wlr_wl_backend_create()
This allows compositors to use an existing wl_display, to integrate
wlroots with an existing toolkit.
2023-08-16 16:29:09 +02:00
Simon Ser 307720d501 backend/drm: restore custom modes
We were only restoring fixed modes here. The DRM backend no longer
creates fixed modes when the compositor sets a custom mode, so we
need to handle this situation when restoring.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3698
2023-07-26 17:08:47 +00:00
Brett Ernst 7ce4d557c5 backend/x11: log output test failure reasons 2023-07-18 15:27:44 -07:00
Brett Ernst 49c7fcdfb1 backend/wayland: log output test failure reasons 2023-07-18 15:26:54 -07: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
Simon Ser aa1055134d backend/drm: handle output layer damage 2023-06-30 04:31:50 +00:00
Simon Ser 7811f22250 backend/wayland: handle output layer damage 2023-06-30 04:31:50 +00:00
Simon Ser f4ee5eae93 backend/headless: leave new outputs disabled by default 2023-06-27 16:26:30 +00:00
Simon Ser e1bdc62c38 backend/x11: leave new outputs disabled by default 2023-06-27 16:26:30 +00:00
Simon Ser 1f716f4bc0 backend/wayland: mark new outputs as disabled
Leave it up to the compositor to enable new outputs (just like the
DRM backend does).
2023-06-27 16:26:30 +00:00
Simon Ser 611ce13625 backend/headless: add support for disabled outputs
We have nothing to do when a headless output is enabled/disabled.
2023-06-27 16:26:30 +00:00
Simon Ser 6c53f7badf backend/headless: only schedule a new frame if buffer was submitted
A no-op commit should not schedule a new frame. This aligns the
headless backend with the rest of the backends.

This will be important to handle the enabled → disabled transition.
2023-06-27 16:26:30 +00:00
Simon Ser bfe8138210 backend/x11: unmap when output is disabled 2023-06-27 16:26:30 +00:00
Simon Ser c0fd37c491 backend/wayland: unmap when output is disabled 2023-06-27 16:26:30 +00: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 530e58b96e backend/wayland: Reject non 0 refresh rate mode sets 2023-06-27 11:47:58 -04:00
Alexander Orzechowski 99314aac9f backend/x11: Reject non 0 refresh rate mode sets 2023-06-27 11:45:44 -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
Alexander Orzechowski e8887f76ed backend/drm: Use texture blend_mode for multigpu blit 2023-06-19 13:16:35 -04:00
Simon Ser 2d9659d765 backend/libinput: use struct initializers for events
This is more readable and consistent with the rest of wlroots.
2023-06-14 15:20:41 +02:00
Simon Ser e1c6801b65 backend/libinput: ignore multiple events for same pointer button
If the same button is pressed on two devices on the same seat,
ignore the second event.

This is also what Mutter does.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3665
2023-06-14 10:48:44 +00:00
Simon Ser 4339c37f99 backend/drm: clip FB damage
The kernel complains when the damage exceeds the FB bounds:

    [73850.448326] i915 0000:00:02.0: [drm:drm_atomic_check_only] [PLANE:31:plane 1A] invalid damage clip 0 0 2147483647 2147483647

Make the DRM backend behave like the Wayland one and allow compositors
to damage (0, 0, INT32_MAX, INT32_MAX) to repaint everything without
needing to know the exact buffer size.

Closes: https://github.com/swaywm/sway/issues/7632
2023-06-12 20:38:03 +00:00
Rose Hudson 9e8947e4d5 add render timer API
Based on five calls:
wlr_render_timer_create - creates a timer which can be reused across
  frames on the same renderer
wlr_renderer_begin_buffer_pass - now takes a timer so that backends can
  record when the rendering starts and finishes
wlr_render_timer_get_time - should be called as late as possible so that
  queries can make their way back from the GPU
wlr_render_timer_destroy - self-explanatory

The timer is exposed as an opaque `struct wlr_render_timer` so that
backends can store whatever they want in there.
2023-06-05 19:50:07 +00:00
Simon Ser 4e513c93bd backend/wayland: add support for cropping output layers 2023-06-05 18:29:55 +00:00
Simon Ser 4c5eadecce backend/wayland: add scaling support for output layers
Use the viewporter protocol to scale output layers.
2023-06-05 18:29:55 +00: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
Simon Ser 8fe29e6bd1 backend/drm: use new rendering API 2023-05-30 16:18:19 +00:00
Austin Shafer 0910fa9179 drm_plane_pick_render_format: return false if no format could be found
Commit 90d08f8f1c changed the way
wlr_drm_format_intersect worked, including passing in a destination
format list. This breaks scenarios where the intersection doesn't
find any matching formats, since we still have a valid destination
format set. This changes it to only return true if more than one
matching format is present in the intersection list.
2023-05-17 18:24:20 +00:00
Tobias Predel 3dc5c7e5e7 backend_destroy: Similiar logic like DRM backend
In the logic of the DRM backend in backend_destroy, wlr_backend_finish
is called first, then the outputs are destroyed and then the
display->destroy.link is removed from the list.

This commit applies the same order to the headless backend.
2023-05-15 20:21:23 +02:00
Alexander Orzechowski 300bd80772 wlr_drm_format_set: Store formats on array 2023-05-11 18:25:52 +02: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
Alexander Orzechowski b45396c790 wlr_drm_format: Introduce drm_format_finish 2023-05-11 03:51:01 -04:00
zhoulei 2c30500ce1 backend/drm: fix di_info memory leak 2023-05-08 10:16:25 +08:00
ptrcnull 56502be1d1 backend/x11: prevent segfault on empty DRI3 response 2022-05-01 06:13:58 +02:00