From owner-svn-src-all@freebsd.org Tue Sep 3 14:08:22 2019 Return-Path: Delivered-To: svn-src-all@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 9EBE2DDB52; Tue, 3 Sep 2019 14:07:27 +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 46N80b1wwZz4Qcf; Tue, 3 Sep 2019 14:07:27 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id C82B71B66F; Tue, 3 Sep 2019 14:06:40 +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 E68881A378; Wed, 24 Apr 2019 15:35:33 +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 335136B4CA; Wed, 24 Apr 2019 15:35:33 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 110B91A323; Wed, 24 Apr 2019 15:35:33 +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 9D62C1A321 for ; Wed, 24 Apr 2019 15:35:30 +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 682CF6B4C7; Wed, 24 Apr 2019 15:35:30 +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 4198DE35E; Wed, 24 Apr 2019 15:35:30 +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 x3OFZUBA013801; Wed, 24 Apr 2019 15:35:30 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3OFZTWe013796; Wed, 24 Apr 2019 15:35:29 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201904241535.x3OFZTWe013796@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: r346639 - head/lib/libvgl X-SVN-Group: head X-SVN-Commit-Author: bde X-SVN-Commit-Paths: head/lib/libvgl X-SVN-Commit-Revision: 346639 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: 335136B4CA X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.977,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-all@freebsd.org X-Mailman-Version: 2.1.29 List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:08:22 -0000 X-Original-Date: Wed, 24 Apr 2019 15:35:29 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:08:22 -0000 Author: bde Date: Wed Apr 24 15:35:29 2019 New Revision: 346639 URL: https://svnweb.freebsd.org/changeset/base/346639 Log: Refactor mouse freezing and fix some minor bugs. VGLMouseFreeze() now only defers mouse signals and leaves it to higher levels to hide and unhide the mouse cursor if necessary. (It is never necessary, but is done to simplify the implementation. It is slow and flashes the cursor. It is still done for copying bitmaps and clearing.) VGLMouseUnFreeze() now only undoes 1 level of freezing. Its old optimization to reduce mouse redrawing is too hard to do with unhiding in higher levels, and its undoing of multiple levels was a historical mistake. VGLMouseOverlap() determines if a region overlaps the (full) mouse region. VGLMouseFreezeXY() is the freezing and a precise overlap check combined for the special case of writing a single pixel. This is the single-pixel case of the old VGLMouseFreeze() with cleanups. Fixes: - check in more cases that the application didn't pass an invalid VIDBUF - check for errors from copying a bitmap to the shadow buffer - freeze the mouse before writing to the shadow buffer in all cases. This was not done for the case of writing a single pixel (there was a race) - don't spell the #defined values for VGLMouseShown as 0, 1 or boolean. 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 Wed Apr 24 15:02:59 2019 (r346638) +++ head/lib/libvgl/bitmap.c Wed Apr 24 15:35:29 2019 (r346639) @@ -214,23 +214,36 @@ int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight) { - int error; + int error, mouseoverlap; if (src == VGLDisplay) src = &VGLVDisplay; if (src->Type != MEMBUF) return -1; /* invalid */ if (dst == VGLDisplay) { - VGLMouseFreeze(dstx, dsty, width, hight, 0); - __VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty, width, hight); + VGLMouseFreeze(); + mouseoverlap = VGLMouseOverlap(dstx, dsty, width, hight); + if (mouseoverlap) + VGLMousePointerHide(); + error = __VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty, + width, hight); + if (error != 0) { + if (mouseoverlap) + VGLMousePointerShow(); + VGLMouseUnFreeze(); + return error; + } 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 (dst == VGLDisplay) + if (dst == VGLDisplay) { + if (mouseoverlap) + VGLMousePointerShow(); VGLMouseUnFreeze(); + } return error; } Modified: head/lib/libvgl/mouse.c ============================================================================== --- head/lib/libvgl/mouse.c Wed Apr 24 15:02:59 2019 (r346638) +++ head/lib/libvgl/mouse.c Wed Apr 24 15:35:29 2019 (r346639) @@ -89,7 +89,7 @@ static VGLBitmap VGLMouseStdOrMask = VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask); static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask; static int VGLMouseVisible = 0; -static int VGLMouseShown = 0; +static int VGLMouseShown = VGL_MOUSEHIDE; static int VGLMouseXpos = 0; static int VGLMouseYpos = 0; static int VGLMouseButtons = 0; @@ -316,48 +316,47 @@ VGLMouseStatus(int *x, int *y, char *buttons) return VGLMouseShown; } -int -VGLMouseFreeze(int x, int y, int width, int hight, u_long color) +void +VGLMouseFreeze(void) { - INTOFF(); - if (width > 1 || hight > 1 || (color & 0xc0000000) == 0) { /* bitmap */ - if (VGLMouseShown == 1) { - int overlap; + INTOFF(); +} - 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) { - if (color & 0x80000000) { /* Set */ - if (VGLMouseAndMask->Bitmap - [(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) { - return 1; - } - } - } - } +int +VGLMouseFreezeXY(int x, int y) +{ + INTOFF(); + if (VGLMouseShown != VGL_MOUSESHOW) + return 0; + if (x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE && + y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE && + VGLMouseAndMask->Bitmap[(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) + return 1; return 0; } +int +VGLMouseOverlap(int x, int y, int width, int hight) +{ + int overlap; + + if (VGLMouseShown != VGL_MOUSESHOW) + return 0; + if (x > VGLMouseXpos) + overlap = (VGLMouseXpos + MOUSE_IMG_SIZE) - x; + else + overlap = (x + width) - VGLMouseXpos; + if (overlap <= 0) + return 0; + if (y > VGLMouseYpos) + overlap = (VGLMouseYpos + MOUSE_IMG_SIZE) - y; + else + overlap = (y + hight) - VGLMouseYpos; + return overlap > 0; +} + void VGLMouseUnFreeze() { - if (VGLMouseShown == VGL_MOUSESHOW && !VGLMouseVisible && !VGLMintpending) - VGLMousePointerShow(); - while (VGLMsuppressint) - INTON(); + INTON(); } Modified: head/lib/libvgl/simple.c ============================================================================== --- head/lib/libvgl/simple.c Wed Apr 24 15:02:59 2019 (r346638) +++ head/lib/libvgl/simple.c Wed Apr 24 15:35:29 2019 (r346639) @@ -51,14 +51,18 @@ static byte VGLSavePaletteBlue[256]; void VGLSetXY(VGLBitmap *object, int x, int y, u_long color) { - int offset; + int offset, undermouse; VGLCheckSwitch(); if (x>=0 && xVXsize && y>=0 && yVYsize) { - if (object == VGLDisplay) + if (object == VGLDisplay) { + undermouse = VGLMouseFreezeXY(x, y); VGLSetXY(&VGLVDisplay, x, y, color); - if (object->Type == MEMBUF || - !VGLMouseFreeze(x, y, 1, 1, 0x80000000 | color)) { + } else if (object->Type != MEMBUF) + return; /* invalid */ + else + undermouse = 0; + if (!undermouse) { offset = (y * object->VXsize + x) * object->PixelBytes; switch (object->Type) { case VIDBUF8S: @@ -106,7 +110,7 @@ set_planar: object->Bitmap[offset] |= (byte)color; } } - if (object->Type != MEMBUF) + if (object == VGLDisplay) VGLMouseUnFreeze(); } } @@ -143,7 +147,7 @@ VGLGetXY(VGLBitmap *object, int x, int y) return 0; if (object == VGLDisplay) object = &VGLVDisplay; - if (object->Type != MEMBUF) + else if (object->Type != MEMBUF) return 0; /* invalid */ return __VGLGetXY(object, x, y); } @@ -449,13 +453,14 @@ void VGLClear(VGLBitmap *object, u_long color) { VGLBitmap src; - int offset; - int len; - int i; + int i, len, mouseoverlap, offset; VGLCheckSwitch(); if (object == VGLDisplay) { - VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); + VGLMouseFreeze(); + mouseoverlap = VGLMouseOverlap(0, 0, object->Xsize, object->Ysize); + if (mouseoverlap) + VGLMousePointerHide(); VGLClear(&VGLVDisplay, color); } else if (object->Type != MEMBUF) return; /* invalid */ @@ -509,8 +514,11 @@ VGLClear(VGLBitmap *object, u_long color) outb(0x3ce, 0x05); outb(0x3cf, 0x00); break; } - if (object == VGLDisplay) + if (object == VGLDisplay) { + if (mouseoverlap) + VGLMousePointerShow(); VGLMouseUnFreeze(); + } } static inline u_long Modified: head/lib/libvgl/vgl.h ============================================================================== --- head/lib/libvgl/vgl.h Wed Apr 24 15:02:59 2019 (r346638) +++ head/lib/libvgl/vgl.h Wed Apr 24 15:35:29 2019 (r346639) @@ -134,7 +134,9 @@ void VGLMouseSetStdImage(void); int VGLMouseInit(int mode); void VGLMouseRestore(void); int VGLMouseStatus(int *x, int *y, char *buttons); -int VGLMouseFreeze(int x, int y, int width, int hight, u_long color); +void VGLMouseFreeze(void); +int VGLMouseFreezeXY(int x, int y); +int VGLMouseOverlap(int x, int y, int width, int hight); void VGLMouseUnFreeze(void); /* simple.c */ void VGLSetXY(VGLBitmap *object, int x, int y, u_long color);