From owner-svn-src-head@freebsd.org Tue Sep 3 14:07:42 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9B357DDA3F; Tue, 3 Sep 2019 14:07:24 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N80W3xZfz4QYM; Tue, 3 Sep 2019 14:07:23 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id C910E1B560; Tue, 3 Sep 2019 14:06:37 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id A947A1582C; Mon, 22 Apr 2019 19:31:21 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 606A273186; Mon, 22 Apr 2019 19:31:21 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 0C3E4157F6; Mon, 22 Apr 2019 19:31:21 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 0DAE0157E7 for ; Mon, 22 Apr 2019 19:31:18 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B604173168; Mon, 22 Apr 2019 19:31:17 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 909F819883; Mon, 22 Apr 2019 19:31:17 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3MJVH4X001321; Mon, 22 Apr 2019 19:31:17 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3MJVGo6001317; Mon, 22 Apr 2019 19:31:16 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201904221931.x3MJVGo6001317@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346580 - head/lib/libvgl X-SVN-Group: head X-SVN-Commit-Author: bde X-SVN-Commit-Paths: head/lib/libvgl X-SVN-Commit-Revision: 346580 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 606A273186 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:07:42 -0000 X-Original-Date: Mon, 22 Apr 2019 19:31:16 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:07:42 -0000 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 #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 StdAndM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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, + 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 = @@ -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);