Home | History | Annotate | Line # | Download | only in rasops
rasops2.c revision 1.27
      1  1.27       rin /* 	$NetBSD: rasops2.c,v 1.27 2019/07/31 00:14:25 rin 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.27       rin __KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.27 2019/07/31 00:14:25 rin Exp $");
     34   1.8     lukem 
     35   1.1        ad #include "opt_rasops.h"
     36   1.1        ad 
     37   1.1        ad #include <sys/param.h>
     38   1.1        ad #include <sys/systm.h>
     39   1.1        ad #include <sys/time.h>
     40   1.1        ad #include <machine/endian.h>
     41   1.1        ad 
     42   1.1        ad #include <dev/wscons/wsdisplayvar.h>
     43   1.1        ad #include <dev/wscons/wsconsio.h>
     44  1.27       rin 
     45  1.27       rin #define	_RASOPS_PRIVATE
     46   1.1        ad #include <dev/rasops/rasops.h>
     47   1.1        ad #include <dev/rasops/rasops_masks.h>
     48   1.1        ad 
     49  1.10     perry static void	rasops2_copycols(void *, int, int, int, int);
     50  1.10     perry static void	rasops2_erasecols(void *, int, int, int, long);
     51  1.10     perry static void	rasops2_do_cursor(struct rasops_info *);
     52  1.10     perry static void	rasops2_putchar(void *, int, int col, u_int, long);
     53   1.4        ad #ifndef RASOPS_SMALL
     54  1.10     perry static void	rasops2_putchar8(void *, int, int col, u_int, long);
     55  1.10     perry static void	rasops2_putchar12(void *, int, int col, u_int, long);
     56  1.10     perry static void	rasops2_putchar16(void *, int, int col, u_int, long);
     57  1.10     perry static void	rasops2_makestamp(struct rasops_info *, long);
     58   1.1        ad 
     59   1.5        pk /*
     60   1.5        pk  * 4x1 stamp for optimized character blitting
     61   1.1        ad  */
     62  1.21       rin static uint8_t	stamp[16];
     63   1.1        ad static long	stamp_attr;
     64   1.1        ad static int	stamp_mutex;	/* XXX see note in README */
     65   1.7     bjh21 #endif
     66   1.1        ad 
     67   1.1        ad /*
     68  1.26       rin  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     69  1.26       rin  * destination = STAMP_READ(offset)
     70  1.26       rin  */
     71  1.26       rin #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
     72  1.26       rin #define	STAMP_MASK		0xf
     73  1.26       rin #define	STAMP_READ(o)		stamp[o]
     74  1.26       rin 
     75  1.26       rin /*
     76   1.1        ad  * Initialize rasops_info struct for this colordepth.
     77   1.1        ad  */
     78   1.1        ad void
     79  1.13       dsl rasops2_init(struct rasops_info *ri)
     80   1.1        ad {
     81   1.1        ad 
     82   1.1        ad 	switch (ri->ri_font->fontwidth) {
     83   1.4        ad #ifndef RASOPS_SMALL
     84   1.1        ad 	case 8:
     85   1.1        ad 		ri->ri_ops.putchar = rasops2_putchar8;
     86   1.1        ad 		break;
     87   1.1        ad 	case 12:
     88   1.1        ad 		ri->ri_ops.putchar = rasops2_putchar12;
     89   1.1        ad 		break;
     90   1.1        ad 	case 16:
     91   1.1        ad 		ri->ri_ops.putchar = rasops2_putchar16;
     92   1.1        ad 		break;
     93   1.4        ad #endif	/* !RASOPS_SMALL */
     94   1.1        ad 	default:
     95   1.4        ad 		panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
     96   1.1        ad 		ri->ri_ops.putchar = rasops2_putchar;
     97   1.1        ad 		break;
     98   1.1        ad 	}
     99   1.5        pk 
    100   1.3        ad 	if ((ri->ri_font->fontwidth & 3) != 0) {
    101   1.1        ad 		ri->ri_ops.erasecols = rasops2_erasecols;
    102   1.1        ad 		ri->ri_ops.copycols = rasops2_copycols;
    103   1.1        ad 		ri->ri_do_cursor = rasops2_do_cursor;
    104   1.1        ad 	}
    105   1.1        ad }
    106   1.1        ad 
    107   1.1        ad /*
    108   1.1        ad  * Put a single character. This is the generic version.
    109   1.1        ad  */
    110   1.1        ad static void
    111  1.14       dsl rasops2_putchar(void *cookie, int row, int col, u_int uc, long attr)
    112   1.1        ad {
    113   1.1        ad 
    114   1.1        ad 	/* XXX punt */
    115   1.1        ad }
    116   1.1        ad 
    117   1.4        ad #ifndef RASOPS_SMALL
    118   1.4        ad /*
    119   1.4        ad  * Recompute the blitting stamp.
    120   1.4        ad  */
    121   1.4        ad static void
    122  1.13       dsl rasops2_makestamp(struct rasops_info *ri, long attr)
    123   1.4        ad {
    124   1.4        ad 	int i, fg, bg;
    125   1.5        pk 
    126  1.25       rin 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3;
    127  1.25       rin 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3;
    128   1.4        ad 	stamp_attr = attr;
    129   1.5        pk 
    130   1.4        ad 	for (i = 0; i < 16; i++) {
    131  1.18  kiyohara #if BYTE_ORDER == BIG_ENDIAN
    132  1.18  kiyohara #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    133  1.18  kiyohara #else
    134  1.18  kiyohara #define NEED_LITTLE_ENDIAN_STAMP 0
    135  1.18  kiyohara #endif
    136  1.18  kiyohara 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    137  1.18  kiyohara 			/* littel endian */
    138  1.26       rin 			stamp[i]  = (i & 8 ? fg : bg);
    139  1.18  kiyohara 			stamp[i] |= (i & 4 ? fg : bg) << 2;
    140  1.18  kiyohara 			stamp[i] |= (i & 2 ? fg : bg) << 4;
    141  1.18  kiyohara 			stamp[i] |= (i & 1 ? fg : bg) << 6;
    142  1.18  kiyohara 		} else {
    143  1.18  kiyohara 			/* big endian */
    144  1.26       rin 			stamp[i]  = (i & 1 ? fg : bg);
    145  1.18  kiyohara 			stamp[i] |= (i & 2 ? fg : bg) << 2;
    146  1.18  kiyohara 			stamp[i] |= (i & 4 ? fg : bg) << 4;
    147  1.18  kiyohara 			stamp[i] |= (i & 8 ? fg : bg) << 6;
    148  1.18  kiyohara 		}
    149   1.4        ad 	}
    150   1.4        ad }
    151   1.1        ad 
    152  1.26       rin #define	RASOPS_DEPTH	2
    153   1.1        ad 
    154  1.26       rin #define	RASOPS_WIDTH	8
    155  1.26       rin #include "rasops_putchar_width.h"
    156  1.26       rin #undef	RASOPS_WIDTH
    157  1.26       rin 
    158  1.26       rin #define	RASOPS_WIDTH	12
    159  1.26       rin #include "rasops_putchar_width.h"
    160  1.26       rin #undef	RASOPS_WIDTH
    161  1.26       rin 
    162  1.26       rin #define	RASOPS_WIDTH	16
    163  1.26       rin #include "rasops_putchar_width.h"
    164  1.26       rin #undef	RASOPS_WIDTH
    165   1.5        pk 
    166   1.4        ad #endif	/* !RASOPS_SMALL */
    167   1.1        ad 
    168   1.1        ad /*
    169   1.1        ad  * Grab routines common to depths where (bpp < 8)
    170   1.1        ad  */
    171   1.1        ad #define NAME(ident)	rasops2_##ident
    172   1.1        ad #define PIXEL_SHIFT	1
    173   1.1        ad 
    174   1.1        ad #include <dev/rasops/rasops_bitops.h>
    175