Commit Graph

607 Commits

Author SHA1 Message Date
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 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 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 053ebe7c27 backend/drm: terminate display on drmHandleEvent failure 2021-04-14 23:56:56 +02:00
Stephan Hilb 9f012cac2f drm: check for PRIME support
PRIME support for buffer sharing has become mandatory since the renderer
rewrite. Make sure we check for the appropriate capabilities in backend,
allocator and renderer.

See also #2819.
2021-04-10 10:49:55 +02:00
Simon Ser 8ccb4bbb5f backend/drm: stop testing for buffer in drm_connector_commit_buffer
We now do the test in drm_connector_test, called from
drm_connector_commit.
2021-04-06 20:35:15 +02:00
Simon Ser d0bf750916 backend/drm: use atomic test-only commits for direct scan-out
This allows callers to use wlr_output_test to figure out whether a
buffer can be scanned out prior to committing the output.
2021-04-06 20:35:15 +02:00
Simon Ser 1ec97bdf4f backend/drm: improve logs in drm_fb_create
Downgrade errors to DEBUG level, because drm_fb_create is used in
test_buffer, so errors aren't always fatal. Add ERROR logs at call
sites where a failure is fatal, to make it clear something wrong
happened.
2021-04-06 14:57:59 +02:00
Simon Ser 511e42be5e backend/drm: try to import buffer when testing it
If the import to KMS succeeds, we have a better chance to be able to
scan it out.

Importing is also necessary for test-only commits, which we want to
add in the future.
2021-04-06 14:57:59 +02:00
Simon Ser 7709a965e5 backend/drm: use format table in test_buffer
Instead of an ad-hoc strip_alpha_channel function, use the
centralized format table to get an opaque substitute.
2021-03-31 17:29:31 +02:00
Simon Ser 44fa2c4b49 output: fix transform matrix for 90/270 rotations
We need to adjust the second translation depending on the transform
we applied.

Fixes: 9601a2abf0 ("output: improve transform matrix calculation"
Closes: https://github.com/swaywm/wlroots/issues/2774
2021-03-11 22:52:38 +01:00
Simon Zeni 9601a2abf0 output: improve transform matrix calculation
Compute only the transform matrix in the output. The projection matrix
will be calculated inside the gles2 renderer when we start rendering.

The goal is to help the pixman rendering process.
2021-03-10 15:33:36 +01:00
Simon Ser 73ffab70b0 backend/drm: don't blit in drm_fb_import
Instead blit in drm_plane_lock_surface. This makes drm_fb_import simpler
and better fits its name.
2021-01-24 18:33:56 +01:00
Simon Ser 4af85f4c19 backend/drm: simplify drm_fb_lock_surface
Make it take a plane instead, and rename to drm_plane_lock_surface.
2021-01-24 18:22:03 +01:00
Simon Ser 04d89a8bc5
backend/drm: fix modifiers for cursor plane buffers
In 93cd3a79b2 ("backend/drm: stop using GBM flags"), we stopped
using the GBM_BO_USE_LINEAR flag in favor of a modifier list set
to { DRM_FORMAT_MOD_LINEAR }. However, the last argument of
drm_plane_init_surface disables modifiers -- so the buffer will just
get allocated with an implicit modifier, without necessarily being
LINEAR.

To fix this, allow modifiers when allocating the cursor buffers.
wlr_drm_plane.formats should already have the necessary LINEAR
restrictions.

Fixes: 93cd3a79b2 ("backend/drm: stop using GBM flags")
2021-01-17 22:25:18 +01:00
Simon Ser f17b0f975d backend/drm: add wlr_drm_connector_get_id
This allows a compositor to get a KMS connector object ID from a
wlr_output. The compositor can then query more information about
the connector via libdrm.

This gives more freedom to compositors and allows them to read
KMS properties that wlroots doesn't know about. For instance,
they could read the EDID or the suggested_{X,Y} properties and
change their output configuration based on that.
2021-01-17 12:42:32 +01:00
Simon Ser cb6f584496 backend/drm: add support for the subconnector property
The subconnector property indicates the connector sub-type. This is
useful because that usually indicates what kind of connector the user
has plugged in to their monitor, e.g. a DisplayPort-to-DVI cable will
indicate a DVI subconnector. Also some laptops have non-DP connectors
that are internally linked to a DP port on the GPU.

Set the output description accordingly.

See https://drmdb.emersion.fr/properties/3233857728/subconnector
2021-01-17 12:42:25 +01:00
Simon Ser a6a0568316
backend: remove unnecessary GLES2 includes 2021-01-14 12:36:49 +01:00
Simon Ser dc61f471da
backend/drm: remove unnecessary wlr_drm_fb.wlr_buf check
We don't need this check, wlr_buf is guaranteed not to be NULL.
2021-01-13 19:01:02 +01:00
Simon Ser 5d054258af
backend/drm: fix segfault in page_flip_handler
Since 5b1b43c68c ("backend/drm: make wlr_drm_plane.{pending,queued,current}_fb
pointers"), current_fb can be NULL if there's no buffer. If current_fb
is not NULL, current_fb->wlr_buf is guaranteed to not be NULL.

Closes: https://github.com/swaywm/wlroots/issues/2634
2021-01-12 11:41:45 +01:00
Simon Ser 91cb0fc443 backend/drm: only keep track of local buffer
Stop keeping track of buffers on the parent GPU when multi-GPU is used.

This removes support for export_dmabuf on secondary GPUs, but renderer
v6 will bring this back by managing the swapchains in wlr_output instead
of the backends.
2021-01-10 11:24:35 +01:00
Simon Ser 5b1b43c68c backend/drm: make wlr_drm_plane.{pending,queued,current}_fb pointers
This will be useful once we start re-using wlr_drm_fb.
2021-01-10 11:24:35 +01:00
Simon Ser adfb7cd35a backend/drm: stash pending page-flip CRTC
wlr_drm_connector.crtc may be updated by the DRM backend while a
page-flip is pending. In this case, the page-flip handler won't be able
to find the right wlr_drm_connector from the CRTC ID.

Save the CRTC when performing a page-flip to ensure we always find the
right connector when we get the event.
2021-01-03 19:35:02 +01:00
Simon Ser bec1e6b149 backend/drm: remove special linear case for cursor plane
We now properly mark the cursor plane's formats as linear-only, and we
now have a version of wlr_drm_format_intersect that handles the case of
linear-only formats and implicit modifiers.

We can remove the special drm_plane_init_surface flag we had for cursor
planes. This also allows us to use a non-linear layout for cursor planes
on drivers that support it.

Tested on amdgpu GFX9.
2020-12-30 11:17:43 +01:00
Simon Ser 7ea0e9f277 backend/drm: force LINEAR for cursor plane formats
If the kernel driver doesn't support modifiers, it still expects cursor
FBs to have a LINEAR layout. See [1] for expectations for framebuffers
attached to the cursor plane.

[1]: https://patchwork.freedesktop.org/patch/408512/
2020-12-30 11:17:43 +01:00
Simon Ser b9460ab724
Stop using wlr_texture_get_size
Just use wlr_texture.{width,height} directly.
2020-12-25 12:21:29 +01:00
Simon Ser a7a230ebef
backend/drm: make drmModePlane arg in add_plane const
Make it clearer it'll be free'd after add_plane returns.
2020-12-24 12:34:13 +01:00
Simon Ser c011a0e2ed
backend/drm: add special case for cursor in add_plane
The code calling add_plane now makes sure not to add a cursor plane to a
CRTC which already has one.
2020-12-24 12:31:20 +01:00
Simon Ser 5548406667
backend/drm: log whether ADDFB2 modifiers are supported 2020-12-24 12:29:30 +01:00
Simon Ser 64a2ca4dba
backend/drm: don't retry page-flip when modifiers are unsupported
Parse WLR_DRM_NO_MODIFIERS at startup. Don't parse IN_FORMATS when
WLR_DRM_NO_MODIFIERS is set, so that the legacy behaviour is better
reproduced.

When modifiers aren't supported, try the initial page-flip once only.
2020-12-23 19:49:27 +01:00
Simon Ser 54ec17ff64
backend/drm: use plural form for possible_crtcs
Make it clearer that this is a bitmask of CRTC indices.
2020-12-23 12:14:36 +01:00
Simon Ser 2de400a541
backend/drm: assert connector state after wlr_output_destroy 2020-12-22 19:53:33 +01:00
Simon Ser 85cf4b235d
backend/drm: destroy DRM connectors that disappear
This was lost during the refactoring. We were previously calling
wlr_output_destroy, which destroyed the connector as well.

Fixes: 248c7787c7 ("backend/drm: refactor wlr_output destruction")
2020-12-22 19:38:29 +01:00
Simon Ser d3bcd63a40 backend/drm: remove drm_fb_acquire
Instead, import the buffer into GBM and KMS in drm_fb_import. Also move
the multi-GPU copy there if necessary.
2020-12-22 15:53:10 +01:00
Simon Ser dabd2e7207 backend/drm: grab DMA-BUF from wlr_buffer instead of gbm_bo
Get the DMA-BUF directly out of the wlr_buffer instead of relying on the
gbm_bo. This eliminates a roundtrip through GBM.
2020-12-22 15:53:10 +01:00
Ronan Pigott 917ecca58e backend/drm: avoid gcc stringop-truncation warning 2020-12-18 22:19:16 +01:00
Simon Ser 352fdd1bb0
backend/drm: remove unused wlr_drm_plane.drm_format 2020-12-18 11:44:50 +01:00
Simon Ser 248c7787c7 backend/drm: refactor wlr_output destruction
Instead of hand-rolling our own manual wlr_output cleanup function, rely
on wlr_output_destroy to remove an output from the compositor's state.
2020-12-18 10:48:44 +01:00
Simon Ser 019ffe8a5b backend/drm: introduce wlr_drm_connector.name
The DRM backend is a little special when it comes to wlr_outputs: the
wlr_drm_connectors are long-lived and are created even when no screen is
connected.

A wlr_drm_connector only advertises a wlr_output to the compositor when
a screen is connected. As such, most of wlr_output's state is invalid
when the connector is disconnected.

We want to stop using wlr_output state on disconnected connectors.
Introduce wlr_drm_connector.name which is always valid regardless of the
connector status to avoid reading wlr_output.name when disconnected.
2020-12-18 10:48:44 +01:00
Simon Ser c89b131f29 backend/drm: introduce wlr_drm_conn_log
Simplify and unify connector-specific logging with a new
wlr_drm_conn_log macro. This makes it easier to understand which
connector a failure is about, without having to explicitly integrate the
connector name in each log message.
2020-12-18 10:48:44 +01:00
Simon Ser 253f447329
backend/drm: print DRM device name when scanning connectors 2020-12-17 20:50:19 +01:00
Simon Ser 60001a75a2
backend/drm: remove nouveau workaround
The workaround is broken because drm_fb_acquire doesn't leave the EGL
context current anymore. We'll need to re-introduce it.

References: https://github.com/swaywm/wlroots/issues/2525
2020-12-17 20:38:02 +01:00
Simon Ser da2a216934
backend/drm: add wlr_drm_connector.backend
This allows the DRM code to have direct access to the wlr_drm_backend
without having to go through an upcast via get_drm_backend_from_backend.
2020-12-15 22:56:14 +01:00
Simon Ser 93cd3a79b2 backend/drm: stop using GBM flags
gbm_bo_create_with_modifiers doesn't take GBM flags, so our
wlr_gbm_allocator interface doesn't either. We were still internally
using GBM flags in the DRM backend, leading to awkward back-and-forth
conversions.

The only flag passed to drm_plane_init_surface was GBM_BO_USE_LINEAR, so
turn that into a bool to make sure other flags can't be passed in.

Move the "force linear" logic out of init_drm_surface, because the
supplied wlr_drm_format should already contain that information.
2020-12-13 13:20:39 +01:00
Simon Ser 4c363a564f backend/drm: remove workaround for amdgpu DP MST
Closes: https://github.com/swaywm/wlroots/issues/2533
2020-12-11 23:27:13 +01:00
Simon Ser 6ff478632a backend/drm: remove EGL config
Since we're using wlr_swapchain, we don't need to provide an EGL config.
2020-12-09 14:25:41 +01:00
Stephane Chauveau b790e5ea34 backend/drm: don't assume possible_crtcs has only one bit set
This isn't necessarily the case [1].

This should fix an assertion failure on Raspberry Pi 4 dual screen.

[1]: https://lists.freedesktop.org/archives/dri-devel/2020-August/275142.html

Closes: https://github.com/swaywm/wlroots/issues/1943
Co-authored-by: Simon Ser <contact@emersion.fr>
2020-12-08 18:38:42 +01:00
Simon Ser 863acb26c0 backend/drm: stop tracking overlay planes
We don't do anything with them. Once we do, we can easily add this back.
2020-12-08 18:38:42 +01:00
Ilia Bozhinov 54b7ca56c0 drm: do not unset make/model before emitting destroy event 2020-12-07 10:39:29 +01:00
Simon Ser 1336ad2a23
backend/drm: remove unused if in drm_connector_move_cursor
We return early if we don't have a plane.
2020-12-04 19:34:35 +01:00
Simon Ser 8bc5a92a98 Revert "backend/drm: stop force-probing connectors"
This reverts commit 713c1661b7.

It turns out we do need to force-probe on startup and on hotplug [1].
This is unfortunate, but that's just how the uAPI works. Fixing this
would require patching the kernel.

[1]: https://lists.freedesktop.org/archives/dri-devel/2020-November/289506.html

Closes: https://github.com/swaywm/wlroots/issues/2499
2020-12-01 11:31:03 +01:00
Simon Ser 713c1661b7 backend/drm: stop force-probing connectors
After discussing with Pekka and Daniel on #dri-devel, we concluded [1]
that user-space shouldn't need to force-probe connectors. Force-probing
can take some time, so using drmModeGetConnectorCurrent can result in
faster start-up.

Users can manually trigger a force-probe if necessary:

    echo detect | sudo tee /sys/class/drm/card0-DP-1/status

Or just by running a tool like drm_info.

A similar change has been submitted to Weston [2].

[1]: https://lists.freedesktop.org/archives/dri-devel/2020-November/287728.html
[2]: https://gitlab.freedesktop.org/wayland/weston/-/issues/437
2020-11-24 15:00:46 +01:00
Kenny Levinsen fb3bea8014 backend/drm: Use legacy gamma size for legacy backend
We would always return the GAMMA_LUT_SIZE property if available, and
only fall back to legacy gamma size otherwise. This leads to issues if
both are available in differs in size while we use the legacy backend.

Ensure that we only return the legacy size if we're using the legacy
backend.

Closes: https://github.com/swaywm/wlroots/issues/2429
2020-11-19 22:46:25 +01:00
Simon Ser eef8b3dde8 backend/drm: check drm_surface_render_black_frame return value
This avoids hitting an assertion in drm_fb_lock_surface when
we failed to render a black frame.
2020-11-15 22:48:42 +01:00
Simon Ser 8058e338ea backend/drm: get rid of wlr_drm_fb_type
Since all DRM FBs are backed by a wlr_buffer, there's no need for this
anymore.
2020-11-15 22:48:42 +01:00
Simon Ser 68a8d99055 backend/drm: add support for wlr_swapchain buffer age 2020-11-15 22:48:42 +01:00
Simon Ser ef846a8839 backend/drm: use wlr_swapchain 2020-11-15 22:48:42 +01:00
Simon Ser 1328477a82 backend/drm: export pending FB in export_dmabuf, if any
This allows callers to grab the current frame right after committing it,
without having to incur a full vblank worth of latency.
2020-11-05 09:43:42 +01:00
Simon Ser ee43ef3c9d backend/drm: fix "a page-flip is already pending" errors on modeset
When performing a modeset, the DRM backend will request a page-flip
event. However frame_pending wasn't set to true, so any subsequent
wlr_output_schedule_frame calls would imemdiately trigger a synthetic
frame event, asking the compositor to submit a new frame. Committing the
new frame fails with "a page-flip is already pending" error in the DRM
backend.
2020-11-03 08:09:54 +01:00
Marten Ringwelski 85757665e6 backend/drm: Check if output is enabled before sending frame event
When an output is disabled one last pageflip will happen to disable it.
Currently this pageflip causes a frame event.
Since the output is disabled we don't want to send this frame event.
2020-10-30 10:04:54 +01:00
Devin J. Pohly aaf490d794 drm: fix uninitialized read
get_drm_prop_blob does not set path_len if it returns NULL.  Check the
return value before path_len to avoid reading uninitialized memory.

(Granted, this doesn't change the logic at all, but it does make
Valgrind a bit happier.)
2020-07-31 09:32:14 +02:00
Antonin Décimo d9bb792794 Fix incorrect format parameters 2020-07-27 10:49:19 +02:00
Simon Ser b6377b59ff backend/drm: check drm_surface_make_current return value
drm_connector_set_cursor wasn't checking the return value of the
drm_surface_make_current call. On failure, this results in a failed
assertion in wlr_renderer_begin (because no rendering context is
current).
2020-07-07 11:18:07 -06:00
Simon Ser bf93d2e67c output: rename impl->rollback to rollback_render
The output backend API is now mostly state-less thanks to the atomic
hooks (commit and test). There is one exception though: attach_render.
This function makes the rendering context current. However sometimes the
compositor might decide not to render after attach_render (e.g. when
there's nothing new to render to the back buffer). Thus
wlr_output_rollback has been introduced to revert the pending state.

Because the output backend API is mostly state-less, the only thing
wlr_output_impl.rollback needs to do is revert the current rendering
context. Rename the function to rollback_render to make this clear. Add
a check in the common wlr_output code to only call rollback_render when
attach_buffer has been previously called.

On the long term, we'll be able to remove attach_render and
rollback_render together.
2020-06-19 11:50:42 -06:00
Simon Ser e77c046cf9 backend/drm: fix stack overflow in dealloc_crtc
Call drm_crtc_commit directly instead of calling drm_connector_set_mode.
This restores the previous behaviour where conn_enable was called [1].

[1]: 0c7c562482/backend/drm/drm.c (L1093)

Closes: https://github.com/swaywm/wlroots/issues/2253
2020-06-08 10:13:00 -06:00
Simon Ser 8f28f5b2f8 backend/drm: fix black screens when enabling output
This patch fixes this failure:

    01:57:16.642 [ERROR] [backend/drm/drm.c:360] Failed to page-flip output 'eDP-1': a page-flip is already pending
    01:57:16.684 [ERROR] [backend/drm/drm.c:360] Failed to page-flip output 'eDP-1': a page-flip is already pending
    01:57:16.684 [ERROR] [backend/drm/drm.c:732] Failed to initialize renderer on connector 'eDP-1': initial page-flip failed
    01:57:16.684 [ERROR] [backend/drm/drm.c:805] Failed to initialize renderer for plane
    01:57:16.684 [sway/config/output.c:423] Failed to commit output eDP-1

References: https://github.com/swaywm/sway/issues/5101
2020-06-03 10:27:21 -06:00
Simon Ser b03eebf7d4 backend/drm: always perform a CRTC commit in drm_connector_commit
When the mode, status or buffer hasn't changed, drm_connector_commit was
a no-op. Because of this individual changes to the gamma LUT or adaptive
sync status were ignored (if committed without a buffer).

Instead, perform a commit to apply the changes.
2020-06-01 11:45:11 -06:00
Simon Ser 1a2e82e327 backend/drm: drop extra wlr_output_update_enabled call
drm_connector_set_mode already takes care of keeping this up-to-date.
2020-06-01 11:45:11 -06:00
Simon Ser 80467f6ae8 backend/drm: commit/rollback FBs in drm_crtc_commit
We need to perform the FB bookkeeping on all commits, not just on
page-flips.
2020-06-01 11:45:11 -06:00
Simon Ser 70f3a0bb27 backend/drm: make adaptive_sync atomic
Stop using drmModeObjectSetProperty, set the property in the crtc_commit
function instead.
2020-06-01 11:45:11 -06:00
Simon Ser 42126c2022 backend/drm: rollback pending CRTC state on test commit
A test commit doesn't apply the pending state.

The CRTC state will be populated again if the compositor decides to
perform a regular commit afterwards.
2020-06-01 11:45:11 -06:00
Simon Ser d66b9966e9 backend/drm: fix missing crtc->cursor NULL check
Fixes: cdb6fdbc6c ("backend/drm: remove missing cursor plane workaround")
2020-05-27 21:01:20 +02:00
Simon Ser e7a8ea84c3 backend/drm: don't set cursor if off-screen
Closes: https://github.com/swaywm/wlroots/issues/2216
2020-05-27 21:01:20 +02:00
Simon Ser 15d8f1806e backend/drm: introduce pending and current CRTC state
Previously, we only had the pending state (crtc->pending, crtc->mode and
crtc->active). This causes issues when a commit fails: the pending state
is left as-is, and the next commit may read stale data from it.

This will also cause issues when implementing test-only commits: we need
to rollback the pending CRTC state after a test-only commit.

Introduce separate pending and current CRTC states. Properly update the
current state after a commit.
2020-05-26 23:34:37 +02:00
Simon Ser d6cc718472 backend/drm: nuke retry_pageflip
retry_pageflip is now dead code, since drm_connector_start_renderer
isn't called anymore. It was previously called when enabling an output.
The name "retry_pageflip" was a little confusing because the function
retried a modeset and the timer wasn't set up while performing a simple
page-flip.

Let's just remove this altogether for now. We can discuss whether it's
worth it to bring it back. Should we only do it on failed page-flips?
Should we only do it on EBUSY?
2020-05-26 23:34:37 +02:00
Simon Ser 61095f4a12 backend/drm: make drm_connector_set_mode take a wlr_drm_connector
Since this is an internal DRM backend function, there's no reason we
need to take a generic wlr_output.
2020-05-26 23:34:37 +02:00
Simon Ser 445750aa9a backend/drm: remove enable_drm_connector
Merge enable_drm_connector into drm_connector_set_mode. This allows us
to de-duplicate logic since enabling an output performs a modeset.
2020-05-26 23:34:37 +02:00
Simon Ser c02e9c2bb1 backend/drm: remove drm_connector_set_custom_mode
Replace it with a function that returns the pending mode.
2020-05-26 23:34:37 +02:00
Simon Ser 21c6cc5e4c backend/drm: refuse to enable an output without a mode 2020-05-26 20:10:55 +02:00
Simon Ser af2f69e6c1 render/egl: unset current context after swapping buffers
After swapping buffers, it doesn't make sense to perform more rendering
operations. Unset the context to reflect this.

This commit makes it so the context is always only current between
wlr_egl_make_current and wlr_egl_swap_buffers.

This is an alternative to [1].

[1]: https://github.com/swaywm/wlroots/pull/2212
2020-05-20 17:39:34 +02:00
Simon Ser d28a7da95d backend/drm: add missing wlr_egl_unset_current 2020-05-19 21:32:38 +02:00
Simon Ser 1edc42157b render/egl: introduce wlr_egl_unset_current
This function can be called after wlr_egl_make_current to cleanup the
EGL context. This avoids having lingering EGL contexts that make things
work by chance.

Closes: https://github.com/swaywm/wlroots/issues/2197
2020-05-19 14:56:20 +02:00
Simon Ser 347bdb6d9a output: make wlr_output_set_gamma atomic
wlr_output_set_gamma is now double-buffered and applies the gamma LUT on
the next output commit.
2020-05-14 20:09:28 +02:00
Simon Ser 42e485dcc3 backend/drm: fix segfault in drm_crtc_page_flip
When no cursor plane is available, drm_crtc_page_flip would segfault.
2020-05-14 10:20:37 +02:00
Simon Ser 9412d34e2d backend/drm: disable cursor in dealloc_crtc
dealloc_crtc was destroying GBM surfaces, but the cursor_enabled flag
was left as-is. When re-enabling the output, atomic_crtc_pageflip would
try enabling the cursor plane, but would fail because no framebuffer is
available.

Closes: https://github.com/swaywm/wlroots/issues/2150
2020-05-12 15:12:22 +02:00
Simon Ser da4df82532 backend/drm: fix combined modeset+enable commits
When an output is enabled and modeset at the same time,
drm_connector_commit would first try to modeset then try to commit. This
won't work because both will trigger a page-flip. KMS will reject that.

Change the logic to only enable an output if no modeset has been
requested. The logic in wlr_output already checks that the user isn't
doing a modeset and disabling the output at the same time.
2020-05-12 15:12:06 +02:00
Simon Ser cdb6fdbc6c backend/drm: remove missing cursor plane workaround
We have a workaround for legacy drivers that support drmModeSetCursor
without exposing a cursor plane. It doesn't work anymore now that we've
moved to a more atomic interface.

Let's just remove this workaround and fallback to software cursors.

Closes: https://github.com/swaywm/wlroots/issues/2166
2020-05-12 08:57:13 +02:00
JonnyMako 1139234117
backend/drm: fix missing cursor on external monitors with multi-GPU setup and nouveau
We need to make the multi-GPU surface current before the glFinish call.

Closes: https://github.com/swaywm/sway/issues/5319
2020-05-11 08:51:41 +02:00
Simon Ser 2ca3bdc35e backend/drm: simplify atomic commit logic
We don't need a per-CRTC atomic request anymore. Let's make the request
per-commit so that it's easier to debug.

This is also groundwork for supporting wlr_output_test properly.
2020-05-10 09:21:04 +02:00
Simon Ser 06d5aa5780 backend/drm: GAMMA_LUT_SIZE isn't atomic
GAMMA_LUT_SIZE isn't an atomic property. It can be used with the legacy
interface too. So we can unify both codepaths and remove
wlr_drm_interface.crtc_get_gamma_size.

It's no guaranteed to exist though, so we still need to keep the
fallback.
2020-05-10 09:20:46 +02:00
Simon Ser da63d11d34 backend/drm: remove crtc_set_cursor from interface 2020-05-09 16:42:25 +02:00
Simon Ser f8e02db4bc backend/drm: remove conn_enable from interface
Use crtc_commit instead.
2020-05-09 16:42:25 +02:00
Simon Ser c608fc89d8 backend/drm: rename crtc_pageflip to crtc_commit
Also add a flags argument.

The commit function will also be used for disabling the CRTC.
2020-05-09 16:42:25 +02:00
Simon Ser 70883fd10b backend/drm: apply gamma LUT on page-flip 2020-05-09 16:42:25 +02:00
Simon Ser 69b2279092 backend/drm: remove mode argument to crtc_pageflip
Add a new wlr_drm_crtc.pending bitfield which keeps track of pending
output changes. More fields will be added in the future (e.g. active,
gamma).
2020-05-09 16:42:25 +02:00
Simon Ser c9d6b18eef backend/drm: remove wlr_drm_interface.crtc_move_cursor
Instead, make the legacy backend call drmModeMoveCursor on page-flip.
2020-05-09 16:42:25 +02:00
Simon Ser 90ede7f838 backend/drm: make page-flip error scarier
The logs don't currently display the importance of a line. It's easy to
read "skipping page-flip" as a debug message instead of an error
message.

Change the error message to make it more explicit.

References: https://github.com/swaywm/wlroots/pull/2147
2020-05-01 16:48:42 +02:00
Will Daly 044a9f28d6 Fix error when reconnecting external display
Reconnecting an external display fails on initial
page-flip.  This occurs when the pageflip_pending flag
has been set on the connector at the time the monitor
is removed.  Once the connector's CRTC has been deallocated,
page_flip_handler cannot find the connector by its crtc_id,
so pageflip_pending will remain set.  This causes
initialization to fail when the monitor is reconnected
with the error messages:

    Skipping pageflip on output 'X'
    Failed to initialize renderer on connector 'X': initial page-flip failed

To fix this problem, clear the pageflip_pending flag
when cleaning up the connector.
2020-05-01 16:01:30 +02:00
Scott Anderson 321537ee92 backend/drm: don't allow legacy to use direct scanout 2020-04-28 09:54:52 +02:00
Scott Anderson 52281cb8ba backend/drm: move atomic cursor code into pageflip code
It makes sense to construct as much atomic state as possible in the same
place, so it doesn't get lost if we "reset" it.
2020-04-28 09:54:52 +02:00
Scott Anderson 8da9d9679e backend/drm: introduce wlr_drm_fb
This is a type which manages gbm_surfaces and imported dmabufs in the
same place, and makes the lifetime management between the two shared. It
should lead to easier to understand code, and fewer special cases.

This also contains a fair bit of refactoring to start using this new
type.

Co-authored-by: Simon Ser <contact@emersion.fr>
2020-04-28 09:54:52 +02:00
Simon Ser 50ade3671f output: check for buffer size compatibility in common code
Instead of checking for buffer size compatibility in each backend,
centralize the check in wlr_output itself.
2020-04-10 15:52:20 +02:00
Simon Ser 5f092c55d1 output: fix blurred hw cursors with fractional scaling
The scaling factor was being implicitly cast to an int.

Closes: https://github.com/swaywm/sway/issues/4927
2020-04-10 15:10:12 +02:00
Simon Ser 507d9bc19e Add wlr_output_impl.rollback
Most of the pending output state is not forwarded to the backend prior
to an output commit. For instance, wlr_output_set_mode just stashes the
mode without calling any wlr_output_impl function.
wlr_output_impl.commit is responsible for applying the pending mode.

However, there are exceptions to this rule. The first one is
wlr_output_attach_render. It won't go away before renderer v6 is
complete, because it needs to set the current EGL surface.

The second one is wlr_output_attach_buffer.
wlr_output_impl.attach_buffer is removed in [1].

When wlr_output_rollback is called, all pending state is supposed to be
cleared. This works for all the state except the two exceptions
mentionned above. To fix this, introduce wlr_output_impl.rollback.

Right now, the backend resets the current EGL surface. This prevents GL
commands from affecting the output after wlr_output_rollback.

This patch is required for FBO-based outputs to work properly. The
compositor might be using FBOs for its own purposes [2], having leftover
FBO state can have bad consequences.

[1]: https://github.com/swaywm/wlroots/pull/2097
[2]: https://github.com/swaywm/wlroots/pull/2063#issuecomment-597614312
2020-04-08 17:33:00 +02:00
Simon Ser d3bd5f2a7b backend: reset EGL surface after buffer swap
This prevents GL commands to affect a previously current EGL surface
after a buffer swap.
2020-04-08 17:33:00 +02:00
Simon Ser 6977f3a843 output: check buffer in wlr_output_test
Check that buffer can be scanned out in wlr_output_test instead of
wlr_output_attach_buffer. This allows the backend to have access to the
whole pending state when performing the check.

This brings the wlr_output API more in line with the KMS API.

This removes the need for wlr_output_attach_buffer to return a value,
and for wlr_output_impl.attach_buffer.
2020-04-08 16:31:21 +02:00
Simon Ser e041158988 output: introduce wlr_output_test 2020-04-08 16:31:21 +02:00
Simon Ser 6595db6409 buffer: add a release event
Consumers call wlr_buffer_lock. Once all consumers are done with the
buffer, only the producer should have a reference to the buffer. In this
case, we can release the buffer (and let the producer re-use it).
2020-04-02 15:03:43 +02:00
Filip Sandborg 5ee52a3ab9
Fix uint32 overflow in fill_empty_gamma_table on Icelake platform
Closes: https://github.com/swaywm/sway/issues/4826
2020-03-15 18:41:12 +01:00
Simon Ser 52c67284e2 backend/drm: add support for adaptive_sync_enabled
The vrr_capable and VRR_ENABLED properties are used.
2020-03-06 21:32:58 +01:00
Simon Ser 348f52b5fc output: remove wlr_output_impl.schedule_frame
This function allowed backends to provide a custom function for frame
scheduling. Before resuming the rendering loop, the DRM and Wayland
backends would wait for vsync.

There isn't a clear benefit of doing this. The only upside is that we
get more stable timings: the delay between two repaints doesn't change too
much and is close to a mutliple of the refresh rate.

However this introduces latency, especially when a client misses a
frame. For instance a fullscreen game missing vblank will need to wait
more than a whole frame before being able to display new content. This
worst case scenario happens as follows:

- Client is still rendering its frame and cannot submit it in time
- Deadline is reached
- Compositor decides to stop the rendering loop since nothing changed on
  screen
- Client finally manages to render its frame, submits it
- Compositor calls wlr_output_schedule_frame
- DRM backend waits for next vblank
- The wlr_output frame event is fired, compositor draws new content on screen
- On the second next vblank, the new content reaches the screen

With this patch, the wlr_output frame event is fired immediately when
the client submits its late frame.

This change also makes it easier to support variable refresh rate, since
VRR is all about being able to present too-late frames earlier.

References: https://github.com/swaywm/wlroots/issues/1925
2020-03-04 03:22:19 +01:00
Rouven Czerwinski 144d2041ad backend/drm: remove overzealous finish_drm_surface
The previous PR was overzealous in adding a finish_drm_surface call
which was also done by the caller. Remove the call and also move the
comment to the correct code location.
2020-01-24 19:57:09 +01:00
Rouven Czerwinski f0594fb732 backend/drm: add env variable to disable modifiers
In some cases modesets fail if the planes are initialized with
modifiers. Since in this case possibly all planes need to reinitialized,
which is not possible in the current wlroots design, add an environment
variable for affected users.
2020-01-24 19:43:51 +01:00
Simon Ser 7c05933e51 backend/drm: prevent outputs from being destroyed on commit
This would happen if initializing the renderer fails. Instead, we just
mark the output as disabled.

References: https://github.com/swaywm/sway/pull/4917
2020-01-17 06:49:31 -07:00
Simon Ser 21e1953b61 backend/drm: don't modeset with a NULL mode after TTY switch
This fixes a segfault in drm_connector_set_mode (mode = NULL).

This happens because we set wlr_output.enabled to true if the connector
is attached to the CRTC. When the user disables an output in the
wlroots-based compositor, switches to another VT (enabling the output),
then switches back, wlroots sets wlr_output.enabled to true but
wlr_output.current_mode is NULL.

We should consider not reading properties from KMS after a TTY switch,
disabling all connectors. However this may result in flickering (outputs
being disabled then re-enabled).

Closes: https://github.com/swaywm/wlroots/issues/1874
2019-12-30 14:32:37 -07:00
Simon Ser 8fc16890c7 output: refuse to commit a buffer or modeset a disabled output
References: https://github.com/swaywm/wlroots/issues/1780#issuecomment-518938390
2019-12-30 11:21:11 -07:00
Simon Ser f0781cd792 backend/drm: modeset before enabling an output
This saves one modeset in case the previous mode is different.
2019-12-30 11:21:11 -07:00
Simon Ser 5d1ba0f446 output: re-introduce atomic mode, enabled, scale and transform
This reverts commit 01f903874b and re-applies
commit ee5f98ad49.

Updates: https://github.com/swaywm/wlroots/issues/1640 (Atomic output updates issue)
See also: https://github.com/swaywm/wlroots/pull/1762 (Atomic output updates original PR)
See also: https://github.com/swaywm/wlroots/issues/1780 (Issue caused by atomic output updates)
See also: https://github.com/swaywm/sway/issues/4419 (Issue caused by atomic output updates)
See also: https://github.com/swaywm/wlroots/pull/1781 (Revert PR)
2019-12-30 11:21:11 -07:00
Simon Ser 4da4a15d6b output: add description
wlr_output.description is a string containing a human-readable string
identifying the output. Compositors can customise it via
wlr_output_set_description, for instance to make the name more
user-friendly.

References: https://github.com/swaywm/wlroots/issues/1623
2019-12-29 12:35:22 -05:00
Rouven Czerwinski be4b9f7f5b backend/drm: print preferred mode
While printing the supported output modes, annotate the preferred mode.
2019-12-20 11:00:21 +01:00
Jason e8855ee462 Amend typos 2019-11-23 10:33:47 -05:00
Simon Ser 6c649bab53 output: add wlr_output_event_present.commit_seq
This is set to the value of wlr_output.commit_seq when the frame has
been submitted. This allows tracking presentation with more then 1 full
frame of latency.

References: https://github.com/swaywm/wlroots/issues/1917
2019-11-17 00:12:59 +01:00
Simon Ser 0e57effd38 backend/drm: add support for custom modes
Use the CVT algorithm to create a drmModeModeInfo.
2019-10-27 10:46:47 -04:00
Simon Ser e97c2c3639 backend/drm: retry without modifiers for the primary plane
On some Intel cards using modifiers can fill the FIFO and prevent
hotplugged outputs from being properly enabled.

Add a fallback without modifiers.

Fixes: 2bdd1d0896 ("backend/drm: use modifiers for our GBM buffers")
References: https://github.com/swaywm/wlroots/issues/1840
Closes: https://github.com/swaywm/wlroots/issues/1852
2019-10-23 09:36:50 +00:00
Simon Ser fd25e2ca11 backend/drm: track gbm_bo during direct scan-out
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: https://github.com/swaywm/sway/issues/4662
2019-10-22 21:50:31 +00:00
Simon Ser 2bdd1d0896 backend/drm: use modifiers for our GBM buffers 2019-10-11 08:11:48 -04:00
Rouven Czerwinski bf90474b74 backend/drm: check for mst: in path property
Instead of checking that the path property is not 0 to determine if the
connector is an MST connector, check if the path contains the mst:
string.

Fixes #1813
2019-09-05 10:25:12 +03:00
Simon Ser 8d2ea9544b backend/drm: fix missing plane formats
The loop populating the format list was exiting early if ARGB8888 was found.
2019-08-15 12:33:42 +12:00
Antonin Décimo 39c5d93dea backend/drm: use UINT64_C for uint64_t literals
Prevents an integer promotion bug during the byte-shift.
2019-08-12 09:37:21 +09:00
Rouven Czerwinski 01f903874b Revert "output: atomic mode"
This reverts commit ee5f98ad49.

This intoduced problems where outputs could not be turned off because
they had flips pending.
2019-08-07 16:22:11 +09:00
Rouven Czerwinski 4d36cc86eb backend/drm: destroy output immediately
Instead of waiting for the next pageflip, destroy the output immediately
since we can now handle flips for outputs which no longer exist.
Also demote the missing crtc on flip to debug.

Fixes #1739
2019-08-03 15:44:21 +02:00
Simon Ser ee5f98ad49 output: atomic mode, enabled, scale and transform
This commit makes more output properties (mode, enabled, scale and transform)
atomic. This means that they are double-buffered and only applied on commit.

Compositors now need to call wlr_output_commit after setting any of those
properties.

Internally, backends still apply properties sequentially. The behaviour should
be exactly the same as before. Future commits will update some backends to take
advantage of the atomic interface. Some backends are non-atomic by design, e.g.
the X11 backend or the legacy DRM backend.

Updates: https://github.com/swaywm/wlroots/issues/1640
2019-08-02 10:01:29 -04:00
Simon Ser ca45f4490c Remove all wayland-server.h includes
The documentation for wayland-server.h says:

> Use of this header file is discouraged. Prefer including
> wayland-server-core.h instead, which does not include the server protocol
> header and as such only defines the library PI, excluding the deprecated API
> below.

Replacing wayland-server.h with wayland-server-core.h allows us to drop the
WL_HIDE_DEPRECATED declaration.
2019-07-27 15:49:32 -04:00
Rouven Czerwinski d10072e76c backend: drm: switch to pageflip_handler_2
atomic and legacy now both pass the backend as the user data for the
pageflip event. We than retrieve the correct connector by matching on
the crtc_id passed to the page_flip_handler2.

Wlroots also requires the DRM_CRTC_IN_VBLANK_EVENT capability now.

Fixes #1297
2019-06-27 00:17:27 +00:00
Scott Anderson 46dc4100d6 backend/drm: Exit-early if 0 crtcs
This fixes an assertion failure if we're using a device that has 0 crtcs
as a renderer.
This would happen on some laptops with discrete GPUs.
2019-06-24 09:09:36 +03:00
Scott Anderson b3f42548d0 backend/drm: Simplify object matching code
We originally used match_obj on planes, but this was largely
unnecessary. Instead, this assigns planes statically at startup.
2019-06-22 11:58:33 +03:00
Simon Ser ce3f4c3fe1 output: remove wlr_output_impl.transform
The backend doesn't need to handle transform changes, since everything is done
in software. In fact, all of the implementations were all identical and just
set the transform.

We could add support for hardware transforms, but:

- This would require a different field (something like hardware_transform)
- Not all combinations are possible because there often are hardware
  limitations
- The Wayland protocol isn't ready for this (in particular xdg-output, see [1])

This belongs to a different patch series anyway.

[1]: https://patchwork.freedesktop.org/series/52324/
2019-06-16 10:51:49 -04:00
Simon Ser e8057bb60c backend/drm: fallback to drmModeAddFB2 2019-06-07 09:06:11 -04:00
Simon Ser d1766547bd backend/drm: reject DMA-BUFs with flags 2019-06-07 09:06:11 -04:00
Simon Ser 44ba603c0e backend/drm: hold buffers while scanning out 2019-06-07 09:06:11 -04:00
Simon Ser afe7b207d5 output: fix attach_buffer semantics 2019-06-07 09:06:11 -04:00
Simon Ser 1d222309b8 output: change set_dmabuf to attach_buffer 2019-06-07 09:06:11 -04:00
Simon Ser 5c78f1b0d5 backend/drm: strip alpha channel on scan-out 2019-06-07 09:06:11 -04:00
Simon Ser e516ea4c79 backend/drm: check format when scanning out DMA-BUF 2019-06-07 09:06:11 -04:00
emersion 96d6fde5dc backend/drm: add basic support for direct scan-out 2019-06-07 09:06:11 -04:00
Simon Ser 20690346c7 output: rename needs_commit to needs_frame
This new name makes more sense, since it is a request from the backend to get
a new frame. In the future a commit may not convey a new frame.
2019-04-23 14:34:30 -06:00
Simon Ser 9a0f8a194c output: refactor backend API
This updates the backend part of the output API. This is mostly renaming:
make_current becomes attach_render and swap_buffers becomes commit.

This also fixes the RDP backend to support NULL damage.
2019-04-23 14:34:30 -06:00
Alyssa Ross 95b22619e0 Fix missing headers when building without X11
The deleted includes are redundant, because other headers will include
the necessary files. Additionally, they cause build failures, because
including EGL/egl.h or EGL/eglext.h directly, instead of through
wlr/render/egl.h or wlr/render/interface.h, will mean that
MESA_EGL_NO_X11_HEADERS will not have been defined, and so the EGL
headers will attempt to pull in unnecessary X11 headers that may not
exist on the system.

For the headers produced by glgen.sh, the includes couldn't simply be
deleted, because no other header would include the EGL headers. Neither
wlr/render/egl.h or wlr/render/interface.h felt appropriate to include,
so I opted instead to copy the MESA_EGL_NO_X11_HEADERS definition before
the EGL includes.
2019-04-22 00:04:08 +03:00
Guido Günther cd60f40bbb wlr_output: Add preferred property (#1625)
* wlr_output: Indicate modes link

* wlr_output: Introduce preferred flag

This indicates an outputs preferred mode.

* drm: Set preferred flag for an outputs preferred mode
2019-03-21 22:12:43 +02:00
Scott Anderson 6a8f17b5f6 backend/drm: Don't fail on failing to find overlay format
Some hardware exists which doesn't support XRGB/ARGB overlays, and we
aren't even using overlay planes, so don't fail on trying to find a
format.
2019-03-05 23:15:20 +01:00
Scott Anderson d945c97926 backend/drm: Unset cursor on cleanup
This will prevent the cursor from persisting on the Linux framebuffer
terminal on exit.
2019-02-24 09:04:36 +01:00
Rouven Czerwinski e1834ace28 backend/drm: fix memory leak in realloc crtcs
If *changed_outputs is not supplied by the calling function, track the local
allocation with a bool variable and free the allocation at the end of the
function.
2019-02-21 08:19:12 +01:00
Brian Ashworth 50011e7170 backend/drm: fix modeset on drm fd resume
On DRM resume, such as switching back to a TTY, the output needs to be
modeset to the current mode. However, wlr_output_set_mode will return
early when attempting to set the mode to the current mode. This just
steps around wlr_output_set_mode and calls drm_connector_set_mode
directly.
2019-02-19 16:49:51 +01:00
emersion 2a738803b2
backend/drm: fix NULL dereference when unsetting cursor
This segfault happens on multi-GPU systems.

Fixes https://github.com/swaywm/sway/issues/3717
2019-02-18 20:15:39 +01:00
Drew DeVault 2d2c79e37c
Merge pull request #1537 from VincentVanlaer/cursor-dmabuf-nouveau
Add workaround for hardware cursors on nouveau
2019-02-15 16:07:50 +01:00
Vincent Vanlaer 26a9fa8148 Add workaround for hardware cursors on nouveau 2019-02-15 15:59:09 +01:00
Drew DeVault 9a5d59a839 Revert "drm: do not modeset to current mode"
This reverts commit 72c76b128e.
2019-02-15 09:44:42 -05:00
Vincent Vanlaer bc048b22fb Copy cursor surface to secondary gpu if necessary 2019-02-14 12:31:54 +01:00
Brian Ashworth 72c76b128e drm: do not modeset to current mode
There is no point in modesetting an output to a mode that it is already
set to. Modesetting will cause the output to briefly flicker which is
undesirable for a noop. This returns early in `drm_connector_set_mode`
when attempting to modeset to the current mode.
2019-02-14 10:59:06 +01:00
Vincent Vanlaer 7bc43413ed Allow cursor render surface to be used as fb
In order for a surface to be used as a cursor plane framebuffer, it
appears that requiring the buffer to be linear is sufficient.

GBM_BO_USE_SCANOUT is added in case GBM_BO_USE_LINEAR isn't sufficient
on untested hardware.

Fixes #1323

Removed wlr_drm_plane.cursor_bo as it does not serve any purpose
anymore.

Relevant analysis (taken from the PR description):

While trying to implement a fix for #1323, I found that when exporting
the rendered surface into a DMA-BUF and reimporting it with
`GBM_BO_USE_CURSOR`, the resulting object does not appear to be valid.
After some digging (turning on drm-kms debugging and switching to legacy
mode), I managed to extract the following error: ```
[drm:__setplane_check.isra.1 [drm]] Invalid pixel format AR24
little-endian (0x34325241), modifier 0x100000000000001 ``` The format
itself refers to ARGB8888 which is the same format as
`renderer->gbm_format` used in master to create the cursor bo. However,
using `gbm_bo_create` with `GBM_BO_USE_CURSOR` results in a modifier of
0. A modifier of zero represents a linear buffer while the modifier of
the surface that is rendered to is  `I915_FORMAT_MOD_X_TILED` (see
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/uapi/drm/drm_fourcc.h?h=v4.20.6#n263).
In order to fix this mismatch in modifier, I added the
`GBM_BO_USE_LINEAR` to the render surface and everything started to work
just fine. I wondered however, whether the export and import is really
necessary. I then decided to test if the back buffer of the render
surface works as well, and at least on my hardware (Intel HD 530 and
Intel UHD 620) it does. This is the patch in this PR and this requires
no exporting and importing.

I have to note that I cheated in order to import DMA_BUFs into a cursor
bo when doing the first tests, since on import the Intel drivers check
that the cursor is 64x64. This is strange since cursor sizes other than
64x64 have been around for quite some time now
(https://lists.freedesktop.org/archives/mesa-commit/2014-June/050268.html).
Removing this check made everything work fine. I later (while writing
this PR) found out that `__DRI_IMAGE_USE_CURSOR` (to which
`GBM_BO_USE_CURSOR` translates) has been deprecated in mesa
(https://gitlab.freedesktop.org/mesa/mesa/blob/master/include/GL/internal/dri_interface.h#L1296),
which makes me wonder what the usecase of `GBM_BO_USE_CURSOR` is. The
reason we never encountered this is that when specifying
`GBM_BO_USE_WRITE`, a dumb buffer is created trough DRM and the usage
flag never reaches the Intel driver directly. The relevant code is in
https://gitlab.freedesktop.org/mesa/mesa/blob/master/src/gbm/backends/dri/gbm_dri.c#L1011-1089
. From this it seems that as long as the size, format and modifiers are
right, any surface can be used as a cursor.
2019-02-04 20:47:07 +01:00
emersion ee293fab58
backend/drm: fix GBM format mismatch
We create the EGL config with GBM_FORMAT_ARGB8888, but then initialize GBM BOs
with GBM_FORMAT_XRGB8888. This mismatch confuses Mesa.

Instead, we can always use GBM_FORMAT_ARGB8888, and use DRM_FORMAT_XRGB8888
when calling drmModeAddFB2.

Fixes https://github.com/swaywm/wlroots/issues/1438
2019-01-29 12:04:12 +01:00
emersion d4ffa5b7a6
backend/drm: fix state for outputs loosing their CRTC
When there aren't enough CRTCs for all outputs, we try to move a CRTC from a
disabled output to an enabled one. When this happens, the old output's state
wasn't changed, so the compositor thought it was still enabled and rendering.

This commit marks the old output as WLR_DRM_CONN_NEEDS_MODESET and sets its
current mode to NULL.
2019-01-19 10:18:03 +01:00
Timidger 9af0c5338f
Standardize the wlr_box input paramaters
Fixes #1094
2018-12-21 13:56:10 -05:00
emersion ff6c4f80b2
backend/drm: don't insert duplicate custom modes, fix refresh rate 2018-12-16 11:06:46 +01:00
Scott Anderson fec88770dd backend/drm: Fix uninitialized variable 2018-12-09 22:55:53 +13:00
Scott Anderson efdd4d6ea2 backend/drm: Improve encoder logic
This fixes an issue that can occur with DP MST connectors not reporting
any encoders.
2018-12-09 22:48:00 +13:00
emersion f8056a0350
backend/drm: fix disappeared output indices
This commit changes `scan_drm_connectors` to add new outputs to the end of the
list. That way, it's easier to understand what's going on with indices.

When we need to destroy outputs, we now walk the list in reverse order. This
ensures indices remain correct while iterating and removing items from the
list.

We now also make outputs without a CRTC disappear (those are in
WLR_DRM_CONN_NEEDS_MODESET state).
2018-12-09 10:12:52 +01:00
emersion 491f1dbf75
backend/drm: fix VLA overflow 2018-12-04 18:56:29 +01:00
Rostislav Pehlivanov 91513c89cd Fix interlaced mode rejection 2018-11-22 17:52:52 +00:00
Rostislav Pehlivanov dc9fdd6385 Skip interlaced modes during drm mode detection
Fixes #3167
A better solution could be made if there's a need to.
2018-11-21 19:23:48 +00:00
emersion 68362b37a8
backend/drm: fix frame scheduling on secondary GPUs
There was a missing copy_drm_surface_mgpu call in drm_connector_schedule_frame
so we asked for a pageflip with an unknown BO, resulting in ENOENT.

Additionally, this commit makes schedule_frame return a bool indicating
failures. This allows schedule_frame_handle_idle_timer to only set
frame_pending to true if a frame has been successfully scheduled. Thus, if a
pageflip fails, rendering won't be blocked forever anymore.

In case a pageflip is already pending, true is returned because a frame has
already been scheduled and will be sent sometime soon.
2018-10-29 20:38:57 +01:00
sghctoma fa587b8ea9 Increase _POSIX_C_SOURCE to 200112L
CLOCK_MONOTONIC appeared in IEEE Std. 1003.1-200x, it was not part of
POSIX.1b (the 1993 version), and FreeBSD treats it accordingly.
2018-10-17 08:33:19 +02:00
emersion b66041a9e5 backend/drm: don't reset conn->pageflip_pending in drm_connector_cleanup
If a pageflip is pending before cleanup, it's still pending after. This
is used line 1177: drm_connector_cleanup is called and
conn->pageflip_pending is checked afterwards.

Fixes #1297
2018-10-09 14:54:33 +02:00
Drew DeVault 8488ed2997
Merge pull request #1298 from emersion/output-dangling-idle-frame
output: remove idle_frame event source when destroying output
2018-10-09 13:41:04 +02:00
Rouven Czerwinski 77478ac302 backend/drm: set drmEventContext version to 2
As per [1] set drmEventContext version to 2, since wlroots does not use the
page_flip_handler2.

[1]: https://s-opensource.org/2017/04/12/libdrm-event-handling-youre-probably-wrong/
2018-10-09 12:34:01 +02:00
emersion 46b1ba386f output: remove idle_frame event source when destroying output
This prevents the idle event to be activated on a destroyed
output.

This also makes the backend responsible for free-ing modes, as it
is the one allocating them and adding them to the list. Note that
the DRM backend (the only one using modes) already frees them.
2018-10-09 10:55:03 +02:00
Scott Anderson 885586a831
Merge pull request #1280 from emersion/drm-link-status
backend/drm: add support for the link-status property
2018-10-08 21:01:30 +02:00
emersion 37de179013 backend/drm: fix zero-length VLAs 2018-10-07 13:04:52 +02:00
emersion 776008da69 backend/drm: properly handle GPUs without CRTCs 2018-10-07 12:59:00 +02:00
emersion ba91422747 output: don't trigger a frame immediately in schedule_frame
This desynchronizes our rendering loop with the vblank cycle.

In case a compositor doesn't swap buffers but schedules a frame,
emitting a frame event immediately enters a busy-loop.

Instead, ask the backend to send a frame when appropriate. On
Wayland we can just register a frame callback on our surface. On
DRM we can do a no-op pageflip.

Fixes #617
Fixes swaywm/sway#2748
2018-10-05 16:18:37 +02:00
emersion eac7c2ad2f output: add presentation refresh prediction 2018-10-04 22:00:24 +02:00
emersion 54e1287f30 backend: add get_present_clock 2018-10-04 21:58:17 +02:00
emersion 78389fe722 output: add present event 2018-10-04 21:56:38 +02:00
emersion f5a147b739 backend/drm: add support for the link-status property 2018-10-04 21:54:27 +02:00
emersion e88db9a3fb backend/drm: reset gamma table on VT switch 2018-10-03 10:53:35 +02:00
emersion 2beb68007e output: make gamma size a size_t and gamma table const 2018-10-03 10:36:33 +02:00
emersion 79dd9ba151 backend/drm: don't free connector immediately
When a pageflip is pending, we'll get a DRM event for the connector
in the future. We don't want to free the connector immediately
otherwise we'll use-after-free in the pageflip handler.

This commit adds a new state, "DISAPPEARED". This asks the pageflip
handler to destroy the output after it's done pageflipping.
2018-09-28 10:00:40 +02:00
emersion 139a905924 backend/drm: add assertions 2018-09-18 11:06:01 +02:00
emersion f8a50e4fe7 backend/drm: steal CRTCs from disabled outputs
This commit allows outputs that need a CRTC to steal it from
user-disabled outputs. Note that in the case there are enough
CRTCs, disabled outputs don't loose it (so there's no modeset
and plane initialization needed after DPMS). CRTC allocation
still prefers to keep the old configuration, even if that means
allocating an extra CRTC to a disabled output.

CRTC reallocation now happen when enabling/disabling an output as
well as when trying to modeset. When enabling an output without a
CRTC, we realloc to try to steal a CRTC from a disabled output
(that doesn't really need the CRTC). When disabling an output, we
try to give our CRTC to an output that needs one. Modesetting is
similar to enabling.

A new DRM connector field has been added: `desired_enabled`.
Outputs without CRTCs get automatically disabled. This field keeps
track of the state desired by the user, allowing to automatically
re-enable outputs when a CRTC becomes free.

This required some changes to the allocation algorithm. Previously,
the algorithm tried to keep the previous configuration even if a
new configuration with a better score was possible (it only changed
configuration when the old one didn't work anymore). This is now
changed and the old configuration (still preferred) is only
retained without considering new possibilities when it's perfect
(all outputs have CRTCs).

User-disabled outputs now have `possible_crtcs` set to 0, meaning
they can only retain a previous CRTC (not acquire a new one). The
allocation algorithm has been updated to do not bump the score
when assigning a CRTC to a disabled output.
2018-09-15 08:37:33 +02:00
emersion cb293f09e7 output: make wlr_output_enable return a bool 2018-09-14 18:18:07 +02:00
emersion 1fcecd68df backend/drm: de-allocate unused CRTCs
They can be re-used by another output after a subsequent hotplug.
2018-09-10 18:46:30 +02:00
emersion 8a6bdc193d backend/drm: damage outputs when switching CRTCs 2018-09-04 23:10:37 +02:00
emersion 017cfb0b86 backend/drm: log when de-allocating CRTC 2018-09-04 19:44:44 +02:00
emersion b877daded1 backend/drm: better hotplug handling
This commit handles better situations in which the number of
connected outputs is greater than the number of available CRTCs.
It'll enable as many outputs as possible, and transfer CRTCs to
outputs that need one on unplug.

This changes CRTC and plane reallocation to happen after scanning
DRM connectors instead of on modeset.

This cleanups CRTCs and planes on unplug to allow them to be
re-used for other outputs.

On modeset, if an output doesn't have a CRTC, the desired mode is
saved and used later when the output gains a CRTC.

Future work includes giving priority to enabled outputs over
disabled ones for CRTC allocation. This requires the compositor to
know about all outputs (even outputs without CRTCs) to properly
modeset outputs enabled in the compositor config file and disable
outputs disabled in the config file.
2018-09-04 15:09:07 +02:00
emersion 95d05acda5 backend/drm: fix invalid VLA size in scan_drm_connectors
I failed to see this issue with Valgrind because of the +1.
2018-09-02 10:11:23 +02:00
emersion ef88df2142 backend/drm: emit new_output after scanning connectors
This prevents receiving modesetting requests from the compositor
while we don't have the whole picture (ie. while we haven't yet
scanned all connectors).

This also makes connectors without CRTCs disabled (they can't be
enabled yet even if some CRTCs are free'd -- this is future work).
2018-09-02 01:03:20 +02:00
emersion e84f01168d backend/drm: allow disabling outputs in NEEDS_MODESET state
This correctly frees CRTCs when disabling outputs without setting
a mode.
2018-09-01 23:43:16 +02:00
Scott Anderson 2d8f53affd Check for DRM prime
This will indicate the user properly when multi-GPU is not supported by
their GPU driver.
2018-08-05 18:25:25 +12:00
Scott Anderson 4bee710c30 Fix hardware cursor on secondary GPU
Create rendering resources on parent GPU, so that we can sample the
passed in texture properly. The cursor buffer needs to remain on the
same GPU.
2018-08-04 15:08:28 +12:00
emersion 364afced3e backend/drm: remove unnecessary casts 2018-08-02 23:33:59 +01:00
emersion 2ebecb6727 backend/drm: allow to pass empty gamma ramp to reset it 2018-08-02 23:33:59 +01:00
emersion a149c2370a Implement wlr-gamma-control-unstable-v1 2018-08-02 23:33:04 +01:00
emersion 7cbef15206
util: add wlr_ prefix to log symbols 2018-07-09 22:49:54 +01:00
Drew DeVault be54278207
Merge pull request #1095 from agx/output-add-mode
Allow to add additional modes to outputs
2018-07-07 08:58:17 -07:00
Guido Günther 8d72090afe drm: Allow to add additional modes
This allows to add additional modes to the list of available video modes
using VESA Coordinated Video Timing information.

Closes #1080
2018-07-07 14:51:39 +02:00
emersion 2b9cbaddf3
screencopy: add support for frame flags 2018-06-30 22:18:03 +01:00
Dominique Martinet f0d455f088 drm backend: overflow fixes
These operations are done in 32-bit arithmetics before being casted to 64-bit,
thus can overflow before the cast.
Casting early fixes the issue.

Found through static analysis
2018-06-30 11:21:22 +09:00
emersion 21928cbe61
Merge branch 'master' into screencontent 2018-05-31 12:33:27 +01:00
emersion bd430b8620
backend/drm: support multi-planar DMA-BUFs when exporting 2018-05-29 18:47:17 +01:00
emersion 9e26808c28
output, backend/drm: add wlr_output_export_dmabuf 2018-05-29 18:45:45 +01:00
emersion 79683ee497
backend/drm: better connector cleanup, add more logs 2018-05-27 13:21:41 +01:00
Markus Ongyerth 6a46fcc6f2 recalculate cursor projection matrix on set_cursor
Updates the projection matrix for the cursor plane in the DRM backend,
when the cursor is set, so new cursor are uploaded with the correct
transformation.
2018-05-16 15:44:41 +02:00
emersion 13098a18ea
Fix hardware cursors scale & transform 2018-05-09 19:58:18 +01:00
emersion caf9f9022c
Merge pull request #936 from emersion/full-hardware-cursors
output: always use hardware cursors if available
2018-05-04 19:00:45 +01:00
Guido Günther 1637053ef8 drm: only disable atomic modesetting when WLR_DRM_NO_ATOMIC == 1
Don't allow any value of the env var to disable atomic mode setting.
2018-05-03 15:37:37 +02:00
emersion 225d182765
output: always use hardware cursors if available
This changes the `wlr_output_impl.set_cursor` function to take a
`wlr_texture` instead of a byte buffer. This simplifies the
DRM and Wayland backends since they were creating textures from
the byte buffer anyway.

With this commit, performance should be improved when moving the
cursor since outputs don't need to be re-rendered anymore.
2018-05-01 21:38:04 +01:00
emersion 71ca45e2c0
Make sure we don't use others' prefixes 2018-04-25 23:24:58 +01:00
emersion b0d99f5c67
Remove wlr_ prefix from local symbols 2018-04-25 23:00:46 +01:00
emersion 94fa6c88f4
output: don't emit the mode event if it hasn't changed
This also fixes #535.
2018-04-18 00:15:25 +01:00
emersion a2391a6047
Fix cursor transform on DRM backend 2018-03-31 20:55:31 -04:00
emersion c63d94483b
Redesign wlr_texture
- Textures are now immutable (apart from those created from raw
  pixels), no more invalid textures
- Move all wl_drm stuff in wlr_renderer
- Most of wlr_texture fields are now private
- Remove some duplicated DMA-BUF code in the DRM backend
- Add more assertions
- Stride is now always given as bytes rather than pixels
- Drop wl_shm functions

Fun fact: this patch has been written 10,000 meters up in the air.
2018-03-24 23:48:32 -04:00
emersion 60bfe0a6aa
backend/drm: remove remaining raw GL call
This makes the hardware cursor code a less efficient. Can be
fixed with a GLES3 renderer.
2018-03-21 11:34:08 +01:00
emersion 3581573bdc
render/gles2: make wlr_renderer_begin take viewport size
This allows raw GL calls outside wlr_renderer to be removed.
2018-03-21 07:37:09 +01:00
emersion c41de2d1be
render: split render.h into wlr_renderer.h and wlr_texture.h 2018-03-19 23:16:29 +01:00
emersion 7894fca224
matrix: rename wlr_matrix_texture to wlr_matrix_projection 2018-03-15 21:26:45 +01:00
emersion 876f07e9f1
renderer: replace wlr_texture_get_matrix by wlr_render_texture 2018-03-15 19:31:02 +01:00
emersion 824a95ad19
matrix: use 2D matrices 2018-03-15 15:33:58 +01:00
emersion d26b67cb06
matrix: unify API, don't use array pointers 2018-03-15 11:10:56 +01:00
emersion b6a3f240c7
matrix: move to types/ 2018-03-15 09:11:27 +01:00
emersion d24f868bbe
backend/drm: fix cursor hotspot not updated 2018-03-12 19:34:43 +01:00
emersion 92ca4ad474
backend/drm: refactor wlr_drm_connector_set_cursor 2018-03-11 11:40:03 +01:00
Markus Ongyerth 2cea430488 prevent current_mode null on output_enable(false)
The current mode was set to NULL to abuse it as state variable
persisting DRM suspend/resume, this results resulted in a segfault on
normal DPMS cycle.

This reverts that change and uses the wlr_output enabled variable, which
also persists and makes more sense.
2018-03-01 15:48:25 +01:00
Markus Ongyerth a65ef8ea86 restore dpms state on drm resume
If there is no current mode, set outputs to dpms off in drm resume.
Sets current mode to null on disable to ensure this can be checked.
2018-02-26 18:12:51 +01:00
Guido Günther d08792bfff Add alpha to wlr_render_with_matrix
so we can use the alpha channel to e.g. blend in textures
2018-02-25 13:47:48 +01:00
Drew DeVault 1d9be89e2d
Revert "ELF Visibility" 2018-02-19 18:01:27 -05:00
Scott Anderson 86269052eb Explicitly export EFL symbols 2018-02-19 14:26:40 +13:00
emersion c2e1474010
Reformat all #include directives 2018-02-12 21:29:23 +01:00
emersion 36ead80cd1
Make wlr_signal_emit_safe private 2018-02-12 19:52:47 +01:00
emersion 10ecf871f2
Remove wlr_backend.events.{output_remove,device_remove} 2018-02-12 10:36:43 +01:00
emersion 5e58d46cc1
Add wlr_signal_emit_safe 2018-02-12 09:12:31 +01:00