1 /* $NetBSD: wsdisplay_glyphcachevar.h,v 1.6 2023/06/08 05:48:41 macallan Exp $ */ 2 3 /* 4 * Copyright (c) 2012 Michael Lorenz 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* a simple glyph cache in offscreen memory */ 29 30 #ifndef WSDISPLAY_GLYPHCACHEVAR_H 31 #define WSDISPLAY_GLYPHCACHEVAR_H 32 33 #include <sys/time.h> 34 35 typedef struct _gc_bucket { 36 int gb_firstcell; 37 int gb_numcells; 38 volatile unsigned int gb_usedcells; 39 int gb_index; /* -1 for unused buckets */ 40 uint32_t gb_map[223]; /* we only care about char codes 0x21 and up */ 41 time_t gb_lastread; 42 } gc_bucket; 43 44 typedef struct _glyphcache { 45 /* geometry */ 46 int gc_numcells; 47 int gc_cellwidth; 48 int gc_cellstride; 49 int gc_cellalign; 50 int gc_cellheight; 51 int gc_cellsperline; 52 int gc_firstline; /* first line in vram to use for glyphs */ 53 int gc_lines; 54 int gc_width; 55 int gc_fontcookie; 56 /* buckets */ 57 int gc_numbuckets; /* buckets we can use */ 58 int gc_nbuckets; /* buckets allocated */ 59 gc_bucket *gc_buckets; /* we allocate as many as we can get into vram */ 60 gc_bucket *gc_next; /* bucket the next glyph goes into */ 61 long gc_underline; /* draw an underline in glyphcache_add() */ 62 int gc_attrmap[256]; /* mapping a colour attribute to a bucket */ 63 /* 64 * method to copy glyphs within vram, 65 * to be initialized before calling glyphcache_init() 66 */ 67 void (*gc_bitblt)(void *, int, int, int, int, int, int, int); 68 void (*gc_rectfill)(void *, int, int, int, int, long); 69 void *gc_blitcookie; 70 int gc_rop; 71 } glyphcache; 72 73 /* first line, lines, width, cellwidth, cellheight, attr */ 74 int glyphcache_init(glyphcache *, int, int, int, int, int, long); 75 76 /* first line, lines, width, cellwidth, cellheight, attr, alignment */ 77 int glyphcache_init_align(glyphcache *, int, int, int, int, int, long, int); 78 79 /* adapt to changed font */ 80 int glyphcache_reconfig(glyphcache *, int, int, long); 81 82 /* helper for showscreen_cb */ 83 void glyphcache_adapt(struct vcons_screen *, void *); 84 85 /* clear out the cache, for example when returning from X */ 86 void glyphcache_wipe(glyphcache *); 87 88 /* add a glyph to the cache */ 89 int glyphcache_add(glyphcache *, int, int, int); /* char code, x, y */ 90 91 /* try to draw a glyph from the cache */ 92 int glyphcache_try(glyphcache *, int, int, int, long); /* char code, x, y, attr */ 93 #define GC_OK 0 /* glyph was in cache and has been drawn */ 94 #define GC_ADD 1 /* glyph is not in cache but can be added */ 95 #define GC_NOPE 2 /* glyph is not in cache and can't be added */ 96 /* 97 * draw an underline in the given attribute 98 * must be called by the driver if glyphcache_try() returns GC_NOPE and for 99 * blanks 100 */ 101 void glyphcache_underline(glyphcache *, int, int, long); 102 103 #endif /* WSDISPLAY_GLYPHCACHEVAR_H */ 104