forge
Explore
Log in

Don't you dare go Hollow

Add a 1 Hz fallback frame callback timer

Browse files at this commit

ed8a6afe806fbc3438b1fd467a71919900d04852Ivan MolodetskikhParent: 43aa2f9
gamescope + Minecraft with NeoForge throws an error upon starting if
there are no frame callbacks, thus making it the first client that has a
problem. Also, apparently, Veloren disconnects from server with VSync
and no frame callbacks.
src/niri.rsmodified+111 -6
@@ -39,7 +39,7 @@ use smithay::desktop::{
39 use smithay::input::keyboard::{Layout as KeyboardLayout, XkbContextHandler};39 use smithay::input::keyboard::{Layout as KeyboardLayout, XkbContextHandler};
40 use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent};40 use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent};
41 use smithay::input::{Seat, SeatState};41 use smithay::input::{Seat, SeatState};
42-use smithay::output::{self, Output};42+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::{
@@ -118,6 +118,11 @@ use crate::{animation, niri_render_elements};
118 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];118 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
119 const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.];119 const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.];
120 120
121+// We'll try to send frame callbacks at least once a second. We'll make a timer that fires once a
122+// second, so with the worst timing the maximum interval between two frame callbacks for a surface
123+// should be ~1.995 seconds.
124+const FRAME_CALLBACK_THROTTLE: Option<Duration> = Some(Duration::from_millis(995));
125+
121 pub struct Niri {126 pub struct Niri {
122 pub config: Rc<RefCell<Config>>,127 pub config: Rc<RefCell<Config>>,
123 128
@@ -967,6 +972,16 @@ impl Niri {
967 }972 }
968 };973 };
969 974
975+ event_loop
976+ .insert_source(
977+ Timer::from_duration(Duration::from_secs(1)),
978+ |_, _, state| {
979+ state.niri.send_frame_callbacks_on_fallback_timer();
980+ TimeoutAction::ToDuration(Duration::from_secs(1))
981+ },
982+ )
983+ .unwrap();
984+
970 let socket_source = ListeningSocketSource::new_auto().unwrap();985 let socket_source = ListeningSocketSource::new_auto().unwrap();
971 let socket_name = socket_source.socket_name().to_os_string();986 let socket_name = socket_source.socket_name().to_os_string();
972 event_loop987 event_loop
@@ -2430,11 +2445,21 @@ impl Niri {
2430 let frame_callback_time = get_monotonic_time();2445 let frame_callback_time = get_monotonic_time();
2431 2446
2432 for win in self.layout.windows_for_output(output) {2447 for win in self.layout.windows_for_output(output) {
2433- win.send_frame(output, frame_callback_time, None, should_send);2448+ win.send_frame(
2449+ output,
2450+ frame_callback_time,
2451+ FRAME_CALLBACK_THROTTLE,
2452+ should_send,
2453+ );
2434 }2454 }
2435 2455
2436 for surface in layer_map_for_output(output).layers() {2456 for surface in layer_map_for_output(output).layers() {
2437- surface.send_frame(output, frame_callback_time, None, should_send);2457+ surface.send_frame(
2458+ output,
2459+ frame_callback_time,
2460+ FRAME_CALLBACK_THROTTLE,
2461+ should_send,
2462+ );
2438 }2463 }
2439 2464
2440 if let Some(surface) = &self.output_state[output].lock_surface {2465 if let Some(surface) = &self.output_state[output].lock_surface {
@@ -2442,17 +2467,97 @@ impl Niri {
2442 surface.wl_surface(),2467 surface.wl_surface(),
2443 output,2468 output,
2444 frame_callback_time,2469 frame_callback_time,
2445- None,2470+ FRAME_CALLBACK_THROTTLE,
2471+ should_send,
2472+ );
2473+ }
2474+
2475+ if let Some(surface) = &self.dnd_icon {
2476+ send_frames_surface_tree(
2477+ surface,
2478+ output,
2479+ frame_callback_time,
2480+ FRAME_CALLBACK_THROTTLE,
2481+ should_send,
2482+ );
2483+ }
2484+
2485+ if let CursorImageStatus::Surface(surface) = self.cursor_manager.cursor_image() {
2486+ send_frames_surface_tree(
2487+ surface,
2488+ output,
2489+ frame_callback_time,
2490+ FRAME_CALLBACK_THROTTLE,
2446 should_send,2491 should_send,
2447 );2492 );
2448 }2493 }
2494+ }
2495+
2496+ pub fn send_frame_callbacks_on_fallback_timer(&self) {
2497+ let _span = tracy_client::span!("Niri::send_frame_callbacks_on_fallback_timer");
2498+
2499+ // Make up a bogus output; we don't care about it here anyway, just the throttling timer.
2500+ let output = Output::new(
2501+ String::new(),
2502+ PhysicalProperties {
2503+ size: Size::from((0, 0)),
2504+ subpixel: Subpixel::Unknown,
2505+ make: String::new(),
2506+ model: String::new(),
2507+ },
2508+ );
2509+ let output = &output;
2510+
2511+ let frame_callback_time = get_monotonic_time();
2512+
2513+ self.layout.with_windows(|win, _| {
2514+ win.send_frame(
2515+ output,
2516+ frame_callback_time,
2517+ FRAME_CALLBACK_THROTTLE,
2518+ |_, _| None,
2519+ );
2520+ });
2521+
2522+ for (output, state) in self.output_state.iter() {
2523+ for surface in layer_map_for_output(output).layers() {
2524+ surface.send_frame(
2525+ output,
2526+ frame_callback_time,
2527+ FRAME_CALLBACK_THROTTLE,
2528+ |_, _| None,
2529+ );
2530+ }
2531+
2532+ if let Some(surface) = &state.lock_surface {
2533+ send_frames_surface_tree(
2534+ surface.wl_surface(),
2535+ output,
2536+ frame_callback_time,
2537+ FRAME_CALLBACK_THROTTLE,
2538+ |_, _| None,
2539+ );
2540+ }
2541+ }
2449 2542
2450 if let Some(surface) = &self.dnd_icon {2543 if let Some(surface) = &self.dnd_icon {
2451- send_frames_surface_tree(surface, output, frame_callback_time, None, should_send);2544+ send_frames_surface_tree(
2545+ surface,
2546+ output,
2547+ frame_callback_time,
2548+ FRAME_CALLBACK_THROTTLE,
2549+ |_, _| None,
2550+ );
2452 }2551 }
2453 2552
2454 if let CursorImageStatus::Surface(surface) = self.cursor_manager.cursor_image() {2553 if let CursorImageStatus::Surface(surface) = self.cursor_manager.cursor_image() {
2455- send_frames_surface_tree(surface, output, frame_callback_time, None, should_send);2554+ send_frames_surface_tree(
2555+ surface,
2556+ output,
2557+ frame_callback_time,
2558+ FRAME_CALLBACK_THROTTLE,
2559+ |_, _| None,
2560+ );
2456 }2561 }
2457 }2562 }
2458 2563