summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/dev/rasops/rasops.c86
-rw-r--r--sys/dev/rasops/rasops.h3
-rw-r--r--sys/dev/wsfont/wsfont.c25
-rw-r--r--sys/dev/wsfont/wsfont.h6
4 files changed, 101 insertions, 19 deletions
diff --git a/sys/dev/rasops/rasops.c b/sys/dev/rasops/rasops.c
index c9233eb16b8..f524eac9296 100644
--- a/sys/dev/rasops/rasops.c
+++ b/sys/dev/rasops/rasops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rasops.c,v 1.28 2013/10/18 17:38:34 miod Exp $ */
+/* $OpenBSD: rasops.c,v 1.29 2013/10/20 16:44:47 miod Exp $ */
/* $NetBSD: rasops.c,v 1.35 2001/02/02 06:01:01 marcus Exp $ */
/*-
@@ -176,6 +176,9 @@ int rasops_vcons_eraserows(void *, int, int, long);
int rasops_vcons_alloc_attr(void *, int, int, int, long *);
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 *);
+
/*
* Initialize a 'rasops_info' descriptor.
*/
@@ -1623,3 +1626,84 @@ rasops_vcons_unpack_attr(void *cookie, long attr, int *fg, int *bg,
rasops_unpack_attr(scr->rs_ri, attr, fg, bg, underline);
}
+
+/*
+ * Font management.
+ *
+ * Fonts usable on raster frame buffers are managed by wsfont, and are not
+ * tied to any particular display.
+ */
+
+int
+rasops_add_font(struct rasops_info *ri, struct wsdisplay_font *font)
+{
+ /* only accept matching metrics */
+ if (font->fontwidth != ri->ri_font->fontwidth ||
+ font->fontheight != ri->ri_font->fontheight)
+ return EINVAL;
+
+ /* for raster consoles, only accept ISO Latin-1 or Unicode encoding */
+ if (font->encoding != WSDISPLAY_FONTENC_ISO)
+ return EINVAL;
+
+ if (wsfont_add(font, 1) != 0)
+ return EEXIST; /* name collision */
+
+ font->index = -1; /* do not store in wsdisplay_softc */
+
+ return 0;
+}
+
+int
+rasops_use_font(struct rasops_info *ri, struct wsdisplay_font *font)
+{
+ int wsfcookie;
+ struct wsdisplay_font *wsf;
+ const char *name;
+
+ /* allow an empty font name to revert to the initial font choice */
+ name = font->name;
+ if (*name == '\0')
+ name = NULL;
+
+ wsfcookie = wsfont_find(name, ri->ri_font->fontwidth,
+ ri->ri_font->fontheight, 0);
+ if (wsfcookie < 0) {
+ wsfcookie = wsfont_find(name, 0, 0, 0);
+ if (wsfcookie < 0)
+ return ENOENT; /* font exist, but different metrics */
+ else
+ return EINVAL;
+ }
+ if (wsfont_lock(wsfcookie, &wsf, WSDISPLAY_FONTORDER_KNOWN,
+ WSDISPLAY_FONTORDER_KNOWN) < 0)
+ return EINVAL;
+
+ /* if (ri->ri_wsfcookie >= 0) */
+ wsfont_unlock(ri->ri_wsfcookie);
+ ri->ri_wsfcookie = wsfcookie;
+ ri->ri_font = wsf;
+ ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
+
+ return 0;
+}
+
+int
+rasops_load_font(void *v, void *cookie, struct wsdisplay_font *font)
+{
+ struct rasops_info *ri = v;
+
+ /*
+ * For now, we want to only allow loading fonts of the same
+ * metrics as the currently in-use font. This requires the
+ * rasops struct to have been correctly configured, and a
+ * font to have been selected.
+ */
+ if ((ri->ri_flg & RI_CFGDONE) == 0 || ri->ri_font == NULL)
+ return EINVAL;
+
+ if (font->data != NULL)
+ return rasops_add_font(ri, font);
+ else
+ return rasops_use_font(ri, font);
+}
diff --git a/sys/dev/rasops/rasops.h b/sys/dev/rasops/rasops.h
index c58d1197dbf..bb255ef4c4f 100644
--- a/sys/dev/rasops/rasops.h
+++ b/sys/dev/rasops/rasops.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rasops.h,v 1.13 2013/06/28 20:06:50 kettenis Exp $ */
+/* $OpenBSD: rasops.h,v 1.14 2013/10/20 16:44:48 miod Exp $ */
/* $NetBSD: rasops.h,v 1.13 2000/06/13 13:36:54 ad Exp $ */
/*-
@@ -173,6 +173,7 @@ int rasops_alloc_screen(void *, void **, int *, int *, long *);
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_getchar(void *, int, int, struct wsdisplay_charcell *);
extern const u_char rasops_isgray[16];
diff --git a/sys/dev/wsfont/wsfont.c b/sys/dev/wsfont/wsfont.c
index 0ff612958d1..46e9d7be0e1 100644
--- a/sys/dev/wsfont/wsfont.c
+++ b/sys/dev/wsfont/wsfont.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsfont.c,v 1.33 2013/10/20 09:35:36 miod Exp $ */
+/* $OpenBSD: wsfont.c,v 1.34 2013/10/20 16:44:48 miod Exp $ */
/* $NetBSD: wsfont.c,v 1.17 2001/02/07 13:59:24 ad Exp $ */
/*-
@@ -268,7 +268,7 @@ wsfont_revbyte(struct wsdisplay_font *font)
* Enumerate the list of fonts
*/
void
-wsfont_enum(void (*cb)(char *, int, int, int))
+wsfont_enum(void (*cb)(const char *, int, int, int))
{
struct wsdisplay_font *f;
struct font *ent;
@@ -409,7 +409,7 @@ wsfont_find0(int cookie)
* Find a font.
*/
int
-wsfont_find(char *name, int width, int height, int stride)
+wsfont_find(const char *name, int width, int height, int stride)
{
struct font *ent;
int s;
@@ -445,7 +445,6 @@ wsfont_add(struct wsdisplay_font *font, int copy)
{
static int cookiegen = 666;
struct font *ent;
- size_t size;
int s;
s = splhigh();
@@ -463,20 +462,18 @@ wsfont_add(struct wsdisplay_font *font, int copy)
ent->flg = 0;
ent->cookie = cookiegen++;
- /* Is this font statically allocated? */
- if (!copy) {
- ent->font = font;
- ent->flg = WSFONT_STATIC;
- } else {
+ /*
+ * If we are coming from a WSDISPLAYIO_LDFONT ioctl, we need to
+ * make a copy of the wsdisplay_font struct, but not of font->bits.
+ */
+ if (copy) {
ent->font = (struct wsdisplay_font *)malloc(sizeof *ent->font,
M_DEVBUF, M_WAITOK);
-
memcpy(ent->font, font, sizeof(*ent->font));
-
- size = font->fontheight * font->numchars * font->stride;
- ent->font->data = (void *)malloc(size, M_DEVBUF, M_WAITOK);
- memcpy(ent->font->data, font->data, size);
ent->flg = 0;
+ } else {
+ ent->font = font;
+ ent->flg = WSFONT_STATIC;
}
/* Now link into the list and return */
diff --git a/sys/dev/wsfont/wsfont.h b/sys/dev/wsfont/wsfont.h
index e30d3d69568..4ad947cfcb1 100644
--- a/sys/dev/wsfont/wsfont.h
+++ b/sys/dev/wsfont/wsfont.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsfont.h,v 1.8 2012/01/10 18:53:18 shadchin Exp $ */
+/* $OpenBSD: wsfont.h,v 1.9 2013/10/20 16:44:48 miod Exp $ */
/* $NetBSD: wsfont.h,v 1.12 2000/06/13 13:37:07 ad Exp $ */
/*-
@@ -66,10 +66,10 @@ struct wsdisplay_font;
/* wsfont.c */
void wsfont_init(void);
-int wsfont_find(char *, int, int, int);
+int wsfont_find(const char *, int, int, int);
int wsfont_add(struct wsdisplay_font *, int);
int wsfont_remove(int);
-void wsfont_enum(void (*)(char *, int, int, int));
+void wsfont_enum(void (*)(const char *, int, int, int));
int wsfont_lock(int, struct wsdisplay_font **, int, int);
int wsfont_unlock(int);
int wsfont_map_unichar(struct wsdisplay_font *, int);