Index: head/lib/libvgl/bitmap.c =================================================================== --- head/lib/libvgl/bitmap.c (revision 345584) +++ head/lib/libvgl/bitmap.c (revision 345585) @@ -1,409 +1,413 @@ /*- * 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 "vgl.h" #define min(x, y) (((x) < (y)) ? (x) : (y)) static byte mask[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; static int color2bit[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, 0x00010100, 0x00010101, 0x01000000, 0x01000001, 0x01000100, 0x01000101, 0x01010000, 0x01010001, 0x01010100, 0x01010101}; static void WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line) { int i, pos, last, planepos, start_offset, end_offset, offset; int len; unsigned int word = 0; byte *address; byte *VGLPlane[4]; switch (dst->Type) { case VIDBUF4: case VIDBUF4S: start_offset = (x & 0x07); end_offset = (x + width) & 0x07; i = (width + start_offset) / 8; if (end_offset) i++; VGLPlane[0] = VGLBuf; VGLPlane[1] = VGLPlane[0] + i; VGLPlane[2] = VGLPlane[1] + i; VGLPlane[3] = VGLPlane[2] + i; pos = 0; planepos = 0; last = 8 - start_offset; while (pos < width) { word = 0; while (pos < last && pos < width) word = (word<<1) | color2bit[line[pos++]&0x0f]; VGLPlane[0][planepos] = word; VGLPlane[1][planepos] = word>>8; VGLPlane[2][planepos] = word>>16; VGLPlane[3][planepos] = word>>24; planepos++; last += 8; } planepos--; if (end_offset) { word <<= (8 - end_offset); VGLPlane[0][planepos] = word; VGLPlane[1][planepos] = word>>8; VGLPlane[2][planepos] = word>>16; VGLPlane[3][planepos] = word>>24; } if (start_offset || end_offset) width+=8; width /= 8; outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ for (i=0; i<4; i++) { outb(0x3c4, 0x02); outb(0x3c5, 0x01<Type == VIDBUF4) { if (end_offset) VGLPlane[i][planepos] |= dst->Bitmap[pos+planepos] & mask[end_offset]; if (start_offset) VGLPlane[i][0] |= dst->Bitmap[pos] & ~mask[start_offset]; bcopy(&VGLPlane[i][0], dst->Bitmap + pos, width); } else { /* VIDBUF4S */ if (end_offset) { offset = VGLSetSegment(pos + planepos); VGLPlane[i][planepos] |= dst->Bitmap[offset] & mask[end_offset]; } offset = VGLSetSegment(pos); if (start_offset) VGLPlane[i][0] |= dst->Bitmap[offset] & ~mask[start_offset]; for (last = width; ; ) { len = min(VGLAdpInfo.va_window_size - offset, last); bcopy(&VGLPlane[i][width - last], dst->Bitmap + offset, len); pos += len; last -= len; if (last <= 0) break; offset = VGLSetSegment(pos); } } } break; case VIDBUF8X: address = dst->Bitmap + VGLAdpInfo.va_line_width * y + x/4; for (i=0; i<4; i++) { outb(0x3c4, 0x02); outb(0x3c5, 0x01 << ((x + i)%4)); for (planepos=0, pos=i; posVXsize * y + x; while (width > 0) { offset = VGLSetSegment(pos); i = min(VGLAdpInfo.va_window_size - offset, width); bcopy(line, dst->Bitmap + offset, i); line += i; pos += i; width -= i; } break; case VIDBUF16S: case VIDBUF24S: case VIDBUF32S: width = width * dst->PixelBytes; pos = (dst->VXsize * y + x) * dst->PixelBytes; while (width > 0) { offset = VGLSetSegment(pos); i = min(VGLAdpInfo.va_window_size - offset, width); bcopy(line, dst->Bitmap + offset, i); line += i; pos += i; width -= i; } break; case VIDBUF8: case MEMBUF: address = dst->Bitmap + dst->VXsize * y + x; bcopy(line, address, width); break; case VIDBUF16: case VIDBUF24: case VIDBUF32: address = dst->Bitmap + (dst->VXsize * y + x) * dst->PixelBytes; bcopy(line, address, width * dst->PixelBytes); break; default: ; } } static void ReadVerticalLine(VGLBitmap *src, int x, int y, int width, byte *line) { int i, bit, pos, count, planepos, start_offset, end_offset, offset; int width2, len; byte *address; byte *VGLPlane[4]; switch (src->Type) { case VIDBUF4S: start_offset = (x & 0x07); end_offset = (x + width) & 0x07; count = (width + start_offset) / 8; if (end_offset) count++; VGLPlane[0] = VGLBuf; VGLPlane[1] = VGLPlane[0] + count; VGLPlane[2] = VGLPlane[1] + count; VGLPlane[3] = VGLPlane[2] + count; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, i); pos = VGLAdpInfo.va_line_width*y + x/8; for (width2 = count; width2 > 0; ) { offset = VGLSetSegment(pos); len = min(VGLAdpInfo.va_window_size - offset, width2); bcopy(src->Bitmap + offset, &VGLPlane[i][count - width2], len); pos += len; width2 -= len; } } goto read_planar; case VIDBUF4: address = src->Bitmap + VGLAdpInfo.va_line_width * y + x/8; start_offset = (x & 0x07); end_offset = (x + width) & 0x07; count = (width + start_offset) / 8; if (end_offset) count++; VGLPlane[0] = VGLBuf; VGLPlane[1] = VGLPlane[0] + count; VGLPlane[2] = VGLPlane[1] + count; VGLPlane[3] = VGLPlane[2] + count; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, i); bcopy(address, &VGLPlane[i][0], count); } read_planar: pos = 0; planepos = 0; bit = 7 - start_offset; while (pos < width) { for (; bit >= 0 && pos < width; bit--, pos++) { line[pos] = (VGLPlane[0][planepos] & (1<Bitmap + VGLAdpInfo.va_line_width * y + x/4; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, (x + i)%4); for (planepos=0, pos=i; posVXsize * y + x; while (width > 0) { offset = VGLSetSegment(pos); i = min(VGLAdpInfo.va_window_size - offset, width); bcopy(src->Bitmap + offset, line, i); line += i; pos += i; width -= i; } break; case VIDBUF16S: case VIDBUF24S: case VIDBUF32S: width = width * src->PixelBytes; pos = (src->VXsize * y + x) * src->PixelBytes; while (width > 0) { offset = VGLSetSegment(pos); i = min(VGLAdpInfo.va_window_size - offset, width); bcopy(src->Bitmap + offset, line, i); line += i; pos += i; width -= i; } break; case VIDBUF8: case MEMBUF: address = src->Bitmap + src->VXsize * y + x; bcopy(address, line, width); break; case VIDBUF16: case VIDBUF24: case VIDBUF32: address = src->Bitmap + (src->VXsize * y + x) * src->PixelBytes; bcopy(address, line, width * src->PixelBytes); break; default: ; } } int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight) { int srcline, dstline; if (srcx>src->VXsize || srcy>src->VYsize || dstx>dst->VXsize || dsty>dst->VYsize) return -1; if (srcx < 0) { width=width+srcx; dstx-=srcx; srcx=0; } if (srcy < 0) { hight=hight+srcy; dsty-=srcy; srcy=0; } if (dstx < 0) { width=width+dstx; srcx-=dstx; dstx=0; } if (dsty < 0) { hight=hight+dsty; srcy-=dsty; dsty=0; } if (srcx+width > src->VXsize) width=src->VXsize-srcx; if (srcy+hight > src->VYsize) hight=src->VYsize-srcy; if (dstx+width > dst->VXsize) width=dst->VXsize-dstx; if (dsty+hight > dst->VYsize) hight=dst->VYsize-dsty; if (width < 0 || hight < 0) return -1; if (src->Type == MEMBUF) { for (srcline=srcy, dstline=dsty; srclineBitmap+(srcline*src->VXsize+srcx)*dst->PixelBytes); } } else if (dst->Type == MEMBUF) { for (srcline=srcy, dstline=dsty; srclineBitmap+(dstline*dst->VXsize+dstx)*src->PixelBytes); } } else { byte buffer[2048]; /* XXX */ byte *p; if (width * src->PixelBytes > sizeof(buffer)) { p = malloc(width * src->PixelBytes); if (p == NULL) return 1; } else { p = buffer; } for (srcline=srcy, dstline=dsty; srclinePixelBytes > sizeof(buffer)) free(p); } return 0; } int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight) { int error; - VGLMouseFreeze(dstx, dsty, width, hight, 0); + if (src->Type != MEMBUF) + VGLMouseFreeze(srcx, srcy, width, hight, 0); + if (dst->Type != MEMBUF) + VGLMouseFreeze(dstx, dsty, width, hight, 0); error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, hight); - VGLMouseUnFreeze(); + if (src->Type != MEMBUF || dst->Type != MEMBUF) + VGLMouseUnFreeze(); return error; } VGLBitmap *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits) { VGLBitmap *object; if (type != MEMBUF) return NULL; if (xsize < 0 || ysize < 0) return NULL; object = (VGLBitmap *)malloc(sizeof(*object)); if (object == NULL) return NULL; object->Type = type; object->Xsize = xsize; object->Ysize = ysize; object->VXsize = xsize; object->VYsize = ysize; object->Xorigin = 0; object->Yorigin = 0; object->Bitmap = bits; object->PixelBytes = VGLDisplay->PixelBytes; return object; } void VGLBitmapDestroy(VGLBitmap *object) { if (object->Bitmap) free(object->Bitmap); free(object); } int VGLBitmapAllocateBits(VGLBitmap *object) { object->Bitmap = malloc(object->VXsize*object->VYsize*object->PixelBytes); if (object->Bitmap == NULL) return -1; return 0; } Index: head/lib/libvgl/mouse.c =================================================================== --- head/lib/libvgl/mouse.c (revision 345584) +++ head/lib/libvgl/mouse.c (revision 345585) @@ -1,311 +1,323 @@ /*- * 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" #define X 0xff 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,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,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,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; static byte StdOrMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,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,0,X,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,X,X,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,X,X,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; #undef X 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 byte map[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE*4]; static VGLBitmap VGLMouseSave = VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, map); static int VGLMouseVisible = 0; static int VGLMouseFrozen = 0; static int VGLMouseShown = 0; static int VGLMouseXpos = 0; static int VGLMouseYpos = 0; static int VGLMouseButtons = 0; void VGLMousePointerShow() { byte buf[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE*4]; VGLBitmap buffer = VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf); byte crtcidx, crtcval, gdcidx, gdcval; int i, pos, pos1; if (!VGLMouseVisible) { + VGLMouseFrozen++; VGLMouseVisible = 1; crtcidx = inb(0x3c4); crtcval = inb(0x3c5); gdcidx = inb(0x3ce); gdcval = inb(0x3cf); __VGLBitmapCopy(VGLDisplay, VGLMouseXpos, VGLMouseYpos, &VGLMouseSave, 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); bcopy(VGLMouseSave.Bitmap, buffer.Bitmap, MOUSE_IMG_SIZE*MOUSE_IMG_SIZE*VGLDisplay->PixelBytes); for (pos = 0; pos < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; pos++) for (i = 0; i < VGLDisplay->PixelBytes; i++) { pos1 = pos * VGLDisplay->PixelBytes + i; buffer.Bitmap[pos1] = (buffer.Bitmap[pos1] & ~VGLMouseAndMask->Bitmap[pos]) | VGLMouseOrMask->Bitmap[pos]; } __VGLBitmapCopy(&buffer, 0, 0, VGLDisplay, VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); outb(0x3c4, crtcidx); outb(0x3c5, crtcval); outb(0x3ce, gdcidx); outb(0x3cf, gdcval); + VGLMouseFrozen--; } } void VGLMousePointerHide() { byte crtcidx, crtcval, gdcidx, gdcval; if (VGLMouseVisible) { + VGLMouseFrozen++; VGLMouseVisible = 0; crtcidx = inb(0x3c4); crtcval = inb(0x3c5); gdcidx = inb(0x3ce); gdcval = inb(0x3cf); __VGLBitmapCopy(&VGLMouseSave, 0, 0, VGLDisplay, VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); outb(0x3c4, crtcidx); outb(0x3c5, crtcval); outb(0x3ce, gdcidx); outb(0x3cf, gdcval); + VGLMouseFrozen--; } } void VGLMouseMode(int mode) { if (mode == VGL_MOUSESHOW) { if (VGLMouseShown == VGL_MOUSEHIDE) { VGLMousePointerShow(); VGLMouseShown = VGL_MOUSESHOW; } } else { if (VGLMouseShown == VGL_MOUSESHOW) { VGLMousePointerHide(); VGLMouseShown = VGL_MOUSEHIDE; } } } void VGLMouseAction(int dummy) { struct mouse_info mouseinfo; if (VGLMouseFrozen) { - VGLMouseFrozen++; + VGLMouseFrozen += 8; return; } mouseinfo.operation = MOUSE_GETINFO; ioctl(0, CONS_MOUSECTL, &mouseinfo); if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerHide(); VGLMouseXpos = mouseinfo.u.data.x; VGLMouseYpos = mouseinfo.u.data.y; VGLMouseButtons = mouseinfo.u.data.buttons; if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerShow(); } void VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask) { if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerHide(); VGLMouseAndMask = AndMask; VGLMouseOrMask = OrMask; if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerShow(); } void VGLMouseSetStdImage() { if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerHide(); VGLMouseAndMask = &VGLMouseStdAndMask; VGLMouseOrMask = &VGLMouseStdOrMask; if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerShow(); } int VGLMouseInit(int mode) { struct mouse_info mouseinfo; int error, i, mask; switch (VGLModeInfo.vi_mem_model) { case V_INFO_MM_PACKED: case V_INFO_MM_PLANAR: mask = 0x0f; break; case V_INFO_MM_VGAX: mask = 0x3f; break; default: mask = 0xff; break; } for (i = 0; i < 256; i++) VGLMouseStdOrMask.Bitmap[i] &= mask; 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; } int VGLMouseStatus(int *x, int *y, char *buttons) { signal(SIGUSR2, SIG_IGN); *x = VGLMouseXpos; *y = VGLMouseYpos; *buttons = VGLMouseButtons; signal(SIGUSR2, VGLMouseAction); return VGLMouseShown; } int VGLMouseFreeze(int x, int y, int width, int hight, u_long color) { int i, xstride, ystride; - if (!VGLMouseFrozen) { - VGLMouseFrozen = 1; - if (width > 1 || hight > 1) { /* bitmap */ + VGLMouseFrozen++; + if (width > 1 || hight > 1 || (color & 0xc0000000) == 0) { /* bitmap */ if (VGLMouseShown == 1) { int overlap; if (x > VGLMouseXpos) overlap = (VGLMouseXpos + MOUSE_IMG_SIZE) - x; else overlap = (x + width) - VGLMouseXpos; if (overlap > 0) { if (y > VGLMouseYpos) overlap = (VGLMouseYpos + MOUSE_IMG_SIZE) - y; else overlap = (y + hight) - VGLMouseYpos; if (overlap > 0) VGLMousePointerHide(); } } } else { /* bit */ if (VGLMouseShown && x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE && y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE) { xstride = VGLDisplay->PixelBytes; ystride = MOUSE_IMG_SIZE * xstride; - for (i = 0; i < xstride; i++, color >>= 8) - VGLMouseSave.Bitmap[(y-VGLMouseYpos)*ystride+ - (x-VGLMouseXpos)*xstride+i] = color; - if (VGLMouseAndMask->Bitmap - [(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) { - return 1; + if (color & 0x40000000) { /* Get */ + color = 0; + for (i = xstride - 1; i >= 0; i--) + color = (color << 8) | + VGLMouseSave.Bitmap[(y-VGLMouseYpos)*ystride+ + (x-VGLMouseXpos)*xstride+i]; + return 0x40000000 | (color & 0xffffff); + } else { /* Set */ + color &= 0xffffff; /* discard flag and other garbage */ + for (i = 0; i < xstride; i++, color >>= 8) + VGLMouseSave.Bitmap[(y-VGLMouseYpos)*ystride+ + (x-VGLMouseXpos)*xstride+i] = color; + if (VGLMouseAndMask->Bitmap + [(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) { + return 1; + } } } } - } return 0; } void VGLMouseUnFreeze() { - if (VGLMouseFrozen > 1) { + if (VGLMouseFrozen > 8) { VGLMouseFrozen = 0; VGLMouseAction(0); } else { - VGLMouseFrozen = 0; if (VGLMouseShown == VGL_MOUSESHOW && !VGLMouseVisible) VGLMousePointerShow(); + VGLMouseFrozen = 0; } } Index: head/lib/libvgl/simple.c =================================================================== --- head/lib/libvgl/simple.c (revision 345584) +++ head/lib/libvgl/simple.c (revision 345585) @@ -1,670 +1,692 @@ /*- * 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 "vgl.h" 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)) static void color2mem(u_long color, byte *b, int len) { switch (len) { case 4: b[3] = (color >> 24) & 0xff; /* fallthrough */ case 3: b[2] = (color >> 16) & 0xff; /* fallthrough */ case 2: b[1] = (color >> 8) & 0xff; /* fallthrough */ case 1: default: b[0] = color & 0xff; break; } return; } static u_long mem2color(byte *b, int len) { u_long color = 0; switch (len) { case 4: color |= (b[3] & 0xff) << 24; /* fallthrough */ case 3: color |= (b[2] & 0xff) << 16; /* fallthrough */ case 2: color |= (b[1] & 0xff) << 8; /* fallthrough */ case 1: default: color |= (b[0] & 0xff); break; } return color; } void VGLSetXY(VGLBitmap *object, int x, int y, u_long color) { int offset; byte b[4]; VGLCheckSwitch(); if (x>=0 && xVXsize && y>=0 && yVYsize) { - if (!VGLMouseFreeze(x, y, 1, 1, color)) { + if (object->Type == MEMBUF || + !VGLMouseFreeze(x, y, 1, 1, 0x80000000 | color)) { switch (object->Type) { case MEMBUF: case VIDBUF8: object->Bitmap[y*object->VXsize+x]=((byte)color); break; case VIDBUF8S: object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=((byte)color); break; case VIDBUF16: case VIDBUF24: case VIDBUF32: color2mem(color, b, object->PixelBytes); bcopy(b, &object->Bitmap[(y*object->VXsize+x) * object->PixelBytes], object->PixelBytes); break; case VIDBUF16S: case VIDBUF24S: case VIDBUF32S: color2mem(color, b, object->PixelBytes); offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes); bcopy(b, &object->Bitmap[offset], object->PixelBytes); 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; } } - VGLMouseUnFreeze(); + if (object->Type != MEMBUF) + VGLMouseUnFreeze(); } } -u_long -VGLGetXY(VGLBitmap *object, int x, int y) +static u_long +__VGLGetXY(VGLBitmap *object, int x, int y) { int offset; byte b[4]; int i; u_long color; byte mask; - VGLCheckSwitch(); - if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize) - return 0; switch (object->Type) { case MEMBUF: case VIDBUF8: return object->Bitmap[((y*object->VXsize)+x)]; case VIDBUF8S: return object->Bitmap[VGLSetSegment(y*object->VXsize+x)]; case VIDBUF16: case VIDBUF24: case VIDBUF32: bcopy(&object->Bitmap[(y*object->VXsize+x) * object->PixelBytes], b, object->PixelBytes); return (mem2color(b, object->PixelBytes)); case VIDBUF16S: case VIDBUF24S: case VIDBUF32S: offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes); bcopy(&object->Bitmap[offset], b, object->PixelBytes); return (mem2color(b, object->PixelBytes)); case VIDBUF8X: outb(0x3ce, 0x04); outb(0x3cf, x & 0x3); return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)]; case VIDBUF4S: offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8); goto get_planar; case VIDBUF4: offset = y*VGLAdpInfo.va_line_width + x/8; get_planar: color = 0; mask = 0x80 >> (x%8); for (i = 0; i < VGLModeInfo.vi_planes; i++) { outb(0x3ce, 0x04); outb(0x3cf, i); color |= (((volatile VGLBitmap *)object)->Bitmap[offset] & mask) ? (1 << i) : 0; } return color; } return 0; /* XXX black? */ } +u_long +VGLGetXY(VGLBitmap *object, int x, int y) +{ + u_long color; + + VGLCheckSwitch(); + if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize) + return 0; + if (object->Type != MEMBUF) { + color = VGLMouseFreeze(x, y, 1, 1, 0x40000000); + if (color & 0x40000000) { + VGLMouseUnFreeze(); + return color & 0xffffff; + } + } + color = __VGLGetXY(object, x, y); + if (object->Type != MEMBUF) + VGLMouseUnFreeze(); + return color; +} + /* * 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, byte 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) { int offset; int len; int i, total = 0; byte b[4]; VGLCheckSwitch(); - VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); /* XXX */ + if (object->Type != MEMBUF) + VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); switch (object->Type) { case MEMBUF: case VIDBUF8: memset(object->Bitmap, (byte)color, object->VXsize*object->VYsize); break; case VIDBUF8S: for (offset = 0; offset < object->VXsize*object->VYsize; ) { VGLSetSegment(offset); len = min(object->VXsize*object->VYsize - offset, VGLAdpInfo.va_window_size); memset(object->Bitmap, (byte)color, len); offset += len; } break; case VIDBUF16: case VIDBUF24: case VIDBUF32: color2mem(color, b, object->PixelBytes); total = object->VXsize*object->VYsize*object->PixelBytes; for (i = 0; i < total; i += object->PixelBytes) bcopy(b, object->Bitmap + i, object->PixelBytes); break; case VIDBUF16S: case VIDBUF24S: case VIDBUF32S: color2mem(color, b, object->PixelBytes); total = object->VXsize*object->VYsize*object->PixelBytes; for (offset = 0; offset < total; ) { VGLSetSegment(offset); len = min(total - offset, VGLAdpInfo.va_window_size); for (i = 0; i < len; i += object->PixelBytes) bcopy(object->Bitmap + (offset + i) % VGLAdpInfo.va_window_size, b, object->PixelBytes); offset += len; } break; case VIDBUF8X: /* 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); break; case VIDBUF4: case VIDBUF4S: /* 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); break; } - VGLMouseUnFreeze(); + if (object->Type != MEMBUF) + VGLMouseUnFreeze(); } void VGLRestorePalette() { int i; 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; 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; 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) { 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 VGLSetBorder(byte color) { VGLCheckSwitch(); inb(0x3DA); outb(0x3C0,0x11); outb(0x3C0, color); inb(0x3DA); outb(0x3C0, 0x20); } void VGLBlankDisplay(int blank) { byte val; VGLCheckSwitch(); outb(0x3C4, 0x01); val = inb(0x3C5); outb(0x3C4, 0x01); outb(0x3C5, ((blank) ? (val |= 0x20) : (val &= 0xDF))); }