Home | History | Annotate | Line # | Download | only in rasops
rasops24.c revision 1.34
      1 /* 	$NetBSD: rasops24.c,v 1.34 2019/07/25 03:02:44 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: rasops24.c,v 1.34 2019/07/25 03:02:44 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 
     41 #include <machine/endian.h>
     42 #include <sys/bswap.h>
     43 
     44 #include <dev/wscons/wsdisplayvar.h>
     45 #include <dev/wscons/wsconsio.h>
     46 #include <dev/rasops/rasops.h>
     47 
     48 static void 	rasops24_erasecols(void *, int, int, int, long);
     49 static void 	rasops24_eraserows(void *, int, int, long);
     50 static void 	rasops24_putchar(void *, int, int, u_int, long attr);
     51 #ifndef RASOPS_SMALL
     52 static void 	rasops24_putchar8(void *, int, int, u_int, long attr);
     53 static void 	rasops24_putchar12(void *, int, int, u_int, long attr);
     54 static void 	rasops24_putchar16(void *, int, int, u_int, long attr);
     55 static void	rasops24_makestamp(struct rasops_info *, long);
     56 
     57 /*
     58  * 4x1 stamp for optimized character blitting
     59  */
     60 static uint32_t	stamp[64];
     61 static long	stamp_attr;
     62 static int	stamp_mutex;	/* XXX see note in readme */
     63 #endif
     64 
     65 /*
     66  * XXX this confuses the hell out of gcc2 (not egcs) which always insists
     67  * that the shift count is negative.
     68  *
     69  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     70  * destination uint32_t[0] = STAMP_READ(offset)
     71  * destination uint32_t[1] = STAMP_READ(offset + 4)
     72  * destination uint32_t[2] = STAMP_READ(offset + 8)
     73  */
     74 #define STAMP_SHIFT(fb,n)	((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4))
     75 #define STAMP_MASK		(0xf << 4)
     76 #define STAMP_READ(o)		(*(uint32_t *)((char *)stamp + (o)))
     77 
     78 /*
     79  * Initialize rasops_info struct for this colordepth.
     80  */
     81 void
     82 rasops24_init(struct rasops_info *ri)
     83 {
     84 
     85 	switch (ri->ri_font->fontwidth) {
     86 #ifndef RASOPS_SMALL
     87 	case 8:
     88 		ri->ri_ops.putchar = rasops24_putchar8;
     89 		break;
     90 	case 12:
     91 		ri->ri_ops.putchar = rasops24_putchar12;
     92 		break;
     93 	case 16:
     94 		ri->ri_ops.putchar = rasops24_putchar16;
     95 		break;
     96 #endif
     97 	default:
     98 		ri->ri_ops.putchar = rasops24_putchar;
     99 		break;
    100 	}
    101 
    102 	if (ri->ri_rnum == 0) {
    103 		ri->ri_rnum = 8;
    104 		ri->ri_rpos = 0;
    105 		ri->ri_gnum = 8;
    106 		ri->ri_gpos = 8;
    107 		ri->ri_bnum = 8;
    108 		ri->ri_bpos = 16;
    109 	}
    110 
    111 	ri->ri_ops.erasecols = rasops24_erasecols;
    112 	ri->ri_ops.eraserows = rasops24_eraserows;
    113 }
    114 
    115 /*
    116  * Put a single character. This is the generic version.
    117  * XXX this bites - we should use masks.
    118  */
    119 static void
    120 rasops24_putchar(void *cookie, int row, int col, u_int uc, long attr)
    121 {
    122 	int fb, width, height, cnt, clr[2];
    123 	struct rasops_info *ri = (struct rasops_info *)cookie;
    124 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    125 	uint8_t *dp, *rp, *fr;
    126 
    127 #ifdef RASOPS_CLIPPING
    128 	/* Catches 'row < 0' case too */
    129 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    130 		return;
    131 
    132 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    133 		return;
    134 #endif
    135 
    136 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    137 	height = font->fontheight;
    138 	width = font->fontwidth;
    139 
    140 	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
    141 	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
    142 
    143 	if (uc == ' ') {
    144 		uint8_t c = clr[0];
    145 		while (height--) {
    146 			dp = rp;
    147 			rp += ri->ri_stride;
    148 
    149 			for (cnt = width; cnt; cnt--) {
    150 				*dp++ = c >> 16;
    151 				*dp++ = c >> 8;
    152 				*dp++ = c;
    153 			}
    154 		}
    155 	} else {
    156 		fr = FONT_GLYPH(uc, font, ri);
    157 
    158 		while (height--) {
    159 			dp = rp;
    160 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    161 			    (fr[0] << 24);
    162 			fr += font->stride;
    163 			rp += ri->ri_stride;
    164 
    165 			for (cnt = width; cnt; cnt--, fb <<= 1) {
    166 				if ((fb >> 31) & 1) {
    167 					*dp++ = clr[1] >> 16;
    168 					*dp++ = clr[1] >> 8;
    169 					*dp++ = clr[1];
    170 				} else {
    171 					*dp++ = clr[0] >> 16;
    172 					*dp++ = clr[0] >> 8;
    173 					*dp++ = clr[0];
    174 				}
    175 			}
    176 		}
    177 	}
    178 
    179 	/* Do underline */
    180 	if ((attr & WSATTR_UNDERLINE) != 0) {
    181 		uint8_t c = clr[1];
    182 
    183 		rp -= ri->ri_stride << 1;
    184 
    185 		while (width--) {
    186 			*rp++ = c >> 16;
    187 			*rp++ = c >> 8;
    188 			*rp++ = c;
    189 		}
    190 	}
    191 }
    192 
    193 #ifndef RASOPS_SMALL
    194 /*
    195  * Recompute the blitting stamp.
    196  */
    197 static void
    198 rasops24_makestamp(struct rasops_info *ri, long attr)
    199 {
    200 	u_int fg, bg, c1, c2, c3, c4;
    201 	int i;
    202 
    203 	fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffffff;
    204 	bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffffff;
    205 	stamp_attr = attr;
    206 
    207 	for (i = 0; i < 64; i += 4) {
    208 #if BYTE_ORDER == LITTLE_ENDIAN
    209 		c1 = (i & 32 ? fg : bg);
    210 		c2 = (i & 16 ? fg : bg);
    211 		c3 = (i & 8 ? fg : bg);
    212 		c4 = (i & 4 ? fg : bg);
    213 #else
    214 		c1 = (i & 8 ? fg : bg);
    215 		c2 = (i & 4 ? fg : bg);
    216 		c3 = (i & 16 ? fg : bg);
    217 		c4 = (i & 32 ? fg : bg);
    218 #endif
    219 		stamp[i+0] = (c1 <<  8) | (c2 >> 16);
    220 		stamp[i+1] = (c2 << 16) | (c3 >>  8);
    221 		stamp[i+2] = (c3 << 24) | c4;
    222 
    223 #if BYTE_ORDER == LITTLE_ENDIAN
    224 		if ((ri->ri_flg & RI_BSWAP) == 0) {
    225 #else
    226 		if ((ri->ri_flg & RI_BSWAP) != 0) {
    227 #endif
    228 			stamp[i+0] = bswap32(stamp[i+0]);
    229 			stamp[i+1] = bswap32(stamp[i+1]);
    230 			stamp[i+2] = bswap32(stamp[i+2]);
    231 		}
    232 	}
    233 }
    234 
    235 /*
    236  * Put a single character. This is for 8-pixel wide fonts.
    237  */
    238 static void
    239 rasops24_putchar8(void *cookie, int row, int col, u_int uc, long attr)
    240 {
    241 	struct rasops_info *ri = (struct rasops_info *)cookie;
    242 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    243 	int height, so, fs;
    244 	uint32_t *rp;
    245 	uint8_t *fr;
    246 
    247 	/* Can't risk remaking the stamp if it's already in use */
    248 	if (stamp_mutex++) {
    249 		stamp_mutex--;
    250 		rasops24_putchar(cookie, row, col, uc, attr);
    251 		return;
    252 	}
    253 
    254 #ifdef RASOPS_CLIPPING
    255 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    256 		stamp_mutex--;
    257 		return;
    258 	}
    259 
    260 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    261 		stamp_mutex--;
    262 		return;
    263 	}
    264 #endif
    265 
    266 	/* Recompute stamp? */
    267 	if (attr != stamp_attr)
    268 		rasops24_makestamp(ri, attr);
    269 
    270 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    271 	height = font->fontheight;
    272 
    273 	if (uc == (u_int)-1) {
    274 		while (height--) {
    275 			rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] =
    276 			    stamp[0];
    277 			DELTA(rp, ri->ri_stride, uint32_t *);
    278 		}
    279 	} else {
    280 		fr = FONT_GLYPH(uc, font, ri);
    281 		fs = font->stride;
    282 
    283 		while (height--) {
    284 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    285 			rp[0] = STAMP_READ(so);
    286 			rp[1] = STAMP_READ(so + 4);
    287 			rp[2] = STAMP_READ(so + 8);
    288 
    289 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    290 			rp[3] = STAMP_READ(so);
    291 			rp[4] = STAMP_READ(so + 4);
    292 			rp[5] = STAMP_READ(so + 8);
    293 
    294 			fr += fs;
    295 			DELTA(rp, ri->ri_stride, uint32_t *);
    296 		}
    297 	}
    298 
    299 	/* Do underline */
    300 	if ((attr & WSATTR_UNDERLINE) != 0) {
    301 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    302 		rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = STAMP_READ(52);
    303 	}
    304 
    305 	stamp_mutex--;
    306 }
    307 
    308 /*
    309  * Put a single character. This is for 12-pixel wide fonts.
    310  */
    311 static void
    312 rasops24_putchar12(void *cookie, int row, int col, u_int uc, long attr)
    313 {
    314 	struct rasops_info *ri = (struct rasops_info *)cookie;
    315 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    316 	int height, so, fs;
    317 	uint32_t *rp;
    318 	uint8_t *fr;
    319 
    320 	/* Can't risk remaking the stamp if it's already in use */
    321 	if (stamp_mutex++) {
    322 		stamp_mutex--;
    323 		rasops24_putchar(cookie, row, col, uc, attr);
    324 		return;
    325 	}
    326 
    327 #ifdef RASOPS_CLIPPING
    328 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    329 		stamp_mutex--;
    330 		return;
    331 	}
    332 
    333 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    334 		stamp_mutex--;
    335 		return;
    336 	}
    337 #endif
    338 
    339 	/* Recompute stamp? */
    340 	if (attr != stamp_attr)
    341 		rasops24_makestamp(ri, attr);
    342 
    343 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    344 	height = font->fontheight;
    345 
    346 	if (uc == (u_int)-1) {
    347 		while (height--) {
    348 			rp[0] = rp[1] = rp[2] = rp[3] =
    349 			rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = stamp[0];
    350 			DELTA(rp, ri->ri_stride, uint32_t *);
    351 		}
    352 	} else {
    353 		fr = FONT_GLYPH(uc, font, ri);
    354 		fs = font->stride;
    355 
    356 		while (height--) {
    357 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    358 			rp[0] = STAMP_READ(so);
    359 			rp[1] = STAMP_READ(so + 4);
    360 			rp[2] = STAMP_READ(so + 8);
    361 
    362 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    363 			rp[3] = STAMP_READ(so);
    364 			rp[4] = STAMP_READ(so + 4);
    365 			rp[5] = STAMP_READ(so + 8);
    366 
    367 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    368 			rp[6] = STAMP_READ(so);
    369 			rp[7] = STAMP_READ(so + 4);
    370 			rp[8] = STAMP_READ(so + 8);
    371 
    372 			fr += fs;
    373 			DELTA(rp, ri->ri_stride, uint32_t *);
    374 		}
    375 	}
    376 
    377 	/* Do underline */
    378 	if ((attr & WSATTR_UNDERLINE) != 0) {
    379 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    380 		rp[0] = rp[1] = rp[2] = rp[3] =
    381 		rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = STAMP_READ(52);
    382 	}
    383 
    384 	stamp_mutex--;
    385 }
    386 
    387 /*
    388  * Put a single character. This is for 16-pixel wide fonts.
    389  */
    390 static void
    391 rasops24_putchar16(void *cookie, int row, int col, u_int uc, long attr)
    392 {
    393 	struct rasops_info *ri = (struct rasops_info *)cookie;
    394 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    395 	int height, so, fs;
    396 	uint32_t *rp;
    397 	uint8_t *fr;
    398 
    399 	/* Can't risk remaking the stamp if it's already in use */
    400 	if (stamp_mutex++) {
    401 		stamp_mutex--;
    402 		rasops24_putchar(cookie, row, col, uc, attr);
    403 		return;
    404 	}
    405 
    406 #ifdef RASOPS_CLIPPING
    407 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    408 		stamp_mutex--;
    409 		return;
    410 	}
    411 
    412 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    413 		stamp_mutex--;
    414 		return;
    415 	}
    416 #endif
    417 
    418 	/* Recompute stamp? */
    419 	if (attr != stamp_attr)
    420 		rasops24_makestamp(ri, attr);
    421 
    422 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    423 	height = font->fontheight;
    424 
    425 	if (uc == (u_int)-1) {
    426 		while (height--) {
    427 			rp[0] = rp[1] = rp[2] = rp[3] =
    428 			rp[4] = rp[5] = rp[6] = rp[7] =
    429 			rp[8] = rp[9] = rp[10] = rp[11] = stamp[0];
    430 			DELTA(rp, ri->ri_stride, uint32_t *);
    431 		}
    432 	} else {
    433 		fr = FONT_GLYPH(uc, font, ri);
    434 		fs = font->stride;
    435 
    436 		while (height--) {
    437 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    438 			rp[0] = STAMP_READ(so);
    439 			rp[1] = STAMP_READ(so + 4);
    440 			rp[2] = STAMP_READ(so + 8);
    441 
    442 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    443 			rp[3] = STAMP_READ(so);
    444 			rp[4] = STAMP_READ(so + 4);
    445 			rp[5] = STAMP_READ(so + 8);
    446 
    447 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    448 			rp[6] = STAMP_READ(so);
    449 			rp[7] = STAMP_READ(so + 4);
    450 			rp[8] = STAMP_READ(so + 8);
    451 
    452 			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
    453 			rp[9] = STAMP_READ(so);
    454 			rp[10] = STAMP_READ(so + 4);
    455 			rp[11] = STAMP_READ(so + 8);
    456 
    457 			DELTA(rp, ri->ri_stride, uint32_t *);
    458 			fr += fs;
    459 		}
    460 	}
    461 
    462 	/* Do underline */
    463 	if ((attr & WSATTR_UNDERLINE) != 0) {
    464 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    465 		rp[0] = rp[1] = rp[2] = rp[3] =
    466 		rp[4] = rp[5] = rp[6] = rp[7] =
    467 		rp[8] = rp[9] = rp[10] = rp[11] = STAMP_READ(52);
    468 	}
    469 
    470 	stamp_mutex--;
    471 }
    472 #endif	/* !RASOPS_SMALL */
    473 
    474 /*
    475  * Erase rows. This is nice and easy due to alignment.
    476  */
    477 static void
    478 rasops24_eraserows(void *cookie, int row, int num, long attr)
    479 {
    480 	int n9, n3, n1, cnt, stride, delta;
    481 	uint32_t *dp, clr, xstamp[3];
    482 	struct rasops_info *ri;
    483 
    484 	/*
    485 	 * If the color is gray, we can cheat and use the generic routines
    486 	 * (which are faster, hopefully) since the r,g,b values are the same.
    487 	 */
    488 	if ((attr & WSATTR_PRIVATE2) != 0) {
    489 		rasops_eraserows(cookie, row, num, attr);
    490 		return;
    491 	}
    492 
    493 	ri = (struct rasops_info *)cookie;
    494 
    495 #ifdef RASOPS_CLIPPING
    496 	if (row < 0) {
    497 		num += row;
    498 		row = 0;
    499 	}
    500 
    501 	if ((row + num) > ri->ri_rows)
    502 		num = ri->ri_rows - row;
    503 
    504 	if (num <= 0)
    505 		return;
    506 #endif
    507 
    508 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    509 	xstamp[0] = (clr <<  8) | (clr >> 16);
    510 	xstamp[1] = (clr << 16) | (clr >>  8);
    511 	xstamp[2] = (clr << 24) | clr;
    512 
    513 #if BYTE_ORDER == LITTLE_ENDIAN
    514 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    515 #else
    516 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    517 #endif
    518 		xstamp[0] = bswap32(xstamp[0]);
    519 		xstamp[1] = bswap32(xstamp[1]);
    520 		xstamp[2] = bswap32(xstamp[2]);
    521 	}
    522 
    523 	/*
    524 	 * XXX the wsdisplay_emulops interface seems a little deficient in
    525 	 * that there is no way to clear the *entire* screen. We provide a
    526 	 * workaround here: if the entire console area is being cleared, and
    527 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    528 	 */
    529 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    530 		stride = ri->ri_stride;
    531 		num = ri->ri_height;
    532 		dp = (uint32_t *)ri->ri_origbits;
    533 		delta = 0;
    534 	} else {
    535 		stride = ri->ri_emustride;
    536 		num *= ri->ri_font->fontheight;
    537 		dp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale);
    538 		delta = ri->ri_delta;
    539 	}
    540 
    541 	n9 = stride / 36;
    542 	cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
    543 	n3 = (stride - cnt) / 12;
    544 	cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
    545 	n1 = (stride - cnt) >> 2;
    546 
    547 	while (num--) {
    548 		for (cnt = n9; cnt; cnt--) {
    549 			dp[0] = xstamp[0];
    550 			dp[1] = xstamp[1];
    551 			dp[2] = xstamp[2];
    552 			dp[3] = xstamp[0];
    553 			dp[4] = xstamp[1];
    554 			dp[5] = xstamp[2];
    555 			dp[6] = xstamp[0];
    556 			dp[7] = xstamp[1];
    557 			dp[8] = xstamp[2];
    558 			dp += 9;
    559 		}
    560 
    561 		for (cnt = n3; cnt; cnt--) {
    562 			dp[0] = xstamp[0];
    563 			dp[1] = xstamp[1];
    564 			dp[2] = xstamp[2];
    565 			dp += 3;
    566 		}
    567 
    568 		for (cnt = 0; cnt < n1; cnt++)
    569 			*dp++ = xstamp[cnt];
    570 
    571 		DELTA(dp, delta, uint32_t *);
    572 	}
    573 }
    574 
    575 /*
    576  * Erase columns.
    577  */
    578 static void
    579 rasops24_erasecols(void *cookie, int row, int col, int num, long attr)
    580 {
    581 	int n12, n4, height, cnt, slop, clr, xstamp[3];
    582 	struct rasops_info *ri;
    583 	uint32_t *dp, *rp;
    584 	uint8_t *dbp;
    585 
    586 	/*
    587 	 * If the color is gray, we can cheat and use the generic routines
    588 	 * (which are faster, hopefully) since the r,g,b values are the same.
    589 	 */
    590 	if ((attr & WSATTR_PRIVATE2) != 0) {
    591 		rasops_erasecols(cookie, row, col, num, attr);
    592 		return;
    593 	}
    594 
    595 	ri = (struct rasops_info *)cookie;
    596 
    597 #ifdef RASOPS_CLIPPING
    598 	/* Catches 'row < 0' case too */
    599 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    600 		return;
    601 
    602 	if (col < 0) {
    603 		num += col;
    604 		col = 0;
    605 	}
    606 
    607 	if ((col + num) > ri->ri_cols)
    608 		num = ri->ri_cols - col;
    609 
    610 	if (num <= 0)
    611 		return;
    612 #endif
    613 
    614 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    615 	num *= ri->ri_font->fontwidth;
    616 	height = ri->ri_font->fontheight;
    617 
    618 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    619 	xstamp[0] = (clr <<  8) | (clr >> 16);
    620 	xstamp[1] = (clr << 16) | (clr >>  8);
    621 	xstamp[2] = (clr << 24) | clr;
    622 
    623 #if BYTE_ORDER == LITTLE_ENDIAN
    624 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    625 #else
    626 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    627 #endif
    628 		xstamp[0] = bswap32(xstamp[0]);
    629 		xstamp[1] = bswap32(xstamp[1]);
    630 		xstamp[2] = bswap32(xstamp[2]);
    631 	}
    632 
    633 	/*
    634 	 * The current byte offset mod 4 tells us the number of 24-bit pels
    635 	 * we need to write for alignment to 32-bits. Once we're aligned on
    636 	 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
    637 	 * the stamp does not need to be rotated. The following shows the
    638 	 * layout of 4 pels in a 3 word region and illustrates this:
    639 	 *
    640 	 *	aaab bbcc cddd
    641 	 */
    642 	slop = (int)(long)rp & 3;	num -= slop;
    643 	n12 = num / 12;		num -= (n12 << 3) + (n12 << 2);
    644 	n4 = num >> 2;		num &= 3;
    645 
    646 	while (height--) {
    647 		dbp = (uint8_t *)rp;
    648 		DELTA(rp, ri->ri_stride, uint32_t *);
    649 
    650 		/* Align to 4 bytes */
    651 		/* XXX handle with masks, bring under control of RI_BSWAP */
    652 		for (cnt = slop; cnt; cnt--) {
    653 			*dbp++ = (clr >> 16);
    654 			*dbp++ = (clr >> 8);
    655 			*dbp++ = clr;
    656 		}
    657 
    658 		dp = (uint32_t *)dbp;
    659 
    660 		/* 12 pels per loop */
    661 		for (cnt = n12; cnt; cnt--) {
    662 			dp[0] = xstamp[0];
    663 			dp[1] = xstamp[1];
    664 			dp[2] = xstamp[2];
    665 			dp[3] = xstamp[0];
    666 			dp[4] = xstamp[1];
    667 			dp[5] = xstamp[2];
    668 			dp[6] = xstamp[0];
    669 			dp[7] = xstamp[1];
    670 			dp[8] = xstamp[2];
    671 			dp += 9;
    672 		}
    673 
    674 		/* 4 pels per loop */
    675 		for (cnt = n4; cnt; cnt--) {
    676 			dp[0] = xstamp[0];
    677 			dp[1] = xstamp[1];
    678 			dp[2] = xstamp[2];
    679 			dp += 3;
    680 		}
    681 
    682 		/* Trailing slop */
    683 		/* XXX handle with masks, bring under control of RI_BSWAP */
    684 		dbp = (uint8_t *)dp;
    685 		for (cnt = num; cnt; cnt--) {
    686 			*dbp++ = (clr >> 16);
    687 			*dbp++ = (clr >> 8);
    688 			*dbp++ = clr;
    689 		}
    690 	}
    691 }
    692