Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.29
      1  1.29       rin /* 	$NetBSD: rasops1.c,v 1.29 2019/07/29 02:57:41 rin Exp $	*/
      2   1.1        ad 
      3   1.5        ad /*-
      4   1.5        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5   1.1        ad  * All rights reserved.
      6   1.1        ad  *
      7   1.5        ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.12        ad  * by Andrew Doran.
      9   1.5        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.5        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.5        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.5        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.5        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.5        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.5        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.5        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.5        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.5        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.5        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.5        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        ad  */
     31   1.2        ad 
     32  1.14     lukem #include <sys/cdefs.h>
     33  1.29       rin __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.29 2019/07/29 02:57:41 rin Exp $");
     34  1.14     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.3        ad #include <dev/wscons/wsconsio.h>
     44   1.1        ad #include <dev/rasops/rasops.h>
     45   1.4        ad #include <dev/rasops/rasops_masks.h>
     46   1.1        ad 
     47  1.16     perry static void	rasops1_copycols(void *, int, int, int, int);
     48  1.16     perry static void	rasops1_erasecols(void *, int, int, int, long);
     49  1.16     perry static void	rasops1_do_cursor(struct rasops_info *);
     50  1.16     perry static void	rasops1_putchar(void *, int, int col, u_int, long);
     51  1.10        ad #ifndef RASOPS_SMALL
     52  1.16     perry static void	rasops1_putchar8(void *, int, int col, u_int, long);
     53  1.16     perry static void	rasops1_putchar16(void *, int, int col, u_int, long);
     54  1.10        ad #endif
     55   1.1        ad 
     56   1.1        ad /*
     57  1.13       wiz  * Initialize rasops_info struct for this colordepth.
     58   1.1        ad  */
     59   1.1        ad void
     60  1.19       dsl rasops1_init(struct rasops_info *ri)
     61   1.1        ad {
     62   1.1        ad 
     63  1.29       rin 	if ((ri->ri_font->fontwidth & 7) != 0) {
     64  1.29       rin 		ri->ri_ops.erasecols = rasops1_erasecols;
     65  1.29       rin 		ri->ri_ops.copycols = rasops1_copycols;
     66  1.29       rin 		ri->ri_do_cursor = rasops1_do_cursor;
     67  1.29       rin 	}
     68  1.29       rin 
     69   1.1        ad 	switch (ri->ri_font->fontwidth) {
     70  1.10        ad #ifndef RASOPS_SMALL
     71   1.1        ad 	case 8:
     72   1.1        ad 		ri->ri_ops.putchar = rasops1_putchar8;
     73   1.1        ad 		break;
     74   1.1        ad 	case 16:
     75   1.1        ad 		ri->ri_ops.putchar = rasops1_putchar16;
     76   1.1        ad 		break;
     77  1.10        ad #endif
     78   1.1        ad 	default:
     79   1.1        ad 		ri->ri_ops.putchar = rasops1_putchar;
     80   1.1        ad 		break;
     81   1.1        ad 	}
     82   1.1        ad }
     83   1.1        ad 
     84   1.1        ad /*
     85   1.4        ad  * Paint a single character. This is the generic version, this is ugly.
     86   1.1        ad  */
     87   1.1        ad static void
     88  1.20       dsl rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
     89   1.1        ad {
     90  1.23  macallan 	struct rasops_info *ri = (struct rasops_info *)cookie;
     91  1.23  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
     92  1.29       rin 	uint32_t fs, rs, fb, bg, fg, lmask, rmask;
     93  1.29       rin 	uint32_t height, width;
     94  1.29       rin 	uint32_t *rp, *hrp, tmp, tmp0, tmp1;
     95  1.25       rin 	uint8_t *fr;
     96  1.29       rin 	bool space;
     97  1.29       rin 
     98  1.29       rin 	hrp = NULL;	/* XXX GCC */
     99  1.11        pk 
    100  1.11        pk #ifdef RASOPS_CLIPPING
    101  1.11        pk 	/* Catches 'row < 0' case too */
    102   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    103   1.4        ad 		return;
    104   1.4        ad 
    105   1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    106   1.4        ad 		return;
    107   1.4        ad #endif
    108   1.4        ad 
    109   1.4        ad 	col *= ri->ri_font->fontwidth;
    110  1.26       rin 	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
    111  1.26       rin 	    ((col >> 3) & ~3));
    112  1.21  macallan 	if (ri->ri_hwbits)
    113  1.26       rin 		hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
    114  1.21  macallan 		    ((col >> 3) & ~3));
    115  1.23  macallan 	height = font->fontheight;
    116  1.23  macallan 	width = font->fontwidth;
    117  1.29       rin 	col &= 31;
    118   1.4        ad 	rs = ri->ri_stride;
    119  1.11        pk 
    120   1.9        ad 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    121   1.9        ad 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    122   1.4        ad 
    123   1.4        ad 	/* If fg and bg match this becomes a space character */
    124  1.29       rin 	if (uc == ' ' || fg == bg) {
    125  1.29       rin 		space = true;
    126  1.29       rin 		fr = NULL;	/* XXX GCC */
    127  1.29       rin 		fs = 0;		/* XXX GCC */
    128   1.4        ad 	} else {
    129  1.29       rin 		space = false;
    130  1.28       rin 		fr = FONT_GLYPH(uc, font, ri);
    131  1.23  macallan 		fs = font->stride;
    132   1.4        ad 	}
    133  1.11        pk 
    134  1.29       rin 	if (col + width <= 32) {
    135  1.29       rin 		/* Single word, only one mask */
    136  1.29       rin 
    137   1.4        ad 		rmask = rasops_pmask[col][width];
    138   1.4        ad 		lmask = ~rmask;
    139  1.11        pk 
    140  1.29       rin 		if (space) {
    141   1.4        ad 			bg &= rmask;
    142   1.4        ad 			while (height--) {
    143  1.21  macallan 				tmp = (*rp & lmask) | bg;
    144  1.21  macallan 				*rp = tmp;
    145  1.26       rin 				DELTA(rp, rs, uint32_t *);
    146  1.21  macallan 				if (ri->ri_hwbits) {
    147  1.21  macallan 					*hrp = tmp;
    148  1.26       rin 					DELTA(hrp, rs, uint32_t *);
    149  1.21  macallan 				}
    150   1.4        ad 			}
    151   1.4        ad 		} else {
    152  1.29       rin 			while (height--) {
    153  1.29       rin 				tmp = *rp & lmask;
    154  1.29       rin 				fb = fr[3] | (fr[2] << 8) |
    155  1.29       rin 				    (fr[1] << 16) | (fr[0] << 24);
    156  1.29       rin 				fr += fs;
    157  1.29       rin 				if (bg)
    158  1.29       rin 					fb = ~fb;
    159  1.29       rin 				tmp |= (MBE(fb >> col) & rmask);
    160  1.29       rin 				*rp = tmp;
    161  1.29       rin 				DELTA(rp, rs, uint32_t *);
    162  1.29       rin 				if (ri->ri_hwbits) {
    163  1.29       rin 					*hrp = tmp;
    164  1.29       rin 					DELTA(hrp, rs, uint32_t *);
    165   1.4        ad 				}
    166   1.4        ad 			}
    167   1.4        ad 		}
    168  1.11        pk 
    169   1.4        ad 		/* Do underline */
    170  1.24   mlelstv 		if ((attr & WSATTR_UNDERLINE) != 0) {
    171  1.26       rin 			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    172  1.21  macallan 			tmp = (*rp & lmask) | (fg & rmask);
    173  1.21  macallan 			*rp = tmp;
    174  1.21  macallan 			if (ri->ri_hwbits) {
    175  1.26       rin 				DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
    176  1.21  macallan 				*hrp = tmp;
    177  1.21  macallan 			}
    178   1.4        ad 		}
    179   1.4        ad 	} else {
    180  1.29       rin 		/* Word boundary, two masks needed */
    181  1.29       rin 
    182   1.4        ad 		lmask = ~rasops_lmask[col];
    183   1.4        ad 		rmask = ~rasops_rmask[(col + width) & 31];
    184  1.11        pk 
    185  1.29       rin 		if (space) {
    186   1.8     mouse 			width = bg & ~rmask;
    187   1.4        ad 			bg = bg & ~lmask;
    188   1.4        ad 			while (height--) {
    189  1.29       rin 				tmp0 = (rp[0] & lmask) | bg;
    190  1.29       rin 				tmp1 = (rp[1] & rmask) | width;
    191  1.29       rin 				rp[0] = tmp0;
    192  1.29       rin 				rp[1] = tmp1;
    193  1.26       rin 				DELTA(rp, rs, uint32_t *);
    194  1.21  macallan 				if (ri->ri_hwbits) {
    195  1.29       rin 					hrp[0] = tmp0;
    196  1.29       rin 					hrp[1] = tmp1;
    197  1.26       rin 					DELTA(hrp, rs, uint32_t *);
    198  1.21  macallan 				}
    199   1.4        ad 			}
    200   1.4        ad 		} else {
    201   1.4        ad 			width = 32 - col;
    202  1.29       rin 			while (height--) {
    203  1.29       rin 				tmp0 = rp[0] & lmask;
    204  1.29       rin 				tmp1 = rp[1] & rmask;
    205  1.29       rin 				fb = fr[3] | (fr[2] << 8) |
    206  1.29       rin 				    (fr[1] << 16) | (fr[0] << 24);
    207  1.29       rin 				fr += fs;
    208  1.29       rin 				if (bg)
    209  1.29       rin 					fb = ~fb;
    210  1.29       rin 				tmp0 |= MBE(fb >> col);
    211  1.29       rin 				tmp1 |= (MBE(fb << width) & ~rmask);
    212  1.29       rin 				rp[0] = tmp0;
    213  1.29       rin 				rp[1] = tmp1;
    214  1.29       rin 				DELTA(rp, rs, uint32_t *);
    215  1.29       rin 				if (ri->ri_hwbits) {
    216  1.29       rin 					hrp[0] = tmp0;
    217  1.29       rin 					hrp[1] = tmp1;
    218  1.29       rin 					DELTA(hrp, rs, uint32_t *);
    219   1.4        ad 				}
    220   1.4        ad 			}
    221   1.4        ad 		}
    222   1.1        ad 
    223   1.4        ad 		/* Do underline */
    224  1.24   mlelstv 		if ((attr & WSATTR_UNDERLINE) != 0) {
    225  1.26       rin 			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    226  1.29       rin 			tmp0 = (rp[0] & lmask) | (fg & ~lmask);
    227  1.29       rin 			tmp1 = (rp[1] & rmask) | (fg & ~rmask);
    228  1.29       rin 			rp[0] = tmp0;
    229  1.29       rin 			rp[1] = tmp1;
    230  1.21  macallan 			if (ri->ri_hwbits) {
    231  1.26       rin 				DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
    232  1.29       rin 				hrp[0] = tmp0;
    233  1.29       rin 				hrp[1] = tmp1;
    234  1.21  macallan 			}
    235   1.4        ad 		}
    236   1.4        ad 	}
    237   1.1        ad }
    238   1.1        ad 
    239  1.10        ad #ifndef RASOPS_SMALL
    240   1.1        ad 
    241  1.29       rin #define	RASOPS_WIDTH	8
    242  1.29       rin #include "rasops1_putchar_width.h"
    243  1.29       rin #undef	RASOPS_WIDTH
    244  1.29       rin 
    245  1.29       rin #define	RASOPS_WIDTH	16
    246  1.29       rin #include "rasops1_putchar_width.h"
    247  1.29       rin #undef	RASOPS_WIDTH
    248   1.1        ad 
    249  1.10        ad #endif	/* !RASOPS_SMALL */
    250   1.1        ad 
    251   1.1        ad /*
    252   1.4        ad  * Grab routines common to depths where (bpp < 8)
    253   1.1        ad  */
    254   1.4        ad #define NAME(ident)	rasops1_##ident
    255   1.4        ad #define PIXEL_SHIFT	0
    256   1.1        ad 
    257   1.4        ad #include <dev/rasops/rasops_bitops.h>
    258