Home | History | Annotate | Line # | Download | only in rasops
rasops2.c revision 1.31
      1 /* 	$NetBSD: rasops2.c,v 1.31 2019/08/07 12:36:36 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: rasops2.c,v 1.31 2019/08/07 12:36:36 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 #include <machine/endian.h>
     41 
     42 #include <dev/wscons/wsdisplayvar.h>
     43 #include <dev/wscons/wsconsio.h>
     44 
     45 #define	_RASOPS_PRIVATE
     46 #define	RASOPS_DEPTH	2
     47 #include <dev/rasops/rasops.h>
     48 #include <dev/rasops/rasops_masks.h>
     49 
     50 static void	rasops2_copycols(void *, int, int, int, int);
     51 static void	rasops2_erasecols(void *, int, int, int, long);
     52 static void	rasops2_do_cursor(struct rasops_info *);
     53 static void	rasops2_putchar(void *, int, int col, u_int, long);
     54 static void	rasops2_putchar_aa(void *, int, int col, u_int, long);
     55 #ifndef RASOPS_SMALL
     56 static void	rasops2_putchar8(void *, int, int col, u_int, long);
     57 static void	rasops2_putchar12(void *, int, int col, u_int, long);
     58 static void	rasops2_putchar16(void *, int, int col, u_int, long);
     59 static void	rasops2_makestamp(struct rasops_info *, long);
     60 #endif
     61 
     62 #ifndef RASOPS_SMALL
     63 /* 4x1 stamp for optimized character blitting */
     64 static uint8_t			stamp[16];
     65 static long			stamp_attr;
     66 static struct rasops_info	*stamp_ri;
     67 
     68 /*
     69  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     70  * destination = STAMP_READ(offset)
     71  */
     72 #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
     73 #define	STAMP_MASK		0xf
     74 #define	STAMP_READ(o)		stamp[o]
     75 #endif
     76 
     77 /*
     78  * Initialize rasops_info struct for this colordepth.
     79  */
     80 void
     81 rasops2_init(struct rasops_info *ri)
     82 {
     83 
     84 	if ((ri->ri_font->fontwidth & 3) != 0) {
     85 		ri->ri_ops.erasecols = rasops2_erasecols;
     86 		ri->ri_ops.copycols = rasops2_copycols;
     87 		ri->ri_do_cursor = rasops2_do_cursor;
     88 	}
     89 
     90 	if (FONT_IS_ALPHA(ri->ri_font)) {
     91 		ri->ri_ops.putchar = rasops2_putchar_aa;
     92 		return;
     93 	}
     94 
     95 	switch (ri->ri_font->fontwidth) {
     96 #ifndef RASOPS_SMALL
     97 	case 8:
     98 		ri->ri_ops.putchar = rasops2_putchar8;
     99 		break;
    100 	case 12:
    101 		ri->ri_ops.putchar = rasops2_putchar12;
    102 		break;
    103 	case 16:
    104 		ri->ri_ops.putchar = rasops2_putchar16;
    105 		break;
    106 #endif
    107 	default:
    108 		ri->ri_ops.putchar = rasops2_putchar;
    109 		return;
    110 	}
    111 
    112 #ifndef RASOPS_SMALL
    113 	stamp_attr = 0;
    114 	stamp_ri = NULL;
    115 #endif
    116 }
    117 
    118 #ifndef RASOPS_SMALL
    119 /*
    120  * Recompute the blitting stamp.
    121  */
    122 static void
    123 rasops2_makestamp(struct rasops_info *ri, long attr)
    124 {
    125 	int i, fg, bg;
    126 
    127 	stamp_attr = attr;
    128 	stamp_ri = ri;
    129 
    130 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3;
    131 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3;
    132 
    133 	for (i = 0; i < 16; i++) {
    134 #if BYTE_ORDER == BIG_ENDIAN
    135 #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    136 #else
    137 #define NEED_LITTLE_ENDIAN_STAMP 0
    138 #endif
    139 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    140 			/* littel endian */
    141 			stamp[i]  = (i & 8 ? fg : bg);
    142 			stamp[i] |= (i & 4 ? fg : bg) << 2;
    143 			stamp[i] |= (i & 2 ? fg : bg) << 4;
    144 			stamp[i] |= (i & 1 ? fg : bg) << 6;
    145 		} else {
    146 			/* big endian */
    147 			stamp[i]  = (i & 1 ? fg : bg);
    148 			stamp[i] |= (i & 2 ? fg : bg) << 2;
    149 			stamp[i] |= (i & 4 ? fg : bg) << 4;
    150 			stamp[i] |= (i & 8 ? fg : bg) << 6;
    151 		}
    152 	}
    153 }
    154 
    155 #define	RASOPS_WIDTH	8
    156 #include "rasops_putchar_width.h"
    157 #undef	RASOPS_WIDTH
    158 
    159 #define	RASOPS_WIDTH	12
    160 #include "rasops_putchar_width.h"
    161 #undef	RASOPS_WIDTH
    162 
    163 #define	RASOPS_WIDTH	16
    164 #include "rasops_putchar_width.h"
    165 #undef	RASOPS_WIDTH
    166 
    167 #endif	/* !RASOPS_SMALL */
    168 
    169 /*
    170  * Grab routines common to depths where (bpp < 8)
    171  */
    172 #undef	RASOPS_AA
    173 #include "rasops1-4_putchar.h"
    174 
    175 #define	RASOPS_AA
    176 #include "rasops1-4_putchar.h"
    177 #undef	RASOPS_AA
    178 
    179 #include <dev/rasops/rasops_bitops.h>
    180