diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2013-10-20 21:24:02 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2013-10-20 21:24:02 +0000 |
commit | fb33eeebaac60c24bf5ead035da2d63f675dc290 (patch) | |
tree | b6964334238130bf91233521e15ebc711a8d8a83 /sys/dev | |
parent | 10e70977872a9790c42077be5db06d18048385c9 (diff) |
No longer store fonts added with the WSDISPLAYIO_LDFONT ioctl into the
wsdisplay softc. Instead, since the knowledge about available fonts lies in
the parent driver itself, introduce a list_font wsdisplay_accessop which
queries a font index, suitable to use within the WSDISPLAYIO_LSFONT ioctl.
With this in place:
- there is no global wsdisplay limit on the number of fonts loaded. Such a
limit will be enforced by the display drivers themselves.
- built-in kernel fonts will now appear in the list of fonts.
Grow a list_font accesop for rasops, which relies upon wsfont_enum(), which
is turned into something useful (and abortable if you do not need to iterate
further). Not used by any rasops driver yet.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ic/vga.c | 35 | ||||
-rw-r--r-- | sys/dev/rasops/rasops.c | 54 | ||||
-rw-r--r-- | sys/dev/rasops/rasops.h | 3 | ||||
-rw-r--r-- | sys/dev/wscons/wsdisplay.c | 15 | ||||
-rw-r--r-- | sys/dev/wscons/wsdisplayvar.h | 4 | ||||
-rw-r--r-- | sys/dev/wsfont/wsfont.c | 12 | ||||
-rw-r--r-- | sys/dev/wsfont/wsfont.h | 4 |
7 files changed, 102 insertions, 25 deletions
diff --git a/sys/dev/ic/vga.c b/sys/dev/ic/vga.c index 1f97a286aaa..6a536b6bbf4 100644 --- a/sys/dev/ic/vga.c +++ b/sys/dev/ic/vga.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vga.c,v 1.60 2013/10/20 20:07:29 miod Exp $ */ +/* $OpenBSD: vga.c,v 1.61 2013/10/20 21:24:00 miod Exp $ */ /* $NetBSD: vga.c,v 1.28.2.1 2000/06/30 16:27:47 simonb Exp $ */ /*- @@ -245,6 +245,7 @@ void vga_free_screen(void *, void *); int vga_show_screen(void *, void *, int, void (*) (void *, int, int), void *); int vga_load_font(void *, void *, struct wsdisplay_font *); +int vga_list_font(void *, struct wsdisplay_font *); void vga_scrollback(void *, void *, int); void vga_burner(void *v, u_int on, u_int flags); int vga_getchar(void *, int, int, struct wsdisplay_charcell *); @@ -258,6 +259,7 @@ const struct wsdisplay_accessops vga_accessops = { .free_screen = vga_free_screen, .show_screen = vga_show_screen, .load_font = vga_load_font, + .list_font = vga_list_font, .scrollback = vga_scrollback, .getchar = vga_getchar, .burn_screen = vga_burner @@ -499,7 +501,7 @@ vga_init(struct vga_config *vc, bus_space_tag_t iot, bus_space_tag_t memt) vc->vc_fonts[0] = &vga_builtinfont; for (i = 1; i < 8; i++) - vc->vc_fonts[i] = 0; + vc->vc_fonts[i] = NULL; vc->currentfontset1 = vc->currentfontset2 = 0; @@ -890,6 +892,35 @@ vga_load_font(void *v, void *cookie, struct wsdisplay_font *data) return (0); } +int +vga_list_font(void *v, struct wsdisplay_font *data) +{ + struct vga_config *vc = v; + struct vgafont *f; + + if (data->index < 0 || data->index >= nitems(vc->vc_fonts)) + return EINVAL; + + if ((f = vc->vc_fonts[data->index]) == NULL) + return EINVAL; + + strlcpy(data->name, f->name, sizeof data->name); +#ifdef notyet + data->firstchar = f->firstchar; + data->numchars = f->numchars; +#else + data->firstchar = 0; + data->numchars = 256; +#endif + data->encoding = f->encoding; + data->fontwidth = 8; + data->fontheight = f->height; + data->stride = 1; + data->bitorder = data->byteorder = WSDISPLAY_FONTORDER_L2R; + + return (0); +} + void vga_scrollback(void *v, void *cookie, int lines) { diff --git a/sys/dev/rasops/rasops.c b/sys/dev/rasops/rasops.c index f524eac9296..1d561e6a23b 100644 --- a/sys/dev/rasops/rasops.c +++ b/sys/dev/rasops/rasops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rasops.c,v 1.29 2013/10/20 16:44:47 miod Exp $ */ +/* $OpenBSD: rasops.c,v 1.30 2013/10/20 21:24:00 miod Exp $ */ /* $NetBSD: rasops.c,v 1.35 2001/02/02 06:01:01 marcus Exp $ */ /*- @@ -178,6 +178,7 @@ void rasops_vcons_unpack_attr(void *, long, int *, int *, int *); int rasops_add_font(struct rasops_info *, struct wsdisplay_font *); int rasops_use_font(struct rasops_info *, struct wsdisplay_font *); +int rasops_list_font_cb(void *, struct wsdisplay_font *); /* * Initialize a 'rasops_info' descriptor. @@ -1707,3 +1708,54 @@ rasops_load_font(void *v, void *cookie, struct wsdisplay_font *font) else return rasops_use_font(ri, font); } + +struct rasops_list_font_ctx { + struct rasops_info *ri; + int cnt; + struct wsdisplay_font *font; +}; + +int +rasops_list_font_cb(void *cbarg, struct wsdisplay_font *font) +{ + struct rasops_list_font_ctx *ctx = cbarg; + + if (font->fontheight != ctx->ri->ri_font->fontheight || + font->fontwidth != ctx->ri->ri_font->fontwidth) + return 0; + + if (ctx->cnt-- == 0) { + ctx->font = font; + return 1; + } + + return 0; +} + +int +rasops_list_font(void *v, struct wsdisplay_font *font) +{ + struct rasops_info *ri = v; + struct rasops_list_font_ctx ctx; + int idx; + + if ((ri->ri_flg & RI_CFGDONE) == 0 || ri->ri_font == NULL) + return EINVAL; + + if (font->index < 0) + return EINVAL; + + ctx.ri = ri; + ctx.cnt = font->index; + ctx.font = NULL; + wsfont_enum(rasops_list_font_cb, &ctx); + + if (ctx.font == NULL) + return EINVAL; + + idx = font->index; + *font = *ctx.font; /* struct copy */ + font->index = idx; + font->cookie = font->data = NULL; /* don't leak kernel pointers */ + return 0; +} diff --git a/sys/dev/rasops/rasops.h b/sys/dev/rasops/rasops.h index bb255ef4c4f..bda5e40e1a3 100644 --- a/sys/dev/rasops/rasops.h +++ b/sys/dev/rasops/rasops.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rasops.h,v 1.14 2013/10/20 16:44:48 miod Exp $ */ +/* $OpenBSD: rasops.h,v 1.15 2013/10/20 21:24:00 miod Exp $ */ /* $NetBSD: rasops.h,v 1.13 2000/06/13 13:36:54 ad Exp $ */ /*- @@ -174,6 +174,7 @@ void rasops_free_screen(void *, void *); int rasops_show_screen(void *, void *, int, void (*)(void *, int, int), void *); int rasops_load_font(void *, void *, struct wsdisplay_font *); +int rasops_list_font(void *, struct wsdisplay_font *); int rasops_getchar(void *, int, int, struct wsdisplay_charcell *); extern const u_char rasops_isgray[16]; diff --git a/sys/dev/wscons/wsdisplay.c b/sys/dev/wscons/wsdisplay.c index a59b9d575ae..0eb6c07260b 100644 --- a/sys/dev/wscons/wsdisplay.c +++ b/sys/dev/wscons/wsdisplay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsdisplay.c,v 1.115 2013/10/20 13:20:14 miod Exp $ */ +/* $OpenBSD: wsdisplay.c,v 1.116 2013/10/20 21:24:01 miod Exp $ */ /* $NetBSD: wsdisplay.c,v 1.82 2005/02/27 00:27:52 perry Exp $ */ /* @@ -177,8 +177,6 @@ struct wsdisplay_softc { int sc_burnflags; #endif - struct wsdisplay_font sc_fonts[WSDISPLAY_MAXFONT]; - int sc_isconsole; int sc_flags; @@ -1343,8 +1341,6 @@ wsdisplay_cfg_ioctl(struct wsdisplay_softc *sc, u_long cmd, caddr_t data, #define d ((struct wsdisplay_font *)data) if (!sc->sc_accessops->load_font) return (EINVAL); - if (d->index >= WSDISPLAY_MAXFONT) - return (EINVAL); fontsz = d->fontheight * d->stride * d->numchars; if (fontsz > WSDISPLAY_MAXFONTSZ) return (EINVAL); @@ -1360,15 +1356,14 @@ wsdisplay_cfg_ioctl(struct wsdisplay_softc *sc, u_long cmd, caddr_t data, (*sc->sc_accessops->load_font)(sc->sc_accesscookie, 0, d); if (error) free(buf, M_DEVBUF); - else if (d->index >= 0 || d->index < WSDISPLAY_MAXFONT) - sc->sc_fonts[d->index] = *d; return (error); case WSDISPLAYIO_LSFONT: - if (d->index < 0 || d->index >= WSDISPLAY_MAXFONT) + if (!sc->sc_accessops->list_font) return (EINVAL); - *d = sc->sc_fonts[d->index]; - return (0); + error = + (*sc->sc_accessops->list_font)(sc->sc_accesscookie, d); + return (error); case WSDISPLAYIO_DELFONT: return (EINVAL); diff --git a/sys/dev/wscons/wsdisplayvar.h b/sys/dev/wscons/wsdisplayvar.h index c829d252f8f..35d719b6ee5 100644 --- a/sys/dev/wscons/wsdisplayvar.h +++ b/sys/dev/wscons/wsdisplayvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsdisplayvar.h,v 1.27 2013/08/20 17:44:36 kettenis Exp $ */ +/* $OpenBSD: wsdisplayvar.h,v 1.28 2013/10/20 21:24:01 miod Exp $ */ /* $NetBSD: wsdisplayvar.h,v 1.30 2005/02/04 02:10:49 perry Exp $ */ /* @@ -57,7 +57,6 @@ struct device; */ #define WSDISPLAY_MAXSCREEN 12 -#define WSDISPLAY_MAXFONT 8 /* * Emulation functions, for displays that can support glass-tty terminal @@ -141,6 +140,7 @@ struct wsdisplay_accessops { int (*show_screen)(void *, void *, int, void (*) (void *, int, int), void *); int (*load_font)(void *, void *, struct wsdisplay_font *); + int (*list_font)(void *, struct wsdisplay_font *); void (*scrollback)(void *, void *, int); int (*getchar)(void *, int, int, struct wsdisplay_charcell *); void (*burn_screen)(void *, u_int, u_int); diff --git a/sys/dev/wsfont/wsfont.c b/sys/dev/wsfont/wsfont.c index 46e9d7be0e1..4720de12f64 100644 --- a/sys/dev/wsfont/wsfont.c +++ b/sys/dev/wsfont/wsfont.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsfont.c,v 1.34 2013/10/20 16:44:48 miod Exp $ */ +/* $OpenBSD: wsfont.c,v 1.35 2013/10/20 21:24:01 miod Exp $ */ /* $NetBSD: wsfont.c,v 1.17 2001/02/07 13:59:24 ad Exp $ */ /*- @@ -268,18 +268,16 @@ wsfont_revbyte(struct wsdisplay_font *font) * Enumerate the list of fonts */ void -wsfont_enum(void (*cb)(const char *, int, int, int)) +wsfont_enum(int (*cb)(void *, struct wsdisplay_font *), void *cbarg) { - struct wsdisplay_font *f; struct font *ent; int s; s = splhigh(); - TAILQ_FOREACH(ent, &list, chain) { - f = ent->font; - cb(f->name, f->fontwidth, f->fontheight, f->stride); - } + TAILQ_FOREACH(ent, &list, chain) + if (cb(cbarg, ent->font) != 0) + break; splx(s); } diff --git a/sys/dev/wsfont/wsfont.h b/sys/dev/wsfont/wsfont.h index 4ad947cfcb1..f1b989ec300 100644 --- a/sys/dev/wsfont/wsfont.h +++ b/sys/dev/wsfont/wsfont.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsfont.h,v 1.9 2013/10/20 16:44:48 miod Exp $ */ +/* $OpenBSD: wsfont.h,v 1.10 2013/10/20 21:24:01 miod Exp $ */ /* $NetBSD: wsfont.h,v 1.12 2000/06/13 13:37:07 ad Exp $ */ /*- @@ -69,7 +69,7 @@ void wsfont_init(void); int wsfont_find(const char *, int, int, int); int wsfont_add(struct wsdisplay_font *, int); int wsfont_remove(int); -void wsfont_enum(void (*)(const char *, int, int, int)); +void wsfont_enum(int (*)(void *, struct wsdisplay_font *), void *); int wsfont_lock(int, struct wsdisplay_font **, int, int); int wsfont_unlock(int); int wsfont_map_unichar(struct wsdisplay_font *, int); |