From 0570fcfd93a29dcd9d41bc709edd78a7c1b4e1e7 Mon Sep 17 00:00:00 2001 From: Sean D'Epagnier Date: Tue, 21 Nov 2006 09:35:49 +0000 Subject: Added correct include files to files, No longer modify cmap if the device is truecolor (messes up dual monitors with vt switching) --- src/glut/fbdev/callback.c | 2 ++ src/glut/fbdev/colormap.c | 3 ++- src/glut/fbdev/cursor.c | 2 ++ src/glut/fbdev/ext.c | 2 ++ src/glut/fbdev/fbdev.c | 4 +++- src/glut/fbdev/gamemode.c | 1 + src/glut/fbdev/input.c | 6 +++--- src/glut/fbdev/internal.h | 7 +++---- src/glut/fbdev/menu.c | 2 ++ src/glut/fbdev/state.c | 1 + 10 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src/glut') diff --git a/src/glut/fbdev/callback.c b/src/glut/fbdev/callback.c index 37373672d36..946c8d8c133 100644 --- a/src/glut/fbdev/callback.c +++ b/src/glut/fbdev/callback.c @@ -24,6 +24,8 @@ * Written by Sean D'Epagnier (c) 2006 */ +#include + #include #include "internal.h" diff --git a/src/glut/fbdev/colormap.c b/src/glut/fbdev/colormap.c index 89556ef4a5c..3a81f93657d 100644 --- a/src/glut/fbdev/colormap.c +++ b/src/glut/fbdev/colormap.c @@ -24,6 +24,7 @@ * Written by Sean D'Epagnier (c) 2006 */ +#include #include #include @@ -37,7 +38,7 @@ #define TORMAP(x)(unsigned short)((x<0?0:x>1?1:x)*(GLfloat)(REVERSECMAPSIZE-1)) #define FROMCMAP(x) (GLfloat)x / (GLfloat)((1<<16) - 1) -static struct fb_cmap ColorMap; +static struct fb_cmap ColorMap, OriginalColorMap; unsigned short RedColorMap[256], GreenColorMap[256], BlueColorMap[256]; diff --git a/src/glut/fbdev/cursor.c b/src/glut/fbdev/cursor.c index 88386956a44..6cd087e93c8 100644 --- a/src/glut/fbdev/cursor.c +++ b/src/glut/fbdev/cursor.c @@ -28,8 +28,10 @@ to render the cursor, this is faster, it would be good to use a hardware cursor if it exists instead */ +#include #include #include +#include #include diff --git a/src/glut/fbdev/ext.c b/src/glut/fbdev/ext.c index 4a3c185a16d..65953e705b9 100644 --- a/src/glut/fbdev/ext.c +++ b/src/glut/fbdev/ext.c @@ -24,6 +24,8 @@ * Written by Sean D'Epagnier (c) 2006 */ +#include + #include #include diff --git a/src/glut/fbdev/fbdev.c b/src/glut/fbdev/fbdev.c index ce6419816dd..7b46d545920 100644 --- a/src/glut/fbdev/fbdev.c +++ b/src/glut/fbdev/fbdev.c @@ -571,7 +571,8 @@ void SetVideoMode(void) } /* initialize colormap */ - LoadColorMap(); + if(FixedInfo.visual != FB_VISUAL_TRUECOLOR) + LoadColorMap(); } void CreateBuffer() @@ -786,6 +787,7 @@ void glutDestroyWindow(int win) glFBDevDestroyContext(Context); glFBDevDestroyBuffer(Buffer); glFBDevDestroyVisual(Visual); + Visual = NULL; } diff --git a/src/glut/fbdev/gamemode.c b/src/glut/fbdev/gamemode.c index 9f32d9d7e82..30be36af7af 100644 --- a/src/glut/fbdev/gamemode.c +++ b/src/glut/fbdev/gamemode.c @@ -24,6 +24,7 @@ * Written by Sean D'Epagnier (c) 2006 */ +#include #include #include diff --git a/src/glut/fbdev/input.c b/src/glut/fbdev/input.c index 2528a74a105..d09de22ed7e 100644 --- a/src/glut/fbdev/input.c +++ b/src/glut/fbdev/input.c @@ -53,7 +53,7 @@ int GpmMouse; #endif -int CurrentVT; +int CurrentVT = 0; int ConsoleFD = -1; int KeyboardModifiers; @@ -529,14 +529,14 @@ static void VTSwitchHandler(int sig) /* this is a hack to turn the cursor off */ ioctl(FrameBufferFD, FBIOPUT_VSCREENINFO, &VarInfo); - RestoreColorMap(); + if(FixedInfo.visual != FB_VISUAL_TRUECOLOR) + RestoreColorMap(); Active = 1; Visible = 1; VisibleSwitch = 1; Redisplay = 1; - break; } } diff --git a/src/glut/fbdev/internal.h b/src/glut/fbdev/internal.h index 082cd4f6f3a..8801cc9f6c3 100644 --- a/src/glut/fbdev/internal.h +++ b/src/glut/fbdev/internal.h @@ -72,14 +72,13 @@ extern GLFBDevVisualPtr Visual; #define REVERSECMAPSIZE (1< +#include +#include #include diff --git a/src/glut/fbdev/state.c b/src/glut/fbdev/state.c index bca675c52c4..212a04aa028 100644 --- a/src/glut/fbdev/state.c +++ b/src/glut/fbdev/state.c @@ -24,6 +24,7 @@ * Written by Sean D'Epagnier (c) 2006 */ +#include #include #include -- cgit v1.2.3 From 10cbd089aeb1087a277baf3a7ef0b4d9223970dc Mon Sep 17 00:00:00 2001 From: Sean D'Epagnier Date: Thu, 30 Nov 2006 03:25:28 +0000 Subject: 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 --- configs/linux-fbdev | 10 +- src/glut/fbdev/callback.c | 3 - src/glut/fbdev/colormap.c | 6 + src/glut/fbdev/cursor.c | 22 ++-- src/glut/fbdev/fbdev.c | 91 ++++++++------- src/glut/fbdev/input.c | 282 ++++++++++++++++++++++++++++------------------ src/glut/fbdev/internal.h | 5 +- src/glut/fbdev/menu.c | 2 +- src/glut/fbdev/overlay.c | 1 + src/mesa/Makefile | 4 +- 10 files changed, 253 insertions(+), 173 deletions(-) (limited to 'src/glut') diff --git a/configs/linux-fbdev b/configs/linux-fbdev index 7a5d1b600f9..e36d20a702c 100644 --- a/configs/linux-fbdev +++ b/configs/linux-fbdev @@ -4,17 +4,13 @@ include $(TOP)/configs/linux CONFIG_NAME = linux-fbdev -DRIVER_DIRS = fbdev +CFLAGS = -O3 -ffast-math -ansi -pedantic -fPIC -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DPTHREADS -DUSE_GLFBDEV_DRIVER SRC_DIRS = mesa glu glut/fbdev - -CFLAGS = -O3 -ffast-math -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DPTHREADS -DUSE_GLFBDEV_DRIVER - - -SRC_DIRS = mesa glu glut/fbdev -DRIVER_DIRS = fbdev +DRIVER_DIRS = fbdev osmesa PROGRAM_DIRS = fbdev demos redbook samples GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lm -lpthread +OSMESA_LIB_DEPS = -lm -lpthread GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(EXTRA_LIB_PATH) -lgpm -lm diff --git a/src/glut/fbdev/callback.c b/src/glut/fbdev/callback.c index 946c8d8c133..8c039f530be 100644 --- a/src/glut/fbdev/callback.c +++ b/src/glut/fbdev/callback.c @@ -74,19 +74,16 @@ void glutKeyboardUpFunc(void (*func)(unsigned char key, int x, int y)) void glutMouseFunc(void (*func)(int button, int state, int x, int y)) { - MouseEnabled = 1; MouseFunc = func; } void glutMotionFunc(void (*func)(int x, int y)) { - MouseEnabled = 1; MotionFunc = func; } void glutPassiveMotionFunc(void (*func)(int x, int y)) { - MouseEnabled = 1; PassiveMotionFunc = func; } diff --git a/src/glut/fbdev/colormap.c b/src/glut/fbdev/colormap.c index 3a81f93657d..3e72a7b0513 100644 --- a/src/glut/fbdev/colormap.c +++ b/src/glut/fbdev/colormap.c @@ -92,12 +92,18 @@ static void FillReverseColorMap(void) void RestoreColorMap(void) { + if(FixedInfo.visual == FB_VISUAL_TRUECOLOR) + return; + if (ioctl(FrameBufferFD, FBIOPUTCMAP, (void *) &ColorMap) < 0) sprintf(exiterror, "ioctl(FBIOPUTCMAP) failed!\n"); } void LoadColorMap(void) { + if(FixedInfo.visual == FB_VISUAL_TRUECOLOR) + return; + ColorMap.start = 0; ColorMap.red = RedColorMap; ColorMap.green = GreenColorMap; diff --git a/src/glut/fbdev/cursor.c b/src/glut/fbdev/cursor.c index 6cd087e93c8..4bb2b7fba01 100644 --- a/src/glut/fbdev/cursor.c +++ b/src/glut/fbdev/cursor.c @@ -66,6 +66,9 @@ void EraseCursor(void) unsigned char *src = MouseBuffer; + if(!MouseVisible || CurrentCursor < 0 || CurrentCursor >= NUM_CURSORS) + return; + for(i = 0; i= NUM_CURSORS) + if(!MouseVisible || CurrentCursor < 0 || CurrentCursor >= NUM_CURSORS) return; px = MouseX - CursorsXOffset[CurrentCursor]; @@ -212,10 +215,12 @@ void SwapCursor(void) int miny = MIN(py, LastMouseY); int sizey = abs(py - LastMouseY); - DrawCursor(); - /* now update the portion of the screen that has changed */ + if(MouseVisible) + DrawCursor(); - if(DisplayMode & GLUT_DOUBLE && (sizex || sizey)) { + /* now update the portion of the screen that has changed, this is also + used to hide the mouse if MouseVisible is 0 */ + if(DisplayMode & GLUT_DOUBLE && ((sizex || sizey) || !MouseVisible)) { int off, stride, i; if(minx < 0) minx = 0; @@ -230,7 +235,7 @@ void SwapCursor(void) + minx * VarInfo.bits_per_pixel / 8; stride = (sizex + CURSOR_WIDTH) * VarInfo.bits_per_pixel / 8; - for(i = 0; i< sizey + CURSOR_HEIGHT; i++) { + for(i = 0; i < sizey + CURSOR_HEIGHT; i++) { memcpy(FrameBuffer+off, BackBuffer+off, stride); off += FixedInfo.line_length; } @@ -260,11 +265,8 @@ void glutSetCursor(int cursor) if(cursor == GLUT_CURSOR_FULL_CROSSHAIR) cursor = GLUT_CURSOR_CROSSHAIR; - if(CurrentCursor >= 0 && CurrentCursor < NUM_CURSORS) - EraseCursor(); - + EraseCursor(); + MouseVisible = 1; CurrentCursor = cursor; - - MouseEnabled = 1; SwapCursor(); } 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) diff --git a/src/glut/fbdev/input.c b/src/glut/fbdev/input.c index d09de22ed7e..044aa50fd86 100644 --- a/src/glut/fbdev/input.c +++ b/src/glut/fbdev/input.c @@ -65,8 +65,8 @@ double MouseSpeed = 0; int KeyRepeatMode = GLUT_KEY_REPEAT_DEFAULT; -/* only display the mouse if there is a registered callback for it */ -int MouseEnabled = 0; +int MouseVisible = 0; +int LastMouseTime = 0; static int OldKDMode = -1; static int OldMode = KD_TEXT; @@ -79,6 +79,8 @@ static int MouseFD; static int kbdpipe[2]; +static int LastStdinKeyTime, LastStdinSpecialKey = -1, LastStdinCode = -1; + #define MODIFIER(mod) \ KeyboardModifiers = release ? KeyboardModifiers & ~mod \ : KeyboardModifiers | mod; @@ -93,7 +95,6 @@ static void KeyboardHandler(int sig) unsigned char code; while(read(ConsoleFD, &code, 1) == 1) { - int release, labelval; struct kbentry entry; static int lalt; /* only left alt does vt switch */ @@ -163,10 +164,47 @@ static void LedModifier(int led, int release) KeyboardLedState ^= led; releaseflag &= ~led; } + ioctl(ConsoleFD, KDSKBLED, KeyboardLedState); ioctl(ConsoleFD, KDSETLED, 0x80); } +static void HandleKeyPress(unsigned char key, int up) +{ + if(up) { + if(KeyboardUpFunc) + KeyboardUpFunc(key, MouseX, MouseY); + } else + if(KeyboardFunc) + KeyboardFunc(key, MouseX, MouseY); + + /* there was no keyboard handler to provide a way to exit the program */ + if(key == 27) + exit(0); +} + +static void HandleSpecialPress(int key, int up) +{ + if(up) { + if(SpecialUpFunc) + SpecialUpFunc(key, MouseX, MouseY); + } else + if(SpecialFunc) + SpecialFunc(key, MouseX, MouseY); +} + +static void ReleaseStdinKey(void) +{ + if(LastStdinSpecialKey != -1) { + HandleSpecialPress(LastStdinSpecialKey, 1); + LastStdinSpecialKey = -1; + } + if(LastStdinCode != -1) { + HandleKeyPress(LastStdinCode, 1); + LastStdinCode = -1; + } +} + #define READKEY read(kbdpipe[0], &code, 1) static int ReadKey(void) { @@ -175,8 +213,14 @@ static int ReadKey(void) int specialkey = 0; struct kbentry entry; - if(READKEY != 1) + if(READKEY != 1) { + /* if we are reading from stdin, we detect key releases when the key + does not repeat after a given timeout */ + if(ConsoleFD == 0 && LastStdinKeyTime + 100 < glutGet(GLUT_ELAPSED_TIME)) + ReleaseStdinKey(); return 0; + } + if(code == 0) return 0; @@ -185,65 +229,82 @@ static int ReadKey(void) KeyboardModifiers = 0; altset: if(code == 27 && READKEY == 1) { - switch(code) { - case 79: /* function key */ - READKEY; - if(code == 50) { - READKEY; - shiftfunc: - KeyboardModifiers |= GLUT_ACTIVE_SHIFT; - specialkey = GLUT_KEY_F1 + code - 53; - READKEY; - } else { - READKEY; - specialkey = GLUT_KEY_F1 + code - 80; - } - break; - case 91: - READKEY; - switch(code) { - case 68: - specialkey = GLUT_KEY_LEFT; break; - case 65: - specialkey = GLUT_KEY_UP; break; - case 67: - specialkey = GLUT_KEY_RIGHT; break; - case 66: - specialkey = GLUT_KEY_DOWN; break; - case 53: - specialkey = GLUT_KEY_PAGE_UP; READKEY; break; - case 54: - specialkey = GLUT_KEY_PAGE_DOWN; READKEY; break; - case 49: - specialkey = GLUT_KEY_HOME; READKEY; break; - case 52: - specialkey = GLUT_KEY_END; READKEY; break; - case 50: - READKEY; - if(code != 126) - goto shiftfunc; - specialkey = GLUT_KEY_INSERT; - break; - case 51: - code = '\b'; - goto stdkey; - case 91: - READKEY; - specialkey = GLUT_KEY_F1 + code - 65; - break; - default: - return 0; - } - break; - default: + if(code != 91) { KeyboardModifiers |= GLUT_ACTIVE_ALT; goto altset; } + READKEY; + switch(code) { + case 68: + specialkey = GLUT_KEY_LEFT; break; + case 65: + specialkey = GLUT_KEY_UP; break; + case 67: + specialkey = GLUT_KEY_RIGHT; break; + case 66: + specialkey = GLUT_KEY_DOWN; break; + case 52: + specialkey = GLUT_KEY_END; READKEY; break; + case 53: + specialkey = GLUT_KEY_PAGE_UP; READKEY; break; + case 54: + specialkey = GLUT_KEY_PAGE_DOWN; READKEY; break; + case 49: + READKEY; + if(code == 126) + specialkey = GLUT_KEY_HOME; + else { + specialkey = GLUT_KEY_F1 + code - 50; + READKEY; + } + break; + case 50: + READKEY; + if(code == 126) + specialkey = GLUT_KEY_INSERT; + else { + if(code > '1') + code--; + if(code > '6') + code--; + if(code > '3') { + KeyboardModifiers |= GLUT_ACTIVE_SHIFT; + code -= 12; + } + specialkey = GLUT_KEY_F1 + code - 40; + READKEY; + } + break; + case 51: + READKEY; + if(code == 126) { + code = '\b'; + goto stdkey; + } + KeyboardModifiers |= GLUT_ACTIVE_SHIFT; + specialkey = GLUT_KEY_F1 + code - 45; + READKEY; + break; + case 91: + READKEY; + specialkey = GLUT_KEY_F1 + code - 65; + break; + default: + return 0; + } } if(specialkey) { - if(SpecialFunc) - SpecialFunc(specialkey, MouseX, MouseY); + LastStdinKeyTime = glutGet(GLUT_ELAPSED_TIME); + + if(LastStdinSpecialKey != specialkey) { + ReleaseStdinKey(); + HandleSpecialPress(specialkey, 0); + LastStdinSpecialKey = specialkey; + LastStdinKeyTime += 200; /* initial repeat */ + } else + if(KeyRepeatMode != GLUT_KEY_REPEAT_OFF) + HandleSpecialPress(specialkey, 0); } else { if(code >= 1 && code <= 26 && code != '\r') { KeyboardModifiers |= GLUT_ACTIVE_CTRL; @@ -255,8 +316,15 @@ static int ReadKey(void) KeyboardModifiers |= GLUT_ACTIVE_SHIFT; stdkey: - if(KeyboardFunc) - KeyboardFunc(code, MouseX, MouseY); + LastStdinKeyTime = glutGet(GLUT_ELAPSED_TIME); + if(LastStdinCode != code) { + ReleaseStdinKey(); + HandleKeyPress(code, 0); + LastStdinCode = code; + LastStdinKeyTime += 200; /* initial repeat */ + } else + if(KeyRepeatMode != GLUT_KEY_REPEAT_OFF) + HandleSpecialPress(code, 0); } return 1; } @@ -348,12 +416,7 @@ static int ReadKey(void) /* dispatch callback */ if(specialkey) { - if(release) { - if(SpecialUpFunc) - SpecialUpFunc(specialkey, MouseX, MouseY); - } else - if(SpecialFunc) - SpecialFunc(specialkey, MouseX, MouseY); + HandleSpecialPress(specialkey, release); } else { char c = labelval; @@ -364,12 +427,7 @@ static int ReadKey(void) if(c >= 'a' && c <= 'z') c += 'A' - 'a'; } - if(release) { - if(KeyboardUpFunc) - KeyboardUpFunc(c, MouseX, MouseY); - } else - if(KeyboardFunc) - KeyboardFunc(c, MouseX, MouseY); + HandleKeyPress(c, release); } return 1; } @@ -432,28 +490,22 @@ static int ReadMouse(void) dy = event.dy; } else #endif - { - char data[4]; - - if(MouseFD == -1) - return 0; + { + char data[4]; - if(fcntl(MouseFD, F_SETFL, O_NONBLOCK) == -1) { - close(MouseFD); - MouseFD = -1; - return 0; - } + if(MouseFD == -1) + return 0; - if(read(MouseFD, data, 4) != 4) - return 0; + if(read(MouseFD, data, 4) != 4) + return 0; - l = ((data[0] & 0x20) >> 3); - m = ((data[3] & 0x10) >> 3); - r = ((data[0] & 0x10) >> 4); + l = ((data[0] & 0x20) >> 3); + m = ((data[3] & 0x10) >> 3); + r = ((data[0] & 0x10) >> 4); - dx = (((data[0] & 0x03) << 6) | (data[1] & 0x3F)); - dy = (((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); - } + dx = (((data[0] & 0x03) << 6) | (data[1] & 0x3F)); + dy = (((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); + } MouseX += dx * MouseSpeed; if(MouseX < 0) @@ -478,7 +530,7 @@ static int ReadMouse(void) ll = l, lm = m, lr = r; - if(dx || dy) { + if(dx || dy || !MouseVisible) { if(l || m || r) { if(MotionFunc) MotionFunc(MouseX, MouseY); @@ -488,12 +540,16 @@ static int ReadMouse(void) EraseCursor(); + MouseVisible = 1; + if(ActiveMenu) Redisplay = 1; else SwapCursor(); } + LastMouseTime = glutGet(GLUT_ELAPSED_TIME); + return 1; } @@ -502,8 +558,14 @@ void ReceiveInput(void) if(ConsoleFD != -1) while(ReadKey()); - if(MouseEnabled) - while(ReadMouse()); + while(ReadMouse()); + + /* implement a 2 second timeout on the mouse */ + if(MouseVisible && glutGet(GLUT_ELAPSED_TIME) - LastMouseTime > 2000) { + EraseCursor(); + MouseVisible = 0; + SwapCursor(); + } } static void VTSwitchHandler(int sig) @@ -526,11 +588,7 @@ static void VTSwitchHandler(int sig) if(st.v_active) ioctl(ConsoleFD, VT_RELDISP, VT_ACKACQ); - /* this is a hack to turn the cursor off */ - ioctl(FrameBufferFD, FBIOPUT_VSCREENINFO, &VarInfo); - - if(FixedInfo.visual != FB_VISUAL_TRUECOLOR) - RestoreColorMap(); + RestoreColorMap(); Active = 1; Visible = 1; @@ -570,11 +628,6 @@ void InitializeVT(int usestdin) exit(0); } - if(fcntl(0, F_SETFL, O_NONBLOCK | O_ASYNC) < 0) { - sprintf(exiterror, "Failed to set keyboard to non-blocking\n"); - exit(0); - } - Active = 1; if(usestdin) { @@ -582,6 +635,12 @@ void InitializeVT(int usestdin) return; } + /* enable sigio for input */ + if(fcntl(0, F_SETFL, O_ASYNC) < 0) { + sprintf(exiterror, "Failed to set O_ASYNC mode on fd 0\n"); + exit(0); + } + /* detect the current vt if it was not specified */ if(CurrentVT == 0) { int fd = open("/dev/tty", O_RDWR | O_NDELAY, 0); @@ -590,15 +649,16 @@ void InitializeVT(int usestdin) sprintf(exiterror, "Failed to open /dev/tty\n"); exit(0); } + if(ioctl(fd, VT_GETSTATE, &st) == -1) { fprintf(stderr, "Could not detect current vt, specify with -vt\n"); fprintf(stderr, "Defaulting to stdin input\n"); ConsoleFD = 0; close(fd); return; - } else - CurrentVT = st.v_active; + } + CurrentVT = st.v_active; close(fd); } @@ -686,10 +746,10 @@ void RestoreVT(void) if (tcsetattr(0, TCSANOW, &OldTermios) < 0) fprintf(stderr, "tcsetattr failed\n"); - /* setting the mode to text from graphics restores the colormap*/ + /* setting the mode to text from graphics restores the colormap */ if( #ifdef HAVE_GPM - GpmMouse || + !GpmMouse || #endif ConsoleFD == 0) if(ioctl(ConsoleFD, KDSETMODE, KD_GRAPHICS) < 0) @@ -725,11 +785,11 @@ void InitializeMouse(void) const char *mousedev = getenv("MOUSE"); if(!mousedev) mousedev = MOUSEDEV; - if((MouseFD = open(mousedev, O_RDONLY)) >= 0) { - if(!MouseSpeed) - MouseSpeed = 1; - NumMouseButtons = 3; - return; + if((MouseFD = open(mousedev, O_RDONLY | O_NONBLOCK)) >= 0) { + if(!MouseSpeed) + MouseSpeed = 1; + NumMouseButtons = 3; + return; } } #ifdef HAVE_GPM diff --git a/src/glut/fbdev/internal.h b/src/glut/fbdev/internal.h index 8801cc9f6c3..0a159d96b0a 100644 --- a/src/glut/fbdev/internal.h +++ b/src/glut/fbdev/internal.h @@ -51,6 +51,8 @@ extern int Swapping, VTSwitch; void TestVisible(void); int ParseFBModes(int, int, int, int, int, int); +void SetVideoMode(void); +void CreateBuffer(void); void CreateVisual(void); extern int FrameBufferFD; @@ -84,7 +86,8 @@ void RestoreColorMap(void); /* --- mouse --- */ extern int MouseX, MouseY; extern int CurrentCursor; -extern int MouseEnabled; +extern int MouseVisible; +extern int LastMouseTime; extern int NumMouseButtons; void InitializeCursor(void); diff --git a/src/glut/fbdev/menu.c b/src/glut/fbdev/menu.c index 18cd58d6a2d..4ab4eb30d46 100644 --- a/src/glut/fbdev/menu.c +++ b/src/glut/fbdev/menu.c @@ -71,6 +71,7 @@ void FreeMenus(void) free(Menus[i].Items[j].name); free(Menus[i].Items); } + free(Menus); } @@ -206,7 +207,6 @@ void CloseMenu(void) int glutCreateMenu(void (*func)(int value)) { - MouseEnabled = 1; CurrentMenu = NumMenus; NumMenus++; Menus = realloc(Menus, sizeof(*Menus) * NumMenus); diff --git a/src/glut/fbdev/overlay.c b/src/glut/fbdev/overlay.c index 8bd207155c0..374cf30e7df 100644 --- a/src/glut/fbdev/overlay.c +++ b/src/glut/fbdev/overlay.c @@ -24,6 +24,7 @@ * Written by Sean D'Epagnier (c) 2006 */ +#include #include void glutEstablishOverlay(void) diff --git a/src/mesa/Makefile b/src/mesa/Makefile index 3f65ecf5cc9..1cd9e5b2bb7 100644 --- a/src/mesa/Makefile +++ b/src/mesa/Makefile @@ -33,8 +33,8 @@ default: $(MAKE) beos ; \ elif [ "$(DRIVER_DIRS)" = "directfb" ]; then \ $(MAKE) directfb ; \ - elif [ "$(DRIVER_DIRS)" = "fbdev" ]; then \ - $(MAKE) fbdev ; \ + elif [ "$(DRIVER_DIRS)" = "fbdev osmesa" ]; then \ + $(MAKE) fbdev ; $(MAKE) osmesa-only ; \ else \ $(MAKE) stand-alone ; \ fi -- cgit v1.2.3 From 73fdecca9fdd9e63aa5e57bcd67911fbb761d318 Mon Sep 17 00:00:00 2001 From: Claudio Ciccani Date: Fri, 1 Dec 2006 14:12:05 +0000 Subject: Remove DirectFBGL header from Mesa bacause since 1.0.0 DirectFB installs its own header. Updated to the current DirectFBGL interface (i.e. added GetProcAddress()). --- docs/README.directfb | 2 +- progs/directfb/df_gears.c | 2 +- progs/directfb/df_morph3d.c | 2 +- progs/directfb/df_reflect.c | 2 +- src/glut/directfb/ext.c | 7 +++ src/glut/directfb/internal.h | 3 +- src/mesa/drivers/directfb/idirectfbgl_mesa.c | 80 ++++++++++++++++++---------- 7 files changed, 65 insertions(+), 33 deletions(-) (limited to 'src/glut') diff --git a/docs/README.directfb b/docs/README.directfb index 169ebe486ee..e3bada4888b 100644 --- a/docs/README.directfb +++ b/docs/README.directfb @@ -6,7 +6,7 @@ Requirements ============ To build Mesa with DirectFB (DirectFBGL) support you need: - - DirectFB at least 0.9.21 (http://directfb.org) + - DirectFB at least 1.0.0 (http://directfb.org) - pkg-config at least 0.9 (http://pkgconfig.sf.net) diff --git a/progs/directfb/df_gears.c b/progs/directfb/df_gears.c index 27df900115f..c480767bd33 100644 --- a/progs/directfb/df_gears.c +++ b/progs/directfb/df_gears.c @@ -27,9 +27,9 @@ #include #include +#include #include -#include /* the super interface */ diff --git a/progs/directfb/df_morph3d.c b/progs/directfb/df_morph3d.c index f7f143447f4..2730fa61569 100644 --- a/progs/directfb/df_morph3d.c +++ b/progs/directfb/df_morph3d.c @@ -159,9 +159,9 @@ So the angle is: #include #include +#include #include -#include /* the super interface */ diff --git a/progs/directfb/df_reflect.c b/progs/directfb/df_reflect.c index ce4d12f749f..a0e789c3871 100644 --- a/progs/directfb/df_reflect.c +++ b/progs/directfb/df_reflect.c @@ -27,9 +27,9 @@ #include #include +#include #include -#include #include "util/showbuffer.c" #include "util/readtex.c" diff --git a/src/glut/directfb/ext.c b/src/glut/directfb/ext.c index d7338ce5f7b..e37ecf5afad 100644 --- a/src/glut/directfb/ext.c +++ b/src/glut/directfb/ext.c @@ -156,6 +156,13 @@ glutGetProcAddress( const char *name ) return glut_functions[i].address; } +#if DIRECTFBGL_INTERFACE_VERSION >= 1 + if (g_current) { + void *address = NULL; + g_current->gl->GetProcAddress( g_current->gl, name, &address ); + return address; + } +#endif return NULL; } diff --git a/src/glut/directfb/internal.h b/src/glut/directfb/internal.h index 2e986c9f286..bc3e20e93e7 100644 --- a/src/glut/directfb/internal.h +++ b/src/glut/directfb/internal.h @@ -26,8 +26,9 @@ #include #include +#include + #include "GL/glut.h" -#include "GL/directfbgl.h" #define VERSION_CODE( M, m, r ) (((M) << 16) | ((m) << 8) | ((r))) diff --git a/src/mesa/drivers/directfb/idirectfbgl_mesa.c b/src/mesa/drivers/directfb/idirectfbgl_mesa.c index eefc964889c..f5bbd127c28 100644 --- a/src/mesa/drivers/directfb/idirectfbgl_mesa.c +++ b/src/mesa/drivers/directfb/idirectfbgl_mesa.c @@ -25,24 +25,16 @@ #include -#include -#include -#include - #include #include -#define VERSION_CODE( M, m, r ) (((M) * 1000) + ((m) * 100) + ((r))) -#define DIRECTFB_VERSION_CODE VERSION_CODE( DIRECTFB_MAJOR_VERSION, \ - DIRECTFB_MINOR_VERSION, \ - DIRECTFB_MICRO_VERSION ) - +#include -#ifdef CLAMP -# undef CLAMP -#endif +#include +#include +#include -#include "GL/directfbgl.h" +#undef CLAMP #include "glheader.h" #include "buffers.h" #include "context.h" @@ -62,6 +54,12 @@ #include "drivers/common/driverfuncs.h" +#define VERSION_CODE( M, m, r ) (((M) * 1000) + ((m) * 100) + ((r))) +#define DIRECTFB_VERSION_CODE VERSION_CODE( DIRECTFB_MAJOR_VERSION, \ + DIRECTFB_MINOR_VERSION, \ + DIRECTFB_MICRO_VERSION ) + + static DFBResult Probe( void *data ); @@ -79,7 +77,7 @@ DIRECT_INTERFACE_IMPLEMENTATION( IDirectFBGL, Mesa ) typedef struct { int ref; /* reference counter */ - DFBBoolean locked; + int locked; IDirectFBSurface *surface; DFBSurfacePixelFormat format; @@ -189,8 +187,10 @@ IDirectFBGL_Mesa_Lock( IDirectFBGL *thiz ) DIRECT_INTERFACE_GET_DATA( IDirectFBGL ); - if (data->locked) - return DFB_LOCKED; + if (data->locked) { + data->locked++; + return DFB_OK; + } if (directfbgl_lock()) return DFB_LOCKED; @@ -202,6 +202,7 @@ IDirectFBGL_Mesa_Lock( IDirectFBGL *thiz ) (void*)&data->video.start, &data->video.pitch ); if (ret) { D_ERROR( "DirectFBGL/Mesa: couldn't lock surface.\n" ); + directfbgl_unlock(); return ret; } data->video.end = data->video.start + (height-1) * data->video.pitch; @@ -218,7 +219,7 @@ IDirectFBGL_Mesa_Lock( IDirectFBGL *thiz ) &data->framebuffer, width, height); } - data->locked = DFB_TRUE; + data->locked++; return DFB_OK; } @@ -230,14 +231,14 @@ IDirectFBGL_Mesa_Unlock( IDirectFBGL *thiz ) if (!data->locked) return DFB_OK; - - _mesa_make_current( NULL, NULL, NULL ); + + if (--data->locked == 0) { + _mesa_make_current( NULL, NULL, NULL ); - data->surface->Unlock( data->surface ); - - directfbgl_unlock(); + data->surface->Unlock( data->surface ); - data->locked = DFB_FALSE; + directfbgl_unlock(); + } return DFB_OK; } @@ -276,6 +277,26 @@ IDirectFBGL_Mesa_GetAttributes( IDirectFBGL *thiz, return DFB_OK; } +#if DIRECTFBGL_INTERFACE_VERSION >= 1 +static DFBResult +IDirectFBGL_Mesa_GetProcAddress( IDirectFBGL *thiz, + const char *name, + void **ret_address ) +{ + DIRECT_INTERFACE_GET_DATA( IDirectFBGL ); + + if (!name) + return DFB_INVARG; + + if (!ret_address) + return DFB_INVARG; + + *ret_address = _glapi_get_proc_address( name ); + + return (*ret_address) ? DFB_OK : DFB_UNSUPPORTED; +} +#endif + /* exported symbols */ @@ -326,11 +347,14 @@ Construct( IDirectFBGL *thiz, IDirectFBSurface *surface ) } /* Assign interface pointers. */ - thiz->AddRef = IDirectFBGL_Mesa_AddRef; - thiz->Release = IDirectFBGL_Mesa_Release; - thiz->Lock = IDirectFBGL_Mesa_Lock; - thiz->Unlock = IDirectFBGL_Mesa_Unlock; - thiz->GetAttributes = IDirectFBGL_Mesa_GetAttributes; + thiz->AddRef = IDirectFBGL_Mesa_AddRef; + thiz->Release = IDirectFBGL_Mesa_Release; + thiz->Lock = IDirectFBGL_Mesa_Lock; + thiz->Unlock = IDirectFBGL_Mesa_Unlock; + thiz->GetAttributes = IDirectFBGL_Mesa_GetAttributes; +#if DIRECTFBGL_INTERFACE_VERSION >= 1 + thiz->GetProcAddress = IDirectFBGL_Mesa_GetProcAddress; +#endif return DFB_OK; } -- cgit v1.2.3 From af0190bc6ece5ab71346ad436f5e2558d072ad56 Mon Sep 17 00:00:00 2001 From: Sean D'Epagnier Date: Thu, 21 Dec 2006 01:50:33 -0700 Subject: Updated keyboard input so that glut programs can read from stdin without problems if tty input is used. Also corrected a few stdin keycodes. --- src/glut/fbdev/input.c | 86 ++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'src/glut') diff --git a/src/glut/fbdev/input.c b/src/glut/fbdev/input.c index 044aa50fd86..1445682c760 100644 --- a/src/glut/fbdev/input.c +++ b/src/glut/fbdev/input.c @@ -177,10 +177,9 @@ static void HandleKeyPress(unsigned char key, int up) } else if(KeyboardFunc) KeyboardFunc(key, MouseX, MouseY); - - /* there was no keyboard handler to provide a way to exit the program */ - if(key == 27) - exit(0); + else + if(key == 27) + exit(0); /* no handler, to provide a way to exit */ } static void HandleSpecialPress(int key, int up) @@ -410,14 +409,17 @@ static int ReadKey(void) labelval = '\b'; break; case K_ENTER: - case K_ENTER - 1: /* keypad enter */ labelval = '\r'; break; } + /* likely a keypad input, but depends on keyboard mapping, ignore */ + if(labelval == 512) + return 1; + /* dispatch callback */ - if(specialkey) { + if(specialkey) HandleSpecialPress(specialkey, release); - } else { + else { char c = labelval; if(KeyboardLedState & LED_CAP) { @@ -607,38 +609,11 @@ void InitializeVT(int usestdin) signal(SIGIO, SIG_IGN); - /* save old terminos settings */ - if (tcgetattr(0, &OldTermios) < 0) { - sprintf(exiterror, "tcgetattr failed\n"); - exit(0); - } - - tio = OldTermios; - - /* terminos settings for straight-through mode */ - tio.c_lflag &= ~(ICANON | ECHO | ISIG); - tio.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); - tio.c_iflag |= IGNBRK; - - tio.c_cc[VMIN] = 0; - tio.c_cc[VTIME] = 0; - - if (tcsetattr(0, TCSANOW, &tio) < 0) { - sprintf(exiterror, "tcsetattr failed\n"); - exit(0); - } - Active = 1; if(usestdin) { ConsoleFD = 0; - return; - } - - /* enable sigio for input */ - if(fcntl(0, F_SETFL, O_ASYNC) < 0) { - sprintf(exiterror, "Failed to set O_ASYNC mode on fd 0\n"); - exit(0); + goto setattribs; } /* detect the current vt if it was not specified */ @@ -655,7 +630,7 @@ void InitializeVT(int usestdin) fprintf(stderr, "Defaulting to stdin input\n"); ConsoleFD = 0; close(fd); - return; + goto setattribs; } CurrentVT = st.v_active; @@ -673,7 +648,7 @@ void InitializeVT(int usestdin) sprintf(exiterror, "error couldn't open %s," " defaulting to stdin \n", console); ConsoleFD = 0; - return; + goto setattribs; } signal(SIGUSR1, VTSwitchHandler); @@ -683,7 +658,7 @@ void InitializeVT(int usestdin) sprintf(exiterror,"Failed to grab %s, defaulting to stdin\n", console); close(ConsoleFD); ConsoleFD = 0; - return; + goto setattribs; } vt = OldVTMode; @@ -715,7 +690,7 @@ void InitializeVT(int usestdin) exit(0); } - fcntl(0, F_SETOWN, getpid()); + fcntl(ConsoleFD, F_SETOWN, getpid()); if(ioctl(ConsoleFD, KDGETMODE, &OldMode) < 0) sprintf(exiterror, "Warning: Failed to get terminal mode\n"); @@ -728,7 +703,6 @@ void InitializeVT(int usestdin) if(ioctl(ConsoleFD, KDSKBMODE, K_MEDIUMRAW) < 0) { sprintf(exiterror, "ioctl KDSKBMODE failed!\n"); - tcsetattr(0, TCSANOW, &OldTermios); exit(0); } @@ -736,6 +710,34 @@ void InitializeVT(int usestdin) sprintf(exiterror, "ioctl KDGKBLED failed!\n"); exit(0); } + + setattribs: + /* enable async input input */ + if(fcntl(ConsoleFD, F_SETFL, O_ASYNC) < 0) { + sprintf(exiterror, "Failed to set O_ASYNC mode on fd %d\n", ConsoleFD); + exit(0); + } + + /* save old terminos settings */ + if (tcgetattr(ConsoleFD, &OldTermios) < 0) { + sprintf(exiterror, "tcgetattr failed\n"); + exit(0); + } + + tio = OldTermios; + + /* terminos settings for straight-through mode */ + tio.c_lflag &= ~(ICANON | ECHO | ISIG); + tio.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); + tio.c_iflag |= IGNBRK; + + tio.c_cc[VMIN] = 0; + tio.c_cc[VTIME] = 0; + + if (tcsetattr(ConsoleFD, TCSANOW, &tio) < 0) { + sprintf(exiterror, "tcsetattr failed\n"); + exit(0); + } } void RestoreVT(void) @@ -743,8 +745,8 @@ void RestoreVT(void) if(ConsoleFD < 0) return; - if (tcsetattr(0, TCSANOW, &OldTermios) < 0) - fprintf(stderr, "tcsetattr failed\n"); + if (tcsetattr(ConsoleFD, TCSANOW, &OldTermios) < 0) + sprintf(exiterror, "tcsetattr failed\n"); /* setting the mode to text from graphics restores the colormap */ if( -- cgit v1.2.3