forge
Explore
Log in

Don't you dare go Hollow

Don't use an idle for queued redraw tracking

Browse files at this commit

021a2a1af771421e39a990bb1eac624e0ef274deIvan MolodetskikhParent: 354f0b0
This way we can order the redraw after all the refreshing, where it
should be.
src/backend/tty.rsmodified+8 -8
@@ -1055,7 +1055,7 @@ impl Tty {
1055 1055
1056 let redraw_needed = match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {1056 let redraw_needed = match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {
1057 RedrawState::Idle => unreachable!(),1057 RedrawState::Idle => unreachable!(),
1058- RedrawState::Queued(_) => unreachable!(),1058+ RedrawState::Queued => unreachable!(),
1059 RedrawState::WaitingForVBlank { redraw_needed } => redraw_needed,1059 RedrawState::WaitingForVBlank { redraw_needed } => redraw_needed,
1060 RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),1060 RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),
1061 RedrawState::WaitingForEstimatedVBlankAndQueued(_) => unreachable!(),1061 RedrawState::WaitingForEstimatedVBlankAndQueued(_) => unreachable!(),
@@ -1089,12 +1089,12 @@ impl Tty {
1089 1089
1090 match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {1090 match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {
1091 RedrawState::Idle => unreachable!(),1091 RedrawState::Idle => unreachable!(),
1092- RedrawState::Queued(_) => unreachable!(),1092+ RedrawState::Queued => unreachable!(),
1093 RedrawState::WaitingForVBlank { .. } => unreachable!(),1093 RedrawState::WaitingForVBlank { .. } => unreachable!(),
1094 RedrawState::WaitingForEstimatedVBlank(_) => (),1094 RedrawState::WaitingForEstimatedVBlank(_) => (),
1095 // The timer fired just in front of a redraw.1095 // The timer fired just in front of a redraw.
1096- RedrawState::WaitingForEstimatedVBlankAndQueued((_, idle)) => {1096+ RedrawState::WaitingForEstimatedVBlankAndQueued(_) => {
1097- output_state.redraw_state = RedrawState::Queued(idle);1097+ output_state.redraw_state = RedrawState::Queued;
1098 return;1098 return;
1099 }1099 }
1100 }1100 }
@@ -1198,10 +1198,10 @@ impl Tty {
1198 };1198 };
1199 match mem::replace(&mut output_state.redraw_state, new_state) {1199 match mem::replace(&mut output_state.redraw_state, new_state) {
1200 RedrawState::Idle => unreachable!(),1200 RedrawState::Idle => unreachable!(),
1201- RedrawState::Queued(_) => (),1201+ RedrawState::Queued => (),
1202 RedrawState::WaitingForVBlank { .. } => unreachable!(),1202 RedrawState::WaitingForVBlank { .. } => unreachable!(),
1203 RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),1203 RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),
1204- RedrawState::WaitingForEstimatedVBlankAndQueued((token, _)) => {1204+ RedrawState::WaitingForEstimatedVBlankAndQueued(token) => {
1205 niri.event_loop.remove(token);1205 niri.event_loop.remove(token);
1206 }1206 }
1207 };1207 };
@@ -1909,10 +1909,10 @@ fn queue_estimated_vblank_timer(
1909 let output_state = niri.output_state.get_mut(&output).unwrap();1909 let output_state = niri.output_state.get_mut(&output).unwrap();
1910 match mem::take(&mut output_state.redraw_state) {1910 match mem::take(&mut output_state.redraw_state) {
1911 RedrawState::Idle => unreachable!(),1911 RedrawState::Idle => unreachable!(),
1912- RedrawState::Queued(_) => (),1912+ RedrawState::Queued => (),
1913 RedrawState::WaitingForVBlank { .. } => unreachable!(),1913 RedrawState::WaitingForVBlank { .. } => unreachable!(),
1914 RedrawState::WaitingForEstimatedVBlank(token)1914 RedrawState::WaitingForEstimatedVBlank(token)
1915- | RedrawState::WaitingForEstimatedVBlankAndQueued((token, _)) => {1915+ | RedrawState::WaitingForEstimatedVBlankAndQueued(token) => {
1916 output_state.redraw_state = RedrawState::WaitingForEstimatedVBlank(token);1916 output_state.redraw_state = RedrawState::WaitingForEstimatedVBlank(token);
1917 return;1917 return;
1918 }1918 }
src/backend/winit.rsmodified+1 -1
@@ -193,7 +193,7 @@ impl Winit {
193 let output_state = niri.output_state.get_mut(output).unwrap();193 let output_state = niri.output_state.get_mut(output).unwrap();
194 match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {194 match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {
195 RedrawState::Idle => unreachable!(),195 RedrawState::Idle => unreachable!(),
196- RedrawState::Queued(_) => (),196+ RedrawState::Queued => (),
197 RedrawState::WaitingForVBlank { .. } => unreachable!(),197 RedrawState::WaitingForVBlank { .. } => unreachable!(),
198 RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),198 RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),
199 RedrawState::WaitingForEstimatedVBlankAndQueued(_) => unreachable!(),199 RedrawState::WaitingForEstimatedVBlankAndQueued(_) => unreachable!(),
src/niri.rsmodified+39 -40
@@ -43,7 +43,7 @@ use smithay::output::{self, Output, PhysicalProperties, Subpixel};
43 use smithay::reexports::calloop::generic::Generic;43 use smithay::reexports::calloop::generic::Generic;
44 use smithay::reexports::calloop::timer::{TimeoutAction, Timer};44 use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
45 use smithay::reexports::calloop::{45 use smithay::reexports::calloop::{
46- Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction, RegistrationToken,46+ Interest, LoopHandle, LoopSignal, Mode, PostAction, RegistrationToken,
47 };47 };
48 use smithay::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1;48 use smithay::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1;
49 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities;49 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities;
@@ -270,13 +270,13 @@ pub enum RedrawState {
270 #[default]270 #[default]
271 Idle,271 Idle,
272 /// A redraw is queued.272 /// A redraw is queued.
273- Queued(Idle<'static>),273+ Queued,
274 /// We submitted a frame to the KMS and waiting for it to be presented.274 /// We submitted a frame to the KMS and waiting for it to be presented.
275 WaitingForVBlank { redraw_needed: bool },275 WaitingForVBlank { redraw_needed: bool },
276 /// We did not submit anything to KMS and made a timer to fire at the estimated VBlank.276 /// We did not submit anything to KMS and made a timer to fire at the estimated VBlank.
277 WaitingForEstimatedVBlank(RegistrationToken),277 WaitingForEstimatedVBlank(RegistrationToken),
278 /// A redraw is queued on top of the above.278 /// A redraw is queued on top of the above.
279- WaitingForEstimatedVBlankAndQueued((RegistrationToken, Idle<'static>)),279+ WaitingForEstimatedVBlankAndQueued(RegistrationToken),
280 }280 }
281 281
282 pub struct PopupGrabState {282 pub struct PopupGrabState {
@@ -417,6 +417,7 @@ impl State {
417 self.update_keyboard_focus();417 self.update_keyboard_focus();
418 self.refresh_pointer_focus();418 self.refresh_pointer_focus();
419 foreign_toplevel::refresh(self);419 foreign_toplevel::refresh(self);
420+ self.niri.redraw_queued_outputs(&mut self.backend);
420 421
421 {422 {
422 let _span = tracy_client::span!("flush_clients");423 let _span = tracy_client::span!("flush_clients");
@@ -1497,13 +1498,10 @@ impl Niri {
1497 1498
1498 match state.redraw_state {1499 match state.redraw_state {
1499 RedrawState::Idle => (),1500 RedrawState::Idle => (),
1500- RedrawState::Queued(idle) => idle.cancel(),1501+ RedrawState::Queued => (),
1501 RedrawState::WaitingForVBlank { .. } => (),1502 RedrawState::WaitingForVBlank { .. } => (),
1502 RedrawState::WaitingForEstimatedVBlank(token) => self.event_loop.remove(token),1503 RedrawState::WaitingForEstimatedVBlank(token) => self.event_loop.remove(token),
1503- RedrawState::WaitingForEstimatedVBlankAndQueued((token, idle)) => {1504+ RedrawState::WaitingForEstimatedVBlankAndQueued(token) => self.event_loop.remove(token),
1504- self.event_loop.remove(token);
1505- idle.cancel();
1506- }
1507 }1505 }
1508 1506
1509 // Disable the output global and remove some time later to give the clients some time to1507 // Disable the output global and remove some time later to give the clients some time to
@@ -1890,34 +1888,36 @@ impl Niri {
1890 /// Schedules an immediate redraw if one is not already scheduled.1888 /// Schedules an immediate redraw if one is not already scheduled.
1891 pub fn queue_redraw(&mut self, output: Output) {1889 pub fn queue_redraw(&mut self, output: Output) {
1892 let state = self.output_state.get_mut(&output).unwrap();1890 let state = self.output_state.get_mut(&output).unwrap();
1893- let token = match mem::take(&mut state.redraw_state) {1891+ state.redraw_state = match mem::take(&mut state.redraw_state) {
1894- RedrawState::Idle => None,1892+ RedrawState::Idle => RedrawState::Queued,
1895- RedrawState::WaitingForEstimatedVBlank(token) => Some(token),1893+ RedrawState::WaitingForEstimatedVBlank(token) => {
1896-1894+ RedrawState::WaitingForEstimatedVBlankAndQueued(token)
1897- // A redraw is already queued, put it back and do nothing.
1898- value @ (RedrawState::Queued(_)
1899- | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => {
1900- state.redraw_state = value;
1901- return;
1902 }1895 }
1903 1896
1904- // We're waiting for VBlank, request a redraw afterwards.1897+ // A redraw is already queued.
1905- RedrawState::WaitingForVBlank { .. } => {1898+ value @ (RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => {
1906- state.redraw_state = RedrawState::WaitingForVBlank {1899+ value
1907- redraw_needed: true,
1908- };
1909- return;
1910 }1900 }
1901+
1902+ // We're waiting for VBlank, request a redraw afterwards.
1903+ RedrawState::WaitingForVBlank { .. } => RedrawState::WaitingForVBlank {
1904+ redraw_needed: true,
1905+ },
1911 };1906 };
1907+ }
1912 1908
1913- let idle = self.event_loop.insert_idle(move |state| {1909+ pub fn redraw_queued_outputs(&mut self, backend: &mut Backend) {
1914- state.niri.redraw(&mut state.backend, &output);1910+ let _span = tracy_client::span!("Niri::redraw_queued_outputs");
1915- });
1916 1911
1917- state.redraw_state = match token {1912+ while let Some((output, _)) = self.output_state.iter().find(|(_, state)| {
1918- Some(token) => RedrawState::WaitingForEstimatedVBlankAndQueued((token, idle)),1913+ matches!(
1919- None => RedrawState::Queued(idle),1914+ state.redraw_state,
1920- };1915+ RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)
1916+ )
1917+ }) {
1918+ let output = output.clone();
1919+ self.redraw(backend, &output);
1920+ }
1921 }1921 }
1922 1922
1923 pub fn pointer_element<R: NiriRenderer>(1923 pub fn pointer_element<R: NiriRenderer>(
@@ -2290,7 +2290,7 @@ impl Niri {
2290 let state = self.output_state.get_mut(output).unwrap();2290 let state = self.output_state.get_mut(output).unwrap();
2291 assert!(matches!(2291 assert!(matches!(
2292 state.redraw_state,2292 state.redraw_state,
2293- RedrawState::Queued(_) | RedrawState::WaitingForEstimatedVBlankAndQueued(_)2293+ RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)
2294 ));2294 ));
2295 2295
2296 let target_presentation_time = state.frame_clock.next_presentation_time();2296 let target_presentation_time = state.frame_clock.next_presentation_time();
@@ -2324,15 +2324,14 @@ impl Niri {
2324 2324
2325 if res == RenderResult::Skipped {2325 if res == RenderResult::Skipped {
2326 // Update the redraw state on failed render.2326 // Update the redraw state on failed render.
2327- state.redraw_state =2327+ state.redraw_state = if let RedrawState::WaitingForEstimatedVBlank(token)
2328- if let RedrawState::WaitingForEstimatedVBlank(token)2328+ | RedrawState::WaitingForEstimatedVBlankAndQueued(token) =
2329- | RedrawState::WaitingForEstimatedVBlankAndQueued((token, _)) =2329+ state.redraw_state
2330- state.redraw_state2330+ {
2331- {2331+ RedrawState::WaitingForEstimatedVBlank(token)
2332- RedrawState::WaitingForEstimatedVBlank(token)2332+ } else {
2333- } else {2333+ RedrawState::Idle
2334- RedrawState::Idle2334+ };
2335- };
2336 }2335 }
2337 2336
2338 // Update the lock render state on successful render, or if monitors are inactive. When2337 // Update the lock render state on successful render, or if monitors are inactive. When