Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic manage fonts through the wsfont framework, which ...



details:   https://anonhg.NetBSD.org/src/rev/3aa012e4cec7
branches:  trunk
changeset: 514474:3aa012e4cec7
user:      drochner <drochner%NetBSD.org@localhost>
date:      Mon Sep 03 17:34:07 2001 +0000

description:
manage fonts through the wsfont framework, which allows to use both
compiled-in or runtime loaded fonts,
keep font pointers in a LRU queue and load into the adapter on demand,
 so we can have more fonts in use than physical font slots

CAUTION: font loading through the wsdisplay device directly into the
adapter doesn't work anymore!

diffstat:

 sys/dev/ic/vga.c |  282 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 186 insertions(+), 96 deletions(-)

diffs (truncated from 410 to 300 lines):

diff -r ebc02c695093 -r 3aa012e4cec7 sys/dev/ic/vga.c
--- a/sys/dev/ic/vga.c  Mon Sep 03 17:18:22 2001 +0000
+++ b/sys/dev/ic/vga.c  Mon Sep 03 17:34:07 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vga.c,v 1.36 2001/07/07 15:53:22 thorpej Exp $ */
+/* $NetBSD: vga.c,v 1.37 2001/09/03 17:34:07 drochner Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -44,29 +44,34 @@
 #include <dev/wscons/wsdisplayvar.h>
 #include <dev/wscons/wsconsio.h>
 #include <dev/wscons/unicode.h>
+#include <dev/wsfont/wsfont.h>
 
 #include <dev/ic/pcdisplay.h>
 
 #include "opt_wsdisplay_compat.h" /* for WSCONS_SUPPORT_PCVTFONTS */
 
-static const struct vgafont {
-       char name[16];
-       int height;
-       int encoding;
-#ifdef notyet
-       int firstchar, numchars;
-#endif
-       int slot;
-} vga_builtinfont = {
+static struct wsdisplay_font _vga_builtinfont = {
        "builtin",
-       16,
+       0, 256,
        WSDISPLAY_FONTENC_IBM,
-#ifdef notyet
-       0, 256,
-#endif
+       8, 16, 1,
+       WSDISPLAY_FONTORDER_L2R, 0,
        0
 };
 
+struct egavga_font {
+       struct wsdisplay_font *wsfont;
+       int cookie; /* wsfont handle */
+       int slot; /* in adapter RAM */
+       int usecount;
+       TAILQ_ENTRY(egavga_font) next; /* LRU queue */
+};
+
+static struct egavga_font vga_builtinfont = {
+       &_vga_builtinfont,
+       0, 0
+};
+
 struct vgascreen {
        struct pcdisplayscreen pcs;
 
@@ -75,7 +80,7 @@
        struct vga_config *cfg;
 
        /* videostate */
-       const struct vgafont *fontset1, *fontset2;
+       struct egavga_font *fontset1, *fontset2;
        /* font data */
        /* palette */
 
@@ -95,7 +100,8 @@
        bus_space_tag_t vc_biostag;
        bus_space_handle_t vc_bioshdl;
 
-       const struct vgafont *vc_fonts[8];
+       struct egavga_font *vc_fonts[8]; /* currently loaded */
+       TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
 
        struct vgascreen *wantedscreen;
        void (*switchcb) __P((void *, int, int));
@@ -110,6 +116,10 @@
 static struct vgascreen vga_console_screen;
 static struct vga_config vga_console_vc;
 
+struct egavga_font *egavga_getfont(struct vga_config *, struct vgascreen *,
+                                  char *, int);
+void egavga_unreffont(struct vga_config *, struct egavga_font *);
+
 int vga_selectfont __P((struct vga_config *, struct vgascreen *,
                        char *, char *));
 void vga_init_screen __P((struct vga_config *, struct vgascreen *,
@@ -347,9 +357,84 @@
  * first font slot.
  */
 #define vga_valid_primary_font(f) \
-       (f->encoding == WSDISPLAY_FONTENC_IBM || \
-       f->encoding == WSDISPLAY_FONTENC_ISO || \
-       f->encoding == WSDISPLAY_FONTENC_ISO7)
+       (f->wsfont->encoding == WSDISPLAY_FONTENC_IBM || \
+       f->wsfont->encoding == WSDISPLAY_FONTENC_ISO || \
+       f->wsfont->encoding == WSDISPLAY_FONTENC_ISO7)
+
+struct egavga_font *
+egavga_getfont(vc, scr, name, primary)
+       struct vga_config *vc;
+       struct vgascreen *scr;
+       char *name;
+       int primary;
+{
+       struct egavga_font *f;
+       int cookie;
+       struct wsdisplay_font *wf;
+
+       TAILQ_FOREACH(f, &vc->vc_fontlist, next) {
+               if (wsfont_matches(f->wsfont, name,
+                                  8, scr->pcs.type->fontheight, 0) &&
+                   (!primary || vga_valid_primary_font(f))) {
+#ifdef VGAFONTDEBUG
+                       if (scr != &vga_console_screen || vga_console_attached)
+                               printf("vga_getfont: %s already present\n",
+                                      name ? name : <default>);
+#endif
+                       goto found;
+               }
+       }
+
+       cookie = wsfont_find(name, 8, scr->pcs.type->fontheight, 0);
+       /* XXX obey "primary" */
+       if (cookie == -1) {
+#ifdef VGAFONTDEBUG
+               if (scr != &vga_console_screen || vga_console_attached)
+                       printf("vga_getfont: %s not found\n", name);
+#endif
+               return (0);
+       }
+
+       if (wsfont_lock(cookie, &wf, WSDISPLAY_FONTORDER_L2R, 0) < 0)
+               return (0);
+
+       f = malloc(sizeof(struct egavga_font), M_DEVBUF, M_NOWAIT);
+       if (!f) {
+               wsfont_unlock(cookie);
+               return (0);
+       }
+       f->wsfont = wf;
+       f->cookie = cookie;
+       f->slot = -1; /* not yet loaded */
+       f->usecount = 0; /* incremented below */
+       TAILQ_INSERT_TAIL(&vc->vc_fontlist, f, next);
+
+found:
+       f->usecount++;
+#ifdef VGAFONTDEBUG
+       if (scr != &vga_console_screen || vga_console_attached)
+               printf("vga_getfont: usecount=%d\n", f->usecount);
+#endif
+       return (f);
+}
+
+void
+egavga_unreffont(vc, f)
+       struct vga_config *vc;
+       struct egavga_font *f;
+{
+
+       f->usecount--;
+#ifdef VGAFONTDEBUG
+       printf("vga_unreffont: usecount=%d\n", f->usecount);
+#endif
+       if (f->usecount == 0) {
+               /* XXX not for builtin font */
+               TAILQ_REMOVE(&vc->vc_fontlist, f, next);
+               wsfont_unlock(f->cookie);
+               free(f, M_DEVBUF);
+       }
+}
 
 int
 vga_selectfont(vc, scr, name1, name2)
@@ -358,49 +443,38 @@
        char *name1, *name2; /* NULL: take first found */
 {
        const struct wsscreen_descr *type = scr->pcs.type;
-       const struct vgafont *f1, *f2;
-       int i;
+       struct egavga_font *f1, *f2;
 
-       f1 = f2 = 0;
+       f1 = egavga_getfont(vc, scr, name1, 1);
+       if (!f1)
+               return (ENXIO);
 
-       for (i = 0; i < 8; i++) {
-               const struct vgafont *f = vc->vc_fonts[i];
-               if (!f || f->height != type->fontheight)
-                       continue;
-               if (!f1 &&
-                   vga_valid_primary_font(f) &&
-                   (!name1 || !strcmp(name1, f->name))) {
-                       f1 = f;
-                       continue;
+       if (VGA_SCREEN_CANTWOFONTS(type) && name2) {
+               f2 = egavga_getfont(vc, scr, name2, 0);
+               if (!f2) {
+                       egavga_unreffont(vc, f1);
+                       return (ENXIO);
                }
-               if (!f2 &&
-                   VGA_SCREEN_CANTWOFONTS(type) &&
-                   (!name2 || !strcmp(name2, f->name))) {
-                       f2 = f;
-                       continue;
-               }
+       } else
+               f2 = 0;
+
+#ifdef VGAFONTDEBUG
+       if (scr != &vga_console_screen || vga_console_attached) {
+               printf("vga (%s): font1=%s (slot %d)", type->name,
+                      f1->wsfont->name, f1->slot);
+               if (f2)
+                       printf(", font2=%s (slot %d)",
+                              f2->wsfont->name, f2->slot);
+               printf("\n");
        }
-
-       /*
-        * The request fails if no primary font was found,
-        * or if a second font was requested but not found.
-        */
-       if (f1 && (!name2 || f2)) {
-#ifdef VGAFONTDEBUG
-               if (scr != &vga_console_screen || vga_console_attached) {
-                       printf("vga (%s): font1=%s (slot %d)", type->name,
-                              f1->name, f1->slot);
-                       if (f2)
-                               printf(", font2=%s (slot %d)",
-                                      f2->name, f2->slot);
-                       printf("\n");
-               }
 #endif
-               scr->fontset1 = f1;
-               scr->fontset2 = f2;
-               return (0);
-       }
-       return (ENXIO);
+       if (scr->fontset1)
+               egavga_unreffont(vc, scr->fontset1);
+       scr->fontset1 = f1;
+       if (scr->fontset2)
+               egavga_unreffont(vc, scr->fontset2);
+       scr->fontset2 = f2;
+       return (0);
 }
 
 void
@@ -462,6 +536,7 @@
 
        scr->pcs.mem = NULL;
 
+       wsfont_init();
        scr->fontset1 = scr->fontset2 = 0;
        if (vga_selectfont(vc, scr, 0, 0)) {
                if (scr == &vga_console_screen)
@@ -522,6 +597,8 @@
        vc->vc_fonts[0] = &vga_builtinfont;
        for (i = 1; i < 8; i++)
                vc->vc_fonts[i] = 0;
+       TAILQ_INIT(&vc->vc_fontlist);
+       TAILQ_INSERT_HEAD(&vc->vc_fontlist, &vga_builtinfont, next);
 
        vc->currentfontset1 = vc->currentfontset2 = 0;
 }
@@ -727,6 +804,48 @@
                vc->active = 0;
 }
 
+void vga_usefont(struct vga_config *, struct egavga_font *);
+
+void
+vga_usefont(vc, f)
+       struct vga_config *vc;
+       struct egavga_font *f;
+{
+       int slot;
+       struct egavga_font *of;
+
+       if (f->slot != -1)
+               goto toend;
+
+       for (slot = 0; slot < 8; slot++) {
+               if (!vc->vc_fonts[slot])
+                       goto loadit;
+       }
+
+       /* have to kick out another one */
+       TAILQ_FOREACH(of, &vc->vc_fontlist, next) {
+               if (of->slot != -1) {
+                       if (of == &vga_builtinfont)
+                               continue; /* XXX for now */
+                       KASSERT(vc->vc_fonts[of->slot] == of);
+                       slot = of->slot;
+                       of->slot = -1;
+                       goto loadit;



Home | Main Index | Thread Index | Old Index