Home | History | Annotate | Line # | Download | only in rasops
      1 /* 	$NetBSD: rasops8.c,v 1.51 2019/08/14 00:51:10 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 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.51 2019/08/14 00:51:10 rin Exp $");
     34 
     35 #ifdef _KERNEL_OPT
     36 #include "opt_rasops.h"
     37 #endif
     38 
     39 #include <sys/param.h>
     40 
     41 #include <dev/wscons/wsdisplayvar.h>
     42 #include <dev/wscons/wsconsio.h>
     43 
     44 #define	_RASOPS_PRIVATE
     45 #define	RASOPS_DEPTH	8
     46 #include <dev/rasops/rasops.h>
     47 
     48 static void 	rasops8_putchar(void *, int, int, u_int, long);
     49 static void 	rasops8_putchar_aa(void *, int, int, u_int, long);
     50 #ifndef RASOPS_SMALL
     51 static void 	rasops8_putchar8(void *, int, int, u_int, long);
     52 static void 	rasops8_putchar12(void *, int, int, u_int, long);
     53 static void 	rasops8_putchar16(void *, int, int, u_int, long);
     54 static void	rasops8_makestamp(struct rasops_info *ri, long);
     55 #endif
     56 
     57 #ifndef RASOPS_SMALL
     58 /* stamp for optimized character blitting */
     59 static uint32_t			stamp[16];
     60 static long			stamp_attr;
     61 static struct rasops_info	*stamp_ri;
     62 
     63 /*
     64  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     65  * destination = STAMP_READ(offset)
     66  */
     67 #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 2 : (fb) << 2)
     68 #define	STAMP_MASK		(0xf << 2)
     69 #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     70 #endif
     71 
     72 /*
     73  * Initialize a 'rasops_info' descriptor for this depth.
     74  */
     75 void
     76 rasops8_init(struct rasops_info *ri)
     77 {
     78 
     79 	if (ri->ri_flg & RI_8BIT_IS_RGB) {
     80 		ri->ri_rnum = ri->ri_gnum = 3;
     81 		ri->ri_bnum = 2;
     82 
     83 		ri->ri_rpos = 5;
     84 		ri->ri_gpos = 2;
     85 		ri->ri_bpos = 0;
     86 	}
     87 
     88 	if (FONT_IS_ALPHA(ri->ri_font)) {
     89 		ri->ri_ops.putchar = rasops8_putchar_aa;
     90 		return;
     91 	}
     92 
     93 	switch (ri->ri_font->fontwidth) {
     94 #ifndef RASOPS_SMALL
     95 	case 8:
     96 		ri->ri_ops.putchar = rasops8_putchar8;
     97 		break;
     98 	case 12:
     99 		ri->ri_ops.putchar = rasops8_putchar12;
    100 		break;
    101 	case 16:
    102 		ri->ri_ops.putchar = rasops8_putchar16;
    103 		break;
    104 #endif /* !RASOPS_SMALL */
    105 	default:
    106 		ri->ri_ops.putchar = rasops8_putchar;
    107 		return;
    108 	}
    109 
    110 #ifndef RASOPS_SMALL
    111 	stamp_attr = -1;
    112 	stamp_ri = NULL;
    113 #endif
    114 }
    115 
    116 /* rasops8_putchar */
    117 #undef	RASOPS_AA
    118 #include <dev/rasops/rasops_putchar.h>
    119 
    120 /* rasops8_putchar_aa */
    121 #define	RASOPS_AA
    122 #include <dev/rasops/rasops_putchar.h>
    123 #undef	RASOPS_AA
    124 
    125 #ifndef RASOPS_SMALL
    126 /*
    127  * Recompute the blitting stamp.
    128  */
    129 static void
    130 rasops8_makestamp(struct rasops_info *ri, long attr)
    131 {
    132 	int i;
    133 	uint32_t bg, fg;
    134 
    135 	stamp_attr = attr;
    136 	stamp_ri = ri;
    137 
    138 	bg = ATTR_BG(ri, attr) & 0xff;
    139 	fg = ATTR_FG(ri, attr) & 0xff;
    140 
    141 	for (i = 0; i < 16; i++) {
    142 #if BYTE_ORDER == LITTLE_ENDIAN
    143 		if ((ri->ri_flg & RI_BSWAP) == 0)
    144 #else
    145 		if ((ri->ri_flg & RI_BSWAP) != 0)
    146 #endif
    147 		{
    148 			/* little endian */
    149 			stamp[i]  = (i & 8 ? fg : bg);
    150 			stamp[i] |= (i & 4 ? fg : bg) << 8;
    151 			stamp[i] |= (i & 2 ? fg : bg) << 16;
    152 			stamp[i] |= (i & 1 ? fg : bg) << 24;
    153 		} else {
    154 			/* big endian */
    155 			stamp[i]  = (i & 1 ? fg : bg);
    156 			stamp[i] |= (i & 2 ? fg : bg) << 8;
    157 			stamp[i] |= (i & 4 ? fg : bg) << 16;
    158 			stamp[i] |= (i & 8 ? fg : bg) << 24;
    159 		}
    160 	}
    161 }
    162 
    163 /*
    164  * Width-optimized putchar functions
    165  */
    166 #define	RASOPS_WIDTH	8
    167 #include <dev/rasops/rasops_putchar_width.h>
    168 #undef	RASOPS_WIDTH
    169 
    170 #define	RASOPS_WIDTH	12
    171 #include <dev/rasops/rasops_putchar_width.h>
    172 #undef	RASOPS_WIDTH
    173 
    174 #define	RASOPS_WIDTH	16
    175 #include <dev/rasops/rasops_putchar_width.h>
    176 #undef	RASOPS_WIDTH
    177 
    178 #endif /* !RASOPS_SMALL */
    179