Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses * Don't redraw the background if the new backg...



details:   https://anonhg.NetBSD.org/src/rev/918f69bc402f
branches:  trunk
changeset: 365909:918f69bc402f
user:      blymn <blymn%NetBSD.org@localhost>
date:      Tue May 03 07:25:34 2022 +0000

description:
* Don't redraw the background if the new background character is the
   same as the old one.  This prevents excessive redraws in some
   applications.

 * Fix bug introduced when wbkgrndset was fixed, we cannot blindly
   replace any instance of the old background character with the new one
   because some of those characters were put there by the application
   leading to display corruption.  So flag characters as background when
   they are erased and only update the flagged characters when setting
   the background.

diffstat:

 lib/libcurses/add_wchstr.c     |   6 ++++--
 lib/libcurses/addbytes.c       |  11 ++++++++---
 lib/libcurses/background.c     |  30 ++++++++++++++++--------------
 lib/libcurses/border.c         |  16 ++++++++++++++--
 lib/libcurses/clrtobot.c       |   5 +++--
 lib/libcurses/curses.c         |   6 +++---
 lib/libcurses/curses_private.h |   8 +++++---
 lib/libcurses/delch.c          |   8 +++++---
 lib/libcurses/erase.c          |   5 +++--
 lib/libcurses/newwin.c         |   5 +++--
 lib/libcurses/refresh.c        |  12 ++++++------
 11 files changed, 70 insertions(+), 42 deletions(-)

diffs (truncated from 511 to 300 lines):

diff -r 08e9d2cba301 -r 918f69bc402f lib/libcurses/add_wchstr.c
--- a/lib/libcurses/add_wchstr.c        Tue May 03 00:29:23 2022 +0000
+++ b/lib/libcurses/add_wchstr.c        Tue May 03 07:25:34 2022 +0000
@@ -1,4 +1,4 @@
-/*   $NetBSD: add_wchstr.c,v 1.12 2022/04/12 07:03:04 blymn Exp $ */
+/*   $NetBSD: add_wchstr.c,v 1.13 2022/05/03 07:25:34 blymn Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: add_wchstr.c,v 1.12 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: add_wchstr.c,v 1.13 2022/05/03 07:25:34 blymn Exp $");
 #endif                         /* not lint */
 
 #include <stdlib.h>
@@ -210,6 +210,7 @@
                                            == ERR)
                                                return ERR;
                                        lp->attr = win->battr;
+                                       lp->cflags |= CA_BACKGROUND;
                                        (*lp).wcols = 1;
                                        lp++, ex++;
                                }
@@ -229,6 +230,7 @@
                        }
                        lp->ch = chp->vals[0];
                        lp->attr = chp->attributes & WA_ATTRIBUTES;
+                       lp->cflags &= ~CA_BACKGROUND;
                        (*lp).wcols = cw;
                        if (chp->elements > 1) {
                                for (i = 1; i < chp->elements; i++) {
diff -r 08e9d2cba301 -r 918f69bc402f lib/libcurses/addbytes.c
--- a/lib/libcurses/addbytes.c  Tue May 03 00:29:23 2022 +0000
+++ b/lib/libcurses/addbytes.c  Tue May 03 07:25:34 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: addbytes.c,v 1.62 2022/04/12 07:03:04 blymn Exp $      */
+/*     $NetBSD: addbytes.c,v 1.63 2022/05/03 07:25:34 blymn Exp $      */
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: addbytes.c,v 1.62 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: addbytes.c,v 1.63 2022/05/03 07:25:34 blymn Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -311,6 +311,8 @@
 #endif
        }
 
+       (*lp)->line[*x].cflags &= ~ CA_BACKGROUND;
+
        if (attributes & __COLOR)
                (*lp)->line[*x].attr =
                        attributes | (win->battr & ~__COLOR);
@@ -449,6 +451,7 @@
                            *y, sx);
                        tp = &win->alines[*y]->line[sx];
                        tp->ch = win->bch;
+                       tp->cflags |= CA_BACKGROUND;
                        if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
                                return ERR;
 
@@ -513,6 +516,7 @@
        }
 
        lp->ch = wch->vals[0];
+       lp->cflags &= ~CA_BACKGROUND;
 
        attributes = (win->wattr | wch->attributes)
                & (WA_ATTRIBUTES & ~__COLOR);
@@ -559,7 +563,7 @@
                tp->ch = wch->vals[0];
                tp->attr = lp->attr & WA_ATTRIBUTES;
                /* Mark as "continuation" cell */
-               tp->wflags |= WCA_CONTINUATION;
+               tp->cflags |= CA_CONTINUATION;
        }
 
 
@@ -596,6 +600,7 @@
                                    "remaining of current char (%d,%d)nn",
                                    *y, ex);
                                tp->ch = win->bch;
+                               tp->cflags |= CA_BACKGROUND;
                                if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
                                        return ERR;
                                tp->attr = win->battr;
diff -r 08e9d2cba301 -r 918f69bc402f lib/libcurses/background.c
--- a/lib/libcurses/background.c        Tue May 03 00:29:23 2022 +0000
+++ b/lib/libcurses/background.c        Tue May 03 07:25:34 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: background.c,v 1.30 2022/04/19 22:26:57 blymn Exp $    */
+/*     $NetBSD: background.c,v 1.31 2022/05/03 07:25:34 blymn Exp $    */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: background.c,v 1.30 2022/04/19 22:26:57 blymn Exp $");
+__RCSID("$NetBSD: background.c,v 1.31 2022/05/03 07:25:34 blymn Exp $");
 #endif                         /* not lint */
 
 #include <stdlib.h>
@@ -87,12 +87,10 @@
 int
 wbkgd(WINDOW *win, chtype ch)
 {
-       chtype obch;
        int y, x;
 
        __CTRACE(__CTRACE_ATTR, "wbkgd: (%p), '%s', %08x\n",
            win, unctrl(ch & __CHARTEXT), ch & __ATTRIBUTES);
-       obch = win->bch;
        wbkgdset(win, ch);
 
        for (y = 0; y < win->maxy; y++) {
@@ -100,7 +98,7 @@
                        __LDATA *cp = &win->alines[y]->line[x];
 
                        /* Update/switch background characters */
-                       if (cp->ch == obch)
+                       if (cp->cflags & CA_BACKGROUND)
                                cp->ch = win->bch;
 
                        /* Update/merge attributes */
@@ -174,7 +172,7 @@
        /* get a copy of the old background, we will need it. */
        obkgrnd.ch = win->bch;
        obkgrnd.attr = win->battr;
-       obkgrnd.wflags = 0;
+       obkgrnd.cflags |= CA_BACKGROUND;
        obkgrnd.wcols = win->wcols;
        obkgrnd.nsp = NULL;
        _cursesi_copy_nsp(win->bnsp, &obkgrnd);
@@ -223,22 +221,26 @@
        win->battr = battr;
        win->wcols = 1;
 
+       nbkgrnd.ch = win->bch;
+       nbkgrnd.attr = win->battr;
+       nbkgrnd.cflags |= CA_BACKGROUND;
+       nbkgrnd.wcols = win->wcols;
+       nbkgrnd.nsp = NULL;
+       _cursesi_copy_nsp(win->bnsp, &nbkgrnd);
+
+       /* if the background is already this char then skip updating */
+       if (_cursesi_celleq(&obkgrnd, &nbkgrnd))
+               return;
+
        /*
         * Now do the dirty work of updating all the locations
         * that have the old background character with the new.
         */
 
-       nbkgrnd.ch = win->bch;
-       nbkgrnd.attr = win->battr;
-       nbkgrnd.wflags = 0;
-       nbkgrnd.wcols = win->wcols;
-       nbkgrnd.nsp = NULL;
-       _cursesi_copy_nsp(win->bnsp, &nbkgrnd);
-
        for (wy = 0; wy < win->maxy; wy++) {
                wlp = win->alines[wy];
                for (wx = 0; wx < win->maxx; wx++) {
-                       if (_cursesi_celleq(&obkgrnd, &wlp->line[wx])) {
+                       if (wlp->line[wx].cflags & CA_BACKGROUND) {
                                _cursesi_copy_wchar(&nbkgrnd, &wlp->line[wx]);
                        }
                }
diff -r 08e9d2cba301 -r 918f69bc402f lib/libcurses/border.c
--- a/lib/libcurses/border.c    Tue May 03 00:29:23 2022 +0000
+++ b/lib/libcurses/border.c    Tue May 03 07:25:34 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: border.c,v 1.23 2022/04/12 07:03:04 blymn Exp $        */
+/*     $NetBSD: border.c,v 1.24 2022/05/03 07:25:34 blymn Exp $        */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: border.c,v 1.23 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: border.c,v 1.24 2022/05/03 07:25:34 blymn Exp $");
 #endif                         /* not lint */
 
 #include <stdlib.h>
@@ -301,6 +301,7 @@
                        cw = 1;
                for ( j = 0; j < cw; j++ ) {
                        win->alines[i]->line[j].ch = left.vals[0];
+                       win->alines[i]->line[j].cflags &= ~CA_BACKGROUND;
                        win->alines[i]->line[j].attr = left.attributes;
                        np = win->alines[i]->line[j].nsp;
                        if (np) {
@@ -332,6 +333,7 @@
                        __CTRACE(__CTRACE_INPUT,
                            "wborder_set: clean out partial char[%d]", j);
                        win->alines[i]->line[j].ch = win->bch;
+                       win->alines[i]->line[j].cflags |= CA_BACKGROUND;
                        if (_cursesi_copy_nsp(win->bnsp,
                                              &win->alines[i]->line[j]) == ERR)
                                return ERR;
@@ -344,6 +346,7 @@
                pcw = win->alines[i]->line[endx - cw].wcols;
                for ( j = endx - cw + 1; j <= endx; j++ ) {
                        win->alines[i]->line[j].ch = right.vals[0];
+                       win->alines[i]->line[j].cflags &= ~CA_BACKGROUND;
                        win->alines[i]->line[j].attr = right.attributes;
                        np = win->alines[i]->line[j].nsp;
                        if (np) {
@@ -378,6 +381,7 @@
                        k = pcw < 0 ? endx -cw + pcw : endx - cw;
                        for (j = endx - cw; j >= k; j--) {
                                win->alines[i]->line[j].ch = win->bch;
+                               win->alines[i]->line[j].cflags |= CA_BACKGROUND;
                                if (_cursesi_copy_nsp(win->bnsp,
                                               &win->alines[i]->line[j]) == ERR)
                                        return ERR;
@@ -405,6 +409,7 @@
        for (i = tlcw; i <= min( endx - cw, endx - trcw); i += cw) {
                for (j = 0; j < cw; j++) {
                        win->alines[0]->line[i + j].ch = top.vals[0];
+                       win->alines[0]->line[i + j].cflags &= ~CA_BACKGROUND;
                        win->alines[0]->line[i + j].attr = top.attributes;
                        np = win->alines[0]->line[i + j].nsp;
                        if (np) {
@@ -435,6 +440,7 @@
        }
        while (i <= endx - trcw) {
                win->alines[0]->line[i].ch = win->bch;
+               win->alines[0]->line[i].cflags |= CA_BACKGROUND;
                if (_cursesi_copy_nsp(win->bnsp,
                                      &win->alines[0]->line[i]) == ERR)
                        return ERR;
@@ -446,6 +452,7 @@
        for (i = blcw; i <= min( endx - cw, endx - brcw); i += cw) {
                for (j = 0; j < cw; j++) {
                        win->alines[endy]->line[i + j].ch = bottom.vals[0];
+                       win->alines[endy]->line[i + j].cflags &= ~CA_BACKGROUND;
                        win->alines[endy]->line[i + j].attr = bottom.attributes;
                        np = win->alines[endy]->line[i + j].nsp;
                        if (np) {
@@ -475,6 +482,7 @@
        }
        while (i <= endx - brcw) {
                win->alines[endy]->line[i].ch = win->bch;
+               win->alines[endy]->line[i].cflags |= CA_BACKGROUND;
                if (_cursesi_copy_nsp(win->bnsp,
                                      &win->alines[endy]->line[i]) == ERR)
                        return ERR;
@@ -488,6 +496,7 @@
                (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
                for (i = 0; i < tlcw; i++) {
                        win->alines[0]->line[i].ch = topleft.vals[0];
+                       win->alines[0]->line[i].cflags &= ~CA_BACKGROUND;
                        win->alines[0]->line[i].attr = topleft.attributes;
                        np = win->alines[0]->line[i].nsp;
                        if (np) {
@@ -517,6 +526,7 @@
                }
                for (i = endx - trcw + 1; i <= endx; i++) {
                        win->alines[0]->line[i].ch = topright.vals[0];
+                       win->alines[0]->line[i].cflags &= ~CA_BACKGROUND;
                        win->alines[0]->line[i].attr = topright.attributes;
                        np = win->alines[0]->line[i].nsp;
                        if (np) {
@@ -546,6 +556,7 @@
                }
                for (i = 0; i < blcw; i++) {
                        win->alines[endy]->line[i].ch = botleft.vals[0];
+                       win->alines[endy]->line[i].cflags &= ~CA_BACKGROUND;
                        win->alines[endy]->line[i].attr = botleft.attributes;
                        np = win->alines[ endy ]->line[i].nsp;
                        if (np) {
@@ -574,6 +585,7 @@
                }
                for (i = endx - brcw + 1; i <= endx; i++) {
                        win->alines[endy]->line[i].ch = botright.vals[0];
+                       win->alines[endy]->line[i].cflags &= ~CA_BACKGROUND;
                        win->alines[endy]->line[i].attr = botright.attributes;
                        np = win->alines[endy]->line[i].nsp;
                        if (np) {
diff -r 08e9d2cba301 -r 918f69bc402f lib/libcurses/clrtobot.c
--- a/lib/libcurses/clrtobot.c  Tue May 03 00:29:23 2022 +0000
+++ b/lib/libcurses/clrtobot.c  Tue May 03 07:25:34 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clrtobot.c,v 1.29 2022/04/12 07:03:04 blymn Exp $      */
+/*     $NetBSD: clrtobot.c,v 1.30 2022/05/03 07:25:34 blymn Exp $      */
 
 /*



Home | Main Index | Thread Index | Old Index