Home | History | Annotate | Line # | Download | only in rasops
      1 /* 	$NetBSD: rasops15.c,v 1.39 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: rasops15.c,v 1.39 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	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 /* 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 = -1;
    113 	stamp_ri = NULL;
    114 #endif
    115 }
    116 
    117 /* rasops15_putchar */
    118 #undef	RASOPS_AA
    119 #include <dev/rasops/rasops_putchar.h>
    120 
    121 /* rasops15_putchar_aa */
    122 #define	RASOPS_AA
    123 #include <dev/rasops/rasops_putchar.h>
    124 #undef	RASOPS_AA
    125 
    126 #ifndef RASOPS_SMALL
    127 /*
    128  * Recompute the 4x1 blitting stamp.
    129  */
    130 static void
    131 rasops15_makestamp(struct rasops_info *ri, long attr)
    132 {
    133 	int i;
    134 	uint32_t bg, fg;
    135 
    136 	stamp_attr = attr;
    137 	stamp_ri = ri;
    138 
    139 	bg = ATTR_BG(ri, attr) & 0xffff;
    140 	fg = ATTR_FG(ri, attr) & 0xffff;
    141 
    142 	for (i = 0; i < 32; i += 2) {
    143 #if BYTE_ORDER == LITTLE_ENDIAN
    144 		stamp[i]      = (i & 16 ? fg : bg);
    145 		stamp[i]     |= (i &  8 ? fg : bg) << 16;
    146 		stamp[i + 1]  = (i &  4 ? fg : bg);
    147 		stamp[i + 1] |= (i &  2 ? fg : bg) << 16;
    148 #else
    149 		stamp[i]      = (i &  8 ? fg : bg);
    150 		stamp[i]     |= (i & 16 ? fg : bg) << 16;
    151 		stamp[i + 1]  = (i &  2 ? fg : bg);
    152 		stamp[i + 1] |= (i &  4 ? fg : bg) << 16;
    153 #endif
    154 	}
    155 }
    156 
    157 /*
    158  * Width-optimized putchar functions
    159  */
    160 #define	RASOPS_WIDTH	8
    161 #include <dev/rasops/rasops_putchar_width.h>
    162 #undef	RASOPS_WIDTH
    163 
    164 #define	RASOPS_WIDTH	12
    165 #include <dev/rasops/rasops_putchar_width.h>
    166 #undef	RASOPS_WIDTH
    167 
    168 #define	RASOPS_WIDTH	16
    169 #include <dev/rasops/rasops_putchar_width.h>
    170 #undef	RASOPS_WIDTH
    171 
    172 #endif /* !RASOPS_SMALL */
    173