Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.34
      1 /* 	$NetBSD: rasops1.c,v 1.34 2019/08/02 04:39:09 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: rasops1.c,v 1.34 2019/08/02 04:39:09 rin Exp $");
     34 
     35 #include "opt_rasops.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/time.h>
     40 #include <machine/endian.h>
     41 
     42 #include <dev/wscons/wsdisplayvar.h>
     43 #include <dev/wscons/wsconsio.h>
     44 
     45 #define	_RASOPS_PRIVATE
     46 #define	RASOPS_DEPTH	1
     47 #include <dev/rasops/rasops.h>
     48 #include <dev/rasops/rasops_masks.h>
     49 
     50 static void	rasops1_copycols(void *, int, int, int, int);
     51 static void	rasops1_erasecols(void *, int, int, int, long);
     52 static void	rasops1_do_cursor(struct rasops_info *);
     53 static void	rasops1_putchar(void *, int, int col, u_int, long);
     54 #ifndef RASOPS_SMALL
     55 static void	rasops1_putchar8(void *, int, int col, u_int, long);
     56 static void	rasops1_putchar16(void *, int, int col, u_int, long);
     57 #endif
     58 
     59 /*
     60  * Initialize rasops_info struct for this colordepth.
     61  */
     62 void
     63 rasops1_init(struct rasops_info *ri)
     64 {
     65 
     66 	if ((ri->ri_font->fontwidth & 7) != 0) {
     67 		ri->ri_ops.erasecols = rasops1_erasecols;
     68 		ri->ri_ops.copycols = rasops1_copycols;
     69 		ri->ri_do_cursor = rasops1_do_cursor;
     70 	}
     71 
     72 	switch (ri->ri_font->fontwidth) {
     73 #ifndef RASOPS_SMALL
     74 	case 8:
     75 		ri->ri_ops.putchar = rasops1_putchar8;
     76 		break;
     77 	case 16:
     78 		ri->ri_ops.putchar = rasops1_putchar16;
     79 		break;
     80 #endif
     81 	default:
     82 		ri->ri_ops.putchar = rasops1_putchar;
     83 		break;
     84 	}
     85 }
     86 
     87 /*
     88  * Paint a single character. This is the generic version, this is ugly.
     89  */
     90 static void
     91 rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
     92 {
     93 	struct rasops_info *ri = (struct rasops_info *)cookie;
     94 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
     95 	uint32_t fs, rs, fb, bg, fg, lmask, rmask;
     96 	uint32_t height, width;
     97 	uint32_t *rp, *hp, tmp, tmp0, tmp1;
     98 	uint8_t *fr;
     99 	bool space;
    100 
    101 	hp = NULL;	/* XXX GCC */
    102 
    103 #ifdef RASOPS_CLIPPING
    104 	/* Catches 'row < 0' case too */
    105 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    106 		return;
    107 
    108 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    109 		return;
    110 #endif
    111 
    112 	col *= ri->ri_font->fontwidth;
    113 	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
    114 	    ((col >> 3) & ~3));
    115 	if (ri->ri_hwbits)
    116 		hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
    117 		    ((col >> 3) & ~3));
    118 	height = font->fontheight;
    119 	width = font->fontwidth;
    120 	col &= 31;
    121 	rs = ri->ri_stride;
    122 
    123 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    124 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    125 
    126 	/* If fg and bg match this becomes a space character */
    127 	if (uc == ' ' || fg == bg) {
    128 		space = true;
    129 		fr = NULL;	/* XXX GCC */
    130 		fs = 0;		/* XXX GCC */
    131 	} else {
    132 		space = false;
    133 		fr = FONT_GLYPH(uc, font, ri);
    134 		fs = font->stride;
    135 	}
    136 
    137 	if (col + width <= 32) {
    138 		/* Single word, only one mask */
    139 
    140 		rmask = rasops_pmask[col][width & 31];
    141 		lmask = ~rmask;
    142 
    143 		if (space) {
    144 			bg &= rmask;
    145 			while (height--) {
    146 				tmp = (*rp & lmask) | bg;
    147 				*rp = tmp;
    148 				DELTA(rp, rs, uint32_t *);
    149 				if (ri->ri_hwbits) {
    150 					*hp = tmp;
    151 					DELTA(hp, rs, uint32_t *);
    152 				}
    153 			}
    154 		} else {
    155 			while (height--) {
    156 				tmp = *rp & lmask;
    157 				fb = be32uatoh(fr);
    158 				fr += fs;
    159 				if (bg)
    160 					fb = ~fb;
    161 				tmp |= (MBE(fb >> col) & rmask);
    162 				*rp = tmp;
    163 				DELTA(rp, rs, uint32_t *);
    164 				if (ri->ri_hwbits) {
    165 					*hp = tmp;
    166 					DELTA(hp, rs, uint32_t *);
    167 				}
    168 			}
    169 		}
    170 
    171 		/* Do underline */
    172 		if ((attr & WSATTR_UNDERLINE) != 0) {
    173 			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    174 			tmp = (*rp & lmask) | (fg & rmask);
    175 			*rp = tmp;
    176 			if (ri->ri_hwbits) {
    177 				DELTA(hp, -(ri->ri_stride << 1), uint32_t *);
    178 				*hp = tmp;
    179 			}
    180 		}
    181 	} else {
    182 		/* Word boundary, two masks needed */
    183 
    184 		lmask = ~rasops_lmask[col];
    185 		rmask = ~rasops_rmask[(col + width) & 31];
    186 
    187 		if (space) {
    188 			width = bg & ~rmask;
    189 			bg = bg & ~lmask;
    190 			while (height--) {
    191 				tmp0 = (rp[0] & lmask) | bg;
    192 				tmp1 = (rp[1] & rmask) | width;
    193 				rp[0] = tmp0;
    194 				rp[1] = tmp1;
    195 				DELTA(rp, rs, uint32_t *);
    196 				if (ri->ri_hwbits) {
    197 					hp[0] = tmp0;
    198 					hp[1] = tmp1;
    199 					DELTA(hp, rs, uint32_t *);
    200 				}
    201 			}
    202 		} else {
    203 			width = 32 - col;
    204 			while (height--) {
    205 				tmp0 = rp[0] & lmask;
    206 				tmp1 = rp[1] & rmask;
    207 				fb = be32uatoh(fr);
    208 				fr += fs;
    209 				if (bg)
    210 					fb = ~fb;
    211 				tmp0 |= MBE(fb >> col);
    212 				tmp1 |= (MBE(fb << width) & ~rmask);
    213 				rp[0] = tmp0;
    214 				rp[1] = tmp1;
    215 				DELTA(rp, rs, uint32_t *);
    216 				if (ri->ri_hwbits) {
    217 					hp[0] = tmp0;
    218 					hp[1] = tmp1;
    219 					DELTA(hp, rs, uint32_t *);
    220 				}
    221 			}
    222 		}
    223 
    224 		/* Do underline */
    225 		if ((attr & WSATTR_UNDERLINE) != 0) {
    226 			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    227 			tmp0 = (rp[0] & lmask) | (fg & ~lmask);
    228 			tmp1 = (rp[1] & rmask) | (fg & ~rmask);
    229 			rp[0] = tmp0;
    230 			rp[1] = tmp1;
    231 			if (ri->ri_hwbits) {
    232 				DELTA(hp, -(ri->ri_stride << 1), uint32_t *);
    233 				hp[0] = tmp0;
    234 				hp[1] = tmp1;
    235 			}
    236 		}
    237 	}
    238 }
    239 
    240 #ifndef RASOPS_SMALL
    241 
    242 #define	RASOPS_WIDTH	8
    243 #include "rasops1_putchar_width.h"
    244 #undef	RASOPS_WIDTH
    245 
    246 #define	RASOPS_WIDTH	16
    247 #include "rasops1_putchar_width.h"
    248 #undef	RASOPS_WIDTH
    249 
    250 #endif	/* !RASOPS_SMALL */
    251 
    252 /*
    253  * Grab routines common to depths where (bpp < 8)
    254  */
    255 #include <dev/rasops/rasops_bitops.h>
    256