diff --git a/lib/libvgl/bitmap.c b/lib/libvgl/bitmap.c index 76e206ac56c0..9c21914d36ce 100644 --- a/lib/libvgl/bitmap.c +++ b/lib/libvgl/bitmap.c @@ -163,108 +163,6 @@ WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line) } } -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; posPixelBytes; - 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 MEMBUF: - case VIDBUF8: - 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) @@ -304,37 +202,10 @@ __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, yextra = hight - 1; ystep = -1; } - if (src->Type == MEMBUF) { - for (srcline = srcy + yextra, dstline = dsty + yextra; srcline != yend; - srcline += ystep, dstline += ystep) { - WriteVerticalLine(dst, dstx, dstline, width, - src->Bitmap+(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 + yextra, dstline = dsty + yextra; srcline != yend; - srcline += ystep, dstline += ystep) { - ReadVerticalLine(src, srcx, srcline, width, p); - WriteVerticalLine(dst, dstx, dstline, width, p); - } - if (width * src->PixelBytes > sizeof(buffer)) - free(p); + for (srcline = srcy + yextra, dstline = dsty + yextra; srcline != yend; + srcline += ystep, dstline += ystep) { + WriteVerticalLine(dst, dstx, dstline, width, + src->Bitmap+(srcline*src->VXsize+srcx)*dst->PixelBytes); } return 0; } @@ -345,12 +216,20 @@ VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, { int error; + if (src == VGLDisplay) + src = &VGLVDisplay; if (src->Type != MEMBUF) - VGLMouseFreeze(srcx, srcy, width, hight, 0); - if (dst->Type != MEMBUF) + return -1; /* invalid */ + if (dst == VGLDisplay) { VGLMouseFreeze(dstx, dsty, width, hight, 0); + __VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty, width, hight); + src = &VGLVDisplay; + srcx = dstx; + srcy = dsty; + } else if (dst->Type != MEMBUF) + return -1; /* invalid */ error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, hight); - if (src->Type != MEMBUF || dst->Type != MEMBUF) + if (dst == VGLDisplay) VGLMouseUnFreeze(); return error; } diff --git a/lib/libvgl/main.c b/lib/libvgl/main.c index 6a5d987ed92e..354e45bc6d51 100644 --- a/lib/libvgl/main.c +++ b/lib/libvgl/main.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #define max(x, y) (((x) > (y)) ? (x) : (y)) VGLBitmap *VGLDisplay; +VGLBitmap VGLVDisplay; video_info_t VGLModeInfo; video_adapter_info_t VGLAdpInfo; byte *VGLBuf; @@ -334,6 +335,13 @@ VGLInit(int mode) } 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 @@ -365,10 +373,6 @@ VGLCheckSwitch() exit(0); } while (VGLSwitchPending) { - unsigned int offset; - unsigned int len; - int i; - VGLSwitchPending = 0; if (VGLOnDisplay) { if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) @@ -440,98 +444,12 @@ VGLCheckSwitch() VGLRestoreBorder(); VGLMouseRestore(); VGLPanScreen(VGLDisplay, VGLDisplay->Xorigin, VGLDisplay->Yorigin); - switch (VGLDisplay->Type) { - case VIDBUF4S: - outb(0x3c6, 0xff); - outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ - outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ - for (offset = 0; offset < VGLBufSize/VGLModeInfo.vi_planes; - offset += len) { - VGLSetSegment(offset); - len = min(VGLBufSize/VGLModeInfo.vi_planes - offset, - VGLAdpInfo.va_window_size); - for (i = 0; i < VGLModeInfo.vi_planes; i++) { - outb(0x3c4, 0x02); - outb(0x3c5, 0x01<VXsize, VGLDisplay->VYsize); VGLRestorePalette(); ioctl(0, VT_RELDISP, VT_ACKACQ); } else { - switch (VGLDisplay->Type) { - case VIDBUF4S: - for (offset = 0; offset < VGLBufSize/VGLModeInfo.vi_planes; - offset += len) { - VGLSetSegment(offset); - len = min(VGLBufSize/VGLModeInfo.vi_planes - offset, - VGLAdpInfo.va_window_size); - for (i = 0; i < VGLModeInfo.vi_planes; i++) { - outb(0x3ce, 0x04); - outb(0x3cf, i); - bcopy(VGLMem, &VGLBuf[i*VGLBufSize/VGLModeInfo.vi_planes + offset], - len); - } - } - break; - case VIDBUF4: - case VIDBUF8X: - /* - * NOTE: the saved buffer is NOT in the MEMBUF format which - * the ordinary memory bitmap object is stored in. XXX - */ - for (i = 0; i < VGLModeInfo.vi_planes; i++) { - outb(0x3ce, 0x04); - outb(0x3cf, i); - bcopy(VGLMem, &VGLBuf[i*VGLAdpInfo.va_window_size], - VGLAdpInfo.va_window_size); - } - break; - case VIDBUF8: - case VIDBUF8S: - case VIDBUF16: - case VIDBUF16S: - case VIDBUF24: - case VIDBUF24S: - case VIDBUF32: - case VIDBUF32S: - for (offset = 0; offset < VGLBufSize; offset += len) { - VGLSetSegment(offset); - len = min(VGLBufSize - offset, VGLAdpInfo.va_window_size); - bcopy(VGLMem, &VGLBuf[offset], len); - } - break; - } VGLMem = MAP_FAILED; munmap(VGLDisplay->Bitmap, VGLAdpInfo.va_window_size); ioctl(0, VGLOldMode, 0); diff --git a/lib/libvgl/mouse.c b/lib/libvgl/mouse.c index bee63f3c94dd..e4dfef04f5cb 100644 --- a/lib/libvgl/mouse.c +++ b/lib/libvgl/mouse.c @@ -82,9 +82,6 @@ static VGLBitmap VGLMouseStdAndMask = 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 VGLMouseShown = 0; static int VGLMouseXpos = 0; @@ -117,10 +114,9 @@ VGLMousePointerShow() 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); + buffer.PixelBytes = VGLDisplay->PixelBytes; + __VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos, + &buffer, 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); for (pos = 0; pos < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; pos++) for (i = 0; i < VGLDisplay->PixelBytes; i++) { pos1 = pos * VGLDisplay->PixelBytes + i; @@ -154,8 +150,8 @@ VGLMousePointerHide() gdcidx = inb(0x3ce); gdcval = inb(0x3cf); } - __VGLBitmapCopy(&VGLMouseSave, 0, 0, VGLDisplay, - VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); + __VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos, VGLDisplay, + VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) { outb(0x3c4, crtcidx); outb(0x3c5, crtcval); @@ -302,8 +298,6 @@ VGLMouseStatus(int *x, int *y, char *buttons) int VGLMouseFreeze(int x, int y, int width, int hight, u_long color) { - int i, xstride, ystride; - INTOFF(); if (width > 1 || hight > 1 || (color & 0xc0000000) == 0) { /* bitmap */ if (VGLMouseShown == 1) { @@ -327,20 +321,7 @@ VGLMouseFreeze(int x, int y, int width, int hight, u_long color) if (VGLMouseShown && x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE && y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE) { - xstride = VGLDisplay->PixelBytes; - ystride = MOUSE_IMG_SIZE * xstride; - 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 (color & 0x80000000) { /* Set */ if (VGLMouseAndMask->Bitmap [(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) { return 1; diff --git a/lib/libvgl/simple.c b/lib/libvgl/simple.c index 73496c0a783d..d59893e721fd 100644 --- a/lib/libvgl/simple.c +++ b/lib/libvgl/simple.c @@ -55,6 +55,8 @@ VGLSetXY(VGLBitmap *object, int x, int y, u_long color) VGLCheckSwitch(); if (x>=0 && xVXsize && y>=0 && yVYsize) { + if (object == VGLDisplay) + VGLSetXY(&VGLVDisplay, x, y, color); if (object->Type == MEMBUF || !VGLMouseFreeze(x, y, 1, 1, 0x80000000 | color)) { offset = (y * object->VXsize + x) * object->PixelBytes; @@ -113,78 +115,37 @@ static u_long __VGLGetXY(VGLBitmap *object, int x, int y) { int offset; - int i; u_long color; - byte mask; offset = (y * object->VXsize + x) * object->PixelBytes; - switch (object->Type) { - case VIDBUF8S: - case VIDBUF16S: - case VIDBUF24S: - case VIDBUF32S: - offset = VGLSetSegment(offset); - /* FALLTHROUGH */ - case MEMBUF: - case VIDBUF8: - case VIDBUF16: - case VIDBUF24: - case VIDBUF32: - 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); - } - break; - 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; + 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; /* XXX black? */ + return 0; /* invalid */ } 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 == VGLDisplay) + object = &VGLVDisplay; if (object->Type != MEMBUF) - VGLMouseUnFreeze(); - return color; + return 0; /* invalid */ + return __VGLGetXY(object, x, y); } /* @@ -493,8 +454,11 @@ VGLClear(VGLBitmap *object, u_long color) int i; VGLCheckSwitch(); - if (object->Type != MEMBUF) + if (object == VGLDisplay) { VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); + VGLClear(&VGLVDisplay, color); + } else if (object->Type != MEMBUF) + return; /* invalid */ switch (object->Type) { case MEMBUF: case VIDBUF8: @@ -545,7 +509,7 @@ VGLClear(VGLBitmap *object, u_long color) outb(0x3ce, 0x05); outb(0x3cf, 0x00); break; } - if (object->Type != MEMBUF) + if (object == VGLDisplay) VGLMouseUnFreeze(); } diff --git a/lib/libvgl/vgl.h b/lib/libvgl/vgl.h index 106d9a79956d..cd7717d8773e 100644 --- a/lib/libvgl/vgl.h +++ b/lib/libvgl/vgl.h @@ -100,6 +100,7 @@ typedef struct VGLObject { extern video_adapter_info_t VGLAdpInfo; extern video_info_t VGLModeInfo; extern VGLBitmap *VGLDisplay; +extern VGLBitmap VGLVDisplay; extern byte *VGLBuf; /*