Date: Tue, 03 Sep 2019 14:07:42 -0000 From: Bruce Evans <bde@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346580 - head/lib/libvgl Message-ID: <201904221931.x3MJVGo6001317@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bde Date: Mon Apr 22 19:31:16 2019 New Revision: 346580 URL: https://svnweb.freebsd.org/changeset/base/346580 Log: Fix mouse cursor coloring in depths > 8 (previously, a hack that only worked right for white interiors and black borders was used). Advertise this by changing the default colors to a red interior and a white border (the same as the kernel default). Add undocumented env variables for changing these colors. Also change to the larger and better-shaped 16x10 cursor sometimes used in the kernel. The kernel choice is fancier, but libvgl is closer to supporting the larger cursors needed in newer modes. The (n)and-or logic for the cursor doesn't work right for more than 2 colors. The (n)and part only masks out all color bits for the pixel under the cursor when all bits are set in the And mask. With more complicated logic, the non-masked bits could be used to implement translucent cursors, but they actually just gave strange colors (especially in packed and planar modes where the bits are indirect through 1 or 2 palettes so it is hard to predict the final color). They also gave a bug for writing pixels under the cursor. The non-masked bits under the cursor were not combined in this case. Drop support for combining with bits under the cursor by making any nonzero value in the And mask mean all bits set. Convert the Or mask (which is represented as a half-initialized 256-color bitmap) to a fully initialized bitmap with the correct number of colors. The 256-color representation must be as in 3:3:2 direct mode iff the final bitmap has more than 256 colors. The conversion of colors is not very efficient, so convert at initialization time. Modified: head/lib/libvgl/bitmap.c head/lib/libvgl/mouse.c head/lib/libvgl/simple.c head/lib/libvgl/vgl.h Modified: head/lib/libvgl/bitmap.c ============================================================================== --- head/lib/libvgl/bitmap.c Mon Apr 22 19:24:21 2019 (r346579) +++ head/lib/libvgl/bitmap.c Mon Apr 22 19:31:16 2019 (r346580) @@ -274,3 +274,27 @@ VGLBitmapAllocateBits(VGLBitmap *object) return -1; return 0; } + +void +VGLBitmapCvt(VGLBitmap *src, VGLBitmap *dst) +{ + u_long color; + int dstpos, i, pb, size, srcpb, srcpos; + + size = src->VXsize * src->VYsize; + srcpb = src->PixelBytes; + if (srcpb <= 0) + srcpb = 1; + pb = dst->PixelBytes; + if (pb == srcpb) { + bcopy(src->Bitmap, dst->Bitmap, size * pb); + return; + } + if (srcpb != 1) + return; /* not supported */ + for (srcpos = dstpos = 0; srcpos < size; srcpos++) { + color = VGLrgb332ToNative(src->Bitmap[srcpos]); + for (i = 0; i < pb; i++, color >>= 8) + dst->Bitmap[dstpos++] = color; + } +} Modified: head/lib/libvgl/mouse.c ============================================================================== --- head/lib/libvgl/mouse.c Mon Apr 22 19:24:21 2019 (r346579) +++ head/lib/libvgl/mouse.c Mon Apr 22 19:31:16 2019 (r346580) @@ -39,7 +39,11 @@ __FBSDID("$FreeBSD$"); #include <sys/fbio.h> #include "vgl.h" -#define X 0xff +#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, @@ -49,34 +53,36 @@ static byte StdAndMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] 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, - 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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,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 = @@ -103,7 +109,7 @@ VGLMousePointerShow() VGLBitmap buffer = VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf); byte crtcidx, crtcval, gdcidx, gdcval; - int i, pos, pos1; + int pos; if (!VGLMouseVisible) { INTOFF(); @@ -118,12 +124,10 @@ VGLMousePointerShow() __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; - buffer.Bitmap[pos1] = (buffer.Bitmap[pos1] & - ~VGLMouseAndMask->Bitmap[pos]) | - VGLMouseOrMask->Bitmap[pos]; - } + if (VGLMouseAndMask->Bitmap[pos]) + bcopy(&VGLMouseOrMask->Bitmap[pos*VGLDisplay->PixelBytes], + &buffer.Bitmap[pos*VGLDisplay->PixelBytes], + VGLDisplay->PixelBytes); __VGLBitmapCopy(&buffer, 0, 0, VGLDisplay, VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) { @@ -216,8 +220,17 @@ VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask { if (VGLMouseShown == VGL_MOUSESHOW) VGLMousePointerHide(); + VGLMouseAndMask = AndMask; - VGLMouseOrMask = OrMask; + + 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(); } @@ -225,34 +238,42 @@ VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask void VGLMouseSetStdImage() { - if (VGLMouseShown == VGL_MOUSESHOW) - VGLMousePointerHide(); - VGLMouseAndMask = &VGLMouseStdAndMask; - VGLMouseOrMask = &VGLMouseStdOrMask; - if (VGLMouseShown == VGL_MOUSESHOW) - VGLMousePointerShow(); + VGLMouseSetImage(&VGLMouseStdAndMask, &VGLMouseStdOrMask); } int VGLMouseInit(int mode) { struct mouse_info mouseinfo; - int error, i, mask; + int andmask, border, error, i, interior; switch (VGLModeInfo.vi_mem_model) { case V_INFO_MM_PACKED: case V_INFO_MM_PLANAR: - mask = 0x0f; + andmask = 0x0f; + border = 0x0f; + interior = 0x04; break; case V_INFO_MM_VGAX: - mask = 0x3f; + andmask = 0x3f; + border = 0x3f; + interior = 0x24; break; default: - mask = 0xff; + andmask = 0xff; + border = BORDER; + interior = INTERIOR; break; } - for (i = 0; i < 256; i++) - VGLMouseStdOrMask.Bitmap[i] &= mask; + 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; Modified: head/lib/libvgl/simple.c ============================================================================== --- head/lib/libvgl/simple.c Mon Apr 22 19:24:21 2019 (r346579) +++ head/lib/libvgl/simple.c Mon Apr 22 19:31:16 2019 (r346580) @@ -513,6 +513,31 @@ VGLClear(VGLBitmap *object, u_long color) 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() { Modified: head/lib/libvgl/vgl.h ============================================================================== --- head/lib/libvgl/vgl.h Mon Apr 22 19:24:21 2019 (r346579) +++ head/lib/libvgl/vgl.h Mon Apr 22 19:31:16 2019 (r346580) @@ -112,6 +112,7 @@ int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, 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); @@ -144,6 +145,7 @@ void VGLFilledBox(VGLBitmap *object, int x1, int y1, i 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904221931.x3MJVGo6001317>