Index: head/lib/libvgl/main.c =================================================================== --- head/lib/libvgl/main.c (revision 346888) +++ head/lib/libvgl/main.c (revision 346889) @@ -1,531 +1,531 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991-1997 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include "vgl.h" #define min(x, y) (((x) < (y)) ? (x) : (y)) #define max(x, y) (((x) > (y)) ? (x) : (y)) VGLBitmap *VGLDisplay; VGLBitmap VGLVDisplay; video_info_t VGLModeInfo; video_adapter_info_t VGLAdpInfo; byte *VGLBuf; static int VGLMode; static int VGLOldMode; static size_t VGLBufSize; static byte *VGLMem = MAP_FAILED; static int VGLSwitchPending; static int VGLAbortPending; static int VGLOnDisplay; static unsigned int VGLCurWindow; static int VGLInitDone = 0; static video_info_t VGLOldModeInfo; static vid_info_t VGLOldVInfo; static int VGLOldVXsize; void VGLEnd() { struct vt_mode smode; int size[3]; if (!VGLInitDone) return; VGLInitDone = 0; signal(SIGUSR1, SIG_IGN); signal(SIGUSR2, SIG_IGN); VGLSwitchPending = 0; VGLAbortPending = 0; - VGLMousePointerHide(); + VGLMouseMode(VGL_MOUSEHIDE); if (VGLMem != MAP_FAILED) { VGLClear(VGLDisplay, 0); munmap(VGLMem, VGLAdpInfo.va_window_size); } ioctl(0, FBIO_SETLINEWIDTH, &VGLOldVXsize); if (VGLOldMode >= M_VESA_BASE) ioctl(0, _IO('V', VGLOldMode - M_VESA_BASE), 0); else ioctl(0, _IO('S', VGLOldMode), 0); if (VGLOldModeInfo.vi_flags & V_INFO_GRAPHICS) { size[0] = VGLOldVInfo.mv_csz; size[1] = VGLOldVInfo.mv_rsz; size[2] = VGLOldVInfo.font_size;; ioctl(0, KDRASTER, size); } if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) ioctl(0, KDDISABIO, 0); ioctl(0, KDSETMODE, KD_TEXT); smode.mode = VT_AUTO; ioctl(0, VT_SETMODE, &smode); if (VGLBuf) free(VGLBuf); VGLBuf = NULL; free(VGLDisplay); VGLDisplay = NULL; VGLKeyboardEnd(); } static void VGLAbort(int arg) { sigset_t mask; VGLAbortPending = 1; signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGUSR2, SIG_IGN); if (arg == SIGBUS || arg == SIGSEGV) { signal(arg, SIG_DFL); sigemptyset(&mask); sigaddset(&mask, arg); sigprocmask(SIG_UNBLOCK, &mask, NULL); VGLEnd(); kill(getpid(), arg); } } static void VGLSwitch(int arg __unused) { if (!VGLOnDisplay) VGLOnDisplay = 1; else VGLOnDisplay = 0; VGLSwitchPending = 1; signal(SIGUSR1, VGLSwitch); } int VGLInit(int mode) { struct vt_mode smode; int adptype, depth; if (VGLInitDone) return -1; signal(SIGUSR1, VGLSwitch); signal(SIGINT, VGLAbort); signal(SIGTERM, VGLAbort); signal(SIGSEGV, VGLAbort); signal(SIGBUS, VGLAbort); signal(SIGUSR2, SIG_IGN); VGLOnDisplay = 1; VGLSwitchPending = 0; VGLAbortPending = 0; if (ioctl(0, CONS_GET, &VGLOldMode) || ioctl(0, CONS_CURRENT, &adptype)) return -1; if (IOCGROUP(mode) == 'V') /* XXX: this is ugly */ VGLModeInfo.vi_mode = (mode & 0x0ff) + M_VESA_BASE; else VGLModeInfo.vi_mode = mode & 0x0ff; if (ioctl(0, CONS_MODEINFO, &VGLModeInfo)) /* FBIO_MODEINFO */ return -1; /* Save info for old mode to restore font size if old mode is graphics. */ VGLOldModeInfo.vi_mode = VGLOldMode; if (ioctl(0, CONS_MODEINFO, &VGLOldModeInfo)) return -1; VGLOldVInfo.size = sizeof(VGLOldVInfo); if (ioctl(0, CONS_GETINFO, &VGLOldVInfo)) return -1; VGLDisplay = (VGLBitmap *)malloc(sizeof(VGLBitmap)); if (VGLDisplay == NULL) return -2; if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0)) { free(VGLDisplay); return -3; } VGLInitDone = 1; /* * vi_mem_model specifies the memory model of the current video mode * in -CURRENT. */ switch (VGLModeInfo.vi_mem_model) { case V_INFO_MM_PLANAR: /* we can handle EGA/VGA planner modes only */ if (VGLModeInfo.vi_depth != 4 || VGLModeInfo.vi_planes != 4 || (adptype != KD_EGA && adptype != KD_VGA)) { VGLEnd(); return -4; } VGLDisplay->Type = VIDBUF4; VGLDisplay->PixelBytes = 1; break; case V_INFO_MM_PACKED: /* we can do only 256 color packed modes */ if (VGLModeInfo.vi_depth != 8) { VGLEnd(); return -4; } VGLDisplay->Type = VIDBUF8; VGLDisplay->PixelBytes = 1; break; case V_INFO_MM_VGAX: VGLDisplay->Type = VIDBUF8X; VGLDisplay->PixelBytes = 1; break; case V_INFO_MM_DIRECT: VGLDisplay->PixelBytes = VGLModeInfo.vi_pixel_size; switch (VGLDisplay->PixelBytes) { case 2: VGLDisplay->Type = VIDBUF16; break; case 3: VGLDisplay->Type = VIDBUF24; break; case 4: VGLDisplay->Type = VIDBUF32; break; default: VGLEnd(); return -4; } break; default: VGLEnd(); return -4; } ioctl(0, VT_WAITACTIVE, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); if (ioctl(0, mode, 0)) { VGLEnd(); return -5; } if (ioctl(0, CONS_ADPINFO, &VGLAdpInfo)) { /* FBIO_ADPINFO */ VGLEnd(); return -6; } /* * Calculate the shadow screen buffer size. In -CURRENT, va_buffer_size * always holds the entire frame buffer size, wheather it's in the linear * mode or windowed mode. * VGLBufSize = VGLAdpInfo.va_buffer_size; * In -STABLE, va_buffer_size holds the frame buffer size, only if * the linear frame buffer mode is supported. Otherwise the field is zero. * We shall calculate the minimal size in this case: * VGLAdpInfo.va_line_width*VGLModeInfo.vi_height*VGLModeInfo.vi_planes * or * VGLAdpInfo.va_window_size*VGLModeInfo.vi_planes; * Use whichever is larger. */ if (VGLAdpInfo.va_buffer_size != 0) VGLBufSize = VGLAdpInfo.va_buffer_size; else VGLBufSize = max(VGLAdpInfo.va_line_width*VGLModeInfo.vi_height, VGLAdpInfo.va_window_size)*VGLModeInfo.vi_planes; /* * The above is for old -CURRENT. Current -CURRENT since r203535 and/or * r248799 restricts va_buffer_size to the displayed size in VESA modes to * avoid wasting kva for mapping unused parts of the frame buffer. But all * parts were usable here. Applying the same restriction to user mappings * makes our virtualization useless and breaks our panning, but large frame * buffers are also difficult for us to manage (clearing and switching may * be too slow, and malloc() may fail). Restrict ourselves similarly to * get the same efficiency and bugs for all kernels. */ if (VGLModeInfo.vi_mode >= M_VESA_BASE) VGLBufSize = VGLAdpInfo.va_line_width*VGLModeInfo.vi_height* VGLModeInfo.vi_planes; VGLBuf = malloc(VGLBufSize); if (VGLBuf == NULL) { VGLEnd(); return -7; } #ifdef LIBVGL_DEBUG fprintf(stderr, "VGLBufSize:0x%x\n", VGLBufSize); #endif /* see if we are in the windowed buffer mode or in the linear buffer mode */ if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) { switch (VGLDisplay->Type) { case VIDBUF4: VGLDisplay->Type = VIDBUF4S; break; case VIDBUF8: VGLDisplay->Type = VIDBUF8S; break; case VIDBUF16: VGLDisplay->Type = VIDBUF16S; break; case VIDBUF24: VGLDisplay->Type = VIDBUF24S; break; case VIDBUF32: VGLDisplay->Type = VIDBUF32S; break; default: VGLEnd(); return -8; } } VGLMode = mode; VGLCurWindow = 0; VGLDisplay->Xsize = VGLModeInfo.vi_width; VGLDisplay->Ysize = VGLModeInfo.vi_height; depth = VGLModeInfo.vi_depth; if (depth == 15) depth = 16; VGLOldVXsize = VGLDisplay->VXsize = VGLAdpInfo.va_line_width *8/(depth/VGLModeInfo.vi_planes); VGLDisplay->VYsize = VGLBufSize/VGLModeInfo.vi_planes/VGLAdpInfo.va_line_width; VGLDisplay->Xorigin = 0; VGLDisplay->Yorigin = 0; VGLMem = (byte*)mmap(0, VGLAdpInfo.va_window_size, PROT_READ|PROT_WRITE, MAP_FILE | MAP_SHARED, 0, 0); if (VGLMem == MAP_FAILED) { VGLEnd(); return -7; } VGLDisplay->Bitmap = VGLMem; VGLVDisplay = *VGLDisplay; VGLVDisplay.Type = MEMBUF; if (VGLModeInfo.vi_depth < 8) VGLVDisplay.Bitmap = malloc(2 * VGLBufSize); else VGLVDisplay.Bitmap = VGLBuf; VGLSavePalette(); #ifdef LIBVGL_DEBUG fprintf(stderr, "va_line_width:%d\n", VGLAdpInfo.va_line_width); fprintf(stderr, "VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d\n", VGLDisplay->Xsize, VGLDisplay->Ysize, VGLDisplay->VXsize, VGLDisplay->VYsize); #endif smode.mode = VT_PROCESS; smode.waitv = 0; smode.relsig = SIGUSR1; smode.acqsig = SIGUSR1; smode.frsig = SIGINT; if (ioctl(0, VT_SETMODE, &smode)) { VGLEnd(); return -9; } VGLTextSetFontFile((byte*)0); VGLClear(VGLDisplay, 0); return 0; } void VGLCheckSwitch() { if (VGLAbortPending) { VGLEnd(); exit(0); } while (VGLSwitchPending) { VGLSwitchPending = 0; if (VGLOnDisplay) { if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) ioctl(0, KDENABIO, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); ioctl(0, VGLMode, 0); VGLCurWindow = 0; VGLMem = (byte*)mmap(0, VGLAdpInfo.va_window_size, PROT_READ|PROT_WRITE, MAP_FILE | MAP_SHARED, 0, 0); /* XXX: what if mmap() has failed! */ VGLDisplay->Type = VIDBUF8; /* XXX */ switch (VGLModeInfo.vi_mem_model) { case V_INFO_MM_PLANAR: if (VGLModeInfo.vi_depth == 4 && VGLModeInfo.vi_planes == 4) { if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) VGLDisplay->Type = VIDBUF4S; else VGLDisplay->Type = VIDBUF4; } else { /* shouldn't be happening */ } break; case V_INFO_MM_PACKED: if (VGLModeInfo.vi_depth == 8) { if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) VGLDisplay->Type = VIDBUF8S; else VGLDisplay->Type = VIDBUF8; } break; case V_INFO_MM_VGAX: VGLDisplay->Type = VIDBUF8X; break; case V_INFO_MM_DIRECT: switch (VGLModeInfo.vi_pixel_size) { case 2: if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) VGLDisplay->Type = VIDBUF16S; else VGLDisplay->Type = VIDBUF16; break; case 3: if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) VGLDisplay->Type = VIDBUF24S; else VGLDisplay->Type = VIDBUF24; break; case 4: if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) VGLDisplay->Type = VIDBUF32S; else VGLDisplay->Type = VIDBUF32; break; default: /* shouldn't be happening */ break; } default: /* shouldn't be happening */ break; } VGLDisplay->Bitmap = VGLMem; VGLDisplay->Xsize = VGLModeInfo.vi_width; VGLDisplay->Ysize = VGLModeInfo.vi_height; VGLSetVScreenSize(VGLDisplay, VGLDisplay->VXsize, VGLDisplay->VYsize); VGLRestoreBlank(); VGLRestoreBorder(); VGLMouseRestore(); VGLPanScreen(VGLDisplay, VGLDisplay->Xorigin, VGLDisplay->Yorigin); VGLBitmapCopy(&VGLVDisplay, 0, 0, VGLDisplay, 0, 0, VGLDisplay->VXsize, VGLDisplay->VYsize); VGLRestorePalette(); ioctl(0, VT_RELDISP, VT_ACKACQ); } else { VGLMem = MAP_FAILED; munmap(VGLDisplay->Bitmap, VGLAdpInfo.va_window_size); ioctl(0, VGLOldMode, 0); ioctl(0, KDSETMODE, KD_TEXT); if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) ioctl(0, KDDISABIO, 0); ioctl(0, VT_RELDISP, VT_TRUE); VGLDisplay->Bitmap = VGLBuf; VGLDisplay->Type = MEMBUF; VGLDisplay->Xsize = VGLDisplay->VXsize; VGLDisplay->Ysize = VGLDisplay->VYsize; while (!VGLOnDisplay) pause(); } } } int VGLSetSegment(unsigned int offset) { if (offset/VGLAdpInfo.va_window_size != VGLCurWindow) { ioctl(0, CONS_SETWINORG, offset); /* FBIO_SETWINORG */ VGLCurWindow = offset/VGLAdpInfo.va_window_size; } return (offset%VGLAdpInfo.va_window_size); } int VGLSetVScreenSize(VGLBitmap *object, int VXsize, int VYsize) { int depth; if (VXsize < object->Xsize || VYsize < object->Ysize) return -1; if (object->Type == MEMBUF) return -1; if (ioctl(0, FBIO_SETLINEWIDTH, &VXsize)) return -1; ioctl(0, CONS_ADPINFO, &VGLAdpInfo); /* FBIO_ADPINFO */ depth = VGLModeInfo.vi_depth; if (depth == 15) depth = 16; object->VXsize = VGLAdpInfo.va_line_width *8/(depth/VGLModeInfo.vi_planes); object->VYsize = VGLBufSize/VGLModeInfo.vi_planes/VGLAdpInfo.va_line_width; if (VYsize < object->VYsize) object->VYsize = VYsize; #ifdef LIBVGL_DEBUG fprintf(stderr, "new size: VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d\n", object->Xsize, object->Ysize, object->VXsize, object->VYsize); #endif return 0; } int VGLPanScreen(VGLBitmap *object, int x, int y) { video_display_start_t origin; if (x < 0 || x + object->Xsize > object->VXsize || y < 0 || y + object->Ysize > object->VYsize) return -1; if (object->Type == MEMBUF) return 0; origin.x = x; origin.y = y; if (ioctl(0, FBIO_SETDISPSTART, &origin)) return -1; object->Xorigin = x; object->Yorigin = y; #ifdef LIBVGL_DEBUG fprintf(stderr, "new origin: (%d, %d)\n", x, y); #endif return 0; } Index: head/lib/libvgl/mouse.c =================================================================== --- head/lib/libvgl/mouse.c (revision 346888) +++ head/lib/libvgl/mouse.c (revision 346889) @@ -1,341 +1,336 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991-1997 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "vgl.h" +static void VGLMouseAction(int dummy); + #define BORDER 0xff /* default border -- light white in rgb 3:3:2 */ #define INTERIOR 0xa0 /* default interior -- red in rgb 3:3:2 */ #define X 0xff /* any nonzero in And mask means part of cursor */ #define B BORDER #define I INTERIOR static byte StdAndMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = { X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0, X,X,X,0,0,0,0,0,0,0,0,0,0,0,0,0, X,X,X,X,0,0,0,0,0,0,0,0,0,0,0,0, X,X,X,X,X,0,0,0,0,0,0,0,0,0,0,0, X,X,X,X,X,X,0,0,0,0,0,0,0,0,0,0, X,X,X,X,X,X,X,0,0,0,0,0,0,0,0,0, X,X,X,X,X,X,X,X,0,0,0,0,0,0,0,0, X,X,X,X,X,X,X,X,X,0,0,0,0,0,0,0, X,X,X,X,X,X,X,X,X,X,0,0,0,0,0,0, X,X,X,X,X,X,X,X,X,X,0,0,0,0,0,0, X,X,X,X,X,X,X,0,0,0,0,0,0,0,0,0, X,X,X,0,X,X,X,X,0,0,0,0,0,0,0,0, X,X,0,0,X,X,X,X,0,0,0,0,0,0,0,0, 0,0,0,0,0,X,X,X,X,0,0,0,0,0,0,0, 0,0,0,0,0,X,X,X,X,0,0,0,0,0,0,0, 0,0,0,0,0,0,X,X,0,0,0,0,0,0,0,0, }; static byte StdOrMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = { B,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0, B,I,B,0,0,0,0,0,0,0,0,0,0,0,0,0, B,I,I,B,0,0,0,0,0,0,0,0,0,0,0,0, B,I,I,I,B,0,0,0,0,0,0,0,0,0,0,0, B,I,I,I,I,B,0,0,0,0,0,0,0,0,0,0, B,I,I,I,I,I,B,0,0,0,0,0,0,0,0,0, B,I,I,I,I,I,I,B,0,0,0,0,0,0,0,0, B,I,I,I,I,I,I,I,B,0,0,0,0,0,0,0, B,I,I,I,I,I,I,I,I,B,0,0,0,0,0,0, B,I,I,I,I,I,B,B,B,B,0,0,0,0,0,0, B,I,I,B,I,I,B,0,0,0,0,0,0,0,0,0, B,I,B,0,B,I,I,B,0,0,0,0,0,0,0,0, B,B,0,0,B,I,I,B,0,0,0,0,0,0,0,0, 0,0,0,0,0,B,I,I,B,0,0,0,0,0,0,0, 0,0,0,0,0,B,I,I,B,0,0,0,0,0,0,0, 0,0,0,0,0,0,B,B,0,0,0,0,0,0,0,0, }; #undef X #undef B #undef I static VGLBitmap VGLMouseStdAndMask = VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask); static VGLBitmap VGLMouseStdOrMask = VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask); static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask; -static int VGLMouseVisible = 0; static int VGLMouseShown = VGL_MOUSEHIDE; static int VGLMouseXpos = 0; static int VGLMouseYpos = 0; static int VGLMouseButtons = 0; static volatile sig_atomic_t VGLMintpending; static volatile sig_atomic_t VGLMsuppressint; #define INTOFF() (VGLMsuppressint++) #define INTON() do { \ if (--VGLMsuppressint == 0 && VGLMintpending) \ VGLMouseAction(0); \ } while (0) -void -VGLMousePointerShow() +int +__VGLMouseMode(int mode) { - if (!VGLMouseVisible) { - INTOFF(); - VGLMouseVisible = 1; - __VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos, VGLDisplay, - VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, -MOUSE_IMG_SIZE); - INTON(); - } -} + int oldmode; -void -VGLMousePointerHide() -{ - if (VGLMouseVisible) { - INTOFF(); - VGLMouseVisible = 0; - __VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos, VGLDisplay, - VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); - INTON(); - } -} - -void -VGLMouseMode(int mode) -{ + INTOFF(); + oldmode = VGLMouseShown; if (mode == VGL_MOUSESHOW) { if (VGLMouseShown == VGL_MOUSEHIDE) { - VGLMousePointerShow(); VGLMouseShown = VGL_MOUSESHOW; + __VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos, VGLDisplay, + VGLMouseXpos, VGLMouseYpos, + MOUSE_IMG_SIZE, -MOUSE_IMG_SIZE); } } else { if (VGLMouseShown == VGL_MOUSESHOW) { - VGLMousePointerHide(); VGLMouseShown = VGL_MOUSEHIDE; + __VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos, VGLDisplay, + VGLMouseXpos, VGLMouseYpos, + MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); } } + INTON(); + return oldmode; } void +VGLMouseMode(int mode) +{ + __VGLMouseMode(mode); +} + +static void VGLMouseAction(int dummy) { struct mouse_info mouseinfo; + int mousemode; if (VGLMsuppressint) { VGLMintpending = 1; return; } again: INTOFF(); VGLMintpending = 0; mouseinfo.operation = MOUSE_GETINFO; ioctl(0, CONS_MOUSECTL, &mouseinfo); - if (VGLMouseShown == VGL_MOUSESHOW) - VGLMousePointerHide(); - VGLMouseXpos = mouseinfo.u.data.x; - VGLMouseYpos = mouseinfo.u.data.y; + if (VGLMouseXpos != mouseinfo.u.data.x || + VGLMouseYpos != mouseinfo.u.data.y) { + mousemode = __VGLMouseMode(VGL_MOUSEHIDE); + VGLMouseXpos = mouseinfo.u.data.x; + VGLMouseYpos = mouseinfo.u.data.y; + __VGLMouseMode(mousemode); + } VGLMouseButtons = mouseinfo.u.data.buttons; - if (VGLMouseShown == VGL_MOUSESHOW) - VGLMousePointerShow(); /* * Loop to handle any new (suppressed) signals. This is INTON() without * recursion. !SA_RESTART prevents recursion in signal handling. So the * maximum recursion is 2 levels. */ VGLMsuppressint = 0; if (VGLMintpending) goto again; } void VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask) { - if (VGLMouseShown == VGL_MOUSESHOW) - VGLMousePointerHide(); + int mousemode; + mousemode = __VGLMouseMode(VGL_MOUSEHIDE); + VGLMouseAndMask = AndMask; if (VGLMouseOrMask != NULL) { free(VGLMouseOrMask->Bitmap); free(VGLMouseOrMask); } VGLMouseOrMask = VGLBitmapCreate(MEMBUF, OrMask->VXsize, OrMask->VYsize, 0); VGLBitmapAllocateBits(VGLMouseOrMask); VGLBitmapCvt(OrMask, VGLMouseOrMask); - if (VGLMouseShown == VGL_MOUSESHOW) - VGLMousePointerShow(); + __VGLMouseMode(mousemode); } void VGLMouseSetStdImage() { VGLMouseSetImage(&VGLMouseStdAndMask, &VGLMouseStdOrMask); } int VGLMouseInit(int mode) { struct mouse_info mouseinfo; int andmask, border, error, i, interior; switch (VGLModeInfo.vi_mem_model) { case V_INFO_MM_PACKED: case V_INFO_MM_PLANAR: andmask = 0x0f; border = 0x0f; interior = 0x04; break; case V_INFO_MM_VGAX: andmask = 0x3f; border = 0x3f; interior = 0x24; break; default: andmask = 0xff; border = BORDER; interior = INTERIOR; break; } if (VGLModeInfo.vi_mode == M_BG640x480) border = 0; /* XXX (palette makes 0x04 look like 0x0f) */ if (getenv("VGLMOUSEBORDERCOLOR") != NULL) border = strtoul(getenv("VGLMOUSEBORDERCOLOR"), NULL, 0); if (getenv("VGLMOUSEINTERIORCOLOR") != NULL) interior = strtoul(getenv("VGLMOUSEINTERIORCOLOR"), NULL, 0); for (i = 0; i < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; i++) VGLMouseStdOrMask.Bitmap[i] = VGLMouseStdOrMask.Bitmap[i] == BORDER ? border : VGLMouseStdOrMask.Bitmap[i] == INTERIOR ? interior : 0; VGLMouseSetStdImage(); mouseinfo.operation = MOUSE_MODE; mouseinfo.u.mode.signal = SIGUSR2; if ((error = ioctl(0, CONS_MOUSECTL, &mouseinfo))) return error; signal(SIGUSR2, VGLMouseAction); mouseinfo.operation = MOUSE_GETINFO; ioctl(0, CONS_MOUSECTL, &mouseinfo); VGLMouseXpos = mouseinfo.u.data.x; VGLMouseYpos = mouseinfo.u.data.y; VGLMouseButtons = mouseinfo.u.data.buttons; VGLMouseMode(mode); return 0; } void VGLMouseRestore(void) { struct mouse_info mouseinfo; INTOFF(); mouseinfo.operation = MOUSE_GETINFO; if (ioctl(0, CONS_MOUSECTL, &mouseinfo) == 0) { mouseinfo.operation = MOUSE_MOVEABS; mouseinfo.u.data.x = VGLMouseXpos; mouseinfo.u.data.y = VGLMouseYpos; ioctl(0, CONS_MOUSECTL, &mouseinfo); } INTON(); } int VGLMouseStatus(int *x, int *y, char *buttons) { INTOFF(); *x = VGLMouseXpos; *y = VGLMouseYpos; *buttons = VGLMouseButtons; INTON(); return VGLMouseShown; } void VGLMouseFreeze(void) { INTOFF(); } int VGLMouseFreezeXY(int x, int y) { INTOFF(); if (VGLMouseShown != VGL_MOUSESHOW) return 0; if (x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE && y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE && VGLMouseAndMask->Bitmap[(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) return 1; return 0; } int VGLMouseOverlap(int x, int y, int width, int hight) { int overlap; if (VGLMouseShown != VGL_MOUSESHOW) return 0; if (x > VGLMouseXpos) overlap = (VGLMouseXpos + MOUSE_IMG_SIZE) - x; else overlap = (x + width) - VGLMouseXpos; if (overlap <= 0) return 0; if (y > VGLMouseYpos) overlap = (VGLMouseYpos + MOUSE_IMG_SIZE) - y; else overlap = (y + hight) - VGLMouseYpos; return overlap > 0; } void VGLMouseMerge(int x, int y, int width, byte *line) { int pos, x1, xend, xstart; xstart = x; if (xstart < VGLMouseXpos) xstart = VGLMouseXpos; xend = x + width; if (xend > VGLMouseXpos + MOUSE_IMG_SIZE) xend = VGLMouseXpos + MOUSE_IMG_SIZE; for (x1 = xstart; x1 < xend; x1++) { pos = (y - VGLMouseYpos) * MOUSE_IMG_SIZE + x1 - VGLMouseXpos; if (VGLMouseAndMask->Bitmap[pos]) bcopy(&VGLMouseOrMask->Bitmap[pos * VGLDisplay->PixelBytes], &line[(x1 - x) * VGLDisplay->PixelBytes], VGLDisplay->PixelBytes); } } void VGLMouseUnFreeze() { INTON(); } Index: head/lib/libvgl/simple.c =================================================================== --- head/lib/libvgl/simple.c (revision 346888) +++ head/lib/libvgl/simple.c (revision 346889) @@ -1,690 +1,688 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991-1997 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include "vgl.h" static int VGLBlank; static byte VGLBorderColor; static byte VGLSavePaletteRed[256]; static byte VGLSavePaletteGreen[256]; static byte VGLSavePaletteBlue[256]; #define ABS(a) (((a)<0) ? -(a) : (a)) #define SGN(a) (((a)<0) ? -1 : 1) #define min(x, y) (((x) < (y)) ? (x) : (y)) #define max(x, y) (((x) > (y)) ? (x) : (y)) void VGLSetXY(VGLBitmap *object, int x, int y, u_long color) { int offset, soffset, undermouse; VGLCheckSwitch(); if (x>=0 && xVXsize && y>=0 && yVYsize) { if (object == VGLDisplay) { undermouse = VGLMouseFreezeXY(x, y); VGLSetXY(&VGLVDisplay, x, y, color); } else if (object->Type != MEMBUF) return; /* invalid */ else undermouse = 0; if (!undermouse) { offset = (y * object->VXsize + x) * object->PixelBytes; switch (object->Type) { case VIDBUF8S: case VIDBUF16S: case VIDBUF32S: offset = VGLSetSegment(offset); /* FALLTHROUGH */ case MEMBUF: case VIDBUF8: case VIDBUF16: case VIDBUF24: case VIDBUF32: color = htole32(color); switch (object->PixelBytes) { case 1: memcpy(&object->Bitmap[offset], &color, 1); break; case 2: memcpy(&object->Bitmap[offset], &color, 2); break; case 3: memcpy(&object->Bitmap[offset], &color, 3); break; case 4: memcpy(&object->Bitmap[offset], &color, 4); break; } break; case VIDBUF24S: soffset = VGLSetSegment(offset); color = htole32(color); switch (VGLAdpInfo.va_window_size - soffset) { case 1: memcpy(&object->Bitmap[soffset], &color, 1); soffset = VGLSetSegment(offset + 1); memcpy(&object->Bitmap[soffset], (byte *)&color + 1, 2); break; case 2: memcpy(&object->Bitmap[soffset], &color, 2); soffset = VGLSetSegment(offset + 2); memcpy(&object->Bitmap[soffset], (byte *)&color + 2, 1); break; default: memcpy(&object->Bitmap[soffset], &color, 3); break; } break; case VIDBUF8X: outb(0x3c4, 0x02); outb(0x3c5, 0x01 << (x&0x3)); object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = ((byte)color); break; case VIDBUF4S: offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8); goto set_planar; case VIDBUF4: offset = y*VGLAdpInfo.va_line_width + x/8; set_planar: outb(0x3c4, 0x02); outb(0x3c5, 0x0f); outb(0x3ce, 0x00); outb(0x3cf, (byte)color & 0x0f); /* set/reset */ outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */ outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */ object->Bitmap[offset] |= (byte)color; } } if (object == VGLDisplay) VGLMouseUnFreeze(); } } u_long VGLGetXY(VGLBitmap *object, int x, int y) { u_long color; int offset; VGLCheckSwitch(); if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize) return 0; if (object == VGLDisplay) object = &VGLVDisplay; else if (object->Type != MEMBUF) return 0; /* invalid */ offset = (y * object->VXsize + x) * object->PixelBytes; switch (object->PixelBytes) { case 1: memcpy(&color, &object->Bitmap[offset], 1); return le32toh(color) & 0xff; case 2: memcpy(&color, &object->Bitmap[offset], 2); return le32toh(color) & 0xffff; case 3: memcpy(&color, &object->Bitmap[offset], 3); return le32toh(color) & 0xffffff; case 4: memcpy(&color, &object->Bitmap[offset], 4); return le32toh(color); } return 0; /* invalid */ } /* * Symmetric Double Step Line Algorithm by Brian Wyvill from * "Graphics Gems", Academic Press, 1990. */ #define SL_SWAP(a,b) {a^=b; b^=a; a^=b;} #define SL_ABSOLUTE(i,j,k) ( (i-j)*(k = ( (i-j)<0 ? -1 : 1))) void plot(VGLBitmap * object, int x, int y, int flag, u_long color) { /* non-zero flag indicates the pixels need swapping back. */ if (flag) VGLSetXY(object, y, x, color); else VGLSetXY(object, x, y, color); } void VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color) { int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left; int sign_x, sign_y, step, reverse, i; dx = SL_ABSOLUTE(x2, x1, sign_x); dy = SL_ABSOLUTE(y2, y1, sign_y); /* decide increment sign by the slope sign */ if (sign_x == sign_y) step = 1; else step = -1; if (dy > dx) { /* chooses axis of greatest movement (make dx) */ SL_SWAP(x1, y1); SL_SWAP(x2, y2); SL_SWAP(dx, dy); reverse = 1; } else reverse = 0; /* note error check for dx==0 should be included here */ if (x1 > x2) { /* start from the smaller coordinate */ x = x2; y = y2; /* x1 = x1; y1 = y1; */ } else { x = x1; y = y1; x1 = x2; y1 = y2; } /* Note dx=n implies 0 - n or (dx+1) pixels to be set */ /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */ /* In fact (dx-1)/4 as 2 pixels are already plotted */ xend = (dx - 1) / 4; pixels_left = (dx - 1) % 4; /* number of pixels left over at the * end */ plot(object, x, y, reverse, color); if (pixels_left < 0) return; /* plot only one pixel for zero length * vectors */ plot(object, x1, y1, reverse, color); /* plot first two points */ incr2 = 4 * dy - 2 * dx; if (incr2 < 0) { /* slope less than 1/2 */ c = 2 * dy; incr1 = 2 * c; D = incr1 - dx; for (i = 0; i < xend; i++) { /* plotting loop */ ++x; --x1; if (D < 0) { /* pattern 1 forwards */ plot(object, x, y, reverse, color); plot(object, ++x, y, reverse, color); /* pattern 1 backwards */ plot(object, x1, y1, reverse, color); plot(object, --x1, y1, reverse, color); D += incr1; } else { if (D < c) { /* pattern 2 forwards */ plot(object, x, y, reverse, color); plot(object, ++x, y += step, reverse, color); /* pattern 2 backwards */ plot(object, x1, y1, reverse, color); plot(object, --x1, y1 -= step, reverse, color); } else { /* pattern 3 forwards */ plot(object, x, y += step, reverse, color); plot(object, ++x, y, reverse, color); /* pattern 3 backwards */ plot(object, x1, y1 -= step, reverse, color); plot(object, --x1, y1, reverse, color); } D += incr2; } } /* end for */ /* plot last pattern */ if (pixels_left) { if (D < 0) { plot(object, ++x, y, reverse, color); /* pattern 1 */ if (pixels_left > 1) plot(object, ++x, y, reverse, color); if (pixels_left > 2) plot(object, --x1, y1, reverse, color); } else { if (D < c) { plot(object, ++x, y, reverse, color); /* pattern 2 */ if (pixels_left > 1) plot(object, ++x, y += step, reverse, color); if (pixels_left > 2) plot(object, --x1, y1, reverse, color); } else { /* pattern 3 */ plot(object, ++x, y += step, reverse, color); if (pixels_left > 1) plot(object, ++x, y, reverse, color); if (pixels_left > 2) plot(object, --x1, y1 -= step, reverse, color); } } } /* end if pixels_left */ } /* end slope < 1/2 */ else { /* slope greater than 1/2 */ c = 2 * (dy - dx); incr1 = 2 * c; D = incr1 + dx; for (i = 0; i < xend; i++) { ++x; --x1; if (D > 0) { /* pattern 4 forwards */ plot(object, x, y += step, reverse, color); plot(object, ++x, y += step, reverse, color); /* pattern 4 backwards */ plot(object, x1, y1 -= step, reverse, color); plot(object, --x1, y1 -= step, reverse, color); D += incr1; } else { if (D < c) { /* pattern 2 forwards */ plot(object, x, y, reverse, color); plot(object, ++x, y += step, reverse, color); /* pattern 2 backwards */ plot(object, x1, y1, reverse, color); plot(object, --x1, y1 -= step, reverse, color); } else { /* pattern 3 forwards */ plot(object, x, y += step, reverse, color); plot(object, ++x, y, reverse, color); /* pattern 3 backwards */ plot(object, x1, y1 -= step, reverse, color); plot(object, --x1, y1, reverse, color); } D += incr2; } } /* end for */ /* plot last pattern */ if (pixels_left) { if (D > 0) { plot(object, ++x, y += step, reverse, color); /* pattern 4 */ if (pixels_left > 1) plot(object, ++x, y += step, reverse, color); if (pixels_left > 2) plot(object, --x1, y1 -= step, reverse, color); } else { if (D < c) { plot(object, ++x, y, reverse, color); /* pattern 2 */ if (pixels_left > 1) plot(object, ++x, y += step, reverse, color); if (pixels_left > 2) plot(object, --x1, y1, reverse, color); } else { /* pattern 3 */ plot(object, ++x, y += step, reverse, color); if (pixels_left > 1) plot(object, ++x, y, reverse, color); if (pixels_left > 2) { if (D > c) /* step 3 */ plot(object, --x1, y1 -= step, reverse, color); else /* step 2 */ plot(object, --x1, y1, reverse, color); } } } } } } void VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color) { VGLLine(object, x1, y1, x2, y1, color); VGLLine(object, x2, y1, x2, y2, color); VGLLine(object, x2, y2, x1, y2, color); VGLLine(object, x1, y2, x1, y1, color); } void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color) { int y; for (y=y1; y<=y2; y++) VGLLine(object, x1, y, x2, y, color); } static inline void set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, u_long color) { if (x!=0) { VGLSetXY(object, xc+x, yc+y, color); VGLSetXY(object, xc-x, yc+y, color); if (y!=0) { VGLSetXY(object, xc+x, yc-y, color); VGLSetXY(object, xc-x, yc-y, color); } } else { VGLSetXY(object, xc, yc+y, color); if (y!=0) VGLSetXY(object, xc, yc-y, color); } } void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color) { int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b; int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b; while (dx0) { y--; dy-=asq2; d-=dy; } x++; dx+=bsq2; d+=bsq+dx; } d+=(3*(asq-bsq)/2-(dx+dy))/2; while (y>=0) { set4pixels(object, x, y, xc, yc, color); if (d<0) { x++; dx+=bsq2; d+=dx; } y--; dy-=asq2; d+=asq-dy; } } static inline void set2lines(VGLBitmap *object, int x, int y, int xc, int yc, u_long color) { if (x!=0) { VGLLine(object, xc+x, yc+y, xc-x, yc+y, color); if (y!=0) VGLLine(object, xc+x, yc-y, xc-x, yc-y, color); } else { VGLLine(object, xc, yc+y, xc, yc-y, color); } } void VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color) { int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b; int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b; while (dx0) { y--; dy-=asq2; d-=dy; } x++; dx+=bsq2; d+=bsq+dx; } d+=(3*(asq-bsq)/2-(dx+dy))/2; while (y>=0) { set2lines(object, x, y, xc, yc, color); if (d<0) { x++; dx+=bsq2; d+=dx; } y--; dy-=asq2; d+=asq-dy; } } void VGLClear(VGLBitmap *object, u_long color) { VGLBitmap src; - int i, len, mouseoverlap, offset; + int i, len, mousemode, offset; VGLCheckSwitch(); if (object == VGLDisplay) { VGLMouseFreeze(); - mouseoverlap = VGLMouseOverlap(0, 0, object->VXsize, object->VYsize); - if (mouseoverlap) - VGLMousePointerHide(); VGLClear(&VGLVDisplay, color); } else if (object->Type != MEMBUF) return; /* invalid */ switch (object->Type) { case MEMBUF: case VIDBUF8: case VIDBUF8S: case VIDBUF16: case VIDBUF16S: case VIDBUF24: case VIDBUF24S: case VIDBUF32: case VIDBUF32S: src.Type = MEMBUF; src.Xsize = object->Xsize; src.VXsize = object->VXsize; src.Ysize = 1; src.VYsize = 1; src.Xorigin = 0; src.Yorigin = 0; src.Bitmap = alloca(object->VXsize * object->PixelBytes); src.PixelBytes = object->PixelBytes; color = htole32(color); for (i = 0; i < object->VXsize; i++) bcopy(&color, src.Bitmap + i * object->PixelBytes, object->PixelBytes); for (i = 0; i < object->VYsize; i++) __VGLBitmapCopy(&src, 0, 0, object, 0, i, object->VXsize, 1); break; case VIDBUF8X: + mousemode = __VGLMouseMode(VGL_MOUSEHIDE); /* XXX works only for Xsize % 4 = 0 */ outb(0x3c6, 0xff); outb(0x3c4, 0x02); outb(0x3c5, 0x0f); memset(object->Bitmap, (byte)color, VGLAdpInfo.va_line_width*object->VYsize); + __VGLMouseMode(mousemode); break; case VIDBUF4: case VIDBUF4S: + mousemode = __VGLMouseMode(VGL_MOUSEHIDE); /* XXX works only for Xsize % 8 = 0 */ outb(0x3c4, 0x02); outb(0x3c5, 0x0f); outb(0x3ce, 0x05); outb(0x3cf, 0x02); /* mode 2 */ outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) { VGLSetSegment(offset); len = min(object->VXsize*object->VYsize - offset, VGLAdpInfo.va_window_size); memset(object->Bitmap, (byte)color, len); offset += len; } outb(0x3ce, 0x05); outb(0x3cf, 0x00); + __VGLMouseMode(mousemode); break; } - if (object == VGLDisplay) { - if (mouseoverlap) - VGLMousePointerShow(); + if (object == VGLDisplay) VGLMouseUnFreeze(); - } } static inline u_long VGLrgbToNative(uint16_t r, uint16_t g, uint16_t b) { int nr, ng, nb; nr = VGLModeInfo.vi_pixel_fsizes[2]; ng = VGLModeInfo.vi_pixel_fsizes[1]; nb = VGLModeInfo.vi_pixel_fsizes[0]; return (r >> (16 - nr) << (ng + nb)) | (g >> (16 - ng) << nb) | (b >> (16 - nb) << 0); } u_long VGLrgb332ToNative(byte c) { uint16_t r, g, b; /* 3:3:2 to 16:16:16 */ r = ((c & 0xe0) >> 5) * 0xffff / 7; g = ((c & 0x1c) >> 2) * 0xffff / 7; b = ((c & 0x03) >> 0) * 0xffff / 3; return VGLrgbToNative(r, g, b); } void VGLRestorePalette() { int i; if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT) return; outb(0x3C6, 0xFF); inb(0x3DA); outb(0x3C8, 0x00); for (i=0; i<256; i++) { outb(0x3C9, VGLSavePaletteRed[i]); inb(0x84); outb(0x3C9, VGLSavePaletteGreen[i]); inb(0x84); outb(0x3C9, VGLSavePaletteBlue[i]); inb(0x84); } inb(0x3DA); outb(0x3C0, 0x20); } void VGLSavePalette() { int i; if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT) return; outb(0x3C6, 0xFF); inb(0x3DA); outb(0x3C7, 0x00); for (i=0; i<256; i++) { VGLSavePaletteRed[i] = inb(0x3C9); inb(0x84); VGLSavePaletteGreen[i] = inb(0x3C9); inb(0x84); VGLSavePaletteBlue[i] = inb(0x3C9); inb(0x84); } inb(0x3DA); outb(0x3C0, 0x20); } void VGLSetPalette(byte *red, byte *green, byte *blue) { int i; if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT) return; for (i=0; i<256; i++) { VGLSavePaletteRed[i] = red[i]; VGLSavePaletteGreen[i] = green[i]; VGLSavePaletteBlue[i] = blue[i]; } VGLCheckSwitch(); outb(0x3C6, 0xFF); inb(0x3DA); outb(0x3C8, 0x00); for (i=0; i<256; i++) { outb(0x3C9, VGLSavePaletteRed[i]); inb(0x84); outb(0x3C9, VGLSavePaletteGreen[i]); inb(0x84); outb(0x3C9, VGLSavePaletteBlue[i]); inb(0x84); } inb(0x3DA); outb(0x3C0, 0x20); } void VGLSetPaletteIndex(byte color, byte red, byte green, byte blue) { if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT) return; VGLSavePaletteRed[color] = red; VGLSavePaletteGreen[color] = green; VGLSavePaletteBlue[color] = blue; VGLCheckSwitch(); outb(0x3C6, 0xFF); inb(0x3DA); outb(0x3C8, color); outb(0x3C9, red); outb(0x3C9, green); outb(0x3C9, blue); inb(0x3DA); outb(0x3C0, 0x20); } void VGLRestoreBorder(void) { VGLSetBorder(VGLBorderColor); } void VGLSetBorder(byte color) { if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0)) return; VGLCheckSwitch(); inb(0x3DA); outb(0x3C0,0x11); outb(0x3C0, color); inb(0x3DA); outb(0x3C0, 0x20); VGLBorderColor = color; if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT) ioctl(0, KDDISABIO, 0); } void VGLRestoreBlank(void) { VGLBlankDisplay(VGLBlank); } void VGLBlankDisplay(int blank) { byte val; if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0)) return; VGLCheckSwitch(); outb(0x3C4, 0x01); val = inb(0x3C5); outb(0x3C4, 0x01); outb(0x3C5, ((blank) ? (val |= 0x20) : (val &= 0xDF))); VGLBlank = blank; if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT) ioctl(0, KDDISABIO, 0); } Index: head/lib/libvgl/vgl.h =================================================================== --- head/lib/libvgl/vgl.h (revision 346888) +++ head/lib/libvgl/vgl.h (revision 346889) @@ -1,165 +1,163 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991-1997 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _VGL_H_ #define _VGL_H_ #include #include #include #include typedef unsigned char byte; typedef struct { byte Type; int Xsize, Ysize; int VXsize, VYsize; int Xorigin, Yorigin; byte *Bitmap; int PixelBytes; } VGLBitmap; #define VGLBITMAP_INITIALIZER(t, x, y, bits) \ { (t), (x), (y), (x), (y), 0, 0, (bits), -1 } /* * Defined Type's */ #define MEMBUF 0 #define VIDBUF4 1 #define VIDBUF8 2 #define VIDBUF8X 3 #define VIDBUF8S 4 #define VIDBUF4S 5 #define VIDBUF16 6 /* Direct Color linear buffer */ #define VIDBUF24 7 /* Direct Color linear buffer */ #define VIDBUF32 8 /* Direct Color linear buffer */ #define VIDBUF16S 9 /* Direct Color segmented buffer */ #define VIDBUF24S 10 /* Direct Color segmented buffer */ #define VIDBUF32S 11 /* Direct Color segmented buffer */ #define NOBUF 255 typedef struct VGLText { byte Width, Height; byte *BitmapArray; } VGLText; typedef struct VGLObject { int Id; int Type; int Status; int Xpos, Ypos; int Xhot, Yhot; VGLBitmap *Image; VGLBitmap *Mask; int (*CallBackFunction)(); } VGLObject; #define MOUSE_IMG_SIZE 16 #define VGL_MOUSEHIDE 0 #define VGL_MOUSESHOW 1 #define VGL_MOUSEFREEZE 0 #define VGL_MOUSEUNFREEZE 1 #define VGL_DIR_RIGHT 0 #define VGL_DIR_UP 1 #define VGL_DIR_LEFT 2 #define VGL_DIR_DOWN 3 #define VGL_RAWKEYS 1 #define VGL_CODEKEYS 2 #define VGL_XLATEKEYS 3 extern video_adapter_info_t VGLAdpInfo; extern video_info_t VGLModeInfo; extern VGLBitmap *VGLDisplay; extern VGLBitmap VGLVDisplay; extern byte *VGLBuf; /* * Prototypes */ /* bitmap.c */ int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); VGLBitmap *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits); void VGLBitmapDestroy(VGLBitmap *object); int VGLBitmapAllocateBits(VGLBitmap *object); void VGLBitmapCvt(VGLBitmap *src, VGLBitmap *dst); /* keyboard.c */ int VGLKeyboardInit(int mode); void VGLKeyboardEnd(void); int VGLKeyboardGetCh(void); /* main.c */ void VGLEnd(void); int VGLInit(int mode); void VGLCheckSwitch(void); int VGLSetVScreenSize(VGLBitmap *object, int VXsize, int VYsize); int VGLPanScreen(VGLBitmap *object, int x, int y); int VGLSetSegment(unsigned int offset); /* mouse.c */ -void VGLMousePointerShow(void); -void VGLMousePointerHide(void); +int __VGLMouseMode(int mode); void VGLMouseMode(int mode); -void VGLMouseAction(int dummy); void VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask); void VGLMouseSetStdImage(void); int VGLMouseInit(int mode); void VGLMouseRestore(void); int VGLMouseStatus(int *x, int *y, char *buttons); void VGLMouseFreeze(void); int VGLMouseFreezeXY(int x, int y); void VGLMouseMerge(int x, int y, int width, byte *line); int VGLMouseOverlap(int x, int y, int width, int hight); void VGLMouseUnFreeze(void); /* simple.c */ void VGLSetXY(VGLBitmap *object, int x, int y, u_long color); u_long VGLGetXY(VGLBitmap *object, int x, int y); void VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color); void VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color); void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color); void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color); void VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color); void VGLClear(VGLBitmap *object, u_long color); u_long VGLrgb332ToNative(byte c); void VGLRestoreBlank(void); void VGLRestoreBorder(void); void VGLRestorePalette(void); void VGLSavePalette(void); void VGLSetPalette(byte *red, byte *green, byte *blue); void VGLSetPaletteIndex(byte color, byte red, byte green, byte blue); void VGLSetBorder(byte color); void VGLBlankDisplay(int blank); /* text.c */ int VGLTextSetFontFile(char *filename); void VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch, u_long fgcol, u_long bgcol, int fill, int dir); void VGLBitmapString(VGLBitmap *Object, int x, int y, char *str, u_long fgcol, u_long bgcol, int fill, int dir); #endif /* !_VGL_H_ */