gtk4paintablesink: Add support for direct-scanout / zero-copy on Wayland (using subsurfaces with YCbCr/YUV formats)
Motivation
Wayland allows us to pass dmabufs from hardware video decoders directly to the system compositor, which again may be able to pass them on to display controller hardware planes, archiving highly resource efficient video playback. That is the concept behind GstWl
/waylandsink
/gtkwaylandsink
which, however, focus on embedded use cases.
Adding support for this to gtk4paintablesink
would greatly increase its reach, making video (and possible camera) apps more efficient. Optimally, things will work transparently for apps, so various video players like Clapper would automatically benefit from it. This in turn would benefit the whole Linux/Wayland ecosystem in various ways.
Idea
Whenever possible the gtk4paintablesink
should use a Wayland subsurface to upload dmabufs directly, essentially like gtkwaylandsink
. Otherwise it should fall back to the current behavior and render the content via GSK.
In case of Clapper this would be the case when no controls/overlays are visible (the gtk4paintablesink
is fully unobscured, no other GTK widgets are on top) and no modifications are done to the visible area (no clip masks for e.g. rounded corners) - i.e. when Clapper is in fullscreen mode.
Steps / Brainstorming
I haven't investigated the details yet, but on a high level I think at least the following steps would be necessary:
- The
gtk4paintablesink
needs direct access to dmabufs. Possibly either:- Advertise the capabilities for
video/x-raw(memory:DMABuf)
with formats likeNV12
,P010_10LE
,YUY2
etc. Judging from 95a7a3c0 for the GSK path some kind of shader would be necessary in order to meet the renderers expectations, even if the driver can sample directly from the format. - Add the formats to the
video/x-raw(memory:GLMemory)
section and re-export the dmabufs if needed?
- Advertise the capabilities for
- In order to properly detect the cases when we can use a subsurface we most likely need new API in GTK4. Something along the lines of
gtk_widget_can_be_promoted_to_overlay()
- GTK4 unofficially supports subsurfaces in a similar way to GTK3 (where subsurfaces are used by
gtkwaylandsink
and notably Firefox), however it hasn't carried over dirty hacks like this. Thus better subsurface support API most likely is needed.
Notes:
- Gnome/Mutter supports YUV format since the recently released version 45