Home | History | Annotate | Line # | Download | only in rasops
rasops.h revision 1.44
      1 /* 	$NetBSD: rasops.h,v 1.44 2019/08/07 11:47:33 rin Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _RASOPS_H_
     33 #define _RASOPS_H_ 1
     34 
     35 #include <dev/wscons/wsconsio.h>
     36 #include <dev/wsfont/wsfont.h>
     37 
     38 /* For rasops_info::ri_flg */
     39 #define RI_FULLCLEAR	0x01	/* eraserows() hack to clear full screen */
     40 #define RI_FORCEMONO	0x02	/* monochrome output even if we can do color */
     41 #define RI_BSWAP	0x04	/* framebuffer endianness doesn't match CPU */
     42 #define RI_CURSOR	0x08	/* cursor is switched on */
     43 #define RI_CLEAR	0x10	/* clear display on startup */
     44 #define RI_CENTER	0x20	/* center onscreen output */
     45 #define RI_CURSORCLIP	0x40	/* cursor is currently clipped */
     46 #define RI_CFGDONE	0x80	/* rasops_reconfig() completed successfully */
     47 #define RI_ROTATE_CW	0x100	/* display is rotated, quarter clockwise */
     48 #define RI_ROTATE_CCW	0x200	/* display is rotated, quarter counter-clockwise */
     49 #define RI_ROTATE_UD	0x400	/* display is rotated, upside-down */
     50 #define RI_ROTATE_MASK	0x700
     51 /*
     52  * if you call rasops_init() or rasops_reconfig() in a context where it is not
     53  * safe to call kmem_alloc(), like early on during kernel startup, you MUST set
     54  * RI_NO_AUTO to keep rasops from trying to allocate memory for autogenerated
     55  * box drawing characters
     56  */
     57 #define	RI_NO_AUTO	0x800	/* do not generate box drawing characters */
     58 /*
     59  * Set this if your driver's putchar() method supports anti-aliased fonts in
     60  * the given video mode. Without this flag rasops_init() will only ever pick
     61  * monochrome bitmap fonts.
     62  */
     63 #define RI_ENABLE_ALPHA	0x1000
     64 /* set this in order to use r3g3b2 'true' colour in 8 bit */
     65 #define RI_8BIT_IS_RGB	0x2000
     66 /*
     67  * drivers can set this to tell the font selection code that they'd rather
     68  * use alpha fonts
     69  */
     70 #define RI_PREFER_ALPHA	0x4000
     71 
     72 struct rasops_info {
     73 	/* These must be filled in by the caller */
     74 	int	ri_depth;	/* depth in bits */
     75 	uint8_t	*ri_bits;	/* ptr to bits */
     76 	int	ri_width;	/* width (pels) */
     77 	int	ri_height;	/* height (pels) */
     78 	int	ri_stride;	/* stride in bytes */
     79 
     80 	/*
     81 	 * If you want shadow framebuffer support, point ri_hwbits
     82 	 * to the real framebuffer, and ri_bits to the shadow framebuffer
     83 	 */
     84 	uint8_t	*ri_hwbits;
     85 
     86 	/*
     87 	 * These can optionally be left zeroed out. If you fill ri_font,
     88 	 * but aren't using wsfont, set ri_wsfcookie to -1.
     89 	 */
     90 	struct	wsdisplay_font *ri_font;
     91 	struct	wsdisplay_font ri_optfont;
     92 	int	ri_wsfcookie;	/* wsfont cookie */
     93 	void	*ri_hw;		/* driver private data; ignored by rasops */
     94 	int	ri_crow;	/* cursor row */
     95 	int	ri_ccol;	/* cursor column */
     96 	int	ri_flg;		/* various operational flags */
     97 
     98 	/*
     99 	 * These are optional and will default if zero. Meaningless
    100 	 * on depths other than 15, 16, 24 and 32 bits per pel. On
    101 	 * 24 bit displays, ri_{r,g,b}num must be 8.
    102 	 */
    103 	uint8_t	ri_rnum;	/* number of bits for red */
    104 	uint8_t	ri_gnum;	/* number of bits for green */
    105 	uint8_t	ri_bnum;	/* number of bits for blue */
    106 	uint8_t	ri_rpos;	/* which bit red starts at */
    107 	uint8_t	ri_gpos;	/* which bit green starts at */
    108 	uint8_t	ri_bpos;	/* which bit blue starts at */
    109 
    110 	/* These are filled in by rasops_init() */
    111 	int	ri_emuwidth;	/* width we actually care about */
    112 	int	ri_emuheight;	/* height we actually care about */
    113 	int	ri_emustride;	/* bytes per row we actually care about */
    114 	int	ri_rows;	/* number of rows (characters, not pels) */
    115 	int	ri_cols;	/* number of columns (characters, not pels) */
    116 	int	ri_pelbytes;	/* bytes per pel (may be zero) */
    117 	int	ri_fontscale;	/* fontheight * fontstride */
    118 	int	ri_xscale;	/* fontwidth * pelbytes */
    119 	int	ri_yscale;	/* fontheight * stride */
    120 	uint8_t	*ri_origbits;	/* where screen bits actually start */
    121 	uint8_t *ri_hworigbits;	/* where hw bits actually start */
    122 	int	ri_xorigin;	/* where ri_bits begins (x) */
    123 	int	ri_yorigin;	/* where ri_bits begins (y) */
    124 	uint32_t
    125 		ri_devcmap[16]; /* color -> framebuffer data */
    126 
    127 	/* The emulops you need to use, and the screen caps for wscons */
    128 	struct	wsdisplay_emulops ri_ops;
    129 	int	ri_caps;
    130 
    131 	/* Callbacks so we can share some code */
    132 	void	(*ri_do_cursor)(struct rasops_info *);
    133 
    134 	/* buffer capable of single-row pixels */
    135 	void	*ri_buf;
    136 	size_t	ri_buflen;
    137 
    138 	/* 4x1 stamp for optimized character blitting */
    139 	void	*ri_stamp;
    140 	long	ri_stamp_attr;
    141 	size_t	ri_stamp_len;
    142 
    143 #if NRASOPS_ROTATION > 0
    144 	/* Used to intercept putchar to permit display rotation */
    145 	struct	wsdisplay_emulops ri_real_ops;
    146 #endif
    147 };
    148 
    149 #define CHAR_IN_FONT(c,font) 					\
    150        ((c) >= (font)->firstchar && 				\
    151 	((c) - (font)->firstchar) < (font)->numchars)
    152 
    153 #define PICK_FONT(ri, c) (((c & WSFONT_FLAGS_MASK) == WSFONT_FLAG_OPT) && \
    154 			  (ri->ri_optfont.data != NULL)) ? \
    155 			 &ri->ri_optfont : ri->ri_font
    156 
    157 /*
    158  * rasops_init().
    159  *
    160  * Integer parameters are the number of rows and columns we'd *like*.
    161  *
    162  * In terms of optimization, fonts that are a multiple of 8 pixels wide
    163  * work the best.
    164  *
    165  * rasops_init() takes care of rasops_reconfig(). The parameters to both
    166  * are the same. If calling rasops_reconfig() to change the font and
    167  * ri_wsfcookie >= 0, you must call wsfont_unlock() on it, and reset it
    168  * to -1 (or a new, valid cookie).
    169  */
    170 
    171 /* rasops.c */
    172 int	rasops_init(struct rasops_info *, int, int);
    173 int	rasops_reconfig(struct rasops_info *, int, int);
    174 void	rasops_unpack_attr(long, int *, int *, int *);
    175 int	rasops_get_cmap(struct rasops_info *, uint8_t *, size_t);
    176 
    177 extern const uint8_t	rasops_cmap[256 * 3];
    178 
    179 #ifdef _RASOPS_PRIVATE
    180 void	rasops_eraserows(void *, int, int, long);
    181 void	rasops_erasecols(void *, int, int, int, long);
    182 
    183 /*
    184  * Per-depth initialization functions.
    185  */
    186 void	rasops1_init(struct rasops_info *);
    187 void	rasops2_init(struct rasops_info *);
    188 void	rasops4_init(struct rasops_info *);
    189 void	rasops8_init(struct rasops_info *);
    190 void	rasops15_init(struct rasops_info *);
    191 void	rasops24_init(struct rasops_info *);
    192 void	rasops32_init(struct rasops_info *);
    193 
    194 #define	DELTA(p, d, cast) ((p) = (cast)((uint8_t *)(p) + (d)))
    195 
    196 #define	FONT_GLYPH(uc, font, ri)					\
    197 	((uint8_t *)(font)->data + ((uc) - ((font)->firstchar)) *	\
    198 	    (ri)->ri_fontscale)
    199 
    200 static __inline void
    201 rasops_memset32(void *p, uint32_t val, size_t bytes)
    202 {
    203 	int slop1, slop2, full;
    204 	uint8_t *dp = (uint8_t *)p;
    205 
    206 	if (bytes == 1) {
    207 		*dp = val;
    208 		return;
    209 	}
    210 
    211 	slop1 = (4 - ((uintptr_t)dp & 3)) & 3;
    212 	slop2 = (bytes - slop1) & 3;
    213 	full = (bytes - slop1 /* - slop2 */) >> 2;
    214 
    215 	if (slop1 & 1)
    216 		*dp++ = val;
    217 
    218 	if (slop1 & 2) {
    219 		*(uint16_t *)dp = val;
    220 		dp += 2;
    221 	}
    222 
    223 	for (; full; full--) {
    224 		*(uint32_t *)dp = val;
    225 		dp += 4;
    226 	}
    227 
    228 	if (slop2 & 2) {
    229 		*(uint16_t *)dp = val;
    230 		dp += 2;
    231 	}
    232 
    233 	if (slop2 & 1)
    234 		*dp = val;
    235 
    236 	return;
    237 }
    238 
    239 static __inline uint32_t
    240 be32uatoh(uint8_t *p)
    241 {
    242 	uint32_t u;
    243 
    244 	u  = p[0]; u <<= 8;
    245 	u |= p[1]; u <<= 8;
    246 	u |= p[2]; u <<= 8;
    247 	u |= p[3];
    248 	return u;
    249 }
    250 #endif /* _RASOPS_PRIVATE */
    251 
    252 #endif /* _RASOPS_H_ */
    253