forge
Explore
Log in

Don't you dare go Hollow

Implement wp-presentation

Browse files at this commit

6e36ccb1bd4ca6a5e4374e1fa50e519599d7a060Ivan MolodetskikhParent: d4d2cef
src/handlers/mod.rsmodified+3 -1
@@ -11,7 +11,7 @@ use smithay::wayland::data_device::{
11 set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,11 set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,
12 ServerDndGrabHandler,12 ServerDndGrabHandler,
13 };13 };
14-use smithay::{delegate_data_device, delegate_output, delegate_seat};14+use smithay::{delegate_data_device, delegate_output, delegate_presentation, delegate_seat};
15 15
16 use crate::Niri;16 use crate::Niri;
17 17
@@ -68,3 +68,5 @@ impl ServerDndGrabHandler for Niri {}
68 delegate_data_device!(Niri);68 delegate_data_device!(Niri);
69 69
70 delegate_output!(Niri);70 delegate_output!(Niri);
71+
72+delegate_presentation!(Niri);
src/layout.rsmodified+9 -0
@@ -560,6 +560,15 @@ impl<W: LayoutElement> MonitorSet<W> {
560 })560 })
561 }561 }
562 562
563+ pub fn windows_for_output(&self, output: &Output) -> impl Iterator<Item = &W> + '_ {
564+ let MonitorSet::Normal { monitors, .. } = self else {
565+ panic!()
566+ };
567+
568+ let mon = monitors.iter().find(|mon| &mon.output == output).unwrap();
569+ mon.workspaces.iter().flat_map(|ws| ws.windows())
570+ }
571+
563 fn active_monitor(&mut self) -> Option<&mut Monitor<W>> {572 fn active_monitor(&mut self) -> Option<&mut Monitor<W>> {
564 let MonitorSet::Normal {573 let MonitorSet::Normal {
565 monitors,574 monitors,
src/niri.rsmodified+67 -3
@@ -7,10 +7,13 @@ use smithay::backend::renderer::element::surface::{
7 render_elements_from_surface_tree, WaylandSurfaceRenderElement,7 render_elements_from_surface_tree, WaylandSurfaceRenderElement,
8 };8 };
9 use smithay::backend::renderer::element::texture::{TextureBuffer, TextureRenderElement};9 use smithay::backend::renderer::element::texture::{TextureBuffer, TextureRenderElement};
10-use smithay::backend::renderer::element::{render_elements, AsRenderElements};10+use smithay::backend::renderer::element::{render_elements, AsRenderElements, RenderElementStates};
11 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};11 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
12 use smithay::backend::renderer::{ImportAll, Renderer};12 use smithay::backend::renderer::{ImportAll, Renderer};
13-use smithay::desktop::utils::send_frames_surface_tree;13+use smithay::desktop::utils::{
14+ send_frames_surface_tree, surface_presentation_feedback_flags_from_states,
15+ take_presentation_feedback_surface_tree, OutputPresentationFeedback,
16+};
14 use smithay::desktop::{17 use smithay::desktop::{
15 layer_map_for_output, LayerSurface, PopupManager, Space, Window, WindowSurfaceType,18 layer_map_for_output, LayerSurface, PopupManager, Space, Window, WindowSurfaceType,
16 };19 };
@@ -20,6 +23,7 @@ use smithay::input::{Seat, SeatState};
20 use smithay::output::Output;23 use smithay::output::Output;
21 use smithay::reexports::calloop::generic::Generic;24 use smithay::reexports::calloop::generic::Generic;
22 use smithay::reexports::calloop::{Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction};25 use smithay::reexports::calloop::{Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction};
26+use smithay::reexports::nix::libc::CLOCK_MONOTONIC;
23 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities;27 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities;
24 use smithay::reexports::wayland_server::backend::{28 use smithay::reexports::wayland_server::backend::{
25 ClientData, ClientId, DisconnectReason, GlobalId,29 ClientData, ClientId, DisconnectReason, GlobalId,
@@ -30,6 +34,7 @@ use smithay::utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, SERIAL
30 use smithay::wayland::compositor::{with_states, CompositorClientState, CompositorState};34 use smithay::wayland::compositor::{with_states, CompositorClientState, CompositorState};
31 use smithay::wayland::data_device::DataDeviceState;35 use smithay::wayland::data_device::DataDeviceState;
32 use smithay::wayland::output::OutputManagerState;36 use smithay::wayland::output::OutputManagerState;
37+use smithay::wayland::presentation::PresentationState;
33 use smithay::wayland::shell::wlr_layer::{Layer, WlrLayerShellState};38 use smithay::wayland::shell::wlr_layer::{Layer, WlrLayerShellState};
34 use smithay::wayland::shell::xdg::XdgShellState;39 use smithay::wayland::shell::xdg::XdgShellState;
35 use smithay::wayland::shm::ShmState;40 use smithay::wayland::shm::ShmState;
@@ -69,6 +74,7 @@ pub struct Niri {
69 pub seat_state: SeatState<Self>,74 pub seat_state: SeatState<Self>,
70 pub data_device_state: DataDeviceState,75 pub data_device_state: DataDeviceState,
71 pub popups: PopupManager,76 pub popups: PopupManager,
77+ pub presentation_state: PresentationState,
72 78
73 pub seat: Seat<Self>,79 pub seat: Seat<Self>,
74 80
@@ -109,6 +115,8 @@ impl Niri {
109 let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle);115 let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle);
110 let mut seat_state = SeatState::new();116 let mut seat_state = SeatState::new();
111 let data_device_state = DataDeviceState::new::<Self>(&display_handle);117 let data_device_state = DataDeviceState::new::<Self>(&display_handle);
118+ let presentation_state =
119+ PresentationState::new::<Self>(&display_handle, CLOCK_MONOTONIC as u32);
112 120
113 let mut seat: Seat<Self> = seat_state.new_wl_seat(&display_handle, seat_name);121 let mut seat: Seat<Self> = seat_state.new_wl_seat(&display_handle, seat_name);
114 // FIXME: get Xkb and repeat interval from GNOME dconf.122 // FIXME: get Xkb and repeat interval from GNOME dconf.
@@ -169,6 +177,7 @@ impl Niri {
169 seat_state,177 seat_state,
170 data_device_state,178 data_device_state,
171 popups: PopupManager::default(),179 popups: PopupManager::default(),
180+ presentation_state,
172 181
173 seat,182 seat,
174 pointer_buffer: None,183 pointer_buffer: None,
@@ -544,6 +553,9 @@ impl Niri {
544 }),553 }),
545 );554 );
546 555
556+ // backend.render() uses this.
557+ drop(layer_map);
558+
547 // Hand it over to the backend.559 // Hand it over to the backend.
548 backend.render(self, output, &elements);560 backend.render(self, output, &elements);
549 561
@@ -551,7 +563,7 @@ impl Niri {
551 let frame_callback_time = self.start_time.elapsed();563 let frame_callback_time = self.start_time.elapsed();
552 self.monitor_set.send_frame(output, frame_callback_time);564 self.monitor_set.send_frame(output, frame_callback_time);
553 565
554- for surface in layer_map.layers() {566+ for surface in layer_map_for_output(output).layers() {
555 surface.send_frame(output, frame_callback_time, None, |_, _| {567 surface.send_frame(output, frame_callback_time, None, |_, _| {
556 Some(output.clone())568 Some(output.clone())
557 });569 });
@@ -569,6 +581,58 @@ impl Niri {
569 });581 });
570 }582 }
571 }583 }
584+
585+ pub fn take_presentation_feedbacks(
586+ &mut self,
587+ output: &Output,
588+ render_element_states: &RenderElementStates,
589+ ) -> OutputPresentationFeedback {
590+ let mut feedback = OutputPresentationFeedback::new(output);
591+
592+ if let CursorImageStatus::Surface(surface) = &self.cursor_image {
593+ take_presentation_feedback_surface_tree(
594+ surface,
595+ &mut feedback,
596+ |_, _| Some(output.clone()),
597+ |surface, _| {
598+ surface_presentation_feedback_flags_from_states(surface, render_element_states)
599+ },
600+ );
601+ }
602+
603+ if let Some(surface) = &self.dnd_icon {
604+ take_presentation_feedback_surface_tree(
605+ surface,
606+ &mut feedback,
607+ |_, _| Some(output.clone()),
608+ |surface, _| {
609+ surface_presentation_feedback_flags_from_states(surface, render_element_states)
610+ },
611+ );
612+ }
613+
614+ for win in self.monitor_set.windows_for_output(output) {
615+ win.take_presentation_feedback(
616+ &mut feedback,
617+ |_, _| Some(output.clone()),
618+ |surface, _| {
619+ surface_presentation_feedback_flags_from_states(surface, render_element_states)
620+ },
621+ )
622+ }
623+
624+ for surface in layer_map_for_output(output).layers() {
625+ surface.take_presentation_feedback(
626+ &mut feedback,
627+ |_, _| Some(output.clone()),
628+ |surface, _| {
629+ surface_presentation_feedback_flags_from_states(surface, render_element_states)
630+ },
631+ );
632+ }
633+
634+ feedback
635+ }
572 }636 }
573 637
574 render_elements! {638 render_elements! {
src/tty.rsmodified+36 -12
@@ -16,6 +16,7 @@ use smithay::backend::renderer::{Bind, ImportEgl};
16 use smithay::backend::session::libseat::LibSeatSession;16 use smithay::backend::session::libseat::LibSeatSession;
17 use smithay::backend::session::{Event as SessionEvent, Session};17 use smithay::backend::session::{Event as SessionEvent, Session};
18 use smithay::backend::udev::{self, UdevBackend, UdevEvent};18 use smithay::backend::udev::{self, UdevBackend, UdevEvent};
19+use smithay::desktop::utils::OutputPresentationFeedback;
19 use smithay::output::{Mode, Output, OutputModeSource, PhysicalProperties, Subpixel};20 use smithay::output::{Mode, Output, OutputModeSource, PhysicalProperties, Subpixel};
20 use smithay::reexports::calloop::{LoopHandle, RegistrationToken};21 use smithay::reexports::calloop::{LoopHandle, RegistrationToken};
21 use smithay::reexports::drm::control::{22 use smithay::reexports::drm::control::{
@@ -24,6 +25,7 @@ use smithay::reexports::drm::control::{
24 use smithay::reexports::input::Libinput;25 use smithay::reexports::input::Libinput;
25 use smithay::reexports::nix::fcntl::OFlag;26 use smithay::reexports::nix::fcntl::OFlag;
26 use smithay::reexports::nix::libc::dev_t;27 use smithay::reexports::nix::libc::dev_t;
28+use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
27 use smithay::utils::DeviceFd;29 use smithay::utils::DeviceFd;
28 use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner};30 use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner};
29 use smithay_drm_extras::edid::EdidInfo;31 use smithay_drm_extras::edid::EdidInfo;
@@ -42,8 +44,12 @@ pub struct Tty {
42 output_device: Option<OutputDevice>,44 output_device: Option<OutputDevice>,
43 }45 }
44 46
45-type GbmDrmCompositor =47+type GbmDrmCompositor = DrmCompositor<
46- DrmCompositor<GbmAllocator<DrmDeviceFd>, GbmDevice<DrmDeviceFd>, (), DrmDeviceFd>;48+ GbmAllocator<DrmDeviceFd>,
49+ GbmDevice<DrmDeviceFd>,
50+ OutputPresentationFeedback,
51+ DrmDeviceFd,
52+>;
47 53
48 struct OutputDevice {54 struct OutputDevice {
49 id: dev_t,55 id: dev_t,
@@ -91,7 +97,10 @@ impl Backend for Tty {
91 Ok(res) => {97 Ok(res) => {
92 assert!(!res.needs_sync());98 assert!(!res.needs_sync());
93 if res.damage.is_some() {99 if res.damage.is_some() {
94- match drm_compositor.queue_frame(()) {100+ let presentation_feedbacks =
101+ niri.take_presentation_feedbacks(output, &res.states);
102+
103+ match drm_compositor.queue_frame(presentation_feedbacks) {
95 Ok(()) => {104 Ok(()) => {
96 niri.output_state105 niri.output_state
97 .get_mut(output)106 .get_mut(output)
@@ -246,11 +255,6 @@ impl Tty {
246 let device = tty.output_device.as_mut().unwrap();255 let device = tty.output_device.as_mut().unwrap();
247 let drm_compositor = device.surfaces.get_mut(&crtc).unwrap();256 let drm_compositor = device.surfaces.get_mut(&crtc).unwrap();
248 257
249- // Mark the last frame as submitted.
250- if let Err(err) = drm_compositor.frame_submitted() {
251- error!("error marking frame as submitted: {err}");
252- }
253-
254 let presentation_time = match metadata.as_mut().unwrap().time {258 let presentation_time = match metadata.as_mut().unwrap().time {
255 DrmEventTime::Monotonic(time) => time,259 DrmEventTime::Monotonic(time) => time,
256 DrmEventTime::Realtime(_) => {260 DrmEventTime::Realtime(_) => {
@@ -261,10 +265,30 @@ impl Tty {
261 }265 }
262 };266 };
263 267
264- // Send presentation time feedback.268+ // Mark the last frame as submitted.
265- // catacomb269+ match drm_compositor.frame_submitted() {
266- // .windows270+ Ok(Some(mut feedback)) => {
267- // .mark_presented(&output_device.last_render_states, metadata);271+ let refresh =
272+ feedback.output().unwrap().current_mode().unwrap().refresh
273+ as u32;
274+ // FIXME: ideally should be monotonically increasing for a surface.
275+ let seq = metadata.as_ref().unwrap().sequence as u64;
276+ let flags = wp_presentation_feedback::Kind::Vsync
277+ | wp_presentation_feedback::Kind::HwClock
278+ | wp_presentation_feedback::Kind::HwCompletion;
279+
280+ feedback.presented::<_, smithay::utils::Monotonic>(
281+ presentation_time,
282+ refresh,
283+ seq,
284+ flags,
285+ );
286+ }
287+ Ok(None) => (),
288+ Err(err) => {
289+ error!("error marking frame as submitted: {err}");
290+ }
291+ }
268 292
269 let output = data293 let output = data
270 .niri294 .niri
src/winit.rsmodified+16 -4
@@ -6,6 +6,7 @@ use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, Wini
6 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};6 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
7 use smithay::reexports::calloop::timer::{TimeoutAction, Timer};7 use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
8 use smithay::reexports::calloop::LoopHandle;8 use smithay::reexports::calloop::LoopHandle;
9+use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
9 use smithay::reexports::winit::dpi::LogicalSize;10 use smithay::reexports::winit::dpi::LogicalSize;
10 use smithay::reexports::winit::window::WindowBuilder;11 use smithay::reexports::winit::window::WindowBuilder;
11 use smithay::utils::Transform;12 use smithay::utils::Transform;
@@ -13,6 +14,7 @@ use smithay::utils::Transform;
13 use crate::backend::Backend;14 use crate::backend::Backend;
14 use crate::input::CompositorMod;15 use crate::input::CompositorMod;
15 use crate::niri::OutputRenderElements;16 use crate::niri::OutputRenderElements;
17+use crate::utils::get_monotonic_time;
16 use crate::{LoopData, Niri};18 use crate::{LoopData, Niri};
17 19
18 pub struct Winit {20 pub struct Winit {
@@ -33,20 +35,30 @@ impl Backend for Winit {
33 35
34 fn render(36 fn render(
35 &mut self,37 &mut self,
36- _niri: &mut Niri,38+ niri: &mut Niri,
37- _output: &Output,39+ output: &Output,
38 elements: &[OutputRenderElements<GlesRenderer>],40 elements: &[OutputRenderElements<GlesRenderer>],
39 ) {41 ) {
40 let _span = tracy_client::span!("Winit::render");42 let _span = tracy_client::span!("Winit::render");
41 43
42 self.backend.bind().unwrap();44 self.backend.bind().unwrap();
43 let age = self.backend.buffer_age().unwrap();45 let age = self.backend.buffer_age().unwrap();
44- let result = self46+ let res = self
45 .damage_tracker47 .damage_tracker
46 .render_output(self.backend.renderer(), age, elements, [0.1, 0.1, 0.1, 1.0])48 .render_output(self.backend.renderer(), age, elements, [0.1, 0.1, 0.1, 1.0])
47 .unwrap();49 .unwrap();
48- if let Some(damage) = result.damage {50+ if let Some(damage) = res.damage {
49 self.backend.submit(Some(&damage)).unwrap();51 self.backend.submit(Some(&damage)).unwrap();
52+
53+ let mut presentation_feedbacks = niri.take_presentation_feedbacks(output, &res.states);
54+ let refresh = output.current_mode().unwrap().refresh as u32;
55+ presentation_feedbacks.presented::<_, smithay::utils::Monotonic>(
56+ get_monotonic_time(),
57+ refresh,
58+ 0,
59+ wp_presentation_feedback::Kind::empty(),
60+ );
61+
50 self.backend.window().request_redraw();62 self.backend.window().request_redraw();
51 }63 }
52 }64 }