Home | History | Annotate | Line # | Download | only in rasops
rasops8.c revision 1.47
      1 /* 	$NetBSD: rasops8.c,v 1.47 2019/08/02 04:40:53 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.47 2019/08/02 04:40:53 rin Exp $");
     34 
     35 #include "opt_rasops.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/time.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 /*
     58  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     59  * destination = STAMP_READ(offset)
     60  */
     61 #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 2 : (fb) << 2)
     62 #define	STAMP_MASK		(0xf << 2)
     63 #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     64 
     65 /*
     66  * Initialize a 'rasops_info' descriptor for this depth.
     67  */
     68 void
     69 rasops8_init(struct rasops_info *ri)
     70 {
     71 
     72 	if (ri->ri_flg & RI_8BIT_IS_RGB) {
     73 		ri->ri_rnum = ri->ri_gnum = 3;
     74 		ri->ri_bnum = 2;
     75 
     76 		ri->ri_rpos = 5;
     77 		ri->ri_gpos = 2;
     78 		ri->ri_bpos = 0;
     79 	}
     80 
     81 	if (FONT_IS_ALPHA(ri->ri_font)) {
     82 		ri->ri_ops.putchar = rasops8_putchar_aa;
     83 		return;
     84 	}
     85 
     86 	switch (ri->ri_font->fontwidth) {
     87 #ifndef RASOPS_SMALL
     88 	case 8:
     89 		ri->ri_ops.putchar = rasops8_putchar8;
     90 		break;
     91 	case 12:
     92 		ri->ri_ops.putchar = rasops8_putchar12;
     93 		break;
     94 	case 16:
     95 		ri->ri_ops.putchar = rasops8_putchar16;
     96 		break;
     97 #endif /* !RASOPS_SMALL */
     98 	default:
     99 		ri->ri_ops.putchar = rasops8_putchar;
    100 		return;
    101 	}
    102 
    103 #ifndef RASOPS_SMALL
    104 	rasops_allocstamp(ri, sizeof(uint32_t) * 16);
    105 #endif
    106 }
    107 
    108 #include "rasops_putchar.h"
    109 #include "rasops_putchar_aa.h"
    110 
    111 #ifndef RASOPS_SMALL
    112 /*
    113  * Recompute the 4x1 blitting stamp.
    114  */
    115 static void
    116 rasops8_makestamp(struct rasops_info *ri, long attr)
    117 {
    118 	uint32_t *stamp = (uint32_t *)ri->ri_stamp;
    119 	uint32_t fg, bg;
    120 	int i;
    121 
    122 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xff;
    123 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xff;
    124 	ri->ri_stamp_attr = attr;
    125 
    126 	for (i = 0; i < 16; i++) {
    127 #if BYTE_ORDER == BIG_ENDIAN
    128 #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    129 #else
    130 #define NEED_LITTLE_ENDIAN_STAMP 0
    131 #endif
    132 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    133 			/* little endian */
    134 			stamp[i]  = (i & 8 ? fg : bg);
    135 			stamp[i] |= (i & 4 ? fg : bg) << 8;
    136 			stamp[i] |= (i & 2 ? fg : bg) << 16;
    137 			stamp[i] |= (i & 1 ? fg : bg) << 24;
    138 		} else {
    139 			/* big endian */
    140 			stamp[i]  = (i & 1 ? fg : bg);
    141 			stamp[i] |= (i & 2 ? fg : bg) << 8;
    142 			stamp[i] |= (i & 4 ? fg : bg) << 16;
    143 			stamp[i] |= (i & 8 ? fg : bg) << 24;
    144 		}
    145 	}
    146 }
    147 
    148 #define	RASOPS_WIDTH	8
    149 #include "rasops_putchar_width.h"
    150 #undef	RASOPS_WIDTH
    151 
    152 #define	RASOPS_WIDTH	12
    153 #include "rasops_putchar_width.h"
    154 #undef	RASOPS_WIDTH
    155 
    156 #define	RASOPS_WIDTH	16
    157 #include "rasops_putchar_width.h"
    158 #undef	RASOPS_WIDTH
    159 
    160 #endif
    161