src/timer/windows/SDL_systimer.c
changeset 9566 7454bfce9202
parent 9222 f4ef6e5fb804
child 9567 b69cac1cbc8f
equal deleted inserted replaced
9563:537881242756 9566:7454bfce9202
    41 /* The number of ticks per second of the high-resolution performance counter */
    41 /* The number of ticks per second of the high-resolution performance counter */
    42 static LARGE_INTEGER hires_ticks_per_second;
    42 static LARGE_INTEGER hires_ticks_per_second;
    43 
    43 
    44 #ifndef __WINRT__
    44 #ifndef __WINRT__
    45 static void
    45 static void
    46 timeSetPeriod(UINT uPeriod)
    46 timeSetPeriod(const UINT uPeriod)
    47 {
    47 {
    48     static UINT timer_period = 0;
    48     static UINT timer_period = 0;
    49 
    49 
    50     if (uPeriod != timer_period) {
    50     if (uPeriod != timer_period) {
    51         if (timer_period) {
    51         if (timer_period) {
    84 {
    84 {
    85     if (ticks_started) {
    85     if (ticks_started) {
    86         return;
    86         return;
    87     }
    87     }
    88     ticks_started = SDL_TRUE;
    88     ticks_started = SDL_TRUE;
       
    89 
       
    90     /* if we didn't set a precision, set it high. This affects lots of things
       
    91        on Windows besides the SDL timers, like audio callbacks, etc. */
       
    92     SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
       
    93                         SDL_TimerResolutionChanged, NULL);
    89 
    94 
    90     /* Set first ticks value */
    95     /* Set first ticks value */
    91 #ifdef USE_GETTICKCOUNT
    96 #ifdef USE_GETTICKCOUNT
    92     start = GetTickCount();
    97     start = GetTickCount();
    93 #else
    98 #else
   100     } else {
   105     } else {
   101         hires_timer_available = FALSE;
   106         hires_timer_available = FALSE;
   102 #ifdef __WINRT__
   107 #ifdef __WINRT__
   103         start = 0;            /* the timer failed to start! */
   108         start = 0;            /* the timer failed to start! */
   104 #else
   109 #else
   105         timeSetPeriod(1);     /* use 1 ms timer precision */
       
   106         start = timeGetTime();
   110         start = timeGetTime();
   107 
       
   108         SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
       
   109                             SDL_TimerResolutionChanged, NULL);
       
   110 #endif /* __WINRT__ */
   111 #endif /* __WINRT__ */
   111     }
   112     }
   112 #endif /* USE_GETTICKCOUNT */
   113 #endif /* USE_GETTICKCOUNT */
   113 }
   114 }
   114 
   115 
   118 #ifndef USE_GETTICKCOUNT
   119 #ifndef USE_GETTICKCOUNT
   119     if (!hires_timer_available) {
   120     if (!hires_timer_available) {
   120 #ifndef __WINRT__
   121 #ifndef __WINRT__
   121         SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
   122         SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
   122                             SDL_TimerResolutionChanged, NULL);
   123                             SDL_TimerResolutionChanged, NULL);
   123 
       
   124         timeSetPeriod(0);
       
   125 #endif /* __WINRT__ */
   124 #endif /* __WINRT__ */
   126     }
   125     }
   127 #endif /* USE_GETTICKCOUNT */
   126 #endif /* USE_GETTICKCOUNT */
       
   127 
       
   128 #ifndef __WINRT__
       
   129     timeSetPeriod(0);  /* always release our timer resolution request. */
       
   130 #endif
   128 
   131 
   129     ticks_started = SDL_FALSE;
   132     ticks_started = SDL_FALSE;
   130 }
   133 }
   131 
   134 
   132 Uint32
   135 Uint32