From e31cda4d3685b3bd740385c4d0ca36b2eb22ba08 Mon Sep 17 00:00:00 2001 From: f0e <7321764+f0e@users.noreply.github.com> Date: Sat, 23 Nov 2024 23:45:52 +1000 Subject: [PATCH] fix: optimise vsync --- src/gui/gui.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2afdff6..1b72d53 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -96,12 +96,17 @@ bool processEvent(const os::Event& ev) { void gui::generate_messages_from_os_events() { // https://github.com/aseprite/aseprite/blob/45c2a5950445c884f5d732edc02989c3fb6ab1a6/src/ui/manager.cpp#L393 assert(event_queue); - os::Event lastMouseMoveEvent; + static float timeout = 1.f / 60; - auto screen_handle = window->screen()->nativeHandle(); - double rate = utils::get_display_refresh_rate(screen_handle); + void* screen_handle = window->screen()->nativeHandle(); + static void* last_screen_handle = nullptr; - double timeout = 1.f / (rate + rendering_fps_pad); + if (screen_handle != last_screen_handle) { + double rate = utils::get_display_refresh_rate(screen_handle); + timeout = 1.f / (rate + rendering_fps_pad); + printf("switched screen, updated timeout. refresh rate: %.2f hz\n", rate); + last_screen_handle = screen_handle; + } os::Event event; while (true) {