diff options
Diffstat (limited to 'src/glut/fbdev/fbdev.c')
-rw-r--r-- | src/glut/fbdev/fbdev.c | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/src/glut/fbdev/fbdev.c b/src/glut/fbdev/fbdev.c index 7b46d545920..3b63cd70ea1 100644 --- a/src/glut/fbdev/fbdev.c +++ b/src/glut/fbdev/fbdev.c @@ -74,6 +74,7 @@ int Redisplay; int Visible; int VisibleSwitch; int Active; +static int Resized; /* we have to poll to see if we are visible on a framebuffer that is not active */ int VisiblePoll; @@ -127,8 +128,10 @@ static void Cleanup(void) fprintf(stderr, "ioctl(FBIOPUT_VSCREENINFO failed): %s\n", strerror(errno)); - munmap(FrameBuffer, FixedInfo.smem_len); + if(FrameBuffer) + munmap(FrameBuffer, FixedInfo.smem_len); close(FrameBufferFD); + } /* free allocated back buffer */ @@ -424,6 +427,8 @@ static void ProcessTimers(void) void glutMainLoop(void) { + int idleiters; + if(ReshapeFunc) ReshapeFunc(VarInfo.xres, VarInfo.yres); @@ -440,8 +445,6 @@ void glutMainLoop(void) else if(VisiblePoll) TestVisible(); - else - usleep(1); if(IdleFunc) IdleFunc(); @@ -452,17 +455,48 @@ void glutMainLoop(void) VisibilityFunc(Visible ? GLUT_VISIBLE : GLUT_NOT_VISIBLE); } + if(Resized) { + SetVideoMode(); + CreateBuffer(); + + if(!glFBDevMakeCurrent( Context, Buffer, Buffer )) { + sprintf(exiterror, "Failure to Make Current\n"); + exit(0); + } + + InitializeMenus(); + + if(ReshapeFunc) + ReshapeFunc(VarInfo.xres, VarInfo.yres); + + Redisplay = 1; + Resized = 0; + } + if(Visible && Redisplay) { Redisplay = 0; - if(MouseEnabled) - EraseCursor(); + EraseCursor(); DisplayFunc(); if(!(DisplayMode & GLUT_DOUBLE)) { if(ActiveMenu) DrawMenus(); - if(MouseEnabled) - DrawCursor(); + DrawCursor(); } + idleiters = 0; + } else { + /* we sleep if not receiving redisplays, and + the main loop is running faster than 2khz */ + + static int lasttime; + int time = glutGet(GLUT_ELAPSED_TIME); + if(time > lasttime) { + if(idleiters >= 2) + usleep(100); + + idleiters = 0; + lasttime = time; + } + idleiters++; } } } @@ -536,17 +570,16 @@ int ParseFBModes(int minw, int maxw, int minh, int maxh, int minf, int maxf) return 0; } -/* ---------- Window Management ----------*/ void SetVideoMode(void) { /* set new variable screen info */ if (ioctl(FrameBufferFD, FBIOPUT_VSCREENINFO, &VarInfo)) { - sprintf(exiterror, "ioctl(FBIOPUT_VSCREENINFO failed): %s\n", - strerror(errno)); + sprintf(exiterror, "FBIOPUT_VSCREENINFO failed: %s\n", strerror(errno)); + strcat(exiterror, "Perhaps the device does not support the selected mode\n"); exit(0); } - /* reload the screen info to update offsets */ + /* reload the screen info to update rgb bits */ if (ioctl(FrameBufferFD, FBIOGET_VSCREENINFO, &VarInfo)) { sprintf(exiterror, "error: ioctl(FBIOGET_VSCREENINFO) failed: %s\n", strerror(errno)); @@ -571,11 +604,10 @@ void SetVideoMode(void) } /* initialize colormap */ - if(FixedInfo.visual != FB_VISUAL_TRUECOLOR) - LoadColorMap(); + LoadColorMap(); } -void CreateBuffer() +void CreateBuffer(void) { int size = VarInfo.xres_virtual * VarInfo.yres_virtual * VarInfo.bits_per_pixel / 8; @@ -674,20 +706,6 @@ void CreateVisual(void) } } -static void ResizeVisual(void) -{ - if(!glFBDevMakeCurrent( Context, Buffer, Buffer )) { - sprintf(exiterror, "Failure to Make Current\n"); - exit(0); - } - - InitializeMenus(); - - if(ReshapeFunc) - ReshapeFunc(VarInfo.xres, VarInfo.yres); - Redisplay = 1; -} - static void SignalWinch(int arg) { /* we can't change bitdepth without destroying the visual */ @@ -709,10 +727,7 @@ static void SignalWinch(int arg) VarInfo.blue = blue; VarInfo.transp = transp; - SetVideoMode(); - CreateBuffer(); - - ResizeVisual(); + Resized = 1; } int glutCreateWindow (const char *title) @@ -805,12 +820,14 @@ void glutSwapBuffers(void) { glFlush(); + if(!(DisplayMode & GLUT_DOUBLE)) + return; + if(ActiveMenu) DrawMenus(); - if(MouseEnabled) - DrawCursor(); + DrawCursor(); - if(DisplayMode & GLUT_DOUBLE && Visible) { + if(Visible) { Swapping = 1; glFBDevSwapBuffers(Buffer); Swapping = 0; @@ -839,10 +856,8 @@ void glutReshapeWindow(int width, int height) signal(SIGWINCH, SIG_IGN); SetVideoMode(); - CreateBuffer(); - - ResizeVisual(); signal(SIGWINCH, SignalWinch); + Resized = 1; } void glutFullScreen(void) |