Home | History | Annotate | Line # | Download | only in rasops
      1  1.39       rin /* 	$NetBSD: rasops15.c,v 1.39 2019/08/14 00:51:10 rin Exp $	*/
      2   1.1        ad 
      3   1.4        ad /*-
      4   1.4        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5   1.1        ad  * All rights reserved.
      6   1.1        ad  *
      7   1.4        ad  * This code is derived from software contributed to The NetBSD Foundation
      8   1.8        ad  * by Andrew Doran.
      9   1.4        ad  *
     10   1.1        ad  * Redistribution and use in source and binary forms, with or without
     11   1.1        ad  * modification, are permitted provided that the following conditions
     12   1.1        ad  * are met:
     13   1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14   1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15   1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17   1.1        ad  *    documentation and/or other materials provided with the distribution.
     18   1.1        ad  *
     19   1.4        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.4        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.4        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.4        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.4        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.4        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.4        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.4        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.4        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.4        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.4        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        ad  */
     31   1.2        ad 
     32  1.10     lukem #include <sys/cdefs.h>
     33  1.39       rin __KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.39 2019/08/14 00:51:10 rin Exp $");
     34  1.10     lukem 
     35  1.38       rin #ifdef _KERNEL_OPT
     36   1.1        ad #include "opt_rasops.h"
     37  1.38       rin #endif
     38   1.1        ad 
     39   1.1        ad #include <sys/param.h>
     40   1.1        ad 
     41   1.1        ad #include <dev/wscons/wsdisplayvar.h>
     42   1.1        ad #include <dev/wscons/wsconsio.h>
     43  1.32       rin 
     44  1.32       rin #define	_RASOPS_PRIVATE
     45  1.34       rin #define	RASOPS_DEPTH	15
     46   1.1        ad #include <dev/rasops/rasops.h>
     47   1.1        ad 
     48  1.30       rin static void 	rasops15_putchar(void *, int, int, u_int, long);
     49  1.30       rin static void 	rasops15_putchar_aa(void *, int, int, u_int, long);
     50   1.5        ad #ifndef RASOPS_SMALL
     51  1.30       rin static void 	rasops15_putchar8(void *, int, int, u_int, long);
     52  1.30       rin static void 	rasops15_putchar12(void *, int, int, u_int, long);
     53  1.30       rin static void 	rasops15_putchar16(void *, int, int, u_int, long);
     54  1.12     perry static void	rasops15_makestamp(struct rasops_info *, long);
     55   1.5        ad #endif
     56   1.1        ad 
     57  1.14  jmcneill #ifndef RASOPS_SMALL
     58  1.38       rin /* stamp for optimized character blitting */
     59  1.35       rin static uint32_t			stamp[32];
     60  1.35       rin static long			stamp_attr;
     61  1.35       rin static struct rasops_info	*stamp_ri;
     62  1.35       rin 
     63   1.7        pk /*
     64   1.1        ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     65  1.25       rin  * destination uint32_t[0] = STAMP_READ(offset)
     66  1.25       rin  * destination uint32_t[1] = STAMP_READ(offset + 4)
     67   1.1        ad  */
     68  1.30       rin #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 1: (fb) << 3)
     69  1.30       rin #define	STAMP_MASK		(0xf << 3)
     70  1.30       rin #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     71  1.14  jmcneill #endif
     72   1.1        ad 
     73   1.1        ad /*
     74   1.9       wiz  * Initialize rasops_info struct for this colordepth.
     75   1.1        ad  */
     76   1.1        ad void
     77  1.17       dsl rasops15_init(struct rasops_info *ri)
     78   1.1        ad {
     79   1.1        ad 
     80  1.30       rin 	if (ri->ri_rnum == 0) {
     81  1.30       rin 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
     82  1.30       rin 		ri->ri_gnum += (ri->ri_depth == 16);
     83  1.30       rin 
     84  1.30       rin 		ri->ri_rpos = 10 + (ri->ri_depth == 16);
     85  1.30       rin 		ri->ri_gpos = 5;
     86  1.30       rin 		ri->ri_bpos = 0;
     87  1.30       rin 	}
     88  1.30       rin 
     89  1.21  jakllsch 	if (FONT_IS_ALPHA(ri->ri_font)) {
     90  1.21  jakllsch 		ri->ri_ops.putchar = rasops15_putchar_aa;
     91  1.30       rin 		return;
     92  1.30       rin 	}
     93  1.30       rin 
     94  1.30       rin 	switch (ri->ri_font->fontwidth) {
     95   1.5        ad #ifndef RASOPS_SMALL
     96  1.30       rin 	case 8:
     97  1.30       rin 		ri->ri_ops.putchar = rasops15_putchar8;
     98  1.30       rin 		break;
     99  1.30       rin 	case 12:
    100  1.30       rin 		ri->ri_ops.putchar = rasops15_putchar12;
    101  1.30       rin 		break;
    102  1.30       rin 	case 16:
    103  1.30       rin 		ri->ri_ops.putchar = rasops15_putchar16;
    104  1.30       rin 		break;
    105   1.5        ad #endif	/* !RASOPS_SMALL */
    106  1.30       rin 	default:
    107  1.30       rin 		ri->ri_ops.putchar = rasops15_putchar;
    108  1.33       rin 		return;
    109   1.1        ad 	}
    110  1.33       rin 
    111  1.33       rin #ifndef RASOPS_SMALL
    112  1.39       rin 	stamp_attr = -1;
    113  1.35       rin 	stamp_ri = NULL;
    114  1.33       rin #endif
    115   1.1        ad }
    116   1.1        ad 
    117  1.38       rin /* rasops15_putchar */
    118  1.37       rin #undef	RASOPS_AA
    119  1.38       rin #include <dev/rasops/rasops_putchar.h>
    120  1.37       rin 
    121  1.38       rin /* rasops15_putchar_aa */
    122  1.37       rin #define	RASOPS_AA
    123  1.38       rin #include <dev/rasops/rasops_putchar.h>
    124  1.37       rin #undef	RASOPS_AA
    125  1.21  jakllsch 
    126   1.5        ad #ifndef RASOPS_SMALL
    127   1.1        ad /*
    128  1.30       rin  * Recompute the 4x1 blitting stamp.
    129   1.1        ad  */
    130   1.1        ad static void
    131  1.17       dsl rasops15_makestamp(struct rasops_info *ri, long attr)
    132   1.1        ad {
    133   1.1        ad 	int i;
    134  1.38       rin 	uint32_t bg, fg;
    135   1.7        pk 
    136  1.35       rin 	stamp_attr = attr;
    137  1.35       rin 	stamp_ri = ri;
    138  1.35       rin 
    139  1.38       rin 	bg = ATTR_BG(ri, attr) & 0xffff;
    140  1.38       rin 	fg = ATTR_FG(ri, attr) & 0xffff;
    141   1.7        pk 
    142   1.3        ad 	for (i = 0; i < 32; i += 2) {
    143   1.1        ad #if BYTE_ORDER == LITTLE_ENDIAN
    144  1.30       rin 		stamp[i]      = (i & 16 ? fg : bg);
    145  1.30       rin 		stamp[i]     |= (i &  8 ? fg : bg) << 16;
    146  1.30       rin 		stamp[i + 1]  = (i &  4 ? fg : bg);
    147  1.30       rin 		stamp[i + 1] |= (i &  2 ? fg : bg) << 16;
    148   1.1        ad #else
    149  1.30       rin 		stamp[i]      = (i &  8 ? fg : bg);
    150  1.30       rin 		stamp[i]     |= (i & 16 ? fg : bg) << 16;
    151  1.30       rin 		stamp[i + 1]  = (i &  2 ? fg : bg);
    152  1.30       rin 		stamp[i + 1] |= (i &  4 ? fg : bg) << 16;
    153   1.1        ad #endif
    154   1.1        ad 	}
    155   1.1        ad }
    156   1.1        ad 
    157  1.38       rin /*
    158  1.38       rin  * Width-optimized putchar functions
    159  1.38       rin  */
    160  1.28       rin #define	RASOPS_WIDTH	8
    161  1.38       rin #include <dev/rasops/rasops_putchar_width.h>
    162  1.28       rin #undef	RASOPS_WIDTH
    163  1.28       rin 
    164  1.28       rin #define	RASOPS_WIDTH	12
    165  1.38       rin #include <dev/rasops/rasops_putchar_width.h>
    166  1.28       rin #undef	RASOPS_WIDTH
    167  1.28       rin 
    168  1.28       rin #define	RASOPS_WIDTH	16
    169  1.38       rin #include <dev/rasops/rasops_putchar_width.h>
    170  1.28       rin #undef	RASOPS_WIDTH
    171   1.1        ad 
    172  1.28       rin #endif /* !RASOPS_SMALL */
    173