Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.36
      1 /* 	$NetBSD: rasops1.c,v 1.36 2019/08/09 12:05:51 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.36 2019/08/09 12:05:51 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 	if (__predict_false(!CHAR_IN_FONT(uc, font)))
    104 		return;
    105 
    106 #ifdef RASOPS_CLIPPING
    107 	/* Catches 'row < 0' case too */
    108 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    109 		return;
    110 
    111 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    112 		return;
    113 #endif
    114 
    115 	col *= ri->ri_font->fontwidth;
    116 	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
    117 	    ((col >> 3) & ~3));
    118 	if (ri->ri_hwbits)
    119 		hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
    120 		    ((col >> 3) & ~3));
    121 	height = font->fontheight;
    122 	width = font->fontwidth;
    123 	col &= 31;
    124 	rs = ri->ri_stride;
    125 
    126 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    127 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    128 
    129 	/* If fg and bg match this becomes a space character */
    130 	if (uc == ' ' || fg == bg) {
    131 		space = true;
    132 		fr = NULL;	/* XXX GCC */
    133 		fs = 0;		/* XXX GCC */
    134 	} else {
    135 		space = false;
    136 		fr = FONT_GLYPH(uc, font, ri);
    137 		fs = font->stride;
    138 	}
    139 
    140 	if (col + width <= 32) {
    141 		/* Single word, only one mask */
    142 
    143 		rmask = rasops_pmask[col][width & 31];
    144 		lmask = ~rmask;
    145 
    146 		if (space) {
    147 			bg &= rmask;
    148 			while (height--) {
    149 				tmp = (*rp & lmask) | bg;
    150 				*rp = tmp;
    151 				DELTA(rp, rs, uint32_t *);
    152 				if (ri->ri_hwbits) {
    153 					*hp = tmp;
    154 					DELTA(hp, rs, uint32_t *);
    155 				}
    156 			}
    157 		} else {
    158 			while (height--) {
    159 				tmp = *rp & lmask;
    160 				fb = be32uatoh(fr);
    161 				fr += fs;
    162 				if (bg)
    163 					fb = ~fb;
    164 				tmp |= (MBE(fb >> col) & rmask);
    165 				*rp = tmp;
    166 				DELTA(rp, rs, uint32_t *);
    167 				if (ri->ri_hwbits) {
    168 					*hp = tmp;
    169 					DELTA(hp, rs, uint32_t *);
    170 				}
    171 			}
    172 		}
    173 
    174 		/* Do underline */
    175 		if ((attr & WSATTR_UNDERLINE) != 0) {
    176 			DELTA(rp, - ri->ri_stride * ri->ri_ul.off, uint32_t *);
    177 			if (ri->ri_hwbits)
    178 				DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
    179 				    uint32_t *);
    180 			for (height = ri->ri_ul.height; height; height--) {
    181 				DELTA(rp, - ri->ri_stride, uint32_t *);
    182 				tmp = (*rp & lmask) | (fg & rmask);
    183 				*rp = tmp;
    184 				if (ri->ri_hwbits) {
    185 					DELTA(hp, - ri->ri_stride, uint32_t *);
    186 					*hp = tmp;
    187 				}
    188 			}
    189 		}
    190 	} else {
    191 		/* Word boundary, two masks needed */
    192 
    193 		lmask = ~rasops_lmask[col];
    194 		rmask = ~rasops_rmask[(col + width) & 31];
    195 
    196 		if (space) {
    197 			width = bg & ~rmask;
    198 			bg = bg & ~lmask;
    199 			while (height--) {
    200 				tmp0 = (rp[0] & lmask) | bg;
    201 				tmp1 = (rp[1] & rmask) | width;
    202 				rp[0] = tmp0;
    203 				rp[1] = tmp1;
    204 				DELTA(rp, rs, uint32_t *);
    205 				if (ri->ri_hwbits) {
    206 					hp[0] = tmp0;
    207 					hp[1] = tmp1;
    208 					DELTA(hp, rs, uint32_t *);
    209 				}
    210 			}
    211 		} else {
    212 			width = 32 - col;
    213 			while (height--) {
    214 				tmp0 = rp[0] & lmask;
    215 				tmp1 = rp[1] & rmask;
    216 				fb = be32uatoh(fr);
    217 				fr += fs;
    218 				if (bg)
    219 					fb = ~fb;
    220 				tmp0 |= MBE(fb >> col);
    221 				tmp1 |= (MBE(fb << width) & ~rmask);
    222 				rp[0] = tmp0;
    223 				rp[1] = tmp1;
    224 				DELTA(rp, rs, uint32_t *);
    225 				if (ri->ri_hwbits) {
    226 					hp[0] = tmp0;
    227 					hp[1] = tmp1;
    228 					DELTA(hp, rs, uint32_t *);
    229 				}
    230 			}
    231 		}
    232 
    233 		/* Do underline */
    234 		if ((attr & WSATTR_UNDERLINE) != 0) {
    235 			DELTA(rp, - ri->ri_stride * ri->ri_ul.off, uint32_t *);
    236 			if (ri->ri_hwbits)
    237 				DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
    238 				    uint32_t *);
    239 			for (height = ri->ri_ul.height; height; height--) {
    240 				DELTA(rp, - ri->ri_stride, uint32_t *);
    241 				tmp0 = (rp[0] & lmask) | (fg & ~lmask);
    242 				tmp1 = (rp[1] & rmask) | (fg & ~rmask);
    243 				rp[0] = tmp0;
    244 				rp[1] = tmp1;
    245 				if (ri->ri_hwbits) {
    246 					DELTA(hp, - ri->ri_stride, uint32_t *);
    247 					hp[0] = tmp0;
    248 					hp[1] = tmp1;
    249 				}
    250 			}
    251 		}
    252 	}
    253 }
    254 
    255 #ifndef RASOPS_SMALL
    256 
    257 #define	RASOPS_WIDTH	8
    258 #include "rasops1_putchar_width.h"
    259 #undef	RASOPS_WIDTH
    260 
    261 #define	RASOPS_WIDTH	16
    262 #include "rasops1_putchar_width.h"
    263 #undef	RASOPS_WIDTH
    264 
    265 #endif	/* !RASOPS_SMALL */
    266 
    267 /*
    268  * Grab routines common to depths where (bpp < 8)
    269  */
    270 #include <dev/rasops/rasops_bitops.h>
    271