summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Cambus <fcambus@cvs.openbsd.org>2017-08-18 20:19:37 +0000
committerFrederic Cambus <fcambus@cvs.openbsd.org>2017-08-18 20:19:37 +0000
commit2c2f39062eb4351fc9fba3074f4b0e79a8ebaed1 (patch)
tree67d2eb5863ade7887d0b77aa8ffc787001a7f5eb
parent8da62c95a9dc6861d981c6398f9098ab87fb116d (diff)
Add compressed fonts support in the kernel.
The wsdisplay_font structure has been modified to add two new members (zdata and zdata_len) to store compressed font data and its size. We define compressed fonts by setting the data field to NULL and populating the zdata and zdata_len fields. In wsfont_lock(), we check if the selected font needs to be inflated, and we call the newly introduced wsfont_inflate() if required. OK kettenis@
-rw-r--r--sys/dev/wscons/wsconsio.h4
-rw-r--r--sys/dev/wsfont/wsfont.c45
2 files changed, 47 insertions, 2 deletions
diff --git a/sys/dev/wscons/wsconsio.h b/sys/dev/wscons/wsconsio.h
index de79bd627ff..62f0c4706c1 100644
--- a/sys/dev/wscons/wsconsio.h
+++ b/sys/dev/wscons/wsconsio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsconsio.h,v 1.83 2017/06/15 11:48:49 fcambus Exp $ */
+/* $OpenBSD: wsconsio.h,v 1.84 2017/08/18 20:19:36 fcambus Exp $ */
/* $NetBSD: wsconsio.h,v 1.74 2005/04/28 07:15:44 martin Exp $ */
/*
@@ -514,6 +514,8 @@ struct wsdisplay_font {
#define WSDISPLAY_FONTORDER_R2L 2
void *cookie;
void *data;
+ void *zdata;
+ u_int zdata_len;
};
#define WSDISPLAYIO_LDFONT _IOW ('W', 77, struct wsdisplay_font)
#define WSDISPLAYIO_LSFONT _IOWR('W', 78, struct wsdisplay_font)
diff --git a/sys/dev/wsfont/wsfont.c b/sys/dev/wsfont/wsfont.c
index 24eec85d56b..e4d41c37274 100644
--- a/sys/dev/wsfont/wsfont.c
+++ b/sys/dev/wsfont/wsfont.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsfont.c,v 1.49 2017/08/17 20:21:53 kettenis Exp $ */
+/* $OpenBSD: wsfont.c,v 1.50 2017/08/18 20:19:36 fcambus Exp $ */
/* $NetBSD: wsfont.c,v 1.17 2001/02/07 13:59:24 ad Exp $ */
/*-
@@ -40,6 +40,8 @@
#include <dev/wscons/wsconsio.h>
#include <dev/wsfont/wsfont.h>
+#include <lib/libz/zlib.h>
+
#include "wsfont_glue.h" /* NRASOPS_ROTATION */
#undef HAVE_FONT
@@ -155,6 +157,7 @@ static const u_char reverse[256] = {
#endif
static struct font *wsfont_find0(int);
+static int wsfont_inflate(struct wsdisplay_font *);
#ifdef INCLUDE_FONT_BIT_ENDIANNESS_SWAP_CODE
@@ -528,6 +531,12 @@ wsfont_lock(int cookie, struct wsdisplay_font **ptr, int bitorder,
s = splhigh();
if ((ent = wsfont_find0(cookie)) != NULL) {
+ /* Decompress font data if necessary */
+ if (ent->font->data == NULL &&
+ ent->font->zdata && ent->font->zdata_len)
+ if (wsfont_inflate(ent->font))
+ return -1;
+
if (bitorder && bitorder != ent->font->bitorder) {
#ifdef INCLUDE_FONT_BIT_ENDIANNESS_SWAP_CODE
if (ent->lockcount) {
@@ -753,3 +762,37 @@ wsfont_map_unichar(struct wsdisplay_font *font, int c)
return (-1);
}
+
+/*
+ * Inflate a compressed font
+ */
+static int
+wsfont_inflate(struct wsdisplay_font *font) {
+ int fontdata_len = font->fontheight * font->stride * font->numchars;
+ z_stream zstream;
+
+ font->data = malloc(fontdata_len, M_DEVBUF, M_WAITOK);
+ if (font->data == NULL)
+ return ENOMEM;
+
+ memset(&zstream, 0, sizeof(zstream));
+ zstream.next_in = font->zdata;
+ zstream.avail_in = font->zdata_len;
+ zstream.next_out = font->data;
+ zstream.avail_out = fontdata_len;
+ zstream.opaque = Z_NULL;
+
+ if (inflateInit(&zstream) != Z_OK)
+ return -1;
+
+ if (inflate(&zstream, Z_FINISH) != Z_STREAM_END)
+ return -1;
+
+ if (inflateEnd(&zstream) != Z_OK)
+ return -1;
+
+ if (zstream.total_out != fontdata_len)
+ return -1;
+
+ return 0;
+}