Added high resolution timing API: SDL_GetPerformanceCounter(), SDL_GetPerformanceFrequency()

This commit is contained in:
Sam Lantinga 2011-03-25 14:45:04 -07:00
parent 98e5ddb37d
commit 85ad17e7d6
8 changed files with 127 additions and 1 deletions

View file

@ -42,6 +42,18 @@ SDL_GetTicks(void)
return ((system_time() - start) / 1000);
}
Uint64
SDL_GetPerformanceCounter(void)
{
return system_time();
}
Uint64
SDL_GetPerformanceFrequency(void)
{
return 1000000;
}
void
SDL_Delay(Uint32 ms)
{

View file

@ -37,6 +37,18 @@ SDL_GetTicks(void)
return 0;
}
Uint64
SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks();
}
Uint64
SDL_GetPerformanceFrequency(void)
{
return 1000;
}
void
SDL_Delay(Uint32 ms)
{

View file

@ -52,6 +52,18 @@ SDL_GetTicks(void)
return timer_ticks;
}
Uint64
SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks();
}
Uint64
SDL_GetPerformanceFrequency(void)
{
return 1000;
}
void
SDL_Delay(Uint32 ms)
{

View file

@ -64,6 +64,7 @@ SDL_GetTicks(void)
#if HAVE_CLOCK_GETTIME
Uint32 ticks;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
ticks =
(now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec -
@ -72,6 +73,7 @@ SDL_GetTicks(void)
#else
Uint32 ticks;
struct timeval now;
gettimeofday(&now, NULL);
ticks =
(now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec -
@ -80,6 +82,40 @@ SDL_GetTicks(void)
#endif
}
Uint64
SDL_GetPerformanceCounter(void)
{
#if HAVE_CLOCK_GETTIME
Uint64 ticks;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
ticks = now.tv_sec;
ticks *= 1000000000;
ticks += now.tv_nsec;
return (ticks);
#else
Uint64 ticks;
struct timeval now;
gettimeofday(&now, NULL);
ticks = now.tv_sec;
ticks *= 1000000;
ticks += now.tv_usec;
return (ticks);
#endif
}
Uint64
SDL_GetPerformanceFrequency(void)
{
#if HAVE_CLOCK_GETTIME
return 1000000000;
#else
return 1000000;
#endif
}
void
SDL_Delay(Uint32 ms)
{

View file

@ -87,6 +87,18 @@ SDL_GetTicks()
return ((Uint32) wce_rel_ticks());
}
Uint64
SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks();
}
Uint64
SDL_GetPerformanceFrequency(void)
{
return 1000;
}
/* Give up approx. givem milliseconds to the OS. */
void
SDL_Delay(Uint32 ms)

View file

@ -99,6 +99,28 @@ SDL_GetTicks(void)
return (ticks);
}
Uint64
SDL_GetPerformanceCounter(void)
{
LARGE_INTEGER counter;
if (!QueryPerformanceCounter(&counter)) {
return SDL_GetTicks();
}
return counter.QuadPart;
}
Uint64
SDL_GetPerformanceFrequency(void)
{
LARGE_INTEGER frequency;
if (!QueryPerformanceFrequency(&frequency)) {
return 1000;
}
return frequency.QuadPart;
}
void
SDL_Delay(Uint32 ms)
{