forge
Explore
Log in

Don't you dare go Hollow

backend/winit: Add GBM device for screencasting

Browse files at this commit

ab8e7742caaad4467e91cea9cef906cb371d4bb1Ivan MolodetskikhParent: 3232b02
Enables dmabuf PW screencasting on winit.
src/backend/mod.rsmodified+1 -1
@@ -176,7 +176,7 @@ impl Backend {
176 ) -> Option<smithay::backend::allocator::gbm::GbmDevice<smithay::utils::DeviceFd>> {176 ) -> Option<smithay::backend::allocator::gbm::GbmDevice<smithay::utils::DeviceFd>> {
177 match self {177 match self {
178 Backend::Tty(tty) => tty.primary_gbm_device(),178 Backend::Tty(tty) => tty.primary_gbm_device(),
179- Backend::Winit(_) => None,179+ Backend::Winit(winit) => winit.gbm_device(),
180 Backend::Headless(_) => None,180 Backend::Headless(_) => None,
181 }181 }
182 }182 }
src/backend/winit.rsmodified+41 -0
@@ -35,6 +35,8 @@ pub struct Winit {
35 damage_tracker: OutputDamageTracker,35 damage_tracker: OutputDamageTracker,
36 render_node: Option<DrmNode>,36 render_node: Option<DrmNode>,
37 dmabuf_global: Option<DmabufGlobal>,37 dmabuf_global: Option<DmabufGlobal>,
38+ #[cfg(feature = "xdp-gnome-screencast")]
39+ gbm_device: Option<smithay::backend::allocator::gbm::GbmDevice<smithay::utils::DeviceFd>>,
38 ipc_outputs: Arc<Mutex<IpcOutputMap>>,40 ipc_outputs: Arc<Mutex<IpcOutputMap>>,
39 }41 }
40 42
@@ -148,6 +150,8 @@ impl Winit {
148 damage_tracker,150 damage_tracker,
149 render_node: None,151 render_node: None,
150 dmabuf_global: None,152 dmabuf_global: None,
153+ #[cfg(feature = "xdp-gnome-screencast")]
154+ gbm_device: None,
151 ipc_outputs,155 ipc_outputs,
152 })156 })
153 }157 }
@@ -197,6 +201,11 @@ impl Winit {
197 201
198 self.create_dmabuf_global(niri);202 self.create_dmabuf_global(niri);
199 203
204+ #[cfg(feature = "xdp-gnome-screencast")]
205+ if let Err(err) = self.create_gbm_device() {
206+ debug!("couldn't create GBM device for screencasting: {err:?}");
207+ };
208+
200 niri.add_output(self.output.clone(), None, false);209 niri.add_output(self.output.clone(), None, false);
201 }210 }
202 211
@@ -238,6 +247,38 @@ impl Winit {
238 assert!(self.dmabuf_global.replace(dmabuf_global).is_none());247 assert!(self.dmabuf_global.replace(dmabuf_global).is_none());
239 }248 }
240 249
250+ #[cfg(feature = "xdp-gnome-screencast")]
251+ fn create_gbm_device(&mut self) -> anyhow::Result<()> {
252+ use std::os::fd::OwnedFd;
253+
254+ use smithay::backend::allocator::gbm::GbmDevice;
255+ use smithay::utils::DeviceFd;
256+
257+ let node = self
258+ .render_node
259+ .as_ref()
260+ .context("no render node available")?;
261+ let path = node.dev_path().context("render node has no device path")?;
262+ let file = std::fs::File::options()
263+ .read(true)
264+ .write(true)
265+ .open(path)
266+ .context("error opening render node")?;
267+
268+ let gbm_device = GbmDevice::new(DeviceFd::from(OwnedFd::from(file)))
269+ .context("error creating GBM device")?;
270+
271+ self.gbm_device = Some(gbm_device);
272+ Ok(())
273+ }
274+
275+ #[cfg(feature = "xdp-gnome-screencast")]
276+ pub fn gbm_device(
277+ &self,
278+ ) -> Option<smithay::backend::allocator::gbm::GbmDevice<smithay::utils::DeviceFd>> {
279+ self.gbm_device.clone()
280+ }
281+
241 pub fn seat_name(&self) -> String {282 pub fn seat_name(&self) -> String {
242 "winit".to_owned()283 "winit".to_owned()
243 }284 }