Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/wscons make glyph caches reconfigurable



details:   https://anonhg.NetBSD.org/src/rev/aa3a6b8ebdda
branches:  trunk
changeset: 354056:aa3a6b8ebdda
user:      macallan <macallan%NetBSD.org@localhost>
date:      Fri Jun 02 19:30:10 2017 +0000

description:
make glyph caches reconfigurable

diffstat:

 sys/dev/wscons/wsdisplay_glyphcache.c    |  65 ++++++++++++++++++++++++++-----
 sys/dev/wscons/wsdisplay_glyphcachevar.h |  17 +++++++-
 2 files changed, 68 insertions(+), 14 deletions(-)

diffs (162 lines):

diff -r 8d923c9cd2c1 -r aa3a6b8ebdda sys/dev/wscons/wsdisplay_glyphcache.c
--- a/sys/dev/wscons/wsdisplay_glyphcache.c     Fri Jun 02 19:10:19 2017 +0000
+++ b/sys/dev/wscons/wsdisplay_glyphcache.c     Fri Jun 02 19:30:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wsdisplay_glyphcache.c,v 1.8 2017/06/01 02:45:12 chs Exp $     */
+/*     $NetBSD: wsdisplay_glyphcache.c,v 1.9 2017/06/02 19:30:10 macallan Exp $        */
 
 /*
  * Copyright (c) 2012 Michael Lorenz
@@ -27,9 +27,6 @@
 
 /* 
  * a simple glyph cache in offscreen memory
- * For now it only caches glyphs with the default attribute ( assuming they're
- * the most commonly used glyphs ) but the API should at least not prevent
- * more sophisticated caching algorithms
  */
 
 #ifdef _KERNEL_OPT
@@ -40,6 +37,9 @@
 #include <sys/atomic.h>
 #include <sys/errno.h>
 #include <sys/kmem.h>
+#include <dev/wscons/wsdisplayvar.h>
+#include <dev/rasops/rasops.h>
+#include <dev/wscons/wsdisplay_vconsvar.h>
 #include <dev/wscons/wsdisplay_glyphcachevar.h>
 
 #ifdef GLYPHCACHE_DEBUG
@@ -48,6 +48,8 @@
 #define DPRINTF while (0) printf
 #endif
 
+#define NBUCKETS 32
+
 static inline int
 attr2idx(long attr)
 {
@@ -62,18 +64,42 @@
 glyphcache_init(glyphcache *gc, int first, int lines, int width,
     int cellwidth, int cellheight, long attr)
 {
+
+       /* first the geometry stuff */
+       if (lines < 0) lines = 0;
+       gc->gc_width = width;
+       gc->gc_cellwidth = -1;
+       gc->gc_cellheight = -1;
+       gc->gc_firstline = first;
+       gc->gc_lines = lines;
+       gc->gc_buckets = NULL;
+       gc->gc_numbuckets = 0;
+       gc->gc_buckets = kmem_alloc(sizeof(gc_bucket) * NBUCKETS, KM_SLEEP);
+       gc->gc_nbuckets = NBUCKETS;
+       return glyphcache_reconfig(gc, cellwidth, cellheight, attr);
+
+}
+
+int
+glyphcache_reconfig(glyphcache *gc, int cellwidth, int cellheight, long attr)
+{
        int cache_lines, buckets, i, usedcells = 0, idx;
        gc_bucket *b;
 
-       /* first the geometry stuff */
+       /* see if we actually need to reconfigure anything */
+       if ((gc->gc_cellwidth == cellwidth) &&
+           (gc->gc_cellheight == cellheight) &&
+           ((gc->gc_buckets != NULL) &&
+            (gc->gc_buckets[0].gb_index == attr2idx(attr)))) {
+               return 0;
+       }
+
        gc->gc_cellwidth = cellwidth;
        gc->gc_cellheight = cellheight;
-       gc->gc_firstline = first;
-       gc->gc_cellsperline = width / cellwidth;
-       gc->gc_buckets = NULL;
-       gc->gc_numbuckets = 0;
-       if (lines < 0) lines = 0;
-       cache_lines = lines / cellheight;
+
+       gc->gc_cellsperline = gc->gc_width / cellwidth;
+
+       cache_lines = gc->gc_lines / cellheight;
        gc->gc_numcells = cache_lines * gc->gc_cellsperline;
 
        /* now allocate buckets */
@@ -88,7 +114,7 @@
        if (buckets < 1)
                return ENOMEM;
 
-       gc->gc_buckets = kmem_alloc(sizeof(gc_bucket) * buckets, KM_SLEEP);
+       buckets = min(buckets, gc->gc_nbuckets);
        gc->gc_numbuckets = buckets;
 
        DPRINTF("%s: using %d buckets\n", __func__, buckets);
@@ -120,6 +146,21 @@
 }
 
 void
+glyphcache_adapt(struct vcons_screen *scr, void *cookie)
+{
+       glyphcache *gc = cookie;
+       struct rasops_info *ri = &scr->scr_ri;
+
+       if (ri->ri_wsfcookie != gc->gc_fontcookie) {
+               glyphcache_wipe(gc);
+               gc->gc_fontcookie = ri->ri_wsfcookie;
+       }
+
+       glyphcache_reconfig(gc, ri->ri_font->fontwidth,
+                               ri->ri_font->fontheight, scr->scr_defattr);
+} 
+
+void
 glyphcache_wipe(glyphcache *gc)
 {
        gc_bucket *b;
diff -r 8d923c9cd2c1 -r aa3a6b8ebdda sys/dev/wscons/wsdisplay_glyphcachevar.h
--- a/sys/dev/wscons/wsdisplay_glyphcachevar.h  Fri Jun 02 19:10:19 2017 +0000
+++ b/sys/dev/wscons/wsdisplay_glyphcachevar.h  Fri Jun 02 19:30:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wsdisplay_glyphcachevar.h,v 1.4 2012/10/04 10:26:32 macallan Exp $     */
+/*     $NetBSD: wsdisplay_glyphcachevar.h,v 1.5 2017/06/02 19:30:10 macallan Exp $     */
 
 /*
  * Copyright (c) 2012 Michael Lorenz
@@ -48,8 +48,12 @@
        int gc_cellheight;
        int gc_cellsperline;
        int gc_firstline;       /* first line in vram to use for glyphs */
+       int gc_lines;
+       int gc_width;
+       int gc_fontcookie;
        /* buckets */
-       int gc_numbuckets;
+       int gc_numbuckets;      /* buckets we can use */
+       int gc_nbuckets;        /* buckets allocated */
        gc_bucket *gc_buckets;  /* we allocate as many as we can get into vram */
        gc_bucket *gc_next;     /* bucket the next glyph goes into */
        long gc_underline;      /* draw an underline in glyphcache_add() */
@@ -66,10 +70,19 @@
 
 /* first line, lines, width, cellwidth, cellheight, attr */
 int glyphcache_init(glyphcache *, int, int, int, int, int, long);
+
+/* adapt to changed font */
+int glyphcache_reconfig(glyphcache *, int, int, long);
+
+/* helper for showscreen_cb */
+void glyphcache_adapt(struct vcons_screen *, void *);
+
 /* clear out the cache, for example when returning from X */
 void glyphcache_wipe(glyphcache *);
+
 /* add a glyph to the cache */
 int glyphcache_add(glyphcache *, int, int, int); /* char code, x, y */
+
 /* try to draw a glyph from the cache */
 int glyphcache_try(glyphcache *, int, int, int, long); /* char code, x, y, attr */
 #define        GC_OK   0 /* glyph was in cache and has been drawn */



Home | Main Index | Thread Index | Old Index