Currently, we use a proprietary protocol for sharing GBM buffers, which are then imported in xdg-desktop-portal-kde. The main problem with the current approach is that it's not suitable for capturing individual windows and we have to copy buffers in xdg-desktop-portal-kde.
A better way to implement screen casting would be to introduce an API which xdg-desktop-portal-kde could use to request a PipeWire stream for the particular screen or window. Once, KWin is a PipeWire server, we can drop the GBM thing.
PipeWire allows buffers to be shared using DMA-Buf and memfd. memfd can be especially useful for NVIDIA users. Obviously, this would mean higher CPU usage, but it's better than nothing.
Protocol-wise, the API for requesting PipeWire streams can be implemented using D-Bus. For reference, here's Mutter's D-Bus API https://gitlab.gnome.org/GNOME/mutter/-/blob/master/src/org.gnome.Mutter.ScreenCast.xml