Commit graph

153 commits

Author SHA1 Message Date
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
Heghedus Razvan
e1f196a3e9 Replace list_t with wl_list for wlr_input_device
Signed-off-by: Heghedus Razvan <heghedus.razvan@gmail.com>
2017-10-20 11:50:43 +03:00
Heghedus Razvan
c03e774636 Replace list_t with wl_list in wlr_drm_backend
Signed-off-by: Heghedus Razvan <heghedus.razvan@gmail.com>
2017-10-20 11:46:03 +03:00
Versus Void
c5df6ca900 Fix memory leaks 2017-10-05 20:01:56 +00:00
Scott Anderson
f6f9c40965 Minor fixes 2017-10-01 22:44:24 +13:00
Scott Anderson
009c3747a8 Multi-GPU DRM 2017-10-01 22:29:25 +13:00
Scott Anderson
fa3d0ed929 Change wlr_session to open every GPU 2017-10-01 16:47:05 +13:00
Scott Anderson
4101b89700 Rename wlr_drm_output to wlr_drm_connector 2017-09-30 23:31:08 +13:00
Scott Anderson
22e77d9195 Rename backend to drm 2017-09-30 22:22:26 +13:00
Scott Anderson
096249a2a1 Split DRM rendering to its own file 2017-09-30 20:52:58 +13:00
Scott Anderson
610b0493ac Rename files to remove pointless drm prefix 2017-09-30 19:03:34 +13:00
Scott Anderson
c8a8ff66f2 Removed unused fields 2017-09-30 18:53:05 +13:00
Scott Anderson
459d138fa2 Add timeout to DRM cleanup
This prevents a potential infinite loop preventing us from closing
properly.
2017-09-23 16:32:25 +12:00
Scott Anderson
fb93628bda Merge wlr_udev into wlr_session 2017-08-26 14:02:04 +12:00
Calvin Lee
de66bdb867 Add backend detection functions
Resolves #80
2017-08-13 23:08:33 +02:00
Drew DeVault
41e735242d Remove wlr_output_state, update backends 2017-08-13 11:38:03 -04:00
Drew DeVault
4386816889 wlr_backend_init -> wlr_backend_start
Also renames create to init. We'll use create for anything that
allocates and init for anything that takes a pointer and initializes it.
2017-08-13 10:19:57 -04:00
Drew DeVault
234b2104e4 Refactor wlr_backend_state out of DRM backend 2017-08-12 19:52:22 -04:00
Dominique Martinet
0354aaeff2 Complete a few destroy functions
This adds missing free calls for:
 - drm outputs
 - libinput backend in general
 - final udev free
 - output mode state
2017-08-11 19:17:03 +02:00
Drew DeVault
c24351681f Refactor EGL handling 2017-08-10 22:15:37 -04:00
nyorain
67369173aa Implement drm (egl) buffer attaching 2017-08-10 10:59:58 +02:00
Scott Anderson
a77fac0760 Added null check on crtc 2017-08-10 01:43:42 +12:00
Scott Anderson
af67966d92 Atomic modesetting 2017-08-09 08:07:00 -04:00
Scott Anderson
5f7042a1f2 Moved headers 2017-08-06 21:49:04 +12:00
Scott Anderson
1db97a9af9 Updated DRM cursor rendering 2017-08-06 21:38:40 +12:00
Scott Anderson
2f8b5c4448 More cleanups 2017-08-06 15:53:41 +12:00
Scott Anderson
dd7a349295 Various cleanups 2017-08-06 15:51:49 +12:00
Scott Anderson
31867a1b2e Various changes/cleanups 2017-08-06 15:49:05 +12:00
Scott Anderson
7b772e1a4b DRM resource initalisation 2017-08-06 15:49:02 +12:00
Scott Anderson
cb4d50e22c Changed header paths. 2017-08-06 13:25:26 +12:00
Drew DeVault
168f0955ab Add wl_output globals for wlr_outputs 2017-06-22 14:27:35 -04:00
Drew DeVault
f4453d104d Reorganize wlr-common 2017-06-21 12:10:07 -04:00
Drew DeVault
fd91244e83 Update everyone to use new headers 2017-06-21 10:27:45 -04:00
Scott Anderson
55854565dc Fixed VT switching 2017-06-21 13:31:29 +12:00
Scott Anderson
091de12bf4 Changed session signal to only emit on DRM changes 2017-06-21 12:47:53 +12:00
Drew DeVault
2b06f88f0b Combine internal DRM headers into one
Everything always just included both anyway
2017-06-10 12:30:02 -04:00
Drew DeVault
7d82476590 Refactor type implementations 2017-06-04 19:30:50 -04:00
Scott Anderson
5df56653ab Changed invalidate interface. 2017-06-04 17:43:34 +12:00
Scott Anderson
de44994dfc Udev event device matching 2017-06-03 15:47:33 +12:00
Drew DeVault
40b85d992a Refactor udev and drm initialization 2017-06-01 20:29:10 -04:00
ascent12
62d612a01e Merge branch 'master' into session 2017-06-01 23:10:19 +12:00
Drew DeVault
e2ee67125e s/wayland.h/types.h/g 2017-05-31 16:24:32 -04:00
Drew DeVault
c7f6981d9c Clean up outputs on exit 2017-05-31 16:17:04 -04:00
Drew DeVault
fee409bd0a Generalize DPMS, remove DRM refs from example 2017-05-31 15:38:26 -04:00
Scott Anderson
f9d363fece Added device matching 2017-05-14 13:07:34 +12:00
Scott Anderson
7efdd3c9fc Refactored renderer startup to function. 2017-05-14 12:48:47 +12:00
Scott Anderson
ce8786721b Got it working. 2017-05-14 12:42:49 +12:00
Scott Anderson
058b8bdf27 Working commit 2017-05-14 12:42:49 +12:00
Scott Anderson
599d1bcbdc DPMS support 2017-05-13 20:37:15 +12:00
Drew DeVault
00931f2f8f Generalize output handling 2017-05-07 12:26:48 -04:00
Drew DeVault
15b1ce9e6c Refactor backend state management 2017-05-07 10:12:54 -04:00
Scott Anderson
ef9768858e Changed modesetting interface. 2017-05-03 22:41:49 +12:00
Scott Anderson
d196a79b6c Changed backend to accept wl_display. 2017-05-03 21:28:44 +12:00
Scott Anderson
18387468bb Renamed 'wlr_drm_display' to 'wlr_drm_output' 2017-05-03 17:49:03 +12:00
Scott Anderson
81998fdc98 Removed old session code from DRM backend. 2017-05-03 16:23:07 +12:00
Scott Anderson
e446a5300b Added example. 2017-05-02 18:13:17 +12:00
Scott Anderson
e9d716fc0c Changed display to use list_t. 2017-05-02 14:34:33 +12:00