Compare commits

...

473 Commits

Author SHA1 Message Date
blank X c5e3ca6249 wlroots 0.15.1
Alexander Orzechowski (1):
       xdg-foreign: Fix crash on destroy of degenerate surface
 
 Isaac Freund (3):
       wlr_texture: remove wlr_texture_from_wl_drm() from header
       foreign-toplevel: send enter if needed on output bind
       tinywl: fix check whether client is focused or not
 
 Kirill Primak (3):
       scene/subsurface_tree: fix handling subsurface destruction
       compositor: damage the whole buffer on viewport src change
       subsurface: unlock cached state on commit if desynced
 
 Simon Ser (4):
       backend: error out in autocreate without libinput support
       scene: schedule an output frame on wl_surface.frame
       scene: try to import buffers as textures before rendering
       build: bump version to 0.15.1
 
 Tadeo Kondrak (1):
       input_method_v2: improve mapping detection
 
 Thomas Hebb (1):
       render/gles2: don't constrain shm formats to ones that support reading
 
 nyorain (1):
       vulkan: Fix imported image layout
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEENP+VJs/vDpejQOLkD9574OiPXkgFAmH8RzEACgkQD9574OiP
 XkjPGw/+KdgxXeVJ1Typ8fp9ZfhGTW3sJVREpMpnLra/1lA4LQ1jUDFfvXEPAveI
 UjgGiyoBpBWcWgj0jS0GgcTE2ExnGlkd9Y6pImM0zUTQ1mQF8hPxyThQiJNDpBix
 42lqWtIqYPQObJnXa19SpebNCw/TbHoF/0sHR8I/a0o2PgVT9LGIsqI1nAYH7H/e
 lUR5paZU5G60lQdePhTIOv7MuXNt7fgtpizw/WNMqz0Cl+1weoIAtXv2UWZM39wW
 hhK2e02n8GncLYQn459xqf5UfkCnie9u6BCL4PMuEm+sOsYH5sQzsUFfQjBsNCqL
 ztgFssPwW6v/vImvWclvD0DAOgPK0kMEg0RWlBOKfTTxBewloKp4MIY/udKX9+5S
 b8ALOizzS0vL/lTFc+o4XBELE/X9f0S0Sv+mtWXD4xuOMREPUaijJ5LyOmDf6gG5
 K/CB5T2pdQqNC9UdTGMPlauSFVqliBO7hyQSHl3tr5/ZjQZ3tGFL+szp7b62Rb5r
 ChQCUC6NvDhcKzZaPwL9py005yk0LT5oEXVxRJId6ipWuGn+XBnBoWWckpy/3Zpu
 cnacvsxyKaQS3Uts13UlVW4ojr3wolDzBqDPQGU8xsqQcbgcbjGLxkPFDIWT++3D
 XzBx6bRBTKr1EJRoEROuSl0xDEaWJlZt1XUGPLP1Uxew4DSrXOg=
 =mFoc
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE+M9eMyy2C5F27kiEzBX8gix/YfUFAmIphlUACgkQzBX8gix/
 YfVWfA/8C+GEw9/P2s+eKBdK6jIB9H0as/yjLCDQDmAX2iAIGdnJ+4ojd2C6xDMK
 mUDRU1UOufafXMdaFa7DXeWYGkHII62K3qxdVD737bCRApkBGLVC9h11QuWgcYYC
 BxeduZouZ1npRtTxINBCC5TXKDWkt0cvQDrD7pnL+AH+ny5WvOnRO1CaPXCgnc7v
 hqdrVAtHRdAkYBBHuu9WgMpvVzkS3KXr7NaWLpRdGa7nWpkKX9aoa0tNjCL86TPq
 QHDMhQnPxghxJl6xc9rhDWJYcYCUxJ4W4ABbyqkkP64wBtjnDJVh7LWRx4qnFNIO
 ky0E3JM6A5YZ/N0fdOIsxvJ2YOpqYYXhKS8NJa2a+Wnsw+QEHe8hnST4UWGcQERf
 qX0hghKhuYNxpm4vrB3rOPwbcQIdjGo2jlEH4GG3gENduekvvdGAr5qcXDH+5pol
 7iwrbARI3T6kTplx/iDvHk5wYGKwj5oatXy4AKwbBt+DNDakF6Vf9RGLKOtC2cty
 YS607osq9kUUX47RCSP11W3zb84cAtJNw5eHmQzVPJ+hAlGsaMdDVUbUGgJiruVe
 pyYeSKxKyFTao3SYSizZwJB0mwYXWsDsVdf4c6mbdr3w5MBWslrliCof9vzSQSq3
 KAiGawPiT+ar87kyQMaCaMl0ZLaXG7g/MXKNsRp/Ss437nhknqg=
 =6/3L
 -----END PGP SIGNATURE-----

Merge tag '0.15.1' into dkondor-upstream-pr-2551

wlroots 0.15.1

Alexander Orzechowski (1):
      xdg-foreign: Fix crash on destroy of degenerate surface

Isaac Freund (3):
      wlr_texture: remove wlr_texture_from_wl_drm() from header
      foreign-toplevel: send enter if needed on output bind
      tinywl: fix check whether client is focused or not

Kirill Primak (3):
      scene/subsurface_tree: fix handling subsurface destruction
      compositor: damage the whole buffer on viewport src change
      subsurface: unlock cached state on commit if desynced

Simon Ser (4):
      backend: error out in autocreate without libinput support
      scene: schedule an output frame on wl_surface.frame
      scene: try to import buffers as textures before rendering
      build: bump version to 0.15.1

Tadeo Kondrak (1):
      input_method_v2: improve mapping detection

Thomas Hebb (1):
      render/gles2: don't constrain shm formats to ones that support reading

nyorain (1):
      vulkan: Fix imported image layout
2022-03-10 12:02:12 +07:00
Simon Ser 29938b7425 build: bump version to 0.15.1 2022-02-03 22:19:54 +01:00
Isaac Freund eb1a451803 tinywl: fix check whether client is focused or not
Currently this check is too strict and denies the move/resize request
if a subsurface of the client has pointer focus.

(cherry picked from commit 89dc9a44968fbd3fe8a08a41858d1537ee145668)
2022-02-03 22:15:51 +01:00
Isaac Freund a819c512ec foreign-toplevel: send enter if needed on output bind
Currently the output enter event is never sent if the client has not
yet bound the output, which happens every time the compositor creates a
new output.

To fix this, listen for the output bind event and inform clients as
if needed.

(cherry picked from commit 1bd0ea3a809bdba092ef051120bb6d32f79c0ffb)
2022-02-03 22:15:39 +01:00
Alexander Orzechowski c4824b680a xdg-foreign: Fix crash on destroy of degenerate surface
I am running a custom compiled version of chromium with a patch to get
it up and running on sway git at the moment, and in that development
build I compiled there is a bug where the browser will crash if you
try to open a file select dialog. When this crash happens, chromium will
not close, but instead will remain open and impossible to close unless
you send a SIGKILL signal to the process. However, sway will crash to
tty when you send the SIGKILL.

I have a hunch that when chromium is opening the file select dialog
it is creating some sort of a xdg toplevel surface. But it freezes
before it fully initializes the surface. When the SIGKILL signal is
given, sway/wlroots will try to free the xdg_toplevel surface but
because it hasn't fully initialized due to the frozen window, it
segfaults.

Don't be fooled by the assert, the assert is not firing, the surface
pointer is indeed NULL here.

* thread #1, name = 'sway', stop reason = signal SIGSEGV: invalid address (fault address: 0x28)
    frame #0: 0x00007ffff78b9041 libwlroots.so.11`wlr_xdg_toplevel_set_parent(surface=0x0000000000000000, parent=0x0000000000000000) at wlr_xdg_toplevel.c:159:37
   156
   157 	void wlr_xdg_toplevel_set_parent(struct wlr_xdg_surface *surface,
   158 			struct wlr_xdg_surface *parent) {
-> 159 		assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
   160 		assert(!parent || parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
   161
   162 		if (surface->toplevel->parent) {
(lldb) up
error: sway {0x0003442a}: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x67) attribute, but range extraction failed (invalid range list offset 0x67), please file a bug and attach the file at the start of this error message
error: sway {0x0003442a}: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x67) attribute, but range extraction failed (invalid range list offset 0x67), please file a bug and attach the file at the start of this error message
frame #1: 0x00007ffff78e176e libwlroots.so.11`destroy_imported(imported=0x000055555626d570) at wlr_xdg_foreign_v1.c:154:3
   151 		wl_list_for_each_safe(child, child_tmp, &imported->children, link) {
   152 			struct wlr_xdg_surface *xdg_child =
   153 				wlr_xdg_surface_from_wlr_surface(child->surface);
-> 154 			wlr_xdg_toplevel_set_parent(xdg_child, NULL);
   155 		}
   156
   157 		wl_list_remove(&imported->exported_destroyed.link);
(lldb) up
frame #2: 0x00007ffff78e1b9d libwlroots.so.11`xdg_imported_handle_resource_destroy(resource=0x00005555562555a0) at wlr_xdg_foreign_v1.c:280:2
   277 			struct wl_resource *resource) {
   278 		struct wlr_xdg_imported_v1 *imported = xdg_imported_from_resource(resource);
   279 		if (!imported) {
-> 280 			return;
   281 		}
   282
   283 		destroy_imported(imported);
(lldb) up
frame #3: 0x00007ffff794989a libwayland-server.so.0`___lldb_unnamed_symbol211 + 154
libwayland-server.so.0`___lldb_unnamed_symbol211:
->  0x7ffff794989a <+154>: andl   $0x1, %r13d
    0x7ffff794989e <+158>: je     0x7ffff79498b0            ; <+176>
    0x7ffff79498a0 <+160>: addq   $0x8, %rsp
    0x7ffff79498a4 <+164>: movl   $0x1, %eax
(lldb) up
frame #4: 0x00007ffff794fec0 libwayland-server.so.0`___lldb_unnamed_symbol290 + 64
libwayland-server.so.0`___lldb_unnamed_symbol290:
->  0x7ffff794fec0 <+64>: cmpl   $0x1, %eax
    0x7ffff794fec3 <+67>: jne    0x7ffff794fed3            ; <+83>
    0x7ffff794fec5 <+69>: addq   $0x8, %rbx
    0x7ffff794fec9 <+73>: cmpq   %rbx, %r13
(lldb) up
frame #5: 0x00007ffff79503e0 libwayland-server.so.0`___lldb_unnamed_symbol300 + 32
libwayland-server.so.0`___lldb_unnamed_symbol300:
->  0x7ffff79503e0 <+32>: cmpl   $0x1, %eax
    0x7ffff79503e3 <+35>: je     0x7ffff79503f0            ; <+48>
    0x7ffff79503e5 <+37>: popq   %rbx
    0x7ffff79503e6 <+38>: popq   %r12
(lldb) up
frame #6: 0x00007ffff794a30e libwayland-server.so.0`wl_client_destroy + 126
libwayland-server.so.0`wl_client_destroy:
->  0x7ffff794a30e <+126>: movq   %r12, %rdi
    0x7ffff794a311 <+129>: callq  0x7ffff7950150            ; ___lldb_unnamed_symbol293
    0x7ffff794a317 <+135>: movq   0x8(%rbp), %rdi
    0x7ffff794a31b <+139>: callq  *0xdc77(%rip)
(lldb) up
frame #7: 0x00007ffff794a3f7 libwayland-server.so.0`___lldb_unnamed_symbol214 + 119
libwayland-server.so.0`___lldb_unnamed_symbol214:
->  0x7ffff794a3f7 <+119>: movq   0x28(%rsp), %rax
    0x7ffff794a3fc <+124>: subq   %fs:0x28, %rax
    0x7ffff794a405 <+133>: jne    0x7ffff794a727            ; <+935>
    0x7ffff794a40b <+139>: addq   $0x38, %rsp
(lldb) up
frame #8: 0x00007ffff794d1ca libwayland-server.so.0`wl_event_loop_dispatch + 202
libwayland-server.so.0`wl_event_loop_dispatch:
->  0x7ffff794d1ca <+202>: addq   $0xc, %r15
    0x7ffff794d1ce <+206>: cmpq   %r15, %rbp
    0x7ffff794d1d1 <+209>: jne    0x7ffff794d1b8            ; <+184>
    0x7ffff794d1d3 <+211>: movq   0x8(%rsp), %rcx
(lldb) up
frame #9: 0x00007ffff794ad37 libwayland-server.so.0`wl_display_run + 39
libwayland-server.so.0`wl_display_run:
->  0x7ffff794ad37 <+39>: movl   0x8(%rbx), %eax
    0x7ffff794ad3a <+42>: testl  %eax, %eax
    0x7ffff794ad3c <+44>: jne    0x7ffff794ad20            ; <+16>
    0x7ffff794ad3e <+46>: popq   %rbx
(lldb) up
frame #10: 0x000055555557689a sway`server_run(server=0x00005555555f26c0) at server.c:307:2
   304 			wlr_backend_destroy(server->backend);
   305 			return false;
   306 		}
-> 307
   308 		return true;
   309 	}
   310
(lldb) up
frame #11: 0x0000555555575a93 sway`main(argc=3, argv=0x00007fffffffe978) at main.c:431:2
   428 			swaynag_show(&config->swaynag_config_errors);
   429 		}
   430
-> 431 		server_run(&server);
   432
   433 	shutdown:
   434 		sway_log(SWAY_INFO, "Shutting down sway");

(cherry picked from commit cddc1c1bd9f796709c50f4bbb300788edd42fd4f)
2022-02-02 20:29:44 +01:00
Simon Ser ec3780e6ea scene: try to import buffers as textures before rendering
The wlroots APIs currently don't allow importing/uploading a buffer
during rendering operations. Scene-graph buffer nodes need to turn
their wlr_buffer into a wlr_texture at some point. It's not always
possible to do so at wlr_scene_buffer creation time because the
scene-graph may have zero outputs at this point, thus no way to
grab a wlr_renderer.

Instead, add scene-graph buffers to a pending list and try to import
them in wlr_scene_output_commit.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3354
(cherry picked from commit 3db1bcbe641b407b9f5c9e5d0a012b45aa2c6cb7)
2022-02-02 20:28:27 +01:00
Kirill Primak 68c5fa340d subsurface: unlock cached state on commit if desynced
wl_subsurface::set_desync description states: "If cached state exists when
wl_surface.commit is called in desynchronized mode, the pending state is
added to the cached state, and applied as a whole."

This commit reintroduces an implementation of said behavior, previously
removed in 7daf6da9ac05be2cb74c0983e3caee0b21db75d4.

Strictly speaking, this logic isn't fully correct, as the cached state
and the pending state are applied individually instead, if the cached
state isn't locked by anything else. However, the end result is still
the same.

This commit fixes the issue with Firefox permission popups.

(cherry picked from commit 77951968dc9df7214c04c33f4905a9a7aa92f60c)
2022-02-02 20:27:49 +01:00
Kirill Primak 304c61307a compositor: damage the whole buffer on viewport src change
wp_viewporter protocol doesn't seem to say anything about damage, but
Firefox assumes that wp_viewport::set_source alone is enough to damage
the whole surface, and that assumption kinda makes sense, so let's do
that.

(cherry picked from commit da2491d4163e1d8e627d00c8ae594c7f8003472e)
2022-02-02 20:25:28 +01:00
Tadeo Kondrak b0fee56974 input_method_v2: improve mapping detection
Detect NULL commits before the surface is actually committed, allowing
the surface to be properly damaged on unmap.

(cherry picked from commit 5091118bed82394de5a151d658e895bb44059b61)
2022-02-02 20:25:24 +01:00
Kirill Primak 7dde2b66d6 scene/subsurface_tree: fix handling subsurface destruction
This commit renames map/unmap listeners to clarify that they handle
subsurface events, and ensures the node is always destroyed before
the subsurface.

Without this patch, wl_list_remove() would operate on listener links in
already freed memory. glibc is usually lenient to bugs like this, but
musl isn't.

(cherry picked from commit 83ab5055fd36bd0f8a0106257e45d8ed303636d8)
2022-02-02 20:08:20 +01:00
Thomas Hebb ea77cc5cb2 render/gles2: don't constrain shm formats to ones that support reading
commit 44e8451cd9 ("render/gles2: hide shm formats without GL
support") added the is_gles2_pixel_format_supported() function to
render/gles2/pixel_format.c, whose stated purpose is to "check whether
the renderer has the needed GL extensions to read a given pixel format."
It then used that function to filter the pixel formats returned by
get_gles2_shm_formats().

The result of this change is that RGB formats are no longer reported for
GL drivers that don't implement EXT_read_format_bgra, even when those
formats are supported for rendering (which they have to be for
wlr_gles2_renderer_create() to succeed). This is a pretty clear
regression, since wlr_renderer_init_wl_shm() fails when either of
WL_SHM_FORMAT_ARGB8888 or WL_SHM_FORMAT_XRGB8888 are missing.

To fix the regression, change is_gles2_pixel_format_supported() to
accept all pixel formats that support rendering, regardless of whether
we can read them or not, and move the check for EXT_read_format_bgra
back into gles2_read_pixels(). (There's already a check for this
extension in gles2_preferred_read_format(), so we're not breaking any
abstraction that wasn't already broken.)

Tested on the NVIDIA 495.46 proprietary driver, which doesn't support
EXT_read_format_bgra.

Fixes: 44e8451cd9 ("render/gles2: hide shm formats without GL support")
(cherry picked from commit 59b9518f072527ac59593e51df7f5d5331a34f0e)
2022-02-02 20:08:17 +01:00
nyorain a59a957f2b vulkan: Fix imported image layout
(cherry picked from commit 9988eb3378dbc3301059aa9b5e1ff476354cb92b)
2022-02-02 20:08:01 +01:00
Simon Ser df945b665c scene: schedule an output frame on wl_surface.frame
Some clients (e.g. mpv, Firefox) request a new wl_surface.frame
callback without damaging their surface. When this happens,
schedule a new output frame.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3350
(cherry picked from commit 812951f5bc47f502429406e49f4e24f377b7799b)
2022-02-02 20:07:39 +01:00
Isaac Freund 4b358c2f91 wlr_texture: remove wlr_texture_from_wl_drm() from header
This function was already removed in e5b5592a but it was forgotten to
remove it from the header.

(cherry picked from commit 823476e76ed166762095330a8f51eabc825febff)
2022-02-02 20:07:21 +01:00
Simon Ser 7864f26d73 backend: error out in autocreate without libinput support
The libinput backend is now optional. However, this means that a
user building wlroots without the correct libinput dependencies
will end up with a compositor which doesn't respond to input events.

wlr_backend_autocreate is supposed to return a sensible setup, so in
this case let's just error out and explain what happened. Users can
suppress the check by setting WLR_LIBINPUT_NO_DEVICES=1 (already used
to suppress the zero input device case inside the libinput backend).

Compositors which really want to create a bare DRM backend can easily
create it manually instead of using wlr_backend_autocreate.

(cherry picked from commit ec2845750862cc0b175bef59de4305f6da91960a)
2022-02-02 20:07:07 +01:00
blank X b309e8fc39
Update README.md 2021-12-18 19:47:06 +07:00
Daniel Kondor 80d10b9c98 Alternative fix for #2543
No need for an additional enum value
2021-12-18 19:46:53 +07:00
Simon Ser 9f41627aa1 backend/wayland: add basic linux-dmabuf feedback support
This patch makes it so we bind to zwp_linux_dmabuf_v1 version 4 and
we use it to grab the main device. v4 sends supported formats via a
table so we need to handle this as well.

v4 allows wlroots to remove the requirement for Mesa's internal
wl_drm interface.
2021-12-15 14:34:08 +00:00
Stacy Harper 8e566f716c layer-shell: don't set committed flag if the property didn't change
This fixes configure loop in Sway when clients re-send same properties
on every configure event.

Original issue: https://todo.sr.ht/~mil/sxmo-tickets/413
2021-12-15 16:24:33 +03:00
Isaac Freund 07ccc6e0b3
scene: add wlr_scene_set_presentation()
This helper automates sending presentation feedback to clients based on
the primary output of scene surfaces.
2021-12-14 21:34:02 +01:00
Simon Ser c0b120a30c build: add subproject fallback for libdrm 2021-12-14 14:33:00 +01:00
Simon Ser bedfec94bb backend/drm: use drmCloseBufferHandle
This has been added in [1] and allows us to close buffer handles
without manually calling drmIoctl.

[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/192
2021-12-14 14:33:00 +01:00
Simon Ser a15c327718 backend/drm: use drmModeFormatModifierBlobIterNext
This avoids open-coding our own logic. The resulting code is more
readable.

References: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/146
2021-12-14 13:21:09 +00:00
Simon Ser 4377b55292 util/global: remove wl_display arg from wlr_global_destroy_safe
Since [1], we can get the wl_display directly from the wl_global.

[1]: 2b22160fb6
2021-12-14 13:13:50 +00:00
Guido Günther 4c59f7d46a xdg-activation: Allow to submit tokens
Allows the compositor to submit tokens to the pool of
currently active tokens. This can be useful when the
launcher doesn't use or support xdg-activation-v1 by
itself - e.g. when it is X11 based or use gtk_shell1.
2021-12-14 12:01:46 +01:00
David Rosca 31914928d2
seat: Only resend keyboard/pointer enter to focused clients
Otherwise it will send enter events to clients that already
have keyboard/pointer focus.
Notably Qt applications warns about this.
2021-12-14 08:23:53 +01:00
Isaac Freund 1c3e0816f3
scene: fix wlr_scene_send_frame_done() API
This doesn't work if scene outputs are not used as the primary output of
scene surfaces will always be NULL.

Therefore, take a wlr_scene_output instead of separate wlr_scene and
wlr_output arguments and rename the function to
wlr_scene_output_send_frame_done().

The actual behavior of the function is unchanged.
2021-12-13 17:26:22 +01:00
Isaac Freund ad01cdf0b2 tinywl: use wlr_scene_send_frame_done() 2021-12-13 15:21:05 +00:00
Isaac Freund fecde72be3 scene: add wlr_scene_send_frame_done() 2021-12-13 15:21:05 +00:00
Isaac Freund fb1f613510 scene: add primary output to wlr_scene_surface
This allows compositors to avoid sending multiple frame done events
to a surface that is rendered on multiple outputs at once. This may
also be used in the same way for presentation feedback.
2021-12-13 15:21:05 +00:00
Isaac Freund 0215dffba5 scene: send surface enter/leave output events
Co-authored-by: Simon Ser <contact@emersion.fr>
2021-12-13 15:21:05 +00:00
Chris Chamberlain d8ca494558 backend/drm: add wlr_drm_backend_monitor
This helper is responsible for listening for new DRM devices and
create new child DRM backends as necessary.
2021-12-13 14:55:16 +01:00
Chris Chamberlain f6d3efbf4b backend: fix return value of attempt_drm_backend
The multi backend was returned instead of the primary DRM backend.
2021-12-13 14:53:41 +01:00
Simon Ser e3fefda023 output: add support for protocol interface version 4
Two new events are added: name and description. The name is
immutable. The description can be updated on-the-fly.
2021-12-13 12:06:16 +00:00
Kirill Primak 0fcc842291 subsurface: don't add to parent list immediately 2021-12-09 18:26:56 +00:00
Kirill Primak 7964bdae76 surface: fix non-buffer damage handling
This commit fixes the way the damage that doesn't come directly from the
client is handled.
2021-12-09 18:26:56 +00:00
Kirill Primak df7d280343 subsurface: apply position change at the right moment
Subsurface position is considered to be a part of the parent surface's
state, therefore it should be modified when the parent is committed.
2021-12-09 18:26:56 +00:00
Kirill Primak f463ca669a subsurface: simplify and fix parent commit handling 2021-12-09 18:26:56 +00:00
Simon Ser 818fc4a87b Fix incorrect %zd formatting directives
%zd is for ssize_t. For size_t we should use %zu.
2021-12-09 16:42:04 +01:00
Simon Ser 36a2b19485 output: introduce wlr_output_set_name
wlroots picks names for all outputs, but it might be desirable for
compositor to override it.

For instance, Sway will use a headless output as a fallback in
case no outputs are connected. Sway wants to clearly label the
fallback output as such and label "real" headless outputs starting
from HEADLESS-1.
2021-12-09 15:46:46 +01:00
Simon Ser 1fbd13ec79 examples: remove unnecessary partial_dependency() call
The definition of the "drm" dep already calls it.
2021-12-07 16:20:54 +01:00
Simon Ser 90e9d327dd examples: remove unnecessary wlroots deps for clients
These clients don't need wlroots.
2021-12-07 16:20:20 +01:00
Simon Ser 83bdb3ad07 examples/layer-shell: remove wlroots dependency
This is a client example, it shouldn't use a compositor library
like wlroots.
2021-12-07 16:19:26 +01:00
Simon Ser ad28490cf4 build: move wayland-client dep to backend/wayland/
wayland-client isn't really used by wlroots core, so let's move the
dep to where it's needed in the Wayland backend.
2021-12-07 16:11:29 +01:00
Simon Ser c50c4fc5cc linux-dmabuf-v1: add per-surface feedback 2021-12-07 15:18:19 +01:00
Simon Ser 1d8340754b linux-dmabuf-v1: implement v4
Implement a basic version of linux-dmabuf-unstable-v1 version 4.
Only default hints are implemented.

The new wlr_linux_dmabuf_feedback_v1 data structure will allow
compositors to define their own custom hints in the future. This
data structure makes it easy to describe feedback metadata.

It's converted to a "compiled" form suitable for marshalling over
the Wayland socket via feedback_compile.
2021-12-07 15:18:16 +01:00
Simon Ser 77d811a21b render: add wlr_renderer_init_wl_shm
This allows compositors to initialize wl_shm without initializing
other globals like linux-dmabuf.
2021-12-07 15:15:28 +01:00
Kirill Primak c9f3c2b4f7 surface: fix damage transformation 2021-12-06 15:37:36 +00:00
tiosgz ca1af8119c Fix wlr_scene_node_lower_to_bottom
Before this commit, it would keep the node at the top or make it second-
topmost.
2021-12-04 22:22:56 +00:00
Simon Ser efeb8346cf output: drop front_buffer
This lets backends immediately release committed buffers if they
want to.
2021-12-03 14:56:17 +00:00
Simon Ser 45069fb623 screencopy-v1: use wlr_output_event_commit.buffer 2021-12-03 14:56:17 +00:00
Simon Ser 60b7267e18 export-dmabuf-v1: use wlr_output_event_commit.buffer 2021-12-03 14:56:17 +00:00
Simon Ser f016eca97c output: add wlr_output_event_commit.buffer
This allows output commit listeners to access the newly committed
buffer. Currently wlr_output.front_buffer is used but it'll get
removed in the next commit.
2021-12-03 14:56:17 +00:00
Simon Ser 7201aae3d6 render/drm-format-set: add wlr_drm_format_set_intersect
This intersects two DRM format sets. This is useful for implementing
DMA-BUF feedback in compositors, see e.g. the Sway PR [1].

[1]: https://github.com/swaywm/sway/pull/6313
2021-12-03 14:42:41 +00:00
Simon Ser 92080b3a01 readme: update wrapper libraries link
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3336
2021-12-03 11:45:57 +01:00
Simon Ser 0d32118a80 output: fix modifier stripping
DRM formats with an empty modifier list are invalid. Instead of
emptying the list, reduce it to { INVALID }.

Add a check to make sure the renderer and backend support implicit
modifiers, so that we don't fallback on e.g. Vulkan.

Closes: https://github.com/swaywm/sway/issues/6692
2021-12-02 14:31:16 +00:00
Simon Ser 1bf9676e87 render/egl: improve modifier support detection
Support for EXT_image_dma_buf_import_modifiers doesn't necessarily
indicate support for modifiers. For instance, Mesa will advertise
EXT_image_dma_buf_import_modifiers for all drivers. This is a trick
to allow EGL clients to enumerate supported formats (something
EXT_image_dma_buf_import is missing). For more information, see [1].

Add a new wlr_egl.has_modifiers flag which indicates whether
modifiers are supported. It's set to true if any
eglQueryDmaBufModifiersEXT query returned a non-empty list.

Use that flag to figure out whether the buffer modifier should be
passed to the EGL implementation on import.

[1]: https://github.com/KhronosGroup/EGL-Registry/issues/142
2021-12-02 14:21:51 +00:00
Simon Ser de0bc78319 render/pixman: advertise MOD_INVALID instead of MOD_LINEAR
The backends and allocators use INVALID, but the renderer uses
LINEAR. Running a compositor with WLR_RENDERER=pixman results in:

    00:00:00.744 [types/output/render.c:59] Failed to pick primary buffer format for output 'WL-1'
2021-12-02 14:12:14 +00:00
Simon Ser 051d1ce90e render/egl: add wlr_egl_create_with_context
This allows creating a wlr_egl from an already-existing EGL display
and context. This is useful to allow compositors to choose the exact
EGL initialization parameters.
2021-12-01 14:08:20 +01:00
Simon Ser ffd4a27714 render/egl: store IMG_context_priority in wlr_egl
The next commit will split extension lookup and context
initialization.
2021-12-01 14:03:37 +01:00
Quantum 812ab2e716 Fix uninitialized variable errors in release mode
When using `meson --buildtype=release`, `-Wextra -Werror` is passed.
This includes `-Werror=maybe-uninitialized`, which complains about
the instances fixed in this commit.
2021-12-01 02:39:14 -05:00
Moon Sungjoon 611b9ca843 backend/wayland: improve wayland input device name
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3332
This makes input device names include it's type name
2021-11-30 22:06:14 +00:00
Isaac Freund a44b2af672
tinywl: use wlr_scene 2021-11-30 22:06:42 +01:00
Simon Ser ba974a4e9f scene: add wlr_scene_get_scene_output
This allows getting a wlr_scene_output from a wlr_output. Since an
output can only be added once to a scene-graph there's no ambiguity.

This is useful for compositors using wlr_scene_attach_output_layout:
the output layout integration automatically creates a scene-graph
output for each wlr_output added to the layout.
2021-11-30 20:16:24 +00:00
Simon Zeni dd84c5a1cc types/wlr_drm_lease_v1: add NULL check to drm lease resource destroy 2021-11-30 19:59:55 +00:00
Simon Ser 697a1cd0f5 output: add wlr_output_get_primary_formats
This allows compositors to get primary formats without manually
calling wlr_output_impl.get_primary_formats.

For example, the Sway patch for linux-dmabuf feedback [1] needs
this.

[1]: https://github.com/swaywm/sway/pull/6313
2021-11-30 20:49:33 +01:00
Simon Ser e93435016e output: fix typo in wlr_output_impl.get_primary_formats docs
The buffer capabilities indicate whether the formats returned are
for DMA-BUFs or shared memory buffers.
2021-11-30 20:49:33 +01:00
Simon Ser 2540de494e output: don't leave dangling cursor_front_buffer
Sometimes we were calling wlr_output_impl.set_cursor with a NULL
buffer, but we weren't clearing wlr_output.cursor_front_buffer.
Avoid leaving a dangling buffer behind.

Introduce a helper function output_set_hardware_cursor which calls
wlr_output_impl.set_cursor and keeps cursor_front_buffer in sync.
2021-11-30 18:32:48 +00:00
Simon Ser 456b971099 output: destroy swapchain when disabled
This avoids consuming GPU memory when an output is disabled.
2021-11-30 18:32:48 +00:00
Rouven Czerwinski 6bfb930aa7 linux-dmabuf-v1: fix implicit check
The implicit check to filter out LINEAR for dmabuf checked for INVALID
twice instead of checking for INVALID & LINEAR. Fix this.

Fixes: d37eb5c2ea ("linux-dmabuf-v1: filter out LINEAR if implicit")
Reported-by: Dawid Czeluśniak <czelusniakdawid@gmail.com>
2021-11-29 17:44:34 +01:00
Simon Ser fbaefd90fc backend/drm: poison buffers which cannot be scanned out
Rather than repeatedly trying to import DMA-BUFs which cannot be
scanned out, mark the failed ones with a special "poison" marker.
Inspired from [1].

[1]: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/731
2021-11-29 14:32:29 +00:00
John Lindgren bff5b2c559 Insert new outputs at the end of the list
This prevents auto-configuring a new output from changing the
position of existing outputs.

(v2: simplify insert-at-end logic)
2021-11-29 13:14:31 +00:00
Jonathan Wong 0fb479ca61 Added whitespace between "output" and "(not" 2021-11-28 16:56:09 +00:00
Rouven Czerwinski d37eb5c2ea linux-dmabuf-v1: filter out LINEAR if implicit
If only INVALID and LINEAR are valid modifiers, we need to filter out
LINEAR since Xwayland won't be able to allocate a BO with the explicit
linear modifier on hardware that does not support explicit modifiers.
The addition of LINEAR is an internal implementation detail which
simplifies the wlroots architecture for now.

Evntually Xwayland should be fixed to filter out modifiers that are not
supported by the GBM implementation, see [1]. This could be done by
querying EGL for the supported modifiers.

[1]: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1166
2021-11-27 19:32:25 +01:00
Simon Ser 254ab890e7 scene: add support for viewporter
If the surface has a source box set, use that.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3172
2021-11-26 19:31:19 +00:00
Simon Ser 83d78f9fd4 render: add DMA-BUF docs
Document some of the assumptions for DMA-BUF buffer sharing and
modifiers.
2021-11-26 16:40:53 +00:00
Simon Ser ef1669d33e backend/drm: always add LINEAR to supported modifiers 2021-11-26 16:40:53 +00:00
Simon Ser 98f2efde98 render/drm_format_set: remove special LINEAR case
This was used to make the intersection of INVALID and LINEAR result
in LINEAR. We can now just require LINEAR to be in both lists.
2021-11-26 16:40:53 +00:00
Simon Ser d5df8d5cbf render/egl: always add LINEAR to supported modifiers 2021-11-26 16:40:53 +00:00
Simon Ser e163a7cf48 backend/drm: fail on explicit modifier in drmModeAddFB2
drmModeAddFB2 doesn't support explicit modifiers. Only accept INVALID
which indicates an implicit modifier and LINEAR which may indicate
that GBM_BO_USE_LINEAR has been used.
2021-11-26 16:40:53 +00:00
Simon Ser affe9eda57 Require INVALID for implicit format modifiers
See [1] for the motivation.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/75
2021-11-26 16:40:53 +00:00
Simon Ser d78cb808b1 render/drm_format_set: add wlr_drm_format_has 2021-11-26 16:40:53 +00:00
Simon Ser 585a908a01 scene: add wlr_scene_xdg_surface_create
This allows compositors to easily add an xdg_surface to the
scene-graph while retaining the ability to unconstraint popups
and decide their final position.

Compositors can handle new popups with the wlr_xdg_shell.new_surface
event, get the parent scene-graph node via wlr_xdg_popup.parent.data,
create a new scene-graph node via wlr_scene_xdg_surface_tree_create,
and unconstraint the popup if they want to.
2021-11-25 18:53:12 +01:00
Simon Zeni 1d3dd7fc08 backend: remove noop backend 2021-11-25 16:49:05 +00:00
Simon Ser b234edcf58 backend/headless: drop wlr_headless_backend_create_with_renderer
The headless backend no longer needs a parent renderer: it no longer
needs to return it in wlr_backend_impl.get_renderer, nor does it
need to return its DRM FD in wlr_backend_impl.get_drm_fd. Drop this
function altogether since it now behaves exactly like
wlr_headless_backend_create.
2021-11-25 16:16:04 +01:00
Simon Ser 2e33139ef7 render: introduce WLR_RENDER_DRM_DEVICE
This env var allows to override the DRM node used by the GLES2 and
Vulkan renderers. It's especially useful to select a DRM node when
running with the headless backend.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/2656
2021-11-25 15:12:32 +00:00
Simon Ser f29abe4c77 backend/headless: stop picking a DRM FD
Sometimes the headless backend is used standalone with the Pixman
renderer, sometimes it's used together with another backend which
has already picked a DRM FD. In both of these cases it doesn't make
sense to pick a DRM FD.

Broadly speaking the headless backend doesn't really care which DRM
device is used for the buffers it receives. So it doesn't really
make sense to tie it to a particular DRM device.

Let the backend users (e.g. wlr_renderer_autocreate) open an arbitrary
DRM FD as needed instead.
2021-11-25 15:12:32 +00:00
Simon Ser e4f748c6e9 render/allocator: fallback to renderer DRM FD in autocreate
If the backend doesn't have a DRM FD, fallback to the renderer's.
This accomodates for the situation where the headless backend hasn't
picked a DRM FD in particular, but the renderer has picked one.
2021-11-25 15:12:32 +00:00
Simon Ser bf57825560 render: pick DRM FD in autocreate
If the backend hasn't picked a DRM FD but supports DMA-BUF, pick
an arbitrary render node. This will allow removing the DRM device
selection logic from the headless backend.
2021-11-25 15:12:32 +00:00
Simon Ser bcefb71cf6 docs/env_vars: drop WLR_DIRECT_TTY
The direct session is gone, so this env var isn't looked up
anymore.
2021-11-24 10:57:53 +01:00
Joshua Ashton f132d66816 render/vulkan: Optimize vertex shader
This ends up being a horrible global load:

  s_getpc_b64   s[4:5]                                  // 000000000000: BE841C80
  v_add_u32     v0, s2, v0                              // 000000000004: 68000002
  v_sub_co_u32  v1, vcc, 0, v0                          // 000000000008: 34020080
  v_max_i32     v1, v0, v1                              // 00000000000C: 1A020300
  v_and_b32     v1, 3, v1                               // 000000000010: 26020283
  v_cmp_lt_i32  s[0:1], v0, 0                           // 000000000014: D0C10000 00010100
  v_sub_co_u32  v0, vcc, 0, v1                          // 00000000001C: 34000280
  v_cndmask_b32  v0, v1, v0, s[0:1]                     // 000000000020: D1000000 00020101
  v_lshlrev_b32  v1, 3, v0                              // 000000000028: 24020083
  v_mad_u32_u24  v0, v0, 8, 4                           // 00000000002C: D1C30000 02111100
  v_min_u32     v1, 32, v1                              // 000000000034: 1C0202A0
  v_min_u32     v0, 32, v0                              // 000000000038: 1C0000A0
  s_getpc_b64   s[0:1]                                  // 00000000003C: BE801C00
  s_add_u32     s0, s0, 0x0000003c                      // 000000000040: 8000FF00 0000003C
  s_addc_u32    s1, s1, 0                               // 000000000048: 82018001
  global_load_dword  v1, v[1:2], s[0:1]                 // 00000000004C: DC508000 01000001
  global_load_dword  v0, v[0:1], s[0:1]                 // 000000000054: DC508000 00000000
  v_mov_b32     v2, 0                                   // 00000000005C: 7E040280
  v_mov_b32     v3, 1.0                                 // 000000000060: 7E0602F2
  s_waitcnt     vmcnt(0)                                // 000000000064: BF8C0F70
  exp           pos0, v1, v0, v2, v3 done               // 000000000068: C40008CF 03020001
  exp           param0, off, off, off, off              // 000000000070: C4000200 00000000
  s_endpgm                                              // 000000000078: BF810000
  v_cndmask_b32  v0, s0, v0, vcc                        // 00000000007C: 00000000
  v_cndmask_b32  v0, s0, v0, vcc                        // 000000000080: 00000000
  v_add_f16     v192, s0, v0                            // 000000000084: 3F800000
  v_cndmask_b32  v0, s0, v0, vcc                        // 000000000088: 00000000
  v_add_f16     v192, s0, v0                            // 00000000008C: 3F800000
  v_add_f16     v192, s0, v0                            // 000000000090: 3F800000
  v_cndmask_b32  v0, s0, v0, vcc                        // 000000000094: 00000000
  v_add_f16     v192, s0, v0                            // 000000000098: 3F800000
  v_cndmask_b32  v0, s0, v0, vcc                        // 00000000009C: 00000000

With some bit magic, we can get something much nicer:

  v_add_u32     v0, s2, v0                              // 000000000000: 68000002
  v_add_u32     v1, 1, v0                               // 000000000004: 68020081
  v_and_b32     v1, 2, v1                               // 000000000008: 26020282
  v_cvt_f32_i32  v1, v1                                 // 00000000000C: 7E020B01
  v_mul_f32     v1, 0.5, v1                             // 000000000010: 0A0202F0
  v_and_b32     v0, 2, v0                               // 000000000014: 26000082
  v_cvt_f32_i32  v0, v0                                 // 000000000018: 7E000B00
  v_mul_f32     v0, 0.5, v0                             // 00000000001C: 0A0000F0
  v_mov_b32     v2, 0                                   // 000000000020: 7E040280
  v_mov_b32     v3, 1.0                                 // 000000000024: 7E0602F2
  exp           pos0, v1, v0, v2, v3 done               // 000000000028: C40008CF 03020001
  exp           param0, off, off, off, off              // 000000000030: C4000200 00000000
  s_endpgm                                              // 000000000038: BF810000

The above output was based on just shoving it in ShaderPlayground -- I was not able to use pipeline feedback as I was unable to get RenderDoc working due to the EXT_physical_device_drm requirement.

I additionally considered using >> 1 instead of * 0.5, but AMD has dedicated modifiers to merge a * 0.5, * 2.0, etc in a single instruction. (Albeit, not taken advantage of in the code above, but might with ACO)

Signed-off-by: Joshua Ashton <joshua@froggi.es>
2021-11-23 15:46:24 +00:00
Simon Ser 5332935afc render/vulkan: quiet glslangValidator
This suppresses the output filename printed to stdout. Errors and
warnings should still be printed to stderr as usual.
2021-11-23 15:38:56 +00:00
Simon Ser 1d9c1bcea6 input-device: remove wlr_input_device.link
This field's ownership is unclear: it's in wlr_input_device, but
it's not managed by the common code, it's up to each individual
backend to use it and clean it up.

Since this is a backend implementation detail, move it to the
backend-specific structs.
2021-11-23 14:14:18 +00:00
Isaac Freund c9ba9e82b6
wlr_drag: emit destroy after wl_data_device.leave 2021-11-22 22:43:39 +01:00
Simon Ser 3b93da70a0 backend/wayland: report parent presentation clock
There's no guarantee that the parent Wayland compositor uses
CLOCK_MONOTONIC for reporting presentation timestamps, they could
be using e.g. CLOCK_MONOTONIC_RAW or another system-specific clock.

Forward the value via wlr_backend_impl.get_presentation_clock.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3254#note_1143061
2021-11-22 19:31:59 +01:00
Simon Ser 3d73b899ff linux-dmabuf-v1: hide wlr_linux_buffer_params_v1
The parameters are used when the client is in the process of
building a buffer. There's no reason why this internal
implementation detail should be exposed in our public header.
2021-11-22 10:32:55 +01:00
Simon Zeni d70d74ad4f ci/archlinux: enable address and undefined sanitizers 2021-11-19 16:42:14 +00:00
Simon Zeni 52c34e8253 tinywl: build with meson if examples option is enabled 2021-11-19 16:42:14 +00:00
Simon Ser e656697a7d backend/drm: scan leases on uevent
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3181
2021-11-19 16:06:07 +00:00
Simon Ser 6bb8973309 drm-lease-v1: listen to lease destroy event 2021-11-19 16:06:07 +00:00
Simon Ser 86f5ecf468 backend/drm: introduce wlr_drm_lease
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3183
2021-11-19 16:06:07 +00:00
Simon Ser a37f538ca0 Introduce WLR_DEVICE_LEASE events
This will allow the DRM backend to reload its lessee list.
2021-11-19 16:06:07 +00:00
Manuel Stoeckl d0bb7df630 output: remove XRGB8888 cursor fallback format
All graphics drivers supporting cursor planes support ARGB8888,
the default cursor format, so this fallback is almost certainly
unused.

Essentially all cursor themes use alpha transparency to make it
clearer where relative to the screen content the cursor hotspot is.
It is better to fall back to a slightly slower software cursor than
it is to fall back to the opaque square that is a hardware cursor
without an alpha channel.
2021-11-19 15:51:46 +00:00
Manuel Stoeckl e879d566bb output: Add function to set preferred render format
This change introduces new double buffered state to the wlr_output,
corresponding to the buffer format to render to.

The format being rendered to does not control the bit depth of colors
being sent to the display; it does generally determine the format with
which screenshot data is provided. The DRM backend _may_ sent higher
bit depths if the render format depth is increased, but hardware and
other limitations may apply.
2021-11-19 15:51:46 +00:00
Manuel Stoeckl 3d7d6ec06f output: use XRGB8888 format instead of ARGB8888
Most (and possibly all) compositors using wlroots only ever render
fully opaque content. To provide better performance, this change
switches the default format used by wlr_output buffers from
ARGB8888 to the opaque XRGB8888.

Compositors like mutter, kwin, and weston already default to
XRGB8888, so this change is unlikely to expose any new bugs in
underlying drivers and hardware.

This does not affect the hardware cursor's buffer format, which is
still ARGB8888 by default.

As part of this change, the X11 backend (which does not support
changing format at runtime) now picks a true color, 24 bit depth
visual (i.e. XRGB8888) instead of a 32 bit depth (ARGB8888) one.
2021-11-19 15:51:46 +00:00
Manuel Stoeckl 7508f87fcb output: lift up output format fallback logic
This makes it possible for the two functions using output_pick_format
(output_pick_cursor_format and output_create_swapchain) to select
different buffer formats.
2021-11-19 15:51:46 +00:00
Simon Zeni ee210758fc tinywl: init output render before commit 2021-11-19 10:44:51 -05:00
Simon Zeni c0fd60be63 backend: fix attempt_backend_by_name multi backend self insertion 2021-11-19 10:44:51 -05:00
Simon Zeni 25bb92faee backend/multi: add asserts in wlr_multi_backend_add 2021-11-19 10:44:45 -05:00
Simon Ser 33eba9080c output: fix renderer buffer cap sanity check in wlr_output_init_render
The backend and renderer don't directly interact together, so there's
no point in checking that their buffer caps intersect. What we want to
check is that:

- The backend and allocator buffer caps are compatible, because the
  backend consumes buffers to display them.
- The renderer and allocator buffer caps are compatible, because the
  renderer imports buffers to sample them or render to them.

For instance, when running with the DRM backend and the Pixman renderer,
the (backend & renderer) check will fail because backend = DMABUF and
renderer = DATA_PTR.
2021-11-19 15:24:07 +01:00
Érico Nogueira e736ebc63c docs: mention WLR_RENDERER=vulkan.
This option was added with commit
8e34692250.
2021-11-19 02:08:51 +00:00
Simon Zeni fdf3169b41 backend: remove wlr_backend_get_renderer 2021-11-18 09:37:57 -05:00
Simon Zeni d1ebd52ab2 backend/multi: remove backend_get_renderer 2021-11-18 09:37:57 -05:00
Simon Zeni 42549a1c9a backend/drm: stop initializing backend renderer 2021-11-18 09:37:57 -05:00
Simon Zeni a143093339 backend/headless: don't store the parent renderer 2021-11-18 09:37:57 -05:00
Simon Zeni 5f11198605 backend/x11: get renderer from wlr_x11_output 2021-11-18 09:37:57 -05:00
Simon Zeni 5a98eae0dc types/wlr_scene: use renderer from wlr_output 2021-11-18 09:37:57 -05:00
Simon Zeni d07c87f668 types/wlr_screencopy_v1: use renderer from output 2021-11-18 09:37:57 -05:00
Simon Zeni 6dc6af1534 backend: remove backend_get_allocator 2021-11-18 09:37:57 -05:00
Simon Zeni 0c76aef202 backend: remove backend ensure renderer and allocator check 2021-11-18 09:37:57 -05:00
Simon Zeni a6538ced35 tinywl: autocreate allocator and init output 2021-11-18 09:37:57 -05:00
Simon Zeni 6d6e70b9e0 examples: init wlr_output with allocator and renderer 2021-11-18 09:37:57 -05:00
Simon Ser 142d10e591 output: add wlr_output_init_render
Co-authored-by: Simon Zeni <simon@bl4ckb0ne.ca>
2021-11-18 09:37:32 -05:00
Demi Marie Obenour b5d4bc3c62 Improve wlr_drm_format documentation
A wlroots user can easily get confused and think that `cap` refers to
wlroots buffer capabilities, not array capacity.
2021-11-17 16:35:20 +00:00
Simon Ser a04cfca4da Remove support for DMA-BUF flags
They are never used in practice, which makes all of our flag
handling effectively dead code. Also, APIs such as KMS don't
provide a good way to deal with the flags. Let's just fail the
DMA-BUF import when clients provide flags.
2021-11-17 16:12:59 +00:00
Simon Ser 9a4e1095ca linux-dmabuf-v1: properly validate flags
We were send a protocol error if INTERLACED or BOTTOM_FIRST was
set. This is incorrect for the zwp_linux_dmabuf_params.create
code-path because this kills the client without allowing it to
gracefully handle the error.

We should only send a protocol error if the client provides a bit
not listed in the protocol definition.
2021-11-17 16:12:59 +00:00
Roman Gilg 8274c85d21 backend/headless: unlink input device on destroy
Removing an input device requires unlinking it from the list of all headless
input devices. For that implement a destroy function.
2021-11-15 12:49:26 +01:00
Raphael Robatsch 4a8e681a5f util/token: don't leak /dev/urandom fd to children
Closes #3324.
2021-11-14 12:30:03 +01:00
Cole Mickens 3a685b10b6
egl: use alts for EGL_EXT_device_enum, if missing 2021-11-09 16:47:32 -08:00
Simon Zeni 02a1ae169e render/allocator: make wlr_allocator part of the public API 2021-11-09 15:26:36 +00:00
Isaac Freund ab16861e86 text-input: fix type of send_preedit_string() args
The protocol uses a signed integer here, which is also what the
wlr_input_method_v2_preedit_string struct provides to compositors from
the input method protocol. Sway currently just passes those int32_t
values directly to this function leading to an implicit conversion.
2021-11-08 19:56:22 +00:00
Simon Ser 76bab68e70 output: drop wlr_output_export_dmabuf
Callers can access output->front_buffer instead.
2021-11-08 15:57:19 +00:00
Simon Ser fa77aeb80e screencopy-v1: stop using wlr_output_export_dmabuf 2021-11-08 15:57:19 +00:00
Simon Ser f20c49d78a export-dmabuf-v1: stop using wlr_output_export_dmabuf 2021-11-08 15:57:19 +00:00
Isaac Freund e326b76959
text-input/input-method: handle strdup() failure 2021-11-07 21:01:24 +01:00
Simon Ser eb5f23d6d0 scene: fix calloc size mismatch 2021-11-07 13:28:23 +01:00
Kirill Primak fc1ed72bdc CONTRIBUTING.md: add CoC section 2021-11-06 17:01:53 +03:00
Isaac Freund 8634dd3e6a
output: fix leak of wlr_drm_format 2021-11-06 13:35:26 +01:00
Simon Ser e13f3f8608 backend/drm: handle per-connector hotplug events
When a connector ID is specified in a hotplug event, don't scan all
connectors. Only scan the connector that has changed.
2021-11-02 13:36:43 +01:00
Simon Ser 2ff4e113e2 backend/session: introduce wlr_device_change_event
This struct contains additional information for session device
change events, such as the DRM connector ID that has changed.
2021-11-02 13:30:51 +01:00
Simon Ser 3e801d68f2 xwayland: add support for -noTouchPointerEmulation
This allows compositors to handle touch pointer emulation manually,
instead of having Xwayland do it [1].

[1]: https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/691
2021-11-02 12:02:51 +01:00
Jan Beich 760e166578 render: completely disable gles2 if requested but libEGL is found
For `required` to disable search the value needs to be of `feature` type.
Checking `gles2` via `in` keyword returns a `bool` but `required: false`
makes the dependency optional instead of disabled.
2021-11-02 09:36:38 +00:00
Simon Ser 8bc1086cac s/GitHub/GitLab/ 2021-11-01 18:54:26 +00:00
Simon Ser d1b75674d4 ci: add .gitlab-ci.yml
This is a glue file to allow integration with builds.sr.ht.
2021-11-01 16:51:18 +01:00
tiosgz cc2ebd9fc0 scene/subsurface_tree: hide unmapped subsurfaces 2021-10-31 17:07:13 +01:00
Ronan Pigott 8e225261f0 backend/wayland: use xdga client activation 2021-10-31 10:33:14 +01:00
Ronan Pigott e2aff8a9b0 xdg-activation-v1: add data field and emit token destroy events
The data field is useful to track metadata about a token. The destroy
events are useful for compositors that track application startup to
let them know they can stop doing that.
2021-10-31 10:33:14 +01:00
Ronan Pigott 6ad0f819e2 xdg-activation-v1: enable compositors to request their own tokens
These new functions allow a compositor to request new managed tokens
without participating in the xdg-activation procedure as a wayland
client.

This enables the compositor itself to behave as a launcher
application.
2021-10-31 10:33:14 +01:00
Simon Ser 83090de034 backend/drm: avoid creating empty FB_DAMAGE_CLIPS prop
drmModeCreatePropertyBlob cannot create zero-sized blobs, that
fails with EINVAL.

Closes: https://github.com/swaywm/wlroots/issues/3297
2021-10-29 15:03:17 +02:00
Simon Ser b2f6ff45c2 output: fix stack variable lifetime in wlr_output_send_present
Variables on the stack are released when the parent block is closed.
Here, `now` is used outside of the `if` block, causing the following
crash when starting Sway with the headless backend:

    ==49606==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7fff94645f90 at pc 0x5558aeae9e29 bp 0x7fff94645df0 sp 0x7fff94645de0
    READ of size 16 at 0x7fff94645f90 thread T0
        #0 0x5558aeae9e28 in handle_present ../sway/desktop/output.c:834
        #1 0x7fdc8d6792fb in wlr_signal_emit_safe ../subprojects/wlroots/util/signal.c:29
        #2 0x7fdc8d54f77f in wlr_output_send_present ../subprojects/wlroots/types/output/output.c:766
        #3 0x7fdc8d524a28 in output_commit ../subprojects/wlroots/backend/headless/output.c:71
        #4 0x7fdc8d54d2db in wlr_output_commit ../subprojects/wlroots/types/output/output.c:629
        #5 0x5558aeb013cb in output_render ../sway/desktop/render.c:1157
        #6 0x5558aeae549e in output_repaint_timer_handler ../sway/desktop/output.c:544
        #7 0x5558aeae5f8a in damage_handle_frame ../sway/desktop/output.c:606
        #8 0x7fdc8d6792fb in wlr_signal_emit_safe ../subprojects/wlroots/util/signal.c:29
        #9 0x7fdc8d6007d5 in output_handle_frame ../subprojects/wlroots/types/wlr_output_damage.c:44
        #10 0x7fdc8d6792fb in wlr_signal_emit_safe ../subprojects/wlroots/util/signal.c:29
        #11 0x7fdc8d54ee84 in wlr_output_send_frame ../subprojects/wlroots/types/output/output.c:720
        #12 0x7fdc8d54efc3 in schedule_frame_handle_idle_timer ../subprojects/wlroots/types/output/output.c:728
        #13 0x7fdc8c9dcf5a in wl_event_loop_dispatch_idle (/usr/lib/libwayland-server.so.0+0xaf5a)
        #14 0x7fdc8c9dcfb4 in wl_event_loop_dispatch (/usr/lib/libwayland-server.so.0+0xafb4)
        #15 0x7fdc8c9dabc6 in wl_display_run (/usr/lib/libwayland-server.so.0+0x8bc6)
        #16 0x5558aeac8e30 in server_run ../sway/server.c:285
        #17 0x5558aeac3c7d in main ../sway/main.c:396
        #18 0x7fdc8be35b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
        #19 0x5558aea8686d in _start (/home/simon/src/sway/build/sway/sway+0x33f86d)
2021-10-29 15:03:29 +03:00
Simon Ser 0817c52a21 backend/drm: get rid of BO handle table
The BO handle table exists to avoid double-closing a BO handle,
which aren't reference-counted by the kernel. But if we can
guarantee that there is only ever a single ref for each BO handle,
then we don't need the BO handle table anymore.

This is possible if we create the handle right before the ADDFB2
IOCTL, and close the handle right after. The handles are very
short-lived and we don't need to track their lifetime.

Because of multi-planar FBs, we need to be a bit careful: some
FB planes might share the same handle. But with a small check, it's
easy to avoid double-closing the same handle (which wouldn't be a
big deal anyways).

There's one gotcha though: drmModeSetCursor2 takes a BO handle as
input. Saving the handles until drmModeSetCursor2 time would require
us to track BO handle lifetimes, so we wouldn't be able to get rid
of the BO handle table. As a workaround, use drmModeGetFB to turn the
FB ID back to a BO handle, call drmModeSetCursor2 and then immediately
close the BO handle. The overhead should be minimal since these IOCTLs
are pretty cheap.

Closes: https://github.com/swaywm/wlroots/issues/3164
2021-10-29 11:38:37 +02:00
Simon Ser 3b96aa04db sceeencopy-v1: listen to output destroy in capture_output
If the output is destroyed after capture_output but before
frame_handle_copy, it'll have a dangling output pointer. Add the
output destroy listener in capture_output.

Closes: https://github.com/swaywm/wlroots/issues/3284
2021-10-29 11:37:59 +02:00
Simon Ser a80f2b2816 scene: inline subsurface_tree_destroy
This is only called from one function.

To destroy the wlr_scene_subsurface_tree from elsewhere, callers
can destroy the scene-graph node returned by
wlr_scene_subsurface_tree_create instead (just like a compositor
would do). subsurface_tree_handle_surface_destroy does exactly this.

Inlining avoids calling subsurface_tree_destroy by mistake.
2021-10-27 16:18:10 +02:00
Haelwenn (lanodan) Monnier a92293a15a backend/drm/legacy.c: Fix memory leak in drm_legacy_crtc_set_gamma
Found via scan-build
2021-10-27 07:30:36 -06:00
Haelwenn (lanodan) Monnier 6666604f17 render/egl.c: Fix memory leaks in egl_create
calloc is moved to right before egl is called to avoid requiring to free()
unused memory.

Found via scan-build
2021-10-27 07:30:36 -06:00
Haelwenn (lanodan) Monnier 4fb652c27f render/pixman/renderer.c: Fix memory-leak in create_buffer
Found via scan-build
2021-10-27 07:30:36 -06:00
MarkusVolk ebe3cfaceb backend.c: do not try to explicitly clean up the libinput backend
Since libinput is an optional dependency the libinput backend is possibly undeclared.
wlr_backend_destroy(backend) below will clean up the child libinput backend if any.
2021-10-27 14:54:01 +02:00
Simon Ser cbedbd0fc0 backend/x11: fix code style in get_touchpoint_from_x11_touch_id 2021-10-27 12:08:09 +02:00
Simon Ser 5619cf368b backend/drm: add entry for Valve EDID vendor
As found in e.g. the Steam Deck.
2021-10-26 08:45:30 -06:00
Simon Ser c43130cb89 readme: refresh dependencies 2021-10-26 15:31:38 +02:00
Simon Ser bf42630d32 output: refuse to enable with zero mode
This can happen if the compositor enables an output without
picking a mode, or performs a modeset with a zero width/height.
2021-10-26 07:01:34 -06:00
Simon Ser 3d6ca9942d xdg-foreign-v2: use error enum
A wayland-protocols patch [1] has added error codes for invalid
surfaces.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/57

Closes: https://github.com/swaywm/wlroots/issues/2600
2021-10-25 18:22:11 +03:00
Simon Ser fb393ddf84 output: split into multiple files
This organizes the wlr_output implementation into separate files.
This avoids having a single mega-file with lots of unrelated parts
and makes it more obvious what the interactions between all the
parts are.

No functional changes, just moving code around.
2021-10-23 00:49:24 +02:00
Simon Ser a4ccca0834 scene: add support for direct scan-out
Check if only a single node intersects with the output viewport
and all of its properties match. In this case, attempt direct
scan-out.
2021-10-23 00:49:07 +02:00
Simon Ser db4c93028d scene: add wlr_scene_output_for_each_surface
This allows compositors to more easily implement sending
wl_surface.frame callback done events.
2021-10-22 22:29:35 +02:00
Simon Zeni 70e8277175 backend/multi: implement get_buffer_caps 2021-10-22 22:19:47 +02:00
Simon Ser 7c10a77e0a presentation-time: remove unused field 2021-10-22 06:44:39 -06:00
Kirill Primak 6c3a71d9f6 presentation-time: use a surface addon 2021-10-22 11:57:19 +02:00
buffet 3dc99ed281 Update loc count in readme 2021-10-21 16:37:53 +02:00
Simon Ser 36cf387427 render/vulkan: check vulkan-headers dependency
There's no pkg-config file we can check for sadly, so check
vulkan/vulkan.h as a fallback.

Closes: https://github.com/swaywm/wlroots/issues/3272
2021-10-19 06:51:14 -06:00
Simon Ser f7ea33da0a scene: remove surface commit listener when node is destroyed 2021-10-18 16:25:19 +02:00
Joshua Ashton b62ce3c3c8 render/vulkan: Use image view swizzles instead of shader hack
Signed-off-by: Joshua Ashton <joshua@froggi.es>
2021-10-18 15:57:46 +02:00
Anthony Super e22a386319 Add error handling to backend creation
This commit adds two error-handling cases to the function
attempt_dmr_backend. Specifically:

- In the case where the number of found GPUs is zero, we now
  print a log message indicating this and return a NULL pointer
- In the case where we could not successfully create a backend
  on any GPU, we now log a message indicating this and return
  a NULL pointer

This allows us to provide more descriptive error messages,
as well as avoid a SEGFAULT (the function
`ensure_primary_backend_renderer_and_allocator` dereferences the pointer
given, which could be NULL until this patch) when these cases arise.
2021-10-18 14:36:04 +02:00
nyorain 8e34692250 render/vulkan: add Vulkan renderer
This new renderer is implemented with the existing wlr_renderer API
(which is known to be sub-optimal for some operations). It's not
used by default, but users can opt-in by setting WLR_RENDERER=vulkan.

The renderer depends on VK_EXT_image_drm_format_modifier and
VK_EXT_physical_device_drm.

Co-authored-by: Simon Ser <contact@emersion.fr>
Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
2021-10-18 11:51:13 +02:00
Kirill Primak 2edf468aeb presentation-time: don't send presented on discard 2021-10-15 09:38:58 +02:00
Kirill Primak 2af8cc769a output: add presented flag to presentation event 2021-10-15 09:38:58 +02:00
Kirill Primak 1089b7b8d6 output: disallow NULL event for wlr_output_send_present() 2021-10-15 09:38:58 +02:00
Simon Ser 1b65a80e9d render/allocator: use empty DRM lease to re-open node
This allows us to obtain a new DRM file description without relying
on filesystem permissions.
2021-10-14 21:23:41 +02:00
Isaac Freund 4fae8f7be3 scene: add functions to place node on top/bottom
These are very common operations for compositors (including tinywl)
to perform.
2021-10-14 21:10:03 +02:00
Isaac Freund 2a8d385386 scene: assert that node != sibling in place above/below
Currently these functions remove the node from the scene if the sibling
argument is the same node as the node. To prevent confusion when
misusing this API, assert that the nodes are distinct and document this.
2021-10-14 21:10:03 +02:00
fwsmit dc22a06184 examples/foreign-toplevel: fix toplevel not being freed 2021-10-07 20:36:21 +02:00
Kirill Primak c3e54021f8 xdg-decoration: refactor configure/state flow
The same logic/motivation as xdg-toplevel.
2021-10-07 07:27:51 -06:00
Kirill Primak cdaab82020 layer-shell: move NULL buffer check to role precommit handler
This will allow compositor to access the current buffer before
unmapping.
2021-10-06 10:15:49 +02:00
Kirill Primak 28248dd83b xdg-shell: remove redundant NULL buffer check
This is already checked in role precommit handler, and if the buffer is
NULL due to failed upload, that means the surface was already unmapped.
2021-10-06 10:15:49 +02:00
Jan Beich 31af2b67b0 backend: drop unconditional and unused <libinput.h>
After 70fb21c35b made libinput optional the include prevents
building without libinput package installed.

backend/backend.c:4:10: fatal error: 'libinput.h' file not found
 #include <libinput.h>
          ^~~~~~~~~~~~
2021-10-05 09:11:44 +02:00
Simon Ser 13cdb84ee8 render/allocator: use render node if available in reopen_drm_node
If we aren't trying to create a dumb buffer allocator, and if the
DRM device has a render node (ie, not a split render/display SoC),
then we can use the render node instead of the primary node. This
should allow wlroots to run under seatd when the current user
doesn't have the permission to open primary nodes (logind has a
quirk to allow physically logged in users to open primary nodes).
2021-10-04 12:25:27 +02:00
tiosgz ce66244fd2 surface_at: check if surfaces are mapped 2021-10-02 11:38:40 +02:00
tiosgz 893434b2d4 for_each_surface: only iterate mapped surfaces
These functions are used mostly for rendering, where including unmapped
surfaces is undesired.

This is a breaking change. However, few to no usages will have to be
updated.
2021-10-02 11:38:40 +02:00
Elyes HAOUAS dc3d1530bf Fix spelling errors
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2021-10-02 10:22:13 +02:00
Simon Ser 323b8498ad Revert "render/drm_format_set: add wlr_drm_format_has"
This reverts commit 833437d592.
2021-10-01 09:26:05 -06:00
Simon Ser 1d7e438d8a Revert "Require INVALID for implicit format modifiers"
This reverts commit ea7357b703.
2021-10-01 09:26:05 -06:00
Simon Ser 61b83441a1 Revert "backend/drm: fail on explicit modifier in drmModeAddFB2"
This reverts commit d6be1d68b7.
2021-10-01 09:26:05 -06:00
Simon Ser 62be833aef Revert "render/egl: always add LINEAR to supported modifiers"
This reverts commit 780052d4da.
2021-10-01 09:26:05 -06:00
Simon Ser 42138a073b Revert "render/drm_format_set: remove special LINEAR case"
This reverts commit 6d281d96cb.
2021-10-01 09:26:05 -06:00
Simon Ser 6d281d96cb render/drm_format_set: remove special LINEAR case
This was used to make the intersection of INVALID and LINEAR result
in LINEAR. We can now just require LINEAR to be in both lists.
2021-10-01 09:21:50 -06:00
Simon Ser 780052d4da render/egl: always add LINEAR to supported modifiers 2021-10-01 09:21:50 -06:00
Simon Ser d6be1d68b7 backend/drm: fail on explicit modifier in drmModeAddFB2
drmModeAddFB2 doesn't support explicit modifiers. Only accept INVALID
which indicates an implicit modifier and LINEAR which may indicate
that GBM_BO_USE_LINEAR has been used.
2021-10-01 09:21:50 -06:00
Simon Ser ea7357b703 Require INVALID for implicit format modifiers
See [1] for the motivation.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/75
2021-10-01 09:21:50 -06:00
Simon Ser 833437d592 render/drm_format_set: add wlr_drm_format_has 2021-10-01 09:21:50 -06:00
Simon Ser 744a5c2fef xdg-shell: stop clearing wlr_xdg_surface state on unmap
The protocol doesn't say we should, so let's not.

Also it's pointless to reset scheduled_serial, since 0 is a valid
serial.
2021-09-30 23:17:32 +03:00
Simon Ser 665a164f27 xdg-shell: rename wlr_xdg_surface.next_configure_serial
Rename it to scheduled_serial for consistency with the rest of
wlroots.
2021-09-30 23:17:32 +03:00
Simon Ser 0e34208344 xdg-shell: introduce wlr_xdg_surface.current
This holds the current state, and avoids having ad-hoc fields in
wlr_xdg_surface.
2021-09-30 23:17:32 +03:00
Kirill Primak db4afc2408 xdg-surface: add pending state
struct wlr_xdg_surface_state is introduced to hold the geometry
and configure serial to be applied on next wl_surface.commit.

This commit fixes our handling for ack_configure: instead of making
the request mutate our current state, it mutates the pending state
only.

Co-authored-by: Simon Ser <contact@emersion.fr>
2021-09-30 23:17:32 +03:00
Simon Ser 3d0848daae backend: create renderer and allocator in wlr_backend_autocreate
Instead of ensuring the renderer and allocator are initialized in each
backend, do it in wlr_backend_autocreate. This allows compositors to
create backends without any renderer/allocator if they side-step
wlr_backend_autocreate.

Since the wlr_backend_get_renderer and backend_get_allocator end up
calling wlr_renderer_autocreate and wlr_allocator_autocreate, it sounds
like a good idea to centralize all of the opimionated bits in one place.
2021-09-30 08:50:43 -06:00
José Expósito 20d9448257 wlr_pointer_gestures: hold gestures (protocol v3)
Update the pointer gestures protocol to version 3 allowing to send hold
gestures to clients.
2021-09-27 15:30:31 +02:00
José Expósito 5f3e490c80 wlr_pointer_gestures: update protocol to version 2 2021-09-27 15:30:31 +02:00
José Expósito 4c3e307ec8 cursor: emit hold gesture events
Recevie the hold gesture events from the libinput or Wayland backends,
abstracted as pointer signals, and re-emit them from the cursor
interface.
2021-09-27 15:30:31 +02:00
José Expósito 62e62b6942 backend/wayland: send hold gesture events
Receive hold gesture events using a Wayland listiner and emit the
appropiate wlr_pointer signal.
2021-09-27 15:30:31 +02:00
José Expósito 52d2491931 backend/libinput: send hold gesture events
Receive hold gesture events from libinput and emit the appropiate
wlr_pointer signal.
2021-09-27 15:30:31 +02:00
José Expósito 95970b3619 build: check if libinput supports hold gestures
Add a project argument (LIBINPUT_HAS_HOLD_GESTURES) to allow building
against old versions of libinput.
2021-09-27 15:30:31 +02:00
José Expósito d069a783bc pointer: add hold pointer event definition
As touchpad touches are generally fully abstracted, a client cannot
currently know when a user is interacting with the touchpad without
moving. This is solved by hold gestures.

Hold gestures are notifications about one or more fingers being held
down on the touchpad without significant movement.

Hold gestures are primarily designed for two interactions:

 - Hold to interact: where a hold gesture is active for some time a
   menu could pop up, some object could be selected, etc.
 - Hold to cancel: where e.g. kinetic scrolling is currently active,
   the start of a hold gesture can be used to stop the scroll.

Unlike swipe and pinch, hold gestures, by definition, do not have
movement, so there is no need for an "update" stage in the gesture.

Create two structs, wlr_event_pointer_hold_begin and
wlr_event_pointer_hold_end, to represent hold gesture events and the
signals to emit them: wlr_pointer->pointer.hold_begin/hold_end.
2021-09-27 15:30:31 +02:00
José Expósito fb15538247 protocol/meson: bump wayland-protocols requirement to 1.23 2021-09-27 15:30:31 +02:00
Hubert Hirtz d96d2f5f23 Fix a typo in CONTRIBUTING.md 2021-09-24 16:33:26 +02:00
Kirill Primak 754f40f9cb layer-shell: add `committed` bitmask 2021-09-24 14:38:32 +02:00
Kirill Primak 59fa3637c3 layer-shell: refactor configure/state flow
Same logic as xdg-toplevel.
2021-09-23 21:22:41 +02:00
Simon Ser 3c26244340 scene: add wlr_scene_buffer_set_transform 2021-09-22 10:45:39 -06:00
Simon Ser 43833fba64 scene: add wlr_scene_buffer_set_dest_size 2021-09-22 10:45:39 -06:00
Simon Ser 3d4afbe945 scene: use scene_node_get_size in wlr_scene_node_at
This allows to unify the RECT and BUFFER code-paths. The BUFFER one
will become more complicated with destination size and transforms.
2021-09-22 10:45:39 -06:00
Simon Ser 27b529f8a0 scene: add scene_node_get_size helper 2021-09-22 10:45:39 -06:00
Simon Ser 63040d6744 scene: add wlr_scene_buffer_set_source_box 2021-09-22 10:45:39 -06:00
Simon Ser fdc22449d6 util/box: introduce wlr_fbox_empty
Same as wlr_box_empty, but for wlr_fbox.
2021-09-22 10:45:39 -06:00
Simon Ser 7939bf8cc6 scene: add wlr_scene_buffer
This new scene-graph node displays a wlr_buffer.

Closes: https://github.com/swaywm/wlroots/issues/3161
2021-09-22 10:45:39 -06:00
Simon Ser f6f0e010d1 scene: unify intersection logic in wlr_scene_node_at
Let's extract the common bits.
2021-09-22 10:45:39 -06:00
Simon Ser b25759cd20 scene: drop default case in wlr_scene_node_at
This allows the compiler to error out if we haven't enumerated all
of the cases. This is useful to avoid a missing implementation when
adding a new node type.
2021-09-22 10:45:39 -06:00
Tadeo Kondrak 30d3c76817 Implement input_method_v2 popups 2021-09-22 09:42:14 +02:00
Tadeo Kondrak e0daa65aa6 input-method-unstable-v2: Add error for surface with existing role 2021-09-22 09:42:14 +02:00
Simon Ser 2e12de96ca backend/drm: add support for panel orientation
Expose the panel orientation with wlr_drm_connector_get_panel_orientation.
Leave it to the compositor to consume this information and configure the
output accordingly.

Closes: https://github.com/swaywm/wlroots/issues/1581
2021-09-21 11:40:37 -06:00
Simon Ser 0c5ff5efab build: simplify get_variable calls
With recent-ish Meson we can stop repeating the variable name for
each provider.
2021-09-21 11:35:08 -06:00
Simon Ser 2e590026e9 scene: add wlr_scene_subsurface_tree_create 2021-09-21 16:48:31 +02:00
Simon Ser 597ba2b932 surface: add addon set 2021-09-21 16:48:31 +02:00
Simon Ser 211b3b760e scene: add wlr_scene_tree 2021-09-21 16:48:31 +02:00
Kirill Primak ccc84f11a4 xdg surface: check adding configure_idle for NULL 2021-09-21 10:09:09 +02:00
Kirill Primak 0e2d369106 xdg-surface: simplify configure mechanism
This commit removes any checks whether a configure will change anything
and makes configures be sent unconditionally. Additionally, configures
are scheduled on xdg_toplevel.{un,}set_{maximized,fullscreen} events.
2021-09-21 10:09:09 +02:00
Kirill Primak b72a217fcc xdg-toplevel: refactor configure/state flow
Previously, `wlr_xdg_toplevel` didn't follow the usual "current state +
pending state" pattern and instead had confusingly named
`client_pending` and `server_pending`. This commit removes them, and
instead introduces `wlr_xdg_toplevel.scheduled` to store the properties
that are yet to be sent to a client, and `wlr_xdg_toplevel.requested`
to store the properties that a client has requested. They have different
types to emphasize that they aren't actual states.
2021-09-21 10:09:09 +02:00
Simon Zeni 9579d62a16 types/buffer: make {begin,end}_data_ptr_access part of the public API 2021-09-15 11:50:44 +02:00
Simon Ser 6cb25ebad7 ci: switch to seatd-launch
This removes the need for the ad-hoc loop.

Because udev creates the symlinks in /dev/dri/by-path/, we need to
wait for it to consume all pending events before the chmod call.
Previously the delay needed for seatd to come up was enough to let
udev create the symlinks in time (by chance).
2021-09-14 12:47:19 +02:00
Kirill Primak 52da68b591 xdg popup: move function to a file it belongs to 2021-09-11 12:11:55 +02:00
Guido Günther e479dc1ef0 xwayland: Allow to retrieve startup-id via _NET_STARTUP_INFO
A launchee notifies with a "remove"¹ message when done starting up.
Catch these and forward to the compositor. This allows the compositor to
end the startup sequence that might have been started by another
protocol like xdg-activation.

We don't handle other messages since we expect the launcher to use a
wayland protocol like xdg-activation.

While `_NET_STARTUP_ID` helps to associate toplevels with startup-ids
this signals the end of the startup sequence.

1) https://specifications.freedesktop.org/startup-notification-spec/startup-notification-latest.txt
2021-09-11 09:53:23 +02:00
Simon Ser 4e7a8707cc buffer: add data_ptr access flags
This allows callers to specify the operations they'll perform on
the returned data pointer. The motivations for this are:

- The upcoming Linux MAP_NOSIGBUS flag may only be usable on
  read-only mappings.
- gbm_bo_map with GBM_BO_TRANSFER_READ hurts performance.
2021-09-10 13:16:10 -04:00
Andri Yngvason 105fdecd0c screencopy: Handle shm copy in commit event handler
This simplifies the implementation considerably.
2021-09-10 10:37:18 +02:00
Andri Yngvason 04d234bac1 screencopy: Use output->front_buffer instead of wlr_output_export_dmabuf 2021-09-10 10:37:18 +02:00
Simon Ser a181a37b12 scene: add wlr_scene_attach_output_layout
This is a helper to integrate wlr_scene with wlr_output_layout.
2021-09-09 12:04:35 +02:00
Simon Ser 7832005a1f scene: move source to subdir
This will allow more scene-graph extensions to be added without
cluttering wlr_scene.c, for instance for sub-surface handling and
wlr_output_layout integration.
2021-09-09 12:04:35 +02:00
Quantum 679f5ed966 scene: fix compile error in release builds
On release builds, gcc detects a variable uninitialized error, and generates
a warning, which gets converted to an error due to -Werror.
2021-09-09 10:01:48 +02:00
Simon Ser e05c884891 examples/scene-graph: use wlr_scene_output
This allows us to get damage tracking for free™.
2021-09-08 09:50:08 -04:00
Simon Ser 44f0f7a0a7 scene: add damage tracking support 2021-09-08 09:50:08 -04:00
Simon Ser 9195b77e14 scene: add wlr_scene_node_coords 2021-09-08 09:50:08 -04:00
Simon Ser 04d105760d scene: add wlr_scene_output_commit 2021-09-08 09:50:08 -04:00
Simon Ser 968c1df7e9 scene: add scene outputs
These allow describing an output's viewport inside the scene-graph.
2021-09-08 09:50:08 -04:00
Simon Ser 872993f95d scene: fix wlr_scene_render_output offset
When providing non-zero layout-local coordinates to
wlr_scene_render_output, the viewport should be translated by the
given values. However the viewport was translated by the opposite
values: when giving 42,42 the viewport's position would be set to
-42,-42.
2021-09-08 09:50:08 -04:00
Simon Zeni 3984c81faa types: introduce wlr_drm_lease_v1 2021-09-08 11:09:07 +02:00
Simon Zeni c67e3fe3b7 protocol/meson: bump wayland-protocols requirement to 1.22 2021-09-08 11:09:07 +02:00
Simon Zeni 94ed8f9496 backend/drm: introduce wlr_drm_backend_get_non_master_fd 2021-09-08 11:09:07 +02:00
Simon Zeni e5a949a955 backend/drm: implement drm lease function 2021-09-08 11:09:07 +02:00
Simon Ser 42dba9dc90 backend/drm: drop wlr_drm_connector.desired_mode
Previously used by attempt_enable_needs_modeset, but this has been
dropped in the previous commit.
2021-09-07 22:33:40 +02:00
Simon Ser b01d97a38f backend/drm: drop attempt_enable_needs_modeset
Modesets require a buffer. The DRM backend tried to auto-enable
outputs when a CRTC becomes available in the past, but now that
fails because no buffer is available.

Instead of having this magic inside the DRM backend, a better
approach is to do it in the compositor or in an optional helper.
2021-09-07 22:33:40 +02:00
Simon Ser 04304c322e output-damage: fix damage on modeset
On modeset wlr_output will internally allocate a buffer. The
backend will emit a "mode" output event, then wlr_output will
emit a "commit" event.

wlr_output_damage handles the "mode" event by damaging the whole
output, and then handles the "commit" event. However the commit
event has a buffer, so wlr_output_damage rotates the damage in its
ring buffer, thinking the compositor has rendered a frame. The
compositor hasn't rendered a frame, what wlr_output_damage sees is
the internal wlr_output black buffer used for the modeset.

Let's fix this by damaging the whole output in the "commit" event
handler if the mode has changed. Additionally, damage the whole
output after rotating the damage ring buffer.
2021-09-07 22:27:31 +02:00
muradm 35f0a0d570 backend: wait for session to become active 2021-09-07 20:28:02 +02:00
Simon Ser 0c8fba1a2f backend/drm: drop drm_connector_init_renderer
drm_connector_set_pending_fb already takes care of this.
2021-09-07 15:16:30 +02:00
Simon Ser de1c73021c backend/drm: drop unused arg from get_possible_crtcs
Constify drmModeConnector while at it.
2021-09-07 08:45:08 -04:00
Simon Ser 274c8189d4 backend/drm: fix crash on VT switch
Don't set the MODE flag when disabling a CRTC. This fixes a NULL
pointer dereference in drm_connector_state_init.
2021-09-07 11:34:53 +02:00
Simon Ser 3c74bd0c91 backend/drm: introduce wlr_drm_connector_state
Previously, we were copying wlr_output_state on the stack and
patching it up to be guaranteed to have a proper drmModeModeInfo
stored in it (and not a custom mode). Also, we had a bunch of
helpers deriving DRM-specific information from the generic
wlr_output_state.

Copying the wlr_output_state worked fine so far, but with output
layers we'll be getting a wl_list in there. An empty wl_list stores
two pointers to itself, copying it on the stack blindly results in
infinite loops in wl_list_for_each.

To fix this, rework our DRM backend to stop copying wlr_output_state,
instead add a new struct wlr_drm_connector_state which holds both
the wlr_output_state and additional DRM-specific information.
2021-09-07 11:18:18 +02:00
Simon Ser 3fbf6e02a3 backend/drm: rename enum wlr_drm_connector_state to status
"state" is easily confused with wlr_output_state.
2021-09-07 11:18:18 +02:00
Simon Ser 88919464ef surface: fix abort on NULL buffer attach
Fixes: ba0525c5c0 ("surface: drop wlr_surface_state.buffer_resource")
Closes: https://github.com/swaywm/wlroots/issues/3173
2021-09-07 10:27:46 +02:00
Simon Ser ba0525c5c0 surface: drop wlr_surface_state.buffer_resource
Instead, use wlr_surface_state.buffer only.
2021-09-06 14:21:23 -04:00
Simon Ser 0978a702d7 surface: ensure buffer is reset to NULL in surface_state_move
When surface_state_move processes a NULL commit, make sure to
reset state->buffer to NULL instead of leaving behind an old
wlr_buffer.
2021-09-06 14:21:23 -04:00
Simon Ser 0fe3b45361 viewporter: hide wlr_viewport
This is an internal struct.
2021-09-06 19:19:45 +02:00
Simon Ser 24c397dbf8 viewporter: add doc comment explaining compositor requirements 2021-09-06 19:19:45 +02:00
Simon Ser bb82b6dada buffer: make wlr_client_buffer_apply_damage return a bool
We always return the same wlr_client_buffer as the one passed in,
so no need to return anything.
2021-09-06 18:10:26 +02:00
Simon Ser cbe099dcc7 buffer: take a wlr_buffer in wlr_client_buffer_apply_damage
Instead of taking a wl_resource as argument, take a wlr_buffer.
2021-09-06 18:10:26 +02:00
Kirill Primak 610f0c0805 surface: inline surface_commit_pending() 2021-09-06 17:37:08 +02:00
Kirill Primak cf56596565 surface: change surface_finalize_state() to surface_finalize_pending() 2021-09-06 17:37:08 +02:00
Kirill Primak ba55c7c4ff surface: rename impl and its functions
This makes the naming consistent with other resource implementations.
2021-09-06 17:37:08 +02:00
Kirill Primak 90e62390d9 surface: move subsurface lists to state 2021-09-06 17:37:08 +02:00
Simon Ser 3ac99fa4dc subsurface: move parent link to state
Move the wlr_subsurface parent link to the subsurface state.

This is a dumb find/replace operation. This shouldn't result in
any behavior change.
2021-09-06 17:37:08 +02:00
Simon Ser 56b6b80b9a subsurface: rename wlr_subsurface_state to wlr_subsurface_parent_state
Add a comment to explain the difference.
2021-09-06 17:37:08 +02:00
Kirill Primak 242c23743f surface: cache frame callback lists again
Caching frame callback lists is actually the correct behavior, because
if a surface is locked because of e.g. subsurface synchronization,
clients would expect to receive frame done events only after the
pending state is actually committed.
2021-09-06 17:37:08 +02:00
Simon Ser d290b13871 seat: avoid copying the keymap for each client
We can just send a read-only file descriptor instead.
2021-09-05 22:06:25 +02:00
Simon Ser 62924cc523 keyboard: add wlr_keyboard.keymap_fd
This exposes a read-only FD with the keymap.
2021-09-05 22:06:25 +02:00
Simon Ser 55ca93469c util/shm: add allocate_shm_file_pair
This function behaves like allocate_shm_file, except it also
returns a read-only FD. This is useful to share the same segment
of memory with many Wayland clients.
2021-09-05 22:06:25 +02:00
Simon Ser 38cd1b4f4f render/allocator/gbm: add log message for gbm_bo_get_fd_for_plane
Makes it easier to find out which branch is taken when debugging
issues like [1].

[1]: https://github.com/swaywm/wlroots/issues/3156
2021-09-03 22:13:38 +02:00
Simon Ser 5aa5137fae backend/drm: handle drm_surface_blit errors
drm_surface_blit returns NULL on error. This can happen e.g. when
the source buffer cannot be imported into EGL.

Closes: https://github.com/swaywm/wlroots/issues/3154
2021-09-03 17:57:38 +02:00
Simon Ser 7df2ae88fa render/allocator: use legacy authentication for primary nodes
Closes: https://github.com/swaywm/wlroots/issues/3156
2021-09-03 11:44:12 -04:00
Devin J. Pohly 00c2bae1d3 scene: remove redundant empty-region check in render_texture() 2021-09-02 19:05:02 +02:00
Devin J. Pohly e2e68ff680 examples/scene-graph: demonstrate scene_rect node type
Add RECT nodes to the scene-graph demo to illustrate how they are used.
Here, we add a solid rectangle behind each surface as a quick-and-dirty
border, handling surface.commit in order to size it appropriately.
2021-09-02 19:05:02 +02:00
Devin J. Pohly 9ed16e39fa scene: replace surface_at() with node_at()
With the addition of a non-surface node type, it was unclear how such
nodes should interact with scene_node_surface_at().  For example, if the
topmost node at the given point is a RECT, should the function treat
that node as transparent and continue searching, or as opaque and return
(probably) NULL?

Instead, replace the function with one returning a scene_node, which
will allow for more consistent behavior across different node types.
Compositors can downcast scene_surface nodes via the now-public
wlr_scene_surface_from_node() if they need access to the surface itself.
2021-09-02 19:05:02 +02:00
Devin J. Pohly b7cd06e8fa scene: add RECT node type
RECT is a solid-colored rectangle, useful for simple borders or other
decoration.  This can be rendered directly using the wlr_renderer,
without needing to create a surface.
2021-09-02 19:05:02 +02:00
Devin J. Pohly 526652a554 scene: iterate nodes instead of surfaces when rendering
This will allow us to create node types which are rendered but not
surface-based, such as a solid color or image.
2021-09-02 19:05:02 +02:00
Simon Ser b0972a94c3 contributing: don't reference issues in commit first line
Commits named "Fix #XXX" make it pretty complicated to figure out
exactly what the commit is doing from the shortlog. A better place
for issue references is in the extended commit message.
2021-09-02 09:31:53 -04:00
Simon Ser 267eb02c31 build: add subproject fallback for wayland-protocols
Depends on [1].

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/84
2021-09-01 15:51:03 -04:00
Simon Ser d9523faa76 build: add subproject fallback for wayland 2021-09-01 15:51:03 -04:00
Simon Ser ee6c841d47 render/allocator/gbm: fix create() docs for FD ownership
Fixes: d9d8fc1ab9 ("render/allocator: re-open GBM FD")
2021-09-01 21:34:34 +02:00
Simon Ser d9d8fc1ab9 render/allocator: re-open GBM FD
Using the same DRM file description for the DRM backend and for the
GBM allocator will result in GEM handle ref'counting issues [1].
Re-open the DRM FD to fix these issues.

[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
2021-09-01 15:17:05 -04:00
Simon Ser c8d97e2791 Link to gamja for web chat
gamja offers a better experience than Kiwi.
2021-08-30 11:10:11 -04:00
Devin J. Pohly 7ec9523ea3 scene: stricter assertions on reparent
For consistency with the rest of the scene-graph API, prevent detaching
a subtree by giving NULL for the new parent, and don't allow ROOT nodes
to be grafted into another tree.
2021-08-30 16:43:18 +02:00
Devin J. Pohly d5263be355 scene: make graph loops fatal when debugging 2021-08-30 16:43:18 +02:00
Devin J. Pohly 0f534e32e4 scene: ensure node cannot be reparented below itself 2021-08-30 16:43:18 +02:00
Devin J. Pohly a1d462fa81 scene: add node reparent function
If nodes are arranged in a tree rather than at a single level, then it
makes sense that there should be a way to move them to a completely
different parent in addition to moving up or down among siblings.
2021-08-30 16:43:18 +02:00
Simon Ser b18c254e5f contributing: turn remaining links into refs 2021-08-30 16:36:14 +02:00
Simon Ser 1ad3cd7f36 contributing: clone wlroots fork with SSH
HTTPS URLs aren't writable.
2021-08-30 10:31:51 -04:00
Simon Ser ea800b7418 contributing: use references for links
This avoids cluttering the prose with URLs.
2021-08-30 10:31:51 -04:00
Simon Ser 2ddd8e8036 contributing: add new section about commit log
This is shamelessly stolen from Weston [1].

It's been a while we've transitioned away from merge commits and
work-style commit history, so it'd be nice to mention this in the
docs.

[1]: https://gitlab.freedesktop.org/wayland/weston/-/blob/main/CONTRIBUTING.md#formatting-and-separating-commits
2021-08-30 10:29:33 -04:00
Tudor Brindus bfc69decdd xwm: do not restack surfaces on activation
Currently, upon activating a surface, wlroots restacks it on top of all
others.

This may not necessarily be correct from the calling compositor's point
of view, where having focus may not imply being top-of-stack (e.g.,
focusing a window under an always-on-top window).

In Sway's case, this means that focused tiling windows will always be on
top of floating windows, at least in the order communicated to X11 apps.
This breaks drag-and-drop from a focused tiling X11 window to a floating
X11 window which partially obscures the former.

This is a breaking change; to retain the previous behavior, users that
were calling

  wlr_xwayland_surface_activate(xsurface, true);

should now be calling

  wlr_xwayland_surface_activate(xsurface, true);
  wlr_xwayland_surface_restack(xsurface, NULL, XCB_STACK_MODE_ABOVE);
2021-08-28 22:04:01 +02:00
Simon Ser e4d0ec9ee1 scene: add wlr_scene_node_surface_at 2021-08-26 21:12:28 +02:00
Simon Ser 501b29db03 scene: add user data pointer to wlr_scene_node
This allows compositors to attach arbitrary data to the scene-graph
nodes.
2021-08-26 21:12:28 +02:00
Simon Ser 97954154bc scene: allow nodes to have arbitrary parents
For instance, allow a surface node to be a child of another surface
node. This allows easier xdg-popup handling in compositors.
2021-08-26 21:12:28 +02:00
Simon Ser 86e9309808 scene: add wlr_scene_node_toggle
This allows compositors to easily enable or disable a scene-graph node.
This can be used to show/hide a surface when the xdg_surface is
mapped/unmapped.
2021-08-26 21:12:28 +02:00
Simon Ser c41bd320be examples/scene-graph: new example 2021-08-26 21:12:28 +02:00
Simon Ser c7d489b5b6 Introduce new scene-graph API
A new wlr_scene API has been added, following the design ideas from [1].
The new API contains the minimal set of features required to make the
API useful. The goal is to design a solid fundation and add more
features in the future.

[1]: https://github.com/swaywm/wlroots/issues/1826#issuecomment-564601757
2021-08-26 21:12:28 +02:00
Kirill Primak 5f645598d8 subsurface: unlock surface on destroy 2021-08-25 19:40:25 +02:00
Simon Ser 5dfaf5ea9c backend/drm: introduce wlr_drm_bo_handle_table
Using GBM to import DRM dumb buffers tends to not work well. By
using GBM we're calling some driver-specific functions in Mesa.
These functions check whether Mesa can work with the buffer.
Sometimes Mesa has requirements which differ from DRM dumb buffers
and the GBM import will fail (e.g. on amdgpu).

Instead, drop GBM and use drmPrimeFDToHandle directly. But there's
a twist: BO handles are not ref'counted by the kernel and need to
be ref'counted in user-space [1]. libdrm usually performs this
bookkeeping and is used under-the-hood by Mesa.

We can't re-use libdrm for this task without using driver-specific
APIs. So let's just re-implement the ref'counting logic in wlroots.
The wlroots implementation is inspired from amdgpu's in libdrm [2].

Closes: https://github.com/swaywm/wlroots/issues/2916

[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
[2]: 1a4c0ec9ae/amdgpu/handle_table.c
2021-08-25 10:05:37 -04:00
Simon Ser 749b3c00f0 render/egl: reopen DRM node for GBM
This will be necessary for the next patch, to avoid messing up BO
handles shared between the GL implementation and the DRM backend.
2021-08-25 10:05:37 -04:00
Simon Ser 3ce2ea9e16 Move allocator stuff into new directory
Add render/allocator/ and include/render/allocator/ to hold
everything allocator-related.
2021-08-25 09:57:20 -04:00
Simon Ser b37731cdbb backend/{drm,libinput}: exclude headers when disabled 2021-08-25 09:50:27 -04:00
Simon Ser 65c0ab00b6 backend/drm: generate CVT reduced modes
The Coordinated Video Timings (CVT) spec [1] defines two types of
timings: the "CVT standard CRT" timings and the "CVT reduced blanking"
timings (see section 3.6).

The standard CRT timings include pauses in the video stream to allow
CRT displays to reposition their electron beam at the end of each
horizontal scan line [2]. While this was desirable a few decades ago,
nowadays we can just generate a CVT reduced blanking timing by default.
wlroots users can still set full custom DRM modes via
wlr_drm_connector_add_mode.

[1]: https://glenwing.github.io/docs/VESA-CVT-1.2.pdf
[2]: https://en.wikipedia.org/wiki/Coordinated_Video_Timings#Reduced_blanking
2021-08-25 08:37:35 +02:00
Kirill Primak 72a156b18a surface: fix wlr_surface_get_buffer_source_box() 2021-08-24 10:36:06 +02:00
Kirill Primak 664307f968 util/box: introduce wlr_fbox_transform()
A floating-point version of wlr_box_transform().
2021-08-24 10:36:06 +02:00
Isaac Freund f2f3df9fb1 tinywl: simplify logic for sending pointer events 2021-08-20 16:32:28 +02:00
Guido Günther de1522aeee xwayland: Allow to retrieve _NET_STARTUP_ID
This is use for startup notifications per startup-notifiation spec

https://specifications.freedesktop.org/startup-notification-spec/startup-notification-latest.txt
2021-08-20 10:44:22 +02:00
Rouven Czerwinski 9b7803a9b3 backend/drm: try to allocate crtc for formats
To retrieve the formats, an allocated crtc is required. If there is no
currently no crtc available, try to allocate it. This reproducable by
having a disabled output and going through a suspend cycle with amdgpu.
On start CRTCs look like this:

  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1099] Reallocating CRTCs
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1110] State before reallocation:
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-1' crtc=0 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-2' crtc=1 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1167] State after reallocation:
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-1' crtc=0 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-2' crtc=1 state=1 desired_enabled=1
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:00:00.588 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0

where DP-1 is than disabled. After suspend/resume, allocation turns into:

  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1099] Reallocating CRTCs
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1110] State before reallocation:
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-1' crtc=-1 state=1 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DP-2' crtc=1 state=3 desired_enabled=1
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1116]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1167] State after reallocation:
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-1' crtc=-1 state=1 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DP-2' crtc=1 state=3 desired_enabled=1
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-1' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'HDMI-A-2' crtc=-1 state=0 desired_enabled=0
  00:30:22.680 [DEBUG] [wlr] [backend/drm/drm.c:1174]   'DVI-D-1' crtc=-1 state=0 desired_enabled=0

where the crtc for DP-1 is now NULL. Trying to enable the output results
in:

  10:43:36.906 [DEBUG] [sway/config/output.c:351] Turning on output DP-1
  10:43:36.906 [DEBUG] [sway/config/output.c:360] Set preferred mode
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [sway/config/output.c:366] Preferred mode rejected, falling back to another mode
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.906 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.906 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.906 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [DEBUG] [sway/config/output.c:400] Auto-detected output scale: 1.000000
  10:43:36.907 [DEBUG] [sway/config/output.c:430] Committing output DP-1
  10:43:36.907 [DEBUG] [wlr] [backend/drm/drm.c:464] connector DP-1: Can't enable an output without a buffer
  10:43:36.907 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
  10:43:36.907 [ERROR] [wlr] [types/wlr_output.c:512] Failed to get primary display formats
  10:43:36.907 [ERROR] [sway/config/output.c:435] Failed to commit output DP-1

where the primary format can't be queried since there is no crtc
allocated for the connector. Allocating the connector inside
drm_connector_get_primary_formats() fixes this issue. This is possible
since the only user of get_primary_formats() is the swapchain allocation
function, which is only called on output enable. Do the same thing for
the cursor formats in case the user queries them before the output is
enabled.
2021-08-20 10:24:30 +02:00
Simon Ser 18c2dce65e backend: unify startup messages 2021-08-19 20:47:36 +02:00
Simon Ser 46c42e55c6 backend/drm: add support for FB_DAMAGE_CLIPS
This allows the kernel to access our buffer damage. Some drivers
can take advantage of this, e.g. for PSR2 panels (Panel Self
Refresh) or for transfer over USB.

Closes: https://github.com/swaywm/wlroots/issues/1267
2021-08-18 20:59:25 +02:00
Kirill Primak 109405729b surface: fix place_below handling
If a subsurface is being placed below a subsurface right above it, this
should be a noop. However, `node` pointed to the subsurface that was
moved, which resulted in `subsurface->parent_pending_link` being
inserted into itself, breaking parent's pending subsurface list.

This commit separates finding the requested node and getting it's `prev`
field, fixing the issue.
2021-08-18 16:01:18 +02:00
Rouven Czerwinski cdd9a60f72 Revert "backend/drm: Check if output is enabled before sending frame event"
This reverts commit 85757665e6.

We now check if the output is enabled within wlr_output_send_frame, no
need to handle this explicitly in the DRM backend. This also fixes a
race which was introduced with this commit: if we schedule the flip,
disable and commit the output before the flip happens,
output.frame_pending will not be reset to false. We than always fail to
enable the output subsequently:

      00:07:13.276 [INFO] [sway/commands.c:257] Handling command 'output DP-2 enable'
      00:07:13.276 [DEBUG] [sway/commands.c:428] Subcommand: enable
      00:07:13.276 [DEBUG] [sway/config/output.c:204] Merging on top of existing output config
      00:07:13.276 [DEBUG] [sway/config/output.c:227] Config stored for output DP-2 (enabled: 1) (-1x-1@-1.000000Hz position 0,0 scale -1.000000 subpixel unknown transform -1) (bg /home/phoenix/Pictures/Wallpapers/mine/oper.jpg fill) (dpms 1) (max render time: -1)
      00:07:13.276 [DEBUG] [sway/config/output.c:351] Turning on output DP-2
      00:07:13.276 [DEBUG] [sway/config/output.c:360] Set preferred mode
      00:07:13.276 [DEBUG] [wlr] [backend/drm/drm.c:465] connector DP-2: Can't enable an output without a buffer
      00:07:13.276 [DEBUG] [wlr] [types/wlr_output.c:689] Attaching empty buffer to output for modeset
      00:07:13.277 [DEBUG] [sway/config/output.c:329] Output DPI: 162.560000x161.364706
      00:07:13.277 [DEBUG] [sway/config/output.c:400] Auto-detected output scale: 1.000000
      00:07:13.277 [DEBUG] [sway/config/output.c:430] Committing output DP-2
      00:07:13.277 [DEBUG] [wlr] [types/wlr_output.c:729] Tried to commit a buffer while a frame is pending

since the basic_output_test will always fail.
Reset frame_pending to false even if the output has been disabled in the
meantime.

Fixes https://github.com/swaywm/wlroots/issues/3109
2021-08-17 21:07:43 +02:00
Rouven Czerwinski aa78c50bf1 output: check output enabled before sending frame
Similar to commit 85757665e6 ("backend/drm: Check if output is enabled
before sending frame event"), check if the output is still enabled
before sending the frame event. This fixes the bug not only for the DRM
backend, but for wayland and X11 as well.
2021-08-17 21:07:43 +02:00
Rouven Czerwinski 59b292b691 backend/drm: return true on test if no crtc
This should fix the following backtrace, seen on my desktop with one
output disabled:

  #0  atomic_crtc_commit (conn=0x270f5c0, state=0x270f6d0, flags=0, test_only=<optimized out>) at ../backend/drm/atomic.c:178
          drm = 0x1ae9c10
          output = 0x270f5c0
          crtc = 0x0
          modeset = false
          active = false
          mode_id = 43989232
          gamma_lut = 0
          prev_vrr_enabled = <optimized out>
          vrr_enabled = <optimized out>
          atom = {req = 0x270f5c0, failed = 48}
          ok = <optimized out>
  #1  0x00007f1104f33128 in drm_crtc_commit (conn=conn@entry=0x270f5c0, state=state@entry=0x270f6d0, flags=flags@entry=0, test_only=test_only@entry=true) at ../backend/drm/drm.c:339
          __PRETTY_FUNCTION__ = "drm_crtc_commit"
          drm = <optimized out>
          crtc = 0x0
          ok = <optimized out>
  #2  0x00007f1104f34e6c in drm_connector_test (output=output@entry=0x270f5c0) at ../backend/drm/drm.c:488
          conn = 0x270f5c0
          unsupported = <optimized out>
  #3  0x00007f1104f35424 in drm_connector_commit (output=0x270f5c0) at ../backend/drm/drm.c:578
          conn = 0x270f5c0
  #4  0x00007f1104f600b7 in wlr_output_commit (output=output@entry=0x270f5c0) at ../types/wlr_output.c:837
          now = {tv_sec = 7732, tv_nsec = 623813006}
          pre_event = {output = 0x270f5c0, when = 0x7ffecc1be570}
          back_buffer = 0x0
          scale_updated = <optimized out>
          geometry_updated = <optimized out>
          committed = <optimized out>
          event = {output = 0x0, committed = 4401048, when = 0x29f38f0}
  #5  0x0000000000433047 in apply_output_config (oc=oc@entry=0x29f38f0, output=output@entry=0x2710720) at ../sway/config/output.c:431
          wlr_output = 0x270f5c0
          output_box = <optimized out>
  #6  0x0000000000433aaf in apply_output_config_to_outputs (oc=0x2308400) at ../sway/config/output.c:649
          current = 0x29f38f0
          name = <optimized out>
          wildcard = true
          id = "Dell Inc. DELL U2410 F525M9AK0MML\000\060\060\060ACD7\000\000\000\000\000\000\000\220\063\240\002\000\000\000\000L5C\000\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000\000\000\000\355\240E\000\000\000\000\000\377\377\377\377\000\000\000\000@\206+\002\000\000\000\000`\260.\002\000\000\000"
          sway_output = 0x2710720
          tmp = 0x2242030
          seat = <optimized out>
  #7  0x000000000043df6b in cmd_output (argc=<optimized out>, argv=0x2a03390) at ../sway/commands/output.c:108
          error = <optimized out>
          output = <optimized out>
          background = false
  #8  0x0000000000410304 in execute_command (_exec=_exec@entry=0x2975d20 "output * dpms off", seat=0x22a3280, seat@entry=0x0, con=con@entry=0x0) at ../sway/commands.c:291
          res = <optimized out>
          argc = 4
          argv = 0x2a03370
          handler = 0x479230 <handlers+560>
          cmd = <optimized out>
          matched_delim = 0 '\000'
          containers = 0x0
          using_criteria = false
          __PRETTY_FUNCTION__ = "execute_command"
          exec = 0x28f63c0 "output * dpms off"
          head = 0x0
          res_list = 0x2a2e9d0
  #9  0x0000000000418b65 in ipc_client_handle_command (client=client@entry=0x2a6ac80, payload_length=<optimized out>, payload_type=IPC_COMMAND) at ../sway/ipc-server.c:645
          line = <optimized out>
          res_list = <optimized out>
          json = <optimized out>
          length = <optimized out>
          __PRETTY_FUNCTION__ = "ipc_client_handle_command"
          buf = 0x2975d20 "output * dpms off"
  #10 0x000000000041964c in ipc_client_handle_readable (client_fd=<optimized out>, mask=<optimized out>, data=0x2a6ac80) at ../sway/ipc-server.c:267
          pending_length = <optimized out>
          pending_type = <optimized out>
          client = 0x2a6ac80
          read_available = 31
          buf = "i3-ipc\021\000\000\000\000\000\000"
          received = 14
  #11 0x00007f1104fc3492 in wl_event_loop_dispatch () from /nix/store/ridk7k2ka6dbk4ly7qqjgmc523s4fj89-wayland-1.19.0/lib/libwayland-server.so.0
  No symbol table info available.
  #12 0x00007f1104fc1135 in wl_display_run () from /nix/store/ridk7k2ka6dbk4ly7qqjgmc523s4fj89-wayland-1.19.0/lib/libwayland-server.so.0
  No symbol table info available.
  #13 0x000000000041ac10 in server_run (server=server@entry=0x47b0c0 <server>) at ../sway/server.c:261
  No locals.
  #14 0x000000000041a3fc in main (argc=<optimized out>, argv=0x7ffecc1bec68) at ../sway/main.c:395
          verbose = 0
          debug = 0
          validate = 0
          allow_unsupported_gpu = 0
          long_options = {{name = 0x45b516 "help", has_arg = 0, flag = 0x0, val = 104}, {name = 0x45ee69 "config", has_arg = 1, flag = 0x0, val = 99}, {name = 0x45b51b "validate", has_arg = 0, flag = 0x0, val = 67}, {
              name = 0x45b524 "debug", has_arg = 0, flag = 0x0, val = 100}, {name = 0x45b3ac "version", has_arg = 0, flag = 0x0, val = 118}, {name = 0x45a55c "verbose", has_arg = 0, flag = 0x0, val = 86}, {name = 0x45b52a "get-socketpath",
              has_arg = 0, flag = 0x0, val = 112}, {name = 0x45b539 "unsupported-gpu", has_arg = 0, flag = 0x0, val = 117}, {name = 0x45b549 "my-next-gpu-wont-be-nvidia", has_arg = 0, flag = 0x0, val = 117}, {name = 0x0, has_arg = 0,
              flag = 0x0, val = 0}}
          config_path = 0x0
          usage = 0x45b830 "Usage: sway [options] [command]\n\n  -h, --help", ' ' <repeats 13 times>, "Show help message and quit.\n  -c, --config <config>  Specify a config file.\n  -C, --validate         Check the validity of the config file, th"...
          c = <optimized out>

where the second output is not enabled:

  (gdb) frame 4
  #4  0x00007f1104f600b7 in wlr_output_commit (output=output@entry=0x270f5c0) at ../types/wlr_output.c:837
  837	in ../types/wlr_output.c
  (gdb) p output->enabled
  $3 = false
  (gdb)

The culprit being that since 604674dc54 we
always try to perform a commit, even on a disabled output.
2021-08-17 14:07:51 +02:00
Simon Ser 7544b7abf9 backend/drm: use addon for wlr_drm_fb 2021-08-17 11:08:45 +02:00
Michele Sorcinelli cae7b98136 xwayland: do not free cursor in handle_server_ready()
If XWayland terminates for any reason, xwm_set_cursor() has to
to be called again, so the cursor has to stick around.
2021-08-17 09:17:59 +02:00
Tudor Brindus 0c19a28266 input/tablet: fix `wl_array_for_each` usage on tablet proximity
Looks like this instance was missed in
e035f2b9c4.

Fixes #3110.
2021-08-15 23:26:51 +02:00
Isaac Freund 3364eec07e layer-shell: replace close() with destroy()
The protocol specifies that all requests (aside from destroy) are
ignored after the compositor sends the closed event. Therefore,
destroying the wlroots object and rendering the resource inert
when sending the closed event keeps things simpler for wlroots and
compositors.
2021-08-14 20:25:46 +02:00
Simon Ser ad7651a370 render/gles2: make wlr_gles2_texture a wlr_buffer addon 2021-08-12 10:22:19 +02:00
Simon Ser ee1156b62b render/gles2: make wlr_gles2_buffer an addon
Saves us from walking a list.
2021-08-12 10:22:19 +02:00
Simon Ser 93964012e6 buffer: add addon set
This allows wlr_buffer users to extend it with tjeir own state.
2021-08-12 10:22:19 +02:00
Simon Ser 20404ed8bb surface: drop surface_state_copy
This function was weird because it copied some fields but not all.
2021-08-11 18:13:12 +02:00
Simon Ser 3f9e4f7a44 surface: kill wlr_surface.previous
This wlr_surface_state field was a special case because we don't
want to save the whole current state: for instance, the wlr_buffer
must not be saved or else wouldn't get released soon enough.

Let's just inline the state fields we need instead.
2021-08-11 18:13:12 +02:00
Kirill Primak 111d4eafd7 util/addon: find both by owner and impl
This allows to have multiple addons of different types with the same
owner.
2021-08-11 18:12:57 +02:00
Kirill Primak debd6c5f0b wlr_output_layout: use wlr_addons 2021-08-10 19:15:48 +02:00
Kirill Primak 11f799e88e wlr_outputs: add wlr_addon_set 2021-08-10 19:15:48 +02:00
Kirill Primak a6a80850b7 util: add wlr_addon 2021-08-10 19:15:48 +02:00
Simon Ser 604674dc54 backend/drm: always perform a test commit in drm_connector_test
This allows callers to use wlr_output_test to check whether a mode
can be enabled, for instance.

Closes: https://github.com/swaywm/wlroots/issues/2250
2021-08-10 16:38:22 +02:00
Simon Ser eb0ce659cf backend/drm: add proper error handling to wlr_drm_backend_create
Some listeners weren't removed and caused a use-after-free with
e.g. vkms when used as a secondary GPU.
2021-08-10 15:42:36 +02:00
Simon Ser 88f65db87f ci: add smoke test
Add a very basic smoke test which uses VKMS to fire up the DRM
backend.
2021-08-08 22:13:33 +02:00
Tudor Brindus 033c9cab74 input/pointer: try harder to not send duplicate motion events
wl_fixed_t is a 32-bit data type, but our doubles are 64-bit. This meant
that two doubles that would map to the same wl_fixed_t could compare
unequal, and send a duplicate motion event.

Refs swaywm/sway#4632.
2021-08-07 09:04:12 +02:00
Simon Ser c27263c105 seat: allow compositors to not load a keymap
The protocol allows compositors to not send any keymap to Wayland
clients. Handle a keymap-less keyboard correctly by sending
WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP instead of erroring out in the
mmap call.
2021-08-06 23:06:29 +02:00
Simon Ser d48ffac56b build: remove "." from include dirs 2021-08-06 19:44:35 +02:00
Simon Ser ca0b19fc9c examples/fullscreen-shell: remove unused render_data.view field 2021-08-06 18:27:31 +02:00
Simon Ser 1936e136df backend/drm: require buffer on modeset in drm_connector_test
When testing a modeset, make sure the caller has also provided a
buffer. This allows df0e75ba05 ("output: try skipping buffer
allocation if the backend allows it") to work as expected with the
DRM backend.

Closes: https://github.com/swaywm/wlroots/issues/3086
2021-08-04 22:51:40 +02:00
Simon Ser df0e75ba05 output: try skipping buffer allocation if the backend allows it
When enabling an output, skip the empty buffer allocation if the
backend accepts modesets without a buffer.

This fixes mode-setting with the noop backend.
2021-08-04 10:18:59 -04:00
Simon Ser 8a3cd28973 render/pixman/pixel_format: add more formats
Add a bunch of new formats for Pixman: a few missing 32-bit ones,
some 16-bit and 32-bit formats as well.

Mostly based on a Weston patch [1].

[1]: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/664
2021-08-03 02:53:03 -04:00
Simon Ser b913e64f95 render/pixel_format: add more formats for Pixman
These will be added to Pixman in the next commit.
2021-08-03 02:53:03 -04:00
Simon Ser 923258b0be backend/drm: preserve mode order from kernel
The kernel orders the mode list from highest to lowest. Preserve
this ordering in the wlr_output.modes list.
2021-08-02 09:28:21 -04:00
Kirill Primak f12bacf4b4 surface: don't cache frame callback lists 2021-08-02 09:10:10 +02:00
Quantum 456c6e2279 viewporter: remove crop and scale state upon destruction
According to the viewport protocol, upon wp_viewport::destroy():

> The associated wl_surface's crop and scale state is removed.
> The change is applied on the next wl_surface.commit.

Therefore, wp_viewport_destroy(viewport) should remove all viewport state.

Currently, wlroots does not remove the crop and scale state. Instead, a
client must do:

    wl_fixed_t clear = wl_fixed_from_int(-1);
    wp_viewport_set_source(viewport, clear, clear, clear, clear);
    wp_viewport_set_destination(viewport, -1, -1);
    wp_viewport_destroy(viewport);

This commit adds the necessary logic into viewport_destroy and makes
wlroots comply with the protocol.
2021-08-02 09:08:03 +02:00
Manuel Stoeckl f5df956c18 render/gles2: add a few 10-bit and FP16 formats
The half-float formats depend on GL_OES_texture_half_float_linear,
not just the GL_OES_texture_half_float extension, because the latter
does not include support for linear magni/minification filters.

The new 2101010 and 16161616F formats are only available on little-
endian builds, since their gl_types are larger than a byte and thus
endianness dependent.
2021-07-30 08:29:13 +02:00
Manuel Stoeckl 44e8451cd9 render/gles2: hide shm formats without GL support
This change introduces a new function to check whether the renderer
has the needed GL extensions to read a given pixel format.
2021-07-30 08:29:13 +02:00
Manuel Stoeckl 4dc52bcb6c render/pixel-format: add a few 10-bit and FP16 formats 2021-07-30 08:29:13 +02:00
Simon Ser f76960388f render/gles2: add support for some 24 and 16-bit formats
On little-endian, we can enable pixel formats which don't use
gl_type = GL_UNSIGNED_BYTE. See [1].

[1]: https://afrantzis.com/pixel-format-guide/
2021-07-29 10:47:34 -04:00
Simon Ser 6973361d60 render/pixel-format: add some 24 and 16-bit formats 2021-07-29 10:47:34 -04:00
Simon Ser 3132c0ab10 output: drop wlr_output_state.buffer_type
This is now unconditionally set to WLR_OUTPUT_STATE_BUFFER_SCANOUT.
2021-07-29 09:48:33 -04:00
Simon Ser f211bc983a output-damage: stop using enum wlr_output_state_buffer_type
This enum will get dropped in the next commit.
2021-07-29 09:48:33 -04:00
Simon Ser 4ddde1a7bd output: drop wlr_output_impl.{attach,rollback}_render
No backend uses these anymore.
2021-07-29 09:48:33 -04:00
Simon Ser d17a009062 backend/noop: drop attach_render/rollback_render
We no longer require wlr_output_impl.{attach,rollback}_render to
be populated.
2021-07-29 09:48:33 -04:00
Simon Ser 55ac7e335a backend/drm: fix wrong type for get_cursor_format return values
These are bools but should be pointers.
2021-07-28 16:59:21 -04:00
Simon Ser c55f70c8b7 backend/drm: stop initializing renderer for parent backend
Unless we're dealing with a multi-GPU setup and the backend being
initialized is secondary, we don't need a renderer nor an allocator.
Stop initializing these.
2021-07-28 22:52:35 +02:00
Simon Ser c74dc45bb6 backend/drm: drop get_renderer implementation
We can now just rely on the common code for this.
2021-07-28 22:52:35 +02:00
Simon Ser 9b99570869 backend/drm: drop drm_surface_{make,unset}_current 2021-07-28 22:52:35 +02:00
Simon Ser ebb661532c backend/drm: remove SCANOUT check in drm_connector_test
We only accept SCANOUT, the buffer type should never be set to RENDER.
2021-07-28 22:52:35 +02:00
Simon Ser f5900c1f00 backend/drm: remove primary swapchain
We can't nuke it completely, we still need it for multi-GPU.
2021-07-28 22:52:35 +02:00
Simon Ser 85d7ad2eef backend/drm: allow legacy scan-out if FB props match
Historically we haven't allowed direct scan-out for legacy KMS,
because legacy misses the functionality to make sure a buffer can
be scanned out. However with renderer v6 the backend can't figure
out anymore whether the buffer comes from its internal swap-chain,
because the backend doesn't have an internal swap-chain.

The legacy KMS API guarantees that the driver won't reject a buffer
as long as it's been allocated with the same parameters as the
previous one. Let's check this in legacy_crtc_test.
2021-07-28 22:52:35 +02:00
Simon Ser 6aadf811aa output: fallback to modifier-less allocation on modeset test failure
Sometimes we allocate a buffer with modifiers but then fail to
perform a modeset with it. This can happen on Intel because of
bandwidth limitations. To mitigate this issue, it's possible to
re-allocate the buffer with modifiers.

Add the logic to do so in wlr_output.
2021-07-28 22:52:35 +02:00
Simon Ser 0fb55c76d0 output: allocate and attach empty buffer on modeset
Some backends need a buffer in order to be able to perform a
modeset.
2021-07-28 22:52:35 +02:00
Simon Ser 1a5b6722a8 output: use pending resolution when allocating swapchain
This allows the swapchain to be created with the correct resolution
during a mode change.
2021-07-28 22:52:35 +02:00
Simon Ser d6f0fc251e backend/drm: implement get_primary_formats 2021-07-28 22:52:35 +02:00
Simon Ser d1c931cbe8 output: fallback to XRGB in output_pick_format
This will be necessary for the primary buffer.
2021-07-28 22:52:35 +02:00
Dylan Araps e5063ef3a3 util/time: make NSEC_PER_SEC static
This fixes static linking with libseat.

Closes #3072
2021-07-28 09:01:59 +02:00
Simon Zeni 6f19295647 render/egl: initialize wlr_egl with EGL_PLATFORM_DEVICE_EXT
Uses the EXT_device_query extension to get the EGL device matching the
requested DRM file descriptor. If the extension is not supported or no device
is found, the EGL device will be retrieved using GBM.

Depends on the EGL_EXT_device_enumeration to get the list of EGL devices.
2021-07-27 20:45:53 +02:00
yuiiio 7667ab73bd
render/egl: fix typo 2021-07-27 00:35:36 +02:00
Simon Ser 770a561bce xwayland: embed wlr_xwayland_server_options in server struct
As more options are added, more fields will be duplicated. Let's
just embed the struct in wlr_xwayland_server so that we don't need
to keep both in sync.
2021-07-27 00:18:11 +02:00
Simon Ser 4b316a3823 xwayland: simplify argv filling logic
Remove fill_arg and replace it with stack-allocations and simple
array-filling.
2021-07-27 00:18:11 +02:00
Simon Ser 3cf2535c23 render/egl: add support for EGL_EXT_device_drm_render_node
This EGL extension has been added in [1]. The upsides are:

- We directly get a render node, instead of having to convert the
  primary node name to a render node name.
- If EGL_DRM_RENDER_NODE_FILE_EXT returns NULL, that means there is
  no render node being used by the driver.

[1]: https://github.com/KhronosGroup/EGL-Registry/pull/127
2021-07-26 11:44:16 -04:00
Simon Ser ace2eda073 render/egl: set EGL_IMAGE_PRESERVED_KHR
Without setting this the EGL implementation is allowed to perform
destructive actions on the buffer when imported: its contents
become undefined.

This is mostly a pedantic change, because Mesa processes the attrib
and does absolutely nothing with it.
2021-07-23 11:27:17 -04:00
Simon Zeni 04d4fb536d render/wlr_texture: put wlr_texture_from_buffer into the public API 2021-07-22 22:28:24 +02:00
Simon Zeni 0778151f94 types/wlr_buffer: create custom wlr_buffer from wl_resource 2021-07-22 22:28:24 +02:00
Simon Zeni 646a25667e types/wlr_buffer: introduce wlr_buffer_resource_interface
Adds `wlr_buffer_resource_interface` and `wlr_buffer_register_resource_interface`,
which allows a user to register a way to create a wlr_buffer from a specific
wl_resource.
2021-07-22 22:28:24 +02:00
Simon Zeni f09c88c1b7 types/wlr_buffer: remove wlr_renderer argument from wlr_buffer_from_resource 2021-07-22 22:28:24 +02:00
Simon Ser 2fa47c1837 render: drop wlr_renderer_impl.init_wl_display
Now that we have our own wl_drm implementation, there's no reason
to provide custom renderer hooks to init a wl_display in the
interface. We can just initialize the wl_display generically,
depending on the renderer capabilities.
2021-07-22 14:10:26 -04:00
ayaka 70fb21c35b backend: make DRM and libinput backends optional
Co-authored-by: Simon Ser <contact@emersion.fr>
2021-07-22 09:56:38 -04:00
Simon Ser 66c42f4fcb backend/drm: add DRM_MODE_CONNECTOR_USB to conn_get_name
See 757e26712337 ("drm/uapi: Add USB connector type") in the kernel
tree.
2021-07-21 08:47:35 +02:00
Simon Ser cc8bc0db20 backend/drm: stop restoring CRTCs on exit
This is the cause of the spurious "drmHandleEvent failed" messages
at exit. restore_drm_outputs calls handle_drm_event in a loop without
checking whether the FD is readable, so drmHandleEvent ends up with a
short read (0 bytes) and returns an error.

The loop's goal is to wait for all queued page-flip events to complete,
to allow drmModeSetCrtc calls to succeed without EBUSY. The
drmModeSetCrtc calls are supposed to restore whatever KMS state we were
started with. But it's not clear from my PoV that restoring the KMS
state on exit is desirable.

KMS clients are supposed to save and restore the (full) KMS state on VT
switch, but not on exit. Leaving our KMS state on exit avoids unnecessary
modesets and allows flicker-free transitions between clients. See [1]
for more details, and note that with Pekka we've concluded that a new
flag to reset some KMS props to their default value on compositor
start-up is the best way forward. As a side note, Weston doesn't restore
the CRTC by does disable the cursor plane on exit (see
drm_output_deinit_planes, I still think disabling the cursor plane
shouldn't be necessary on exit).

Additionally, restore_drm_outputs only a subset of the KMS state.
Gamma and other atomic properties aren't accounted for. If the previous
KMS client had some outputs disabled, restore_drm_outputs would restore
a garbage mode.

[1]: https://blog.ffwll.ch/2016/01/vt-switching-with-atomic-modeset.html
2021-07-20 15:33:26 +02:00
Simon Ser 8afb4d8bf0 buffer: re-use wlr_shm_client_buffer
The first time wlr_buffer_from_resource is called with a wl_buffer
resource that originates from wl_shm, create a new
wlr_shm_client_buffer as usual. If wlr_buffer_from_resource is called
multiple times, re-use the existing wlr_shm_client_buffer.

This commit changes how the wlr_shm_client_buffer lifetime is managed:
previously it was destroyed as soon as the wlr_buffer was released.
With this commit it's destroyed when the wl_buffer resource is.

Apart from de-duplicating wlr_shm_client_buffer creations, this allows
to easily track when a wlr_shm_client_buffer is re-used. This is useful
for the renderer and the backends, e.g. the Pixman renderer can keep
using the same Pixman image if the buffer is re-used. In the future,
this will also allow to re-use resources in the Wayland and X11 backends
(remote wl_buffer objects for Wayland, pixmaps for X11).
2021-07-19 13:13:10 -04:00
Simon Ser f94eb174c7 backend/drm: fix NULL data in handle_drm_event
wl_event_loop_add_fd was called with a NULL data argument, but the
function expects the data argument to be set to the wlr_drm_backend.

Fixes: 053ebe7c27 ("backend/drm: terminate display on drmHandleEvent failure")
2021-07-19 09:01:21 -04:00
Vyivel a93b18dbd5 input/pointer: send axis source once per frame
Only one wl_pointer.axis_source event is permitted per frame, according
to the Wayland specification.

Fixes https://github.com/swaywm/wlroots/issues/2973
2021-07-19 12:00:31 +02:00
Simon Ser a47f89cf7c backend/wayland: properly cleanup wlr_wl_pointer
We were missing destroy calls for gestures, and we were only
destroying the relative pointer on output destroy.
2021-07-13 09:20:25 -04:00
Simon Ser bcd5d8504c output: remove wlr_output_impl.export_dmabuf
No backend is using it anymore.
2021-07-12 13:29:03 -04:00
Simon Ser 709190c4c8 backend/drm: remove wlr_output_impl.export_dmabuf
This is now provided by the generic wlr_output implementation.
2021-07-12 13:29:03 -04:00
Simon Ser aec062d0d3 backend/headless: remove wlr_output_impl.export_dmabuf
This is now provided by the generic wlr_output implementation.
2021-07-12 13:29:03 -04:00
Simon Ser 87e8c60faf output: add generic wlr_output_export_dmabuf implementation
When wlr_output manages its own swap-chain, there's no need to
hook into the backend to grab DMA-BUFs. Instead, maintain a
wlr_output.front_buffer field with the latest committed buffer.
2021-07-12 13:29:03 -04:00
Simon Ser 28aa803916 buffer: drop resource arg from wlr_client_buffer_create
This function doesn't need the wl_resource anymore.

In the failure paths, wlr_buffer_unlock in surface_apply_damage
will take care of sending wl_buffer.release.
2021-07-12 09:19:18 -04:00
Simon Ser 5544973814 render/gles2: disable blending opportunistically
We don't always need to enable blending: when the texture doesn't
have alpha or when the color is opaque, we can disable it.
2021-07-12 09:16:09 -04:00
Simon Ser 9dba176e8d render/gles2: set has_alpha for DMA-BUFs
Use our internal pixel format table to figure out whether an
imported DMA-BUF has alpha.
2021-07-12 09:16:09 -04:00
Simon Ser 9b70eab194 render/gles2: rename wlr_egl.exts to better match Khronos
Khronos refers to extensions with their namespace as a prefix in
uppercase. Change our naming to align with Khronos conventions.
This also makes grepping easier.
2021-07-12 09:13:49 -04:00
Simon Ser 4c51a0f6eb render/egl: rename wlr_egl.exts to better match Khronos
Khronos refers to extensions with their namespace as a prefix in
uppercase. Change our naming to align with Khronos conventions.
This also makes grepping easier.
2021-07-12 09:13:49 -04:00
Simon Ser 4554f17377 buffer: drop wlr_client_buffer.resource 2021-07-09 17:25:02 -04:00
Simon Ser d7c68ce632 buffer: stop using resource in client_buffer_get_dmabuf
Instead, delegate to the source wlr_buffer.
2021-07-09 17:25:02 -04:00
Simon Ser a0baba4fa0 buffer: add wlr_client_buffer.source
This stores a weak reference to the source buffer.
2021-07-09 17:25:02 -04:00
Simon Ser 0abb67c478 buffer: stop using source resource in wlr_client_buffer_apply_damage
This is the first step towards dropping wlr_client_buffer.resource.
2021-07-09 17:25:02 -04:00
Simon Ser 7b25b0ff88 buffer: rename wlr_client_buffer variables to client_buffer
We often juggle between wlr_buffer and wlr_client_buffer variables.
Use a consistent naming: "buffer" for wlr_buffer and "client_buffer"
for wlr_client_buffer.
2021-07-09 17:25:02 -04:00
Simon Zeni 60f4d8f409 types/wlr_buffer: remove wlr_resource_get_buffer_size 2021-07-09 23:16:39 +02:00
Simon Zeni d086501fba types/wlr_surface: get buffer size from wlr_buffer_import 2021-07-09 23:16:39 +02:00
Simon Zeni 6d8029b07e types/wlr_buffer: split wlr_client_buffer_import function
`wlr_client_buffer_import` is splitted in two distincts function:
	- wlr_buffer_from_resource, which transforms a wl_resource into
	  a wlr_buffer
	- wlr_client_buffer_create, which creates a wlr_client_buffer
	  from a wlr_buffer by creating a texture from it and copying its
	  wl_resource
2021-07-09 23:16:39 +02:00
Simon Ser f67cfb2ce2 backend/drm: remove backend arg from wlr_drm_interface.crtc_commit
The callee can just get it from the wlr_drm_connector.
2021-07-09 15:31:19 -04:00
Simon Ser fde56c20b4 backend/drm: move legacy-specific checks to legacy.c
Now that we have a test_only arg in crtc_commit, we can move the
legacy checks to legacy.c.
2021-07-09 15:31:19 -04:00
Simon Ser 017555651b backend/drm: add test_only arg to wlr_drm_interface.crtc_commit
Right now callers of drm_crtc_commit need to check whether the
interface is legacy or atomic before passing the TEST_ONLY flag.
Additionally, the fallbacks for legacy are in-place in the common
code.

Add a test_only arg to the crtc_commit hook. This way, there's no
risk to pass atomic-only flags to the legacy function (add an assert
to ensure this) and all of the legacy-specific logic can be put back
into legacy.c (done in next commit).
2021-07-09 15:31:19 -04:00
Vyivel a362d21d6b render/pixman: fix texture_is_opaque()
A texture is opaque when it does *not* have alpha.

Fixes https://github.com/swaywm/wlroots/issues/2907
2021-07-09 08:23:45 +02:00
Simon Ser c1b27cc499 backend/drm: stop using drm_surface_make_current in drm_surface_blit
drm_surface_make_current and drm_surface_unset_current set implicit
state and are an unnecessary mid-layer. Prefer to use directly
wlr_renderer_begin_with_buffer, which automatically unsets the back
buffer on wlr_renderer_end.

I'd like to get rid of drm_surface_make_current once we stop using
it for the primary swapchain.
2021-07-08 14:44:42 -04:00
Simon Ser d71ed635b9 backend/drm: force linear layout for multi-GPU buffers
Some buffers need to be copied across GPUs. Such buffers need to be
allocated with a format and modifier suitable for both the source
and the destination.

When explicit modifiers aren't supported, we were forcing the buffers
to be allocated with a linear layout, because implicit modifiers
aren't portable across GPUs. All is well with this case.

When explicit modifiers are supported, we were advertising the whole
list of destination modifiers, in the hope that the source might
have some in common and might be able to allocate a buffer with a
more optimized layout. This works well if the source supports explicit
modifiers. However, if the source doesn't, then wlr_drm_format_intersect
will fallback to implicit modifiers, and everything goes boom: the
source uses a GPU-specific tiling and the destination interprets it
as linear.

To avoid this, just force linear unconditionally. We'll be able to
revert this once we have a good way to indicate that an implicit modifier
isn't supported in wlr_drm_format_set, see [1].

[1]: https://github.com/swaywm/wlroots/pull/2815

Closes: https://github.com/swaywm/wlroots/issues/3030
2021-07-08 17:06:20 +02:00
Simon Ser e035f2b9c4 Fix invalid uses of wl_array_for_each
[1] and [2] have introduced new wl_array usage in wlroots, but
contains a mistake: wl_array_for_each iterates over pointers to
the wl_array entries, not over entries themselves.

Fix all wl_array_for_each call sites. Name the variables "ptr"
to avoid confusion.

Found via ASan:

    ==148752==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x602000214111 in thread T0
        #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
        #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24
        #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51
        #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306
        #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57
        #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57
        #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124
        #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e)
        #8 0x55cd1a77c9e5 in server_fini ../sway/server.c:218
        #9 0x55cd1a77893f in main ../sway/main.c:400
        #10 0x7f6ff04bdb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
        #11 0x55cd1a73a7ad in _start (/home/simon/src/sway/build/sway/sway+0x33a7ad)

    0x602000214111 is located 1 bytes inside of 16-byte region [0x602000214110,0x602000214120)
    freed by thread T0 here:
        #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
        #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24
        #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51
        #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306
        #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57
        #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57
        #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124
        #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e)

    previously allocated by thread T0 here:
        #0 0x7f6ff2236279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
        #1 0x7f6ff1066d03 in wl_array_add (/usr/lib/libwayland-server.so.0+0xdd03)

[1]: https://github.com/swaywm/wlroots/pull/3002
[2]: https://github.com/swaywm/wlroots/pull/3004
2021-07-08 10:08:47 -04:00
Simon Ser b934fbaf04 seat: add wlr_seat_touch_{send,notify}_frame
The wl_touch.frame event is used to group multiple touch events
together. Instead of sending it immediately after each touch event,
rely on the backend to send it (and on the compositor to relay it).

This is a breaking change because compositors now need to manually
send touch frame events instead of relying on wlr_seat to do it.
2021-07-08 09:12:17 +02:00
Simon Ser 22fd411bc3 cursor: add touch frame event 2021-07-08 09:12:17 +02:00
Simon Ser c1902cdb3f backend/x11: send touch frame events 2021-07-08 09:12:17 +02:00
Simon Ser 8eef6a8843 backend/wayland: send touch frame events 2021-07-08 09:12:17 +02:00
Simon Ser 2d36d7fb67 backend/libinput: send touch frame events 2021-07-08 09:12:17 +02:00
Simon Ser 84906a832f touch: add frame event 2021-07-08 09:12:17 +02:00
Simon Ser a48e569d38 output-damage: fix output swapchain handling
When wlr_output.swapchain is used instead of the backend's, the
buffer_type will be set to SCANOUT even if wlr_output_attach_render
has been called. This tricks wlr_output_damage into thinking the
whole output needs to be repainted.

Workaround this issue by forcing buffer_type to RENDER when the
output has a back-buffer set.

Will clean all of that up when removing the precommit event handler
altogether.

This commit fixes damage tracking on the Wayland, X11 and headless
backends.
2021-07-07 12:02:24 -04:00
Simon Ser c2bd63c186 output: detach buffer from renderer before commit
Right now we rely entirely on implicit sync for synchronizing
access to GPU buffers. Implicit sync works by setting
synchronization points on the buffer in writers, and letting
readers wait on these sync points before accessing the buffer.

With OpenGL, sync points are created using functions such as
eglSwapBuffers or glFlush. If none of these special functions
are called, no sync point will be created and readers will
potentially access a buffer that hasn't finished rendering yet.

In the context of wlroots, OpenGL is the writer and the backend
(KMS or parent Wayland/X11 session) is the reader. After we're
done rendering a frame, and before passing that frame to the
backend, we need to call glFlush.

glFlush is called when the buffer is detached from the renderer.
This is a task done by output_clear_back_buffer. So let's call
this function before invoking the impl->commit hook, instead of
calling it after.

All of this is maybe a little tricky to get right with the
current renderer_bind_buffer API. The new
wlr_renderer_begin_with_buffer API is much better, because glFlush
is called on wlr_renderer_end, so it's more intuitive.

Closes: https://github.com/swaywm/wlroots/issues/3020
2021-07-07 12:00:43 -04:00
Simon Zeni 4c7657ee62 util/box: stabilize interface 2021-07-06 21:43:17 +02:00
Simon Zeni e192d87731 move wlr_box from /types to /util 2021-07-06 21:43:17 +02:00
Simon Zeni d975f35bba types/wlr_box: remove unused wlr_box_from_pixman_box32 and wlr_box_rotated_bounds functions 2021-07-06 21:43:17 +02:00
Simon Ser 3fdf8cf07e buffer: unify texture creation in wlr_client_buffer_import
All code-paths now invoke wlr_texture_from_buffer. De-duplicate
the calls.
2021-07-05 11:13:41 -04:00
Simon Ser 9a8097682b buffer: stop sending wl_buffer.release events from wlr_client_buffer
The specialized client buffer implementations take care of this.
2021-07-05 11:13:41 -04:00
Simon Ser d3d1c69aca buffer: remove renderer param from wlr_resource_get_buffer_size
The only reason we had this was because of EGL_WL_bind_wayland_display
support, which has been dropped.
2021-07-05 11:13:41 -04:00
Simon Ser 8a4957570f render/egl: remove EGL_WL_bind_wayland_display support
Our GLES2 renderer doesn't use it anymore, so we can drop it.
2021-07-05 11:13:41 -04:00
Simon Ser e5b5592a95 render: remove wl_drm support from wlr_renderer
Everything needs to go through the unified wlr_buffer interface
now.

If necessary, there are two ways support for
EGL_WL_bind_wayland_display could be restored by compositors:

- Either by using GBM to convert back EGL Wayland buffers to
  DMA-BUFs, then wrap the DMA-BUF into a wlr_buffer.
- Or by wrapping the EGL Wayland buffer into a special wlr_buffer
  that doesn't implement any wlr_buffer_impl hook, and special-case
  that buffer type in the renderer.
2021-07-05 11:13:41 -04:00
Simon Ser 4e07d4cbf9 render/gles2: use wlr_drm for wl_drm implementation
This allows use to remove all of our special wl_drm support code.
2021-07-05 11:13:41 -04:00
Simon Ser d7b19fb294 buffer: handle wl_drm buffers
This allows renderers to choose between implementing the old
wlr_renderer_impl.texture_from_wl_drm hook, or opt for the new
wlr_drm stub. The stub has the advantage of not requiring any
special support code: stubbed wl_drm buffers look exactly like
DMA-BUFs from linux-dmabuf-unstable-v1.
2021-07-05 11:13:41 -04:00
Simon Ser c868e509b7 drm: add support for DMA-BUFs
Mesa's Vulkan WSI still uses wl_drm when modifiers aren't supported.
This has been fixed in [1] but will take some time to be propagated
to users. In the meantime, add a fallback.

[1]: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4942
2021-07-05 11:13:41 -04:00
Simon Ser f7e3d325fe Add a stub wl_drm implementation
This will allow us to remove all of our EGL wl_drm support code
and remove some weird stuff we need just for wl_drm support. In
particular, wl_drm buffers coming from the EGL implementation
can't easily be wrapped into a wlr_buffer properly.
2021-07-05 11:13:41 -04:00
Simon Ser 78121ad2d8 xcursor: improve documentation 2021-07-05 11:00:15 -04:00
Simon Ser 4dee7a2f6f backend/drm: don't clear pending cursor FB on failed commit
The previous fix tried to side-step cursor->pending_fb completely.
However that messes up our buffer locking mechanism.

Instead, stop clearing the pending cursor FB on a failed commit. The
pending cursor FB will remain for the next commit.

Fixes: 6c3d080e25 ("backend/drm: populate cursor plane's current_fb")
2021-07-05 10:55:41 -04:00
Simon Ser 5f26360bd8 Revert "backend/drm: populate cursor plane's current_fb"
This reverts commit 6c3d080e25.

Populating wlr_drm_plane.current_fb messes up the buffer's locking.
The previous buffer is released while it's still being displayed
on-screen.
2021-07-05 10:55:41 -04:00
Simon Ser e8c408b31b region: drop leftover reference to the mailing list
As per [1], the mailing list isn't used anymore.

[1]: https://github.com/swaywm/wlroots/pull/3016

Fixes: 82af6e7208 ("region: stabilize interface")
2021-07-05 10:32:50 -04:00
Simon Ser 82af6e7208 region: stabilize interface
References: https://github.com/swaywm/wlroots/issues/1008
2021-07-05 09:25:25 -04:00
Simon Ser 475d9701e2 Remove reference to the announce mailing list
The mailing list has never been used.

I think listing the deprecated functions in the release notes is
enough. I'd rather not add the burden of maintaining a separate
communication medium.
2021-07-05 09:24:24 -04:00
Simon Ser c7018a45b7 surface: allow locking pending state in commit handler
We were bumping the pending sequence number after emitting the
commit event, so commit handlers were seeing inconsistent state
where current.seq == pending.seq. This prevents commit handlers
from immediately locking the pending state.

Fix this by bumping the pending sequence number before firing the
commit event.
2021-07-05 10:20:19 +02:00
Simon Ser 0a522cb798 backend/libinput: use wl_array for wlr_libinput_tablet.tools
Instead of using a single-field wl_list, let's just use a wl_array.
2021-07-05 10:05:06 +02:00
Simon Ser a38baec1f8 buffer: make enum wlr_buffer_cap public
Custom backends and renderers need to implement
wlr_backend_impl.get_buffer_caps and
wlr_renderer_impl.get_render_buffer_caps. They can't if enum
wlr_buffer_cap isn't made public.
2021-07-01 16:40:19 -04:00
Simon Ser 29be2d47e4 render: drop wlr_renderer_impl.texture_from_dmabuf 2021-07-01 14:57:52 -04:00
Simon Ser 7ad44051a2 render: use wlr_dmabuf_buffer in wlr_texture_from_dmabuf 2021-07-01 14:57:52 -04:00
Simon Ser 08e5b909f9 buffer: add wlr_dmabuf_buffer 2021-07-01 14:57:52 -04:00
Simon Ser 18adb43a44 render: drop wlr_renderer_impl.texture_from_pixels 2021-07-01 14:57:52 -04:00
Simon Ser 29c8df7e0a render: use wlr_readonly_data_buffer in wlr_texture_from_pixels 2021-07-01 14:57:52 -04:00
Simon Ser 7ec66a9990 buffer: introduce wlr_readonly_data_buffer 2021-07-01 14:57:52 -04:00
Simon Ser ea585dba0f tablet-v2: fix pad and tool object versions
These were hardcoded to 1. Instead, create the resource with the
version of the parent object.
2021-07-01 10:52:58 -04:00
Simon Ser 57b70a478c Drop wlr_list 2021-07-01 10:35:39 -04:00
Simon Ser 5888c96da8 tablet: stop using wlr_list 2021-07-01 10:35:39 -04:00
Simon Ser e6cb11d882 backend/libinput: stop using wlr_list internally 2021-07-01 10:35:39 -04:00
Simon Ser a6ed4ae308 util/array: add array_remove_at 2021-07-01 10:35:39 -04:00
Simon Ser dbb0e2f75b Remove unused wlr_list.h includes 2021-07-01 10:35:39 -04:00
Simon Ser 1db976cecb render/egl: replace wlr_egl_create with wlr_egl_create_with_drm_fd
We never create an EGL context with the platform set to something
other than EGL_PLATFORM_GBM_KHR. Let's simplify wlr_egl_create by
taking a DRM FD instead of a (platform, remote_display) tuple.

This hides the internal details of creating an EGL context for a
specific device. This will allow us to transparently use the device
platform [1] when the time comes.

[1]: https://github.com/swaywm/wlroots/pull/2671
2021-06-30 14:02:26 -04:00
Simon Ser 1c4b5bcab3 surface: accept commits with buffer size not divisible by scale
There are still many situations where the buffer scale is not
divisible by scale. The fix will require a tad more work, so
let's just log the client error for now and continue handling
the surface commit as usual.

Closes: https://github.com/swaywm/sway/issues/6352
2021-06-30 13:27:42 -04:00
Simon Ser 1b4fb4b537 touch: document event data types 2021-06-30 11:24:08 +02:00
Simon Ser bcbdee43f7 pointer: document event data types 2021-06-30 11:23:50 +02:00
Simon Ser 7cbcc65ad0 surface: make wlr_subsurface_create private
Same as [1], but for wlr_subsurface.

[1]: https://github.com/swaywm/wlroots/pull/2814
2021-06-29 10:32:17 -04:00
Simon Ser ddc98bf593 surface: remove SURFACE_VERSION
surface_create is now private, so no need to worry about the version
being too high anymore.
2021-06-29 13:34:30 +02:00
Simon Ser 634a20d89c Drop WLR_VERSION_API_*
These weren't set in the build, thus Meson was just dropping them
in the generated file.
2021-06-29 12:22:55 +02:00
Simon Ser f6ae028e99 ci: make Meson warnings fatal
New warnings can be hard to notice in CI, since CI will just pass in
that case. Meson sometimes uses warnings for important mistakes, e.g.
invalid option.

Let's turn warnings into errors so that we can spot these more easily.
2021-06-25 10:01:25 -04:00
Simon Ser 787842c459 ci: remove -Dlibseat from Alpine build
This build option doesn't exist anymore.
2021-06-25 10:01:25 -04:00
Simon Ser 31db232704 build: use meson.global_build_root()
meson.build_root() is deprecated.

References: https://github.com/mesonbuild/meson/pull/8629
2021-06-25 10:01:25 -04:00
Simon Ser d2b6b570ea xwayland: improve startup log message
Logging the raw Xwayland command-line was incomplete, uninformative
and confusing for end-users. Instead, print a proper message in
English.
2021-06-25 10:54:10 +02:00
Simon Ser a2419eb4ea render/egl: make most functions private
The wlr_egl functions are mostly used internally by the GLES2
renderer. Let's reduce our API surface a bit by hiding them. If
there are good use-cases for one of these, we can always make them
public again.

The functions mutating the current EGL context are not made private
because e.g. Wayfire uses them.
2021-06-24 13:53:05 -04:00
Simon Ser b69db15da6 render/egl: remove stale wlr_egl_export_image_to_dmabuf decl
This function has been removed, but we forgot to drop it from the
header.
2021-06-24 11:57:14 +02:00
Simon Ser 264d4e2bce backend/drm: rename page_flip_handler to handle_page_flip
This is more consistent with the rest of the wlroots naming.
2021-06-24 11:56:45 +02:00
Simon Ser 0467a7523a build: bump version to 0.15.0 2021-06-23 14:30:57 +02:00
245 changed files with 15591 additions and 6058 deletions

View File

@ -2,11 +2,14 @@ image: alpine/edge
packages:
- eudev-dev
- ffmpeg-dev
- glslang
- libinput-dev
- libxkbcommon-dev
- mesa-dev
- meson
- pixman-dev
- vulkan-headers
- vulkan-loader-dev
- wayland-dev
- wayland-protocols
- xcb-util-image-dev
@ -15,11 +18,11 @@ packages:
- xwayland
- libseat-dev
sources:
- https://github.com/swaywm/wlroots
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- setup: |
cd wlroots
meson build --default-library=both -Dauto_features=enabled -Dlibseat=disabled -Dxcb-errors=disabled
meson build --fatal-meson-warnings --default-library=both -Dauto_features=enabled -Dxcb-errors=disabled
- build: |
cd wlroots
ninja -C build

View File

@ -15,19 +15,31 @@ packages:
- xcb-util-wm
- xorg-xwayland
- seatd
- vulkan-icd-loader
- vulkan-headers
- glslang
sources:
- https://github.com/swaywm/wlroots
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- setup: |
cd wlroots
CC=gcc meson build-gcc --default-library=both -Dauto_features=enabled --prefix /usr
CC=clang meson build-clang -Dauto_features=enabled
CC=gcc meson build-gcc --fatal-meson-warnings --default-library=both -Dauto_features=enabled --prefix /usr -Db_sanitize=address,undefined
CC=clang meson build-clang --fatal-meson-warnings -Dauto_features=enabled
- gcc: |
cd wlroots/build-gcc
ninja
sudo ninja install
cd ../tinywl
make
CFLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" make
- clang: |
cd wlroots/build-clang
ninja
- smoke-test: |
cd wlroots/tinywl
sudo modprobe vkms
udevadm settle
export WLR_BACKENDS=drm
export WLR_RENDERER=pixman
export WLR_DRM_DEVICES=/dev/dri/by-path/platform-vkms-card
sudo chmod ugo+rw /dev/dri/by-path/platform-vkms-card
sudo -E seatd-launch -- ./tinywl -s 'kill $PPID' || [ $? = 143 ]

View File

@ -5,9 +5,12 @@ packages:
- devel/libudev-devd
- devel/meson # implies ninja
- devel/pkgconf
- graphics/glslang
- graphics/libdrm
- graphics/mesa-libs
- graphics/png
- graphics/vulkan-headers
- graphics/vulkan-loader
- graphics/wayland
- graphics/wayland-protocols
- multimedia/ffmpeg
@ -23,11 +26,11 @@ packages:
- sysutils/seatd
- gmake
sources:
- https://github.com/swaywm/wlroots
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- wlroots: |
cd wlroots
meson build -Dauto_features=enabled
meson build --fatal-meson-warnings -Dauto_features=enabled
ninja -C build
sudo ninja -C build install
- tinywl: |

7
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,7 @@
include: https://git.sr.ht/~emersion/dalligi/blob/master/templates/multi.yml
alpine:
extends: .dalligi
archlinux:
extends: .dalligi
freebsd:
extends: .dalligi

View File

@ -1,22 +1,21 @@
# Contributing to wlroots
Contributing just involves sending a pull request. You will probably be more
successful with your contribution if you visit
[#sway-devel on Libera Chat](https://web.libera.chat/?channels=#sway-devel) upfront and
discuss your plans.
Contributing just involves sending a merge request. You will probably be more
successful with your contribution if you visit [#sway-devel on Libera Chat]
upfront and discuss your plans.
Note: rules are made to be broken. Adjust or ignore any/all of these as you see
fit, but be prepared to justify it to your peers.
## Pull Requests
## Merge Requests
If you already have your own pull request habits, feel free to use them. If you
If you already have your own merge request habits, feel free to use them. If you
don't, however, allow me to make a suggestion: feature branches pulled from
upstream. Try this:
1. Fork wlroots
2. `git clone https://github.com/username/wlroots && cd wlroots`
3. `git remote add upstream https://github.com/swaywm/wlroots`
2. `git clone git@gitlab.freedesktop.org:<username>/wlroots.git && cd wlroots`
3. `git remote add upstream https://gitlab.freedesktop.org/wlroots/wlroots.git`
You only need to do this once. You're never going to use your fork's master
branch. Instead, when you start working on a feature, do this:
@ -25,42 +24,74 @@ branch. Instead, when you start working on a feature, do this:
2. `git checkout -b add-so-and-so-feature upstream/master`
3. Add and commit your changes
4. `git push -u origin add-so-and-so-feature`
5. Make a pull request from your feature branch
5. Make a merge request from your feature branch
When you submit your pull request, your commit log should do most of the talking
When you submit your merge request, your commit log should do most of the talking
when it comes to describing your changes and their motivation. In addition to
this, your pull request's comments will ideally include a test plan that the
this, your merge request's comments will ideally include a test plan that the
reviewers can use to (1) demonstrate the problem on master, if applicable and
(2) verify that the problem no longer exists with your changes applied (or that
your new features work correctly). Document all of the edge cases you're aware
of so we can adequately test them - then verify the test plan yourself before
submitting.
## Commit Log
Unlike many projects using GitHub and GitLab, wlroots has a [linear, "recipe"
style] history. This means that every commit should be small, digestible,
stand-alone, and functional. Rather than a purely chronological commit history
like this:
```
doc: final docs for view transforms
fix tests when disabled, redo broken doc formatting
better transformed-view iteration (thanks Hannah!)
try to catch more cases in tests
tests: add new spline test
fix compilation on splines
doc: notes on reticulating splines
compositor: add spline reticulation for view transforms
```
We aim to have a clean history which only reflects the final state, broken up
into functional groupings:
```
compositor: add spline reticulation for view transforms
compositor: new iterator for view transforms
tests: add view-transform correctness tests
doc: fix formatting for view transforms
```
This ensures that the final patch series only contains the final state,
without the changes and missteps taken along the development process. A linear
history eases reviewing, cherry-picking and reverting changes.
If you aren't comfortable with manipulating the Git history, have a look at
[git-rebase.io].
## Commit Messages
Please strive to write good commit messages. Here's some guidelines to follow:
The first line should be limited to 50 characters and should be a sentence that
completes the thought [When applied, this commit will...] *"Implement
cmd_move"* or *"Fix #742"* or *"Improve performance of arrange_windows on ARM"*
or similar.
cmd_move"* or *"Improve performance of arrange_windows on ARM"* or similar.
The subsequent lines should be separated from the subject line by a single
blank line, and include optional details. In this you can give justification
for the change, [reference Github
issues](https://help.github.com/articles/closing-issues-via-commit-messages/),
or explain some of the subtler details of your patch. This is important because
when someone finds a line of code they don't understand later, they can use the
`git blame` command to find out what the author was thinking when they wrote
it. It's also easier to review your pull requests if they're separated into
logical commits that have good commit messages and justify themselves in the
extended commit description.
for the change, [reference issues], or explain some of the subtler
details of your patch. This is important because when someone finds a line of
code they don't understand later, they can use the `git blame` command to find
out what the author was thinking when they wrote it. It's also easier to review
your merge requests if they're separated into logical commits that have good
commit messages and justify themselves in the extended commit description.
As a good rule of thumb, anything you might put into the pull request
description on Github is probably fair game for going into the extended commit
As a good rule of thumb, anything you might put into the merge request
description on GitLab is probably fair game for going into the extended commit
message as well.
See [here](https://chris.beams.io/posts/git-commit/) for more details.
See [How to Write a Git Commit Message] for more details.
## Code Review
@ -70,23 +101,29 @@ changes will typically see review from several people. Be prepared to receive
some feedback - you may be asked to make changes to your work. Our code review
process is:
1. **Triage** the pull request. Do the commit messages make sense? Is a test
1. **Triage** the merge request. Do the commit messages make sense? Is a test
plan necessary and/or present? Add anyone as reviewers that you think should
be there (using the relevant GitHub feature, if you have the permissions, or
be there (using the relevant GitLab feature, if you have the permissions, or
with an @mention if necessary).
2. **Review** the code. Look for code style violations, naming convention
violations, buffer overflows, memory leaks, logic errors, non-portable code
(including GNU-isms), etc. For significant changes to the public API, loop in
a couple more people for discussion.
3. **Execute** the test plan, if present.
4. **Merge** the pull request when all reviewers approve.
4. **Merge** the merge request when all reviewers approve.
5. **File** follow-up tickets if appropriate.
## Code of Conduct
Note that as a project hosted on freedesktop.org, wlroots follows its
[Code of Conduct], based on the Contributor Covenant. Please conduct yourself
in a respectful and civilized manner when communicating with community members
on IRC and bug tracker.
## Style Reference
wlroots is written in C with a style similar to the [kernel
style](https://www.kernel.org/doc/Documentation/process/coding-style.rst), but
with a few notable differences.
wlroots is written in C with a style similar to the [kernel style], but with a
few notable differences.
Try to keep your code conforming to C11 and POSIX as much as possible, and do
not use GNU extensions.
@ -163,7 +200,7 @@ zeroed value and exit cleanly; this simplifies error handling a lot.
### Error Codes
For functions not returning a value, they should return a (stdbool.h) bool to
indicated if they succeeded or not.
indicate whether they succeeded or not.
### Macros
@ -362,3 +399,11 @@ static void subsurface_handle_surface_destroy(struct wl_listener *listener,
subsurface_destroy(subsurface);
}
```
[#sway-devel on Libera Chat]: https://web.libera.chat/gamja/?channels=#sway-devel
[linear, "recipe" style]: https://www.bitsnbites.eu/git-history-work-log-vs-recipe/
[git-rebase.io]: https://git-rebase.io/
[reference issues]: https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically
[Code of Conduct]: https://www.freedesktop.org/wiki/CodeOfConduct/
[How to Write a Git Commit Message]: https://chris.beams.io/posts/git-commit/
[kernel style]: https://www.kernel.org/doc/Documentation/process/coding-style.rst

View File

@ -1,7 +1,13 @@
# blankie/wlroots - dkondor-upstream-pr-2551
This branch "frontports" https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/2551,
should be updated when there's a new wlroots version and be unmaintained
when the pull request above is merged
# wlroots
Pluggable, composable, unopinionated modules for building a [Wayland]
compositor; or about 50,000 lines of code you were going to write anyway.
compositor; or about 60,000 lines of code you were going to write anyway.
- wlroots provides backends that abstract the underlying display and input
hardware, including KMS/DRM, libinput, Wayland, X11, and headless backends,
@ -43,11 +49,11 @@ Install dependencies:
* meson
* wayland
* wayland-protocols
* EGL
* GLESv2
* EGL and GLESv2 (optional, for the GLES2 renderer)
* Vulkan loader, headers and glslang (optional, for the Vulkan renderer)
* libdrm
* GBM
* libinput
* libinput (optional, for the libinput backend)
* xkbcommon
* udev
* pixman
@ -75,9 +81,9 @@ Install like so:
See [CONTRIBUTING.md].
[Wayland]: https://wayland.freedesktop.org/
[wiki]: https://github.com/swaywm/wlroots/wiki/Getting-started
[#sway-devel on Libera Chat]: https://web.libera.chat/?channels=#sway-devel
[wiki]: https://gitlab.freedesktop.org/wlroots/wlroots/-/wikis/Getting-started
[#sway-devel on Libera Chat]: https://web.libera.chat/gamja/?channels=#sway-devel
[Sway]: https://github.com/swaywm/sway
[wrapper libraries]: https://github.com/search?q=topic%3Abindings+org%3Aswaywm&type=Repositories
[wrapper libraries]: https://gitlab.freedesktop.org/wlroots/wlroots/-/wikis/Projects-which-use-wlroots#wrapper-libraries
[libseat]: https://git.sr.ht/~kennylevinsen/seatd
[CONTRIBUTING.md]: https://github.com/swaywm/wlroots/blob/master/CONTRIBUTING.md
[CONTRIBUTING.md]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/CONTRIBUTING.md

View File

@ -1,17 +1,14 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <errno.h>
#include <libinput.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend/drm.h>
#include <wlr/backend/headless.h>
#include <wlr/backend/interface.h>
#include <wlr/backend/libinput.h>
#include <wlr/backend/multi.h>
#include <wlr/backend/noop.h>
#include <wlr/backend/session.h>
#include <wlr/backend/wayland.h>
#include <wlr/config.h>
@ -19,13 +16,24 @@
#include <wlr/util/log.h>
#include "backend/backend.h"
#include "backend/multi.h"
#include "render/allocator.h"
#include "render/allocator/allocator.h"
#include "util/signal.h"
#if WLR_HAS_DRM_BACKEND
#include <wlr/backend/drm.h>
#include "backend/drm/monitor.h"
#endif
#if WLR_HAS_LIBINPUT_BACKEND
#include <wlr/backend/libinput.h>
#endif
#if WLR_HAS_X11_BACKEND
#include <wlr/backend/x11.h>
#endif
#define WAIT_SESSION_TIMEOUT 10000 // ms
void wlr_backend_init(struct wlr_backend *backend,
const struct wlr_backend_impl *impl) {
assert(backend);
@ -37,8 +45,6 @@ void wlr_backend_init(struct wlr_backend *backend,
void wlr_backend_finish(struct wlr_backend *backend) {
wlr_signal_emit_safe(&backend->events.destroy, backend);
wlr_allocator_destroy(backend->allocator);
wlr_renderer_destroy(backend->renderer);
}
bool wlr_backend_start(struct wlr_backend *backend) {
@ -60,35 +66,6 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
}
}
static bool backend_create_renderer(struct wlr_backend *backend) {
if (backend->renderer != NULL) {
return true;
}
backend->renderer = wlr_renderer_autocreate(backend);
if (backend->renderer == NULL) {
return false;
}
return true;
}
struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) {
if (backend->impl->get_renderer) {
return backend->impl->get_renderer(backend);
}
if (backend_get_buffer_caps(backend) != 0) {
// If the backend is capable of presenting buffers, automatically create
// the renderer if necessary.
if (!backend_create_renderer(backend)) {
wlr_log(WLR_ERROR, "Failed to create backend renderer");
return NULL;
}
return backend->renderer;
}
return NULL;
}
struct wlr_session *wlr_backend_get_session(struct wlr_backend *backend) {
if (backend->impl->get_session) {
return backend->impl->get_session(backend);
@ -96,6 +73,52 @@ struct wlr_session *wlr_backend_get_session(struct wlr_backend *backend) {
return NULL;
}
static uint64_t get_current_time_ms(void) {
struct timespec ts = {0};
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
struct wlr_session *session = wlr_session_create(disp);
if (!session) {
wlr_log(WLR_ERROR, "Failed to start a session");
return NULL;
}
if (!session->active) {
wlr_log(WLR_INFO, "Waiting for a session to become active");
uint64_t started_at = get_current_time_ms();
uint64_t timeout = WAIT_SESSION_TIMEOUT;
struct wl_event_loop *event_loop =
wl_display_get_event_loop(session->display);
while (!session->active) {
int ret = wl_event_loop_dispatch(event_loop, (int)timeout);
if (ret < 0) {
wlr_log_errno(WLR_ERROR, "Failed to wait for session active: "
"wl_event_loop_dispatch failed");
return NULL;
}
uint64_t now = get_current_time_ms();
if (now >= started_at + WAIT_SESSION_TIMEOUT) {
break;
}
timeout = started_at + WAIT_SESSION_TIMEOUT - now;
}
if (!session->active) {
wlr_log(WLR_ERROR, "Timeout waiting session to become active");
return NULL;
}
}
return session;
}
clockid_t wlr_backend_get_presentation_clock(struct wlr_backend *backend) {
if (backend->impl->get_presentation_clock) {
return backend->impl->get_presentation_clock(backend);
@ -118,23 +141,6 @@ uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
return backend->impl->get_buffer_caps(backend);
}
struct wlr_allocator *backend_get_allocator(struct wlr_backend *backend) {
if (backend->allocator != NULL) {
return backend->allocator;
}
struct wlr_renderer *renderer = wlr_backend_get_renderer(backend);
if (renderer == NULL) {
return NULL;
}
backend->allocator = wlr_allocator_autocreate(backend, renderer);
if (backend->allocator == NULL) {
wlr_log(WLR_ERROR, "Failed to create backend allocator");
}
return backend->allocator;
}
static size_t parse_outputs_env(const char *name) {
const char *outputs_str = getenv(name);
if (outputs_str == NULL) {
@ -197,20 +203,7 @@ static struct wlr_backend *attempt_headless_backend(
return backend;
}
static struct wlr_backend *attempt_noop_backend(struct wl_display *display) {
struct wlr_backend *backend = wlr_noop_backend_create(display);
if (backend == NULL) {
return NULL;
}
size_t outputs = parse_outputs_env("WLR_NOOP_OUTPUTS");
for (size_t i = 0; i < outputs; ++i) {
wlr_noop_add_output(backend);
}
return backend;
}
#if WLR_HAS_DRM_BACKEND
static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
struct wlr_backend *backend, struct wlr_session *session) {
struct wlr_device *gpus[8];
@ -220,7 +213,12 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
return NULL;
}
wlr_log(WLR_INFO, "Found %zu GPUs", num_gpus);
if (num_gpus == 0) {
wlr_log(WLR_ERROR, "Found 0 GPUs, cannot create backend");
return NULL;
} else {
wlr_log(WLR_INFO, "Found %zu GPUs", num_gpus);
}
struct wlr_backend *primary_drm = NULL;
for (size_t i = 0; i < (size_t)num_gpus; ++i) {
@ -237,42 +235,53 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
wlr_multi_backend_add(backend, drm);
}
if (!primary_drm) {
wlr_log(WLR_ERROR, "Could not successfully create backend on any GPU");
return NULL;
}
return primary_drm;
}
#endif
static struct wlr_backend *attempt_backend_by_name(struct wl_display *display,
struct wlr_backend *backend, struct wlr_session **session,
const char *name) {
static bool attempt_backend_by_name(struct wl_display *display,
struct wlr_multi_backend *multi, char *name) {
struct wlr_backend *backend = NULL;
if (strcmp(name, "wayland") == 0) {
return attempt_wl_backend(display);
backend = attempt_wl_backend(display);
#if WLR_HAS_X11_BACKEND
} else if (strcmp(name, "x11") == 0) {
return attempt_x11_backend(display, NULL);
backend = attempt_x11_backend(display, NULL);
#endif
} else if (strcmp(name, "headless") == 0) {
return attempt_headless_backend(display);
} else if (strcmp(name, "noop") == 0) {
return attempt_noop_backend(display);
backend = attempt_headless_backend(display);
} else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) {
// DRM and libinput need a session
if (!*session) {
*session = wlr_session_create(display);
if (!*session) {
if (multi->session == NULL) {
multi->session = session_create_and_wait(display);
if (multi->session == NULL) {
wlr_log(WLR_ERROR, "failed to start a session");
return NULL;
return false;
}
}
if (strcmp(name, "libinput") == 0) {
return wlr_libinput_backend_create(display, *session);
#if WLR_HAS_LIBINPUT_BACKEND
backend = wlr_libinput_backend_create(display, multi->session);
#endif
} else {
return attempt_drm_backend(display, backend, *session);
#if WLR_HAS_DRM_BACKEND
// attempt_drm_backend adds the multi drm backends itself
return attempt_drm_backend(display, &multi->backend,
multi->session) != NULL;
#endif
}
} else {
wlr_log(WLR_ERROR, "unrecognized backend '%s'", name);
return false;
}
wlr_log(WLR_ERROR, "unrecognized backend '%s'", name);
return NULL;
return wlr_multi_backend_add(&multi->backend, backend);
}
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
@ -298,17 +307,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
char *saveptr;
char *name = strtok_r(names, ",", &saveptr);
while (name != NULL) {
struct wlr_backend *subbackend = attempt_backend_by_name(display,
backend, &multi->session, name);
if (subbackend == NULL) {
wlr_log(WLR_ERROR, "failed to start backend '%s'", name);
wlr_session_destroy(multi->session);
wlr_backend_destroy(backend);
free(names);
return NULL;
}
if (!wlr_multi_backend_add(backend, subbackend)) {
if (!attempt_backend_by_name(display, multi, name)) {
wlr_log(WLR_ERROR, "failed to add backend '%s'", name);
wlr_session_destroy(multi->session);
wlr_backend_destroy(backend);
@ -348,13 +347,14 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
#endif
// Attempt DRM+libinput
multi->session = wlr_session_create(display);
multi->session = session_create_and_wait(display);
if (!multi->session) {
wlr_log(WLR_ERROR, "Failed to start a DRM session");
wlr_backend_destroy(backend);
return NULL;
}
#if WLR_HAS_LIBINPUT_BACKEND
struct wlr_backend *libinput = wlr_libinput_backend_create(display,
multi->session);
if (!libinput) {
@ -364,18 +364,35 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
return NULL;
}
wlr_multi_backend_add(backend, libinput);
#else
const char *no_devs = getenv("WLR_LIBINPUT_NO_DEVICES");
if (no_devs && strcmp(no_devs, "1") == 0) {
wlr_log(WLR_INFO, "WLR_LIBINPUT_NO_DEVICES is set, "
"starting without libinput backend");
} else {
wlr_log(WLR_ERROR, "libinput support is not compiled in, "
"refusing to start");
wlr_log(WLR_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check");
wlr_session_destroy(multi->session);
wlr_backend_destroy(backend);
return NULL;
}
#endif
#if WLR_HAS_DRM_BACKEND
struct wlr_backend *primary_drm =
attempt_drm_backend(display, backend, multi->session);
if (!primary_drm) {
wlr_log(WLR_ERROR, "Failed to open any DRM device");
wlr_backend_destroy(libinput);
wlr_session_destroy(multi->session);
wlr_backend_destroy(backend);
return NULL;
}
drm_backend_monitor_create(backend, primary_drm, multi->session);
return backend;
#endif
error:
wlr_backend_destroy(backend);

View File

@ -1,4 +1,3 @@
#include <gbm.h>
#include <stdlib.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
@ -55,16 +54,14 @@ static void atomic_add(struct atomic *atom, uint32_t id, uint32_t prop, uint64_t
}
static bool create_mode_blob(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t *blob_id) {
if (!drm_connector_state_active(conn, state)) {
struct wlr_drm_connector *conn,
const struct wlr_drm_connector_state *state, uint32_t *blob_id) {
if (!state->active) {
*blob_id = 0;
return true;
}
drmModeModeInfo mode = {0};
drm_connector_state_mode(conn, state, &mode);
if (drmModeCreatePropertyBlob(drm->fd, &mode,
if (drmModeCreatePropertyBlob(drm->fd, &state->mode,
sizeof(drmModeModeInfo), blob_id)) {
wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
return false;
@ -144,8 +141,8 @@ static void set_plane_props(struct atomic *atom, struct wlr_drm_backend *drm,
goto error;
}
uint32_t width = gbm_bo_get_width(fb->bo);
uint32_t height = gbm_bo_get_height(fb->bo);
uint32_t width = fb->wlr_buf->width;
uint32_t height = fb->wlr_buf->height;
// The src_* properties are in 16.16 fixed point
atomic_add(atom, id, props->src_x, 0);
@ -166,14 +163,15 @@ error:
atom->failed = true;
}
static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t flags) {
static bool atomic_crtc_commit(struct wlr_drm_connector *conn,
const struct wlr_drm_connector_state *state, uint32_t flags,
bool test_only) {
struct wlr_drm_backend *drm = conn->backend;
struct wlr_output *output = &conn->output;
struct wlr_drm_crtc *crtc = conn->crtc;
bool modeset = drm_connector_state_is_modeset(state);
bool active = drm_connector_state_active(conn, state);
bool modeset = state->modeset;
bool active = state->active;
uint32_t mode_id = crtc->mode_id;
if (modeset) {
@ -183,35 +181,51 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
}
uint32_t gamma_lut = crtc->gamma_lut;
if (state->committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
if (state->base->committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
// Fallback to legacy gamma interface when gamma properties are not
// available (can happen on older Intel GPUs that support gamma but not
// degamma).
if (crtc->props.gamma_lut == 0) {
if (!drm_legacy_crtc_set_gamma(drm, crtc,
state->gamma_lut_size,
state->gamma_lut)) {
state->base->gamma_lut_size,
state->base->gamma_lut)) {
return false;
}
} else {
if (!create_gamma_lut_blob(drm, state->gamma_lut_size,
state->gamma_lut, &gamma_lut)) {
if (!create_gamma_lut_blob(drm, state->base->gamma_lut_size,
state->base->gamma_lut, &gamma_lut)) {
return false;
}
}
}
uint32_t fb_damage_clips = 0;
if ((state->base->committed & WLR_OUTPUT_STATE_DAMAGE) &&
pixman_region32_not_empty((pixman_region32_t *)&state->base->damage) &&
crtc->primary->props.fb_damage_clips != 0) {
int rects_len;
const pixman_box32_t *rects = pixman_region32_rectangles(
(pixman_region32_t *)&state->base->damage, &rects_len);
if (drmModeCreatePropertyBlob(drm->fd, rects,
sizeof(*rects) * rects_len, &fb_damage_clips) != 0) {
wlr_log_errno(WLR_ERROR, "Failed to create FB_DAMAGE_CLIPS property blob");
}
}
bool prev_vrr_enabled =
output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED;
bool vrr_enabled = prev_vrr_enabled;
if ((state->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED) &&
if ((state->base->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED) &&
drm_connector_supports_vrr(conn)) {
vrr_enabled = state->adaptive_sync_enabled;
vrr_enabled = state->base->adaptive_sync_enabled;
}
if (test_only) {
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
}
if (modeset) {
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
} else if (!(flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
} else if (!test_only) {
flags |= DRM_MODE_ATOMIC_NONBLOCK;
}
@ -232,6 +246,10 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
atomic_add(&atom, crtc->id, crtc->props.vrr_enabled, vrr_enabled);
}
set_plane_props(&atom, drm, crtc->primary, crtc->id, 0, 0);
if (crtc->primary->props.fb_damage_clips != 0) {
atomic_add(&atom, crtc->primary->id,
crtc->primary->props.fb_damage_clips, fb_damage_clips);
}
if (crtc->cursor) {
if (drm_connector_is_cursor_visible(conn)) {
set_plane_props(&atom, drm, crtc->cursor, crtc->id,
@ -250,7 +268,7 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
bool ok = atomic_commit(&atom, conn, flags);
atomic_finish(&atom);
if (ok && !(flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
if (ok && !test_only) {
commit_blob(drm, &crtc->mode_id, mode_id);
commit_blob(drm, &crtc->gamma_lut, gamma_lut);
@ -266,6 +284,11 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
rollback_blob(drm, &crtc->gamma_lut, gamma_lut);
}
if (fb_damage_clips != 0 &&
drmModeDestroyPropertyBlob(drm->fd, fb_damage_clips) != 0) {
wlr_log_errno(WLR_ERROR, "Failed to destroy FB_DAMAGE_CLIPS property blob");
}
return ok;
}

View File

@ -9,11 +9,9 @@
#include <wlr/backend/interface.h>
#include <wlr/backend/session.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/types/wlr_list.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
#include "backend/drm/drm.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
struct wlr_drm_backend *get_drm_backend_from_backend(
@ -24,7 +22,7 @@ struct wlr_drm_backend *get_drm_backend_from_backend(
static bool backend_start(struct wlr_backend *backend) {
struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
scan_drm_connectors(drm);
scan_drm_connectors(drm, NULL);
return true;
}
@ -35,8 +33,6 @@ static void backend_destroy(struct wlr_backend *backend) {
struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
restore_drm_outputs(drm);
struct wlr_drm_connector *conn, *next;
wl_list_for_each_safe(conn, next, &drm->outputs, link) {
destroy_drm_connector(conn);
@ -56,8 +52,11 @@ static void backend_destroy(struct wlr_backend *backend) {
wl_list_remove(&drm->dev_change.link);
wl_list_remove(&drm->dev_remove.link);
if (drm->parent) {
finish_drm_renderer(&drm->mgpu_renderer);
}
finish_drm_resources(drm);
finish_drm_renderer(&drm->renderer);
free(drm->name);
wlr_session_close_file(drm->session, drm->dev);
@ -65,17 +64,6 @@ static void backend_destroy(struct wlr_backend *backend) {
free(drm);
}
static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *backend) {
struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
if (drm->parent) {
return drm->parent->renderer.wlr_rend;
} else {
return drm->renderer.wlr_rend;
}
}
static clockid_t backend_get_presentation_clock(struct wlr_backend *backend) {
struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
return drm->clock;
@ -91,17 +79,16 @@ static int backend_get_drm_fd(struct wlr_backend *backend) {
}
}
static uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
static uint32_t drm_backend_get_buffer_caps(struct wlr_backend *backend) {
return WLR_BUFFER_CAP_DMABUF;
}
static const struct wlr_backend_impl backend_impl = {
.start = backend_start,
.destroy = backend_destroy,
.get_renderer = backend_get_renderer,
.get_presentation_clock = backend_get_presentation_clock,
.get_drm_fd = backend_get_drm_fd,
.get_buffer_caps = backend_get_buffer_caps,
.get_buffer_caps = drm_backend_get_buffer_caps,
};
bool wlr_backend_is_drm(struct wlr_backend *b) {
@ -115,16 +102,18 @@ static void handle_session_active(struct wl_listener *listener, void *data) {
if (session->active) {
wlr_log(WLR_INFO, "DRM fd resumed");
scan_drm_connectors(drm);
scan_drm_connectors(drm, NULL);
struct wlr_drm_connector *conn;
wl_list_for_each(conn, &drm->outputs, link) {
struct wlr_output_mode *mode = NULL;
uint32_t committed = WLR_OUTPUT_STATE_ENABLED;
if (conn->output.enabled && conn->output.current_mode != NULL) {
committed |= WLR_OUTPUT_STATE_MODE;
mode = conn->output.current_mode;
}
struct wlr_output_state state = {
.committed = WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_ENABLED,
.committed = committed,
.enabled = mode != NULL,
.mode_type = WLR_OUTPUT_STATE_MODE_FIXED,
.mode = mode,
@ -138,13 +127,24 @@ static void handle_session_active(struct wl_listener *listener, void *data) {
static void handle_dev_change(struct wl_listener *listener, void *data) {
struct wlr_drm_backend *drm = wl_container_of(listener, drm, dev_change);
struct wlr_device_change_event *change = data;
if (!drm->session->active) {
return;
}
wlr_log(WLR_DEBUG, "%s invalidated", drm->name);
scan_drm_connectors(drm);
switch (change->type) {
case WLR_DEVICE_HOTPLUG:
wlr_log(WLR_DEBUG, "Received hotplug event for %s", drm->name);
scan_drm_connectors(drm, &change->hotplug);
break;
case WLR_DEVICE_LEASE:
wlr_log(WLR_DEBUG, "Received lease event for %s", drm->name);
scan_drm_leases(drm);
break;
default:
wlr_log(WLR_DEBUG, "Received unknown change event for %s", drm->name);
}
}
static void handle_dev_remove(struct wl_listener *listener, void *data) {
@ -217,7 +217,7 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
struct wl_event_loop *event_loop = wl_display_get_event_loop(display);
drm->drm_event = wl_event_loop_add_fd(event_loop, drm->fd,
WL_EVENT_READABLE, handle_drm_event, NULL);
WL_EVENT_READABLE, handle_drm_event, drm);
if (!drm->drm_event) {
wlr_log(WLR_ERROR, "Failed to create DRM event source");
goto error_fd;
@ -234,37 +234,31 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
goto error_event;
}
if (!init_drm_renderer(drm, &drm->renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize renderer");
goto error_event;
}
if (drm->parent) {
if (!init_drm_renderer(drm, &drm->mgpu_renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize renderer");
goto error_resources;
}
// We'll perform a multi-GPU copy for all submitted buffers, we need
// to be able to texture from them
struct wlr_renderer *renderer = drm->renderer.wlr_rend;
struct wlr_renderer *renderer = drm->mgpu_renderer.wlr_rend;
const struct wlr_drm_format_set *texture_formats =
wlr_renderer_get_dmabuf_texture_formats(renderer);
if (texture_formats == NULL) {
wlr_log(WLR_ERROR, "Failed to query renderer texture formats");
goto error_event;
goto error_mgpu_renderer;
}
// Force a linear layout. In case explicit modifiers aren't supported,
// the meaning of implicit modifiers changes from one GPU to the other.
// In case explicit modifiers are supported, we still have no guarantee
// that the buffer producer will support these, so they might fallback
// to implicit modifiers.
for (size_t i = 0; i < texture_formats->len; i++) {
const struct wlr_drm_format *fmt = texture_formats->formats[i];
if (fmt->len == 0) {
// Modifiers aren't supported. The implicit modifier changes
// from a GPU to the other, so we can only accept linear
// buffers
wlr_drm_format_set_add(&drm->mgpu_formats, fmt->format,
DRM_FORMAT_MOD_LINEAR);
continue;
}
for (size_t j = 0; j < fmt->len; j++) {
wlr_drm_format_set_add(&drm->mgpu_formats, fmt->format,
fmt->modifiers[j]);
}
wlr_drm_format_set_add(&drm->mgpu_formats, fmt->format,
DRM_FORMAT_MOD_LINEAR);
}
}
@ -276,10 +270,17 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
return &drm->backend;
error_mgpu_renderer:
finish_drm_renderer(&drm->mgpu_renderer);
error_resources:
finish_drm_resources(drm);
error_event:
wl_list_remove(&drm->session_active.link);
wl_event_source_remove(drm->drm_event);
error_fd:
wl_list_remove(&drm->dev_remove.link);
wl_list_remove(&drm->dev_change.link);
wl_list_remove(&drm->parent_destroy.link);
wlr_session_close_file(drm->session, dev);
free(drm);
return NULL;

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
#include <assert.h>
#include <gbm.h>
#include <stdlib.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
@ -8,17 +7,73 @@
#include "backend/drm/iface.h"
#include "backend/drm/util.h"
static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t flags) {
static bool legacy_fb_props_match(struct wlr_drm_fb *fb1,
struct wlr_drm_fb *fb2) {
struct wlr_dmabuf_attributes dmabuf1 = {0}, dmabuf2 = {0};
if (!wlr_buffer_get_dmabuf(fb1->wlr_buf, &dmabuf1) ||
!wlr_buffer_get_dmabuf(fb2->wlr_buf, &dmabuf2)) {
return false;
}
if (dmabuf1.width != dmabuf2.width ||
dmabuf1.height != dmabuf2.height ||
dmabuf1.format != dmabuf2.format ||
dmabuf1.modifier != dmabuf2.modifier ||
dmabuf1.n_planes != dmabuf2.n_planes) {
return false;
}
for (int i = 0; i < dmabuf1.n_planes; i++) {
if (dmabuf1.stride[i] != dmabuf2.stride[i] ||
dmabuf1.offset[i] != dmabuf2.offset[i]) {
return false;
}
}
return true;
}
static bool legacy_crtc_test(struct wlr_drm_connector *conn,
const struct wlr_drm_connector_state *state) {
struct wlr_drm_crtc *crtc = conn->crtc;
if ((state->base->committed & WLR_OUTPUT_STATE_BUFFER) && !state->modeset) {
struct wlr_drm_fb *pending_fb = crtc->primary->pending_fb;
struct wlr_drm_fb *prev_fb = crtc->primary->queued_fb;
if (!prev_fb) {
prev_fb = crtc->primary->current_fb;
}
/* Legacy is only guaranteed to be able to display a FB if it's been
* allocated the same way as the previous one. */
if (prev_fb != NULL && !legacy_fb_props_match(prev_fb, pending_fb)) {
wlr_drm_conn_log(conn, WLR_DEBUG,
"Cannot change scan-out buffer parameters with legacy KMS API");
return false;
}
}
return true;
}
static bool legacy_crtc_commit(struct wlr_drm_connector *conn,
const struct wlr_drm_connector_state *state,
uint32_t flags, bool test_only) {
if (!legacy_crtc_test(conn, state)) {
return false;
}
if (test_only) {
return true;
}
struct wlr_drm_backend *drm = conn->backend;
struct wlr_output *output = &conn->output;
struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *cursor = crtc->cursor;
bool active = drm_connector_state_active(conn, state);
uint32_t fb_id = 0;
if (active) {
if (state->active) {
struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
if (fb == NULL) {
wlr_log(WLR_ERROR, "%s: failed to acquire primary FB",
@ -28,19 +83,17 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
fb_id = fb->id;
}
if (drm_connector_state_is_modeset(state)) {
if (state->modeset) {
uint32_t *conns = NULL;
size_t conns_len = 0;
drmModeModeInfo *mode = NULL;
drmModeModeInfo mode_info = {0};
if (active) {
if (state->active) {
conns = &conn->id;
conns_len = 1;
drm_connector_state_mode(conn, state, &mode_info);
mode = &mode_info;
mode = (drmModeModeInfo *)&state->mode;
}
uint32_t dpms = active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
uint32_t dpms = state->active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
dpms) != 0) {
wlr_drm_conn_log_errno(conn, WLR_ERROR,
@ -55,27 +108,27 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
}
}
if (state->committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
if (state->base->committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
if (!drm_legacy_crtc_set_gamma(drm, crtc,
state->gamma_lut_size, state->gamma_lut)) {
state->base->gamma_lut_size, state->base->gamma_lut)) {
return false;
}
}
if ((state->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED) &&
if ((state->base->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED) &&
drm_connector_supports_vrr(conn)) {
if (drmModeObjectSetProperty(drm->fd, crtc->id, DRM_MODE_OBJECT_CRTC,
crtc->props.vrr_enabled,
state->adaptive_sync_enabled) != 0) {
state->base->adaptive_sync_enabled) != 0) {
wlr_drm_conn_log_errno(conn, WLR_ERROR,
"drmModeObjectSetProperty(VRR_ENABLED) failed");
return false;
}
output->adaptive_sync_status = state->adaptive_sync_enabled ?
output->adaptive_sync_status = state->base->adaptive_sync_enabled ?
WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED :
WLR_OUTPUT_ADAPTIVE_SYNC_DISABLED;
wlr_drm_conn_log(conn, WLR_DEBUG, "VRR %s",
state->adaptive_sync_enabled ? "enabled" : "disabled");
state->base->adaptive_sync_enabled ? "enabled" : "disabled");
}
if (cursor != NULL && drm_connector_is_cursor_visible(conn)) {
@ -85,12 +138,26 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
return false;
}
uint32_t cursor_handle = gbm_bo_get_handle(cursor_fb->bo).u32;
uint32_t cursor_width = gbm_bo_get_width(cursor_fb->bo);
uint32_t cursor_height = gbm_bo_get_height(cursor_fb->bo);
if (drmModeSetCursor(drm->fd, crtc->id, cursor_handle,
cursor_width, cursor_height)) {
wlr_drm_conn_log_errno(conn, WLR_DEBUG, "drmModeSetCursor failed");
drmModeFB *drm_fb = drmModeGetFB(drm->fd, cursor_fb->id);
if (drm_fb == NULL) {
wlr_drm_conn_log_errno(conn, WLR_DEBUG, "Failed to get cursor "
"BO handle: drmModeGetFB failed");
return false;
}
uint32_t cursor_handle = drm_fb->handle;
uint32_t cursor_width = drm_fb->width;
uint32_t cursor_height = drm_fb->height;
drmModeFreeFB(drm_fb);
int ret = drmModeSetCursor(drm->fd, crtc->id, cursor_handle,
cursor_width, cursor_height);
int set_cursor_errno = errno;
if (drmCloseBufferHandle(drm->fd, cursor_handle) != 0) {
wlr_log_errno(WLR_ERROR, "drmCloseBufferHandle failed");
}
if (ret != 0) {
wlr_drm_conn_log(conn, WLR_DEBUG, "drmModeSetCursor failed: %s",
strerror(set_cursor_errno));
return false;
}
@ -151,6 +218,7 @@ bool drm_legacy_crtc_set_gamma(struct wlr_drm_backend *drm,
if (drmModeCrtcSetGamma(drm->fd, crtc->id, size, r, g, b) != 0) {
wlr_log_errno(WLR_ERROR, "Failed to set gamma LUT on CRTC %"PRIu32,
crtc->id);
free(linear_lut);
return false;
}

View File

@ -4,7 +4,10 @@ wlr_files += files(
'cvt.c',
'drm.c',
'legacy.c',
'monitor.c',
'properties.c',
'renderer.c',
'util.c',
)
features += { 'drm-backend': true }

94
backend/drm/monitor.c Normal file
View File

@ -0,0 +1,94 @@
#include <wlr/util/log.h>
#include <stdlib.h>
#include "backend/drm/monitor.h"
#include "backend/multi.h"
#include "backend/session/session.h"
static void drm_backend_monitor_destroy(struct wlr_drm_backend_monitor* monitor) {
wl_list_remove(&monitor->session_add_drm_card.link);
wl_list_remove(&monitor->session_destroy.link);
wl_list_remove(&monitor->primary_drm_destroy.link);
wl_list_remove(&monitor->multi_destroy.link);
free(monitor);
}
static void handle_add_drm_card(struct wl_listener *listener, void *data) {
struct wlr_session_add_event *event = data;
struct wlr_drm_backend_monitor *backend_monitor =
wl_container_of(listener, backend_monitor, session_add_drm_card);
struct wlr_device *dev =
session_open_if_kms(backend_monitor->session, event->path);
if (!dev) {
wlr_log(WLR_ERROR, "Unable to open %s as DRM device", event->path);
return;
}
wlr_log(WLR_DEBUG, "Creating DRM backend for %s after hotplug", event->path);
struct wlr_backend *child_drm = wlr_drm_backend_create(
backend_monitor->session->display, backend_monitor->session,
dev, backend_monitor->primary_drm);
if (!child_drm) {
wlr_log(WLR_ERROR, "Failed to create DRM backend after hotplug");
return;
}
if (!wlr_multi_backend_add(backend_monitor->multi, child_drm)) {
wlr_log(WLR_ERROR, "Failed to add new drm backend to multi backend");
wlr_backend_destroy(child_drm);
return;
}
if (!wlr_backend_start(child_drm)) {
wlr_log(WLR_ERROR, "Failed to start new child DRM backend");
wlr_backend_destroy(child_drm);
}
}
static void handle_session_destroy(struct wl_listener *listener, void *data) {
struct wlr_drm_backend_monitor *backend_monitor =
wl_container_of(listener, backend_monitor, session_destroy);
drm_backend_monitor_destroy(backend_monitor);
}
static void handle_primary_drm_destroy(struct wl_listener *listener, void *data) {
struct wlr_drm_backend_monitor *backend_monitor =
wl_container_of(listener, backend_monitor, primary_drm_destroy);
drm_backend_monitor_destroy(backend_monitor);
}
static void handle_multi_destroy(struct wl_listener *listener, void *data) {
struct wlr_drm_backend_monitor *backend_monitor =
wl_container_of(listener, backend_monitor, multi_destroy);
drm_backend_monitor_destroy(backend_monitor);
}
struct wlr_drm_backend_monitor *drm_backend_monitor_create(
struct wlr_backend *multi,
struct wlr_backend *primary_drm,
struct wlr_session *session) {
struct wlr_drm_backend_monitor *monitor =
calloc(1, sizeof(struct wlr_drm_backend_monitor));
if (!monitor) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return NULL;
}
monitor->multi = multi;
monitor->primary_drm = primary_drm;
monitor->session = session;
monitor->session_add_drm_card.notify = handle_add_drm_card;
wl_signal_add(&session->events.add_drm_card, &monitor->session_add_drm_card);
monitor->session_destroy.notify = handle_session_destroy;
wl_signal_add(&session->events.destroy, &monitor->session_destroy);
monitor->primary_drm_destroy.notify = handle_primary_drm_destroy;
wl_signal_add(&primary_drm->events.destroy, &monitor->primary_drm_destroy);
monitor->multi_destroy.notify = handle_multi_destroy;
wl_signal_add(&multi->events.destroy, &monitor->multi_destroy);
return monitor;
}

View File

@ -25,6 +25,8 @@ static const struct prop_info connector_info[] = {
{ "EDID", INDEX(edid) },
{ "PATH", INDEX(path) },
{ "link-status", INDEX(link_status) },
{ "non-desktop", INDEX(non_desktop) },
{ "panel orientation", INDEX(panel_orientation) },
{ "subconnector", INDEX(subconnector) },
{ "vrr_capable", INDEX(vrr_capable) },
#undef INDEX
@ -47,6 +49,7 @@ static const struct prop_info plane_info[] = {
{ "CRTC_W", INDEX(crtc_w) },
{ "CRTC_X", INDEX(crtc_x) },
{ "CRTC_Y", INDEX(crtc_y) },
{ "FB_DAMAGE_CLIPS", INDEX(fb_damage_clips) },
{ "FB_ID", INDEX(fb_id) },
{ "IN_FORMATS", INDEX(in_formats) },
{ "SRC_H", INDEX(src_h) },

View File

@ -2,7 +2,6 @@
#include <assert.h>
#include <drm_fourcc.h>
#include <fcntl.h>
#include <gbm.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@ -14,42 +13,30 @@
#include "backend/drm/drm.h"
#include "backend/drm/util.h"
#include "render/drm_format_set.h"
#include "render/allocator.h"
#include "render/allocator/allocator.h"
#include "render/pixel_format.h"
#include "render/swapchain.h"
#include "render/wlr_renderer.h"
#include "render/wlr_texture.h"
bool init_drm_renderer(struct wlr_drm_backend *drm,
struct wlr_drm_renderer *renderer) {
renderer->backend = drm;
renderer->gbm = gbm_create_device(drm->fd);
if (!renderer->gbm) {
wlr_log(WLR_ERROR, "Failed to create GBM device");
return false;
}
renderer->wlr_rend = renderer_autocreate_with_drm_fd(drm->fd);
if (!renderer->wlr_rend) {
wlr_log(WLR_ERROR, "Failed to create renderer");
goto error_gbm;
return false;
}
renderer->allocator = allocator_autocreate_with_drm_fd(&drm->backend,
renderer->wlr_rend, drm->fd);
if (renderer->allocator == NULL) {
wlr_log(WLR_ERROR, "Failed to create allocator");
goto error_wlr_rend;
wlr_renderer_destroy(renderer->wlr_rend);
return false;
}
return true;
error_wlr_rend:
wlr_renderer_destroy(renderer->wlr_rend);
error_gbm:
gbm_device_destroy(renderer->gbm);
return false;
}
void finish_drm_renderer(struct wlr_drm_renderer *renderer) {
@ -59,7 +46,6 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer) {
wlr_allocator_destroy(renderer->allocator);
wlr_renderer_destroy(renderer->wlr_rend);
gbm_device_destroy(renderer->gbm);
}
bool init_drm_surface(struct wlr_drm_surface *surf,
@ -73,8 +59,6 @@ bool init_drm_surface(struct wlr_drm_surface *surf,
surf->width = width;
surf->height = height;
wlr_buffer_unlock(surf->back_buffer);
surf->back_buffer = NULL;
wlr_swapchain_destroy(surf->swapchain);
surf->swapchain = NULL;
@ -94,38 +78,11 @@ static void finish_drm_surface(struct wlr_drm_surface *surf) {
return;
}
wlr_buffer_unlock(surf->back_buffer);
wlr_swapchain_destroy(surf->swapchain);
memset(surf, 0, sizeof(*surf));
}
bool drm_surface_make_current(struct wlr_drm_surface *surf,
int *buffer_age) {
wlr_buffer_unlock(surf->back_buffer);
surf->back_buffer = wlr_swapchain_acquire(surf->swapchain, buffer_age);
if (surf->back_buffer == NULL) {
wlr_log(WLR_ERROR, "Failed to acquire swapchain buffer");
return false;
}
if (!renderer_bind_buffer(surf->renderer->wlr_rend, surf->back_buffer)) {
wlr_log(WLR_ERROR, "Failed to bind buffer to renderer");
return false;
}
return true;
}
void drm_surface_unset_current(struct wlr_drm_surface *surf) {
assert(surf->back_buffer != NULL);
renderer_bind_buffer(surf->renderer->wlr_rend, NULL);
wlr_buffer_unlock(surf->back_buffer);
surf->back_buffer = NULL;
}
struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
struct wlr_buffer *buffer) {
struct wlr_renderer *renderer = surf->renderer->wlr_rend;
@ -141,7 +98,8 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
return NULL;
}
if (!drm_surface_make_current(surf, NULL)) {
struct wlr_buffer *dst = wlr_swapchain_acquire(surf->swapchain, NULL);
if (!dst) {
wlr_texture_destroy(tex);
return NULL;
}
@ -150,19 +108,20 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
wlr_matrix_identity(mat);
wlr_matrix_scale(mat, surf->width, surf->height);
wlr_renderer_begin(renderer, surf->width, surf->height);
if (!wlr_renderer_begin_with_buffer(renderer, dst)) {
wlr_buffer_unlock(dst);
wlr_texture_destroy(tex);
return NULL;
}
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
wlr_render_texture_with_matrix(renderer, tex, mat, 1.0f);
wlr_renderer_end(renderer);
assert(surf->back_buffer != NULL);
struct wlr_buffer *out = wlr_buffer_lock(surf->back_buffer);
drm_surface_unset_current(surf);
wlr_texture_destroy(tex);
return out;
return dst;
}
@ -175,22 +134,9 @@ void drm_plane_finish_surface(struct wlr_drm_plane *plane) {
drm_fb_clear(&plane->queued_fb);
drm_fb_clear(&plane->current_fb);
finish_drm_surface(&plane->surf);
finish_drm_surface(&plane->mgpu_surf);
}
static struct wlr_drm_format *create_linear_format(uint32_t format) {
struct wlr_drm_format *fmt = wlr_drm_format_create(format);
if (fmt == NULL) {
return NULL;
}
if (!wlr_drm_format_add(&fmt, DRM_FORMAT_MOD_LINEAR)) {
free(fmt);
return NULL;
}
return fmt;
}
struct wlr_drm_format *drm_plane_pick_render_format(
struct wlr_drm_plane *plane, struct wlr_drm_renderer *renderer) {
const struct wlr_drm_format_set *render_formats =
@ -203,7 +149,7 @@ struct wlr_drm_format *drm_plane_pick_render_format(
const struct wlr_drm_format_set *plane_formats = &plane->formats;
uint32_t fmt = DRM_FORMAT_ARGB8888;
if (!wlr_drm_format_set_has(&plane->formats, fmt, DRM_FORMAT_MOD_INVALID)) {
if (!wlr_drm_format_set_get(&plane->formats, fmt)) {
const struct wlr_pixel_format_info *format_info =
drm_get_pixel_format_info(fmt);
assert(format_info != NULL &&
@ -237,53 +183,6 @@ struct wlr_drm_format *drm_plane_pick_render_format(
return format;
}
bool drm_plane_init_surface(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm, int32_t width, uint32_t height,
bool with_modifiers) {
struct wlr_drm_format *format =
drm_plane_pick_render_format(plane, &drm->renderer);
if (format == NULL) {
wlr_log(WLR_ERROR, "Failed to pick render format for plane %"PRIu32,
plane->id);
return false;
}
if (!with_modifiers) {
struct wlr_drm_format *format_implicit_modifier =
wlr_drm_format_create(format->format);
free(format);
format = format_implicit_modifier;
}
drm_plane_finish_surface(plane);
bool ok = true;
if (!drm->parent) {
ok = init_drm_surface(&plane->surf, &drm->renderer,
width, height, format);
} else {
struct wlr_drm_format *format_linear = create_linear_format(format->format);
if (format_linear == NULL) {
free(format);
return false;
}
ok = init_drm_surface(&plane->surf, &drm->parent->renderer,
width, height, format_linear);
free(format_linear);
if (ok && !init_drm_surface(&plane->mgpu_surf, &drm->renderer,
width, height, format)) {
finish_drm_surface(&plane->surf);
ok = false;
}
}
free(format);
return ok;
}
void drm_fb_clear(struct wlr_drm_fb **fb_ptr) {
if (*fb_ptr == NULL) {
return;
@ -295,99 +194,139 @@ void drm_fb_clear(struct wlr_drm_fb **fb_ptr) {
*fb_ptr = NULL;
}
bool drm_plane_lock_surface(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm) {
assert(plane->surf.back_buffer != NULL);
struct wlr_buffer *buf = wlr_buffer_lock(plane->surf.back_buffer);
// Unset the current EGL context ASAP, because other operations may require
// making another context current.
drm_surface_unset_current(&plane->surf);
struct wlr_buffer *local_buf;
if (drm->parent) {
// Perform a copy across GPUs
local_buf = drm_surface_blit(&plane->mgpu_surf, buf);
if (!local_buf) {
wlr_log(WLR_ERROR, "Failed to blit buffer across GPUs");
return false;
}
} else {
local_buf = wlr_buffer_lock(buf);
}
wlr_buffer_unlock(buf);
bool ok = drm_fb_import(&plane->pending_fb, drm, local_buf, NULL);
if (!ok) {
wlr_log(WLR_ERROR, "Failed to import buffer");
}
wlr_buffer_unlock(local_buf);
return ok;
}
static struct gbm_bo *get_bo_for_dmabuf(struct gbm_device *gbm,
struct wlr_dmabuf_attributes *attribs) {
if (attribs->modifier != DRM_FORMAT_MOD_INVALID ||
attribs->n_planes > 1 || attribs->offset[0] != 0) {
struct gbm_import_fd_modifier_data data = {
.width = attribs->width,
.height = attribs->height,
.format = attribs->format,
.num_fds = attribs->n_planes,
.modifier = attribs->modifier,
};
if ((size_t)attribs->n_planes > sizeof(data.fds) / sizeof(data.fds[0])) {
return false;
}
for (size_t i = 0; i < (size_t)attribs->n_planes; ++i) {
data.fds[i] = attribs->fd[i];
data.strides[i] = attribs->stride[i];
data.offsets[i] = attribs->offset[i];
}
return gbm_bo_import(gbm, GBM_BO_IMPORT_FD_MODIFIER,
&data, GBM_BO_USE_SCANOUT);
} else {
struct gbm_import_fd_data data = {
.fd = attribs->fd[0],
.width = attribs->width,
.height = attribs->height,
.stride = attribs->stride[0],
.format = attribs->format,
};
return gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &data, GBM_BO_USE_SCANOUT);
}
}
static void drm_fb_handle_wlr_buf_destroy(struct wl_listener *listener,
void *data) {
struct wlr_drm_fb *fb = wl_container_of(listener, fb, wlr_buf_destroy);
static void drm_fb_handle_destroy(struct wlr_addon *addon) {
struct wlr_drm_fb *fb = wl_container_of(addon, fb, addon);
drm_fb_destroy(fb);
}
static const struct wlr_addon_interface fb_addon_impl = {
.name = "wlr_drm_fb",
.destroy = drm_fb_handle_destroy,
};
static uint32_t get_fb_for_bo(struct wlr_drm_backend *drm,
struct wlr_dmabuf_attributes *dmabuf, uint32_t handles[static 4]) {
uint64_t modifiers[4] = {0};
for (int i = 0; i < dmabuf->n_planes; i++) {
// KMS requires all BO planes to have the same modifier
modifiers[i] = dmabuf->modifier;
}
uint32_t id = 0;
if (drm->addfb2_modifiers && dmabuf->modifier != DRM_FORMAT_MOD_INVALID) {
if (drmModeAddFB2WithModifiers(drm->fd, dmabuf->width, dmabuf->height,
dmabuf->format, handles, dmabuf->stride, dmabuf->offset,
modifiers, &id, DRM_MODE_FB_MODIFIERS) != 0) {
wlr_log_errno(WLR_DEBUG, "drmModeAddFB2WithModifiers failed");
}
} else {
if (dmabuf->modifier != DRM_FORMAT_MOD_INVALID &&
dmabuf->modifier != DRM_FORMAT_MOD_LINEAR) {
wlr_log(WLR_ERROR, "Cannot import DRM framebuffer with explicit "
"modifier 0x%"PRIX64, dmabuf->modifier);
return 0;
}
int ret = drmModeAddFB2(drm->fd, dmabuf->width, dmabuf->height,
dmabuf->format, handles, dmabuf->stride, dmabuf->offset, &id, 0);
if (ret != 0 && dmabuf->format == DRM_FORMAT_ARGB8888 &&
dmabuf->n_planes == 1 && dmabuf->offset[0] == 0) {
// Some big-endian machines don't support drmModeAddFB2. Try a
// last-resort fallback for ARGB8888 buffers, like Xorg's
// modesetting driver does.
wlr_log(WLR_DEBUG, "drmModeAddFB2 failed (%s), falling back to "
"legacy drmModeAddFB", strerror(-ret));
uint32_t depth = 32;
uint32_t bpp = 32;
ret = drmModeAddFB(drm->fd, dmabuf->width, dmabuf->height, depth,
bpp, dmabuf->stride[0], handles[0], &id);
if (ret != 0) {
wlr_log_errno(WLR_DEBUG, "drmModeAddFB failed");
}
} else if (ret != 0) {
wlr_log_errno(WLR_DEBUG, "drmModeAddFB2 failed");
}
}
return id;
}
static void close_all_bo_handles(struct wlr_drm_backend *drm,
uint32_t handles[static 4]) {
for (int i = 0; i < 4; ++i) {
if (handles[i] == 0) {
continue;
}
// If multiple planes share the same BO handle, avoid double-closing it
bool already_closed = false;
for (int j = 0; j < i; ++j) {
if (handles[i] == handles[j]) {
already_closed = true;
break;
}
}
if (already_closed) {
continue;
}
if (drmCloseBufferHandle(drm->fd, handles[i]) != 0) {
wlr_log_errno(WLR_ERROR, "drmCloseBufferHandle failed");
}
}
}
static void drm_poisoned_fb_handle_destroy(struct wlr_addon *addon) {
wlr_addon_finish(addon);
free(addon);
}
static const struct wlr_addon_interface poisoned_fb_addon_impl = {
.name = "wlr_drm_poisoned_fb",
.destroy = drm_poisoned_fb_handle_destroy,
};
static bool is_buffer_poisoned(struct wlr_drm_backend *drm,
struct wlr_buffer *buf) {
return wlr_addon_find(&buf->addons, drm, &poisoned_fb_addon_impl) != NULL;
}
/**
* Mark the buffer as "poisoned", ie. it cannot be imported into KMS. This
* allows us to avoid repeatedly trying to import it when it's not
* scanout-capable.
*/
static void poison_buffer(struct wlr_drm_backend *drm,
struct wlr_buffer *buf) {
struct wlr_addon *addon = calloc(1, sizeof(*addon));
if (addon == NULL) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return;
}
wlr_addon_init(addon, &buf->addons, drm, &poisoned_fb_addon_impl);
wlr_log(WLR_DEBUG, "Poisoning buffer");
}
static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm,
struct wlr_buffer *buf, const struct wlr_drm_format_set *formats) {
struct wlr_dmabuf_attributes attribs;
if (!wlr_buffer_get_dmabuf(buf, &attribs)) {
wlr_log(WLR_DEBUG, "Failed to get DMA-BUF from buffer");
return NULL;
}
if (is_buffer_poisoned(drm, buf)) {
wlr_log(WLR_DEBUG, "Buffer is poisoned");
return NULL;
}
struct wlr_drm_fb *fb = calloc(1, sizeof(*fb));
if (!fb) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return NULL;
}
struct wlr_dmabuf_attributes attribs;
if (!wlr_buffer_get_dmabuf(buf, &attribs)) {
wlr_log(WLR_DEBUG, "Failed to get DMA-BUF from buffer");
goto error_get_dmabuf;
}
if (attribs.flags != 0) {
wlr_log(WLR_DEBUG, "Buffer with DMA-BUF flags 0x%"PRIX32" cannot be "
"scanned out", attribs.flags);
goto error_get_dmabuf;
}
if (formats && !wlr_drm_format_set_has(formats, attribs.format,
attribs.modifier)) {
// The format isn't supported by the plane. Try stripping the alpha
@ -401,66 +340,63 @@ static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm,
wlr_log(WLR_DEBUG, "Buffer format 0x%"PRIX32" with modifier "
"0x%"PRIX64" cannot be scanned out",
attribs.format, attribs.modifier);
goto error_get_dmabuf;
goto error_fb;
}
}
fb->bo = get_bo_for_dmabuf(drm->renderer.gbm, &attribs);
if (!fb->bo) {
wlr_log(WLR_DEBUG, "Failed to import DMA-BUF in GBM");
goto error_get_dmabuf;
uint32_t handles[4] = {0};
for (int i = 0; i < attribs.n_planes; ++i) {
int ret = drmPrimeFDToHandle(drm->fd, attribs.fd[i], &handles[i]);
if (ret != 0) {
wlr_log_errno(WLR_DEBUG, "drmPrimeFDToHandle failed");
goto error_bo_handle;
}
}
fb->id = get_fb_for_bo(fb->bo, drm->addfb2_modifiers);
fb->id = get_fb_for_bo(drm, &attribs, handles);
if (!fb->id) {
wlr_log(WLR_DEBUG, "Failed to import GBM BO in KMS");
goto error_get_fb_for_bo;
wlr_log(WLR_DEBUG, "Failed to import BO in KMS");
poison_buffer(drm, buf);
goto error_bo_handle;
}
close_all_bo_handles(drm, handles);
fb->backend = drm;
fb->wlr_buf = buf;
fb->wlr_buf_destroy.notify = drm_fb_handle_wlr_buf_destroy;
wl_signal_add(&buf->events.destroy, &fb->wlr_buf_destroy);
wlr_addon_init(&fb->addon, &buf->addons, drm, &fb_addon_impl);
wl_list_insert(&drm->fbs, &fb->link);
return fb;
error_get_fb_for_bo:
gbm_bo_destroy(fb->bo);
error_get_dmabuf:
error_bo_handle:
close_all_bo_handles(drm, handles);
error_fb:
free(fb);
return NULL;
}
void drm_fb_destroy(struct wlr_drm_fb *fb) {
wl_list_remove(&fb->link);
wl_list_remove(&fb->wlr_buf_destroy.link);
struct wlr_drm_backend *drm = fb->backend;
struct gbm_device *gbm = gbm_bo_get_device(fb->bo);
if (drmModeRmFB(gbm_device_get_fd(gbm), fb->id) != 0) {
wl_list_remove(&fb->link);
wlr_addon_finish(&fb->addon);
if (drmModeRmFB(drm->fd, fb->id) != 0) {
wlr_log(WLR_ERROR, "drmModeRmFB failed");
}
gbm_bo_destroy(fb->bo);
free(fb);
}
static struct wlr_drm_fb *drm_fb_get(struct wlr_drm_backend *drm,
struct wlr_buffer *local_buf) {
struct wlr_drm_fb *fb;
wl_list_for_each(fb, &drm->fbs, link) {
if (fb->wlr_buf == local_buf) {
return fb;
}
}
return NULL;
}
bool drm_fb_import(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm,
struct wlr_buffer *buf, const struct wlr_drm_format_set *formats) {
struct wlr_drm_fb *fb = drm_fb_get(drm, buf);
if (!fb) {
struct wlr_drm_fb *fb;
struct wlr_addon *addon = wlr_addon_find(&buf->addons, drm, &fb_addon_impl);
if (addon != NULL) {
fb = wl_container_of(addon, fb, addon);
} else {
fb = drm_fb_create(drm, buf, formats);
if (!fb) {
return false;
@ -477,16 +413,3 @@ void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old) {
*new = *old;
*old = NULL;
}
bool drm_surface_render_black_frame(struct wlr_drm_surface *surf) {
if (!drm_surface_make_current(surf, NULL)) {
return false;
}
struct wlr_renderer *renderer = surf->renderer->wlr_rend;
wlr_renderer_begin(renderer, surf->width, surf->height);
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 1.0 });
wlr_renderer_end(renderer);
return true;
}

View File

@ -2,7 +2,6 @@
#include <drm_fourcc.h>
#include <drm_mode.h>
#include <drm.h>
#include <gbm.h>
#include <stdio.h>
#include <string.h>
#include <wlr/util/log.h>
@ -95,6 +94,7 @@ static const char *get_manufacturer(uint16_t id) {
case ID('V', 'E', 'S'): return "Vestel Elektronik Sanayi ve Ticaret A. S.";
case ID('V', 'I', 'T'): return "Visitech AS";
case ID('V', 'I', 'Z'): return "VIZIO, Inc";
case ID('V', 'L', 'V'): return "Valve";
case ID('V', 'S', 'C'): return "ViewSonic Corporation";
case ID('Y', 'M', 'H'): return "Yamaha Corporation";
default: return "Unknown";
@ -167,61 +167,14 @@ const char *conn_get_name(uint32_t type_id) {
case DRM_MODE_CONNECTOR_WRITEBACK: return "Writeback";
#ifdef DRM_MODE_CONNECTOR_SPI
case DRM_MODE_CONNECTOR_SPI: return "SPI";
#endif
#ifdef DRM_MODE_CONNECTOR_USB
case DRM_MODE_CONNECTOR_USB: return "USB";
#endif
default: return "Unknown";
}
}
uint32_t get_fb_for_bo(struct gbm_bo *bo, bool with_modifiers) {
struct gbm_device *gbm = gbm_bo_get_device(bo);
int fd = gbm_device_get_fd(gbm);
uint32_t width = gbm_bo_get_width(bo);
uint32_t height = gbm_bo_get_height(bo);
uint32_t format = gbm_bo_get_format(bo);
uint32_t handles[4] = {0};
uint32_t strides[4] = {0};
uint32_t offsets[4] = {0};
uint64_t modifiers[4] = {0};
for (int i = 0; i < gbm_bo_get_plane_count(bo); i++) {
handles[i] = gbm_bo_get_handle_for_plane(bo, i).u32;
strides[i] = gbm_bo_get_stride_for_plane(bo, i);
offsets[i] = gbm_bo_get_offset(bo, i);
// KMS requires all BO planes to have the same modifier
modifiers[i] = gbm_bo_get_modifier(bo);
}
uint32_t id = 0;
if (with_modifiers && gbm_bo_get_modifier(bo) != DRM_FORMAT_MOD_INVALID) {
if (drmModeAddFB2WithModifiers(fd, width, height, format, handles,
strides, offsets, modifiers, &id, DRM_MODE_FB_MODIFIERS)) {
wlr_log_errno(WLR_ERROR, "Unable to add DRM framebuffer");
}
} else {
int ret = drmModeAddFB2(fd, width, height, format, handles, strides,
offsets, &id, 0);
if (ret != 0 && gbm_bo_get_format(bo) == GBM_FORMAT_ARGB8888 &&
gbm_bo_get_plane_count(bo) == 1) {
// Some big-endian machines don't support drmModeAddFB2. Try a
// last-resort fallback for ARGB8888 buffers, like Xorg's
// modesetting driver does.
wlr_log(WLR_DEBUG, "drmModeAddFB2 failed (%s), falling back to "
"legacy drmModeAddFB", strerror(-ret));
uint32_t depth = 32;
uint32_t bpp = gbm_bo_get_bpp(bo);
ret = drmModeAddFB(fd, width, height, depth, bpp, strides[0],
handles[0], &id);
}
if (ret != 0) {
wlr_log(WLR_ERROR, "Unable to add DRM framebuffer: %s", strerror(-ret));
}
}
return id;
}
static bool is_taken(size_t n, const uint32_t arr[static n], uint32_t key) {
for (size_t i = 0; i < n; ++i) {
if (arr[i] == key) {

View File

@ -1,20 +1,9 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <drm_fourcc.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
#include "backend/backend.h"
#include "backend/headless.h"
#include "render/drm_format_set.h"
#include "render/gbm_allocator.h"
#include "render/wlr_renderer.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
struct wlr_headless_backend *headless_backend_from_backend(
@ -37,8 +26,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
}
struct wlr_headless_input_device *input_device;
wl_list_for_each(input_device, &backend->input_devices,
wlr_input_device.link) {
wl_list_for_each(input_device, &backend->input_devices, link) {
wlr_signal_emit_safe(&backend->backend.events.new_input,
&input_device->wlr_input_device);
}
@ -55,7 +43,6 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
}
wl_list_remove(&backend->display_destroy.link);
wl_list_remove(&backend->parent_renderer_destroy.link);
struct wlr_headless_output *output, *output_tmp;
wl_list_for_each_safe(output, output_tmp, &backend->outputs, link) {
@ -64,33 +51,15 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_headless_input_device *input_device, *input_device_tmp;
wl_list_for_each_safe(input_device, input_device_tmp,
&backend->input_devices, wlr_input_device.link) {
&backend->input_devices, link) {
wlr_input_device_destroy(&input_device->wlr_input_device);
}
wlr_backend_finish(wlr_backend);
close(backend->drm_fd);
free(backend);
}
static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend =
headless_backend_from_backend(wlr_backend);
if (backend->parent_renderer != NULL) {
return backend->parent_renderer;
} else {
return wlr_backend->renderer;
}
}
static int backend_get_drm_fd(struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend =
headless_backend_from_backend(wlr_backend);
return backend->drm_fd;
}
static uint32_t get_buffer_caps(struct wlr_backend *wlr_backend) {
return WLR_BUFFER_CAP_DATA_PTR
| WLR_BUFFER_CAP_DMABUF
@ -100,8 +69,6 @@ static uint32_t get_buffer_caps(struct wlr_backend *wlr_backend) {
static const struct wlr_backend_impl backend_impl = {
.start = backend_start,
.destroy = backend_destroy,
.get_renderer = backend_get_renderer,
.get_drm_fd = backend_get_drm_fd,
.get_buffer_caps = get_buffer_caps,
};
@ -111,91 +78,6 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
backend_destroy(&backend->backend);
}
static void handle_renderer_destroy(struct wl_listener *listener, void *data) {
struct wlr_headless_backend *backend =
wl_container_of(listener, backend, parent_renderer_destroy);
backend_destroy(&backend->backend);
}
static bool backend_init(struct wlr_headless_backend *backend,
struct wl_display *display, struct wlr_renderer *renderer) {
wlr_backend_init(&backend->backend, &backend_impl);
backend->display = display;
wl_list_init(&backend->outputs);
wl_list_init(&backend->input_devices);
wl_list_init(&backend->parent_renderer_destroy.link);
if (renderer == NULL) {
renderer = wlr_renderer_autocreate(&backend->backend);
if (!renderer) {
wlr_log(WLR_ERROR, "Failed to create renderer");
return false;
}
backend->backend.renderer = renderer;
} else {
backend->parent_renderer = renderer;
backend->parent_renderer_destroy.notify = handle_renderer_destroy;
wl_signal_add(&renderer->events.destroy, &backend->parent_renderer_destroy);
}
if (backend_get_allocator(&backend->backend) == NULL) {
wlr_log(WLR_ERROR, "Failed to create allocator");
return false;
}
backend->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &backend->display_destroy);
return true;
}
static int open_drm_render_node(void) {
uint32_t flags = 0;
int devices_len = drmGetDevices2(flags, NULL, 0);
if (devices_len < 0) {
wlr_log(WLR_ERROR, "drmGetDevices2 failed: %s", strerror(-devices_len));
return -1;
}
drmDevice **devices = calloc(devices_len, sizeof(drmDevice *));
if (devices == NULL) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return -1;
}
devices_len = drmGetDevices2(flags, devices, devices_len);
if (devices_len < 0) {
free(devices);
wlr_log(WLR_ERROR, "drmGetDevices2 failed: %s", strerror(-devices_len));
return -1;
}
int fd = -1;
for (int i = 0; i < devices_len; i++) {
drmDevice *dev = devices[i];
if (dev->available_nodes & (1 << DRM_NODE_RENDER)) {
const char *name = dev->nodes[DRM_NODE_RENDER];
wlr_log(WLR_DEBUG, "Opening DRM render node '%s'", name);
fd = open(name, O_RDWR | O_CLOEXEC);
if (fd < 0) {
wlr_log_errno(WLR_ERROR, "Failed to open '%s'", name);
goto out;
}
break;
}
}
if (fd < 0) {
wlr_log(WLR_ERROR, "Failed to find any DRM render node");
}
out:
for (int i = 0; i < devices_len; i++) {
drmFreeDevice(&devices[i]);
}
free(devices);
return fd;
}
struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) {
wlr_log(WLR_INFO, "Creating headless backend");
@ -206,55 +88,16 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) {
return NULL;
}
backend->drm_fd = open_drm_render_node();
if (backend->drm_fd < 0) {
wlr_log(WLR_ERROR, "Failed to open DRM render node");
}
wlr_backend_init(&backend->backend, &backend_impl);
if (!backend_init(backend, display, NULL)) {
goto error_init;
}
backend->display = display;
wl_list_init(&backend->outputs);
wl_list_init(&backend->input_devices);
backend->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &backend->display_destroy);
return &backend->backend;
error_init:
close(backend->drm_fd);
free(backend);
return NULL;
}
struct wlr_backend *wlr_headless_backend_create_with_renderer(
struct wl_display *display, struct wlr_renderer *renderer) {
wlr_log(WLR_INFO, "Creating headless backend with parent renderer");
struct wlr_headless_backend *backend =
calloc(1, sizeof(struct wlr_headless_backend));
if (!backend) {
wlr_log(WLR_ERROR, "Failed to allocate wlr_headless_backend");
return NULL;
}
int drm_fd = wlr_renderer_get_drm_fd(renderer);
if (drm_fd < 0) {
wlr_log(WLR_ERROR, "Failed to get DRM device FD from parent renderer");
backend->drm_fd = -1;
} else {
backend->drm_fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 0);
if (backend->drm_fd < 0) {
wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
}
}
if (!backend_init(backend, display, renderer)) {
goto error_init;
}
return &backend->backend;
error_init:
close(backend->drm_fd);
free(backend);
return NULL;
}
bool wlr_backend_is_headless(struct wlr_backend *backend) {

View File

@ -11,7 +11,16 @@
#include "backend/headless.h"
#include "util/signal.h"
static const struct wlr_input_device_impl input_device_impl = { 0 };
static void input_device_destroy(struct wlr_input_device *wlr_dev) {
struct wlr_headless_input_device *dev =
wl_container_of(wlr_dev, dev, wlr_input_device);
wl_list_remove(&dev->link);
free(dev);
}
static const struct wlr_input_device_impl input_device_impl = {
.destroy = input_device_destroy,
};
bool wlr_input_device_is_headless(struct wlr_input_device *wlr_dev) {
return wlr_dev->impl == &input_device_impl;
@ -86,7 +95,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
wlr_switch_init(wlr_device->switch_device, NULL);
}
wl_list_insert(&backend->input_devices, &wlr_device->link);
wl_list_insert(&backend->input_devices, &device->link);
if (backend->started) {
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_device);

View File

@ -2,7 +2,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/util/log.h>
#include "backend/headless.h"
#include "util/signal.h"
@ -18,11 +17,8 @@ static struct wlr_headless_output *headless_output_from_output(
return (struct wlr_headless_output *)wlr_output;
}
static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
int32_t height, int32_t refresh) {
struct wlr_headless_output *output =
headless_output_from_output(wlr_output);
static bool output_set_custom_mode(struct wlr_headless_output *output,
int32_t width, int32_t height, int32_t refresh) {
if (refresh <= 0) {
refresh = HEADLESS_DEFAULT_REFRESH;
}
@ -58,7 +54,7 @@ static bool output_commit(struct wlr_output *wlr_output) {
}
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) {
if (!output_set_custom_mode(wlr_output,
if (!output_set_custom_mode(output,
wlr_output->pending.custom_mode.width,
wlr_output->pending.custom_mode.height,
wlr_output->pending.custom_mode.refresh)) {
@ -67,48 +63,27 @@ static bool output_commit(struct wlr_output *wlr_output) {
}
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
assert(wlr_output->pending.buffer_type ==
WLR_OUTPUT_STATE_BUFFER_SCANOUT);
wlr_buffer_unlock(output->front_buffer);
output->front_buffer = wlr_buffer_lock(wlr_output->pending.buffer);
wlr_output_send_present(wlr_output, NULL);
struct wlr_output_event_present present_event = {
.commit_seq = wlr_output->commit_seq + 1,
.presented = true,
};
wlr_output_send_present(wlr_output, &present_event);
}
return true;
}
static bool output_export_dmabuf(struct wlr_output *wlr_output,
struct wlr_dmabuf_attributes *attribs) {
struct wlr_headless_output *output =
headless_output_from_output(wlr_output);
if (!output->front_buffer) {
return false;
}
struct wlr_dmabuf_attributes tmp;
if (!wlr_buffer_get_dmabuf(output->front_buffer, &tmp)) {
return false;
}
return wlr_dmabuf_attributes_copy(attribs, &tmp);
}
static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_headless_output *output =
headless_output_from_output(wlr_output);
wl_list_remove(&output->link);
wl_event_source_remove(output->frame_timer);
wlr_buffer_unlock(output->front_buffer);
free(output);
}
static const struct wlr_output_impl output_impl = {
.destroy = output_destroy,
.commit = output_commit,
.export_dmabuf = output_export_dmabuf,
};
bool wlr_output_is_headless(struct wlr_output *wlr_output) {
@ -138,15 +113,17 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
backend->display);
struct wlr_output *wlr_output = &output->wlr_output;
output_set_custom_mode(wlr_output, width, height, 0);
output_set_custom_mode(output, width, height, 0);
strncpy(wlr_output->make, "headless", sizeof(wlr_output->make));
strncpy(wlr_output->model, "headless", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "HEADLESS-%zd",
++backend->last_output_num);
char name[64];
snprintf(name, sizeof(name), "HEADLESS-%zu", ++backend->last_output_num);
wlr_output_set_name(wlr_output, name);
char description[128];
snprintf(description, sizeof(description),
"Headless output %zd", backend->last_output_num);
"Headless output %zu", backend->last_output_num);
wlr_output_set_description(wlr_output, description);
struct wl_event_loop *ev = wl_display_get_event_loop(backend->display);

View File

@ -84,7 +84,7 @@ static void log_libinput(struct libinput *libinput_context,
static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_libinput_backend *backend =
get_libinput_backend_from_backend(wlr_backend);
wlr_log(WLR_DEBUG, "Initializing libinput");
wlr_log(WLR_DEBUG, "Starting libinput backend");
backend->libinput_context = libinput_udev_create_context(&libinput_impl,
backend, backend->session->udev);
@ -110,9 +110,9 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
no_devs = NULL;
}
}
if (!no_devs && backend->wlr_device_lists.length == 0) {
if (!no_devs && backend->wlr_device_lists.size == 0) {
handle_libinput_readable(libinput_fd, WL_EVENT_READABLE, backend);
if (backend->wlr_device_lists.length == 0) {
if (backend->wlr_device_lists.size == 0) {
wlr_log(WLR_ERROR, "libinput initialization failed, no input devices");
wlr_log(WLR_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check");
return false;
@ -141,13 +141,13 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_libinput_backend *backend =
get_libinput_backend_from_backend(wlr_backend);
for (size_t i = 0; i < backend->wlr_device_lists.length; i++) {
struct wl_list *wlr_devices = backend->wlr_device_lists.items[i];
struct wlr_input_device *wlr_dev, *next;
wl_list_for_each_safe(wlr_dev, next, wlr_devices, link) {
wlr_input_device_destroy(wlr_dev);
struct wl_list **wlr_devices_ptr;
wl_array_for_each(wlr_devices_ptr, &backend->wlr_device_lists) {
struct wlr_libinput_input_device *dev, *tmp;
wl_list_for_each_safe(dev, tmp, *wlr_devices_ptr, link) {
wlr_input_device_destroy(&dev->wlr_input_device);
}
free(wlr_devices);
free(*wlr_devices_ptr);
}
wlr_backend_finish(wlr_backend);
@ -156,7 +156,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
wl_list_remove(&backend->session_destroy.link);
wl_list_remove(&backend->session_signal.link);
wlr_list_finish(&backend->wlr_device_lists);
wl_array_release(&backend->wlr_device_lists);
if (backend->input_event) {
wl_event_source_remove(backend->input_event);
}
@ -211,10 +211,7 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
}
wlr_backend_init(&backend->backend, &backend_impl);
if (!wlr_list_init(&backend->wlr_device_lists)) {
wlr_log(WLR_ERROR, "Allocation failed: %s", strerror(errno));
goto error_backend;
}
wl_array_init(&backend->wlr_device_lists);
backend->session = session;
backend->display = display;
@ -229,9 +226,6 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
wl_display_add_destroy_listener(display, &backend->display_destroy);
return &backend->backend;
error_backend:
free(backend);
return NULL;
}
struct libinput_device *wlr_libinput_get_device_handle(

View File

@ -7,6 +7,7 @@
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/util/log.h>
#include "backend/libinput.h"
#include "util/array.h"
#include "util/signal.h"
static struct wlr_libinput_input_device *get_libinput_device_from_device(
@ -22,10 +23,10 @@ struct wlr_input_device *get_appropriate_device(
if (!wlr_devices) {
return NULL;
}
struct wlr_input_device *dev;
struct wlr_libinput_input_device *dev;
wl_list_for_each(dev, wlr_devices, link) {
if (dev->type == desired_type) {
return dev;
if (dev->wlr_input_device.type == desired_type) {
return &dev->wlr_input_device;
}
}
return NULL;
@ -35,7 +36,7 @@ static void input_device_destroy(struct wlr_input_device *wlr_dev) {
struct wlr_libinput_input_device *dev =
get_libinput_device_from_device(wlr_dev);
libinput_device_unref(dev->handle);
wl_list_remove(&dev->wlr_input_device.link);
wl_list_remove(&dev->link);
free(dev);
}
@ -62,7 +63,7 @@ static struct wlr_input_device *allocate_device(
if (output_name != NULL) {
wlr_dev->output_name = strdup(output_name);
}
wl_list_insert(wlr_devices, &wlr_dev->link);
wl_list_insert(wlr_devices, &dev->link);
dev->handle = libinput_dev;
libinput_device_ref(libinput_dev);
wlr_input_device_init(wlr_dev, type, &input_device_impl,
@ -183,8 +184,13 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
}
if (!wl_list_empty(wlr_devices)) {
struct wl_list **dst = wl_array_add(&backend->wlr_device_lists, sizeof(wlr_devices));
if (!dst) {
goto fail;
}
*dst = wlr_devices;
libinput_device_set_user_data(libinput_dev, wlr_devices);
wlr_list_push(&backend->wlr_device_lists, wlr_devices);
} else {
free(wlr_devices);
}
@ -192,7 +198,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
fail:
wlr_log(WLR_ERROR, "Could not allocate new device");
struct wlr_input_device *dev, *tmp_dev;
struct wlr_libinput_input_device *dev, *tmp_dev;
wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) {
free(dev);
}
@ -209,15 +215,20 @@ static void handle_device_removed(struct wlr_libinput_backend *backend,
if (!wlr_devices) {
return;
}
struct wlr_input_device *dev, *tmp_dev;
struct wlr_libinput_input_device *dev, *tmp_dev;
wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) {
wlr_input_device_destroy(dev);
wlr_input_device_destroy(&dev->wlr_input_device);
}
for (size_t i = 0; i < backend->wlr_device_lists.length; i++) {
if (backend->wlr_device_lists.items[i] == wlr_devices) {
wlr_list_del(&backend->wlr_device_lists, i);
size_t i = 0;
struct wl_list **ptr;
wl_array_for_each(ptr, &backend->wlr_device_lists) {
struct wl_list *iter = *ptr;
if (iter == wlr_devices) {
array_remove_at(&backend->wlr_device_lists,
i * sizeof(struct wl_list *), sizeof(struct wl_list *));
break;
}
i++;
}
free(wlr_devices);
}
@ -261,7 +272,7 @@ void handle_libinput_event(struct wlr_libinput_backend *backend,
handle_touch_cancel(event, libinput_dev);
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
// no-op (at least for now)
handle_touch_frame(event, libinput_dev);
break;
case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
handle_tablet_tool_axis(event, libinput_dev);
@ -305,6 +316,14 @@ void handle_libinput_event(struct wlr_libinput_backend *backend,
case LIBINPUT_EVENT_GESTURE_PINCH_END:
handle_pointer_pinch_end(event, libinput_dev);
break;
#if LIBINPUT_HAS_HOLD_GESTURES
case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN:
handle_pointer_hold_begin(event, libinput_dev);
break;
case LIBINPUT_EVENT_GESTURE_HOLD_END:
handle_pointer_hold_end(event, libinput_dev);
break;
#endif
default:
wlr_log(WLR_DEBUG, "Unknown libinput event %d", event_type);
break;

View File

@ -1,3 +1,19 @@
msg = ['Required for libinput backend support.']
if 'libinput' in backends
msg += 'Install "libinput" or disable the libinput backend.'
endif
libinput = dependency(
'libinput',
version: '>=1.14.0',
required: 'libinput' in backends,
not_found_message: '\n'.join(msg),
)
if not libinput.found()
subdir_done()
endif
wlr_files += files(
'backend.c',
'events.c',
@ -8,3 +24,12 @@ wlr_files += files(
'tablet_tool.c',
'touch.c',
)
features += { 'libinput-backend': true }
wlr_deps += libinput
# libinput hold gestures are available since 1.19.0
add_project_arguments(
'-DLIBINPUT_HAS_HOLD_GESTURES=@0@'.format(libinput.version().version_compare('>=1.19.0').to_int()),
language: 'c',
)

View File

@ -260,3 +260,41 @@ void handle_pointer_pinch_end(struct libinput_event *event,
};
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_end, &wlr_event);
}
void handle_pointer_hold_begin(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event);
struct wlr_event_pointer_hold_begin wlr_event = {
.device = wlr_dev,
.time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.fingers = libinput_event_gesture_get_finger_count(gevent),
};
wlr_signal_emit_safe(&wlr_dev->pointer->events.hold_begin, &wlr_event);
}
void handle_pointer_hold_end(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event);
struct wlr_event_pointer_hold_end wlr_event = {
.device = wlr_dev,
.time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.cancelled = libinput_event_gesture_get_cancelled(gevent),
};
wlr_signal_emit_safe(&wlr_dev->pointer->events.hold_end, &wlr_event);
}

View File

@ -85,7 +85,8 @@ struct wlr_tablet_pad *create_libinput_tablet_pad(
libinput_device_tablet_pad_get_num_strips(libinput_dev);
struct udev_device *udev = libinput_device_get_udev_device(libinput_dev);
wlr_list_push(&wlr_tablet_pad->paths, strdup(udev_device_get_syspath(udev)));
char **dst = wl_array_add(&wlr_tablet_pad->paths, sizeof(char *));
*dst = strdup(udev_device_get_syspath(udev));
int groups = libinput_device_tablet_pad_get_num_mode_groups(libinput_dev);
for (int i = 0; i < groups; ++i) {

View File

@ -11,6 +11,7 @@
#include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h>
#include "backend/libinput.h"
#include "util/array.h"
#include "util/signal.h"
static const struct wlr_tablet_impl tablet_impl;
@ -29,18 +30,9 @@ struct wlr_libinput_tablet_tool {
size_t pad_refs;
};
// TODO: Maybe this should be a wlr_list? Do we keep it, or want to get rid of
// it?
struct tablet_tool_list_elem {
struct wl_list link;
struct wlr_libinput_tablet_tool *tool;
};
struct wlr_libinput_tablet {
struct wlr_tablet wlr_tablet;
struct wl_list tools; // tablet_tool_list_elem::link
struct wl_array tools; // struct wlr_libinput_tablet_tool *
};
static void destroy_tool(struct wlr_libinput_tablet_tool *tool) {
@ -56,17 +48,14 @@ static void destroy_tablet(struct wlr_tablet *wlr_tablet) {
struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_tablet, tablet, wlr_tablet);
struct tablet_tool_list_elem *pos;
struct tablet_tool_list_elem *tmp;
wl_list_for_each_safe(pos, tmp, &tablet->tools, link) {
struct wlr_libinput_tablet_tool *tool = pos->tool;
wl_list_remove(&pos->link);
free(pos);
struct wlr_libinput_tablet_tool **tool_ptr;
wl_array_for_each(tool_ptr, &tablet->tools) {
struct wlr_libinput_tablet_tool *tool = *tool_ptr;
if (--tool->pad_refs == 0) {
destroy_tool(tool);
}
}
wl_array_release(&tablet->tools);
free(tablet);
}
@ -84,15 +73,18 @@ struct wlr_tablet *create_libinput_tablet(
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool");
return NULL;
}
struct wlr_tablet *wlr_tablet = &libinput_tablet->wlr_tablet;
wlr_list_init(&wlr_tablet->paths);
struct udev_device *udev = libinput_device_get_udev_device(libinput_dev);
wlr_list_push(&wlr_tablet->paths, strdup(udev_device_get_syspath(udev)));
wlr_tablet->name = strdup(libinput_device_get_name(libinput_dev));
wl_list_init(&libinput_tablet->tools);
wlr_tablet_init(wlr_tablet, &tablet_impl);
struct udev_device *udev = libinput_device_get_udev_device(libinput_dev);
char **dst = wl_array_add(&wlr_tablet->paths, sizeof(char *));
*dst = strdup(udev_device_get_syspath(udev));
wlr_tablet->name = strdup(libinput_device_get_name(libinput_dev));
wl_array_init(&libinput_tablet->tools);
return wlr_tablet;
}
@ -160,9 +152,9 @@ static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool,
struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_dev, tablet, wlr_tablet);
struct tablet_tool_list_elem *pos;
wl_list_for_each(pos, &tablet->tools, link) {
if (pos->tool == tool) { // We already have a ref
struct wlr_libinput_tablet_tool **tool_ptr;
wl_array_for_each(tool_ptr, &tablet->tools) {
if (*tool_ptr == tool) { // We already have a ref
// XXX: We *could* optimize the tool to the front of
// the list here, since we will probably get the next
// couple of events from the same tool.
@ -173,15 +165,13 @@ static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool,
}
}
struct tablet_tool_list_elem *new =
calloc(1, sizeof(struct tablet_tool_list_elem));
if (!new) {
struct wlr_libinput_tablet_tool **dst =
wl_array_add(&tablet->tools, sizeof(tool));
if (!dst) {
wlr_log(WLR_ERROR, "Failed to allocate memory for tracking tablet tool");
return;
}
new->tool = tool;
wl_list_insert(&tablet->tools, &new->link);
*dst = tool;
++tool->pad_refs;
}
@ -294,15 +284,15 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
assert(tablet_is_libinput(wlr_dev->tablet));
struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_dev->tablet, tablet, wlr_tablet);
struct tablet_tool_list_elem *pos;
struct tablet_tool_list_elem *tmp;
wl_list_for_each_safe(pos, tmp, &tablet->tools, link) {
if (pos->tool == tool) {
wl_list_remove(&pos->link);
free(pos);
size_t i = 0;
struct wlr_libinput_tablet_tool **tool_ptr;
wl_array_for_each(tool_ptr, &tablet->tools) {
if (*tool_ptr == tool) {
array_remove_at(&tablet->tools, i * sizeof(tool), sizeof(tool));
break;
}
i++;
}
destroy_tool(tool);

View File

@ -95,3 +95,14 @@ void handle_touch_cancel(struct libinput_event *event,
wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
wlr_signal_emit_safe(&wlr_dev->touch->events.cancel, &wlr_event);
}
void handle_touch_frame(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
return;
}
wlr_signal_emit_safe(&wlr_dev->touch->events.frame, NULL);
}

View File

@ -1,11 +1,21 @@
wlr_files += files('backend.c')
subdir('drm')
subdir('headless')
subdir('libinput')
all_backends = ['drm', 'libinput', 'x11']
backends = get_option('backends')
if 'auto' in backends and get_option('auto_features').enabled()
backends = all_backends
elif 'auto' in backends and get_option('auto_features').disabled()
backends = []
endif
foreach backend : all_backends
if backend in backends or 'auto' in backends
subdir(backend)
endif
endforeach
subdir('multi')
subdir('noop')
subdir('wayland')
subdir('x11')
subdir('headless')
subdir('session')

View File

@ -5,7 +5,9 @@
#include <time.h>
#include <wlr/backend/interface.h>
#include <wlr/backend/session.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/util/log.h>
#include "backend/backend.h"
#include "backend/multi.h"
#include "util/signal.h"
@ -62,20 +64,6 @@ static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
free(backend);
}
static struct wlr_renderer *multi_backend_get_renderer(
struct wlr_backend *backend) {
struct wlr_multi_backend *multi = multi_backend_from_backend(backend);
struct subbackend_state *sub;
wl_list_for_each(sub, &multi->backends, link) {
struct wlr_renderer *rend = wlr_backend_get_renderer(sub->backend);
if (rend != NULL) {
return rend;
}
}
return NULL;
}
static struct wlr_session *multi_backend_get_session(
struct wlr_backend *_backend) {
struct wlr_multi_backend *backend = multi_backend_from_backend(_backend);
@ -109,13 +97,35 @@ static int multi_backend_get_drm_fd(struct wlr_backend *backend) {
return -1;
}
static uint32_t multi_backend_get_buffer_caps(struct wlr_backend *backend) {
struct wlr_multi_backend *multi = multi_backend_from_backend(backend);
if (wl_list_empty(&multi->backends)) {
return 0;
}
uint32_t caps = WLR_BUFFER_CAP_DATA_PTR | WLR_BUFFER_CAP_DMABUF
| WLR_BUFFER_CAP_SHM;
struct subbackend_state *sub;
wl_list_for_each(sub, &multi->backends, link) {
uint32_t backend_caps = backend_get_buffer_caps(sub->backend);
if (backend_caps != 0) {
// only count backend capable of presenting a buffer
caps = caps & backend_caps;
}
}
return caps;
}
static const struct wlr_backend_impl backend_impl = {
.start = multi_backend_start,
.destroy = multi_backend_destroy,
.get_renderer = multi_backend_get_renderer,
.get_session = multi_backend_get_session,
.get_presentation_clock = multi_backend_get_presentation_clock,
.get_drm_fd = multi_backend_get_drm_fd,
.get_buffer_caps = multi_backend_get_buffer_caps,
};
static void handle_display_destroy(struct wl_listener *listener, void *data) {
@ -179,6 +189,9 @@ static struct subbackend_state *multi_backend_get_subbackend(struct wlr_multi_ba
bool wlr_multi_backend_add(struct wlr_backend *_multi,
struct wlr_backend *backend) {
assert(_multi && backend);
assert(_multi != backend);
struct wlr_multi_backend *multi = multi_backend_from_backend(_multi);
if (multi_backend_get_subbackend(multi, backend)) {
@ -186,15 +199,6 @@ bool wlr_multi_backend_add(struct wlr_backend *_multi,
return true;
}
struct wlr_renderer *multi_renderer =
multi_backend_get_renderer(&multi->backend);
struct wlr_renderer *backend_renderer = wlr_backend_get_renderer(backend);
if (multi_renderer != NULL && backend_renderer != NULL && multi_renderer != backend_renderer) {
wlr_log(WLR_ERROR, "Could not add backend: multiple renderers at the "
"same time aren't supported");
return false;
}
struct subbackend_state *sub = calloc(1, sizeof(struct subbackend_state));
if (sub == NULL) {
wlr_log(WLR_ERROR, "Could not add backend: allocation failed");

View File

@ -1,79 +0,0 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h>
#include "backend/noop.h"
#include "util/signal.h"
struct wlr_noop_backend *noop_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_noop(wlr_backend));
return (struct wlr_noop_backend *)wlr_backend;
}
static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_noop_backend *backend = noop_backend_from_backend(wlr_backend);
wlr_log(WLR_INFO, "Starting noop backend");
struct wlr_noop_output *output;
wl_list_for_each(output, &backend->outputs, link) {
wlr_output_update_enabled(&output->wlr_output, true);
wlr_signal_emit_safe(&backend->backend.events.new_output,
&output->wlr_output);
}
backend->started = true;
return true;
}
static void backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_noop_backend *backend = noop_backend_from_backend(wlr_backend);
if (!wlr_backend) {
return;
}
struct wlr_noop_output *output, *output_tmp;
wl_list_for_each_safe(output, output_tmp, &backend->outputs, link) {
wlr_output_destroy(&output->wlr_output);
}
wlr_backend_finish(wlr_backend);
wl_list_remove(&backend->display_destroy.link);
free(backend);
}
static const struct wlr_backend_impl backend_impl = {
.start = backend_start,
.destroy = backend_destroy,
};
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_noop_backend *noop =
wl_container_of(listener, noop, display_destroy);
backend_destroy(&noop->backend);
}
struct wlr_backend *wlr_noop_backend_create(struct wl_display *display) {
wlr_log(WLR_INFO, "Creating noop backend");
struct wlr_noop_backend *backend =
calloc(1, sizeof(struct wlr_noop_backend));
if (!backend) {
wlr_log(WLR_ERROR, "Failed to allocate wlr_noop_backend");
return NULL;
}
wlr_backend_init(&backend->backend, &backend_impl);
backend->display = display;
wl_list_init(&backend->outputs);
backend->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &backend->display_destroy);
return &backend->backend;
}
bool wlr_backend_is_noop(struct wlr_backend *backend) {
return backend->impl == &backend_impl;
}

View File

@ -1,4 +0,0 @@
wlr_files += files(
'backend.c',
'output.c',
)

View File

@ -1,98 +0,0 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h>
#include "backend/noop.h"
#include "util/signal.h"
static const uint32_t SUPPORTED_OUTPUT_STATE =
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
WLR_OUTPUT_STATE_MODE;
static struct wlr_noop_output *noop_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_noop(wlr_output));
return (struct wlr_noop_output *)wlr_output;
}
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
return false;
}
static void output_rollback_render(struct wlr_output *wlr_output) {
// This space is intentionally left blank
}
static bool output_commit(struct wlr_output *wlr_output) {
uint32_t unsupported =
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
if (unsupported != 0) {
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
unsupported);
return false;
}
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) {
assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM);
wlr_output_update_custom_mode(wlr_output,
wlr_output->pending.custom_mode.width,
wlr_output->pending.custom_mode.height,
wlr_output->pending.custom_mode.refresh);
}
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
return false;
}
return true;
}
static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_noop_output *output =
noop_output_from_output(wlr_output);
wl_list_remove(&output->link);
free(output);
}
static const struct wlr_output_impl output_impl = {
.destroy = output_destroy,
.attach_render = output_attach_render,
.rollback_render = output_rollback_render,
.commit = output_commit,
};
bool wlr_output_is_noop(struct wlr_output *wlr_output) {
return wlr_output->impl == &output_impl;
}
struct wlr_output *wlr_noop_add_output(struct wlr_backend *wlr_backend) {
struct wlr_noop_backend *backend = noop_backend_from_backend(wlr_backend);
struct wlr_noop_output *output = calloc(1, sizeof(struct wlr_noop_output));
if (output == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate wlr_noop_output");
return NULL;
}
output->backend = backend;
wlr_output_init(&output->wlr_output, &backend->backend, &output_impl,
backend->display);
struct wlr_output *wlr_output = &output->wlr_output;
strncpy(wlr_output->make, "noop", sizeof(wlr_output->make));
strncpy(wlr_output->model, "noop", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "NOOP-%zd",
++backend->last_output_num);
wl_list_insert(&backend->outputs, &output->link);
if (backend->started) {
wlr_output_update_enabled(wlr_output, true);
wlr_signal_emit_safe(&backend->backend.events.new_output, wlr_output);
}
return wlr_output;
}

View File

@ -139,6 +139,35 @@ static bool is_drm_card(const char *sysname) {
return true;
}
static void read_udev_change_event(struct wlr_device_change_event *event,
struct udev_device *udev_dev) {
const char *hotplug = udev_device_get_property_value(udev_dev, "HOTPLUG");
if (hotplug != NULL && strcmp(hotplug, "1") == 0) {
event->type = WLR_DEVICE_HOTPLUG;
struct wlr_device_hotplug_event *hotplug = &event->hotplug;
const char *connector =
udev_device_get_property_value(udev_dev, "CONNECTOR");
if (connector != NULL) {
hotplug->connector_id = strtoul(connector, NULL, 10);
}
const char *prop =
udev_device_get_property_value(udev_dev, "PROPERTY");
if (prop != NULL) {
hotplug->prop_id = strtoul(prop, NULL, 10);
}
return;
}
const char *lease = udev_device_get_property_value(udev_dev, "LEASE");
if (lease != NULL && strcmp(lease, "1") == 0) {
event->type = WLR_DEVICE_LEASE;
return;
}
}
static int handle_udev_event(int fd, uint32_t mask, void *data) {
struct wlr_session *session = data;
@ -180,7 +209,9 @@ static int handle_udev_event(int fd, uint32_t mask, void *data) {
if (strcmp(action, "change") == 0) {
wlr_log(WLR_DEBUG, "DRM device %s changed", sysname);
wlr_signal_emit_safe(&dev->events.change, NULL);
struct wlr_device_change_event event = {0};
read_udev_change_event(&event, udev_dev);
wlr_signal_emit_safe(&dev->events.change, &event);
} else if (strcmp(action, "remove") == 0) {
wlr_log(WLR_DEBUG, "DRM device %s removed", sysname);
wlr_signal_emit_safe(&dev->events.remove, NULL);
@ -339,7 +370,7 @@ bool wlr_session_change_vt(struct wlr_session *session, unsigned vt) {
/* Tests if 'path' is KMS compatible by trying to open it. Returns the opened
* device on success. */
static struct wlr_device *open_if_kms(struct wlr_session *restrict session,
struct wlr_device *session_open_if_kms(struct wlr_session *restrict session,
const char *restrict path) {
if (!path) {
return NULL;
@ -375,7 +406,7 @@ static ssize_t explicit_find_gpus(struct wlr_session *session,
break;
}
ret[i] = open_if_kms(session, ptr);
ret[i] = session_open_if_kms(session, ptr);
if (!ret[i]) {
wlr_log(WLR_ERROR, "Unable to open %s as DRM device", ptr);
} else {
@ -511,7 +542,7 @@ ssize_t wlr_session_find_gpus(struct wlr_session *session,
}
struct wlr_device *wlr_dev =
open_if_kms(session, udev_device_get_devnode(dev));
session_open_if_kms(session, udev_device_get_devnode(dev));
if (!wlr_dev) {
udev_device_unref(dev);
continue;

View File

@ -4,6 +4,8 @@
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
#include <drm_fourcc.h>
@ -15,24 +17,36 @@
#include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h>
#include "backend/backend.h"
#include "backend/wayland.h"
#include "render/allocator.h"
#include "render/drm_format_set.h"
#include "render/pixel_format.h"
#include "render/wlr_renderer.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
#include "drm-client-protocol.h"
#include "linux-dmabuf-unstable-v1-client-protocol.h"
#include "pointer-gestures-unstable-v1-client-protocol.h"
#include "presentation-time-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "tablet-unstable-v2-client-protocol.h"
#include "relative-pointer-unstable-v1-client-protocol.h"
struct wlr_wl_linux_dmabuf_feedback_v1 {
struct wlr_wl_backend *backend;
dev_t main_device_id;
struct wlr_wl_linux_dmabuf_v1_table_entry *format_table;
size_t format_table_size;
dev_t tranche_target_device_id;
};
struct wlr_wl_linux_dmabuf_v1_table_entry {
uint32_t format;
uint32_t pad; /* unused */
uint64_t modifier;
};
struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *backend) {
assert(wlr_backend_is_wl(backend));
return (struct wlr_wl_backend *)backend;
@ -78,6 +92,16 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = {
xdg_wm_base_handle_ping,
};
static void presentation_handle_clock_id(void *data,
struct wp_presentation *presentation, uint32_t clock) {
struct wlr_wl_backend *wl = data;
wl->presentation_clock = clock;
}
static const struct wp_presentation_listener presentation_listener = {
.clock_id = presentation_handle_clock_id,
};
static void linux_dmabuf_v1_handle_format(void *data,
struct zwp_linux_dmabuf_v1 *linux_dmabuf_v1, uint32_t format) {
// Note, this event is deprecated
@ -101,6 +125,119 @@ static const struct zwp_linux_dmabuf_v1_listener linux_dmabuf_v1_listener = {
.modifier = linux_dmabuf_v1_handle_modifier,
};
static void linux_dmabuf_feedback_v1_handle_done(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback) {
// This space is intentionally left blank
}
static void linux_dmabuf_feedback_v1_handle_format_table(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback, int fd, uint32_t size) {
struct wlr_wl_linux_dmabuf_feedback_v1 *feedback_data = data;
feedback_data->format_table = NULL;
void *table_data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (table_data == MAP_FAILED) {
wlr_log_errno(WLR_ERROR, "failed to mmap DMA-BUF format table");
} else {
feedback_data->format_table = table_data;
feedback_data->format_table_size = size;
}
close(fd);
}
static void linux_dmabuf_feedback_v1_handle_main_device(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback,
struct wl_array *dev_id_arr) {
struct wlr_wl_linux_dmabuf_feedback_v1 *feedback_data = data;
dev_t dev_id;
assert(dev_id_arr->size == sizeof(dev_id));
memcpy(&dev_id, dev_id_arr->data, sizeof(dev_id));
feedback_data->main_device_id = dev_id;
drmDevice *device = NULL;
if (drmGetDeviceFromDevId(dev_id, 0, &device) != 0) {
wlr_log_errno(WLR_ERROR, "drmGetDeviceFromDevId failed");
return;
}
const char *name = NULL;
if (device->available_nodes & (1 << DRM_NODE_RENDER)) {
name = device->nodes[DRM_NODE_RENDER];
} else {
// Likely a split display/render setup. Pick the primary node and hope
// Mesa will open the right render node under-the-hood.
assert(device->available_nodes & (1 << DRM_NODE_PRIMARY));
name = device->nodes[DRM_NODE_PRIMARY];
wlr_log(WLR_DEBUG, "DRM device %s has no render node, "
"falling back to primary node", name);
}
feedback_data->backend->drm_render_name = strdup(name);
drmFreeDevice(&device);
}
static void linux_dmabuf_feedback_v1_handle_tranche_done(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback) {
struct wlr_wl_linux_dmabuf_feedback_v1 *feedback_data = data;
feedback_data->tranche_target_device_id = 0;
}
static void linux_dmabuf_feedback_v1_handle_tranche_target_device(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback,
struct wl_array *dev_id_arr) {
struct wlr_wl_linux_dmabuf_feedback_v1 *feedback_data = data;
dev_t dev_id;
assert(dev_id_arr->size == sizeof(dev_id));
memcpy(&dev_id, dev_id_arr->data, sizeof(dev_id));
feedback_data->tranche_target_device_id = dev_id;
}
static void linux_dmabuf_feedback_v1_handle_tranche_formats(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback,
struct wl_array *indices_arr) {
struct wlr_wl_linux_dmabuf_feedback_v1 *feedback_data = data;
if (feedback_data->format_table == NULL) {
return;
}
if (feedback_data->tranche_target_device_id != feedback_data->main_device_id) {
return;
}
size_t table_cap = feedback_data->format_table_size /
sizeof(struct wlr_wl_linux_dmabuf_v1_table_entry);
uint16_t *index_ptr;
wl_array_for_each(index_ptr, indices_arr) {
assert(*index_ptr < table_cap);
const struct wlr_wl_linux_dmabuf_v1_table_entry *entry =
&feedback_data->format_table[*index_ptr];
wlr_drm_format_set_add(&feedback_data->backend->linux_dmabuf_v1_formats,
entry->format, entry->modifier);
}
}
static void linux_dmabuf_feedback_v1_handle_tranche_flags(void *data,
struct zwp_linux_dmabuf_feedback_v1 *feedback, uint32_t flags) {
// TODO: handle SCANOUT flag
}
static const struct zwp_linux_dmabuf_feedback_v1_listener
linux_dmabuf_feedback_v1_listener = {
.done = linux_dmabuf_feedback_v1_handle_done,
.format_table = linux_dmabuf_feedback_v1_handle_format_table,
.main_device = linux_dmabuf_feedback_v1_handle_main_device,
.tranche_done = linux_dmabuf_feedback_v1_handle_tranche_done,
.tranche_target_device = linux_dmabuf_feedback_v1_handle_tranche_target_device,
.tranche_formats = linux_dmabuf_feedback_v1_handle_tranche_formats,
.tranche_flags = linux_dmabuf_feedback_v1_handle_tranche_flags,
};
static bool device_has_name(const drmDevice *device, const char *name) {
for (size_t i = 0; i < DRM_NODE_MAX; i++) {
if (!(device->available_nodes & (1 << i))) {
@ -165,8 +302,6 @@ static char *get_render_name(const char *name) {
static void legacy_drm_handle_device(void *data, struct wl_drm *drm,
const char *name) {
struct wlr_wl_backend *wl = data;
// TODO: get FD from linux-dmabuf hints instead
wl->drm_render_name = get_render_name(name);
}
@ -226,17 +361,19 @@ static void registry_global(void *data, struct wl_registry *registry,
&zxdg_decoration_manager_v1_interface, 1);
} else if (strcmp(iface, zwp_pointer_gestures_v1_interface.name) == 0) {
wl->zwp_pointer_gestures_v1 = wl_registry_bind(registry, name,
&zwp_pointer_gestures_v1_interface, 1);
&zwp_pointer_gestures_v1_interface, version < 3 ? version : 3);
} else if (strcmp(iface, wp_presentation_interface.name) == 0) {
wl->presentation = wl_registry_bind(registry, name,
&wp_presentation_interface, 1);
wp_presentation_add_listener(wl->presentation,
&presentation_listener, wl);
} else if (strcmp(iface, zwp_tablet_manager_v2_interface.name) == 0) {
wl->tablet_manager = wl_registry_bind(registry, name,
&zwp_tablet_manager_v2_interface, 1);
} else if (strcmp(iface, zwp_linux_dmabuf_v1_interface.name) == 0 &&
version >= 3) {
wl->zwp_linux_dmabuf_v1 = wl_registry_bind(registry, name,
&zwp_linux_dmabuf_v1_interface, 3);
&zwp_linux_dmabuf_v1_interface, version >= 4 ? 4 : version);
zwp_linux_dmabuf_v1_add_listener(wl->zwp_linux_dmabuf_v1,
&linux_dmabuf_v1_listener, wl);
} else if (strcmp(iface, zwp_relative_pointer_manager_v1_interface.name) == 0) {
@ -248,6 +385,9 @@ static void registry_global(void *data, struct wl_registry *registry,
} else if (strcmp(iface, wl_shm_interface.name) == 0) {
wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
wl_shm_add_listener(wl->shm, &shm_listener, wl);
} else if (strcmp(iface, xdg_activation_v1_interface.name) == 0) {
wl->activation_v1 = wl_registry_bind(registry, name,
&xdg_activation_v1_interface, 1);
}
}
@ -268,7 +408,7 @@ static const struct wl_registry_listener registry_listener = {
*/
static bool backend_start(struct wlr_backend *backend) {
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
wlr_log(WLR_INFO, "Initializating wayland backend");
wlr_log(WLR_INFO, "Starting Wayland backend");
wl->started = true;
@ -302,9 +442,9 @@ static void backend_destroy(struct wlr_backend *backend) {
wlr_output_destroy(&output->wlr_output);
}
struct wlr_input_device *input_device, *tmp_input_device;
struct wlr_wl_input_device *input_device, *tmp_input_device;
wl_list_for_each_safe(input_device, tmp_input_device, &wl->devices, link) {
wlr_input_device_destroy(input_device);
wlr_input_device_destroy(&input_device->wlr_input_device);
}
struct wlr_wl_buffer *buffer, *tmp_buffer;
@ -343,6 +483,7 @@ static void backend_destroy(struct wlr_backend *backend) {
zwp_relative_pointer_manager_v1_destroy(wl->zwp_relative_pointer_manager_v1);
}
free(wl->drm_render_name);
free(wl->activation_token);
xdg_wm_base_destroy(wl->xdg_wm_base);
wl_compositor_destroy(wl->compositor);
wl_registry_destroy(wl->registry);
@ -351,6 +492,11 @@ static void backend_destroy(struct wlr_backend *backend) {
free(wl);
}
static clockid_t backend_get_presentation_clock(struct wlr_backend *backend) {
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
return wl->presentation_clock;
}
static int backend_get_drm_fd(struct wlr_backend *backend) {
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
return wl->drm_fd;
@ -365,6 +511,7 @@ static uint32_t get_buffer_caps(struct wlr_backend *backend) {
static const struct wlr_backend_impl backend_impl = {
.start = backend_start,
.destroy = backend_destroy,
.get_presentation_clock = backend_get_presentation_clock,
.get_drm_fd = backend_get_drm_fd,
.get_buffer_caps = get_buffer_caps,
};
@ -396,6 +543,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
wl_list_init(&wl->outputs);
wl_list_init(&wl->seats);
wl_list_init(&wl->buffers);
wl->presentation_clock = CLOCK_MONOTONIC;
wl->remote_display = wl_display_connect(remote);
if (!wl->remote_display) {
@ -408,10 +556,9 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
wlr_log_errno(WLR_ERROR, "Could not obtain reference to remote registry");
goto error_display;
}
wl_registry_add_listener(wl->registry, &registry_listener, wl);
wl_display_roundtrip(wl->remote_display); // get globals
wl_display_roundtrip(wl->remote_display); // get linux-dmabuf formats
if (!wl->compositor) {
wlr_log(WLR_ERROR,
@ -424,6 +571,35 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
goto error_registry;
}
struct zwp_linux_dmabuf_feedback_v1 *linux_dmabuf_feedback_v1 = NULL;
struct wlr_wl_linux_dmabuf_feedback_v1 feedback_data = { .backend = wl };
if (wl->zwp_linux_dmabuf_v1 != NULL &&
zwp_linux_dmabuf_v1_get_version(wl->zwp_linux_dmabuf_v1) >=
ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) {
linux_dmabuf_feedback_v1 =
zwp_linux_dmabuf_v1_get_default_feedback(wl->zwp_linux_dmabuf_v1);
if (linux_dmabuf_feedback_v1 == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
goto error_registry;
}
zwp_linux_dmabuf_feedback_v1_add_listener(linux_dmabuf_feedback_v1,
&linux_dmabuf_feedback_v1_listener, &feedback_data);
if (wl->legacy_drm != NULL) {
wl_drm_destroy(wl->legacy_drm);
wl->legacy_drm = NULL;
}
}
wl_display_roundtrip(wl->remote_display); // get linux-dmabuf formats
if (feedback_data.format_table != NULL) {
munmap(feedback_data.format_table, feedback_data.format_table_size);
}
if (linux_dmabuf_feedback_v1 != NULL) {
zwp_linux_dmabuf_feedback_v1_destroy(linux_dmabuf_feedback_v1);
}
struct wl_event_loop *loop = wl_display_get_event_loop(wl->local_display);
int fd = wl_display_get_fd(wl->remote_display);
wl->remote_display_src = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
@ -446,19 +622,17 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
wl->drm_fd = -1;
}
struct wlr_renderer *renderer = wlr_backend_get_renderer(&wl->backend);
struct wlr_allocator *allocator = backend_get_allocator(&wl->backend);
if (renderer == NULL || allocator == NULL) {
goto error_drm_fd;
}
wl->local_display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &wl->local_display_destroy);
const char *token = getenv("XDG_ACTIVATION_TOKEN");
if (token != NULL) {
wl->activation_token = strdup(token);
unsetenv("XDG_ACTIVATION_TOKEN");
}
return &wl->backend;
error_drm_fd:
close(wl->drm_fd);
error_remote_display_src:
wl_event_source_remove(wl->remote_display_src);
error_registry:

View File

@ -1,3 +1,9 @@
wayland_client = dependency('wayland-client',
fallback: ['wayland', 'wayland_client_dep'],
default_options: wayland_project_options,
)
wlr_deps += wayland_client
wlr_files += files(
'backend.c',
'output.c',
@ -12,6 +18,7 @@ client_protos = [
'presentation-time',
'relative-pointer-unstable-v1',
'tablet-unstable-v2',
'xdg-activation-v1',
'xdg-decoration-unstable-v1',
'xdg-shell',
]

View File

@ -19,11 +19,11 @@
#include "render/pixel_format.h"
#include "render/swapchain.h"
#include "render/wlr_renderer.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
#include "linux-dmabuf-unstable-v1-client-protocol.h"
#include "presentation-time-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
@ -76,6 +76,7 @@ static void presentation_feedback_handle_presented(void *data,
};
struct wlr_output_event_present event = {
.commit_seq = feedback->commit_seq,
.presented = true,
.when = &t,
.seq = ((uint64_t)seq_hi << 32) | seq_lo,
.refresh = refresh_ns,
@ -90,7 +91,11 @@ static void presentation_feedback_handle_discarded(void *data,
struct wp_presentation_feedback *wp_feedback) {
struct wlr_wl_presentation_feedback *feedback = data;
wlr_output_send_present(&feedback->output->wlr_output, NULL);
struct wlr_output_event_present event = {
.commit_seq = feedback->commit_seq,
.presented = false,
};
wlr_output_send_present(&feedback->output->wlr_output, &event);
presentation_feedback_destroy(feedback);
}
@ -161,18 +166,8 @@ static struct wl_buffer *import_dmabuf(struct wlr_wl_backend *wl,
dmabuf->offset[i], dmabuf->stride[i], modifier_hi, modifier_lo);
}
uint32_t flags = 0;
if (dmabuf->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) {
flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT;
}
if (dmabuf->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_INTERLACED) {
flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED;
}
if (dmabuf->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_BOTTOM_FIRST) {
flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST;
}
struct wl_buffer *wl_buffer = zwp_linux_buffer_params_v1_create_immed(
params, dmabuf->width, dmabuf->height, dmabuf->format, flags);
params, dmabuf->width, dmabuf->height, dmabuf->format, 0);
// TODO: handle create() errors
return wl_buffer;
}
@ -262,7 +257,6 @@ static bool output_test(struct wlr_output *wlr_output) {
}
if ((wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) &&
wlr_output->pending.buffer_type == WLR_OUTPUT_STATE_BUFFER_SCANOUT &&
!test_buffer(output->backend, wlr_output->pending.buffer)) {
return false;
}
@ -288,9 +282,6 @@ static bool output_commit(struct wlr_output *wlr_output) {
}
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
assert(wlr_output->pending.buffer_type ==
WLR_OUTPUT_STATE_BUFFER_SCANOUT);
struct wp_presentation_feedback *wp_feedback = NULL;
if (output->backend->presentation != NULL) {
wp_feedback = wp_presentation_feedback(output->backend->presentation,
@ -350,7 +341,11 @@ static bool output_commit(struct wlr_output *wlr_output) {
wp_presentation_feedback_add_listener(wp_feedback,
&presentation_feedback_listener, feedback);
} else {
wlr_output_send_present(wlr_output, NULL);
struct wlr_output_event_present present_event = {
.commit_seq = wlr_output->commit_seq + 1,
.presented = true,
};
wlr_output_send_present(wlr_output, &present_event);
}
}
@ -525,12 +520,14 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
wlr_output_update_custom_mode(wlr_output, 1280, 720, 0);
strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make));
strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%zd",
++backend->last_output_num);
char name[64];
snprintf(name, sizeof(name), "WL-%zu", ++backend->last_output_num);
wlr_output_set_name(wlr_output, name);
char description[128];
snprintf(description, sizeof(description),
"Wayland output %zd", backend->last_output_num);
"Wayland output %zu", backend->last_output_num);
wlr_output_set_description(wlr_output, description);
output->backend = backend;
@ -590,6 +587,12 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
}
}
// TODO: let the compositor do this bit
if (backend->activation_v1 && backend->activation_token) {
xdg_activation_v1_activate(backend->activation_v1,
backend->activation_token, output->surface);
}
// Start the rendering loop by requesting the compositor to render a frame
wlr_output_schedule_frame(wlr_output);

View File

@ -25,12 +25,13 @@
static struct wlr_wl_pointer *output_get_pointer(
struct wlr_wl_output *output,
const struct wl_pointer *wl_pointer) {
struct wlr_input_device *wlr_dev;
wl_list_for_each(wlr_dev, &output->backend->devices, link) {
if (wlr_dev->type != WLR_INPUT_DEVICE_POINTER) {
struct wlr_wl_input_device *dev;
wl_list_for_each(dev, &output->backend->devices, link) {
if (dev->wlr_input_device.type != WLR_INPUT_DEVICE_POINTER) {
continue;
}
struct wlr_wl_pointer *pointer = pointer_get_wl(wlr_dev->pointer);
struct wlr_wl_pointer *pointer =
pointer_get_wl(dev->wlr_input_device.pointer);
if (pointer->output == output && pointer->wl_pointer == wl_pointer) {
return pointer;
}
@ -352,7 +353,10 @@ static void touch_handle_motion(void *data, struct wl_touch *wl_touch,
}
static void touch_handle_frame(void *data, struct wl_touch *wl_touch) {
// no-op
struct wlr_wl_input_device *device = data;
assert(device && device->wlr_input_device.touch);
wlr_signal_emit_safe(&device->wlr_input_device.touch->events.frame, NULL);
}
static void touch_handle_cancel(void *data, struct wl_touch *wl_touch) {
@ -437,7 +441,7 @@ static void input_device_destroy(struct wlr_input_device *wlr_dev) {
}
// We can't destroy pointer here because we might have multiple devices
// exposing it to compositor.
wl_list_remove(&dev->wlr_input_device.link);
wl_list_remove(&dev->link);
free(dev);
}
@ -464,13 +468,36 @@ struct wlr_wl_input_device *create_wl_input_device(
unsigned int vendor = 0, product = 0;
size_t name_size = 8 + strlen(seat->name) + 1;
const char *type_name = "unknown";
switch (type) {
case WLR_INPUT_DEVICE_KEYBOARD:
type_name = "keyboard";
break;
case WLR_INPUT_DEVICE_POINTER:
type_name = "pointer";
break;
case WLR_INPUT_DEVICE_TOUCH:
type_name = "touch";
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
type_name = "tablet-tool";
break;
case WLR_INPUT_DEVICE_TABLET_PAD:
type_name = "tablet-pad";
break;
case WLR_INPUT_DEVICE_SWITCH:
type_name = "switch";
break;
}
size_t name_size = 8 + strlen(type_name) + strlen(seat->name) + 1;
char name[name_size];
(void) snprintf(name, name_size, "wayland-%s", seat->name);
(void) snprintf(name, name_size, "wayland-%s-%s", type_name, seat->name);
wlr_input_device_init(wlr_dev, type, &input_device_impl, name, vendor,
product);
wl_list_insert(&seat->backend->devices, &wlr_dev->link);
wl_list_insert(&seat->backend->devices, &dev->link);
return dev;
}
@ -493,6 +520,21 @@ static void pointer_destroy(struct wlr_pointer *wlr_pointer) {
seat->active_pointer = NULL;
}
// pointer->wl_pointer belongs to the wlr_wl_seat
if (pointer->gesture_swipe != NULL) {
zwp_pointer_gesture_swipe_v1_destroy(pointer->gesture_swipe);
}
if (pointer->gesture_pinch != NULL) {
zwp_pointer_gesture_pinch_v1_destroy(pointer->gesture_pinch);
}
if (pointer->gesture_hold != NULL) {
zwp_pointer_gesture_hold_v1_destroy(pointer->gesture_hold);
}
if (pointer->relative_pointer != NULL) {
zwp_relative_pointer_v1_destroy(pointer->relative_pointer);
}
wl_list_remove(&pointer->output_destroy.link);
free(pointer);
}
@ -601,6 +643,38 @@ static const struct zwp_pointer_gesture_pinch_v1_listener gesture_pinch_impl = {
.end = gesture_pinch_end,
};
static void gesture_hold_begin(void *data,
struct zwp_pointer_gesture_hold_v1 *zwp_pointer_gesture_hold_v1,
uint32_t serial, uint32_t time,
struct wl_surface *surface, uint32_t fingers) {
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
struct wlr_event_pointer_hold_begin wlr_event = {
.device = wlr_dev,
.time_msec = time,
.fingers = fingers,
};
input_device->fingers = fingers;
wlr_signal_emit_safe(&wlr_dev->pointer->events.hold_begin, &wlr_event);
}
static void gesture_hold_end(void *data,
struct zwp_pointer_gesture_hold_v1 *zwp_pointer_gesture_hold_v1,
uint32_t serial, uint32_t time, int32_t cancelled) {
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
struct wlr_event_pointer_hold_end wlr_event = {
.device = wlr_dev,
.time_msec = time,
.cancelled = cancelled,
};
wlr_signal_emit_safe(&wlr_dev->pointer->events.hold_end, &wlr_event);
}
static const struct zwp_pointer_gesture_hold_v1_listener gesture_hold_impl = {
.begin = gesture_hold_begin,
.end = gesture_hold_end,
};
static void relative_pointer_handle_relative_motion(void *data,
struct zwp_relative_pointer_v1 *relative_pointer, uint32_t utime_hi,
@ -634,9 +708,6 @@ static void pointer_handle_output_destroy(struct wl_listener *listener,
void *data) {
struct wlr_wl_pointer *pointer =
wl_container_of(listener, pointer, output_destroy);
if (pointer->relative_pointer) {
zwp_relative_pointer_v1_destroy(pointer->relative_pointer);
}
wlr_input_device_destroy(&pointer->input_device->wlr_input_device);
}
@ -678,12 +749,21 @@ void create_wl_pointer(struct wlr_wl_seat *seat, struct wlr_wl_output *output) {
wlr_pointer_init(wlr_dev->pointer, &pointer_impl);
if (backend->zwp_pointer_gestures_v1) {
uint32_t version = zwp_pointer_gestures_v1_get_version(
backend->zwp_pointer_gestures_v1);
pointer->gesture_swipe = zwp_pointer_gestures_v1_get_swipe_gesture(
backend->zwp_pointer_gestures_v1, wl_pointer);
zwp_pointer_gesture_swipe_v1_add_listener(pointer->gesture_swipe, &gesture_swipe_impl, dev);
pointer->gesture_pinch = zwp_pointer_gestures_v1_get_pinch_gesture(
backend->zwp_pointer_gestures_v1, wl_pointer);
zwp_pointer_gesture_pinch_v1_add_listener(pointer->gesture_pinch, &gesture_pinch_impl, dev);
if (version >= ZWP_POINTER_GESTURES_V1_GET_HOLD_GESTURE) {
pointer->gesture_hold = zwp_pointer_gestures_v1_get_hold_gesture(
backend->zwp_pointer_gestures_v1, wl_pointer);
zwp_pointer_gesture_hold_v1_add_listener(pointer->gesture_hold, &gesture_hold_impl, dev);
}
}
if (backend->zwp_relative_pointer_manager_v1) {
@ -766,19 +846,20 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
struct wl_pointer *wl_pointer = seat->pointer;
struct wlr_input_device *device, *tmp;
struct wlr_wl_input_device *device, *tmp;
wl_list_for_each_safe(device, tmp, &backend->devices, link) {
if (device->type != WLR_INPUT_DEVICE_POINTER) {
if (device->wlr_input_device.type != WLR_INPUT_DEVICE_POINTER) {
continue;
}
struct wlr_wl_pointer *pointer = pointer_get_wl(device->pointer);
struct wlr_wl_pointer *pointer =
pointer_get_wl(device->wlr_input_device.pointer);
if (pointer->wl_pointer != wl_pointer) {
continue;
}
wlr_log(WLR_DEBUG, "dropping pointer %s",
pointer->input_device->wlr_input_device.name);
struct wlr_wl_output *output = pointer->output;
wlr_input_device_destroy(device);
wlr_input_device_destroy(&device->wlr_input_device);
assert(seat->active_pointer != pointer);
assert(output->cursor.pointer != pointer);
}
@ -800,18 +881,16 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard != NULL) {
wlr_log(WLR_DEBUG, "seat %p dropped keyboard", (void *)wl_seat);
struct wlr_input_device *device, *tmp;
struct wlr_wl_input_device *device, *tmp;
wl_list_for_each_safe(device, tmp, &backend->devices, link) {
if (device->type != WLR_INPUT_DEVICE_KEYBOARD) {
if (device->wlr_input_device.type != WLR_INPUT_DEVICE_KEYBOARD) {
continue;
}
struct wlr_wl_input_device *input_device =
get_wl_input_device_from_input_device(device);
if (input_device->seat != seat) {
if (device->seat != seat) {
continue;
}
wlr_input_device_destroy(device);
wlr_input_device_destroy(&device->wlr_input_device);
}
assert(seat->keyboard == NULL); // free'ed by input_device_destroy
}
@ -827,10 +906,10 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch != NULL) {
wlr_log(WLR_DEBUG, "seat %p dropped touch", (void *)wl_seat);
struct wlr_input_device *device, *tmp;
struct wlr_wl_input_device *device, *tmp;
wl_list_for_each_safe(device, tmp, &backend->devices, link) {
if (device->type == WLR_INPUT_DEVICE_TOUCH) {
wlr_input_device_destroy(device);
if (device->wlr_input_device.type == WLR_INPUT_DEVICE_TOUCH) {
wlr_input_device_destroy(&device->wlr_input_device);
}
}

View File

@ -336,7 +336,8 @@ static void handle_tablet_pad_path(void *data,
struct wlr_wl_input_device *dev = data;
struct wlr_tablet_pad *tablet_pad = dev->wlr_input_device.tablet_pad;
wlr_list_push(&tablet_pad->paths, strdup(path));
char **dst = wl_array_add(&tablet_pad->paths, sizeof(char *));
*dst = strdup(path);
}
static void handle_tablet_pad_buttons(void *data,
@ -401,7 +402,7 @@ static void handle_tablet_pad_removed(void *data,
/* This doesn't free anything, but emits the destroy signal */
wlr_input_device_destroy(&dev->wlr_input_device);
/* This is a bit ugly, but we need to remove it from our list */
wl_list_remove(&dev->wlr_input_device.link);
wl_list_remove(&dev->link);
struct wlr_wl_tablet_pad_group *group, *it;
wl_list_for_each_safe(group, it, &tablet_pad->groups, group.link) {
@ -854,7 +855,8 @@ static void handle_tablet_path(void *data, struct zwp_tablet_v2 *zwp_tablet_v2,
struct wlr_wl_input_device *dev = data;
struct wlr_tablet *tablet = dev->wlr_input_device.tablet;
wlr_list_push(&tablet->paths, strdup(path));
char **dst = wl_array_add(&tablet->paths, sizeof(char *));
*dst = strdup(path);
}
static void handle_tablet_done(void *data, struct zwp_tablet_v2 *zwp_tablet_v2) {
@ -871,7 +873,7 @@ static void handle_tablet_removed(void *data,
/* This doesn't free anything, but emits the destroy signal */
wlr_input_device_destroy(&dev->wlr_input_device);
/* This is a bit ugly, but we need to remove it from our list */
wl_list_remove(&dev->wlr_input_device.link);
wl_list_remove(&dev->link);
zwp_tablet_v2_destroy(dev->resource);
free(dev);

View File

@ -29,11 +29,8 @@
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/util/log.h>
#include "backend/backend.h"
#include "backend/x11.h"
#include "render/allocator.h"
#include "render/drm_format_set.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
// See dri2_format_for_depth in mesa
@ -166,6 +163,8 @@ static bool backend_start(struct wlr_backend *backend) {
struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
x11->started = true;
wlr_log(WLR_INFO, "Starting X11 backend");
wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->keyboard_dev);
for (size_t i = 0; i < x11->requested_outputs; ++i) {
@ -355,6 +354,7 @@ static bool query_formats(struct wlr_x11_backend *x11) {
}
if (x11->have_dri3) {
// X11 always supports implicit modifiers
wlr_drm_format_set_add(&x11->dri3_formats, format->drm,
DRM_FORMAT_MOD_INVALID);
if (!query_dri3_modifiers(x11, format)) {
@ -573,9 +573,9 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
goto error_event;
}
x11->depth = get_depth(x11->screen, 32);
x11->depth = get_depth(x11->screen, 24);
if (!x11->depth) {
wlr_log(WLR_ERROR, "Failed to get 32-bit depth for X11 screen");
wlr_log(WLR_ERROR, "Failed to get 24-bit depth for X11 screen");
goto error_event;
}
@ -611,12 +611,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
}
}
struct wlr_renderer *renderer = wlr_backend_get_renderer(&x11->backend);
struct wlr_allocator *allocator = backend_get_allocator(&x11->backend);
if (renderer == NULL || allocator == NULL) {
goto error_event;
}
// Windows can only display buffers with the depth they were created with
// TODO: look into changing the window's depth at runtime
const struct wlr_drm_format *dri3_format =

View File

@ -79,6 +79,7 @@ static void send_touch_down_event(struct wlr_x11_output *output,
.touch_id = touch_id,
};
wlr_signal_emit_safe(&output->touch.events.down, &ev);
wlr_signal_emit_safe(&output->touch.events.frame, NULL);
}
static void send_touch_motion_event(struct wlr_x11_output *output,
@ -91,6 +92,7 @@ static void send_touch_motion_event(struct wlr_x11_output *output,
.touch_id = touch_id,
};
wlr_signal_emit_safe(&output->touch.events.motion, &ev);
wlr_signal_emit_safe(&output->touch.events.frame, NULL);
}
static void send_touch_up_event(struct wlr_x11_output *output,
@ -101,10 +103,11 @@ static void send_touch_up_event(struct wlr_x11_output *output,
.touch_id = touch_id,
};
wlr_signal_emit_safe(&output->touch.events.up, &ev);
wlr_signal_emit_safe(&output->touch.events.frame, NULL);
}
static struct wlr_x11_touchpoint* get_touchpoint_from_x11_touch_id(struct wlr_x11_output *output,
uint32_t id) {
static struct wlr_x11_touchpoint *get_touchpoint_from_x11_touch_id(
struct wlr_x11_output *output, uint32_t id) {
struct wlr_x11_touchpoint *touchpoint;
wl_list_for_each(touchpoint, &output->touchpoints, link) {
if (touchpoint->x11_id == id) {

View File

@ -10,17 +10,14 @@ x11_required = [
'xcb-xinput',
]
msg = []
if get_option('x11-backend').enabled()
msg += 'Install "@0@" or pass "-Dx11-backend=disabled" to disable it.'
endif
if not get_option('x11-backend').disabled()
msg += 'Required for X11 backend support.'
msg = ['Required for X11 backend support.']
if 'x11' in backends
msg += 'Install "@0@" or disable the X11 backend.'
endif
foreach lib : x11_required
dep = dependency(lib,
required: get_option('x11-backend'),
required: 'x11' in backends,
not_found_message: '\n'.join(msg).format(lib),
)
if not dep.found()

View File

@ -21,7 +21,6 @@
#include <wlr/util/log.h>
#include "backend/x11.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
#include "util/time.h"
@ -141,10 +140,6 @@ static xcb_pixmap_t import_dmabuf(struct wlr_x11_output *output,
return XCB_PIXMAP_NONE;
}
if (dmabuf->flags != 0) {
return XCB_PIXMAP_NONE;
}
// xcb closes the FDs after sending them, so we need to dup them here
struct wlr_dmabuf_attributes dup_attrs = {0};
if (!wlr_dmabuf_attributes_copy(&dup_attrs, dmabuf)) {
@ -258,9 +253,6 @@ static struct wlr_x11_buffer *get_or_create_x11_buffer(
static bool output_commit_buffer(struct wlr_x11_output *output) {
struct wlr_x11_backend *x11 = output->x11;
assert(output->wlr_output.pending.buffer_type ==
WLR_OUTPUT_STATE_BUFFER_SCANOUT);
struct wlr_buffer *buffer = output->wlr_output.pending.buffer;
struct wlr_x11_buffer *x11_buffer =
get_or_create_x11_buffer(output, buffer);
@ -384,7 +376,7 @@ static void update_x11_output_cursor(struct wlr_x11_output *output,
static bool output_cursor_to_picture(struct wlr_x11_output *output,
struct wlr_buffer *buffer) {
struct wlr_x11_backend *x11 = output->x11;
struct wlr_renderer *renderer = wlr_backend_get_renderer(&x11->backend);
struct wlr_renderer *renderer = output->wlr_output.renderer;
if (output->cursor.pic != XCB_NONE) {
xcb_render_free_picture(x11->xcb, output->cursor.pic);
@ -520,13 +512,15 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
wlr_output_update_custom_mode(wlr_output, 1024, 768, 0);
snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%zd",
++x11->last_output_num);
char name[64];
snprintf(name, sizeof(name), "X11-%zu", ++x11->last_output_num);
wlr_output_set_name(wlr_output, name);
parse_xcb_setup(wlr_output, x11->xcb);
char description[128];
snprintf(description, sizeof(description),
"X11 output %zd", x11->last_output_num);
"X11 output %zu", x11->last_output_num);
wlr_output_set_description(wlr_output, description);
// The X11 protocol requires us to set a colormap and border pixel if the
@ -694,9 +688,11 @@ void handle_x11_present_event(struct wlr_x11_backend *x11,
flags |= WLR_OUTPUT_PRESENT_ZERO_COPY;
}
bool presented = complete_notify->mode != XCB_PRESENT_COMPLETE_MODE_SKIP;
struct wlr_output_event_present present_event = {
.output = &output->wlr_output,
.commit_seq = complete_notify->serial,
.presented = presented,
.when = &t,
.seq = complete_notify->msc,
.flags = flags,

View File

@ -3,14 +3,15 @@ wlroots reads these environment variables
# wlroots specific
* *WLR_BACKENDS*: comma-separated list of backends to use (available backends:
libinput, drm, wayland, x11, headless, noop)
libinput, drm, wayland, x11, headless)
* *WLR_NO_HARDWARE_CURSORS*: set to 1 to use software cursors instead of
hardware cursors
* *WLR_DIRECT_TTY*: specifies the tty to be used (instead of using /dev/tty)
* *WLR_XWAYLAND*: specifies the path to an Xwayland binary to be used (instead
of following shell search semantics for "Xwayland")
* *WLR_RENDERER*: forces the creation of a specified renderer (available
renderers: gles2, pixman)
renderers: gles2, pixman, vulkan)
* *WLR_RENDER_DRM_DEVICE*: specifies the DRM node to use for
hardware-accelerated renderers.
## DRM backend

View File

@ -128,6 +128,11 @@ static void print_toplevel_state(struct toplevel_v1 *toplevel, bool print_endl)
}
}
static void finish_toplevel_state(struct toplevel_state *state) {
free(state->title);
free(state->app_id);
}
static void toplevel_handle_title(void *data,
struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel,
const char *title) {
@ -228,6 +233,9 @@ static void toplevel_handle_closed(void *data,
printf(" closed\n");
zwlr_foreign_toplevel_handle_v1_destroy(zwlr_toplevel);
finish_toplevel_state(&toplevel->current);
finish_toplevel_state(&toplevel->pending);
free(toplevel);
}
static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_impl = {

View File

@ -7,6 +7,7 @@
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_fullscreen_shell_v1.h>
@ -14,6 +15,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
/**
@ -24,6 +26,7 @@ struct fullscreen_server {
struct wl_display *wl_display;
struct wlr_backend *backend;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_fullscreen_shell_v1 *fullscreen_shell;
struct wl_listener present_surface;
@ -46,7 +49,6 @@ struct fullscreen_output {
struct render_data {
struct wlr_output *output;
struct wlr_renderer *renderer;
struct tinywl_view *view;
struct timespec *when;
};
@ -146,6 +148,8 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
wl_container_of(listener, server, new_output);
struct wlr_output *wlr_output = data;
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct fullscreen_output *output =
calloc(1, sizeof(struct fullscreen_output));
output->wlr_output = wlr_output;
@ -203,8 +207,10 @@ int main(int argc, char *argv[]) {
struct fullscreen_server server = {0};
server.wl_display = wl_display_create();
server.backend = wlr_backend_autocreate(server.wl_display);
server.renderer = wlr_backend_get_renderer(server.backend);
server.renderer = wlr_renderer_autocreate(server.backend);
wlr_renderer_init_wl_display(server.renderer, server.wl_display);
server.allocator = wlr_allocator_autocreate(server.backend,
server.renderer);
wlr_compositor_create(server.wl_display, server.renderer);

View File

@ -11,7 +11,6 @@
#include <wayland-client.h>
#include <wayland-cursor.h>
#include <wayland-egl.h>
#include <wlr/util/log.h>
#include "egl_common.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
@ -177,8 +176,7 @@ static const struct xdg_surface_listener xdg_surface_listener = {
static void xdg_popup_configure(void *data, struct xdg_popup *xdg_popup,
int32_t x, int32_t y, int32_t width, int32_t height) {
wlr_log(WLR_DEBUG, "Popup configured %dx%d@%d,%d",
width, height, x, y);
fprintf(stderr, "Popup configured %dx%d@%d,%d\n", width, height, x, y);
popup_width = width;
popup_height = height;
if (popup_egl_window) {
@ -197,7 +195,7 @@ static void popup_destroy(void) {
}
static void xdg_popup_done(void *data, struct xdg_popup *xdg_popup) {
wlr_log(WLR_DEBUG, "Popup done");
fprintf(stderr, "Popup done\n");
popup_destroy();
}
@ -377,17 +375,17 @@ static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
wlr_log(WLR_DEBUG, "Keyboard enter");
fprintf(stderr, "Keyboard enter\n");
}
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface) {
wlr_log(WLR_DEBUG, "Keyboard leave");
fprintf(stderr, "Keyboard leave\n");
}
static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
wlr_log(WLR_DEBUG, "Key event: %d %d", key, state);
fprintf(stderr, "Key event: %d %d\n", key, state);
}
static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
@ -473,7 +471,6 @@ static const struct wl_registry_listener registry_listener = {
};
int main(int argc, char **argv) {
wlr_log_init(WLR_DEBUG, NULL);
char *namespace = "wlroots";
int exclusive_zone = 0;
int32_t margin_right = 0, margin_bottom = 0, margin_left = 0;

View File

@ -1,6 +1,7 @@
threads = dependency('threads')
wayland_egl = dependency('wayland-egl')
wayland_cursor = dependency('wayland-cursor')
wayland_client = dependency('wayland-client')
libpng = dependency('libpng', required: false, disabler: true)
egl = dependency('egl', required: false, disabler: true)
glesv2 = dependency('glesv2', required: false, disabler: true)
@ -51,6 +52,10 @@ compositors = {
'quads': {
'src': 'quads.c',
},
'scene-graph': {
'src': 'scene-graph.c',
'proto': ['xdg-shell'],
},
}
clients = {
@ -77,7 +82,7 @@ clients = {
},
'layer-shell': {
'src': ['layer-shell.c', 'egl_common.c'],
'dep': [wayland_egl, wayland_cursor, wlroots, egl, glesv2],
'dep': [wayland_egl, wayland_cursor, egl, glesv2],
'proto': [
'wlr-layer-shell-unstable-v1',
'xdg-shell',
@ -98,7 +103,7 @@ clients = {
},
'output-power-management': {
'src': 'output-power-management.c',
'dep': [wayland_client, wlroots],
'dep': [wayland_client],
'proto': ['wlr-output-power-management-unstable-v1'],
},
'pointer-constraints': {
@ -124,7 +129,7 @@ clients = {
libavcodec,
libavformat,
libavutil,
drm.partial_dependency(compile_args: true), # <drm_fourcc.h>
drm,
threads,
],
'proto': ['wlr-export-dmabuf-unstable-v1'],
@ -169,12 +174,10 @@ clients = {
},
'foreign-toplevel': {
'src': 'foreign-toplevel.c',
'dep': [wlroots],
'proto': ['wlr-foreign-toplevel-management-unstable-v1'],
},
'virtual-pointer': {
'src': 'virtual-pointer.c',
'dep': wlroots,
'proto': ['wlr-virtual-pointer-unstable-v1'],
},
'input-method-keyboard-grab': {
@ -211,7 +214,7 @@ foreach name, info : clients
executable(
name,
[info.get('src'), extra_src],
dependencies: [wayland_client, info.get('dep')],
dependencies: [wayland_client, info.get('dep', [])],
build_by_default: get_option('examples'),
)
endforeach

View File

@ -9,10 +9,10 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_list.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_pointer.h>
@ -23,6 +23,8 @@
struct sample_state {
struct wl_display *display;
struct wlr_xcursor *xcursor;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
float default_color[4];
float clear_color[4];
struct wlr_output_layout *layout;
@ -91,7 +93,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
struct sample_output *output = wl_container_of(listener, output, frame);
struct sample_state *sample = output->sample;
struct wlr_output *wlr_output = output->output;
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
struct wlr_renderer *renderer = sample->renderer;
wlr_output_attach_render(wlr_output, NULL);
@ -145,6 +147,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output;
sample_output->sample = sample;
@ -270,6 +275,10 @@ int main(int argc, char *argv[]) {
if (!wlr) {
exit(1);
}
state.renderer = wlr_renderer_autocreate(wlr);
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
wl_list_init(&state.cursors);
wl_list_init(&state.pointers);
wl_list_init(&state.outputs);

View File

@ -11,12 +11,14 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
#include "cat.h"
@ -26,6 +28,7 @@ struct sample_state {
struct wl_listener new_output;
struct wl_listener new_input;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_texture *cat_texture;
struct wlr_output_layout *layout;
float x_offs, y_offs;
@ -157,6 +160,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
wlr_output_layout_add_auto(sample->layout, output);
sample_output->output = output;
@ -272,11 +278,13 @@ int main(int argc, char *argv[]) {
wl_signal_add(&wlr->events.new_input, &state.new_input);
state.new_input.notify = new_input_notify;
state.renderer = wlr_backend_get_renderer(wlr);
state.renderer = wlr_renderer_autocreate(wlr);
state.cat_texture = wlr_texture_from_pixels(state.renderer,
DRM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
cat_tex.pixel_data);
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
if (!wlr_backend_start(wlr)) {
wlr_log(WLR_ERROR, "Failed to start backend");
wlr_backend_destroy(wlr);

View File

@ -9,10 +9,10 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_list.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_pointer.h>
@ -25,6 +25,8 @@
struct sample_state {
struct wl_display *display;
struct compositor_state *compositor;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_xcursor_manager *xcursor_manager;
struct wlr_cursor *cursor;
double cur_x, cur_y;
@ -96,7 +98,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
struct sample_output *sample_output = wl_container_of(listener, sample_output, frame);
struct sample_state *state = sample_output->state;
struct wlr_output *wlr_output = sample_output->output;
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
struct wlr_renderer *renderer = state->renderer;
assert(renderer);
wlr_output_attach_render(wlr_output, NULL);
@ -251,6 +253,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output;
sample_output->state = sample;
@ -332,6 +337,10 @@ int main(int argc, char *argv[]) {
if (!wlr) {
exit(1);
}
state.renderer = wlr_renderer_autocreate(wlr);
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
state.cursor = wlr_cursor_create();
state.layout = wlr_output_layout_create();
wlr_cursor_attach_output_layout(state.cursor, state.layout);

View File

@ -9,11 +9,13 @@
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
@ -23,6 +25,7 @@ struct sample_state {
struct wl_listener new_input;
struct timespec last_frame;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wl_list outputs;
};
@ -102,6 +105,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
struct wlr_output_mode *mode = wlr_output_preferred_mode(output);
@ -194,13 +200,15 @@ int main(int argc, char *argv[]) {
state.new_input.notify = new_input_notify;
clock_gettime(CLOCK_MONOTONIC, &state.last_frame);
state.renderer = wlr_backend_get_renderer(wlr);
state.renderer = wlr_renderer_autocreate(wlr);
if (!state.renderer) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM");
wlr_backend_destroy(wlr);
exit(EXIT_FAILURE);
}
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
if (!wlr_backend_start(wlr)) {
wlr_log(WLR_ERROR, "Failed to start backend");
wlr_backend_destroy(wlr);

View File

@ -10,6 +10,7 @@
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_output.h>
@ -25,6 +26,7 @@ struct sample_state {
struct wl_listener new_input;
struct timespec last_frame;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_texture *cat_texture;
struct wl_list outputs;
enum wl_output_transform transform;
@ -105,6 +107,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->x_offs = sample_output->y_offs = 0;
sample_output->x_vel = sample_output->y_vel = 128;
@ -245,7 +250,7 @@ int main(int argc, char *argv[]) {
state.new_input.notify = new_input_notify;
clock_gettime(CLOCK_MONOTONIC, &state.last_frame);
state.renderer = wlr_backend_get_renderer(wlr);
state.renderer = wlr_renderer_autocreate(wlr);
if (!state.renderer) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM");
wlr_backend_destroy(wlr);
@ -259,6 +264,8 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
if (!wlr_backend_start(wlr)) {
wlr_log(WLR_ERROR, "Failed to start backend");
wlr_backend_destroy(wlr);

214
examples/scene-graph.c Normal file
View File

@ -0,0 +1,214 @@
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
/* Simple compositor making use of the scene-graph API. Input is unimplemented.
*
* New surfaces are stacked on top of the existing ones as they appear. */
static const int border_width = 3;
struct server {
struct wl_display *display;
struct wlr_backend *backend;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_scene *scene;
struct wl_list outputs;
struct wl_list surfaces;
struct wl_listener new_output;
struct wl_listener new_surface;
};
struct surface {
struct wlr_surface *wlr;
struct wlr_scene_surface *scene_surface;
struct wlr_scene_rect *border;
struct wl_list link;
struct wl_listener commit;
struct wl_listener destroy;
};
struct output {
struct wl_list link;
struct server *server;
struct wlr_output *wlr;
struct wlr_scene_output *scene_output;
struct wl_listener frame;
};
static void output_handle_frame(struct wl_listener *listener, void *data) {
struct output *output = wl_container_of(listener, output, frame);
if (!wlr_scene_output_commit(output->scene_output)) {
return;
}
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct surface *surface;
wl_list_for_each(surface, &output->server->surfaces, link) {
wlr_surface_send_frame_done(surface->wlr, &now);
}
}
static void server_handle_new_output(struct wl_listener *listener, void *data) {
struct server *server = wl_container_of(listener, server, new_output);
struct wlr_output *wlr_output = data;
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct output *output =
calloc(1, sizeof(struct output));
output->wlr = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&server->outputs, &output->link);
output->scene_output = wlr_scene_output_create(server->scene, wlr_output);
if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
wlr_output_set_mode(wlr_output, mode);
wlr_output_commit(wlr_output);
}
wlr_output_create_global(wlr_output);
}
static void surface_handle_commit(struct wl_listener *listener, void *data) {
struct surface *surface = wl_container_of(listener, surface, commit);
wlr_scene_rect_set_size(surface->border,
surface->wlr->current.width + 2 * border_width,
surface->wlr->current.height + 2 * border_width);
}
static void surface_handle_destroy(struct wl_listener *listener, void *data) {
struct surface *surface = wl_container_of(listener, surface, destroy);
wlr_scene_node_destroy(&surface->scene_surface->node);
wlr_scene_node_destroy(&surface->border->node);
wl_list_remove(&surface->destroy.link);
wl_list_remove(&surface->link);
free(surface);
}
static void server_handle_new_surface(struct wl_listener *listener,
void *data) {
struct server *server = wl_container_of(listener, server, new_surface);
struct wlr_surface *wlr_surface = data;
int pos = 50 * wl_list_length(&server->surfaces);
struct surface *surface = calloc(1, sizeof(struct surface));
surface->wlr = wlr_surface;
surface->commit.notify = surface_handle_commit;
wl_signal_add(&wlr_surface->events.commit, &surface->commit);
surface->destroy.notify = surface_handle_destroy;
wl_signal_add(&wlr_surface->events.destroy, &surface->destroy);
/* Border dimensions will be set in surface.commit handler */
surface->border = wlr_scene_rect_create(&server->scene->node,
0, 0, (float[4]){ 0.5f, 0.5f, 0.5f, 1 });
wlr_scene_node_set_position(&surface->border->node, pos, pos);
surface->scene_surface =
wlr_scene_surface_create(&server->scene->node, wlr_surface);
wl_list_insert(server->surfaces.prev, &surface->link);
wlr_scene_node_set_position(&surface->scene_surface->node,
pos + border_width, pos + border_width);
}
int main(int argc, char *argv[]) {
wlr_log_init(WLR_DEBUG, NULL);
char *startup_cmd = NULL;
int c;
while ((c = getopt(argc, argv, "s:")) != -1) {
switch (c) {
case 's':
startup_cmd = optarg;
break;
default:
printf("usage: %s [-s startup-command]\n", argv[0]);
return EXIT_FAILURE;
}
}
if (optind < argc) {
printf("usage: %s [-s startup-command]\n", argv[0]);
return EXIT_FAILURE;
}
struct server server = {0};
server.display = wl_display_create();
server.backend = wlr_backend_autocreate(server.display);
server.scene = wlr_scene_create();
server.renderer = wlr_renderer_autocreate(server.backend);
wlr_renderer_init_wl_display(server.renderer, server.display);
server.allocator = wlr_allocator_autocreate(server.backend,
server.renderer);
struct wlr_compositor *compositor =
wlr_compositor_create(server.display, server.renderer);
wlr_xdg_shell_create(server.display);
wl_list_init(&server.outputs);
wl_list_init(&server.surfaces);
server.new_output.notify = server_handle_new_output;
wl_signal_add(&server.backend->events.new_output, &server.new_output);
server.new_surface.notify = server_handle_new_surface;
wl_signal_add(&compositor->events.new_surface, &server.new_surface);
const char *socket = wl_display_add_socket_auto(server.display);
if (!socket) {
wl_display_destroy(server.display);
return EXIT_FAILURE;
}
if (!wlr_backend_start(server.backend)) {
wl_display_destroy(server.display);
return EXIT_FAILURE;
}
setenv("WAYLAND_DISPLAY", socket, true);
if (startup_cmd != NULL) {
if (fork() == 0) {
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, (void *)NULL);
}
}
wlr_log(WLR_INFO, "Running Wayland compositor on WAYLAND_DISPLAY=%s",
socket);
wl_display_run(server.display);
wl_display_destroy_clients(server.display);
wl_display_destroy(server.display);
return EXIT_SUCCESS;
}

View File

@ -7,6 +7,7 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h>
@ -18,6 +19,8 @@ struct sample_state {
struct wl_display *display;
struct wl_listener new_output;
struct wl_listener new_input;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct timespec last_frame;
float color[4];
int dec;
@ -61,8 +64,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_attach_render(wlr_output, NULL);
struct wlr_renderer *renderer =
wlr_backend_get_renderer(wlr_output->backend);
struct wlr_renderer *renderer = sample->renderer;
wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
wlr_renderer_clear(renderer, sample->color);
wlr_renderer_end(renderer);
@ -84,6 +86,9 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample =
wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output =
calloc(1, sizeof(struct sample_output));
sample_output->output = output;
@ -171,6 +176,10 @@ int main(void) {
if (!backend) {
exit(1);
}
state.renderer = wlr_renderer_autocreate(backend);
state.allocator = wlr_allocator_autocreate(backend, state.renderer);
wl_signal_add(&backend->events.new_output, &state.new_output);
state.new_output.notify = new_output_notify;
wl_signal_add(&backend->events.new_input, &state.new_input);

View File

@ -8,20 +8,22 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_tablet_pad.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
struct sample_state {
struct wl_display *display;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
bool proximity, tap, button;
double distance;
double pressure;
@ -237,6 +239,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output;
sample_output->sample = sample;
@ -361,11 +366,14 @@ int main(int argc, char *argv[]) {
state.new_input.notify = new_input_notify;
clock_gettime(CLOCK_MONOTONIC, &state.last_frame);
state.renderer = wlr_backend_get_renderer(wlr);
state.renderer = wlr_renderer_autocreate(wlr);
if (!state.renderer) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
if (!wlr_backend_start(wlr)) {
wlr_log(WLR_ERROR, "Failed to start backend");
wlr_backend_destroy(wlr);

View File

@ -10,9 +10,9 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/types/wlr_output.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_list.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
@ -24,6 +24,7 @@
struct sample_state {
struct wl_display *display;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_texture *cat_texture;
struct wl_list touch_points;
struct timespec last_frame;
@ -149,6 +150,9 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
static void new_output_notify(struct wl_listener *listener, void *data) {
struct wlr_output *output = data;
struct sample_state *sample = wl_container_of(listener, sample, new_output);
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output;
sample_output->sample = sample;
@ -255,8 +259,7 @@ int main(int argc, char *argv[]) {
state.new_input.notify = new_input_notify;
clock_gettime(CLOCK_MONOTONIC, &state.last_frame);
state.renderer = wlr_backend_get_renderer(wlr);
state.renderer = wlr_renderer_autocreate(wlr);
if (!state.renderer) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
@ -269,6 +272,8 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
if (!wlr_backend_start(wlr)) {
wlr_log(WLR_ERROR, "Failed to start backend");
wlr_backend_destroy(wlr);

View File

@ -10,10 +10,4 @@
*/
uint32_t backend_get_buffer_caps(struct wlr_backend *backend);
/**
* Get the backend's allocator. Automatically creates the allocator if
* necessary.
*/
struct wlr_allocator *backend_get_allocator(struct wlr_backend *backend);
#endif

View File

@ -1,7 +1,6 @@
#ifndef BACKEND_DRM_DRM_H
#define BACKEND_DRM_DRM_H
#include <gbm.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -20,9 +19,7 @@ struct wlr_drm_plane {
uint32_t type;
uint32_t id;
/* Local if this isn't a multi-GPU setup, on the parent otherwise. */
struct wlr_drm_surface surf;
/* Local, only initialized on multi-GPU setups. */
/* Only initialized on multi-GPU setups */
struct wlr_drm_surface mgpu_surf;
/* Buffer to be submitted to the kernel on the next page-flip */
@ -39,6 +36,7 @@ struct wlr_drm_plane {
struct wlr_drm_crtc {
uint32_t id;
struct wlr_drm_lease *lease;
// Atomic modesetting only
uint32_t mode_id;
@ -81,7 +79,9 @@ struct wlr_drm_backend {
struct wl_list fbs; // wlr_drm_fb.link
struct wl_list outputs;
struct wlr_drm_renderer renderer;
/* Only initialized on multi-GPU setups */
struct wlr_drm_renderer mgpu_renderer;
struct wlr_session *session;
uint64_t cursor_width, cursor_height;
@ -89,7 +89,7 @@ struct wlr_drm_backend {
struct wlr_drm_format_set mgpu_formats;
};
enum wlr_drm_connector_state {
enum wlr_drm_connector_status {
// Connector is available but no output is plugged in
WLR_DRM_CONN_DISCONNECTED,
// An output just has been plugged in and is waiting for a modeset
@ -103,15 +103,22 @@ struct wlr_drm_mode {
drmModeModeInfo drm_mode;
};
struct wlr_drm_connector_state {
const struct wlr_output_state *base;
bool modeset;
bool active;
drmModeModeInfo mode;
};
struct wlr_drm_connector {
struct wlr_output output; // only valid if state != DISCONNECTED
struct wlr_output output; // only valid if status != DISCONNECTED
struct wlr_drm_backend *backend;
char name[24];
enum wlr_drm_connector_state state;
struct wlr_output_mode *desired_mode;
enum wlr_drm_connector_status status;
bool desired_enabled;
uint32_t id;
struct wlr_drm_lease *lease;
struct wlr_drm_crtc *crtc;
uint32_t possible_crtcs;
@ -123,8 +130,6 @@ struct wlr_drm_connector {
int cursor_width, cursor_height;
int cursor_hotspot_x, cursor_hotspot_y;
drmModeCrtc *old_crtc;
struct wl_list link;
/* CRTC ID if a page-flip is pending, zero otherwise.
@ -142,8 +147,9 @@ struct wlr_drm_backend *get_drm_backend_from_backend(
bool check_drm_features(struct wlr_drm_backend *drm);
bool init_drm_resources(struct wlr_drm_backend *drm);
void finish_drm_resources(struct wlr_drm_backend *drm);
void restore_drm_outputs(struct wlr_drm_backend *drm);
void scan_drm_connectors(struct wlr_drm_backend *state);
void scan_drm_connectors(struct wlr_drm_backend *state,
struct wlr_device_hotplug_event *event);
void scan_drm_leases(struct wlr_drm_backend *drm);
int handle_drm_event(int fd, uint32_t mask, void *data);
void destroy_drm_connector(struct wlr_drm_connector *conn);
bool drm_connector_commit_state(struct wlr_drm_connector *conn,
@ -152,15 +158,10 @@ bool drm_connector_is_cursor_visible(struct wlr_drm_connector *conn);
bool drm_connector_supports_vrr(struct wlr_drm_connector *conn);
size_t drm_crtc_get_gamma_lut_size(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc);
void drm_lease_destroy(struct wlr_drm_lease *lease);
struct wlr_drm_fb *plane_get_next_fb(struct wlr_drm_plane *plane);
bool drm_connector_state_is_modeset(const struct wlr_output_state *state);
bool drm_connector_state_active(struct wlr_drm_connector *conn,
const struct wlr_output_state *state);
void drm_connector_state_mode(struct wlr_drm_connector *conn,
const struct wlr_output_state *state, drmModeModeInfo *mode);
#define wlr_drm_conn_log(conn, verb, fmt, ...) \
wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
#define wlr_drm_conn_log_errno(conn, verb, fmt, ...) \

View File

@ -1,7 +1,6 @@
#ifndef BACKEND_DRM_IFACE_H
#define BACKEND_DRM_IFACE_H
#include <gbm.h>
#include <stdbool.h>
#include <stdint.h>
#include <xf86drm.h>
@ -10,13 +9,14 @@
struct wlr_drm_backend;
struct wlr_drm_connector;
struct wlr_drm_crtc;
struct wlr_drm_connector_state;
// Used to provide atomic or legacy DRM functions
struct wlr_drm_interface {
// Commit al pending changes on a CRTC.
bool (*crtc_commit)(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t flags);
// Commit all pending changes on a CRTC.
bool (*crtc_commit)(struct wlr_drm_connector *conn,
const struct wlr_drm_connector_state *state, uint32_t flags,
bool test_only);
};
extern const struct wlr_drm_interface atomic_iface;

View File

@ -0,0 +1,24 @@
#ifndef BACKEND_DRM_MONITOR_H
#define BACKEND_DRM_MONITOR_H
#include <wlr/backend/drm.h>
/**
* Helper to create new DRM sub-backends on GPU hotplug.
*/
struct wlr_drm_backend_monitor {
struct wlr_backend *multi;
struct wlr_backend *primary_drm;
struct wlr_session *session;
struct wl_listener multi_destroy;
struct wl_listener primary_drm_destroy;
struct wl_listener session_destroy;
struct wl_listener session_add_drm_card;
};
struct wlr_drm_backend_monitor *drm_backend_monitor_create(
struct wlr_backend *multi, struct wlr_backend *primary_drm,
struct wlr_session *session);
#endif

View File

@ -18,6 +18,8 @@ union wlr_drm_connector_props {
uint32_t path;
uint32_t vrr_capable; // not guaranteed to exist
uint32_t subconnector; // not guaranteed to exist
uint32_t non_desktop;
uint32_t panel_orientation; // not guaranteed to exist
// atomic-modesetting only
@ -59,8 +61,9 @@ union wlr_drm_plane_props {
uint32_t crtc_h;
uint32_t fb_id;
uint32_t crtc_id;
uint32_t fb_damage_clips;
};
uint32_t props[13];
uint32_t props[14];
};
bool get_drm_connector_props(int fd, uint32_t id,

View File

@ -1,7 +1,6 @@
#ifndef BACKEND_DRM_RENDERER_H
#define BACKEND_DRM_RENDERER_H
#include <gbm.h>
#include <stdbool.h>
#include <stdint.h>
#include <wlr/backend.h>
@ -13,7 +12,6 @@ struct wlr_buffer;
struct wlr_drm_renderer {
struct wlr_drm_backend *backend;
struct gbm_device *gbm;
struct wlr_renderer *wlr_rend;
struct wlr_allocator *allocator;
@ -26,17 +24,15 @@ struct wlr_drm_surface {
uint32_t height;
struct wlr_swapchain *swapchain;
struct wlr_buffer *back_buffer;
};
struct wlr_drm_fb {
struct wlr_buffer *wlr_buf;
struct wlr_addon addon;
struct wlr_drm_backend *backend;
struct wl_list link; // wlr_drm_backend.fbs
struct gbm_bo *bo;
uint32_t id;
struct wl_listener wlr_buf_destroy;
};
bool init_drm_renderer(struct wlr_drm_backend *drm,
@ -46,8 +42,6 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer);
bool init_drm_surface(struct wlr_drm_surface *surf,
struct wlr_drm_renderer *renderer, uint32_t width, uint32_t height,
const struct wlr_drm_format *drm_format);
bool drm_surface_make_current(struct wlr_drm_surface *surf, int *buffer_age);
void drm_surface_unset_current(struct wlr_drm_surface *surf);
bool drm_fb_import(struct wlr_drm_fb **fb, struct wlr_drm_backend *drm,
struct wlr_buffer *buf, const struct wlr_drm_format_set *formats);
@ -58,15 +52,9 @@ void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old);
struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
struct wlr_buffer *buffer);
bool drm_surface_render_black_frame(struct wlr_drm_surface *surf);
struct wlr_drm_format *drm_plane_pick_render_format(
struct wlr_drm_plane *plane, struct wlr_drm_renderer *renderer);
bool drm_plane_init_surface(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm, int32_t width, uint32_t height,
bool with_modifiers);
void drm_plane_finish_surface(struct wlr_drm_plane *plane);
bool drm_plane_lock_surface(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm);
#endif

View File

@ -13,8 +13,6 @@ void parse_edid(struct wlr_output *restrict output, size_t len,
const uint8_t *data);
// Returns the string representation of a DRM output type
const char *conn_get_name(uint32_t type_id);
// Returns the DRM framebuffer id for a gbm_bo
uint32_t get_fb_for_bo(struct gbm_bo *bo, bool with_modifiers);
// Part of match_obj
enum {

View File

@ -8,14 +8,11 @@
struct wlr_headless_backend {
struct wlr_backend backend;
int drm_fd;
struct wl_display *display;
struct wl_list outputs;
size_t last_output_num;
struct wl_list input_devices;
struct wl_listener display_destroy;
struct wlr_renderer *parent_renderer;
struct wl_listener parent_renderer_destroy;
bool started;
};
@ -25,15 +22,13 @@ struct wlr_headless_output {
struct wlr_headless_backend *backend;
struct wl_list link;
struct wlr_buffer *front_buffer;
struct wl_event_source *frame_timer;
int frame_delay; // ms
};
struct wlr_headless_input_device {
struct wlr_input_device wlr_input_device;
struct wl_list link;
struct wlr_headless_backend *backend;
};

View File

@ -7,7 +7,6 @@
#include <wlr/backend/libinput.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_list.h>
struct wlr_libinput_backend {
struct wlr_backend backend;
@ -22,12 +21,12 @@ struct wlr_libinput_backend {
struct wl_listener session_destroy;
struct wl_listener session_signal;
struct wlr_list wlr_device_lists; // list of struct wl_list
struct wl_array wlr_device_lists; // struct wl_list *
};
struct wlr_libinput_input_device {
struct wlr_input_device wlr_input_device;
struct wl_list link;
struct libinput_device *handle;
};
@ -67,6 +66,10 @@ void handle_pointer_pinch_update(struct libinput_event *event,
struct libinput_device *device);
void handle_pointer_pinch_end(struct libinput_event *event,
struct libinput_device *device);
void handle_pointer_hold_begin(struct libinput_event *event,
struct libinput_device *device);
void handle_pointer_hold_end(struct libinput_event *event,
struct libinput_device *device);
struct wlr_switch *create_libinput_switch(
struct libinput_device *device);
@ -83,6 +86,8 @@ void handle_touch_motion(struct libinput_event *event,
struct libinput_device *device);
void handle_touch_cancel(struct libinput_event *event,
struct libinput_device *device);
void handle_touch_frame(struct libinput_event *event,
struct libinput_device *device);
struct wlr_tablet *create_libinput_tablet(
struct libinput_device *device);

View File

@ -1,27 +0,0 @@
#ifndef BACKEND_NOOP_H
#define BACKEND_NOOP_H
#include <wlr/backend/noop.h>
#include <wlr/backend/interface.h>
struct wlr_noop_backend {
struct wlr_backend backend;
struct wl_display *display;
struct wl_list outputs;
size_t last_output_num;
bool started;
struct wl_listener display_destroy;
};
struct wlr_noop_output {
struct wlr_output wlr_output;
struct wlr_noop_backend *backend;
struct wl_list link;
};
struct wlr_noop_backend *noop_backend_from_backend(
struct wlr_backend *wlr_backend);
#endif

View File

@ -11,4 +11,7 @@ bool libseat_change_vt(struct wlr_session *base, unsigned vt);
void session_init(struct wlr_session *session);
struct wlr_device *session_open_if_kms(struct wlr_session *restrict session,
const char *restrict path);
#endif

View File

@ -8,7 +8,6 @@
#include <wlr/backend/wayland.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/render/drm_format_set.h>
@ -25,6 +24,7 @@ struct wlr_wl_backend {
size_t requested_outputs;
size_t last_output_num;
struct wl_listener local_display_destroy;
char *activation_token;
/* remote state */
struct wl_display *remote_display;
@ -40,9 +40,11 @@ struct wlr_wl_backend {
struct zwp_relative_pointer_manager_v1 *zwp_relative_pointer_manager_v1;
struct wl_list seats; // wlr_wl_seat.link
struct zwp_tablet_manager_v2 *tablet_manager;
clockid_t presentation_clock;
struct wlr_drm_format_set shm_formats;
struct wlr_drm_format_set linux_dmabuf_v1_formats;
struct wl_drm *legacy_drm;
struct xdg_activation_v1 *activation_v1;
char *drm_render_name;
};
@ -85,6 +87,7 @@ struct wlr_wl_output {
struct wlr_wl_input_device {
struct wlr_input_device wlr_input_device;
struct wl_list link;
uint32_t fingers;
struct wlr_wl_backend *backend;
@ -99,6 +102,7 @@ struct wlr_wl_pointer {
struct wl_pointer *wl_pointer;
struct zwp_pointer_gesture_swipe_v1 *gesture_swipe;
struct zwp_pointer_gesture_pinch_v1 *gesture_pinch;
struct zwp_pointer_gesture_hold_v1 *gesture_hold;
struct zwp_relative_pointer_v1 *relative_pointer;
enum wlr_axis_source axis_source;
int32_t axis_discrete;

View File

@ -1,6 +1,12 @@
subdir('wlr')
exclude_files = ['meson.build', 'config.h.in', 'version.h.in']
if not features.get('drm-backend')
exclude_files += 'backend/drm.h'
endif
if not features.get('libinput-backend')
exclude_files += 'backend/libinput.h'
endif
if not features.get('x11-backend')
exclude_files += 'backend/x11.h'
endif
@ -12,6 +18,9 @@ endif
if not features.get('gles2-renderer')
exclude_files += ['render/egl.h', 'render/gles2.h']
endif
if not features.get('vulkan-renderer')
exclude_files += 'render/vulkan.h'
endif
install_subdir('wlr',
install_dir: get_option('includedir'),

View File

@ -0,0 +1,9 @@
#ifndef RENDER_ALLOCATOR_ALLOCATOR_H
#define RENDER_ALLOCATOR_ALLOCATOR_H
#include <wlr/render/allocator.h>
struct wlr_allocator *allocator_autocreate_with_drm_fd(
struct wlr_backend *backend, struct wlr_renderer *renderer, int drm_fd);
#endif

View File

@ -1,9 +1,9 @@
#ifndef RENDER_DRM_DUMB_ALLOCATOR_H
#define RENDER_DRM_DUMB_ALLOCATOR_H
#include "render/allocator.h"
#ifndef RENDER_ALLOCATOR_DRM_DUMB_H
#define RENDER_ALLOCATOR_DRM_DUMB_H
#include <wlr/render/dmabuf.h>
#include <wlr/types/wlr_buffer.h>
#include "render/allocator/allocator.h"
struct wlr_drm_dumb_buffer {
struct wlr_buffer base;

View File

@ -1,9 +1,10 @@
#ifndef RENDER_GBM_ALLOCATOR_H
#define RENDER_GBM_ALLOCATOR_H
#ifndef RENDER_ALLOCATOR_GBM_H
#define RENDER_ALLOCATOR_GBM_H
#include <gbm.h>
#include <wlr/render/dmabuf.h>
#include <wlr/types/wlr_buffer.h>
#include "render/allocator.h"
#include "render/allocator/allocator.h"
struct wlr_gbm_buffer {
struct wlr_buffer base;
@ -26,7 +27,7 @@ struct wlr_gbm_allocator {
/**
* Creates a new GBM allocator from a DRM FD.
*
* Does not take ownership over the FD.
* Takes ownership over the FD.
*/
struct wlr_allocator *wlr_gbm_allocator_create(int drm_fd);

View File

@ -1,8 +1,8 @@
#ifndef RENDER_SHM_ALLOCATOR_H
#define RENDER_SHM_ALLOCATOR_H
#ifndef RENDER_ALLOCATOR_SHM_H
#define RENDER_ALLOCATOR_SHM_H
#include <wlr/types/wlr_buffer.h>
#include "render/allocator.h"
#include "render/allocator/allocator.h"
struct wlr_shm_buffer {
struct wlr_buffer base;

View File

@ -4,6 +4,7 @@
#include <wlr/render/drm_format_set.h>
struct wlr_drm_format *wlr_drm_format_create(uint32_t format);
bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier);
bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier);
struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format);
/**

63
include/render/egl.h Normal file
View File

@ -0,0 +1,63 @@
#ifndef RENDER_EGL_H
#define RENDER_EGL_H
#include <wlr/render/egl.h>
struct wlr_egl_context {
EGLDisplay display;
EGLContext context;
EGLSurface draw_surface;
EGLSurface read_surface;
};
/**
* Initializes an EGL context for the given DRM FD.
*
* Will attempt to load all possibly required API functions.
*/
struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd);
/**
* Frees all related EGL resources, makes the context not-current and
* unbinds a bound wayland display.
*/
void wlr_egl_destroy(struct wlr_egl *egl);
/**
* Creates an EGL image from the given dmabuf attributes. Check usability
* of the dmabuf with wlr_egl_check_import_dmabuf once first.
*/
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_attributes *attributes, bool *external_only);
/**
* Get DMA-BUF formats suitable for sampling usage.
*/
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_texture_formats(
struct wlr_egl *egl);
/**
* Get DMA-BUF formats suitable for rendering usage.
*/
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_render_formats(
struct wlr_egl *egl);
/**
* Destroys an EGL image created with the given wlr_egl.
*/
bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image);
int wlr_egl_dup_drm_fd(struct wlr_egl *egl);
/**
* Save the current EGL context to the structure provided in the argument.
*
* This includes display, context, draw surface and read surface.
*/
void wlr_egl_save_context(struct wlr_egl_context *context);
/**
* Restore EGL context that was previously saved using wlr_egl_save_current().
*/
bool wlr_egl_restore_context(struct wlr_egl_context *context);
#endif

View File

@ -12,6 +12,7 @@
#include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/util/addon.h>
#include <wlr/util/log.h>
struct wlr_gles2_pixel_format {
@ -23,7 +24,6 @@ struct wlr_gles2_pixel_format {
struct wlr_gles2_tex_shader {
GLuint program;
GLint proj;
GLint invert_y;
GLint tex;
GLint alpha;
GLint pos_attrib;
@ -39,10 +39,12 @@ struct wlr_gles2_renderer {
const char *exts_str;
struct {
bool read_format_bgra_ext;
bool debug_khr;
bool egl_image_external_oes;
bool egl_image_oes;
bool EXT_read_format_bgra;
bool KHR_debug;
bool OES_egl_image_external;
bool OES_egl_image;
bool EXT_texture_type_2_10_10_10_REV;
bool OES_texture_half_float_linear;
} exts;
struct {
@ -82,7 +84,7 @@ struct wlr_gles2_buffer {
GLuint rbo;
GLuint fbo;
struct wl_listener buffer_destroy;
struct wlr_addon addon;
};
struct wlr_gles2_texture {
@ -98,34 +100,31 @@ struct wlr_gles2_texture {
EGLImageKHR image;
bool inverted_y;
bool has_alpha;
// Only affects target == GL_TEXTURE_2D
uint32_t drm_format; // used to interpret upload data
// If imported from a wlr_buffer
struct wlr_buffer *buffer;
struct wl_listener buffer_destroy;
struct wlr_addon buffer_addon;
};
bool is_gles2_pixel_format_supported(const struct wlr_gles2_renderer *renderer,
const struct wlr_gles2_pixel_format *format);
const struct wlr_gles2_pixel_format *get_gles2_format_from_drm(uint32_t fmt);
const struct wlr_gles2_pixel_format *get_gles2_format_from_gl(
GLint gl_format, GLint gl_type, bool alpha);
const uint32_t *get_gles2_shm_formats(size_t *len);
const uint32_t *get_gles2_shm_formats(const struct wlr_gles2_renderer *renderer,
size_t *len);
struct wlr_gles2_renderer *gles2_get_renderer(
struct wlr_renderer *wlr_renderer);
struct wlr_gles2_texture *gles2_get_texture(
struct wlr_texture *wlr_texture);
struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer,
uint32_t fmt, uint32_t stride, uint32_t width, uint32_t height,
const void *data);
struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer,
struct wl_resource *data);
struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer,
struct wlr_dmabuf_attributes *attribs);
struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
struct wlr_buffer *buffer);
void gles2_texture_destroy(struct wlr_gles2_texture *texture);

311
include/render/vulkan.h Normal file
View File

@ -0,0 +1,311 @@
#ifndef RENDER_VULKAN_H
#define RENDER_VULKAN_H
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <vulkan/vulkan.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/render/drm_format_set.h>
#include <wlr/render/interface.h>
struct wlr_vk_descriptor_pool;
// Central vulkan state that should only be needed once per compositor.
struct wlr_vk_instance {
VkInstance instance;
VkDebugUtilsMessengerEXT messenger;
// enabled extensions
size_t extension_count;
const char **extensions;
struct {
PFN_vkCreateDebugUtilsMessengerEXT createDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT destroyDebugUtilsMessengerEXT;
} api;
};
// Creates and initializes a vulkan instance.
// Will try to enable the given extensions but not fail if they are not
// available which can later be checked by the caller.
// The debug parameter determines if validation layers are enabled and a
// debug messenger created.
// `compositor_name` and `compositor_version` are passed to the vulkan driver.
struct wlr_vk_instance *vulkan_instance_create(size_t ext_count,
const char **exts, bool debug);
void vulkan_instance_destroy(struct wlr_vk_instance *ini);
// Logical vulkan device state.
// Ownership can be shared by multiple renderers, reference counted
// with `renderers`.
struct wlr_vk_device {
struct wlr_vk_instance *instance;
VkPhysicalDevice phdev;
VkDevice dev;
int drm_fd;
// enabled extensions
size_t extension_count;
const char **extensions;
// we only ever need one queue for rendering and transfer commands
uint32_t queue_family;
VkQueue queue;
struct {
PFN_vkGetMemoryFdPropertiesKHR getMemoryFdPropertiesKHR;
} api;
uint32_t format_prop_count;
struct wlr_vk_format_props *format_props;
struct wlr_drm_format_set dmabuf_render_formats;
struct wlr_drm_format_set dmabuf_texture_formats;
// supported formats for textures (contains only those formats
// that support everything we need for textures)
uint32_t shm_format_count;
uint32_t *shm_formats; // to implement vulkan_get_shm_texture_formats
};
// Tries to find the VkPhysicalDevice for the given drm fd.
// Might find none and return VK_NULL_HANDLE.
VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd);
// Creates a device for the given instance and physical device.
// Will try to enable the given extensions but not fail if they are not
// available which can later be checked by the caller.
struct wlr_vk_device *vulkan_device_create(struct wlr_vk_instance *ini,
VkPhysicalDevice phdev, size_t ext_count, const char **exts);
void vulkan_device_destroy(struct wlr_vk_device *dev);
// Tries to find any memory bit for the given vulkan device that
// supports the given flags and is set in req_bits (e.g. if memory
// type 2 is ok, (req_bits & (1 << 2)) must not be 0.
// Set req_bits to 0xFFFFFFFF to allow all types.
int vulkan_find_mem_type(struct wlr_vk_device *device,
VkMemoryPropertyFlags flags, uint32_t req_bits);
struct wlr_vk_format {
uint32_t drm_format;
VkFormat vk_format;
};
// Returns all known format mappings.
// Might not be supported for gpu/usecase.
const struct wlr_vk_format *vulkan_get_format_list(size_t *len);
const struct wlr_vk_format *vulkan_get_format_from_drm(uint32_t drm_format);
struct wlr_vk_format_modifier_props {
VkDrmFormatModifierPropertiesEXT props;
VkExternalMemoryFeatureFlags dmabuf_flags;
VkExtent2D max_extent;
bool export_imported;
};
struct wlr_vk_format_props {
struct wlr_vk_format format;
VkExtent2D max_extent; // relevant if not created as dma_buf
VkFormatFeatureFlags features; // relevant if not created as dma_buf
uint32_t render_mod_count;
struct wlr_vk_format_modifier_props *render_mods;
uint32_t texture_mod_count;
struct wlr_vk_format_modifier_props *texture_mods;
};
void vulkan_format_props_query(struct wlr_vk_device *dev,
const struct wlr_vk_format *format);
struct wlr_vk_format_modifier_props *vulkan_format_props_find_modifier(
struct wlr_vk_format_props *props, uint64_t mod, bool render);
void vulkan_format_props_finish(struct wlr_vk_format_props *props);
// For each format we want to render, we need a separate renderpass
// and therefore also separate pipelines.
struct wlr_vk_render_format_setup {
struct wl_list link;
VkFormat render_format; // used in renderpass
VkRenderPass render_pass;
VkPipeline tex_pipe;
VkPipeline quad_pipe;
};
// Renderer-internal represenation of an wlr_buffer imported for rendering.
struct wlr_vk_render_buffer {
struct wlr_buffer *wlr_buffer;
struct wlr_vk_renderer *renderer;
struct wlr_vk_render_format_setup *render_setup;
struct wl_list link; // wlr_vk_renderer.buffers
VkImage image;
VkImageView image_view;
VkFramebuffer framebuffer;
uint32_t mem_count;
VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES];
bool transitioned;
struct wl_listener buffer_destroy;
};
// Vulkan wlr_renderer implementation on top of a wlr_vk_device.
struct wlr_vk_renderer {
struct wlr_renderer wlr_renderer;
struct wlr_backend *backend;
struct wlr_vk_device *dev;
VkCommandPool command_pool;
VkShaderModule vert_module;
VkShaderModule tex_frag_module;
VkShaderModule quad_frag_module;
VkDescriptorSetLayout ds_layout;
VkPipelineLayout pipe_layout;
VkSampler sampler;
VkFence fence;
struct wlr_vk_render_buffer *current_render_buffer;
// current frame id. Used in wlr_vk_texture.last_used
// Increased every time a frame is ended for the renderer
uint32_t frame;
VkRect2D scissor; // needed for clearing
VkCommandBuffer cb;
VkPipeline bound_pipe;
uint32_t render_width;
uint32_t render_height;
float projection[9];
size_t last_pool_size;
struct wl_list descriptor_pools; // type wlr_vk_descriptor_pool
struct wl_list render_format_setups;
struct wl_list textures; // wlr_gles2_texture.link
struct wl_list destroy_textures; // wlr_vk_texture to destroy after frame
struct wl_list foreign_textures; // wlr_vk_texture to return to foreign queue
struct wl_list render_buffers; // wlr_vk_render_buffer
struct {
VkCommandBuffer cb;
bool recording;
struct wl_list buffers; // type wlr_vk_shared_buffer
} stage;
};
// Creates a vulkan renderer for the given device.
struct wlr_renderer *vulkan_renderer_create_for_device(struct wlr_vk_device *dev);
// stage utility - for uploading/retrieving data
// Gets an command buffer in recording state which is guaranteed to be
// executed before the next frame.
VkCommandBuffer vulkan_record_stage_cb(struct wlr_vk_renderer *renderer);
// Submits the current stage command buffer and waits until it has
// finished execution.
bool vulkan_submit_stage_wait(struct wlr_vk_renderer *renderer);
// Suballocates a buffer span with the given size that can be mapped
// and used as staging buffer. The allocation is implicitly released when the
// stage cb has finished execution.
struct wlr_vk_buffer_span vulkan_get_stage_span(
struct wlr_vk_renderer *renderer, VkDeviceSize size);
// Tries to allocate a texture descriptor set. Will additionally
// return the pool it was allocated from when successful (for freeing it later).
struct wlr_vk_descriptor_pool *vulkan_alloc_texture_ds(
struct wlr_vk_renderer *renderer, VkDescriptorSet *ds);
// Frees the given descriptor set from the pool its pool.
void vulkan_free_ds(struct wlr_vk_renderer *renderer,
struct wlr_vk_descriptor_pool *pool, VkDescriptorSet ds);
struct wlr_vk_format_props *vulkan_format_props_from_drm(
struct wlr_vk_device *dev, uint32_t drm_format);
struct wlr_vk_renderer *vulkan_get_renderer(struct wlr_renderer *r);
// State (e.g. image texture) associated with a surface.
struct wlr_vk_texture {
struct wlr_texture wlr_texture;
struct wlr_vk_renderer *renderer;
uint32_t mem_count;
VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES];
VkImage image;
VkImageView image_view;
const struct wlr_vk_format *format;
VkDescriptorSet ds;
struct wlr_vk_descriptor_pool *ds_pool;
uint32_t last_used; // to track when it can be destroyed
bool dmabuf_imported;
bool owned; // if dmabuf_imported: whether we have ownership of the image
bool transitioned; // if dma_imported: whether we transitioned it away from preinit
struct wl_list foreign_link;
struct wl_list destroy_link;
struct wl_list link; // wlr_gles2_renderer.textures
// If imported from a wlr_buffer
struct wlr_buffer *buffer;
struct wl_listener buffer_destroy;
};
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture);
VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
const struct wlr_dmabuf_attributes *attribs,
VkDeviceMemory mems[static WLR_DMABUF_MAX_PLANES], uint32_t *n_mems,
bool for_render);
struct wlr_texture *vulkan_texture_from_buffer(
struct wlr_renderer *wlr_renderer, struct wlr_buffer *buffer);
void vulkan_texture_destroy(struct wlr_vk_texture *texture);
struct wlr_vk_descriptor_pool {
VkDescriptorPool pool;
uint32_t free; // number of textures that can be allocated
struct wl_list link;
};
struct wlr_vk_allocation {
VkDeviceSize start;
VkDeviceSize size;
};
// List of suballocated staging buffers.
// Used to upload to/read from device local images.
struct wlr_vk_shared_buffer {
struct wl_list link;
VkBuffer buffer;
VkDeviceMemory memory;
VkDeviceSize buf_size;
size_t allocs_size;
size_t allocs_capacity;
struct wlr_vk_allocation *allocs;
};
// Suballocated range on a buffer.
struct wlr_vk_buffer_span {
struct wlr_vk_shared_buffer *buffer;
struct wlr_vk_allocation alloc;
};
// util
bool vulkan_has_extension(size_t count, const char **exts, const char *find);
const char *vulkan_strerror(VkResult err);
void vulkan_change_layout(VkCommandBuffer cb, VkImage img,
VkImageLayout ol, VkPipelineStageFlags srcs, VkAccessFlags srca,
VkImageLayout nl, VkPipelineStageFlags dsts, VkAccessFlags dsta);
void vulkan_change_layout_queue(VkCommandBuffer cb, VkImage img,
VkImageLayout ol, VkPipelineStageFlags srcs, VkAccessFlags srca,
VkImageLayout nl, VkPipelineStageFlags dsts, VkAccessFlags dsta,
uint32_t src_family, uint32_t dst_family);
#define wlr_vk_error(fmt, res, ...) wlr_log(WLR_ERROR, fmt ": %s (%d)", \
vulkan_strerror(res), res, ##__VA_ARGS__)
#endif // RENDER_VULKAN_H

View File

@ -1,15 +0,0 @@
#ifndef RENDER_WLR_TEXTURE_H
#define RENDER_WLR_TEXTURE_H
#include <wlr/render/wlr_texture.h>
/**
* Create a new texture from a buffer.
*
* Should not be called in a rendering block like renderer_begin()/end() or
* between attaching a renderer to an output and committing it.
*/
struct wlr_texture *wlr_texture_from_buffer(struct wlr_renderer *renderer,
struct wlr_buffer *buffer);
#endif

View File

@ -22,32 +22,51 @@ struct wlr_shm_client_buffer {
struct wl_listener release;
};
struct wlr_shm_client_buffer *shm_client_buffer_create(
struct wl_resource *resource);
/**
* Buffer capabilities.
* A read-only buffer that holds a data pointer.
*
* These bits indicate the features supported by a wlr_buffer. There is one bit
* per function in wlr_buffer_impl.
* This is suitable for passing raw pixel data to a function that accepts a
* wlr_buffer.
*/
enum wlr_buffer_cap {
WLR_BUFFER_CAP_DATA_PTR = 1 << 0,
WLR_BUFFER_CAP_DMABUF = 1 << 1,
WLR_BUFFER_CAP_SHM = 1 << 2,
struct wlr_readonly_data_buffer {
struct wlr_buffer base;
const void *data;
uint32_t format;
size_t stride;
void *saved_data;
};
/**
* Get a pointer to a region of memory referring to the buffer's underlying
* storage. The format and stride can be used to interpret the memory region
* contents.
*
* The returned pointer should be pointing to a valid memory region for read
* and write operations. The returned pointer is only valid up to the next
* buffer_end_data_ptr_access call.
* Wraps a read-only data pointer into a wlr_buffer. The data pointer may be
* accessed until readonly_data_buffer_drop() is called.
*/
bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, void **data,
uint32_t *format, size_t *stride);
void buffer_end_data_ptr_access(struct wlr_buffer *buffer);
struct wlr_readonly_data_buffer *readonly_data_buffer_create(uint32_t format,
size_t stride, uint32_t width, uint32_t height, const void *data);
/**
* Drops ownership of the buffer (see wlr_buffer_drop() for more details) and
* perform a copy of the data pointer if a consumer still has the buffer locked.
*/
bool readonly_data_buffer_drop(struct wlr_readonly_data_buffer *buffer);
struct wlr_dmabuf_buffer {
struct wlr_buffer base;
struct wlr_dmabuf_attributes dmabuf;
bool saved;
};
/**
* Wraps a DMA-BUF into a wlr_buffer. The DMA-BUF may be accessed until
* dmabuf_buffer_drop() is called.
*/
struct wlr_dmabuf_buffer *dmabuf_buffer_create(
struct wlr_dmabuf_attributes *dmabuf);
/**
* Drops ownership of the buffer (see wlr_buffer_drop() for more details) and
* takes a reference to the DMA-BUF (by dup'ing its file descriptors) if a
* consumer still has the buffer locked.
*/
bool dmabuf_buffer_drop(struct wlr_dmabuf_buffer *buffer);
#endif

View File

@ -0,0 +1,15 @@
#ifndef TYPES_WLR_OUTPUT_H
#define TYPES_WLR_OUTPUT_H
#include <wlr/render/drm_format_set.h>
#include <wlr/types/wlr_output.h>
void output_pending_resolution(struct wlr_output *output, int *width,
int *height);
struct wlr_drm_format *output_pick_format(struct wlr_output *output,
const struct wlr_drm_format_set *display_formats, uint32_t format);
void output_clear_back_buffer(struct wlr_output *output);
bool output_ensure_buffer(struct wlr_output *output);
#endif

View File

@ -11,4 +11,10 @@ struct wlr_renderer;
struct wlr_surface *surface_create(struct wl_client *client,
uint32_t version, uint32_t id, struct wlr_renderer *renderer);
/**
* Create a new subsurface resource with the provided new ID.
*/
struct wlr_subsurface *subsurface_create(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t version, uint32_t id);
#endif

View File

@ -13,7 +13,6 @@ struct wlr_xdg_positioner_resource {
extern const struct wlr_surface_role xdg_toplevel_surface_role;
extern const struct wlr_surface_role xdg_popup_surface_role;
uint32_t schedule_xdg_surface_configure(struct wlr_xdg_surface *surface);
struct wlr_xdg_surface *create_xdg_surface(
struct wlr_xdg_client *client, struct wlr_surface *surface,
uint32_t id);
@ -41,7 +40,6 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface,
struct wlr_xdg_surface_configure *configure);
void handle_xdg_toplevel_ack_configure(struct wlr_xdg_surface *surface,
struct wlr_xdg_surface_configure *configure);
bool compare_xdg_surface_toplevel_state(struct wlr_xdg_toplevel *state);
void destroy_xdg_toplevel(struct wlr_xdg_surface *surface);
#endif

View File

@ -4,6 +4,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <wayland-util.h>
size_t push_zeroes_to_end(uint32_t arr[], size_t n);
@ -21,4 +22,9 @@ bool set_add(uint32_t values[], size_t *len, size_t cap, uint32_t target);
*/
bool set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target);
/**
* Remove a chunk of memory of the specified size at the specified offset.
*/
void array_remove_at(struct wl_array *arr, size_t offset, size_t size);
#endif

View File

@ -9,7 +9,6 @@
* Globals that are created and destroyed on the fly need special handling to
* prevent race conditions with wl_registry. Use this function to destroy them.
*/
void wlr_global_destroy_safe(struct wl_global *global,
struct wl_display *display);
void wlr_global_destroy_safe(struct wl_global *global);
#endif

View File

@ -1,7 +1,10 @@
#ifndef UTIL_SHM_H
#define UTIL_SHM_H
#include <stdbool.h>
int create_shm_file(void);
int allocate_shm_file(size_t size);
bool allocate_shm_file_pair(size_t size, int *rw_fd, int *ro_fd);
#endif

View File

@ -25,11 +25,6 @@ struct wlr_backend {
/** Raised when new outputs are added, passed the wlr_output */
struct wl_signal new_output;
} events;
// Private state
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
};
/**
@ -49,10 +44,6 @@ bool wlr_backend_start(struct wlr_backend *backend);
* automatically when the wl_display is destroyed.
*/
void wlr_backend_destroy(struct wlr_backend *backend);
/**
* Obtains the wlr_renderer reference this backend is using.
*/
struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend);
/**
* Obtains the wlr_session reference from this backend if there is any.
* Might return NULL for backends that don't use a session.

View File

@ -14,6 +14,20 @@
#include <wlr/backend/session.h>
#include <wlr/types/wlr_output.h>
struct wlr_drm_backend;
struct wlr_drm_lease {
int fd;
uint32_t lessee_id;
struct wlr_drm_backend *backend;
struct {
struct wl_signal destroy;
} events;
void *data;
};
/**
* Creates a DRM backend using the specified GPU file descriptor (typically from
* a device node in /dev/dri).
@ -33,6 +47,29 @@ bool wlr_output_is_drm(struct wlr_output *output);
*/
uint32_t wlr_drm_connector_get_id(struct wlr_output *output);
/**
* Tries to open non-master DRM FD. The compositor must not call `drmSetMaster`
* on the returned FD.
* Returns a valid opened DRM FD, or -1 on error.
*/
int wlr_drm_backend_get_non_master_fd(struct wlr_backend *backend);
/**
* Leases the given outputs to the caller. The outputs must be from the
* associated DRM backend.
*
* Returns NULL on error.
*/
struct wlr_drm_lease *wlr_drm_create_lease(struct wlr_output **outputs,
size_t n_outputs, int *lease_fd);
/**
* Terminates and destroys a given lease.
*
* The outputs will be owned again by the backend.
*/
void wlr_drm_lease_terminate(struct wlr_drm_lease *lease);
/**
* Add mode to the list of available modes
*/
@ -40,4 +77,15 @@ typedef struct _drmModeModeInfo drmModeModeInfo;
struct wlr_output_mode *wlr_drm_connector_add_mode(struct wlr_output *output,
const drmModeModeInfo *mode);
/**
* Get the connector's panel orientation.
*
* On some devices the panel is mounted in the casing in such a way that the
* top side of the panel does not match with the top side of the device. This
* function returns the output transform which needs to be applied to compensate
* for this.
*/
enum wl_output_transform wlr_drm_connector_get_panel_orientation(
struct wlr_output *output);
#endif

View File

@ -18,11 +18,6 @@
* default.
*/
struct wlr_backend *wlr_headless_backend_create(struct wl_display *display);
/**
* Creates a headless backend with an existing renderer.
*/
struct wlr_backend *wlr_headless_backend_create_with_renderer(
struct wl_display *display, struct wlr_renderer *renderer);
/**
* Create a new headless output backed by an in-memory EGL framebuffer. You can
* read pixels from this framebuffer via wlr_renderer_read_pixels but it is

View File

@ -16,7 +16,6 @@
struct wlr_backend_impl {
bool (*start)(struct wlr_backend *backend);
void (*destroy)(struct wlr_backend *backend);
struct wlr_renderer *(*get_renderer)(struct wlr_backend *backend);
struct wlr_session *(*get_session)(struct wlr_backend *backend);
clockid_t (*get_presentation_clock)(struct wlr_backend *backend);
int (*get_drm_fd)(struct wlr_backend *backend);

View File

@ -1,31 +0,0 @@
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#ifndef WLR_BACKEND_NOOP_H
#define WLR_BACKEND_NOOP_H
#include <wlr/backend.h>
#include <wlr/types/wlr_output.h>
/**
* Creates a noop backend. Noop backends do not have a framebuffer and are not
* capable of rendering anything. They are useful for when there's no real
* outputs connected; you can stash your views on a noop output until an output
* is connected.
*/
struct wlr_backend *wlr_noop_backend_create(struct wl_display *display);
/**
* Create a new noop output.
*/
struct wlr_output *wlr_noop_add_output(struct wlr_backend *backend);
bool wlr_backend_is_noop(struct wlr_backend *backend);
bool wlr_output_is_noop(struct wlr_output *output);
#endif

View File

@ -15,7 +15,7 @@ struct wlr_device {
struct wl_list link;
struct {
struct wl_signal change;
struct wl_signal change; // struct wlr_device_change_event
struct wl_signal remove;
} events;
};
@ -57,6 +57,23 @@ struct wlr_session_add_event {
const char *path;
};
enum wlr_device_change_type {
WLR_DEVICE_HOTPLUG = 1,
WLR_DEVICE_LEASE,
};
struct wlr_device_hotplug_event {
uint32_t connector_id;
uint32_t prop_id;
};
struct wlr_device_change_event {
enum wlr_device_change_type type;
union {
struct wlr_device_hotplug_event hotplug;
};
};
/*
* Opens a session, taking control of the current virtual terminal.
* This should not be called if another program is already in control

View File

@ -1,10 +1,14 @@
#ifndef WLR_CONFIG_H
#define WLR_CONFIG_H
#mesondefine WLR_HAS_DRM_BACKEND
#mesondefine WLR_HAS_LIBINPUT_BACKEND
#mesondefine WLR_HAS_X11_BACKEND
#mesondefine WLR_HAS_GLES2_RENDERER
#mesondefine WLR_HAS_VULKAN_RENDERER
#mesondefine WLR_HAS_XWAYLAND
#endif

View File

@ -11,7 +11,6 @@
#include <stdbool.h>
#include <wlr/backend.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h>
/**
@ -22,6 +21,7 @@
(WLR_OUTPUT_STATE_DAMAGE | \
WLR_OUTPUT_STATE_SCALE | \
WLR_OUTPUT_STATE_TRANSFORM | \
WLR_OUTPUT_STATE_RENDER_FORMAT | \
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED)
/**
@ -52,19 +52,6 @@ struct wlr_output_impl {
* Cleanup backend-specific resources tied to the output.
*/
void (*destroy)(struct wlr_output *output);
/**
* Make the output's back-buffer current for the renderer.
*
* buffer_age must be set to the buffer age in number of frames, or -1 if
* unknown.
*/
bool (*attach_render)(struct wlr_output *output, int *buffer_age);
/**
* Unset the current renderer's buffer.
*
* This is the opposite of attach_render.
*/
void (*rollback_render)(struct wlr_output *output);
/**
* Check that the pending output state is a valid configuration.
*
@ -84,11 +71,6 @@ struct wlr_output_impl {
* Zero can be returned if the output doesn't support gamma LUTs.
*/
size_t (*get_gamma_size)(struct wlr_output *output);
/**
* Export the output's current back-buffer as a DMA-BUF.
*/
bool (*export_dmabuf)(struct wlr_output *output,
struct wlr_dmabuf_attributes *attribs);
/**
* Get the list of formats suitable for the cursor, assuming a buffer with
* the specified capabilities.
@ -104,7 +86,7 @@ struct wlr_output_impl {
*/
void (*get_cursor_size)(struct wlr_output *output, int *width, int *height);
/**
* Get the list of DMA-BUF formats suitable for the primary buffer,
* Get the list of DRM formats suitable for the primary buffer,
* assuming a buffer with the specified capabilities.
*
* If unimplemented, the primary buffer has no format constraint. If NULL

View File

@ -1,13 +1,19 @@
#ifndef RENDER_ALLOCATOR
#define RENDER_ALLOCATOR
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#ifndef WLR_ALLOCATOR_H
#define WLR_ALLOCATOR_H
#include <stdbool.h>
#include <wayland-server-core.h>
#include <wlr/render/dmabuf.h>
#include <wlr/render/drm_format_set.h>
struct wlr_allocator;
struct wlr_backend;
struct wlr_drm_format;
struct wlr_renderer;
struct wlr_allocator_interface {
@ -16,10 +22,13 @@ struct wlr_allocator_interface {
void (*destroy)(struct wlr_allocator *alloc);
};
void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl, uint32_t buffer_caps);
struct wlr_allocator {
const struct wlr_allocator_interface *impl;
// Capabilites of the buffers created with this allocator
// Capabilities of the buffers created with this allocator
uint32_t buffer_caps;
struct {
@ -36,20 +45,26 @@ struct wlr_allocator *wlr_allocator_autocreate(struct wlr_backend *backend,
* Destroy the allocator.
*/
void wlr_allocator_destroy(struct wlr_allocator *alloc);
/**
* Allocate a new buffer.
*
* When the caller is done with it, they must unreference it by calling
* wlr_buffer_drop.
*
* The `format` passed in indicates the format to use and the list of
* acceptable modifiers. The order in which modifiers are listed is not
* significant.
*
* When running with legacy drivers which don't support explicit modifiers, the
* allocator must recognize two modifiers: INVALID (for implicit tiling and/or
* compression) and LINEAR.
*
* The allocator must return a buffer using one of the modifiers listed. In
* particular, allocators must not return a buffer with an implicit modifier
* unless the user has allowed it by passing INVALID in the modifier list.
*/
struct wlr_buffer *wlr_allocator_create_buffer(struct wlr_allocator *alloc,
int width, int height, const struct wlr_drm_format *format);
// For wlr_allocator implementors
void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl, uint32_t buffer_caps);
struct wlr_allocator *allocator_autocreate_with_drm_fd(
struct wlr_backend *backend, struct wlr_renderer *renderer, int drm_fd);
#endif

View File

@ -14,17 +14,27 @@
#define WLR_DMABUF_MAX_PLANES 4
enum wlr_dmabuf_attributes_flags {
WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT = 1 << 0,
WLR_DMABUF_ATTRIBUTES_FLAGS_INTERLACED = 1 << 1,
WLR_DMABUF_ATTRIBUTES_FLAGS_BOTTOM_FIRST = 1 << 2,
};
/**
* A Linux DMA-BUF pixel buffer.
*
* If the buffer was allocated with explicit modifiers enabled, the `modifier`
* field must not be INVALID.
*
* If the buffer was allocated with explicit modifiers disabled (either because
* the driver doesn't support it, or because the user didn't specify a valid
* modifier list), the `modifier` field can have two values: INVALID means that
* an implicit vendor-defined modifier is in use, LINEAR means that the buffer
* is linear. The `modifier` field must not have any other value.
*
* When importing a DMA-BUF, users must not ignore the modifier unless it's
* INVALID or LINEAR. In particular, users must not import a DMA-BUF to a
* legacy API which doesn't support specifying an explicit modifier unless the
* modifier is set to INVALID or LINEAR.
*/
struct wlr_dmabuf_attributes {
int32_t width, height;
uint32_t format;
uint32_t flags; // enum wlr_dmabuf_attributes_flags
uint64_t modifier;
uint32_t format; // FourCC code, see DRM_FORMAT_* in <drm_fourcc.h>
uint64_t modifier; // see DRM_FORMAT_MOD_* in <drm_fourcc.h>
int n_planes;
uint32_t offset[WLR_DMABUF_MAX_PLANES];

View File

@ -5,19 +5,55 @@
#include <stddef.h>
#include <stdint.h>
/** A single DRM format, with a set of modifiers attached. */
struct wlr_drm_format {
// The actual DRM format, from `drm_fourcc.h`
uint32_t format;
size_t len, cap;
// The number of modifiers
size_t len;
// The capacity of the array; do not use.
size_t capacity;
// The actual modifiers
uint64_t modifiers[];
};
/**
* A set of DRM formats and modifiers.
*
* This is used to describe the supported format + modifier combinations. For
* instance, backends will report the set they can display, and renderers will
* report the set they can render to. For a more general overview of formats
* and modifiers, see:
* https://lore.kernel.org/dri-devel/20210905122742.86029-1-daniels@collabora.com/
*
* For compatibility with legacy drivers which don't support explicit
* modifiers, the special modifier DRM_FORMAT_MOD_INVALID is used to indicate
* that implicit modifiers are supported. Legacy drivers can also support the
* DRM_FORMAT_MOD_LINEAR modifier, which forces the buffer to have a linear
* layout.
*
* Users must not assume that implicit modifiers are supported unless INVALID
* is listed in the modifier list.
*/
struct wlr_drm_format_set {
size_t len, cap;
// The number of formats
size_t len;
// The capacity of the array; private to wlroots
size_t capacity;
// A pointer to an array of `struct wlr_drm_format *` of length `len`.
struct wlr_drm_format **formats;
};
/**
* Free all of the DRM formats in the set, making the set empty. Does not
* free the set itself.
*/
void wlr_drm_format_set_finish(struct wlr_drm_format_set *set);
/**
* Return a pointer to a member of this `wlr_drm_format_set` of format
* `format`, or NULL if none exists.
*/
const struct wlr_drm_format *wlr_drm_format_set_get(
const struct wlr_drm_format_set *set, uint32_t format);
@ -27,4 +63,13 @@ bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set,
bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
uint64_t modifier);
/**
* Intersect two DRM format sets `a` and `b`, storing in the destination set
* `dst` the format + modifier pairs which are in both source sets.
*
* Returns false on failure or when the intersection is empty.
*/
bool wlr_drm_format_set_intersect(struct wlr_drm_format_set *dst,
const struct wlr_drm_format_set *a, const struct wlr_drm_format_set *b);
#endif

View File

@ -29,13 +29,6 @@
#include <wlr/render/dmabuf.h>
#include <wlr/render/drm_format_set.h>
struct wlr_egl_context {
EGLDisplay display;
EGLContext context;
EGLSurface draw_surface;
EGLSurface read_surface;
};
struct wlr_egl {
EGLDisplay display;
EGLContext context;
@ -44,13 +37,19 @@ struct wlr_egl {
struct {
// Display extensions
bool bind_wayland_display_wl;
bool image_base_khr;
bool image_dmabuf_import_ext;
bool image_dmabuf_import_modifiers_ext;
bool KHR_image_base;
bool EXT_image_dma_buf_import;
bool EXT_image_dma_buf_import_modifiers;
bool IMG_context_priority;
// Device extensions
bool device_drm_ext;
bool EXT_device_drm;
bool EXT_device_drm_render_node;
// Client extensions
bool EXT_device_query;
bool KHR_platform_gbm;
bool EXT_platform_device;
} exts;
struct {
@ -58,73 +57,21 @@ struct wlr_egl {
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
PFNEGLQUERYWAYLANDBUFFERWL eglQueryWaylandBufferWL;
PFNEGLBINDWAYLANDDISPLAYWL eglBindWaylandDisplayWL;
PFNEGLUNBINDWAYLANDDISPLAYWL eglUnbindWaylandDisplayWL;
PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT;
PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT;
PFNEGLDEBUGMESSAGECONTROLKHRPROC eglDebugMessageControlKHR;
PFNEGLQUERYDISPLAYATTRIBEXTPROC eglQueryDisplayAttribEXT;
PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT;
PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT;
} procs;
struct wl_display *wl_display;
bool has_modifiers;
struct wlr_drm_format_set dmabuf_texture_formats;
struct wlr_drm_format_set dmabuf_render_formats;
};
/**
* Initializes an EGL context for the given platform and remote display.
* Will attempt to load all possibly required api functions.
*/
struct wlr_egl *wlr_egl_create(EGLenum platform, void *remote_display);
/**
* Frees all related EGL resources, makes the context not-current and
* unbinds a bound wayland display.
*/
void wlr_egl_destroy(struct wlr_egl *egl);
/**
* Binds the given display to the EGL instance.
* This will allow clients to create EGL surfaces from wayland ones and render
* to it.
*/
bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display);
/**
* Creates an EGL image from the given wl_drm buffer resource.
*/
EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl,
struct wl_resource *data, EGLint *fmt, int *width, int *height,
bool *inverted_y);
/**
* Creates an EGL image from the given dmabuf attributes. Check usability
* of the dmabuf with wlr_egl_check_import_dmabuf once first.
*/
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_attributes *attributes, bool *external_only);
/**
* Get DMA-BUF formats suitable for sampling usage.
*/
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_texture_formats(
struct wlr_egl *egl);
/**
* Get DMA-BUF formats suitable for rendering usage.
*/
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_render_formats(
struct wlr_egl *egl);
bool wlr_egl_export_image_to_dmabuf(struct wlr_egl *egl, EGLImageKHR image,
int32_t width, int32_t height, uint32_t flags,
struct wlr_dmabuf_attributes *attribs);
/**
* Destroys an EGL image created with the given wlr_egl.
*/
bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image);
struct wlr_egl *wlr_egl_create_with_context(EGLDisplay display,
EGLContext context);
/**
* Make the EGL context current.
@ -138,18 +85,4 @@ bool wlr_egl_unset_current(struct wlr_egl *egl);
bool wlr_egl_is_current(struct wlr_egl *egl);
/**
* Save the current EGL context to the structure provided in the argument.
*
* This includes display, context, draw surface and read surface.
*/
void wlr_egl_save_context(struct wlr_egl_context *context);
/**
* Restore EGL context that was previously saved using wlr_egl_save_current().
*/
bool wlr_egl_restore_context(struct wlr_egl_context *context);
int wlr_egl_dup_drm_fd(struct wlr_egl *egl);
#endif

View File

@ -30,7 +30,6 @@ struct wlr_gles2_texture_attribs {
GLenum target; /* either GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES */
GLuint tex;
bool inverted_y;
bool has_alpha;
};

View File

@ -13,10 +13,12 @@
#include <wayland-server-core.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h>
#include <wlr/render/dmabuf.h>
struct wlr_box;
struct wlr_fbox;
struct wlr_renderer_impl {
bool (*bind_buffer)(struct wlr_renderer *renderer,
struct wlr_buffer *buffer);
@ -30,12 +32,8 @@ struct wlr_renderer_impl {
const float matrix[static 9], float alpha);
void (*render_quad_with_matrix)(struct wlr_renderer *renderer,
const float color[static 4], const float matrix[static 9]);
const uint32_t *(*get_shm_texture_formats)(struct wlr_renderer *renderer,
size_t *len);
bool (*resource_is_wl_drm_buffer)(struct wlr_renderer *renderer,
struct wl_resource *resource);
void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer,
struct wl_resource *buffer, int *width, int *height);
const uint32_t *(*get_shm_texture_formats)(
struct wlr_renderer *renderer, size_t *len);
const struct wlr_drm_format_set *(*get_dmabuf_texture_formats)(
struct wlr_renderer *renderer);
const struct wlr_drm_format_set *(*get_render_formats)(
@ -45,16 +43,7 @@ struct wlr_renderer_impl {
uint32_t *flags, uint32_t stride, uint32_t width, uint32_t height,
uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
void *data);
struct wlr_texture *(*texture_from_pixels)(struct wlr_renderer *renderer,
uint32_t fmt, uint32_t stride, uint32_t width, uint32_t height,
const void *data);
struct wlr_texture *(*texture_from_wl_drm)(struct wlr_renderer *renderer,
struct wl_resource *data);
struct wlr_texture *(*texture_from_dmabuf)(struct wlr_renderer *renderer,
struct wlr_dmabuf_attributes *attribs);
void (*destroy)(struct wlr_renderer *renderer);
bool (*init_wl_display)(struct wlr_renderer *renderer,
struct wl_display *wl_display);
int (*get_drm_fd)(struct wlr_renderer *renderer);
uint32_t (*get_render_buffer_caps)(struct wlr_renderer *renderer);
struct wlr_texture *(*texture_from_buffer)(struct wlr_renderer *renderer,

View File

@ -0,0 +1,18 @@
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#ifndef WLR_RENDER_VULKAN_H
#define WLR_RENDER_VULKAN_H
#include <wlr/render/wlr_renderer.h>
struct wlr_renderer *wlr_vk_renderer_create_with_drm_fd(int drm_fd);
bool wlr_texture_is_vk(struct wlr_texture *texture);
#endif

View File

@ -13,7 +13,6 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/types/wlr_box.h>
enum wlr_renderer_read_pixels_flags {
WLR_RENDERER_READ_PIXELS_Y_INVERT = 1,
@ -22,6 +21,8 @@ enum wlr_renderer_read_pixels_flags {
struct wlr_renderer_impl;
struct wlr_drm_format_set;
struct wlr_buffer;
struct wlr_box;
struct wlr_fbox;
struct wlr_renderer {
const struct wlr_renderer_impl *impl;
@ -80,16 +81,6 @@ void wlr_render_quad_with_matrix(struct wlr_renderer *r,
*/
const uint32_t *wlr_renderer_get_shm_texture_formats(
struct wlr_renderer *r, size_t *len);
/**
* Returns true if this wl_buffer is a wl_drm buffer.
*/
bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *renderer,
struct wl_resource *buffer);
/**
* Gets the width and height of a wl_drm buffer.
*/
void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *renderer,
struct wl_resource *buffer, int *width, int *height);
/**
* Get the DMA-BUF formats supporting sampling usage. Buffers allocated with
* a format from this list may be imported via wlr_texture_from_dmabuf.
@ -108,13 +99,19 @@ bool wlr_renderer_read_pixels(struct wlr_renderer *r, uint32_t fmt,
uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data);
/**
* Creates necessary shm and invokes the initialization of the implementation.
* Initializes wl_shm, linux-dmabuf and other buffer factory protocols.
*
* Returns false on failure.
*/
bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
struct wl_display *wl_display);
/**
* Initializes wl_shm on the provided wl_display.
*/
bool wlr_renderer_init_wl_shm(struct wlr_renderer *r,
struct wl_display *wl_display);
/**
* Obtains the FD of the DRM device used for rendering, or -1 if unavailable.
*

Some files were not shown because too many files have changed in this diff Show More