Skip to content

Commit

Permalink
fix: optimise vsync
Browse files Browse the repository at this point in the history
  • Loading branch information
f0e committed Nov 23, 2024
1 parent e493f0b commit e31cda4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e31cda4

Please sign in to comment.