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.
This commit is contained in:
parent
7687707dd4
commit
a93ca07acd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346580
@ -274,3 +274,27 @@ VGLBitmapAllocateBits(VGLBitmap *object)
|
|||||||
return -1;
|
return -1;
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -39,7 +39,11 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/fbio.h>
|
#include <sys/fbio.h>
|
||||||
#include "vgl.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] = {
|
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,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,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,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,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,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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B,I,I,I,I,I,B,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,
|
B,I,I,I,I,I,I,B,0,0,0,0,0,0,0,0,
|
||||||
0,X,X,0,X,0,0,0,0,0,0,0,0,0,0,0,
|
B,I,I,I,I,I,I,I,B,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,0,
|
B,I,I,I,I,I,I,I,I,B,0,0,0,0,0,0,
|
||||||
0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,0,
|
B,I,I,I,I,I,B,B,B,B,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,
|
B,I,I,B,I,I,B,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,
|
B,I,B,0,B,I,I,B,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,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,0,0,0,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,0,0,0,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,0,0,0,0,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 X
|
||||||
|
#undef B
|
||||||
|
#undef I
|
||||||
static VGLBitmap VGLMouseStdAndMask =
|
static VGLBitmap VGLMouseStdAndMask =
|
||||||
VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask);
|
VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask);
|
||||||
static VGLBitmap VGLMouseStdOrMask =
|
static VGLBitmap VGLMouseStdOrMask =
|
||||||
@ -103,7 +109,7 @@ VGLMousePointerShow()
|
|||||||
VGLBitmap buffer =
|
VGLBitmap buffer =
|
||||||
VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf);
|
VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf);
|
||||||
byte crtcidx, crtcval, gdcidx, gdcval;
|
byte crtcidx, crtcval, gdcidx, gdcval;
|
||||||
int i, pos, pos1;
|
int pos;
|
||||||
|
|
||||||
if (!VGLMouseVisible) {
|
if (!VGLMouseVisible) {
|
||||||
INTOFF();
|
INTOFF();
|
||||||
@ -118,12 +124,10 @@ VGLMousePointerShow()
|
|||||||
__VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos,
|
__VGLBitmapCopy(&VGLVDisplay, VGLMouseXpos, VGLMouseYpos,
|
||||||
&buffer, 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
|
&buffer, 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
|
||||||
for (pos = 0; pos < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; pos++)
|
for (pos = 0; pos < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; pos++)
|
||||||
for (i = 0; i < VGLDisplay->PixelBytes; i++) {
|
if (VGLMouseAndMask->Bitmap[pos])
|
||||||
pos1 = pos * VGLDisplay->PixelBytes + i;
|
bcopy(&VGLMouseOrMask->Bitmap[pos*VGLDisplay->PixelBytes],
|
||||||
buffer.Bitmap[pos1] = (buffer.Bitmap[pos1] &
|
&buffer.Bitmap[pos*VGLDisplay->PixelBytes],
|
||||||
~VGLMouseAndMask->Bitmap[pos]) |
|
VGLDisplay->PixelBytes);
|
||||||
VGLMouseOrMask->Bitmap[pos];
|
|
||||||
}
|
|
||||||
__VGLBitmapCopy(&buffer, 0, 0, VGLDisplay,
|
__VGLBitmapCopy(&buffer, 0, 0, VGLDisplay,
|
||||||
VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
|
VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
|
||||||
if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
|
if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
|
||||||
@ -216,8 +220,17 @@ VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask)
|
|||||||
{
|
{
|
||||||
if (VGLMouseShown == VGL_MOUSESHOW)
|
if (VGLMouseShown == VGL_MOUSESHOW)
|
||||||
VGLMousePointerHide();
|
VGLMousePointerHide();
|
||||||
|
|
||||||
VGLMouseAndMask = AndMask;
|
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)
|
if (VGLMouseShown == VGL_MOUSESHOW)
|
||||||
VGLMousePointerShow();
|
VGLMousePointerShow();
|
||||||
}
|
}
|
||||||
@ -225,34 +238,42 @@ VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask)
|
|||||||
void
|
void
|
||||||
VGLMouseSetStdImage()
|
VGLMouseSetStdImage()
|
||||||
{
|
{
|
||||||
if (VGLMouseShown == VGL_MOUSESHOW)
|
VGLMouseSetImage(&VGLMouseStdAndMask, &VGLMouseStdOrMask);
|
||||||
VGLMousePointerHide();
|
|
||||||
VGLMouseAndMask = &VGLMouseStdAndMask;
|
|
||||||
VGLMouseOrMask = &VGLMouseStdOrMask;
|
|
||||||
if (VGLMouseShown == VGL_MOUSESHOW)
|
|
||||||
VGLMousePointerShow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
VGLMouseInit(int mode)
|
VGLMouseInit(int mode)
|
||||||
{
|
{
|
||||||
struct mouse_info mouseinfo;
|
struct mouse_info mouseinfo;
|
||||||
int error, i, mask;
|
int andmask, border, error, i, interior;
|
||||||
|
|
||||||
switch (VGLModeInfo.vi_mem_model) {
|
switch (VGLModeInfo.vi_mem_model) {
|
||||||
case V_INFO_MM_PACKED:
|
case V_INFO_MM_PACKED:
|
||||||
case V_INFO_MM_PLANAR:
|
case V_INFO_MM_PLANAR:
|
||||||
mask = 0x0f;
|
andmask = 0x0f;
|
||||||
|
border = 0x0f;
|
||||||
|
interior = 0x04;
|
||||||
break;
|
break;
|
||||||
case V_INFO_MM_VGAX:
|
case V_INFO_MM_VGAX:
|
||||||
mask = 0x3f;
|
andmask = 0x3f;
|
||||||
|
border = 0x3f;
|
||||||
|
interior = 0x24;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mask = 0xff;
|
andmask = 0xff;
|
||||||
|
border = BORDER;
|
||||||
|
interior = INTERIOR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (i = 0; i < 256; i++)
|
if (VGLModeInfo.vi_mode == M_BG640x480)
|
||||||
VGLMouseStdOrMask.Bitmap[i] &= mask;
|
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();
|
VGLMouseSetStdImage();
|
||||||
mouseinfo.operation = MOUSE_MODE;
|
mouseinfo.operation = MOUSE_MODE;
|
||||||
mouseinfo.u.mode.signal = SIGUSR2;
|
mouseinfo.u.mode.signal = SIGUSR2;
|
||||||
|
@ -513,6 +513,31 @@ VGLClear(VGLBitmap *object, u_long color)
|
|||||||
VGLMouseUnFreeze();
|
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
|
void
|
||||||
VGLRestorePalette()
|
VGLRestorePalette()
|
||||||
{
|
{
|
||||||
|
@ -112,6 +112,7 @@ int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx,
|
|||||||
VGLBitmap *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits);
|
VGLBitmap *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits);
|
||||||
void VGLBitmapDestroy(VGLBitmap *object);
|
void VGLBitmapDestroy(VGLBitmap *object);
|
||||||
int VGLBitmapAllocateBits(VGLBitmap *object);
|
int VGLBitmapAllocateBits(VGLBitmap *object);
|
||||||
|
void VGLBitmapCvt(VGLBitmap *src, VGLBitmap *dst);
|
||||||
/* keyboard.c */
|
/* keyboard.c */
|
||||||
int VGLKeyboardInit(int mode);
|
int VGLKeyboardInit(int mode);
|
||||||
void VGLKeyboardEnd(void);
|
void VGLKeyboardEnd(void);
|
||||||
@ -144,6 +145,7 @@ void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long colo
|
|||||||
void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, 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 VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color);
|
||||||
void VGLClear(VGLBitmap *object, u_long color);
|
void VGLClear(VGLBitmap *object, u_long color);
|
||||||
|
u_long VGLrgb332ToNative(byte c);
|
||||||
void VGLRestoreBlank(void);
|
void VGLRestoreBlank(void);
|
||||||
void VGLRestoreBorder(void);
|
void VGLRestoreBorder(void);
|
||||||
void VGLRestorePalette(void);
|
void VGLRestorePalette(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user