Home | History | Annotate | Line # | Download | only in rasops
rasops2.c revision 1.18.36.2
      1  1.18.36.2    martin /* 	$NetBSD: rasops2.c,v 1.18.36.2 2020/04/13 08:04:47 martin Exp $	*/
      2        1.1        ad 
      3        1.2        ad /*-
      4        1.2        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5        1.1        ad  * All rights reserved.
      6        1.1        ad  *
      7        1.2        ad  * This code is derived from software contributed to The NetBSD Foundation
      8        1.6        ad  * by Andrew Doran.
      9        1.2        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.2        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.2        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.2        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.2        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.2        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.2        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.2        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.2        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.2        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.2        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.2        ad  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        ad  */
     31        1.1        ad 
     32        1.8     lukem #include <sys/cdefs.h>
     33  1.18.36.2    martin __KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.18.36.2 2020/04/13 08:04:47 martin Exp $");
     34        1.8     lukem 
     35  1.18.36.2    martin #ifdef _KERNEL_OPT
     36        1.1        ad #include "opt_rasops.h"
     37  1.18.36.2    martin #endif
     38        1.1        ad 
     39        1.1        ad #include <sys/param.h>
     40  1.18.36.2    martin 
     41        1.1        ad #include <machine/endian.h>
     42        1.1        ad 
     43        1.1        ad #include <dev/wscons/wsdisplayvar.h>
     44        1.1        ad #include <dev/wscons/wsconsio.h>
     45  1.18.36.2    martin 
     46  1.18.36.2    martin #define	_RASOPS_PRIVATE
     47  1.18.36.2    martin #define	RASOPS_DEPTH	2
     48        1.1        ad #include <dev/rasops/rasops.h>
     49        1.1        ad #include <dev/rasops/rasops_masks.h>
     50        1.1        ad 
     51       1.10     perry static void	rasops2_copycols(void *, int, int, int, int);
     52       1.10     perry static void	rasops2_erasecols(void *, int, int, int, long);
     53       1.10     perry static void	rasops2_do_cursor(struct rasops_info *);
     54       1.10     perry static void	rasops2_putchar(void *, int, int col, u_int, long);
     55  1.18.36.2    martin static void	rasops2_putchar_aa(void *, int, int col, u_int, long);
     56        1.4        ad #ifndef RASOPS_SMALL
     57       1.10     perry static void	rasops2_putchar8(void *, int, int col, u_int, long);
     58       1.10     perry static void	rasops2_putchar12(void *, int, int col, u_int, long);
     59       1.10     perry static void	rasops2_putchar16(void *, int, int col, u_int, long);
     60       1.10     perry static void	rasops2_makestamp(struct rasops_info *, long);
     61  1.18.36.2    martin #endif
     62  1.18.36.2    martin 
     63  1.18.36.2    martin #ifndef RASOPS_SMALL
     64  1.18.36.2    martin /* stamp for optimized character blitting */
     65  1.18.36.2    martin static uint8_t			stamp[16];
     66  1.18.36.2    martin static long			stamp_attr;
     67  1.18.36.2    martin static struct rasops_info	*stamp_ri;
     68        1.1        ad 
     69        1.5        pk /*
     70  1.18.36.2    martin  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     71  1.18.36.2    martin  * destination = STAMP_READ(offset)
     72  1.18.36.2    martin  */
     73  1.18.36.2    martin #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
     74  1.18.36.2    martin #define	STAMP_MASK		0xf
     75  1.18.36.2    martin #define	STAMP_READ(o)		stamp[o]
     76        1.7     bjh21 #endif
     77        1.1        ad 
     78        1.1        ad /*
     79        1.1        ad  * Initialize rasops_info struct for this colordepth.
     80        1.1        ad  */
     81        1.1        ad void
     82       1.13       dsl rasops2_init(struct rasops_info *ri)
     83        1.1        ad {
     84        1.1        ad 
     85  1.18.36.2    martin 	if ((ri->ri_font->fontwidth & 3) != 0) {
     86  1.18.36.2    martin 		ri->ri_ops.erasecols = rasops2_erasecols;
     87  1.18.36.2    martin 		ri->ri_ops.copycols = rasops2_copycols;
     88  1.18.36.2    martin 		ri->ri_do_cursor = rasops2_do_cursor;
     89  1.18.36.2    martin 	}
     90  1.18.36.2    martin 
     91  1.18.36.2    martin 	if (FONT_IS_ALPHA(ri->ri_font)) {
     92  1.18.36.2    martin 		ri->ri_ops.putchar = rasops2_putchar_aa;
     93  1.18.36.2    martin 		return;
     94  1.18.36.2    martin 	}
     95  1.18.36.2    martin 
     96        1.1        ad 	switch (ri->ri_font->fontwidth) {
     97        1.4        ad #ifndef RASOPS_SMALL
     98        1.1        ad 	case 8:
     99        1.1        ad 		ri->ri_ops.putchar = rasops2_putchar8;
    100        1.1        ad 		break;
    101        1.1        ad 	case 12:
    102        1.1        ad 		ri->ri_ops.putchar = rasops2_putchar12;
    103        1.1        ad 		break;
    104        1.1        ad 	case 16:
    105        1.1        ad 		ri->ri_ops.putchar = rasops2_putchar16;
    106        1.1        ad 		break;
    107  1.18.36.2    martin #endif
    108        1.1        ad 	default:
    109        1.1        ad 		ri->ri_ops.putchar = rasops2_putchar;
    110        1.1        ad 		return;
    111        1.1        ad 	}
    112        1.5        pk 
    113  1.18.36.2    martin #ifndef RASOPS_SMALL
    114  1.18.36.2    martin 	stamp_attr = -1;
    115  1.18.36.2    martin 	stamp_ri = NULL;
    116        1.1        ad #endif
    117        1.1        ad }
    118        1.1        ad 
    119        1.4        ad #ifndef RASOPS_SMALL
    120        1.4        ad /*
    121        1.4        ad  * Recompute the blitting stamp.
    122        1.4        ad  */
    123        1.4        ad static void
    124       1.13       dsl rasops2_makestamp(struct rasops_info *ri, long attr)
    125        1.4        ad {
    126  1.18.36.2    martin 	int i;
    127  1.18.36.2    martin 	uint32_t bg, fg;
    128        1.5        pk 
    129        1.4        ad 	stamp_attr = attr;
    130  1.18.36.2    martin 	stamp_ri = ri;
    131  1.18.36.2    martin 
    132  1.18.36.2    martin 	bg = ATTR_BG(ri, attr) & 3;
    133  1.18.36.2    martin 	fg = ATTR_FG(ri, attr) & 3;
    134        1.5        pk 
    135        1.4        ad 	for (i = 0; i < 16; i++) {
    136  1.18.36.2    martin #if BYTE_ORDER == LITTLE_ENDIAN
    137  1.18.36.2    martin 		if ((ri->ri_flg & RI_BSWAP) == 0)
    138       1.18  kiyohara #else
    139  1.18.36.2    martin 		if ((ri->ri_flg & RI_BSWAP) != 0)
    140       1.18  kiyohara #endif
    141  1.18.36.2    martin 		{
    142       1.18  kiyohara 			/* littel endian */
    143  1.18.36.2    martin 			stamp[i]  = (i & 8 ? fg : bg);
    144       1.18  kiyohara 			stamp[i] |= (i & 4 ? fg : bg) << 2;
    145       1.18  kiyohara 			stamp[i] |= (i & 2 ? fg : bg) << 4;
    146       1.18  kiyohara 			stamp[i] |= (i & 1 ? fg : bg) << 6;
    147       1.18  kiyohara 		} else {
    148       1.18  kiyohara 			/* big endian */
    149  1.18.36.2    martin 			stamp[i]  = (i & 1 ? fg : bg);
    150       1.18  kiyohara 			stamp[i] |= (i & 2 ? fg : bg) << 2;
    151       1.18  kiyohara 			stamp[i] |= (i & 4 ? fg : bg) << 4;
    152       1.18  kiyohara 			stamp[i] |= (i & 8 ? fg : bg) << 6;
    153       1.18  kiyohara 		}
    154        1.4        ad 	}
    155        1.4        ad }
    156        1.1        ad 
    157        1.1        ad /*
    158  1.18.36.2    martin  * Width-optimized putchar functions
    159        1.1        ad  */
    160  1.18.36.2    martin #define	RASOPS_WIDTH	8
    161  1.18.36.2    martin #include <dev/rasops/rasops_putchar_width.h>
    162  1.18.36.2    martin #undef	RASOPS_WIDTH
    163  1.18.36.2    martin 
    164  1.18.36.2    martin #define	RASOPS_WIDTH	12
    165  1.18.36.2    martin #include <dev/rasops/rasops_putchar_width.h>
    166  1.18.36.2    martin #undef	RASOPS_WIDTH
    167  1.18.36.2    martin 
    168  1.18.36.2    martin #define	RASOPS_WIDTH	16
    169  1.18.36.2    martin #include <dev/rasops/rasops_putchar_width.h>
    170  1.18.36.2    martin #undef	RASOPS_WIDTH
    171        1.1        ad 
    172        1.4        ad #endif	/* !RASOPS_SMALL */
    173        1.1        ad 
    174  1.18.36.2    martin /* rasops2_putchar */
    175  1.18.36.2    martin #undef	RASOPS_AA
    176  1.18.36.2    martin #include <dev/rasops/rasops1-4_putchar.h>
    177  1.18.36.2    martin 
    178  1.18.36.2    martin /* rasops2_putchar_aa */
    179  1.18.36.2    martin #define	RASOPS_AA
    180  1.18.36.2    martin #include <dev/rasops/rasops1-4_putchar.h>
    181  1.18.36.2    martin #undef	RASOPS_AA
    182  1.18.36.2    martin 
    183        1.1        ad /*
    184        1.1        ad  * Grab routines common to depths where (bpp < 8)
    185        1.1        ad  */
    186        1.1        ad #include <dev/rasops/rasops_bitops.h>
    187