Home | History | Annotate | Line # | Download | only in rasops
rasops32.c revision 1.14.4.1
      1  1.14.4.1  rpaulo /*	 $NetBSD: rasops32.c,v 1.14.4.1 2006/09/09 02:54:25 rpaulo Exp $	*/
      2       1.1      ad 
      3       1.4      ad /*-
      4       1.4      ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5       1.1      ad  * All rights reserved.
      6       1.1      ad  *
      7       1.4      ad  * This code is derived from software contributed to The NetBSD Foundation
      8       1.8      ad  * by Andrew Doran.
      9       1.4      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.4      ad  * 3. All advertising materials mentioning features or use of this software
     19       1.4      ad  *    must display the following acknowledgement:
     20       1.4      ad  *	This product includes software developed by the NetBSD
     21       1.4      ad  *	Foundation, Inc. and its contributors.
     22       1.4      ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.4      ad  *    contributors may be used to endorse or promote products derived
     24       1.4      ad  *    from this software without specific prior written permission.
     25       1.1      ad  *
     26       1.4      ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.4      ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.4      ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.4      ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.4      ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.4      ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.4      ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.4      ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.4      ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.4      ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.4      ad  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      ad  */
     38       1.2      ad 
     39      1.10   lukem #include <sys/cdefs.h>
     40  1.14.4.1  rpaulo __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.14.4.1 2006/09/09 02:54:25 rpaulo Exp $");
     41      1.10   lukem 
     42       1.1      ad #include "opt_rasops.h"
     43       1.1      ad 
     44       1.1      ad #include <sys/param.h>
     45       1.1      ad #include <sys/systm.h>
     46       1.1      ad #include <sys/time.h>
     47       1.1      ad 
     48       1.1      ad #include <dev/wscons/wsdisplayvar.h>
     49       1.1      ad #include <dev/wscons/wsconsio.h>
     50       1.1      ad #include <dev/rasops/rasops.h>
     51       1.1      ad 
     52      1.13   perry static void 	rasops32_putchar(void *, int, int, u_int, long attr);
     53       1.3      ad 
     54       1.1      ad /*
     55       1.9     wiz  * Initialize a 'rasops_info' descriptor for this depth.
     56       1.1      ad  */
     57       1.1      ad void
     58       1.1      ad rasops32_init(ri)
     59       1.1      ad 	struct rasops_info *ri;
     60       1.1      ad {
     61       1.1      ad 
     62       1.3      ad 	if (ri->ri_rnum == 0) {
     63       1.3      ad 		ri->ri_rnum = 8;
     64       1.3      ad 		ri->ri_rpos = 0;
     65       1.3      ad 		ri->ri_gnum = 8;
     66       1.3      ad 		ri->ri_gpos = 8;
     67       1.3      ad 		ri->ri_bnum = 8;
     68       1.3      ad 		ri->ri_bpos = 16;
     69       1.1      ad 	}
     70       1.7      pk 
     71       1.3      ad 	ri->ri_ops.putchar = rasops32_putchar;
     72       1.1      ad }
     73       1.1      ad 
     74       1.1      ad /*
     75       1.1      ad  * Paint a single character.
     76       1.1      ad  */
     77       1.1      ad static void
     78       1.1      ad rasops32_putchar(cookie, row, col, uc, attr)
     79       1.1      ad 	void *cookie;
     80       1.1      ad 	int row, col;
     81       1.1      ad 	u_int uc;
     82       1.1      ad 	long attr;
     83       1.1      ad {
     84       1.5      ad 	int width, height, cnt, fs, fb, clr[2];
     85       1.1      ad 	struct rasops_info *ri;
     86  1.14.4.1  rpaulo 	int32_t *dp, *rp, *hp, *hrp;
     87       1.1      ad 	u_char *fr;
     88       1.7      pk 
     89       1.1      ad 	ri = (struct rasops_info *)cookie;
     90  1.14.4.1  rpaulo 	hp = hrp = NULL;
     91       1.1      ad 
     92       1.7      pk #ifdef RASOPS_CLIPPING
     93       1.7      pk 	/* Catches 'row < 0' case too */
     94       1.1      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     95       1.1      ad 		return;
     96       1.1      ad 
     97       1.1      ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
     98       1.1      ad 		return;
     99       1.1      ad #endif
    100      1.12  petrov 
    101      1.12  petrov 	/* check if character fits into font limits */
    102      1.12  petrov 	if (uc < ri->ri_font->firstchar ||
    103      1.12  petrov 	    (uc - ri->ri_font->firstchar) >= ri->ri_font->numchars)
    104      1.12  petrov 	    return;
    105       1.7      pk 
    106       1.1      ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    107  1.14.4.1  rpaulo 	if (ri->ri_hwbits)
    108  1.14.4.1  rpaulo 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    109  1.14.4.1  rpaulo 		    col*ri->ri_xscale);
    110       1.1      ad 
    111       1.1      ad 	height = ri->ri_font->fontheight;
    112       1.1      ad 	width = ri->ri_font->fontwidth;
    113       1.3      ad 
    114       1.7      pk 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
    115       1.7      pk 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
    116       1.7      pk 
    117       1.1      ad 	if (uc == ' ') {
    118       1.1      ad 		while (height--) {
    119       1.1      ad 			dp = rp;
    120       1.1      ad 			DELTA(rp, ri->ri_stride, int32_t *);
    121  1.14.4.1  rpaulo 			if (ri->ri_hwbits) {
    122  1.14.4.1  rpaulo 				hp = hrp;
    123  1.14.4.1  rpaulo 				DELTA(hrp, ri->ri_stride, int32_t *);
    124  1.14.4.1  rpaulo 			}
    125       1.1      ad 
    126  1.14.4.1  rpaulo 			for (cnt = width; cnt; cnt--) {
    127       1.1      ad 				*dp++ = clr[0];
    128  1.14.4.1  rpaulo 				if (ri->ri_hwbits)
    129  1.14.4.1  rpaulo 					*hp++ = clr[0];
    130  1.14.4.1  rpaulo 			}
    131       1.1      ad 		}
    132       1.1      ad 	} else {
    133       1.1      ad 		uc -= ri->ri_font->firstchar;
    134       1.1      ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    135       1.1      ad 		fs = ri->ri_font->stride;
    136       1.1      ad 
    137       1.1      ad 		while (height--) {
    138       1.1      ad 			dp = rp;
    139       1.7      pk 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    140       1.6      ad 			    (fr[0] << 24);
    141       1.1      ad 			fr += fs;
    142       1.1      ad 			DELTA(rp, ri->ri_stride, int32_t *);
    143  1.14.4.1  rpaulo 			if (ri->ri_hwbits) {
    144  1.14.4.1  rpaulo 				hp = hrp;
    145  1.14.4.1  rpaulo 				DELTA(hrp, ri->ri_stride, int32_t *);
    146  1.14.4.1  rpaulo 			}
    147       1.7      pk 
    148       1.1      ad 			for (cnt = width; cnt; cnt--) {
    149       1.1      ad 				*dp++ = clr[(fb >> 31) & 1];
    150  1.14.4.1  rpaulo 				if (ri->ri_hwbits)
    151  1.14.4.1  rpaulo 					*hp++ = clr[(fb >> 31) & 1];
    152       1.1      ad 				fb <<= 1;
    153       1.1      ad 			}
    154       1.1      ad 		}
    155       1.7      pk 	}
    156       1.1      ad 
    157       1.1      ad 	/* Do underline */
    158       1.5      ad 	if ((attr & 1) != 0) {
    159       1.1      ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    160  1.14.4.1  rpaulo 		if (ri->ri_hwbits)
    161  1.14.4.1  rpaulo 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
    162       1.1      ad 
    163  1.14.4.1  rpaulo 		while (width--) {
    164       1.1      ad 			*rp++ = clr[1];
    165  1.14.4.1  rpaulo 			if (ri->ri_hwbits)
    166  1.14.4.1  rpaulo 				*hrp++ = clr[1];
    167  1.14.4.1  rpaulo 		}
    168       1.7      pk 	}
    169       1.1      ad }
    170