Home | History | Annotate | Line # | Download | only in rasops
rasops32.c revision 1.41
      1  1.41       rin /*	 $NetBSD: rasops32.c,v 1.41 2019/07/31 02:04:14 rin 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.1        ad  *
     19   1.4        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.4        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.4        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.4        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.4        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.4        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.4        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.4        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.4        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.4        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.4        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        ad  */
     31   1.2        ad 
     32  1.10     lukem #include <sys/cdefs.h>
     33  1.41       rin __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.41 2019/07/31 02:04:14 rin Exp $");
     34  1.10     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 
     41   1.1        ad #include <dev/wscons/wsdisplayvar.h>
     42   1.1        ad #include <dev/wscons/wsconsio.h>
     43  1.40       rin 
     44  1.40       rin #define	_RASOPS_PRIVATE
     45   1.1        ad #include <dev/rasops/rasops.h>
     46   1.1        ad 
     47  1.38       rin static void 	rasops32_putchar(void *, int, int, u_int, long);
     48  1.38       rin static void 	rasops32_putchar_aa(void *, int, int, u_int, long);
     49  1.36       rin #ifndef RASOPS_SMALL
     50  1.36       rin static void	rasops32_putchar8(void *, int, int, u_int, long);
     51  1.36       rin static void	rasops32_putchar12(void *, int, int, u_int, long);
     52  1.36       rin static void	rasops32_putchar16(void *, int, int, u_int, long);
     53  1.36       rin static void	rasops32_makestamp(struct rasops_info *, long);
     54  1.36       rin #endif
     55  1.36       rin 
     56  1.36       rin /*
     57  1.36       rin  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     58  1.36       rin  * destination uint32_t[0] = STAMP_READ(offset)
     59  1.36       rin  * destination uint32_t[1] = STAMP_READ(offset +  4)
     60  1.36       rin  * destination uint32_t[2] = STAMP_READ(offset +  8)
     61  1.36       rin  * destination uint32_t[3] = STAMP_READ(offset + 12)
     62  1.36       rin  */
     63  1.36       rin #define	STAMP_SHIFT(fb, n)	((n) ? (fb) : (fb) << 4)
     64  1.36       rin #define	STAMP_MASK		(0xf << 4)
     65  1.38       rin #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     66   1.3        ad 
     67   1.1        ad /*
     68   1.9       wiz  * Initialize a 'rasops_info' descriptor for this depth.
     69   1.1        ad  */
     70   1.1        ad void
     71  1.17       dsl rasops32_init(struct rasops_info *ri)
     72   1.1        ad {
     73   1.1        ad 
     74   1.3        ad 	if (ri->ri_rnum == 0) {
     75  1.38       rin 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
     76  1.38       rin 
     77   1.3        ad 		ri->ri_rpos = 0;
     78   1.3        ad 		ri->ri_gpos = 8;
     79   1.3        ad 		ri->ri_bpos = 16;
     80   1.1        ad 	}
     81   1.7        pk 
     82  1.27    martin 	if (FONT_IS_ALPHA(ri->ri_font)) {
     83  1.27    martin 		ri->ri_ops.putchar = rasops32_putchar_aa;
     84  1.36       rin 		return;
     85  1.36       rin 	}
     86  1.36       rin 
     87  1.36       rin 	switch (ri->ri_font->fontwidth) {
     88  1.36       rin #ifndef RASOPS_SMALL
     89  1.36       rin 	case 8:
     90  1.36       rin 		ri->ri_ops.putchar = rasops32_putchar8;
     91  1.36       rin 		break;
     92  1.36       rin 	case 12:
     93  1.36       rin 		ri->ri_ops.putchar = rasops32_putchar12;
     94  1.36       rin 		break;
     95  1.36       rin 	case 16:
     96  1.36       rin 		ri->ri_ops.putchar = rasops32_putchar16;
     97  1.36       rin 		break;
     98  1.36       rin #endif
     99  1.36       rin 	default:
    100  1.23  macallan 		ri->ri_ops.putchar = rasops32_putchar;
    101  1.41       rin 		return;
    102  1.36       rin 	}
    103  1.41       rin 
    104  1.41       rin #ifndef RASOPS_SMALL
    105  1.41       rin 	rasops_allocstamp(ri, sizeof(uint32_t) * 64);
    106  1.41       rin #endif
    107   1.1        ad }
    108   1.1        ad 
    109  1.37       rin #define	RASOPS_DEPTH	32
    110  1.37       rin #include "rasops_putchar.h"
    111  1.39       rin #include "rasops_putchar_aa.h"
    112  1.36       rin 
    113  1.36       rin #ifndef RASOPS_SMALL
    114  1.36       rin /*
    115  1.36       rin  * Recompute the blitting stamp.
    116  1.36       rin  */
    117  1.36       rin static void
    118  1.36       rin rasops32_makestamp(struct rasops_info *ri, long attr)
    119  1.36       rin {
    120  1.41       rin 	uint32_t *stamp = (uint32_t *)ri->ri_stamp;
    121  1.36       rin 	uint32_t fg, bg;
    122  1.36       rin 	int i;
    123  1.36       rin 
    124  1.36       rin 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
    125  1.36       rin 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
    126  1.41       rin 	ri->ri_stamp_attr = attr;
    127  1.36       rin 
    128  1.36       rin 	for (i = 0; i < 64; i += 4) {
    129  1.38       rin 		stamp[i + 0] = i & 32 ? fg : bg;
    130  1.38       rin 		stamp[i + 1] = i & 16 ? fg : bg;
    131  1.38       rin 		stamp[i + 2] = i &  8 ? fg : bg;
    132  1.38       rin 		stamp[i + 3] = i &  4 ? fg : bg;
    133  1.36       rin 	}
    134  1.36       rin }
    135  1.36       rin 
    136  1.37       rin #define	RASOPS_WIDTH	8
    137  1.37       rin #include "rasops_putchar_width.h"
    138  1.37       rin #undef	RASOPS_WIDTH
    139  1.37       rin 
    140  1.37       rin #define	RASOPS_WIDTH	12
    141  1.37       rin #include "rasops_putchar_width.h"
    142  1.37       rin #undef	RASOPS_WIDTH
    143  1.37       rin 
    144  1.37       rin #define	RASOPS_WIDTH	16
    145  1.37       rin #include "rasops_putchar_width.h"
    146  1.37       rin #undef	RASOPS_WIDTH
    147  1.36       rin 
    148  1.37       rin #endif /* !RASOPS_SMALL */
    149