Commit Graph

29 Commits

Author SHA1 Message Date
Derek Foreman 50d92f9d6f libweston: Fix crash with mirror-of
Since c4eb15d453 we keep a copy of
native mode parameters, however we forgot to initialize the
native mode parameters in some situations, which breaks the
output mirroring code when it sees uninitialized data.

Fixes c4eb15d453
Fixes #949

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-08-30 08:16:45 -05:00
Philipp Zabel 4b4cedfc66 backend-pipewire: add fence to synchronize on finish of render
If the PipeWire-backend renders to a DmaBuf, try to use a fence to synchronize
the submit of the next PipeWire buffer to the completion of the current render
process.

This ensures that the GPU rendering is finished before the buffer is passed to
PipeWire.

If fences are not available, the buffer is submitted without explicit
synchronization as before.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-08-05 09:09:51 +00:00
Michael Tretter ae53d196db backend-pipewire: add DmaBuf allocation and import
The GL renderer allows the PipeWire backend to allocate DMABUFs that can be used
as renderbuffers and passed to PipeWire. This allows to avoid a copy of the
rendered output when using PipeWire.

PipeWire negotiates DmaBuf buffers using the SPA_FORMAT_VIDEO_modifier property.
Currently, the PipeWire-backend only announces and handles
DRM_FORMAT_MOD_LINEAR, which allows to share DmaBufs with consumers that have
modifier support for linear buffers. Consumers which could consume DmaBufs but
don't support modifiers (DRM_FORMAT_MOD_INVALID) are not supported. Moreover,
consumers that would benefit from other formats with modifiers, for example
tiled or compressed, aren't not supported, too.

Modifier negotiation can be added by extending the list of announced modifiers
and selecting and checking the proposed modifiers in param_changed.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-07-19 11:43:42 +02:00
Michael Tretter fa2f05219e backend-pipewire: add MemFd allocator
Instead of letting PipeWire allocate the buffers, allocate them in the PipeWire
backend. This allows the PipeWire backend to define the type of the allocated
buffers, which will ultimately allow to allocate buffers that can be rendered
to.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-07-19 11:43:42 +02:00
Michael Tretter 4304468a7e backend-pipewire: add helper function for building format params
Add a helper function for building the pod for the format.

This simplifies the creation of the EnumFormat params and to provide multiple
EnumFormats. Furthermore, it allows to optionally set add a Modifier to enable
DmaBuf negotiation.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-07-19 11:43:42 +02:00
Michael Tretter 073a97a9f5 backend-pipewire: skip rendering and free if there is no renderbuffer
The PipeWire backend is only able to render into renderbuffers and passing NULL
to the renderer is not valid. Don't try to use the renderbuffer if a buffer
without renderbuffer is dequeued from PipeWire.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-07-19 11:43:42 +02:00
Marius Vlad c6aa8c9b17 backend-pipewire: Nuke band-aid
With commit a1f8c49d5b 'compositor: repaint backends separately'
we will be repainting outputs independently so there's no need to keep
this band-aid on. Further more, the comment was most likely wrong.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2024-07-03 09:30:08 +00:00
Jordan Williams 2e6c58fb37
meson: Add missing dependencies on egl
A proper dependency on egl is missing for several backends as well as
for libshared. This dependency is necessary to pull in the correct
include directories from the egl.pc pkg-config file. 

Signed-off-by: Jordan Williams <jordan@jwillikers.com>
2024-03-18 10:27:40 -05:00
Marius Vlad b93335a741 backend-pipewire: Move region initialization at the start
Failure to do so, might cause a crash if the output repaint happens
before the pipewire pipeline started -- calling pixman_region32_fini on
a uninitialized region.

Fixes 2abe4efcf7, "libweston/backends: Move damage flush into backends"

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2024-03-11 12:31:55 +00:00
Derek Foreman 2abe4efcf7 libweston/backends: Move damage flush into backends
Currently we flush damage for the "primary plane" every repaint, but this
is folly.

The drm backend may skip rendering entirely if using an all-planes
composition. This could leave the renderer plane in a messy state if a
surface on an overlay plane disappears.

Instead, let the backends flush the primary plane damage when they know
they need to render.

Fixes #864

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-01-10 14:13:09 -06:00
Philipp Zabel 308d5cf367 backend-pipewire: enable multi-backend support
Insert the backend into the weston_compositor::backend_list instead
of setting weston_compositor::backend. The compositor uses this to
determine whether the backend is capable of being loaded simultaneously
with other backends.

To stay backwards compatible, the PipeWire backend can be loaded as
primary backend. It also supports being loaded as secondary backend.

Co-authored-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-09-28 14:02:04 +00:00
Philipp Zabel 2fc6a8bbd2 backend-pipewire, libweston: Extract weston_output_finish_frame_from_timer()
Extract the finish frame timestamp code and the call to
weston_output_finish_frame() into a new helper function
weston_output_finish_frame_from_timer() that can be reused
by the other timer driven backends sharing the same logic.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-09-27 12:37:09 +03:00
Philipp Zabel eec50e5aac backend-pipewire, libweston: Extract weston_output_arm_frame_timer()
Extract pipewire_output_arm_timer() into libweston so it can be reused
by the other timer driven backends that use the same delay logic.

Call the shared function weston_output_arm_frame_timer().

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-09-27 12:37:09 +03:00
Philipp Zabel 4d14adaa2c backend-pipewire: make sure to finish frames with timestamps in the past
Round up the ms delay to make sure that the finish_frame_timer always
expires after the next frame_time. That way, finish_frame_handler()
never passes a timestamp in the future to weston_output_finish_frame().
Setting frame_time into the future risks hitting an assert in
weston_output_finish_frame(), when it is called from start_repaint_loop
within the frame interval.

Use CLIP() to simplify limiting the ms delay to a reasonable range.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-09-15 09:44:44 +03:00
Philipp Zabel 1d59530e4b libweston: Set the presentation clock in the compositor
Let backends declare the presentation clocks they can use with a
new bitfield weston_backend::supported_presentation_clocks and set
presentation clock after loading the backend in the compositor.

Make weston_compositor_set_presentation_clock() internal and replace
weston_compositor_set_presentation_clock_software() with an exported
weston_compositor_backends_loaded(), which is called by the compositor
after the backend is loaded.

In the future, this can be extended to determine the subset of clocks
supported by all backends.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-08-02 11:51:56 +03:00
Derek Foreman f07af89f9c libweston: Move output damage subtraction out of backends
Right now every backend clears output damage from the primary plane when
it repaints. Instead of having this same operation spread across all
the backends, just do it in the core instead.

In the future, we want to remove damage tracking from the primary plane
entirely, and this is a small step in that direction.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-07-11 07:26:43 -05:00
Philipp Zabel 90c11cf40e libweston: move weston_compositor_shutdown call out of backends
If we want to support multiple backends, the compositor must take care
to call this once, at the appropriate moment, so stop letting the
backends handle compositor shutdown themselves.

Move the weston_compositor_shutdown() calls from the backend::destroy
callbacks into weston_compositor_destroy() and the calls in the backend
creation error paths into weston_compositor_load_backend().

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-06-27 12:09:47 +01:00
Philipp Zabel 5b1974fa4f backend-pipewire: add GL renderer support
While the GL renderer is not able to directly render into the PipeWire buffers,
it is possible to read the rendered frame from the fbo into the PipeWire buffer.

Use the automatic download to add support for the GL renderer to the PipeWire
backend.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-06-13 13:02:12 +00:00
Michael Tretter a9d1b5dc50 backend-pipewire: make renderer initialization depend on renderer
Instead of always initializing the Pixman renderer, make the initialization
dependent on the selected renderer. This makes it easier to add other renderers.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-06-13 13:02:12 +00:00
Michael Tretter 1effba000e backend-pipewire: add local variables for spa_buffer and data
Make it easier to understand where ptr points to by using local variables for
the spa_buffer and spa_data.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-06-13 13:02:12 +00:00
Michael Tretter b5854ff95d backend-pipewire: move pixman renderbuffer creation to helper
Extract the pixman renderbuffer configuration from the add_buffer function into
a helper function to simplify the addition of the GL renderer.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-06-13 13:02:12 +00:00
Michael Tretter 7155d00929 backend-pipewire: move pixman setup into helper functions
Use helper function for setting up the pixman renderer to simplify the addition
of the GL renderer.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-06-13 13:02:12 +00:00
Michael Tretter 8cf4d79be7 backend-pipewire: remove unused fields from pipewire_frame_data
The output and buffer fields of pipewire_frame_the data are not actually used.
Remove them.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-05-23 10:41:25 +02:00
Michael Tretter 6c20bc5333 backend-pipewire: remove duplicate empty line
There was a sneaky newline. Remove it.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-05-23 10:41:00 +02:00
Philipp Zabel f154fbba97 libweston: consolidate 'Using GL/Pixman renderer' log message
Consolidates the 'Using GL/Pixman renderer' message emitted by the
PipeWire, RDP, VNC, and X11 backends by moving the weston_log() into
weston_compositor_init_renderer(). Only print the message after
initializing the renderer has succeeded.

This effectively adds the message to the DRM, headless, and Wayland
backends.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-05-04 14:47:49 +02:00
Robert Mader 445ff6728b pipewire-[backend|plugin]: Add timestamps to buffers
In Pipewire and Gstreamer terminology Weston is a "live" source (as we
do not explicitly set PW_KEY_STREAM_IS_LIVE to false).
Such sources, be it compositors, cameras or microphones, usually set
the current system time as timestamps on buffers in order to make life
easier for consumers. Thus let's do so as well.

This notably helps when recording using `gstpipewiresrc` with the
`keepalive-time` property set.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
2023-04-20 12:32:49 +00:00
Philipp Zabel 2d3e170955 backend-pipewire: remove linear modifier for now
As of PipeWire version 0.3.69, the gstpipewiresrc element uses the
existence of a modifier as a trigger to select dmabuf memory, failing
caps negotiation as we don't send DMA buffers yet.

Remove the linear modifier for now, to be added back when we add dmabuf
support to the PipeWire backend. This allows testing the PipeWire
backend with current GStreamer + PipeWire.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-04-19 13:56:44 +00:00
Philipp Zabel dfa821d4c0 backend-pipewire: pass backend to weston_pipewire_output_api::create_head()
Pass the backend instead of the compositor to the PipeWire output API
create_head() method and increment the API version.

That way the backend will not have to find the backend pointer from the
compositor. This is trivial now, but in the multi-backend case would
entail iterating over all backends to find the correct one.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-04-19 13:36:45 +00:00
Philipp Zabel ebc3a22b09 backend-pipewire: add PipeWire backend
Add a separate PipeWire backend based on the PipeWire plugin. The backend
requires PipeWire 0.3.x.

The PipeWire backend can be used as a standalone-backend backend for streaming
and composing Wayland clients to PipeWire.

The backend supports the on-demand creation of heads via the
weston_pipewire_output_api_v1. It also supports per-output pixel format
configuration via a gbm-format option.

Multiple PipeWire outputs can be created by setting the num-outputs option in
the [pipewire] section.

Co-authored-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-04-18 10:48:50 +00:00