Reorganise the wsfont stuff slightly so that multiple display adapters

with different bit/byte order requirements can co-exist happily.
This commit is contained in:
ad 2002-03-13 15:05:13 +00:00
parent 17162f3d40
commit b89e39b91a
18 changed files with 271 additions and 307 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: amidisplaycc.c,v 1.4 2002/01/28 09:56:51 aymeric Exp $ */
/* $NetBSD: amidisplaycc.c,v 1.5 2002/03/13 15:05:18 ad Exp $ */
/*-
* Copyright (c) 2000 Jukka Andberg.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: amidisplaycc.c,v 1.4 2002/01/28 09:56:51 aymeric Exp $");
__KERNEL_RCSID(0, "$NetBSD: amidisplaycc.c,v 1.5 2002/03/13 15:05:18 ad Exp $");
/*
* wscons interface to amiga custom chips. Contains the necessary functions
@ -1569,16 +1569,16 @@ amidisplaycc_setnamedfont(struct amidisplaycc_screen *scr, char *fontname)
wsfontcookie = wsfont_find(fontname,
scr->fontwidth,
scr->fontheight,
1);
1,
WSDISPLAY_FONTORDER_L2R,
WSDISPLAY_FONTORDER_L2R);
if (wsfontcookie == -1)
return (EINVAL);
/* So, found a suitable font. Now lock it. */
if (wsfont_lock(wsfontcookie,
&font,
WSDISPLAY_FONTORDER_L2R,
WSDISPLAY_FONTORDER_L2R) == -1)
&font))
return (EINVAL);
/* Ok here we have the font successfully. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: vidcvideo.c,v 1.3 2002/02/18 14:30:20 bjh21 Exp $ */
/* $NetBSD: vidcvideo.c,v 1.4 2002/03/13 15:05:19 ad Exp $ */
/*
* Copyright (c) 2001 Reinoud Zandijk
@ -36,7 +36,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.3 2002/02/18 14:30:20 bjh21 Exp $");
__KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.4 2002/03/13 15:05:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -273,7 +273,7 @@ static void
vidcvideo_config_wscons(dc)
struct fb_devconfig *dc;
{
int i, cookie, font_locked;
int i, cookie, font_not_locked;
/* clear the screen ; why not a memset ? - it was this way so keep it for now */
for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
@ -282,8 +282,11 @@ vidcvideo_config_wscons(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_L2R,
WSDISPLAY_FONTORDER_L2R);
if (cookie <= 0)
cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
WSDISPLAY_FONTORDER_L2R);
if (cookie < 0) {
/* Can I even print here ? */
@ -291,8 +294,7 @@ vidcvideo_config_wscons(dc)
return;
};
font_locked = wsfont_lock(cookie, &dc->rinfo.ri_font,
WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
dc->rinfo.ri_wsfcookie = cookie;
@ -311,7 +313,7 @@ vidcvideo_config_wscons(dc)
vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
if (font_locked < 0) {
if (font_not_locked) {
printf(" warning ... couldn't lock font! ");
};
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pvr.c,v 1.8 2001/03/05 02:45:24 marcus Exp $ */
/* $NetBSD: pvr.c,v 1.9 2002/03/13 15:05:19 ad Exp $ */
/*-
* Copyright (c) 2001 Marcus Comstedt.
@ -65,7 +65,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: pvr.c,v 1.8 2001/03/05 02:45:24 marcus Exp $");
__KERNEL_RCSID(0, "$NetBSD: pvr.c,v 1.9 2002/03/13 15:05:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -213,15 +213,17 @@ pvr_getdevconfig(struct fb_devconfig *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_L2R,
WSDISPLAY_FONTORDER_L2R);
if (cookie <= 0)
cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
WSDISPLAY_FONTORDER_L2R);
if (cookie <= 0) {
printf("pvr: font table is empty\n");
return;
}
if (wsfont_lock(cookie, &dc->rinfo.ri_font,
WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) {
if (wsfont_lock(cookie, &dc->rinfo.ri_font)) {
printf("pvr: unable to lock font\n");
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: gsfb.c,v 1.1 2001/10/16 15:38:37 uch Exp $ */
/* $NetBSD: gsfb.c,v 1.2 2002/03/13 15:05:20 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -356,12 +356,12 @@ gsfb_swinit()
int font;
wsfont_init();
font = wsfont_find(NULL, 8, 16, 0);
font = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
WSDISPLAY_FONTORDER_L2R);
if (font < 0)
return (1);
if (wsfont_lock(font, &gsfb.font, WSDISPLAY_FONTORDER_L2R,
WSDISPLAY_FONTORDER_L2R) < 0)
if (wsfont_lock(font, &gsfb.font))
return (1);
gsfb.screen = &_gsfb_std_screen;

View File

@ -1,4 +1,4 @@
/* $NetBSD: px.c,v 1.37 2001/09/19 19:04:17 thorpej Exp $ */
/* $NetBSD: px.c,v 1.38 2002/03/13 15:05:20 ad Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -43,7 +43,7 @@
#endif
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: px.c,v 1.37 2001/09/19 19:04:17 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: px.c,v 1.38 2002/03/13 15:05:20 ad Exp $");
/*
* px.c: driver for the DEC TURBOchannel 2D and 3D accelerated framebuffers
@ -405,11 +405,12 @@ px_init(fi, slotbase, unit, console)
if (console) {
wsfont_init();
if ((i = wsfont_find(NULL, 0, 0, 2)) <= 0)
i = wsfont_find(NULL, 0, 0, 2, WSDISPLAY_FONTORDER_R2L,
WSDISPLAY_FONTORDER_L2R);
if (i <= 0)
panic("px_init: unable to get font");
if (wsfont_lock(i, &pxi->pxi_font, WSDISPLAY_FONTORDER_R2L,
WSDISPLAY_FONTORDER_L2R) <= 0)
if (wsfont_lock(i, &pxi->pxi_font))
panic("px_init: unable to lock font");
pxi->pxi_wsfcookie = i;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rcons.c,v 1.51 2001/09/19 19:04:17 thorpej Exp $ */
/* $NetBSD: rcons.c,v 1.52 2002/03/13 15:05:20 ad Exp $ */
/*
* Copyright (c) 1995
@ -129,13 +129,17 @@ rcons_connect (info)
wsfont_init();
if (epwf)
cookie = wsfont_find(NULL, 8, 0, 0);
else
cookie = wsfont_find("Gallant", 0, 0, 0);
if (cookie > 0)
wsfont_lock(cookie, &ri.ri_font, bior,
cookie = wsfont_find(NULL, 8, 0, 0, bior,
WSDISPLAY_FONTORDER_L2R);
else
cookie = wsfont_find("Gallant", 0, 0, 0, bior,
WSDISPLAY_FONTORDER_L2R);
if (cookie > 0) {
if (wsfont_lock(cookie, &ri.ri_font))
panic("wsfont_lock failed");
} else
panic("rcons_connect: no font available");
/* Get operations set and set framebugger colormap */
if (rasops_init(&ri, 5000, 80))

View File

@ -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

View File

@ -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;
}

View File

@ -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 ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) {
*cp = ' ';
return (0);
}
}
if (c < ri->ri_font->firstchar) {
*cp = ' ';
return (0);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
if ((ent->flags & WSFONT_STATIC) == 0) {
free(ent->font->data, M_DEVBUF);
free(ent->font->name, M_DEVBUF);
free(ent->font, M_DEVBUF);
}
/* 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);
}
TAILQ_REMOVE(&list, ent, chain);
free(ent, 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;
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;
s = splhigh();
if ((ent = wsfont_find0(cookie, 0xffffffff)) == NULL) {
if ((ent = wsfont_find0(cookie, WSFONT_IDENT_MASK)) == NULL)
return (ENOENT);
if ((ent = wsfont_find0(cookie)) != NULL) {
if (bitorder && bitorder != ent->font->bitorder) {
if (ent->lockcount != 0) {
splx(s);
return (-1);
}
if (ent->lockcount != 0) {
neu = wsfont_add0(ent->font, 1);
neu->flags |= WSFONT_COPY;
ent = neu;
}
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);
}
/*

View File

@ -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_ */