Commit Graph

109 Commits

Author SHA1 Message Date
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 f72686c0b6 backend/drm: fix crash in session_signal
conn->crtc is NULL in case the output is disabled.

However, the DRM backend will set the GAMMA_LUT property anyway. On each
commit the whole state is sent to KMS. Adding WLR_DRM_CRTC_GAMMA_LUT to
the pending state would just make the backend re-create the blob
containing the gamma LUT.
2020-05-10 12:07:05 +02:00
Simon Ser da63d11d34 backend/drm: remove crtc_set_cursor from interface 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 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
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 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 8681e4ab8a backend/drm, backend/libinput: listen to session destroy
This fixes a heap-use-after-free when the session is destroyed before
the backend during wl_display_destroy:

    ==1085==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000000180 at pc 0x7f88e3590c2d bp 0x7ffdc4e33f90 sp 0x7ffdc4e33f80
    READ of size 8 at 0x614000000180 thread T0
        #0 0x7f88e3590c2c in find_device ../subprojects/wlroots/backend/session/session.c:192
        #1 0x7f88e3590e85 in wlr_session_close_file ../subprojects/wlroots/backend/session/session.c:204
        #2 0x7f88e357b80c in libinput_close_restricted ../subprojects/wlroots/backend/libinput/backend.c:24
        #3 0x7f88e21af274  (/lib64/libinput.so.10+0x28274)
        #4 0x7f88e21aff1d  (/lib64/libinput.so.10+0x28f1d)
        #5 0x7f88e219ddac  (/lib64/libinput.so.10+0x16dac)
        #6 0x7f88e21b415d in libinput_unref (/lib64/libinput.so.10+0x2d15d)
        #7 0x7f88e357c9d6 in backend_destroy ../subprojects/wlroots/backend/libinput/backend.c:130
        #8 0x7f88e3545a09 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:50
        #9 0x7f88e358981a in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:54
        #10 0x7f88e358a059 in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:107
        #11 0x7f88e314acde  (/lib64/libwayland-server.so.0+0x8cde)
        #12 0x7f88e314b466 in wl_display_destroy (/lib64/libwayland-server.so.0+0x9466)
        #13 0x559fefb52385 in main ../main.c:67
        #14 0x7f88e2639152 in __libc_start_main (/lib64/libc.so.6+0x27152)
        #15 0x559fefb4297d in _start (/home/simon/src/glider/build/glider+0x2297d)

    0x614000000180 is located 320 bytes inside of 416-byte region [0x614000000040,0x6140000001e0)
    freed by thread T0 here:
        #0 0x7f88e3d0a6b0 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:122
        #1 0x7f88e35b51fb in logind_session_destroy ../subprojects/wlroots/backend/session/logind.c:270
        #2 0x7f88e35905a4 in wlr_session_destroy ../subprojects/wlroots/backend/session/session.c:156
        #3 0x7f88e358f440 in handle_display_destroy ../subprojects/wlroots/backend/session/session.c:65
        #4 0x7f88e314acde  (/lib64/libwayland-server.so.0+0x8cde)

    previously allocated by thread T0 here:
        #0 0x7f88e3d0acd8 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:153
        #1 0x7f88e35b911c in logind_session_create ../subprojects/wlroots/backend/session/logind.c:746
        #2 0x7f88e358f6b4 in wlr_session_create ../subprojects/wlroots/backend/session/session.c:91
        #3 0x559fefb51ea6 in main ../main.c:20
        #4 0x7f88e2639152 in __libc_start_main (/lib64/libc.so.6+0x27152)
2019-12-01 10:26:12 -05: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
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
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 b0635bf3e7 Rename get_present_clock to get_presentation clock, use it 2018-10-04 22:00:22 +02:00
emersion 54e1287f30 backend: add get_present_clock 2018-10-04 21:58:17 +02:00
Drew DeVault 841d04db99
Merge pull request #1262 from nyorain/session_fix
Improve session handling
2018-10-04 17:36:39 +02:00
emersion e88db9a3fb backend/drm: reset gamma table on VT switch 2018-10-03 10:53:35 +02:00
nyorain 7b52388424 Rework session handling
Sessions can now be retrieved from a backend in a more general manner.
Multi-backend gets back its `session` field that contains the session
if one was created, removing the interfacing from multi backend with the
drm backend directly. This adds the possibility to use sessions even
without the drm backend.

It additionally fixes the bug that 2 session objects got created when
WLR_BACKENDS were set to "libinput,drm".

To allow vt switching without drm backend (and drm fd) on logind, start
listening to PropertiesChanged signals from dbus and parse the session
"Active" property when no master fd was created (this does not change
current drm backend behaviour in any way).
2018-09-24 23:35:09 +02:00
emersion 139a905924 backend/drm: add assertions 2018-09-18 11:06:01 +02:00
Mariusz Bialonczyk 15dacebc36 multi-backend: do not expose internal renderers
backend_get_renderer() is now returning the renderer of the primary GPU, instead
of its own renderer, since that's the thing which actually does all of the "real"
rendering

wlr_multi_backend_add() is now adding all subbackends (otherwise only one GPU
is handled).

credits: @ascent12
2018-08-03 07:43:22 +02:00
emersion 7cbef15206
util: add wlr_ prefix to log symbols 2018-07-09 22:49:54 +01:00
emersion 6eb4b5b54d
Merge pull request #993 from emersion/bind-wl-drm-in-renderer
render: bind wl_drm in renderer
2018-05-25 13:54:16 +01:00
Ilia Bozhinov 24cf70ae96 backends: implement custom EGL and renderer initialization
Compositors now have more control over how the backend creates its
renderer. Currently all backends create an EGL/GLES2 renderer, so
the necessary attributes for creating the context are passed to a
user-provided callback function. It is responsible for initializing
provided wlr_egl and to return a renderer. On fail, return 0.

Fixes #987
2018-05-25 14:56:52 +03:00
emersion 41130fe54b
render: bind wl_drm in renderer 2018-05-21 19:07:08 +01:00
emersion 625a7a48dc
Don't use the wlr_ prefix for static functions 2018-04-25 23:51:00 +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 d2ebbd103c
backend: remove wlr_backend_get_egl 2018-04-08 11:00:56 -04:00
emersion b1f93bc5cc
render/egl: use EGL_KHR_debug 2018-03-21 10:42:43 +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
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 5e58d46cc1
Add wlr_signal_emit_safe 2018-02-12 09:12:31 +01:00
emersion 3d3ea32137
Merge remote-tracking branch 'upstream/master' into output-damage 2018-02-03 00:15:44 +01:00
emersion bb4aeb3b2f
backend/drm: support updating cursor when session is paused 2018-02-02 21:01:59 +01:00
emersion babdd6ccf7
backend: fix use-after-free when destroying backends
The backend destroy signal is emitted before the output_remove
signal is. When the destroy signal is emitted listeners remove
their output_remove listener, so the output_remove signal is never
received and listeners have an invalid output pointer.

The correct way to solve this would be to remove the output_remove
signal completely and use the wlr_output.events.destroy signal
instead. This isn't yet possible because wl_signal_emit is unsafe
and listeners cannot be removed in listeners.
2018-01-30 19:45:57 +01:00
Guido Günther c5aac77692 Fix some typos
Prefer initialize over initialise since used more often in the sources.
2018-01-30 16:10:07 +01:00
Tony Crisci ed5b1fdedd
Merge pull request #580 from emersion/screenshooter-renderer-backport
Backport screenshooter fixes from the renderer redesign v1
2018-01-29 17:13:23 -05:00
Vincent Vanlaer 72507f9820 Clean up session signal handler on drm init fail 2018-01-24 18:27:53 +01:00
emersion 4fa90b0511
Backport screenshooter fixes from the renderer redesign v1
This backports some changes to #319 to fix the screenshooter data
format. This also adds wlr_backend_get_renderer which will be
useful to support multiple renderers.
2018-01-23 22:06:54 +01:00
Tony Crisci a937016e38 remove session from multibackend 2017-12-19 18:25:46 -05:00
emersion 9d43adaafa
Listen to display destroy in backends 2017-12-07 23:44:59 +01:00
Dominique Martinet f451ea3639 rootston exit: fix drm destroy
wlr_drm_connector were being freed without removing them
from the drm->outputs list, segfaulting on destroy
2017-11-01 19:37:35 +01:00
emersion 9d587d759f
Do not set hw cursor if disabled when switching VT 2017-10-26 18:58:44 +02:00
Versus Void 3ed3271b98 Rescan connectors on DRM resume 2017-10-22 21:44:24 +00:00
Drew DeVault 16f35ecbea Merge branch 'master' into heghe/wl_list 2017-10-21 22:03:48 -04:00
Drew DeVault 169b68b17c Rename remaining refs to wlr_list 2017-10-21 22:02:36 -04:00
Scott Anderson 9b984253e2 Move egl.h to render/egl.h 2017-10-22 10:36:07 +13:00