From baad636dfec20d0ae86ec4b4e4ed781a6e9ba36a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 20 Apr 2015 12:22:44 -0400 Subject: [PATCH] Windows: Always set the system timer resolution to 1ms by default. An existing hint lets apps that don't need the timer resolution changed avoid this, to save battery, etc, but this fixes several problems in timing, audio callbacks not firing fast enough, etc. Fixes Bugzilla #2944. --HG-- extra : rebase_source : 42542a47baca5460939d3aab79b433ec450b5f91 extra : amend_source : 2c057ab8e81da3fcfbcda0bfc47986b1e023881b --- src/timer/windows/SDL_systimer.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/timer/windows/SDL_systimer.c b/src/timer/windows/SDL_systimer.c index c9435c3e7..c3315a063 100644 --- a/src/timer/windows/SDL_systimer.c +++ b/src/timer/windows/SDL_systimer.c @@ -43,7 +43,7 @@ static LARGE_INTEGER hires_ticks_per_second; #ifndef __WINRT__ static void -timeSetPeriod(UINT uPeriod) +timeSetPeriod(const UINT uPeriod) { static UINT timer_period = 0; @@ -87,6 +87,11 @@ SDL_TicksInit(void) } ticks_started = SDL_TRUE; + /* if we didn't set a precision, set it high. This affects lots of things + on Windows besides the SDL timers, like audio callbacks, etc. */ + SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION, + SDL_TimerResolutionChanged, NULL); + /* Set first ticks value */ #ifdef USE_GETTICKCOUNT start = GetTickCount(); @@ -102,11 +107,7 @@ SDL_TicksInit(void) #ifdef __WINRT__ start = 0; /* the timer failed to start! */ #else - timeSetPeriod(1); /* use 1 ms timer precision */ start = timeGetTime(); - - SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION, - SDL_TimerResolutionChanged, NULL); #endif /* __WINRT__ */ } #endif /* USE_GETTICKCOUNT */ @@ -120,12 +121,14 @@ SDL_TicksQuit(void) #ifndef __WINRT__ SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION, SDL_TimerResolutionChanged, NULL); - - timeSetPeriod(0); #endif /* __WINRT__ */ } #endif /* USE_GETTICKCOUNT */ +#ifndef __WINRT__ + timeSetPeriod(0); /* always release our timer resolution request. */ +#endif + ticks_started = SDL_FALSE; }