summaryrefslogtreecommitdiff
path: root/src/glut/fbdev/fbdev.c
diff options
context:
space:
mode:
authorSean D'Epagnier <geckosenator@freedesktop.org>2006-11-30 03:25:28 +0000
committerSean D'Epagnier <geckosenator@freedesktop.org>2006-11-30 03:25:28 +0000
commit10cbd089aeb1087a277baf3a7ef0b4d9223970dc (patch)
treec1da62da8dabacce0ad67b548ebe872f44fefc13 /src/glut/fbdev/fbdev.c
parent21cf414489af84b8bb374f76c36db8f0f1919733 (diff)
the following improvements to linux-fbdev:
1. updated makefiles to build libOSMesa as well as libGL these are improvements to fbdev-glut 1. mouse cursor will timeout and be invisible if not being used 2. do not restore colormaps to truecolor targets, this causes problems at exit on my g450 3. fixed a crash when cleaning up from failure by munmaping what had not yet been mmaped 4. Resize event handling is improved, the resize function is not invoked from a signal handler now. 5. The main loop can detect if it is running very fast (greater than 2khz) 6. keyboard up and special up events are generated from stdin input mode and if it is also not redrawing, it sleeps 7. corrections in escape sequences for function keys for stdin input
Diffstat (limited to 'src/glut/fbdev/fbdev.c')
-rw-r--r--src/glut/fbdev/fbdev.c91
1 files changed, 53 insertions, 38 deletions
diff --git a/src/glut/fbdev/fbdev.c b/src/glut/fbdev/fbdev.c
index 7b46d54592..3b63cd70ea 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)