Commit Graph

39 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult d708b28adc treewide: drop COMPOSITE symbol
It's always enabled for very long time now (at least since meson transition),
there doesn't seem to be any need to ever disable it again. So we can reduce
code complexity by removing all the ifdef's.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:47:01 +02:00
Enrico Weigelt, metux IT consult 0132baa422 xwayland: use dixDestroyPixmap() instead of direct driver call
Direct calls to ScreenRec->DestroyPixmap() blocks cleaning up the wrapping
jungle, so use the proper dix function instead.

See: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1754

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1711>
2025-02-12 17:48:30 +01:00
Olivier Fourdan 23c295ea8b xwayland: Do not include sys/eventfd.h without DRI3
Now that we won't enable DRI3 if <sys/eventfd.h> is not available, there
is not point in trying to include that header without DRI3.

That allows to build Xwayland with GLAMOR enabled (without DRI3) on
platforms which do not support eventfd.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1523>
2024-08-05 10:24:58 +02:00
Olivier Fourdan fa04e15afc xwayland/window-buffers: optionally force disposal
For cases (to come) where we would want to force the disposal of the
window buffers, add a parameter to force the disposal by calling
dispose() directly instead of maybe_dispose().

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1589>
2024-07-04 08:26:23 +00:00
Olivier Fourdan 571cb13342 xwayland/window-buffers: Move buffer disposal to its own function
No functional change, this is just preparation work for the next commit.

v2: Reshuffle functions (Michel)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1589>
2024-07-04 08:26:23 +00:00
Olivier Fourdan bc9bf56360 xwayland/window-buffers: Set syncpnts for all pixmaps
The wp_linux_drm_syncobj_v1 protocol states that :

| If at surface commit time there is a pending buffer attached but no
| pending release timeline point set, the no_release_point protocol
| error is raised.

So we need to set a release timeline point in any case from the swap
pixmap routine, even for the early out code paths.

Failing to do so may cause a Wayland protocol error that is fatal to the
Wayland client, in this case Xwayland:

| wp_linux_drm_syncobj_surface_v1: error 4: No Acquire point provided
| (EE) failed to dispatch Wayland events: Protocol error

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1688
Fixes: 87bf2cafcc - xwayland: add support for wp_linux_drm_syncobj_v1
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1571>
2024-07-04 08:13:36 +00:00
Olivier Fourdan 33330f0dc9 xwayland/window-buffers: Move code to submit pixmaps
Move the code which takes care of submitting pixmaps and the
synchronization points to its own function.

This will allow to reuse that code from different code path.

No functional change intended.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1571>
2024-07-04 08:13:36 +00:00
Olivier Fourdan aab01c7391 xwayland/window-buffers: Do not always set syncpnts
The function xwl_window_swap_pixmap() can be called from two places,
either from xwl_window_attach_buffer() or from damage_report().

When called from xwl_window_attach_buffer(), the new buffer is attached
and the surface committed.

However, when called from damage_report(), a new buffer might not be
attached before the surface is committed.

That's fine with implicit synchronization, but if we use explicit
synchronization, committing a surface without a new buffer attached but
with a release timeline point set is a protocol error:

| If at surface commit time there is a pending release timeline point
| set but no pending buffer attached, a no_buffer error is raised.

To avoid such an issue, add a new parameter to xwl_window_swap_pixmap()
to hint whether it should set the synchronization points, and have the
synchronization points set only from xwl_window_attach_buffer().

v2: Rename param to handle_sync (Michel)

Suggested-by: Michel Dänzer <mdaenzer@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1571>
2024-07-04 08:13:36 +00:00
Olivier Fourdan 256cef8b20 xwayland/window-buffers: Use synchronization from GLAMOR/GBM
Now that we have the buffer synchronization implemented in the
GLAMOR/GBM code, switch to use that code.

At this point, there is still not functional change intended, this is
still preparation work for a fix that is still to come.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1571>
2024-07-04 08:13:36 +00:00
Olivier Fourdan b5082073b0 xwayland/window-buffers: Add xwl_window_buffer_release()
We want to decorrelate the explicit buffer synchronization from the
window buffers, and move that to the GLAMOR/GBM code instead.

To do that, we need to be able to invoke the xwl_window_buffer's
release_callback() routine from outside the window buffer code.

For that purpose, introduce xwl_window_buffer_release() which calls
xwl_window_buffer_release_callback() for us.

This is preparation work for the following changes, no functional change
intended at this point.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1571>
2024-07-04 08:13:36 +00:00
Michel Dänzer 3a0fc2684a xwayland: Add xwl_window::surface_window
It may track a non-toplevel window which fully covers the area of the
window pixmap / Wayland surface. It is now used instead of
xwl_window::toplevel for updating the Wayland surface contents.

The surface_window can now hit the Present page flip path while it's
automatically redirected.

v2:
* Use "surface_window" instead of "surf_win". (Olivier Fourdan)
* Add comment describing surface_window, and describe what
  surface_window/toplevel are useful for respectively. (Olivier Fourdan)
* Use surface_window in xwl_realize_window.
v3:
* Backtrack up to the closest opaque ancestor in
  xwl_window_update_surface_window. (Olivier Fourdan)
v4:
* Clean up logic for determining the surface window in
  xwl_window_update_surface_window, and document it better.
* Handle window_get_damage(xwl_window->surface_window) returning NULL
  in xwl_window_update_surface_window.
* Call xwl_window_update_surface_window after xwl_window_buffers_init
  in ensure_surface_for_window, since the former may call
  xwl_window_buffers_dispose.
* Rename surf/win_pix to surface/window_pixmap in
  xwl_window_update_surface_window.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1300>
2024-04-10 08:55:08 +00:00
Michel Dänzer db248682b3 xwayland: Pass xwl_window to xwl_glamor_dri3_syncobj_passthrough
Preparation for later changes, no functional change intended.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1300>
2024-04-10 08:55:08 +00:00
Michel Dänzer 972d5af537 xwayland: Rename xwl_window::window to ::toplevel
It's always the toplevel window, i.e. either the root window or a child
of it.

Preparation for later commits, no functional change.

v2: (Olivier Fourdan)
* Fix debug build.
* Add comment describing ::toplevel.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1300>
2024-04-10 08:55:08 +00:00
Erik Kurzinger 87bf2cafcc xwayland: add support for wp_linux_drm_syncobj_v1
This protocol allows for explicit synchronization of GPU operations by
Wayland clients and the compositor. Xwayland can make use of this to
ensure any rendering it initiates has completed before the target image
is accessed by the compositor, without having to rely on kernel-level
implicit synchronization.

Furthermore, for X11 clients that also support explicit synchronization
using the mechanisms exposed in the DRI3 and Present extensions, this
Wayland protocol allows us to simply forward the timeline, acquire, and
release points directly to the compositor, ideally avoiding any
premature stalls in the presentation pipeline.

Signed-off-by: Erik Kurzinger <ekurzinger@nvidia.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/967>
2024-04-09 06:11:03 +00:00
Xaver Hugl d411a8b611 xwayland: add workaround for drivers that don't support impicit sync
Without either implicit or explicit synchronization, the result of rendering is
pretty much undefined, and many glitches can appear. This still doesn't synchronize
buffer release, but it works around most glitches until explicit sync is supported.

Signed-off-by: Xaver Hugl <xaver.hugl@kde.org>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/967>
2024-04-09 06:11:03 +00:00
Olivier Fourdan 54a2dfc229 xwayland: Drop xwl_window_buffers_get_pixmap()
This just calls into xwl_window_swap_pixmap() so we can just use that
instead (Michel).

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1386>
2024-03-18 15:41:18 +00:00
Olivier Fourdan 656d2efd4b xwayland/glamor: Drop xwl_glamor_needs_n_buffering()
This function always return TRUE now that EGLSTream is gone, so we can
remove it.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1386>
2024-03-18 15:41:18 +00:00
Michel Dänzer 6b290fa5d9 xwayland: Replace window pixmap as needed for drawing operation
We must not modify the contents of a client pixmap.

If there's an available window buffer, we re-use that for the window
pixmap. Otherwise we just allocate a new one.

This also avoids Present client hangs due to xwl_present_buffer_release
not getting called for the buffer release event.

v2:
* Use xwl_pixmap_get_buffer_release_cb instead of keeping track of the
  flip pixmap in xwl_window.
* Dispose of xwl_window_buffer in xwl_window_swap_pixmap called from
  damage_report.
v3:
* Use xwl_window->surface_pixmap in damage_report.
v4:
* Don't re-use client pixmaps as window buffers.
* Clear xwl_window_buffer->pixmap before calling
  xwl_window_buffer_maybe_dispose in xwl_window_swap_pixmap, to prevent
  it from clearing the buffer release callback.
v5:
* Keep using xwl_window_buffers_get_pixmap in xwl_window_attach_buffer.
* Always keep a reference to the old window pixmap in _swap_pixmap,
  drop it in damage_report.

Fixes: 6779ec5bf6 ("xwayland: Use window pixmap as a window buffer")
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1633
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1644
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1314>
2024-03-06 17:12:54 +01:00
Michel Dänzer 0e29cccf36 xwayland: Re-use xwl_window_realloc_pixmap in xwl_window_swap_pixmap
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1314>
2024-03-06 17:09:22 +01:00
Michel Dänzer 44527c2549 xwayland: Refactor xwl_window_swap_pixmap out of _buffers_get_pixmap
There will be another caller in a later commit.

v2:
* Bump xwl_window_buffer->refcnt in xwl_window_swap_pixmap, to prevent
  xwl_window_set_pixmap from disposing of it.
v3:
* Go back to bumping xwl_window_buffer->refcnt in
  xwl_window_buffers_get_pixmap. xwl_window_set_pixmap should no longer
  dispose of it now that xwl_glamor_gbm_create_pixmap_for_window is
  fixed, and xwl_window_swap_pixmap forgot to bump it if
  xwl_window_buffer_get_available returned NULL.
v4:
* Unlink xwl_window_buffer from xwl_window->window_buffers_available
  before calling xwl_window_set_pixmap in xwl_window_swap_pixmap, or
  that might dispose of it.
v5:
* xwl_window_swap_pixmap does everything xwl_window_buffer_get_available
  did before, except for just using the window pixmap if
  !xwl_glamor_needs_n_buffering.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1314>
2024-03-06 16:58:17 +01:00
Michel Dänzer af4b64d227 xwayland: Rename xwl_window_recycle_pixmap to xwl_window_realloc_pixmap
It doesn't recycle anything but allocates a new pixmap from scratch.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1314>
2024-03-06 16:55:13 +01:00
Michel Dänzer 716805e3ad xwayland: Call xwl_window_buffer_add_damage_region from damage_report
Before clearing the damage region. Otherwise the damage region from a
Present flip may be ignored when replacing the window pixmap.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1314>
2024-03-06 16:55:13 +01:00
Michel Dänzer c1c5bf382e xwayland: Do not plumb damage region through function parameters
Each function can get the damage region from the xwl_window instead.
Add xwl_window_get_damage_region helper for this.

v2:
* Use xwl_window_get_damage_region in xwl_window_attach_buffer as well
  (Olivier Fourdan)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1314>
2024-03-06 16:55:13 +01:00
Michel Dänzer 3ddb81b15e xwayland: Update screen pixmap for root window in xwl_window_set_pixmap
If the old window pixmap was the screen pixmap.

Fixes screen->GetScreenPixmap() returning a stale pointer to a destroyed
pixmap with rootful Xwayland. It would result in a crash after resizing
the Xwayland window, or at the latest when shutting down.

Fixes: 6779ec5bf6 ("xwayland: Use window pixmap as a window buffer")
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1621
2024-01-17 18:12:37 +01:00
Michel Dänzer cad42fcb08 xwayland: Destroy old window pixmap in xwl_window_recycle_pixmap
We were leaking it.

Fixes: 6779ec5bf6 ("xwayland: Use window pixmap as a window buffer")
2024-01-12 17:06:39 +00:00
Michel Dänzer 777c3e0000 xwayland: Return NULL from xwl_window_buffer_get_available
If there's no available window buffer.

This allows keeping xwl_window_buffer->damage_region empty for a newly
allocated xwl_window_buffer in xwl_window_buffers_get_pixmap, instead
of first populating it in xwl_window_buffer_add_damage_region and then
emptying it again.
2024-01-10 17:31:42 +00:00
Michel Dänzer 6779ec5bf6 xwayland: Use window pixmap as a window buffer
Assuming the same number of window buffers, this results in one less
pixmap per toplevel window, saving pixmap storage.

v2:
* Preserve xwl_window_buffer_get_available behaviour (Olivier Fourdan)
v3:
* Leave RegionEmpty call where it was in xwl_window_buffers_get_pixmap,
  so it takes effect for a newly allocated struct xwl_window_buffer.
* Consolidate xwl_window_buffer->pixmap assignment in the same place.
2024-01-10 17:31:42 +00:00
Michel Dänzer 2b577c2e3b xwayland: Drop xwl_window_buffers_recycle
Use xwl_window_buffers_dispose instead. The pixmaps will need to be
re-created anyway, so keeping around the xwl_window_buffers doesn't
buy much. And dropping this makes the next commit simpler.

Also fold xwl_window_buffer_destroy_pixmap into its only remaining
caller,  xwl_window_buffer_maybe_dispose.

v2: (Olivier Fourdan)
* Fix up indentation in xwl_window_set_window_pixmap
* Leave xwl_window_buffer_destroy_pixmap helper
2024-01-10 17:31:42 +00:00
Michel Dänzer 2879032ecc xwayland: Rename helper to xwl_window_buffer_maybe_dispose
To make it clearer that it doesn't always dispose of the
xwl_window_buffer, only if the reference count drops to 0.
2024-01-10 17:31:42 +00:00
Michel Dänzer 114f060de5 xwayland: Make copy_pixmap_area return void
GetScratchGC can't really fail without a bug elsewhere. Just FatalError
in that case, so we'd get a bug report if it ever happens, instead of
trying to limp along.
2024-01-10 17:31:42 +00:00
Olivier Fourdan 684580d06f xwayland: Try the Xwayland glamor hook to create pixmaps
When creating the window buffer's backing pixmap, try the Xwayland
glamor hook first and fallback to the regular CreatePixmap() code path
otherwise.

That allows to enable direct scanout if possible, either through the
regular dmabuf v4 code path, or from the implicit fallback code path.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-04-03 11:46:15 +02:00
Olivier Fourdan f95d81e88b xwayland: Hold window buffer until released
The window buffer mechanism would free the pixmap and its corresponding
Wayland buffer as soon as window buffers are disposed.

Typically when the X11 window is unrealized, the current window buffer
is still used by the Wayland compositor and yet Xwayland will destroy
the buffer.

As a matter of fact, Xwayland should not destroy the Wayland buffer
before the wl_buffer.release event is received.

Add a reference counter to the window buffer similar to the to pixmap
reference counter to keep the buffer around until the release callback
is received.

Increase that reference counter on the buffer which will be attached to
the surface, and drop that reference when receiving the release callback
notification.

v2: Use a specific reference counter on the buffer rather than relying
    on the pixmap refcnt (Michel Dänzer <mdaenzer@redhat.com>)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Acked-by: Martin Peres <martin.peres@mupuf.org>
2020-12-10 13:49:42 +01:00
Olivier Fourdan 0b86c0c362 xwayland: Add a flag for n-buffers in EGL backend
Using multiple window buffers crashes with EGLStream, which does not
need it anyway as this is handled through EGL directly.

Add a flag to the EGL backend to indicate whether it would benefit from
multiple buffers and use this in the get_buffer() function.

Thanks to Adam Jackson <ajax@redhat.com> for pointing out that issue
with EGLStream.

v2: Fix logical test (Adam Jackson <ajax@redhat.com>)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2020-09-22 17:59:42 +02:00
Michel Dänzer 12af425acd xwayland: Rename xwl_pixmap_cb → xwl_buffer_release_cb
Seems clearer.

While we're at it, also drop the unused pixmap parameter.

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2020-07-07 13:47:11 +00:00
Olivier Fourdan 0617c635fa xwayland: Separate Xwayland screen code
Move Xwayland screen related code to a separate source file and header.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan d780bdc2fd xwayland: Separate Xwayland pixmap code
Move Xwayland generic pixmap code to a separate source file and header.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan 89e32d00f6 xwayland: Move Xwayland windows to its own sources
Over time, Xwayland main source file `xwayland.c` has grown in size
which makes it look cluttered and harder to read.

Move the code dealing with Xwayland window to its own source and header
files.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan 46e5236bbe xwayland: Take border width into account
Damage coordinates are relative to the drawable, (0,0) being the top
left corner inside the border.

Therefore, when applying damages or accumulating damages between window
buffers, we need to take the window border width into account as well,
otherwise the updates might be only partial or misplaced.

Related: https://gitlab.freedesktop.org/xorg/xserver/issues/951
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-13 16:11:09 +01:00
Olivier Fourdan 1c6f875f52 xwayland: Add multiple window buffering support
Add a mechanism to create, recycle and destroy window buffers when
needed.

Typically, this adds a new `xwl_window_buffer` structure which
represents a buffer for a given Xwayland window.

Each Xwayland window has two different pools of buffers:

 - The available buffers pool:
   Those are buffers which where created previously and that have either
   not been submitted to the compositor or submitted and released.

 - The unavailable buffers pool:
   Those are typically the buffers which are being used by the
   compositor, awaiting a release.

Initially, an Xwayland window starts with both pools empty. As soon as a
new buffer is needed, it's either created (if there is none available)
or picked from the pool of available buffers.

Once submitted to the compositor, the buffer is moved to the pool of
unavailable buffers. When the corresponding `wl_buffer` is released by
the compositor, it is moved back to pool of available buffers again to
be reused when needed.

To avoid keeping too many buffers around doing nothing, a garbage
collection of older, unused buffers also takes care of disposing the
buffers being unused for some time.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-11-28 17:32:44 +01:00