Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/rasops Factor out putchar and width-optimized putcha...



details:   https://anonhg.NetBSD.org/src/rev/fe2415269d20
branches:  trunk
changeset: 462137:fe2415269d20
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Jul 25 15:18:53 2019 +0000

description:
Factor out putchar and width-optimized putchar functions into
rasops_putchar.h and rasops_putchar_width.h, respectively.

XXX
Possibly, we can do the same for putchar_aa functions. But it is
currently missing for 24-bpp.

diffstat:

 sys/dev/rasops/rasops15.c             |  423 +---------------------------
 sys/dev/rasops/rasops24.c             |  326 +--------------------
 sys/dev/rasops/rasops32.c             |  511 +---------------------------------
 sys/dev/rasops/rasops8.c              |  373 +-----------------------
 sys/dev/rasops/rasops_putchar.h       |  166 +++++++++++
 sys/dev/rasops/rasops_putchar_width.h |  265 +++++++++++++++++
 6 files changed, 486 insertions(+), 1578 deletions(-)

diffs (truncated from 2187 to 300 lines):

diff -r e523b0aaa9d7 -r fe2415269d20 sys/dev/rasops/rasops15.c
--- a/sys/dev/rasops/rasops15.c Thu Jul 25 15:12:47 2019 +0000
+++ b/sys/dev/rasops/rasops15.c Thu Jul 25 15:18:53 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops15.c,v 1.27 2019/07/25 03:02:44 rin Exp $        */
+/*     $NetBSD: rasops15.c,v 1.28 2019/07/25 15:18:53 rin Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.27 2019/07/25 03:02:44 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.28 2019/07/25 15:18:53 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -112,101 +112,8 @@
        }
 }
 
-/*
- * Paint a single character.
- */
-static void
-rasops15_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-       int fb, width, height, cnt, clr[2];
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       uint8_t *dp, *rp, *hp, *hrp, *fr;
-
-       hp = 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;
-       width = font->fontwidth;
-
-       clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
-       clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
-
-       if (uc == ' ') {
-               uint16_t c = (uint16_t)clr[0];
-               while (height--) {
-                       dp = rp;
-                       rp += ri->ri_stride;
-                       if (ri->ri_hwbits) {
-                               hp = hrp;
-                               hrp += ri->ri_stride;
-                       }
-
-                       for (cnt = width; cnt; cnt--) {
-                               *(uint16_t *)dp = c;
-                               dp += 2;
-                               if (ri->ri_hwbits) {
-                                       *(uint16_t *)hp = c;
-                                       hp += 2;
-                               }
-                       }
-               }
-       } else {
-               fr = FONT_GLYPH(uc, font, ri);
-
-               while (height--) {
-                       dp = rp;
-                       fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
-                           (fr[0] << 24);
-                       fr += font->stride;
-                       rp += ri->ri_stride;
-                       if (ri->ri_hwbits) {
-                               hp = hrp;
-                               hrp += ri->ri_stride;
-                       }
-
-                       for (cnt = width; cnt; cnt--) {
-                               *(uint16_t *)dp = (uint16_t)clr[(fb >> 31) & 1];
-                               if (ri->ri_hwbits)
-                                       *(uint16_t *)hp =
-                                           (uint16_t)clr[(fb >> 31) & 1];
-                               fb <<= 1;
-                               dp += 2;
-                               if (ri->ri_hwbits)
-                                       hp += 2;
-                       }
-               }
-       }
-
-       /* Do underline */
-       if ((attr & WSATTR_UNDERLINE) != 0) {
-               uint16_t c = (uint16_t)clr[1];
-               rp -= ri->ri_stride << 1;
-               if (ri->ri_hwbits)
-                       hrp -= ri->ri_stride << 1;
-
-               while (width--) {
-                       *(uint16_t *)rp = c;
-                       rp += 2;
-                       if (ri->ri_hwbits) {
-                               *(uint16_t *)hrp = c;
-                               hrp += 2;
-                       }
-               }
-       }
-}
+#define        RASOPS_DEPTH    15
+#include "rasops_putchar.h"
 
 static void
 rasops15_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
@@ -329,318 +236,16 @@
        }
 }
 
-/*
- * Paint a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops15_putchar8(void *cookie, int row, int col, u_int uc, long attr)
-{
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       int height, so, fs;
-       uint32_t *rp, *hrp;
-       uint8_t *fr;
-
-       /* Can't risk remaking the stamp if it's already in use */
-       if (stamp_mutex++) {
-               stamp_mutex--;
-               rasops15_putchar(cookie, row, col, uc, attr);
-               return;
-       }
-
-       hrp = NULL;
-
-#ifdef RASOPS_CLIPPING
-       if ((unsigned)row >= (unsigned)ri->ri_rows) {
-               stamp_mutex--;
-               return;
-       }
-
-       if ((unsigned)col >= (unsigned)ri->ri_cols) {
-               stamp_mutex--;
-               return;
-       }
-#endif
-
-       /* Recompute stamp? */
-       if (attr != stamp_attr)
-               rasops15_makestamp(ri, attr);
-
-       rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-       if (ri->ri_hwbits)
-               hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-                   col*ri->ri_xscale);
-       height = font->fontheight;
-
-       if (uc == (u_int)-1) {
-               while (height--) {
-                       rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
-                       DELTA(rp, ri->ri_stride, uint32_t *);
-                       if (ri->ri_hwbits) {
-                               hrp[0] = hrp[1] = hrp[2] = hrp[3] = stamp[0];
-                               DELTA(hrp, ri->ri_stride, uint32_t *);
-                       }
-               }
-       } else {
-               fr = FONT_GLYPH(uc, font, ri);
-               fs = font->stride;
-
-               while (height--) {
-                       so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-                       rp[0] = STAMP_READ(so);
-                       rp[1] = STAMP_READ(so + 4);
-                       if (ri->ri_hwbits) {
-                               hrp[0] = STAMP_READ(so);
-                               hrp[1] = STAMP_READ(so + 4);
-                       }
-
-                       so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-                       rp[2] = STAMP_READ(so);
-                       rp[3] = STAMP_READ(so + 4);
-                       if (ri->ri_hwbits) {
-                               hrp[2] = STAMP_READ(so);
-                               hrp[3] = STAMP_READ(so + 4);
-                       }
-
-                       fr += fs;
-                       DELTA(rp, ri->ri_stride, uint32_t *);
-                       if (ri->ri_hwbits)
-                               DELTA(hrp, ri->ri_stride, uint32_t *);
-               }
-       }
-
-       /* Do underline */
-       if ((attr & WSATTR_UNDERLINE) != 0) {
-               uint32_t c = STAMP_READ(28);
-
-               DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-               rp[0] = rp[1] = rp[2] = rp[3] = c;
-               if (ri->ri_hwbits) {
-                       DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-                       hrp[0] = hrp[1] = hrp[2] = hrp[3] = c;
-               }
-       }
-
-       stamp_mutex--;
-}
-
-/*
- * Paint a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops15_putchar12(void *cookie, int row, int col, u_int uc, long attr)
-{
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       int height, so, fs;
-       uint32_t *rp, *hrp;
-       uint8_t *fr;
-
-       /* Can't risk remaking the stamp if it's already in use */
-       if (stamp_mutex++) {
-               stamp_mutex--;
-               rasops15_putchar(cookie, row, col, uc, attr);
-               return;
-       }
-
-       hrp = NULL;
-
-#ifdef RASOPS_CLIPPING
-       if ((unsigned)row >= (unsigned)ri->ri_rows) {
-               stamp_mutex--;
-               return;
-       }
-
-       if ((unsigned)col >= (unsigned)ri->ri_cols) {
-               stamp_mutex--;
-               return;
-       }
-#endif
-
-       /* Recompute stamp? */
-       if (attr != stamp_attr)
-               rasops15_makestamp(ri, attr);
-
-       rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-       if (ri->ri_hwbits)
-               hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-                   col*ri->ri_xscale);
-       height = font->fontheight;
-
-       if (uc == (u_int)-1) {
-               while (height--) {
-                       rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] =
-                           stamp[0];
-                       DELTA(rp, ri->ri_stride, uint32_t *);
-                       if (ri->ri_hwbits) {
-                               hrp[0] = hrp[1] = hrp[2] = hrp[3] = hrp[4] =
-                                   hrp[5] = stamp[0];
-                               DELTA(hrp, ri->ri_stride, uint32_t *);
-                       }
-               }
-       } else {
-               fr = FONT_GLYPH(uc, font, ri);
-               fs = font->stride;
+#define        RASOPS_WIDTH    8
+#include "rasops_putchar_width.h"
+#undef RASOPS_WIDTH
 
-               while (height--) {
-                       so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-                       rp[0] = STAMP_READ(so);
-                       rp[1] = STAMP_READ(so + 4);
-                       if (ri->ri_hwbits) {
-                               hrp[0] = STAMP_READ(so);
-                               hrp[1] = STAMP_READ(so + 4);
-                       }
-
-                       so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-                       rp[2] = STAMP_READ(so);
-                       rp[3] = STAMP_READ(so + 4);
-                       if (ri->ri_hwbits) {
-                               hrp[2] = STAMP_READ(so);
-                               hrp[3] = STAMP_READ(so + 4);
-                       }
-
-                       so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;



Home | Main Index | Thread Index | Old Index