1 /* $NetBSD: wsdisplay_glyphcachevar.h,v 1.4 2012/10/04 10:26:32 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_cellheight; 49 int gc_cellsperline; 50 int gc_firstline; /* first line in vram to use for glyphs */ 51 /* buckets */ 52 int gc_numbuckets; 53 gc_bucket *gc_buckets; /* we allocate as many as we can get into vram */ 54 gc_bucket *gc_next; /* bucket the next glyph goes into */ 55 long gc_underline; /* draw an underline in glyphcache_add() */ 56 int gc_attrmap[256]; /* mapping a colour attribute to a bucket */ 57 /* 58 * method to copy glyphs within vram, 59 * to be initialized before calling glyphcache_init() 60 */ 61 void (*gc_bitblt)(void *, int, int, int, int, int, int, int); 62 void (*gc_rectfill)(void *, int, int, int, int, long); 63 void *gc_blitcookie; 64 int gc_rop; 65 } glyphcache; 66 67 /* first line, lines, width, cellwidth, cellheight, attr */ 68 int glyphcache_init(glyphcache *, int, int, int, int, int, long); 69 /* clear out the cache, for example when returning from X */ 70 void glyphcache_wipe(glyphcache *); 71 /* add a glyph to the cache */ 72 int glyphcache_add(glyphcache *, int, int, int); /* char code, x, y */ 73 /* try to draw a glyph from the cache */ 74 int glyphcache_try(glyphcache *, int, int, int, long); /* char code, x, y, attr */ 75 #define GC_OK 0 /* glyph was in cache and has been drawn */ 76 #define GC_ADD 1 /* glyph is not in cache but can be added */ 77 #define GC_NOPE 2 /* glyph is not in cache and can't be added */ 78 /* 79 * draw an underline in the given attribute 80 * must be called by the driver if glyphcache_try() returns GC_NOPE and for 81 * blanks 82 */ 83 void glyphcache_underline(glyphcache *, int, int, long); 84 85 #endif /* WSDISPLAY_GLYPHCACHEVAR_H */ 86