From e53fbbe661354620cfc25eb36e159cfa4b9dcf11 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sat, 8 Apr 2017 08:24:25 +0000 Subject: [PATCH] Fix removal of the keyboard cursor image in text mode, especially in the vga renderer. Removal used stale attributes and didn't try to merge with the current attribute for cut marking, so special rendering of cut marking was lost in many cases. The gfb renderer is too broken to support special rendering of cut marking at all, so this change is supposed to be just a style fix for it. Remove all traces of the saveunder method which was used to implement this bug. Fix drawing of the cursor image in text mode, only in the vga renderer. This used a stale attribute from the frame buffer instead of from the saveunder, but did merge with the current attribute for cut marking so it caused less obvious bugs (subtle misrendering for the character under the cursor). The saveunder method may be good in simpler drivers, but in syscons the 'under' is already saved in a better way in the vtb. Just redraw it from there, with visible complications for cut marking and invisible complications for mouse cursors. Almost all drawing requests are passed a flag 'flip' which currently means to flip to reverse video for characters in the cut marking region, but should mean that the the characters are in the cut marking regions so should be rendered specially, preferably using something better than reverse video. The gfb renderer always ignores this flag. The vga renderer ignored it for removal of the text cursor -- the saveunder gave the stale rendering at the time the cursor was drawn. Mouse cursors need even more complicated methods. They are handled by drawing them last and removing them first. Removing them usually redraws many other characters with the correct cut marking (but transiently loses the keyboard cursor, which is redrawn soon). This tended to hide the saveunder bug for forward motions of the keyboard cursor. But slow backward motions of the keyboard cursor always lost the cut marking, and fast backwards motions lost in for about 4 in every 5 characters, depending on races with the scrn_update() timeout handler. This is because the forward motions are usually into the region redrawn for the mouse cursor, while backwards motions rarely are. Text cursor drawing in the vga renderer used also used a possibly-stale copy of the character and its attribute. The vga render has the "optimization" of sometimes reading characters from the screen instead of from the vtb (this was not so good even in 1990 when main memory was only a few times faster than video RAM). Due to care in update orders, the character is never stale, but its attribute might be (just the cut marking part, again due to care in order). gfb doesn't have the scp->scr pointer used for the "optimization", and vga only uses this pointer for text mode. So most cases have to refresh from the vtb, and we can be sure that the ordering of vtb updates and drawing is as required for this to work. --- sys/dev/syscons/scgfbrndr.c | 6 ++---- sys/dev/syscons/scvgarndr.c | 10 ++++------ sys/dev/syscons/syscons.h | 2 -- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/sys/dev/syscons/scgfbrndr.c b/sys/dev/syscons/scgfbrndr.c index 20679b70d452..a17abe5a6088 100644 --- a/sys/dev/syscons/scgfbrndr.c +++ b/sys/dev/syscons/scgfbrndr.c @@ -271,13 +271,11 @@ gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip) c = sc_vtb_getc(&scp->vtb, at); vidd_putc(scp->sc->adp, at, c, (a >> 4) | ((a & 0xf) << 4)); - scp->cursor_saveunder_attr = a; - scp->cursor_saveunder_char = c; } else { if (scp->status & VR_CURSOR_ON) vidd_putc(scp->sc->adp, at, - scp->cursor_saveunder_char, - scp->cursor_saveunder_attr); + sc_vtb_getc(&scp->vtb, at), + sc_vtb_geta(&scp->vtb, at) >> 8); scp->status &= ~VR_CURSOR_ON; } } diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c index 2d2651746004..b56f59b00964 100644 --- a/sys/dev/syscons/scvgarndr.c +++ b/sys/dev/syscons/scvgarndr.c @@ -294,8 +294,6 @@ draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip) sc_softc_t *sc; sc = scp->sc; - scp->cursor_saveunder_char = c; - scp->cursor_saveunder_attr = a; #ifndef SC_NO_FONT_LOADING if (scp->curs_attr.flags & CONS_CHAR_CURSOR) { @@ -372,18 +370,18 @@ vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip) if (on) { scp->status |= VR_CURSOR_ON; draw_txtcharcursor(scp, at, - sc_vtb_getc(&scp->scr, at), - sc_vtb_geta(&scp->scr, at), + sc_vtb_getc(&scp->vtb, at), + sc_vtb_geta(&scp->vtb, at), flip); } else { - cursor_attr = scp->cursor_saveunder_attr; + cursor_attr = sc_vtb_geta(&scp->vtb, at); if (flip) cursor_attr = (cursor_attr & 0x8800) | ((cursor_attr & 0x7000) >> 4) | ((cursor_attr & 0x0700) << 4); if (scp->status & VR_CURSOR_ON) sc_vtb_putc(&scp->scr, at, - scp->cursor_saveunder_char, + sc_vtb_getc(&scp->vtb, at), cursor_attr); scp->status &= ~VR_CURSOR_ON; } diff --git a/sys/dev/syscons/syscons.h b/sys/dev/syscons/syscons.h index 2254014c0632..ac52d6e8627b 100644 --- a/sys/dev/syscons/syscons.h +++ b/sys/dev/syscons/syscons.h @@ -312,8 +312,6 @@ typedef struct scr_stat { int cursor_pos; /* cursor buffer position */ int cursor_oldpos; /* cursor old buffer position */ - u_short cursor_saveunder_char; /* saved char under cursor */ - u_short cursor_saveunder_attr; /* saved attr under cursor */ struct cursor_attr dflt_curs_attr; struct cursor_attr curr_curs_attr; struct cursor_attr curs_attr;