Home | History | Annotate | Line # | Download | only in wscons
      1 /*	$NetBSD: wsdisplay_glyphcachevar.h,v 1.7 2024/12/06 11:46:11 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_firstcol;	/* first column */
     54 	int gc_lines;
     55 	int gc_width;
     56 	int gc_fontcookie;
     57 	/* buckets */
     58 	int gc_numbuckets;	/* buckets we can use */
     59 	int gc_nbuckets;	/* buckets allocated */
     60 	gc_bucket *gc_buckets;	/* we allocate as many as we can get into vram */
     61 	gc_bucket *gc_next;	/* bucket the next glyph goes into */
     62 	long gc_underline;	/* draw an underline in glyphcache_add() */
     63 	int gc_attrmap[256];	/* mapping a colour attribute to a bucket */
     64 	/*
     65 	 * method to copy glyphs within vram,
     66 	 * to be initialized before calling glyphcache_init()
     67 	 */
     68 	void (*gc_bitblt)(void *, int, int, int, int, int, int, int);
     69 	void (*gc_rectfill)(void *, int, int, int, int, long);
     70 	void *gc_blitcookie;
     71 	int gc_rop;
     72 } glyphcache;
     73 
     74 /* first line, lines, width, cellwidth, cellheight, attr */
     75 int glyphcache_init(glyphcache *, int, int, int, int, int, long);
     76 
     77 /* first x, y, lines, width, cellwidth, cellheight, attr */
     78 int glyphcache_init_x(glyphcache *, int, int, int, int, int, int, long);
     79 
     80 /* first line, lines, width, cellwidth, cellheight, attr, alignment */
     81 int glyphcache_init_align(glyphcache *, int, int, int, int, int, long, int);
     82 
     83 /* adapt to changed font */
     84 int glyphcache_reconfig(glyphcache *, int, int, long);
     85 
     86 /* helper for showscreen_cb */
     87 void glyphcache_adapt(struct vcons_screen *, void *);
     88 
     89 /* clear out the cache, for example when returning from X */
     90 void glyphcache_wipe(glyphcache *);
     91 
     92 /* add a glyph to the cache */
     93 int glyphcache_add(glyphcache *, int, int, int); /* char code, x, y */
     94 
     95 /* try to draw a glyph from the cache */
     96 int glyphcache_try(glyphcache *, int, int, int, long); /* char code, x, y, attr */
     97 #define	GC_OK	0 /* glyph was in cache and has been drawn */
     98 #define GC_ADD	1 /* glyph is not in cache but can be added */
     99 #define GC_NOPE 2 /* glyph is not in cache and can't be added */
    100 /*
    101  * draw an underline in the given attribute
    102  * must be called by the driver if glyphcache_try() returns GC_NOPE and for
    103  * blanks
    104  */
    105 void glyphcache_underline(glyphcache *, int, int, long);
    106 
    107 #endif /* WSDISPLAY_GLYPHCACHEVAR_H */
    108