Home | History | Annotate | Line # | Download | only in rasops
rasops15.c revision 1.37
      1 /* 	$NetBSD: rasops15.c,v 1.37 2019/08/07 12:33:48 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: rasops15.c,v 1.37 2019/08/07 12:33:48 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	15
     46 #include <dev/rasops/rasops.h>
     47 
     48 static void 	rasops15_putchar(void *, int, int, u_int, long);
     49 static void 	rasops15_putchar_aa(void *, int, int, u_int, long);
     50 #ifndef RASOPS_SMALL
     51 static void 	rasops15_putchar8(void *, int, int, u_int, long);
     52 static void 	rasops15_putchar12(void *, int, int, u_int, long);
     53 static void 	rasops15_putchar16(void *, int, int, u_int, long);
     54 static void	rasops15_makestamp(struct rasops_info *, long);
     55 #endif
     56 
     57 #ifndef RASOPS_SMALL
     58 /* 4x1 stamp for optimized character blitting */
     59 static uint32_t			stamp[32];
     60 static long			stamp_attr;
     61 static struct rasops_info	*stamp_ri;
     62 
     63 /*
     64  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     65  * destination uint32_t[0] = STAMP_READ(offset)
     66  * destination uint32_t[1] = STAMP_READ(offset + 4)
     67  */
     68 #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 1: (fb) << 3)
     69 #define	STAMP_MASK		(0xf << 3)
     70 #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     71 #endif
     72 
     73 /*
     74  * Initialize rasops_info struct for this colordepth.
     75  */
     76 void
     77 rasops15_init(struct rasops_info *ri)
     78 {
     79 
     80 	if (ri->ri_rnum == 0) {
     81 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
     82 		ri->ri_gnum += (ri->ri_depth == 16);
     83 
     84 		ri->ri_rpos = 10 + (ri->ri_depth == 16);
     85 		ri->ri_gpos = 5;
     86 		ri->ri_bpos = 0;
     87 	}
     88 
     89 	if (FONT_IS_ALPHA(ri->ri_font)) {
     90 		ri->ri_ops.putchar = rasops15_putchar_aa;
     91 		return;
     92 	}
     93 
     94 	switch (ri->ri_font->fontwidth) {
     95 #ifndef RASOPS_SMALL
     96 	case 8:
     97 		ri->ri_ops.putchar = rasops15_putchar8;
     98 		break;
     99 	case 12:
    100 		ri->ri_ops.putchar = rasops15_putchar12;
    101 		break;
    102 	case 16:
    103 		ri->ri_ops.putchar = rasops15_putchar16;
    104 		break;
    105 #endif	/* !RASOPS_SMALL */
    106 	default:
    107 		ri->ri_ops.putchar = rasops15_putchar;
    108 		return;
    109 	}
    110 
    111 #ifndef RASOPS_SMALL
    112 	stamp_attr = 0;
    113 	stamp_ri = NULL;
    114 #endif
    115 }
    116 
    117 #undef	RASOPS_AA
    118 #include "rasops_putchar.h"
    119 
    120 #define	RASOPS_AA
    121 #include "rasops_putchar.h"
    122 #undef	RASOPS_AA
    123 
    124 #ifndef RASOPS_SMALL
    125 /*
    126  * Recompute the 4x1 blitting stamp.
    127  */
    128 static void
    129 rasops15_makestamp(struct rasops_info *ri, long attr)
    130 {
    131 	uint32_t fg, bg;
    132 	int i;
    133 
    134 	stamp_attr = attr;
    135 	stamp_ri = ri;
    136 
    137 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffff;
    138 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffff;
    139 
    140 	for (i = 0; i < 32; i += 2) {
    141 #if BYTE_ORDER == LITTLE_ENDIAN
    142 		stamp[i]      = (i & 16 ? fg : bg);
    143 		stamp[i]     |= (i &  8 ? fg : bg) << 16;
    144 		stamp[i + 1]  = (i &  4 ? fg : bg);
    145 		stamp[i + 1] |= (i &  2 ? fg : bg) << 16;
    146 #else
    147 		stamp[i]      = (i &  8 ? fg : bg);
    148 		stamp[i]     |= (i & 16 ? fg : bg) << 16;
    149 		stamp[i + 1]  = (i &  2 ? fg : bg);
    150 		stamp[i + 1] |= (i &  4 ? fg : bg) << 16;
    151 #endif
    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