From d2d539072252c4ae3a998537e74e8ca2b85f295e Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 17 Dec 2019 08:45:02 +0100 Subject: [PATCH] Do not run faster than 60 FPS --- components/compositing/compositor.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 10f7e6de2e69..aedf95be8bbf 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -1478,9 +1478,9 @@ impl IOCompositor { true } - pub fn perform_updates(&mut self) -> bool { + pub fn perform_updates(&mut self) { if self.shutdown_state == ShutdownState::FinishedShuttingDown { - return false; + return; } // If a pinch-zoom happened recently, ask for tiles at the new resolution @@ -1504,7 +1504,14 @@ impl IOCompositor { if !self.pending_scroll_zoom_events.is_empty() && !self.waiting_for_results_of_scroll { self.process_pending_scroll_events() } - self.shutdown_state != ShutdownState::FinishedShuttingDown + + let frame_duration: u64 = precise_time_ns() - self.last_composite_time; + let frame_min_duration: u64 = 1_000_000_000 / 60; + if frame_min_duration > frame_duration { + let sleep_time: u64 = frame_min_duration - frame_duration; + std::thread::sleep(std::time::Duration::from_nanos(sleep_time)); + } + self.last_composite_time = precise_time_ns(); } /// Repaints and recomposites synchronously. You must be careful when calling this, as if a