backend: Use DeviceFd for GBM allocation
Browse files at this commitc3fff2c654d7898297ecd79f5fb6fcdaaf9d3060Parent: bfb5dd54 changed files +21 -24
- src/backend/mod.rs +1 -2
- src/backend/tty.rs +12 -12
- src/screencasting/mod.rs +2 -3
- src/screencasting/pw_utils.rs +6 -7
src/backend/mod.rsmodified+1 -2
| @@ -173,8 +173,7 @@ impl Backend { | |||
| 173 | #[cfg(feature = "xdp-gnome-screencast")] | 173 | #[cfg(feature = "xdp-gnome-screencast")] |
| 174 | pub fn gbm_device( | 174 | pub fn gbm_device( |
| 175 | &self, | 175 | &self, |
| 176 | - ) -> Option<smithay::backend::allocator::gbm::GbmDevice<smithay::backend::drm::DrmDeviceFd>> | 176 | + ) -> Option<smithay::backend::allocator::gbm::GbmDevice<smithay::utils::DeviceFd>> { |
| 177 | - { | ||
| 178 | match self { | 177 | match self { |
| 179 | Backend::Tty(tty) => tty.primary_gbm_device(), | 178 | Backend::Tty(tty) => tty.primary_gbm_device(), |
| 180 | Backend::Winit(_) => None, | 179 | Backend::Winit(_) => None, |
src/backend/tty.rsmodified+12 -12
| @@ -83,7 +83,7 @@ pub struct Tty { | |||
| 83 | session: LibSeatSession, | 83 | session: LibSeatSession, |
| 84 | udev_dispatcher: Dispatcher<'static, UdevBackend, State>, | 84 | udev_dispatcher: Dispatcher<'static, UdevBackend, State>, |
| 85 | libinput: Libinput, | 85 | libinput: Libinput, |
| 86 | - gpu_manager: GpuManager<GbmGlesBackend<GlesRenderer, DrmDeviceFd>>, | 86 | + gpu_manager: GpuManager<GbmGlesBackend<GlesRenderer, DeviceFd>>, |
| 87 | // DRM node corresponding to the primary GPU. May or may not be the same as | 87 | // DRM node corresponding to the primary GPU. May or may not be the same as |
| 88 | // primary_render_node. | 88 | // primary_render_node. |
| 89 | primary_node: DrmNode, | 89 | primary_node: DrmNode, |
| @@ -106,8 +106,8 @@ pub struct Tty { | |||
| 106 | pub type TtyRenderer<'render> = MultiRenderer< | 106 | pub type TtyRenderer<'render> = MultiRenderer< |
| 107 | 'render, | 107 | 'render, |
| 108 | 'render, | 108 | 'render, |
| 109 | - GbmGlesBackend<GlesRenderer, DrmDeviceFd>, | 109 | + GbmGlesBackend<GlesRenderer, DeviceFd>, |
| 110 | - GbmGlesBackend<GlesRenderer, DrmDeviceFd>, | 110 | + GbmGlesBackend<GlesRenderer, DeviceFd>, |
| 111 | >; | 111 | >; |
| 112 | 112 | ||
| 113 | pub type TtyFrame<'render, 'frame, 'buffer> = MultiFrame< | 113 | pub type TtyFrame<'render, 'frame, 'buffer> = MultiFrame< |
| @@ -115,17 +115,17 @@ pub type TtyFrame<'render, 'frame, 'buffer> = MultiFrame< | |||
| 115 | 'render, | 115 | 'render, |
| 116 | 'frame, | 116 | 'frame, |
| 117 | 'buffer, | 117 | 'buffer, |
| 118 | - GbmGlesBackend<GlesRenderer, DrmDeviceFd>, | 118 | + GbmGlesBackend<GlesRenderer, DeviceFd>, |
| 119 | - GbmGlesBackend<GlesRenderer, DrmDeviceFd>, | 119 | + GbmGlesBackend<GlesRenderer, DeviceFd>, |
| 120 | >; | 120 | >; |
| 121 | 121 | ||
| 122 | pub type TtyRendererError<'render> = <TtyRenderer<'render> as RendererSuper>::Error; | 122 | pub type TtyRendererError<'render> = <TtyRenderer<'render> as RendererSuper>::Error; |
| 123 | 123 | ||
| 124 | type GbmDrmCompositor = DrmCompositor< | 124 | type GbmDrmCompositor = DrmCompositor< |
| 125 | - GbmAllocator<DrmDeviceFd>, | 125 | + GbmAllocator<DeviceFd>, |
| 126 | - GbmFramebufferExporter<DrmDeviceFd>, | 126 | + GbmFramebufferExporter<DeviceFd>, |
| 127 | (OutputPresentationFeedback, Duration), | 127 | (OutputPresentationFeedback, Duration), |
| 128 | - DrmDeviceFd, | 128 | + DeviceFd, |
| 129 | >; | 129 | >; |
| 130 | 130 | ||
| 131 | pub struct OutputDevice { | 131 | pub struct OutputDevice { |
| @@ -138,9 +138,9 @@ pub struct OutputDevice { | |||
| 138 | // SAFETY: drop after all the objects used with them are dropped. | 138 | // SAFETY: drop after all the objects used with them are dropped. |
| 139 | // See https://github.com/Smithay/smithay/issues/1102. | 139 | // See https://github.com/Smithay/smithay/issues/1102. |
| 140 | drm: DrmDevice, | 140 | drm: DrmDevice, |
| 141 | - gbm: GbmDevice<DrmDeviceFd>, | 141 | + gbm: GbmDevice<DeviceFd>, |
| 142 | // For display-only devices this will be the allocator from the primary device. | 142 | // For display-only devices this will be the allocator from the primary device. |
| 143 | - allocator: GbmAllocator<DrmDeviceFd>, | 143 | + allocator: GbmAllocator<DeviceFd>, |
| 144 | 144 | ||
| 145 | pub drm_lease_state: Option<DrmLeaseState>, | 145 | pub drm_lease_state: Option<DrmLeaseState>, |
| 146 | non_desktop_connectors: HashSet<(connector::Handle, crtc::Handle)>, | 146 | non_desktop_connectors: HashSet<(connector::Handle, crtc::Handle)>, |
| @@ -780,7 +780,7 @@ impl Tty { | |||
| 780 | }?; | 780 | }?; |
| 781 | let gbm = { | 781 | let gbm = { |
| 782 | let _span = tracy_client::span!("GbmDevice::new"); | 782 | let _span = tracy_client::span!("GbmDevice::new"); |
| 783 | - GbmDevice::new(device_fd) | 783 | + GbmDevice::new(device_fd.device_fd()) |
| 784 | }?; | 784 | }?; |
| 785 | 785 | ||
| 786 | let mut try_initialize_gpu = || { | 786 | let mut try_initialize_gpu = || { |
| @@ -2253,7 +2253,7 @@ impl Tty { | |||
| 2253 | } | 2253 | } |
| 2254 | 2254 | ||
| 2255 | #[cfg(feature = "xdp-gnome-screencast")] | 2255 | #[cfg(feature = "xdp-gnome-screencast")] |
| 2256 | - pub fn primary_gbm_device(&self) -> Option<GbmDevice<DrmDeviceFd>> { | 2256 | + pub fn primary_gbm_device(&self) -> Option<GbmDevice<DeviceFd>> { |
| 2257 | // Try to find a device corresponding to the primary render node. | 2257 | // Try to find a device corresponding to the primary render node. |
| 2258 | let device = self | 2258 | let device = self |
| 2259 | .devices | 2259 | .devices |
src/screencasting/mod.rsmodified+2 -3
| @@ -7,13 +7,12 @@ use anyhow::Context as _; | |||
| 7 | use calloop::LoopHandle; | 7 | use calloop::LoopHandle; |
| 8 | use smithay::backend::allocator::format::FormatSet; | 8 | use smithay::backend::allocator::format::FormatSet; |
| 9 | use smithay::backend::allocator::gbm::GbmDevice; | 9 | use smithay::backend::allocator::gbm::GbmDevice; |
| 10 | -use smithay::backend::drm::DrmDeviceFd; | ||
| 11 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; | 10 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; |
| 12 | use smithay::backend::renderer::gles::GlesRenderer; | 11 | use smithay::backend::renderer::gles::GlesRenderer; |
| 13 | use smithay::desktop::Window; | 12 | use smithay::desktop::Window; |
| 14 | use smithay::output::Output; | 13 | use smithay::output::Output; |
| 15 | use smithay::reexports::gbm::Modifier; | 14 | use smithay::reexports::gbm::Modifier; |
| 16 | -use smithay::utils::{Physical, Point, Scale, Size}; | 15 | +use smithay::utils::{DeviceFd, Physical, Point, Scale, Size}; |
| 17 | use zbus::object_server::SignalEmitter; | 16 | use zbus::object_server::SignalEmitter; |
| 18 | 17 | ||
| 19 | use crate::dbus::mutter_screen_cast::{self, CursorMode, ScreenCastToNiri, StreamTargetId}; | 18 | use crate::dbus::mutter_screen_cast::{self, CursorMode, ScreenCastToNiri, StreamTargetId}; |
| @@ -77,7 +76,7 @@ impl Screencasting { | |||
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | impl State { | 78 | impl State { |
| 80 | - fn prepare_pw_cast(&mut self) -> anyhow::Result<Option<(GbmDevice<DrmDeviceFd>, FormatSet)>> { | 79 | + fn prepare_pw_cast(&mut self) -> anyhow::Result<Option<(GbmDevice<DeviceFd>, FormatSet)>> { |
| 81 | // Ensure PipeWire is initialized. | 80 | // Ensure PipeWire is initialized. |
| 82 | if self.niri.casting.pipewire.is_none() { | 81 | if self.niri.casting.pipewire.is_none() { |
| 83 | let pw = PipeWire::new( | 82 | let pw = PipeWire::new( |
src/screencasting/pw_utils.rsmodified+6 -7
| @@ -36,7 +36,6 @@ use smithay::backend::allocator::dmabuf::{AsDmabuf, Dmabuf}; | |||
| 36 | use smithay::backend::allocator::format::FormatSet; | 36 | use smithay::backend::allocator::format::FormatSet; |
| 37 | use smithay::backend::allocator::gbm::{GbmBuffer, GbmBufferFlags, GbmDevice}; | 37 | use smithay::backend::allocator::gbm::{GbmBuffer, GbmBufferFlags, GbmDevice}; |
| 38 | use smithay::backend::allocator::Fourcc; | 38 | use smithay::backend::allocator::Fourcc; |
| 39 | -use smithay::backend::drm::DrmDeviceFd; | ||
| 40 | use smithay::backend::renderer::damage::OutputDamageTracker; | 39 | use smithay::backend::renderer::damage::OutputDamageTracker; |
| 41 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; | 40 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; |
| 42 | use smithay::backend::renderer::element::{Element, RenderElement, RenderElementStates}; | 41 | use smithay::backend::renderer::element::{Element, RenderElement, RenderElementStates}; |
| @@ -52,7 +51,7 @@ use smithay::reexports::rustix::fs::{ | |||
| 52 | fcntl_add_seals, ftruncate, memfd_create, MemfdFlags, SealFlags, | 51 | fcntl_add_seals, ftruncate, memfd_create, MemfdFlags, SealFlags, |
| 53 | }; | 52 | }; |
| 54 | use smithay::reexports::rustix::mm::{mmap, munmap, MapFlags, ProtFlags}; | 53 | use smithay::reexports::rustix::mm::{mmap, munmap, MapFlags, ProtFlags}; |
| 55 | -use smithay::utils::{Logical, Physical, Point, Scale, Size, Transform}; | 54 | +use smithay::utils::{DeviceFd, Logical, Physical, Point, Scale, Size, Transform}; |
| 56 | use zbus::object_server::SignalEmitter; | 55 | use zbus::object_server::SignalEmitter; |
| 57 | 56 | ||
| 58 | use crate::dbus::mutter_screen_cast::{self, CursorMode}; | 57 | use crate::dbus::mutter_screen_cast::{self, CursorMode}; |
| @@ -400,7 +399,7 @@ impl PipeWire { | |||
| 400 | #[allow(clippy::too_many_arguments)] | 399 | #[allow(clippy::too_many_arguments)] |
| 401 | pub fn start_cast( | 400 | pub fn start_cast( |
| 402 | &self, | 401 | &self, |
| 403 | - gbm: Option<(GbmDevice<DrmDeviceFd>, FormatSet)>, | 402 | + gbm: Option<(GbmDevice<DeviceFd>, FormatSet)>, |
| 404 | session_id: CastSessionId, | 403 | session_id: CastSessionId, |
| 405 | stream_id: CastStreamId, | 404 | stream_id: CastStreamId, |
| 406 | target: CastTarget, | 405 | target: CastTarget, |
| @@ -1390,7 +1389,7 @@ impl Cast { | |||
| 1390 | impl CastInner { | 1389 | impl CastInner { |
| 1391 | unsafe fn on_add_buffer( | 1390 | unsafe fn on_add_buffer( |
| 1392 | &mut self, | 1391 | &mut self, |
| 1393 | - gbm: Option<&GbmDevice<DrmDeviceFd>>, | 1392 | + gbm: Option<&GbmDevice<DeviceFd>>, |
| 1394 | buffer: *mut pw_buffer, | 1393 | buffer: *mut pw_buffer, |
| 1395 | ) -> anyhow::Result<bool> { | 1394 | ) -> anyhow::Result<bool> { |
| 1396 | let CastState::Ready { | 1395 | let CastState::Ready { |
| @@ -1553,7 +1552,7 @@ fn make_pod(buffer: &mut Vec<u8>, object: pod::Object) -> &Pod { | |||
| 1553 | } | 1552 | } |
| 1554 | 1553 | ||
| 1555 | fn find_preferred_modifier( | 1554 | fn find_preferred_modifier( |
| 1556 | - gbm: &GbmDevice<DrmDeviceFd>, | 1555 | + gbm: &GbmDevice<DeviceFd>, |
| 1557 | size: Size<u32, Physical>, | 1556 | size: Size<u32, Physical>, |
| 1558 | fourcc: Fourcc, | 1557 | fourcc: Fourcc, |
| 1559 | modifiers: Vec<i64>, | 1558 | modifiers: Vec<i64>, |
| @@ -1573,7 +1572,7 @@ fn find_preferred_modifier( | |||
| 1573 | } | 1572 | } |
| 1574 | 1573 | ||
| 1575 | fn allocate_buffer( | 1574 | fn allocate_buffer( |
| 1576 | - gbm: &GbmDevice<DrmDeviceFd>, | 1575 | + gbm: &GbmDevice<DeviceFd>, |
| 1577 | size: Size<u32, Physical>, | 1576 | size: Size<u32, Physical>, |
| 1578 | fourcc: Fourcc, | 1577 | fourcc: Fourcc, |
| 1579 | modifiers: &[i64], | 1578 | modifiers: &[i64], |
| @@ -1605,7 +1604,7 @@ fn allocate_buffer( | |||
| 1605 | } | 1604 | } |
| 1606 | 1605 | ||
| 1607 | fn allocate_dmabuf( | 1606 | fn allocate_dmabuf( |
| 1608 | - gbm: &GbmDevice<DrmDeviceFd>, | 1607 | + gbm: &GbmDevice<DeviceFd>, |
| 1609 | size: Size<u32, Physical>, | 1608 | size: Size<u32, Physical>, |
| 1610 | fourcc: Fourcc, | 1609 | fourcc: Fourcc, |
| 1611 | modifier: Modifier, | 1610 | modifier: Modifier, |