Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev add an ioctl() to get a list of fonts currently avai...



details:   https://anonhg.NetBSD.org/src/rev/77714ec72e9c
branches:  trunk
changeset: 378696:77714ec72e9c
user:      macallan <macallan%NetBSD.org@localhost>
date:      Sat Apr 24 00:15:37 2021 +0000

description:
add an ioctl() to get a list of fonts currently available via wsfont

diffstat:

 sys/dev/wscons/wsconsio.h  |  22 ++++++++++++++++++++-
 sys/dev/wsfont/wsfontdev.c |  47 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 3 deletions(-)

diffs (118 lines):

diff -r be15e3c1bf72 -r 77714ec72e9c sys/dev/wscons/wsconsio.h
--- a/sys/dev/wscons/wsconsio.h Fri Apr 23 22:53:03 2021 +0000
+++ b/sys/dev/wscons/wsconsio.h Sat Apr 24 00:15:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsconsio.h,v 1.124 2020/10/29 09:08:35 nia Exp $ */
+/* $NetBSD: wsconsio.h,v 1.125 2021/04/24 00:15:37 macallan Exp $ */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -684,4 +684,24 @@ struct wsdisplayio_blit {
 #define WSDISPLAYIO_DOBLIT     _IOWR('W', 105, struct wsdisplayio_blit)
 #define WSDISPLAYIO_WAITBLIT   _IOWR('W', 106, struct wsdisplayio_blit)
 
+struct wsdisplayio_fontdesc {
+               char fd_name[64];
+               uint16_t fd_height;
+               uint16_t fd_width;
+};
+
+struct wsdisplayio_fontinfo {
+       uint32_t fi_buffersize;
+       uint32_t fi_numentries;
+       struct wsdisplayio_fontdesc *fi_fonts;
+};
+
+/*
+ * fill buffer pointed at by fi_fonts with wsdisplayio_fontdesc until either
+ * full or all fonts are listed
+ * just return the number of entries needed if fi_fonts is NULL
+ */
+
+#define WSDISPLAYIO_LISTFONTS  _IOWR('W', 107, struct wsdisplayio_fontinfo)
+
 #endif /* _DEV_WSCONS_WSCONSIO_H_ */
diff -r be15e3c1bf72 -r 77714ec72e9c sys/dev/wsfont/wsfontdev.c
--- a/sys/dev/wsfont/wsfontdev.c        Fri Apr 23 22:53:03 2021 +0000
+++ b/sys/dev/wsfont/wsfontdev.c        Sat Apr 24 00:15:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsfontdev.c,v 1.18 2017/06/23 01:57:40 macallan Exp $ */
+/* $NetBSD: wsfontdev.c,v 1.19 2021/04/24 00:15:37 macallan Exp $ */
 
 /*
  * Copyright (c) 2001
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.18 2017/06/23 01:57:40 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.19 2021/04/24 00:15:37 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,8 +41,14 @@
 
 #include "ioconf.h"
 
+#ifdef WSFONT_DEBUG
+#define DPRINTF printf
+#else
+#define DPRINTF while (0) printf
+#endif
 static int wsfont_isopen;
 
+
 void
 wsfontattach(int n)
 {
@@ -70,6 +76,41 @@ wsfontclose(dev_t dev, int flag, int mod
        return (0);
 }
 
+static void
+fontmatchfunc(struct wsdisplay_font *f, void *cookie, int fontcookie)
+{
+       struct wsdisplayio_fontinfo *fi = cookie;
+       struct wsdisplayio_fontdesc fd;
+       int offset;
+
+       DPRINTF("%s %dx%d\n", f->name, f->fontwidth, f->fontheight);
+       if (fi->fi_fonts != NULL && fi->fi_buffersize > 0) {
+               memset(&fd, 0, sizeof(fd));
+               strncpy(fd.fd_name, f->name, sizeof(fd.fd_name) - 1);
+               fd.fd_width = f->fontwidth;
+               fd.fd_height = f->fontheight;
+               offset = sizeof(struct wsdisplayio_fontdesc) * (fi->fi_numentries + 1);
+               if (offset > fi->fi_buffersize) {
+                       fi->fi_fonts = NULL;
+               } else
+                       copyout(&fd, &fi->fi_fonts[fi->fi_numentries],
+                           sizeof(struct wsdisplayio_fontdesc));
+       }
+       fi->fi_numentries++;
+}
+
+static int
+wsdisplayio_listfonts(struct wsdisplayio_fontinfo *f)
+{
+       void *addr = f->fi_fonts;
+       DPRINTF("%s: %d %d\n", __func__, f->fi_buffersize, f->fi_numentries);
+       f->fi_numentries = 0;
+       wsfont_walk(fontmatchfunc, f);
+       /* check if we ran out of buffer space */
+       if (f->fi_fonts == NULL && addr != NULL) return ENOMEM;
+       return 0;
+}
+
 static int
 wsfontioctl(dev_t dev, u_long cmd, void *data, int flag,
     struct lwp *l)
@@ -101,6 +142,8 @@ wsfontioctl(dev_t dev, u_long cmd, void 
                free(buf, M_DEVBUF);
 #undef d
                return (res);
+       case WSDISPLAYIO_LISTFONTS:
+               return wsdisplayio_listfonts(data);
        default:
                return (EINVAL);
        }



Home | Main Index | Thread Index | Old Index