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_aa functions into rasops_p...



details:   https://anonhg.NetBSD.org/src/rev/8cd431d61d98
branches:  trunk
changeset: 1000576:8cd431d61d98
user:      rin <rin%NetBSD.org@localhost>
date:      Mon Jul 29 10:55:56 2019 +0000

description:
Factor out putchar_aa functions into rasops_putchar_aa.h, which includes
the following fixes:

- stop using memset to framebuffer for depth 8
- correctly support non-standard positions/lengths of RGB bits in pixel

diffstat:

 sys/dev/rasops/rasops15.c          |   96 +-------------------
 sys/dev/rasops/rasops32.c          |   90 +-----------------
 sys/dev/rasops/rasops8.c           |  107 +---------------------
 sys/dev/rasops/rasops_putchar_aa.h |  180 +++++++++++++++++++++++++++++++++++++
 4 files changed, 189 insertions(+), 284 deletions(-)

diffs (truncated from 540 to 300 lines):

diff -r 49203082fc19 -r 8cd431d61d98 sys/dev/rasops/rasops15.c
--- a/sys/dev/rasops/rasops15.c Mon Jul 29 10:28:57 2019 +0000
+++ b/sys/dev/rasops/rasops15.c Mon Jul 29 10:55:56 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $        */
+/*     $NetBSD: rasops15.c,v 1.31 2019/07/29 10:55:56 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.30 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.31 2019/07/29 10:55:56 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -110,97 +110,7 @@
 
 #define        RASOPS_DEPTH    15
 #include "rasops_putchar.h"
-
-static void
-rasops15_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
-{
-       int width, height, cnt, clr[2];
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       uint16_t *dp, *rp;
-       uint8_t *rrp;
-       uint8_t *fr;
-       uint16_t buffer[64]; /* XXX */
-       int x, y, r, g, b, aval;
-       int r1, g1, b1, r0, g0, b0, fgo, bgo;
-
-#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
-
-       /* check if character fits into font limits */
-       if (!CHAR_IN_FONT(uc, font))
-               return;
-
-       rrp = (ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-       rp = (uint16_t *)rrp;
-
-       height = font->fontheight;
-       width = font->fontwidth;
-
-       clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
-       clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
-       if (uc == ' ') {
-               for (cnt = 0; cnt < width; cnt++)
-                       buffer[cnt] = clr[0];
-               for (y = 0; y < height; y++) {
-                       dp = rp;
-                       DELTA(rp, ri->ri_stride, uint16_t *);
-                       memcpy(dp, buffer, width << 1);
-               }
-       } else {
-               fr = FONT_GLYPH(uc, font, ri);
-
-               fgo = (((uint32_t)attr >> 24) & 0xf) * 3;
-               bgo = (((uint32_t)attr >> 16) & 0xf) * 3;
-
-               r0 = rasops_cmap[bgo];
-               r1 = rasops_cmap[fgo];
-               g0 = rasops_cmap[bgo + 1];
-               g1 = rasops_cmap[fgo + 1];
-               b0 = rasops_cmap[bgo + 2];
-               b1 = rasops_cmap[fgo + 2];
-
-               for (y = 0; y < height; y++) {
-                       dp = (uint16_t *)(rrp + ri->ri_stride * y);
-                       for (x = 0; x < width; x++) {
-                               aval = *fr;
-                               if (aval == 0) {
-                                       buffer[x] = clr[0];
-                               } else if (aval == 255) {
-                                       buffer[x] = clr[1];
-                               } else {
-                                       r = aval * r1 + (255 - aval) * r0;
-                                       g = aval * g1 + (255 - aval) * g0;
-                                       b = aval * b1 + (255 - aval) * b0;
-                                       buffer[x] =
-                                           ((r >> (16 - ri->ri_rnum)) <<
-                                               ri->ri_rpos) |
-                                           ((g >> (16 - ri->ri_gnum)) <<
-                                               ri->ri_gpos) |
-                                           ((b >> (16 - ri->ri_bnum)) <<
-                                               ri->ri_bpos);
-                               }
-                               fr++;
-                       }
-                       memcpy(dp, buffer, width << 1);
-               }
-       }
-
-       /* Do underline */
-       if ((attr & WSATTR_UNDERLINE) != 0) {
-               rp = (uint16_t *)rrp;
-               DELTA(rp, (ri->ri_stride * (height - 2)), uint16_t *);
-               while (width--)
-                       *rp++ = clr[1];
-       }
-}
+#include "rasops_putchar_aa.h"
 
 #ifndef RASOPS_SMALL
 /*
diff -r 49203082fc19 -r 8cd431d61d98 sys/dev/rasops/rasops32.c
--- a/sys/dev/rasops/rasops32.c Mon Jul 29 10:28:57 2019 +0000
+++ b/sys/dev/rasops/rasops32.c Mon Jul 29 10:55:56 2019 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rasops32.c,v 1.38 2019/07/28 12:06:10 rin Exp $       */
+/*      $NetBSD: rasops32.c,v 1.39 2019/07/29 10:55:56 rin Exp $       */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.38 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.39 2019/07/29 10:55:56 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -109,91 +109,7 @@
 
 #define        RASOPS_DEPTH    32
 #include "rasops_putchar.h"
-
-static void
-rasops32_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
-{
-       int width, height, cnt, clr[2];
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       uint32_t *dp, *rp;
-       uint8_t *rrp;
-       uint8_t *fr;
-       uint32_t buffer[64]; /* XXX */
-       int x, y, r, g, b, aval;
-       int r1, g1, b1, r0, g0, b0;
-
-#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
-
-       /* check if character fits into font limits */
-       if (!CHAR_IN_FONT(uc, font))
-               return;
-
-       rrp = (ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-       rp = (uint32_t *)rrp;
-
-       height = font->fontheight;
-       width = font->fontwidth;
-
-       clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
-       clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
-       if (uc == ' ') {
-               for (cnt = 0; cnt < width; cnt++)
-                       buffer[cnt] = clr[0];
-               while (height--) {
-                       dp = rp;
-                       DELTA(rp, ri->ri_stride, uint32_t *);
-                       memcpy(dp, buffer, width << 2);
-               }
-       } else {
-               fr = FONT_GLYPH(uc, font, ri);
-
-               r0 = (clr[0] >> 16) & 0xff;
-               r1 = (clr[1] >> 16) & 0xff;
-               g0 = (clr[0] >> 8) & 0xff;
-               g1 = (clr[1] >> 8) & 0xff;
-               b0 =  clr[0] & 0xff;
-               b1 =  clr[1] & 0xff;
-
-               for (y = 0; y < height; y++) {
-                       dp = (uint32_t *)(rrp + ri->ri_stride * y);
-                       for (x = 0; x < width; x++) {
-                               aval = *fr;
-                               if (aval == 0) {
-                                       buffer[x] = clr[0];
-                               } else if (aval == 255) {
-                                       buffer[x] = clr[1];
-                               } else {
-                                       r = aval * r1 + (255 - aval) * r0;
-                                       g = aval * g1 + (255 - aval) * g0;
-                                       b = aval * b1 + (255 - aval) * b0;
-                                       buffer[x] = (r & 0xff00) << 8 |
-                                             (g & 0xff00) |
-                                             (b & 0xff00) >> 8;
-                               }
-                               fr++;
-                       }
-                       memcpy(dp, buffer, width << 2);
-               }
-       }
-
-       /* Do underline */
-       if ((attr & WSATTR_UNDERLINE) != 0) {
-               rp = (uint32_t *)rrp;
-               height = font->fontheight;
-               DELTA(rp, (ri->ri_stride * (height - 2)), uint32_t *);
-               while (width--)
-                       *rp++ = clr[1];
-       }
-}
+#include "rasops_putchar_aa.h"
 
 #ifndef RASOPS_SMALL
 /*
diff -r 49203082fc19 -r 8cd431d61d98 sys/dev/rasops/rasops8.c
--- a/sys/dev/rasops/rasops8.c  Mon Jul 29 10:28:57 2019 +0000
+++ b/sys/dev/rasops/rasops8.c  Mon Jul 29 10:55:56 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp $ */
+/*     $NetBSD: rasops8.c,v 1.44 2019/07/29 10:55:56 rin Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.44 2019/07/29 10:55:56 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -107,108 +107,7 @@
 
 #define        RASOPS_DEPTH    8
 #include "rasops_putchar.h"
-
-static void
-rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
-{
-       int width, height;
-       uint8_t *rp, *hrp, *fr, bg, fg, pixel;
-       struct rasops_info *ri = (struct rasops_info *)cookie;
-       struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       int x, y, r, g, b, aval;
-       int r1, g1, b1, r0, g0, b0, fgo, bgo;
-       uint8_t scanline[32] __attribute__ ((aligned(8)));
-
-       hrp = NULL;     /* XXX GCC */
-
-       if (!CHAR_IN_FONT(uc, font))
-               return;
-
-#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;
-       bg = (uint8_t)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
-       fg = (uint8_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
-       if (uc == ' ') {
-
-               while (height--) {
-                       memset(rp, bg, width);
-                       if (ri->ri_hwbits) {
-                               memset(hrp, bg, width);
-                               hrp += ri->ri_stride;
-                       }
-                       rp += ri->ri_stride;
-               }
-       } else {
-               fr = FONT_GLYPH(uc, font, ri);
-               /*
-                * we need the RGB colours here, get offsets into rasops_cmap
-                */



Home | Main Index | Thread Index | Old Index