forge
Explore
Log in

Don't you dare go Hollow

Send scanout feedbacks to surfaces

Browse files at this commit

95cbe2a636e89b4ccd24baa8420e02a519658efdIvan MolodetskikhParent: cc1c9d9
src/backend/mod.rsmodified+2 -1
@@ -1,5 +1,6 @@
1 use smithay::backend::renderer::gles::GlesRenderer;1 use smithay::backend::renderer::gles::GlesRenderer;
2 use smithay::output::Output;2 use smithay::output::Output;
3+use smithay::wayland::dmabuf::DmabufFeedback;
3 4
4 use crate::input::CompositorMod;5 use crate::input::CompositorMod;
5 use crate::niri::OutputRenderElements;6 use crate::niri::OutputRenderElements;
@@ -43,7 +44,7 @@ impl Backend {
43 niri: &mut Niri,44 niri: &mut Niri,
44 output: &Output,45 output: &Output,
45 elements: &[OutputRenderElements<GlesRenderer>],46 elements: &[OutputRenderElements<GlesRenderer>],
46- ) {47+ ) -> Option<&DmabufFeedback> {
47 match self {48 match self {
48 Backend::Tty(tty) => tty.render(niri, output, elements),49 Backend::Tty(tty) => tty.render(niri, output, elements),
49 Backend::Winit(winit) => winit.render(niri, output, elements),50 Backend::Winit(winit) => winit.render(niri, output, elements),
src/backend/tty.rsmodified+32 -8
@@ -25,9 +25,10 @@ use smithay::reexports::drm::control::{
25 use smithay::reexports::input::Libinput;25 use smithay::reexports::input::Libinput;
26 use smithay::reexports::nix::fcntl::OFlag;26 use smithay::reexports::nix::fcntl::OFlag;
27 use smithay::reexports::nix::libc::dev_t;27 use smithay::reexports::nix::libc::dev_t;
28+use smithay::reexports::wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags;
28 use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;29 use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
29 use smithay::utils::DeviceFd;30 use smithay::utils::DeviceFd;
30-use smithay::wayland::dmabuf::{DmabufFeedbackBuilder, DmabufGlobal, DmabufState};31+use smithay::wayland::dmabuf::{DmabufFeedbackBuilder, DmabufGlobal, DmabufState, DmabufFeedback};
31 use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner};32 use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner};
32 use smithay_drm_extras::edid::EdidInfo;33 use smithay_drm_extras::edid::EdidInfo;
33 34
@@ -59,7 +60,7 @@ struct OutputDevice {
59 gles: GlesRenderer,60 gles: GlesRenderer,
60 formats: HashSet<DrmFormat>,61 formats: HashSet<DrmFormat>,
61 drm_scanner: DrmScanner,62 drm_scanner: DrmScanner,
62- surfaces: HashMap<crtc::Handle, GbmDrmCompositor>,63+ surfaces: HashMap<crtc::Handle, (GbmDrmCompositor, DmabufFeedback)>,
63 dmabuf_state: DmabufState,64 dmabuf_state: DmabufState,
64 dmabuf_global: DmabufGlobal,65 dmabuf_global: DmabufGlobal,
65 }66 }
@@ -274,7 +275,7 @@ impl Tty {
274 trace!("vblank {metadata:?}");275 trace!("vblank {metadata:?}");
275 276
276 let device = tty.output_device.as_mut().unwrap();277 let device = tty.output_device.as_mut().unwrap();
277- let drm_compositor = device.surfaces.get_mut(&crtc).unwrap();278+ let drm_compositor = &mut device.surfaces.get_mut(&crtc).unwrap().0;
278 279
279 let presentation_time = match metadata.as_mut().unwrap().time {280 let presentation_time = match metadata.as_mut().unwrap().time {
280 DrmEventTime::Monotonic(time) => time,281 DrmEventTime::Monotonic(time) => time,
@@ -479,6 +480,20 @@ impl Tty {
479 crtc,480 crtc,
480 });481 });
481 482
483+ let planes = surface.planes().unwrap();
484+ let scanout_formats = surface
485+ .supported_formats(planes.primary.handle)
486+ .unwrap()
487+ .into_iter()
488+ .chain(
489+ planes
490+ .overlay
491+ .into_iter()
492+ .flat_map(|p| surface.supported_formats(p.handle).unwrap()),
493+ )
494+ .collect::<HashSet<_>>();
495+ let scanout_formats = scanout_formats.intersection(&device.formats).copied();
496+
482 // Create the compositor.497 // Create the compositor.
483 let compositor = DrmCompositor::new(498 let compositor = DrmCompositor::new(
484 OutputModeSource::Auto(output.clone()),499 OutputModeSource::Auto(output.clone()),
@@ -492,7 +507,12 @@ impl Tty {
492 Some(device.gbm.clone()),507 Some(device.gbm.clone()),
493 )?;508 )?;
494 509
495- let res = device.surfaces.insert(crtc, compositor);510+ let dmabuf_feedback = DmabufFeedbackBuilder::new(device.id, device.formats.clone())
511+ .add_preference_tranche(device.id, Some(TrancheFlags::Scanout), scanout_formats)
512+ .build()
513+ .unwrap();
514+
515+ let res = device.surfaces.insert(crtc, (compositor, dmabuf_feedback));
496 assert!(res.is_none(), "crtc must not have already existed");516 assert!(res.is_none(), "crtc must not have already existed");
497 517
498 niri.add_output(output.clone(), Some(refresh_interval(*mode)));518 niri.add_output(output.clone(), Some(refresh_interval(*mode)));
@@ -541,12 +561,12 @@ impl Tty {
541 niri: &mut Niri,561 niri: &mut Niri,
542 output: &Output,562 output: &Output,
543 elements: &[OutputRenderElements<GlesRenderer>],563 elements: &[OutputRenderElements<GlesRenderer>],
544- ) {564+ ) -> Option<&DmabufFeedback> {
545 let _span = tracy_client::span!("Tty::render");565 let _span = tracy_client::span!("Tty::render");
546 566
547 let device = self.output_device.as_mut().unwrap();567 let device = self.output_device.as_mut().unwrap();
548 let tty_state: &TtyOutputState = output.user_data().get().unwrap();568 let tty_state: &TtyOutputState = output.user_data().get().unwrap();
549- let drm_compositor = device.surfaces.get_mut(&tty_state.crtc).unwrap();569+ let (drm_compositor, dmabuf_feedback) = device.surfaces.get_mut(&tty_state.crtc).unwrap();
550 570
551 match drm_compositor.render_frame::<_, _, GlesTexture>(571 match drm_compositor.render_frame::<_, _, GlesTexture>(
552 &mut device.gles,572 &mut device.gles,
@@ -564,7 +584,9 @@ impl Tty {
564 niri.output_state584 niri.output_state
565 .get_mut(output)585 .get_mut(output)
566 .unwrap()586 .unwrap()
567- .waiting_for_vblank = true587+ .waiting_for_vblank = true;
588+
589+ return Some(dmabuf_feedback);
568 }590 }
569 Err(err) => {591 Err(err) => {
570 error!("error queueing frame: {err}");592 error!("error queueing frame: {err}");
@@ -577,6 +599,8 @@ impl Tty {
577 error!("error rendering frame: {err}");599 error!("error rendering frame: {err}");
578 }600 }
579 }601 }
602+
603+ None
580 }604 }
581 605
582 pub fn change_vt(&mut self, vt: i32) {606 pub fn change_vt(&mut self, vt: i32) {
@@ -593,7 +617,7 @@ impl Tty {
593 617
594 pub fn toggle_debug_tint(&mut self) {618 pub fn toggle_debug_tint(&mut self) {
595 if let Some(device) = self.output_device.as_mut() {619 if let Some(device) = self.output_device.as_mut() {
596- for (_, compositor) in &mut device.surfaces {620+ for (_, (compositor, _)) in &mut device.surfaces {
597 compositor.set_debug_flags(compositor.debug_flags() ^ DebugFlags::TINT);621 compositor.set_debug_flags(compositor.debug_flags() ^ DebugFlags::TINT);
598 }622 }
599 }623 }
src/backend/winit.rsmodified+4 -1
@@ -11,6 +11,7 @@ use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_pre
11 use smithay::reexports::winit::dpi::LogicalSize;11 use smithay::reexports::winit::dpi::LogicalSize;
12 use smithay::reexports::winit::window::WindowBuilder;12 use smithay::reexports::winit::window::WindowBuilder;
13 use smithay::utils::Transform;13 use smithay::utils::Transform;
14+use smithay::wayland::dmabuf::DmabufFeedback;
14 15
15 use crate::niri::OutputRenderElements;16 use crate::niri::OutputRenderElements;
16 use crate::utils::get_monotonic_time;17 use crate::utils::get_monotonic_time;
@@ -129,7 +130,7 @@ impl Winit {
129 niri: &mut Niri,130 niri: &mut Niri,
130 output: &Output,131 output: &Output,
131 elements: &[OutputRenderElements<GlesRenderer>],132 elements: &[OutputRenderElements<GlesRenderer>],
132- ) {133+ ) -> Option<&DmabufFeedback> {
133 let _span = tracy_client::span!("Winit::render");134 let _span = tracy_client::span!("Winit::render");
134 135
135 self.backend.bind().unwrap();136 self.backend.bind().unwrap();
@@ -152,6 +153,8 @@ impl Winit {
152 153
153 self.backend.window().request_redraw();154 self.backend.window().request_redraw();
154 }155 }
156+
157+ None
155 }158 }
156 159
157 pub fn toggle_debug_tint(&mut self) {160 pub fn toggle_debug_tint(&mut self) {
src/handlers/mod.rsmodified+1 -1
@@ -92,7 +92,7 @@ impl DmabufHandler for State {
92 match self.backend.renderer().import_dmabuf(&dmabuf, None) {92 match self.backend.renderer().import_dmabuf(&dmabuf, None) {
93 Ok(_texture) => Ok(()),93 Ok(_texture) => Ok(()),
94 Err(err) => {94 Err(err) => {
95- warn!("error importing dmabuf: {err:?}");95+ debug!("error importing dmabuf: {err:?}");
96 Err(ImportError::Failed)96 Err(ImportError::Failed)
97 }97 }
98 }98 }
src/layout.rsmodified+38 -0
@@ -46,6 +46,7 @@ use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
46 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;46 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
47 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};47 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
48 use smithay::wayland::compositor::{with_states, SurfaceData};48 use smithay::wayland::compositor::{with_states, SurfaceData};
49+use smithay::wayland::dmabuf::DmabufFeedback;
49 use smithay::wayland::shell::xdg::SurfaceCachedState;50 use smithay::wayland::shell::xdg::SurfaceCachedState;
50 51
51 use crate::animation::Animation;52 use crate::animation::Animation;
@@ -79,6 +80,14 @@ pub trait LayoutElement: SpaceElement + PartialEq + Clone {
79 ) where80 ) where
80 T: Into<Duration>,81 T: Into<Duration>,
81 F: FnMut(&WlSurface, &SurfaceData) -> Option<Output> + Copy;82 F: FnMut(&WlSurface, &SurfaceData) -> Option<Output> + Copy;
83+ fn send_dmabuf_feedback<'a, P, F>(
84+ &self,
85+ output: &Output,
86+ primary_scan_out_output: P,
87+ select_dmabuf_feedback: F,
88+ ) where
89+ P: FnMut(&WlSurface, &SurfaceData) -> Option<Output> + Copy,
90+ F: Fn(&WlSurface, &SurfaceData) -> &'a DmabufFeedback + Copy;
82 }91 }
83 92
84 #[derive(Debug)]93 #[derive(Debug)]
@@ -220,6 +229,18 @@ impl LayoutElement for Window {
220 {229 {
221 self.send_frame(output, time, throttle, primary_scan_out_output);230 self.send_frame(output, time, throttle, primary_scan_out_output);
222 }231 }
232+
233+ fn send_dmabuf_feedback<'a, P, F>(
234+ &self,
235+ output: &Output,
236+ primary_scan_out_output: P,
237+ select_dmabuf_feedback: F,
238+ ) where
239+ P: FnMut(&WlSurface, &SurfaceData) -> Option<Output> + Copy,
240+ F: Fn(&WlSurface, &SurfaceData) -> &'a DmabufFeedback + Copy,
241+ {
242+ self.send_dmabuf_feedback(output, primary_scan_out_output, select_dmabuf_feedback);
243+ }
223 }244 }
224 245
225 impl ColumnWidth {246 impl ColumnWidth {
@@ -464,6 +485,16 @@ impl<W: LayoutElement> MonitorSet<W> {
464 }485 }
465 }486 }
466 487
488+ pub fn send_dmabuf_feedback(&self, output: &Output, feedback: &DmabufFeedback) {
489+ if let MonitorSet::Normal { monitors, .. } = self {
490+ for mon in monitors {
491+ if &mon.output == output {
492+ mon.workspaces[mon.active_workspace_idx].send_dmabuf_feedback(feedback);
493+ }
494+ }
495+ }
496+ }
497+
467 pub fn find_window_and_output(&mut self, wl_surface: &WlSurface) -> Option<(W, Output)> {498 pub fn find_window_and_output(&mut self, wl_surface: &WlSurface) -> Option<(W, Output)> {
468 if let MonitorSet::Normal { monitors, .. } = self {499 if let MonitorSet::Normal { monitors, .. } = self {
469 for mon in monitors {500 for mon in monitors {
@@ -1506,6 +1537,13 @@ impl<W: LayoutElement> Workspace<W> {
1506 }1537 }
1507 }1538 }
1508 1539
1540+ fn send_dmabuf_feedback(&self, feedback: &DmabufFeedback) {
1541+ let output = self.output.as_ref().unwrap();
1542+ for win in self.windows() {
1543+ win.send_dmabuf_feedback(output, |_, _| Some(output.clone()), |_, _| feedback);
1544+ }
1545+ }
1546+
1509 fn view_pos(&self) -> i32 {1547 fn view_pos(&self) -> i32 {
1510 self.column_x(self.active_column_idx) + self.view_offset - PADDING1548 self.column_x(self.active_column_idx) + self.view_offset - PADDING
1511 }1549 }
src/niri.rsmodified+39 -4
@@ -19,8 +19,9 @@ use smithay::backend::renderer::element::{
19 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};19 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
20 use smithay::backend::renderer::{Bind, ExportMem, Frame, ImportAll, Offscreen, Renderer};20 use smithay::backend::renderer::{Bind, ExportMem, Frame, ImportAll, Offscreen, Renderer};
21 use smithay::desktop::utils::{21 use smithay::desktop::utils::{
22- send_frames_surface_tree, surface_presentation_feedback_flags_from_states,22+ send_dmabuf_feedback_surface_tree, send_frames_surface_tree,
23- take_presentation_feedback_surface_tree, OutputPresentationFeedback,23+ surface_presentation_feedback_flags_from_states, take_presentation_feedback_surface_tree,
24+ OutputPresentationFeedback,
24 };25 };
25 use smithay::desktop::{26 use smithay::desktop::{
26 layer_map_for_output, LayerSurface, PopupManager, Space, Window, WindowSurfaceType,27 layer_map_for_output, LayerSurface, PopupManager, Space, Window, WindowSurfaceType,
@@ -43,6 +44,7 @@ use smithay::utils::{
43 };44 };
44 use smithay::wayland::compositor::{with_states, CompositorClientState, CompositorState};45 use smithay::wayland::compositor::{with_states, CompositorClientState, CompositorState};
45 use smithay::wayland::data_device::DataDeviceState;46 use smithay::wayland::data_device::DataDeviceState;
47+use smithay::wayland::dmabuf::DmabufFeedback;
46 use smithay::wayland::output::OutputManagerState;48 use smithay::wayland::output::OutputManagerState;
47 use smithay::wayland::pointer_gestures::PointerGesturesState;49 use smithay::wayland::pointer_gestures::PointerGesturesState;
48 use smithay::wayland::presentation::PresentationState;50 use smithay::wayland::presentation::PresentationState;
@@ -378,7 +380,7 @@ impl Niri {
378 380
379 pub fn remove_output(&mut self, output: &Output) {381 pub fn remove_output(&mut self, output: &Output) {
380 let mut state = self.output_state.remove(output).unwrap();382 let mut state = self.output_state.remove(output).unwrap();
381- self.display_handle.remove_global::<Niri>(state.global);383+ self.display_handle.remove_global::<State>(state.global);
382 384
383 if let Some(idle) = state.queued_redraw.take() {385 if let Some(idle) = state.queued_redraw.take() {
384 idle.cancel();386 idle.cancel();
@@ -698,12 +700,45 @@ impl Niri {
698 let elements = self.render(backend.renderer(), output);700 let elements = self.render(backend.renderer(), output);
699 701
700 // Hand it over to the backend.702 // Hand it over to the backend.
701- backend.render(self, output, &elements);703+ let dmabuf_feedback = backend.render(self, output, &elements);
704+
705+ // Send the dmabuf feedbacks.
706+ if let Some(feedback) = dmabuf_feedback {
707+ self.send_dmabuf_feedbacks(output, feedback);
708+ }
702 709
703 // Send the frame callbacks.710 // Send the frame callbacks.
704 self.send_frame_callbacks(output);711 self.send_frame_callbacks(output);
705 }712 }
706 713
714+ fn send_dmabuf_feedbacks(&self, output: &Output, feedback: &DmabufFeedback) {
715+ let _span = tracy_client::span!("Niri::send_dmabuf_feedbacks");
716+
717+ self.monitor_set.send_dmabuf_feedback(output, feedback);
718+
719+ for surface in layer_map_for_output(output).layers() {
720+ surface.send_dmabuf_feedback(output, |_, _| Some(output.clone()), |_, _| feedback);
721+ }
722+
723+ if let Some(surface) = &self.dnd_icon {
724+ send_dmabuf_feedback_surface_tree(
725+ surface,
726+ output,
727+ |_, _| Some(output.clone()),
728+ |_, _| feedback,
729+ );
730+ }
731+
732+ if let CursorImageStatus::Surface(surface) = &self.cursor_image {
733+ send_dmabuf_feedback_surface_tree(
734+ surface,
735+ output,
736+ |_, _| Some(output.clone()),
737+ |_, _| feedback,
738+ );
739+ }
740+ }
741+
707 fn send_frame_callbacks(&self, output: &Output) {742 fn send_frame_callbacks(&self, output: &Output) {
708 let _span = tracy_client::span!("Niri::send_frame_callbacks");743 let _span = tracy_client::span!("Niri::send_frame_callbacks");
709 744