diff options
| author | ad <ad@NetBSD.org> | 2002-03-13 15:05:13 +0000 |
|---|---|---|
| committer | ad <ad@NetBSD.org> | 2002-03-13 15:05:13 +0000 |
| commit | b89e39b91ab5e0592cdc830060747ad3dac1bc22 (patch) | |
| tree | 77d131a4e5c66c0c56ab0323fc4d6c365a31c5c9 /sys/dev | |
| parent | 17162f3d40fc19b0575ce496407ec123b569551b (diff) | |
Reorganise the wsfont stuff slightly so that multiple display adapters
with different bit/byte order requirements can co-exist happily.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ic/vga.c | 9 | ||||
| -rw-r--r-- | sys/dev/pci/tga.c | 14 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops.c | 18 | ||||
| -rw-r--r-- | sys/dev/tc/cfb.c | 14 | ||||
| -rw-r--r-- | sys/dev/tc/mfb.c | 14 | ||||
| -rw-r--r-- | sys/dev/tc/sfb.c | 14 | ||||
| -rw-r--r-- | sys/dev/tc/sfbplus.c | 14 | ||||
| -rw-r--r-- | sys/dev/tc/stic.c | 16 | ||||
| -rw-r--r-- | sys/dev/tc/tfb.c | 14 | ||||
| -rw-r--r-- | sys/dev/tc/xcfb.c | 14 | ||||
| -rw-r--r-- | sys/dev/wsfont/wsfont.c | 323 | ||||
| -rw-r--r-- | sys/dev/wsfont/wsfont.h | 31 |
12 files changed, 225 insertions, 270 deletions
diff --git a/sys/dev/ic/vga.c b/sys/dev/ic/vga.c index ee6b29cd746..b231491f395 100644 --- a/sys/dev/ic/vga.c +++ b/sys/dev/ic/vga.c @@ -1,4 +1,4 @@ -/* $NetBSD: vga.c,v 1.46 2002/01/23 17:11:38 lukem Exp $ */ +/* $NetBSD: vga.c,v 1.47 2002/03/13 15:05:15 ad Exp $ */ /* * Copyright (c) 1995, 1996 Carnegie-Mellon University. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.46 2002/01/23 17:11:38 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.47 2002/03/13 15:05:15 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -349,7 +349,8 @@ egavga_getfont(struct vga_config *vc, struct vgascreen *scr, char *name, TAILQ_FOREACH(f, &vc->vc_fontlist, next) { if (wsfont_matches(f->wsfont, name, - 8, scr->pcs.type->fontheight, 0) && + 8, scr->pcs.type->fontheight, 0, + WSDISPLAY_FONTORDER_L2R, 0) && (!primary || vga_valid_primary_font(f))) { #ifdef VGAFONTDEBUG if (scr != &vga_console_screen || vga_console_attached) @@ -370,7 +371,7 @@ egavga_getfont(struct vga_config *vc, struct vgascreen *scr, char *name, return (0); } - if (wsfont_lock(cookie, &wf, WSDISPLAY_FONTORDER_L2R, 0) < 0) + if (wsfont_lock(cookie, &wf)) return (0); #ifdef VGA_CONSOLE_SCREENTYPE diff --git a/sys/dev/pci/tga.c b/sys/dev/pci/tga.c index 63258be0a6b..9b58cd1f4d3 100644 --- a/sys/dev/pci/tga.c +++ b/sys/dev/pci/tga.c @@ -1,4 +1,4 @@ -/* $NetBSD: tga.c,v 1.39 2002/01/12 16:17:06 tsutsui Exp $ */ +/* $NetBSD: tga.c,v 1.40 2002/03/13 15:05:18 ad Exp $ */ /* * Copyright (c) 1995, 1996 Carnegie-Mellon University. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tga.c,v 1.39 2002/01/12 16:17:06 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tga.c,v 1.40 2002/03/13 15:05:18 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -362,16 +362,18 @@ tga_init(memt, pc, tag, dc) wsfont_init(); /* prefer 8 pixel wide font */ - if ((cookie = wsfont_find(NULL, 8, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("tga: no appropriate fonts.\n"); return; } /* the accelerated tga_putchar() needs LSbit left */ - if (wsfont_lock(cookie, &dc->dc_rinfo.ri_font, - WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &dc->dc_rinfo.ri_font)) { printf("tga: couldn't lock font\n"); return; } diff --git a/sys/dev/rasops/rasops.c b/sys/dev/rasops/rasops.c index 1aca593b868..b855d875702 100644 --- a/sys/dev/rasops/rasops.c +++ b/sys/dev/rasops/rasops.c @@ -1,4 +1,4 @@ -/* $NetBSD: rasops.c,v 1.38 2001/11/15 09:48:14 lukem Exp $ */ +/* $NetBSD: rasops.c,v 1.39 2002/03/13 15:05:15 ad Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.38 2001/11/15 09:48:14 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.39 2002/03/13 15:05:15 ad Exp $"); #include "opt_rasops.h" #include "rasops_glue.h" @@ -129,16 +129,18 @@ rasops_init(ri, wantrows, wantcols) wsfont_init(); /* Want 8 pixel wide, don't care about aestethics */ - if ((cookie = wsfont_find(NULL, 8, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, + WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("rasops_init: font table is empty\n"); return (-1); } - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("rasops_init: couldn't lock font\n"); return (-1); } @@ -331,17 +333,15 @@ rasops_mapchar(cookie, c, cp) if (ri->ri_font == NULL) panic("rasops_mapchar: no font selected\n"); #endif - if (ri->ri_font->encoding != WSDISPLAY_FONTENC_ISO) { + if (ri->ri_font->encoding != WSDISPLAY_FONTENC_ISO) { if ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) { - *cp = ' '; return (0); } } - if (c < ri->ri_font->firstchar) { *cp = ' '; return (0); diff --git a/sys/dev/tc/cfb.c b/sys/dev/tc/cfb.c index 00efb3154b4..d71132ebb05 100644 --- a/sys/dev/tc/cfb.c +++ b/sys/dev/tc/cfb.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfb.c,v 1.30 2001/11/13 06:26:09 lukem Exp $ */ +/* $NetBSD: cfb.c,v 1.31 2002/03/13 15:05:16 ad Exp $ */ /* * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cfb.c,v 1.30 2001/11/13 06:26:09 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cfb.c,v 1.31 2002/03/13 15:05:16 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -329,15 +329,17 @@ cfb_common_init(ri) wsfont_init(); /* prefer 12 pixel wide font */ - if ((cookie = wsfont_find(NULL, 12, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("cfb: font table is empty\n"); return; } - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("cfb: couldn't lock font\n"); return; } diff --git a/sys/dev/tc/mfb.c b/sys/dev/tc/mfb.c index ee5c6d0b816..e5636f6560e 100644 --- a/sys/dev/tc/mfb.c +++ b/sys/dev/tc/mfb.c @@ -1,4 +1,4 @@ -/* $NetBSD: mfb.c,v 1.30 2002/03/13 10:07:14 ad Exp $ */ +/* $NetBSD: mfb.c,v 1.31 2002/03/13 15:05:16 ad Exp $ */ /* * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mfb.c,v 1.30 2002/03/13 10:07:14 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mfb.c,v 1.31 2002/03/13 15:05:16 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -306,15 +306,17 @@ mfb_common_init(ri) wsfont_init(); /* prefer 12 pixel wide font */ - if ((cookie = wsfont_find(NULL, 12, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("mfb: font table is empty\n"); return; } - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("mfb: couldn't lock font\n"); return; } diff --git a/sys/dev/tc/sfb.c b/sys/dev/tc/sfb.c index 14d03a134ed..aef9422ce14 100644 --- a/sys/dev/tc/sfb.c +++ b/sys/dev/tc/sfb.c @@ -1,4 +1,4 @@ -/* $NetBSD: sfb.c,v 1.49 2001/11/13 06:26:10 lukem Exp $ */ +/* $NetBSD: sfb.c,v 1.50 2002/03/13 15:05:16 ad Exp $ */ /* * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sfb.c,v 1.49 2001/11/13 06:26:10 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sfb.c,v 1.50 2002/03/13 15:05:16 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -345,16 +345,18 @@ sfb_common_init(ri) wsfont_init(); /* prefer 12 pixel wide font */ - if ((cookie = wsfont_find(NULL, 12, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("sfb: font table is empty\n"); return; } /* the accelerated sfb_putchar() needs LSbit left */ - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("sfb: couldn't lock font\n"); return; } diff --git a/sys/dev/tc/sfbplus.c b/sys/dev/tc/sfbplus.c index 0a09ef833a7..c75f97be8e0 100644 --- a/sys/dev/tc/sfbplus.c +++ b/sys/dev/tc/sfbplus.c @@ -1,4 +1,4 @@ -/* $NetBSD: sfbplus.c,v 1.12 2001/11/13 06:26:10 lukem Exp $ */ +/* $NetBSD: sfbplus.c,v 1.13 2002/03/13 15:05:17 ad Exp $ */ /* * Copyright (c) 1999, 2000, 2001 Tohru Nishimura. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sfbplus.c,v 1.12 2001/11/13 06:26:10 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sfbplus.c,v 1.13 2002/03/13 15:05:17 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -389,16 +389,18 @@ sfbp_common_init(ri) wsfont_init(); /* prefer 12 pixel wide font */ - if ((cookie = wsfont_find(NULL, 12, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("sfbp: font table is empty\n"); return; } /* the accelerated sfbp_putchar() needs LSbit left */ - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("sfb: couldn't lock font\n"); return; } diff --git a/sys/dev/tc/stic.c b/sys/dev/tc/stic.c index 5045bb42927..30fe4624dc6 100644 --- a/sys/dev/tc/stic.c +++ b/sys/dev/tc/stic.c @@ -1,4 +1,4 @@ -/* $NetBSD: stic.c,v 1.15 2002/02/22 16:05:27 ad Exp $ */ +/* $NetBSD: stic.c,v 1.16 2002/03/13 15:05:17 ad Exp $ */ /*- * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: stic.c,v 1.15 2002/02/22 16:05:27 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: stic.c,v 1.16 2002/03/13 15:05:17 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -338,10 +338,16 @@ stic_init(struct stic_info *si) /* Get a font and set up screen metrics. */ wsfont_init(); - cookie = wsfont_find(NULL, 0, 0, 0); - if (wsfont_lock(cookie, &si->si_font, - WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R) <= 0) + cookie = wsfont_find(NULL, 12, 0, 2, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 2, WSDISPLAY_FONTORDER_R2L, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + panic("stic_init: font table is empty\n"); + + if (wsfont_lock(cookie, &si->si_font)) panic("stic_init: couldn't lock font\n"); si->si_fontw = si->si_font->fontwidth; diff --git a/sys/dev/tc/tfb.c b/sys/dev/tc/tfb.c index 80cac641c8b..85c7fd0fcc5 100644 --- a/sys/dev/tc/tfb.c +++ b/sys/dev/tc/tfb.c @@ -1,4 +1,4 @@ -/* $NetBSD: tfb.c,v 1.32 2001/11/13 06:26:10 lukem Exp $ */ +/* $NetBSD: tfb.c,v 1.33 2002/03/13 15:05:16 ad Exp $ */ /* * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tfb.c,v 1.32 2001/11/13 06:26:10 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tfb.c,v 1.33 2002/03/13 15:05:16 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -386,15 +386,17 @@ tfb_common_init(ri) wsfont_init(); /* prefer 12 pixel wide font */ - if ((cookie = wsfont_find(NULL, 12, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("tfb: font table is empty\n"); return; } - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("tfb: couldn't lock font\n"); return; } diff --git a/sys/dev/tc/xcfb.c b/sys/dev/tc/xcfb.c index 02eaf42d5e8..8bbbd948565 100644 --- a/sys/dev/tc/xcfb.c +++ b/sys/dev/tc/xcfb.c @@ -1,4 +1,4 @@ -/* $NetBSD: xcfb.c,v 1.25 2001/11/13 06:26:10 lukem Exp $ */ +/* $NetBSD: xcfb.c,v 1.26 2002/03/13 15:05:17 ad Exp $ */ /* * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xcfb.c,v 1.25 2001/11/13 06:26:10 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xcfb.c,v 1.26 2002/03/13 15:05:17 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -291,15 +291,17 @@ xcfb_common_init(ri) wsfont_init(); /* prefer 12 pixel wide font */ - if ((cookie = wsfont_find(NULL, 12, 0, 0)) <= 0) - cookie = wsfont_find(NULL, 0, 0, 0); + cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); + if (cookie <= 0) + cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R, + WSDISPLAY_FONTORDER_L2R); if (cookie <= 0) { printf("xcfb: font table is empty\n"); return; } - if (wsfont_lock(cookie, &ri->ri_font, - WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) { + if (wsfont_lock(cookie, &ri->ri_font)) { printf("xcfb: couldn't lock font\n"); return; } diff --git a/sys/dev/wsfont/wsfont.c b/sys/dev/wsfont/wsfont.c index da8836d592a..96306f806cd 100644 --- a/sys/dev/wsfont/wsfont.c +++ b/sys/dev/wsfont/wsfont.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsfont.c,v 1.24 2002/03/13 10:42:56 ad Exp $ */ +/* $NetBSD: wsfont.c,v 1.25 2002/03/13 15:05:13 ad Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1.24 2002/03/13 10:42:56 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1.25 2002/03/13 15:05:13 ad Exp $"); #include "opt_wsfont.h" @@ -102,54 +102,67 @@ __KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1.24 2002/03/13 10:42:56 ad Exp $"); #include <dev/wsfont/bold8x16.h> #endif +#define WSFONT_IDENT_MASK 0xffffff00 +#define WSFONT_IDENT_SHIFT 8 +#define WSFONT_BITO_MASK 0x000000f0 +#define WSFONT_BITO_SHIFT 4 +#define WSFONT_BYTEO_MASK 0x0000000f +#define WSFONT_BYTEO_SHIFT 0 + +#define WSFONT_BUILTIN 0x01 /* In wsfont.c */ +#define WSFONT_STATIC 0x02 /* Font structures not malloc()ed */ +#define WSFONT_COPY 0x04 /* Copy of existing font in table */ + /* Placeholder struct used for linked list */ struct font { - struct font *next; - struct font *prev; + TAILQ_ENTRY(font) chain; struct wsdisplay_font *font; - u_short lockcount; - u_short cookie; - u_short flg; -}; + u_int lockcount; + u_int cookie; + u_int flags; +}; /* Our list of built-in fonts */ -static struct font *list, builtin_fonts[] = { +static struct font builtin_fonts[] = { #ifdef FONT_BOLD8x16 - { NULL, NULL, &bold8x16, 0, 1, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &bold8x16, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_ISO8x16 - { NULL, NULL, &iso8x16, 0, 2, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &iso8x16, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_COURIER11x18 - { NULL, NULL, &courier11x18, 0, 3, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &courier11x18, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_GALLANT12x22 - { NULL, NULL, &gallant12x22, 0, 4, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &gallant12x22, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_LUCIDA16x29 - { NULL, NULL, &lucida16x29, 0, 5, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &lucida16x29, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_QVSS8x15 - { NULL, NULL, &qvss8x15, 0, 6, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &qvss8x15, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_VT220L8x8 - { NULL, NULL, &vt220l8x8, 0, 7, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &vt220l8x8, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_VT220L8x10 - { NULL, NULL, &vt220l8x10, 0, 8, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &vt220l8x10, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_SONY8x16 - { NULL, NULL, &sony8x16, 0, 9, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &sony8x16, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_SONY12x24 - { NULL, NULL, &sony12x24, 0, 10, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &sony12x24, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif #ifdef FONT_OMRON12x20 - { NULL, NULL, &omron12x20, 0, 11, WSFONT_STATIC | WSFONT_BUILTIN }, + { { NULL }, &omron12x20, 0, 0, WSFONT_STATIC | WSFONT_BUILTIN }, #endif - { NULL, NULL, NULL, 0 }, + { { NULL }, NULL, 0, 0, 0 }, }; +static TAILQ_HEAD(,font) list; +static int ident; + /* Reverse the bit order in a byte */ static const u_char reverse[256] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, @@ -186,13 +199,21 @@ static const u_char reverse[256] = { 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, }; -static struct font *wsfont_find0(int); +static struct font *wsfont_find0(int, int); +static struct font *wsfont_add0(struct wsdisplay_font *, int); static void wsfont_revbit(struct wsdisplay_font *); static void wsfont_revbyte(struct wsdisplay_font *); +static int __inline__ wsfont_make_cookie(int, int, int); + +static int __inline__ +wsfont_make_cookie(int ident, int bito, int byteo) +{ + + return ((ident & WSFONT_IDENT_MASK) | + (bito << WSFONT_BITO_SHIFT) | + (byteo << WSFONT_BYTEO_SHIFT)); +} -/* - * Reverse the bit order of a font - */ static void wsfont_revbit(struct wsdisplay_font *font) { @@ -205,9 +226,6 @@ wsfont_revbit(struct wsdisplay_font *font) *p = reverse[*p]; } -/* - * Reverse the byte order of a font - */ static void wsfont_revbyte(struct wsdisplay_font *font) { @@ -235,56 +253,49 @@ wsfont_revbyte(struct wsdisplay_font *font) } } -/* - * Enumarate the list of fonts - */ void wsfont_enum(void (*cb)(char *, int, int, int)) { struct wsdisplay_font *f; struct font *ent; - int s; - s = splhigh(); - - for (ent = list; ent != NULL; ent = ent->next) { + TAILQ_FOREACH(ent, &list, chain) { f = ent->font; cb(f->name, f->fontwidth, f->fontheight, f->stride); } - - splx(s); } -/* - * Initialize list with WSFONT_BUILTIN fonts - */ void wsfont_init(void) { + struct font *ent; static int again; int i; - + if (again != 0) return; again = 1; - - for (i = 0; builtin_fonts[i].font != NULL; i++) { - builtin_fonts[i].next = list; - list = &builtin_fonts[i]; + + TAILQ_INIT(&list); + ent = builtin_fonts; + + for (i = 0; builtin_fonts[i].font != NULL; i++, ent++) { + ident += (1 << WSFONT_IDENT_SHIFT); + ent->cookie = wsfont_make_cookie(ident, + ent->font->bitorder, ent->font->byteorder); + TAILQ_INSERT_TAIL(&list, ent, chain); } } -/* - * Find a font by cookie. Called at splhigh. - */ static struct font * -wsfont_find0(int cookie) +wsfont_find0(int cookie, int mask) { struct font *ent; - for (ent = list; ent != NULL; ent = ent->next) - if (ent->cookie == cookie) + TAILQ_FOREACH(ent, &list, chain) { + if ((ent->cookie & mask) == (cookie & mask)) return (ent); + } return (NULL); } @@ -309,204 +320,142 @@ wsfont_matches(struct wsdisplay_font *font, char *name, return (1); } -/* - * Find a font. - */ int -wsfont_find(char *name, int width, int height, int stride) +wsfont_find(char *name, int width, int height, int stride, int bito, int byteo) { struct font *ent; - int s; - - s = splhigh(); - for (ent = list; ent != NULL; ent = ent->next) { - if (wsfont_matches(ent->font, name, width, height, stride)) { - splx(s); - return (ent->cookie); - } + TAILQ_FOREACH(ent, &list, chain) { + if (wsfont_matches(ent->font, name, width, height, stride)) + return (wsfont_make_cookie(ent->cookie, bito, byteo)); } - splx(s); return (-1); } -/* - * Add a font to the list. - */ -int -wsfont_add(struct wsdisplay_font *font, int copy) +static struct font * +wsfont_add0(struct wsdisplay_font *font, int copy) { - static int cookiegen = 666; struct font *ent; size_t size; - int s; - - s = splhigh(); - - /* Don't allow exact duplicates */ - if (wsfont_find(font->name, font->fontwidth, font->fontheight, - font->stride) >= 0) { - splx(s); - return (EEXIST); - } - MALLOC(ent, struct font *, sizeof *ent, M_DEVBUF, M_WAITOK); - - ent->lockcount = 0; - ent->flg = 0; - ent->cookie = cookiegen++; - ent->next = list; - ent->prev = NULL; + ent = malloc(sizeof(struct font *), M_DEVBUF, M_WAITOK | M_ZERO); /* Is this font statically allocated? */ if (!copy) { ent->font = font; - ent->flg = WSFONT_STATIC; + ent->flags = WSFONT_STATIC; } else { - MALLOC(ent->font, struct wsdisplay_font *, sizeof *ent->font, - M_DEVBUF, M_WAITOK); - memcpy(ent->font, font, sizeof(*ent->font)); - + ent->font = malloc(sizeof(struct wsdisplay_font), M_DEVBUF, + M_WAITOK | M_ZERO); + size = font->fontheight * font->numchars * font->stride; - MALLOC(ent->font->data, void *, size, M_DEVBUF, M_WAITOK); + ent->font->data = malloc(size, M_DEVBUF, M_WAITOK); memcpy(ent->font->data, font->data, size); - MALLOC(ent->font->name, char *, strlen(font->name) + 1, - M_DEVBUF, M_WAITOK); + + ent->font->name = malloc(strlen(font->name) + 1, M_DEVBUF, + M_WAITOK); strcpy(ent->font->name, font->name); - ent->flg = 0; } - /* Now link into the list and return */ - list = ent; - splx(s); + TAILQ_INSERT_TAIL(&list, ent, chain); + return (ent); +} + +int +wsfont_add(struct wsdisplay_font *font, int copy) +{ + struct font *ent; + + /* Don't allow exact duplicates */ + if (wsfont_find(font->name, font->fontwidth, font->fontheight, + font->stride, 0, 0) >= 0) + return (EEXIST); + + ent = wsfont_add0(font, copy); + + ident += (1 << WSFONT_IDENT_SHIFT); + ent->cookie = wsfont_make_cookie(ident, font->bitorder, + font->byteorder); + return (0); } -/* - * Remove a font. - */ int wsfont_remove(int cookie) { struct font *ent; - int s; - - s = splhigh(); - if ((ent = wsfont_find0(cookie)) == NULL) { - splx(s); + if ((ent = wsfont_find0(cookie, 0xffffffff)) == NULL) return (ENOENT); - } - if ((ent->flg & WSFONT_BUILTIN) != 0 || ent->lockcount != 0) { - splx(s); + if ((ent->flags & WSFONT_BUILTIN) != 0 || ent->lockcount != 0) return (EBUSY); - } - /* Don't free statically allocated font data */ - if ((ent->flg & WSFONT_STATIC) != 0) { - FREE(ent->font->data, M_DEVBUF); - FREE(ent->font->name, M_DEVBUF); - FREE(ent->font, M_DEVBUF); + if ((ent->flags & WSFONT_STATIC) == 0) { + free(ent->font->data, M_DEVBUF); + free(ent->font->name, M_DEVBUF); + free(ent->font, M_DEVBUF); } - /* Remove from list, free entry */ - if (ent->prev) - ent->prev->next = ent->next; - else - list = ent->next; - - if (ent->next) - ent->next->prev = ent->prev; + TAILQ_REMOVE(&list, ent, chain); + free(ent, M_DEVBUF); - FREE(ent, M_DEVBUF); - splx(s); return (0); } -/* - * Lock a given font and return new lockcount. This fails if the cookie - * is invalid, or if the font is already locked and the bit/byte order - * requested by the caller differs. - */ int -wsfont_lock(int cookie, struct wsdisplay_font **ptr, - int bitorder, int byteorder) +wsfont_lock(int cookie, struct wsdisplay_font **ptr) { - struct font *ent; - int s, lc; + struct font *ent, *neu; + int bito, byteo; + + if ((ent = wsfont_find0(cookie, 0xffffffff)) == NULL) { + if ((ent = wsfont_find0(cookie, WSFONT_IDENT_MASK)) == NULL) + return (ENOENT); - s = splhigh(); + if (ent->lockcount != 0) { + neu = wsfont_add0(ent->font, 1); + neu->flags |= WSFONT_COPY; + ent = neu; + } - if ((ent = wsfont_find0(cookie)) != NULL) { - if (bitorder && bitorder != ent->font->bitorder) { - if (ent->lockcount != 0) { - splx(s); - return (-1); - } + bito = (cookie & WSFONT_BITO_MASK) >> WSFONT_BITO_SHIFT; + byteo = (cookie & WSFONT_BYTEO_MASK) >> WSFONT_BYTEO_SHIFT; + + if (bito && bito != ent->font->bitorder) { wsfont_revbit(ent->font); - ent->font->bitorder = bitorder; + ent->font->bitorder = bito; } - if (byteorder && byteorder != ent->font->byteorder) { - if (ent->lockcount) { - splx(s); - return (-1); - } + if (byteo && byteo != ent->font->byteorder) { wsfont_revbyte(ent->font); - ent->font->byteorder = byteorder; + ent->font->byteorder = byteo; } - lc = ++ent->lockcount; - *ptr = ent->font; - } else - lc = -1; - - splx(s); - return (lc); -} - -/* - * Get font flags and lockcount. - */ -int -wsfont_getflg(int cookie, int *flg, int *lc) -{ - struct font *ent; - int s; - - s = splhigh(); - - if ((ent = wsfont_find0(cookie)) != NULL) { - *flg = ent->flg; - *lc = ent->lockcount; + ent->cookie = cookie; } - splx(s); - return (ent != NULL ? 0 : -1); + ent->lockcount++; + *ptr = ent->font; + return (0); } -/* - * Unlock a given font and return new lockcount. - */ int wsfont_unlock(int cookie) { struct font *ent; - int s, lc; - s = splhigh(); + if ((ent = wsfont_find0(cookie, 0xffffffff)) == NULL) + return (ENOENT); - if ((ent = wsfont_find0(cookie)) != NULL) { - if (ent->lockcount == 0) - panic("wsfont_unlock: font not locked\n"); - lc = --ent->lockcount; - } else - lc = -1; + if (ent->lockcount == 0) + panic("wsfont_unlock: font not locked\n"); - splx(s); - return (lc); + if (--ent->lockcount == 0 && (ent->flags & WSFONT_COPY) != 0) + wsfont_remove(cookie); + + return (0); } /* diff --git a/sys/dev/wsfont/wsfont.h b/sys/dev/wsfont/wsfont.h index 78253e8ef01..7078fa8a53b 100644 --- a/sys/dev/wsfont/wsfont.h +++ b/sys/dev/wsfont/wsfont.h @@ -1,7 +1,7 @@ -/* $NetBSD: wsfont.h,v 1.15 2001/10/13 16:05:42 augustss Exp $ */ +/* $NetBSD: wsfont.h,v 1.16 2002/03/13 15:05:14 ad Exp $ */ /*- - * Copyright (c) 1999 The NetBSD Foundation, Inc. + * Copyright (c) 1999, 2000, 2001, 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -40,23 +40,17 @@ #define _WSFONT_H_ 1 /* - * wsfont_find() can be called with any of the parameters as 0, meaning we - * don't care about that aspect of the font. It returns a cookie which - * we can use with the other functions. When more flexibility is required, - * wsfont_enum() should be used. The last two parameters to wsfont_lock() - * are the bit order and byte order required (WSDISPLAY_FONTORDER_L2R or - * WSDISPLAY_FONTORDER_R2L). - * * Example: * * struct wsdisplay_font *font; * int cookie; * - * if ((cookie = wsfont_find(NULL, 8, 16, 0, 0)) <= 0) + * cookie = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R, + * WSDISPLAY_FONTORDER_R2L); + * if (cookie <= 0) * panic("unable to get 8x16 font"); * - * if (wsfont_lock(cookie, &font, WSDISPLAY_FONTORDER_L2R, - * WSDISPLAY_FONTORDER_R2L) <= 0) + * if (wsfont_lock(cookie, &font)) * panic("unable to lock font"); * * ... do stuff ... @@ -66,23 +60,14 @@ struct wsdisplay_font; -/* For wsfont_add() */ -#define WSFONT_BUILTIN (0x01) -#define WSFONT_STATIC (0x02) -#define WSFONT_RDONLY (0x04) - -/* wsfont.c */ void wsfont_init(void); int wsfont_matches(struct wsdisplay_font *, char *, int, int, int); -int wsfont_find(char *, int, int, int); +int wsfont_find(char *, int, int, int, int, int); int wsfont_add(struct wsdisplay_font *, int); int wsfont_remove(int); void wsfont_enum(void (*)(char *, int, int, int)); -int wsfont_lock(int, struct wsdisplay_font **, int, int); +int wsfont_lock(int, struct wsdisplay_font **); int wsfont_unlock(int); -int wsfont_getflg(int, int *, int *); int wsfont_map_unichar(struct wsdisplay_font *, int); -int wsfont_add(struct wsdisplay_font *, int); -int wsfont_remove(int); #endif /* !_WSFONT_H_ */ |
