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