Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic support anti-aliased fonts, glyphcache etc.



details:   https://anonhg.NetBSD.org/src/rev/b931a1fb8152
branches:  trunk
changeset: 351112:b931a1fb8152
user:      macallan <macallan%NetBSD.org@localhost>
date:      Thu Feb 02 19:55:05 2017 +0000

description:
support anti-aliased fonts, glyphcache etc.

diffstat:

 sys/dev/ic/ct65550.c    |  209 ++++++++++++++++++++++++++++++++++++++++-------
 sys/dev/ic/ct65550reg.h |    5 +-
 sys/dev/ic/ct65550var.h |    8 +-
 3 files changed, 184 insertions(+), 38 deletions(-)

diffs (truncated from 419 to 300 lines):

diff -r e250dc373ff2 -r b931a1fb8152 sys/dev/ic/ct65550.c
--- a/sys/dev/ic/ct65550.c      Thu Feb 02 19:50:35 2017 +0000
+++ b/sys/dev/ic/ct65550.c      Thu Feb 02 19:55:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ct65550.c,v 1.11 2016/08/26 22:50:11 macallan Exp $    */
+/*     $NetBSD: ct65550.c,v 1.12 2017/02/02 19:55:05 macallan Exp $    */
 
 /*
  * Copyright (c) 2006 Michael Lorenz
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ct65550.c,v 1.11 2016/08/26 22:50:11 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ct65550.c,v 1.12 2017/02/02 19:55:05 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -71,11 +71,12 @@
 static int     chipsfb_putpalreg(struct chipsfb_softc *, uint8_t, uint8_t,
                            uint8_t, uint8_t);
 
-static void    chipsfb_bitblt(struct chipsfb_softc *, int, int, int, int,
-                           int, int, uint8_t);
+static void    chipsfb_bitblt(void *, int, int, int, int,
+                           int, int, int);
 static void    chipsfb_rectfill(struct chipsfb_softc *, int, int, int, int,
                            int);
 static void    chipsfb_putchar(void *, int, int, u_int, long);
+static void    chipsfb_putchar_aa(void *, int, int, u_int, long);
 static void    chipsfb_setup_mono(struct chipsfb_softc *, int, int, int,
                            int, uint32_t, uint32_t);
 static void    chipsfb_feed(struct chipsfb_softc *, int, uint8_t *);
@@ -159,7 +160,7 @@
        return chipsfb_read_vga(sc, reg | 0x0001);
 }
 
-__unused static inline void
+static inline void
 chipsfb_write_indexed(struct chipsfb_softc *sc, uint32_t reg, uint8_t index,
     uint8_t val)
 {
@@ -224,14 +225,14 @@
        } else
                aprint_verbose("Panel size: %d x %d\n", width, height);
 
-       if (!prop_dictionary_get_uint32(dict, "width", &sc->width))
-               sc->width = width;
-       if (!prop_dictionary_get_uint32(dict, "height", &sc->height))
-               sc->height = height;
-       if (!prop_dictionary_get_uint32(dict, "depth", &sc->bits_per_pixel))
-               sc->bits_per_pixel = 8;
-       if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->linebytes))
-               sc->linebytes = (sc->width * sc->bits_per_pixel) >> 3;
+       if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width))
+               sc->sc_width = width;
+       if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height))
+               sc->sc_height = height;
+       if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_bits_per_pixel))
+               sc->sc_bits_per_pixel = 8;
+       if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_linebytes))
+               sc->sc_linebytes = (sc->sc_width * sc->sc_bits_per_pixel) >> 3;
 
        prop_dictionary_get_bool(dict, "is_console", &console);
 
@@ -243,6 +244,10 @@
        vcons_init(&sc->vd, sc, &chipsfb_defaultscreen, &chipsfb_accessops);
        sc->vd.init_screen = chipsfb_init_screen;
 
+       sc->sc_gc.gc_bitblt = chipsfb_bitblt;
+       sc->sc_gc.gc_blitcookie = sc;
+       sc->sc_gc.gc_rop = ROP_COPY;
+
        ri = &chipsfb_console_screen.scr_ri;
        if (console) {
                vcons_init_screen(&sc->vd, &chipsfb_console_screen, 1,
@@ -253,6 +258,12 @@
                chipsfb_defaultscreen.capabilities = ri->ri_caps;
                chipsfb_defaultscreen.nrows = ri->ri_rows;
                chipsfb_defaultscreen.ncols = ri->ri_cols;
+               glyphcache_init(&sc->sc_gc, sc->sc_height + 1,
+                               (sc->sc_fbsize / sc->sc_linebytes) - sc->sc_height - 1,
+                               sc->sc_width,
+                               ri->ri_font->fontwidth,
+                               ri->ri_font->fontheight,
+                               defattr);
                wsdisplay_cnattach(&chipsfb_defaultscreen, ri, 0, 0, defattr);
        } else {
                if (chipsfb_console_screen.scr_ri.ri_rows == 0) {
@@ -262,6 +273,12 @@
                } else
                        (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
 
+               glyphcache_init(&sc->sc_gc, sc->sc_height + 1,
+                               (sc->sc_fbsize / sc->sc_linebytes) - sc->sc_height - 1,
+                               sc->sc_width,
+                               ri->ri_font->fontwidth,
+                               ri->ri_font->fontheight,
+                               defattr);
        }
 
        rasops_unpack_attr(defattr, &fg, &bg, &ul);
@@ -378,7 +395,7 @@
 static void
 chipsfb_clearscreen(struct chipsfb_softc *sc)
 {
-       chipsfb_rectfill(sc, 0, 0, sc->width, sc->height, sc->sc_bg);
+       chipsfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
 }
 
 /*
@@ -508,16 +525,17 @@
 }
 
 static void
-chipsfb_bitblt(struct chipsfb_softc *sc, int xs, int ys, int xd, int yd,
-    int width, int height, uint8_t rop)
+chipsfb_bitblt(void *cookie, int xs, int ys, int xd, int yd,
+    int width, int height, int rop)
 {
+       struct chipsfb_softc *sc = cookie;
        uint32_t src, dst, cmd = rop, stride, size;
 
        cmd |= BLT_PAT_IS_SOLID;
 
        /* we assume 8 bit for now */
-       src = xs + ys * sc->linebytes;
-       dst = xd + yd * sc->linebytes;
+       src = xs + ys * sc->sc_linebytes;
+       dst = xd + yd * sc->sc_linebytes;
 
        if (xs < xd) {
                /* right-to-left operation */
@@ -529,11 +547,11 @@
        if (ys < yd) {
                /* bottom-to-top operation */
                cmd |= BLT_START_BOTTOM;
-               src += (height - 1) * sc->linebytes;
-               dst += (height - 1) * sc->linebytes;
+               src += (height - 1) * sc->sc_linebytes;
+               dst += (height - 1) * sc->sc_linebytes;
        }
 
-       stride = (sc->linebytes << 16) | sc->linebytes;
+       stride = (sc->sc_linebytes << 16) | sc->sc_linebytes;
        size = (height << 16) | width;
 
        chipsfb_wait_idle(sc);
@@ -556,9 +574,9 @@
        cmd = BLT_PAT_IS_SOLID | BLT_PAT_IS_MONO | ROP_PAT;
 
        /* we assume 8 bit for now */
-       dst = x + y * sc->linebytes;
+       dst = x + y * sc->sc_linebytes;
 
-       stride = (sc->linebytes << 16) | sc->linebytes;
+       stride = (sc->sc_linebytes << 16) | sc->sc_linebytes;
        size = (height << 16) | width;
 
        chipsfb_wait_idle(sc);
@@ -575,6 +593,117 @@
 }
 
 static void
+chipsfb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
+{
+       struct rasops_info *ri = cookie;
+       struct wsdisplay_font *font = PICK_FONT(ri, c);
+       struct vcons_screen *scr = ri->ri_hw;
+       struct chipsfb_softc *sc = scr->scr_cookie;
+       uint32_t bg, latch = 0, bg8, fg8, pixel, dst, stride, size;
+       int i, l, x, y, wi, he, r, g, b, aval;
+       int r1, g1, b1, r0, g0, b0, fgo, bgo, off;
+       uint8_t *data8;
+       int rv;
+
+       if (__predict_false((unsigned int)row > ri->ri_rows ||
+           (unsigned int)col > ri->ri_cols))
+               return;
+
+       if (__predict_false((sc->sc_mode != WSDISPLAYIO_MODE_EMUL)))
+               return;
+       
+       if (__predict_false((!CHAR_IN_FONT(c, font))))
+               return;
+
+       wi = font->fontwidth;
+       he = font->fontheight;
+
+       bg = ri->ri_devcmap[(attr >> 16) & 0xf];
+       x = ri->ri_xorigin + col * wi;
+       y = ri->ri_yorigin + row * he;
+
+       if (c == 0x20) {
+               chipsfb_rectfill(sc, x, y, wi, he, bg);
+               return;
+       }
+
+       rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
+       if (rv == GC_OK)
+               return;
+
+       data8 = WSFONT_GLYPH(c, font);
+
+       /* we assume 8 bit for now */
+       dst = x + y * sc->sc_linebytes;
+
+       stride = sc->sc_linebytes << 16;
+       size = (he << 16) | wi;
+
+       /* set up for host blit */
+       chipsfb_wait_idle(sc);
+       chipsfb_write32(sc, CT_BLT_STRIDE, stride);
+       chipsfb_write32(sc, CT_BLT_DSTADDR, dst);
+       chipsfb_write32(sc, CT_BLT_SRCADDR, 0);
+       chipsfb_write32(sc, CT_BLT_CONTROL,
+           BLT_PAT_IS_SOLID | BLT_SRC_IS_CPU | ROP_COPY);
+       chipsfb_write32(sc, CT_BLT_SIZE, size);
+
+       /*
+        * we need the RGB colours here, so get offsets into rasops_cmap
+        */
+       fgo = ((attr >> 24) & 0xf) * 3;
+       bgo = ((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];
+#define R3G3B2(r, g, b) ((r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6))
+       bg8 = R3G3B2(r0, g0, b0);
+       fg8 = R3G3B2(r1, g1, b1);
+
+       for (l = 0; l < he; l++) {
+               off = 0;
+               for (i = 0; i < wi; i++) {
+                       aval = *data8;
+                       if (aval == 0) {
+                               pixel = bg8;
+                       } else if (aval == 255) {
+                               pixel = fg8;
+                       } else {
+                               r = aval * r1 + (255 - aval) * r0;
+                               g = aval * g1 + (255 - aval) * g0;
+                               b = aval * b1 + (255 - aval) * b0;
+                               pixel = ((r & 0xe000) >> 8) |
+                                       ((g & 0xe000) >> 11) |
+                                       ((b & 0xc000) >> 14);
+                       }
+                       latch |= pixel << off;
+                       off += 8;
+                       /* write in 32bit chunks */
+                       if ((i & 3) == 3) {
+                               chipsfb_write32(sc, CT_OFF_DATA - CT_OFF_BITBLT, latch);
+                               latch = 0;
+                               off = 0;
+                       }
+                       data8++;
+               }
+               /* if we have pixels left in latch write them out */
+               if ((i & 3) != 0) {
+                       chipsfb_write32(sc, CT_OFF_DATA - CT_OFF_BITBLT, latch);
+               }
+               /* this chip needs scanlines 64bit aligned */
+               if (wi & 7) chipsfb_write32(sc, CT_OFF_DATA - CT_OFF_BITBLT, 0);
+       }
+
+       if (rv == GC_ADD) {
+               glyphcache_add(&sc->sc_gc, c, x, y);
+       }
+}
+
+static void
 chipsfb_putchar(void *cookie, int row, int col, u_int c, long attr)
 {
        struct rasops_info *ri = cookie;
@@ -621,14 +750,13 @@
        cmd = BLT_PAT_IS_SOLID | BLT_SRC_IS_CPU | BLT_SRC_IS_MONO | ROP_COPY;
 
        /* we assume 8 bit for now */
-       dst = xd + yd * sc->linebytes;
+       dst = xd + yd * sc->sc_linebytes;
 
-       stride = (sc->linebytes << 16);
+       stride = (sc->sc_linebytes << 16);
        size = (height << 16) | width;
 
        chipsfb_wait_idle(sc);
        chipsfb_write32(sc, CT_BLT_STRIDE, stride);
-       chipsfb_write32(sc, CT_BLT_EXPCTL, MONO_SRC_ALIGN_BYTE);
        chipsfb_write32(sc, CT_BLT_DSTADDR, dst);
        chipsfb_write32(sc, CT_BLT_SRCADDR, 0);
        chipsfb_write32(sc, CT_BLT_CONTROL, cmd);
@@ -744,7 +872,9 @@
                if (new_mode != sc->sc_mode) {
                        sc->sc_mode = new_mode;
                        if(new_mode == WSDISPLAYIO_MODE_EMUL) {
+                               chipsfb_init(sc);



Home | Main Index | Thread Index | Old Index