Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/rasops Clean up for rasops1.c:



details:   https://anonhg.NetBSD.org/src/rev/c9eb9463d130
branches:  trunk
changeset: 962694:c9eb9463d130
user:      rin <rin%NetBSD.org@localhost>
date:      Mon Jul 29 02:57:41 2019 +0000

description:
Clean up for rasops1.c:
- dedup ugly copy-paste
- rewrite to factorize width-optimized putchar functions
- misc style

diffstat:

 sys/dev/rasops/rasops1.c               |  336 +++++++-------------------------
 sys/dev/rasops/rasops1_putchar_width.h |  137 +++++++++++++
 2 files changed, 212 insertions(+), 261 deletions(-)

diffs (truncated from 582 to 300 lines):

diff -r 2dd16659e731 -r c9eb9463d130 sys/dev/rasops/rasops1.c
--- a/sys/dev/rasops/rasops1.c  Mon Jul 29 02:20:59 2019 +0000
+++ b/sys/dev/rasops/rasops1.c  Mon Jul 29 02:57:41 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops1.c,v 1.28 2019/07/25 03:02:44 rin Exp $ */
+/*     $NetBSD: rasops1.c,v 1.29 2019/07/29 02:57:41 rin Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.28 2019/07/25 03:02:44 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.29 2019/07/29 02:57:41 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -60,6 +60,12 @@
 rasops1_init(struct rasops_info *ri)
 {
 
+       if ((ri->ri_font->fontwidth & 7) != 0) {
+               ri->ri_ops.erasecols = rasops1_erasecols;
+               ri->ri_ops.copycols = rasops1_copycols;
+               ri->ri_do_cursor = rasops1_do_cursor;
+       }
+
        switch (ri->ri_font->fontwidth) {
 #ifndef RASOPS_SMALL
        case 8:
@@ -73,12 +79,6 @@
                ri->ri_ops.putchar = rasops1_putchar;
                break;
        }
-
-       if ((ri->ri_font->fontwidth & 7) != 0) {
-               ri->ri_ops.erasecols = rasops1_erasecols;
-               ri->ri_ops.copycols = rasops1_copycols;
-               ri->ri_do_cursor = rasops1_do_cursor;
-       }
 }
 
 /*
@@ -87,12 +87,15 @@
 static void
 rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
 {
-       u_int fs, rs, fb, bg, fg, lmask, rmask;
-       uint32_t height, width;
        struct rasops_info *ri = (struct rasops_info *)cookie;
        struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       uint32_t *rp, *hrp = NULL, tmp, tmp2;
+       uint32_t fs, rs, fb, bg, fg, lmask, rmask;
+       uint32_t height, width;
+       uint32_t *rp, *hrp, tmp, tmp0, tmp1;
        uint8_t *fr;
+       bool space;
+
+       hrp = NULL;     /* XXX GCC */
 
 #ifdef RASOPS_CLIPPING
        /* Catches 'row < 0' case too */
@@ -111,30 +114,31 @@
                    ((col >> 3) & ~3));
        height = font->fontheight;
        width = font->fontwidth;
-       col = col & 31;
+       col &= 31;
        rs = ri->ri_stride;
 
        bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
 
        /* If fg and bg match this becomes a space character */
-       if (fg == bg || uc == ' ') {
-               uc = (u_int)-1;
-               fr = 0;         /* shutup gcc */
-               fs = 0;         /* shutup gcc */
+       if (uc == ' ' || fg == bg) {
+               space = true;
+               fr = NULL;      /* XXX GCC */
+               fs = 0;         /* XXX GCC */
        } else {
+               space = false;
                fr = FONT_GLYPH(uc, font, ri);
                fs = font->stride;
        }
 
-       /* Single word, one mask */
-       if ((col + width) <= 32) {
+       if (col + width <= 32) {
+               /* Single word, only one mask */
+
                rmask = rasops_pmask[col][width];
                lmask = ~rmask;
 
-               if (uc == (u_int)-1) {
+               if (space) {
                        bg &= rmask;
-
                        while (height--) {
                                tmp = (*rp & lmask) | bg;
                                *rp = tmp;
@@ -145,36 +149,19 @@
                                }
                        }
                } else {
-                       /* NOT fontbits if bg is white */
-                       if (bg) {
-                               while (height--) {
-                                       fb = ~(fr[3] | (fr[2] << 8) |
-                                           (fr[1] << 16) | (fr[0] << 24));
-                                       tmp = (*rp & lmask)
-                                           | (MBE(fb >> col) & rmask);
-                                       *rp = tmp;
-
-                                       fr += fs;
-                                       DELTA(rp, rs, uint32_t *);
-                                       if (ri->ri_hwbits) {
-                                               *hrp = tmp;
-                                               DELTA(hrp, rs, uint32_t *);
-                                       }
-                               }
-                       } else {
-                               while (height--) {
-                                       fb = (fr[3] | (fr[2] << 8) |
-                                           (fr[1] << 16) | (fr[0] << 24));
-                                       tmp = (*rp & lmask)
-                                           | (MBE(fb >> col) & rmask);
-                                       *rp = tmp;
-
-                                       fr += fs;
-                                       DELTA(rp, rs, uint32_t *);
-                                       if (ri->ri_hwbits) {
-                                               *hrp = tmp;
-                                               DELTA(hrp, rs, uint32_t *);
-                                       }
+                       while (height--) {
+                               tmp = *rp & lmask;
+                               fb = fr[3] | (fr[2] << 8) |
+                                   (fr[1] << 16) | (fr[0] << 24);
+                               fr += fs;
+                               if (bg)
+                                       fb = ~fb;
+                               tmp |= (MBE(fb >> col) & rmask);
+                               *rp = tmp;
+                               DELTA(rp, rs, uint32_t *);
+                               if (ri->ri_hwbits) {
+                                       *hrp = tmp;
+                                       DELTA(hrp, rs, uint32_t *);
                                }
                        }
                }
@@ -190,68 +177,45 @@
                        }
                }
        } else {
+               /* Word boundary, two masks needed */
+
                lmask = ~rasops_lmask[col];
                rmask = ~rasops_rmask[(col + width) & 31];
 
-               if (uc == (u_int)-1) {
+               if (space) {
                        width = bg & ~rmask;
                        bg = bg & ~lmask;
-
                        while (height--) {
-                               tmp = (rp[0] & lmask) | bg;
-                               tmp2 = (rp[1] & rmask) | width;
-                               rp[0] = tmp;
-                               rp[1] = tmp2;
+                               tmp0 = (rp[0] & lmask) | bg;
+                               tmp1 = (rp[1] & rmask) | width;
+                               rp[0] = tmp0;
+                               rp[1] = tmp1;
                                DELTA(rp, rs, uint32_t *);
                                if (ri->ri_hwbits) {
-                                       hrp[0] = tmp;
-                                       hrp[1] = tmp2;
+                                       hrp[0] = tmp0;
+                                       hrp[1] = tmp1;
                                        DELTA(hrp, rs, uint32_t *);
                                }
                        }
                } else {
                        width = 32 - col;
-
-                       /* NOT fontbits if bg is white */
-                       if (bg) {
-                               while (height--) {
-                                       fb = ~(fr[3] | (fr[2] << 8) |
-                                           (fr[1] << 16) | (fr[0] << 24));
-
-                                       tmp = (rp[0] & lmask) |
-                                           MBE((u_int)fb >> col);
-
-                                       tmp2 = (rp[1] & rmask) |
-                                           (MBE((u_int)fb << width) & ~rmask);
-                                       rp[0] = tmp;
-                                       rp[1] = tmp2;
-                                       fr += fs;
-                                       DELTA(rp, rs, uint32_t *);
-                                       if (ri->ri_hwbits) {
-                                               hrp[0] = tmp;
-                                               hrp[1] = tmp2;
-                                               DELTA(hrp, rs, uint32_t *);
-                                       }
-                               }
-                       } else {
-                               while (height--) {
-                                       fb = (fr[3] | (fr[2] << 8) |
-                                           (fr[1] << 16) | (fr[0] << 24));
-
-                                       tmp = (rp[0] & lmask) |
-                                           MBE(fb >> col);
-
-                                       tmp2 = (rp[1] & rmask) |
-                                           (MBE(fb << width) & ~rmask);
-                                       rp[0] = tmp;
-                                       rp[1] = tmp2;
-                                       fr += fs;
-                                       DELTA(rp, rs, uint32_t *);
-                                       if (ri->ri_hwbits) {
-                                               hrp[0] = tmp;
-                                               hrp[1] = tmp2;
-                                               DELTA(hrp, rs, uint32_t *);
-                                       }
+                       while (height--) {
+                               tmp0 = rp[0] & lmask;
+                               tmp1 = rp[1] & rmask;
+                               fb = fr[3] | (fr[2] << 8) |
+                                   (fr[1] << 16) | (fr[0] << 24);
+                               fr += fs;
+                               if (bg)
+                                       fb = ~fb;
+                               tmp0 |= MBE(fb >> col);
+                               tmp1 |= (MBE(fb << width) & ~rmask);
+                               rp[0] = tmp0;
+                               rp[1] = tmp1;
+                               DELTA(rp, rs, uint32_t *);
+                               if (ri->ri_hwbits) {
+                                       hrp[0] = tmp0;
+                                       hrp[1] = tmp1;
+                                       DELTA(hrp, rs, uint32_t *);
                                }
                        }
                }
@@ -259,179 +223,29 @@
                /* Do underline */
                if ((attr & WSATTR_UNDERLINE) != 0) {
                        DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-                       tmp = (rp[0] & lmask) | (fg & ~lmask);
-                       tmp2 = (rp[1] & rmask) | (fg & ~rmask);
-                       rp[0] = tmp;
-                       rp[1] = tmp2;
+                       tmp0 = (rp[0] & lmask) | (fg & ~lmask);
+                       tmp1 = (rp[1] & rmask) | (fg & ~rmask);
+                       rp[0] = tmp0;
+                       rp[1] = tmp1;
                        if (ri->ri_hwbits) {
                                DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-                               hrp[0] = tmp;
-                               hrp[1] = tmp2;
+                               hrp[0] = tmp0;
+                               hrp[1] = tmp1;
                        }
                }
        }
 }
 
 #ifndef RASOPS_SMALL
-/*
- * Paint a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops1_putchar8(void *cookie, int row, int col, u_int uc, long attr)
-{
-       int height, fs, rs, bg, fg;
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       uint8_t *fr, *rp, *hrp = NULL;
 
-#ifdef RASOPS_CLIPPING
-       /* Catches 'row < 0' case too */
-       if ((unsigned)row >= (unsigned)ri->ri_rows)
-               return;
-
-       if ((unsigned)col >= (unsigned)ri->ri_cols)
-               return;
-#endif
-
-       rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-       if (ri->ri_hwbits)
-               hrp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
-       height = font->fontheight;
-       rs = ri->ri_stride;
-
-       bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];



Home | Main Index | Thread Index | Old Index