summaryrefslogtreecommitdiffstats
path: root/src/glut/directfb/callback.c
diff options
context:
space:
mode:
authorZou Nan hai <[email protected]>2007-07-04 10:52:35 +0800
committerZou Nan hai <[email protected]>2007-07-04 10:52:35 +0800
commitfb9ee9b323bff93973a39560b2bc007aace4bddd (patch)
tree05e1e72e8f4d321cde2c48b8518e6d9736c680dd /src/glut/directfb/callback.c
parent285b326c606e9b2f90e4fe177b15b3fa23239b86 (diff)
parent7ff4359a3be1278b26950f96ab23014a667af838 (diff)
Merge branch 'master' of git+ssh://[email protected]/git/mesa/mesa into 965-glsl
Diffstat (limited to 'src/glut/directfb/callback.c')
-rw-r--r--src/glut/directfb/callback.c68
1 files changed, 45 insertions, 23 deletions
diff --git a/src/glut/directfb/callback.c b/src/glut/directfb/callback.c
index 38cfccbd4f8..4f23441167a 100644
--- a/src/glut/directfb/callback.c
+++ b/src/glut/directfb/callback.c
@@ -28,14 +28,13 @@
typedef void (GLUTCALLBACK *__GlutTimerCallback) ( int value );
typedef struct __GlutTimer_s {
- unsigned int interval;
+ struct timeval interval;
struct timeval expire;
__GlutTimerCallback func;
int value;
struct __GlutTimer_s *next;
- struct __GlutTimer_s *prev;
} __GlutTimer;
/*****************************************************************************/
@@ -207,8 +206,7 @@ glutIdleFunc( void (GLUTCALLBACK *func) (void) )
void GLUTAPIENTRY
glutTimerFunc( unsigned int msec, void (GLUTCALLBACK *func) (int value), int value )
{
- __GlutTimer *timer;
- struct timeval now;
+ __GlutTimer *timer;
if (!func)
return;
@@ -217,24 +215,19 @@ glutTimerFunc( unsigned int msec, void (GLUTCALLBACK *func) (int value), int val
if (!timer)
__glutFatalError( "out of memory" );
- gettimeofday( &now, NULL );
-
- timer->interval = msec;
- timer->expire.tv_sec = now.tv_sec + (now.tv_usec/1000 + msec) / 1000;
- timer->expire.tv_usec = (now.tv_usec + msec*1000) % 1000000;
+ timer->interval.tv_sec = msec / 1000;
+ timer->interval.tv_usec = (msec % 1000) * 1000;
+
+ gettimeofday( &timer->expire, NULL );
+ timer->expire.tv_usec += timer->interval.tv_usec;
+ timer->expire.tv_sec += timer->interval.tv_sec + timer->expire.tv_usec/1000000;
+ timer->expire.tv_usec %= 1000000;
timer->func = func;
timer->value = value;
- if (g_timers) {
- timer->prev = g_timers->prev;
- g_timers->prev->next = timer;
- g_timers->prev = timer;
- }
- else {
- g_timers = timer;
- g_timers->prev = timer;
- }
+ timer->next = g_timers;
+ g_timers = timer;
}
@@ -254,12 +247,41 @@ __glutHandleTimers( void )
g_idle = GL_FALSE;
cur->func( cur->value );
-
- cur->expire.tv_sec += (cur->expire.tv_usec/1000 + cur->interval) / 1000;
- cur->expire.tv_usec = (cur->expire.tv_usec + cur->interval*1000) % 1000000;
+
+ cur->expire.tv_usec += cur->interval.tv_usec;
+ cur->expire.tv_sec += cur->interval.tv_sec + cur->expire.tv_usec/1000000;
+ cur->expire.tv_usec %= 1000000;
}
}
-}
+}
+
+
+GLboolean
+__glutGetTimeout( int *ret_msec )
+{
+ __GlutTimer *cur;
+ struct timeval *time = NULL;
+ struct timeval now;
+
+ for (cur = g_timers; cur; cur = cur->next) {
+ if (time == NULL ||
+ time->tv_sec > cur->expire.tv_sec ||
+ (time->tv_sec == cur->expire.tv_sec &&
+ time->tv_usec > cur->expire.tv_usec)) {
+ time = &cur->expire;
+ }
+ }
+
+ if (time == NULL)
+ return GL_FALSE;
+
+ gettimeofday( &now, NULL );
+
+ *ret_msec = (time->tv_sec - now.tv_sec) * 1000 +
+ (time->tv_usec - now.tv_usec + 500) / 1000;
+
+ return GL_TRUE;
+}
void
@@ -275,4 +297,4 @@ __glutFreeTimers( void )
g_timers = NULL;
}
-
+