1 /* $NetBSD: rasops32.c,v 1.46 2019/08/14 00:51:10 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: rasops32.c,v 1.46 2019/08/14 00:51:10 rin Exp $"); 34 35 #ifdef _KERNEL_OPT 36 #include "opt_rasops.h" 37 #endif 38 39 #include <sys/param.h> 40 41 #include <dev/wscons/wsdisplayvar.h> 42 #include <dev/wscons/wsconsio.h> 43 44 #define _RASOPS_PRIVATE 45 #define RASOPS_DEPTH 32 46 #include <dev/rasops/rasops.h> 47 48 static void rasops32_putchar(void *, int, int, u_int, long); 49 static void rasops32_putchar_aa(void *, int, int, u_int, long); 50 #ifndef RASOPS_SMALL 51 static void rasops32_putchar8(void *, int, int, u_int, long); 52 static void rasops32_putchar12(void *, int, int, u_int, long); 53 static void rasops32_putchar16(void *, int, int, u_int, long); 54 static void rasops32_makestamp(struct rasops_info *, long); 55 #endif 56 57 #ifndef RASOPS_SMALL 58 /* stamp for optimized character blitting */ 59 static uint32_t stamp[64]; 60 static long stamp_attr; 61 static struct rasops_info *stamp_ri; 62 63 /* 64 * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK 65 * destination uint32_t[0] = STAMP_READ(offset) 66 * destination uint32_t[1] = STAMP_READ(offset + 4) 67 * destination uint32_t[2] = STAMP_READ(offset + 8) 68 * destination uint32_t[3] = STAMP_READ(offset + 12) 69 */ 70 #define STAMP_SHIFT(fb, n) ((n) ? (fb) : (fb) << 4) 71 #define STAMP_MASK (0xf << 4) 72 #define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o))) 73 #endif 74 75 /* 76 * Initialize a 'rasops_info' descriptor for this depth. 77 */ 78 void 79 rasops32_init(struct rasops_info *ri) 80 { 81 82 if (ri->ri_rnum == 0) { 83 ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8; 84 85 ri->ri_rpos = 0; 86 ri->ri_gpos = 8; 87 ri->ri_bpos = 16; 88 } 89 90 if (FONT_IS_ALPHA(ri->ri_font)) { 91 ri->ri_ops.putchar = rasops32_putchar_aa; 92 return; 93 } 94 95 switch (ri->ri_font->fontwidth) { 96 #ifndef RASOPS_SMALL 97 case 8: 98 ri->ri_ops.putchar = rasops32_putchar8; 99 break; 100 case 12: 101 ri->ri_ops.putchar = rasops32_putchar12; 102 break; 103 case 16: 104 ri->ri_ops.putchar = rasops32_putchar16; 105 break; 106 #endif 107 default: 108 ri->ri_ops.putchar = rasops32_putchar; 109 return; 110 } 111 112 #ifndef RASOPS_SMALL 113 stamp_attr = -1; 114 stamp_ri = NULL; 115 #endif 116 } 117 118 /* rasops32_putchar */ 119 #undef RASOPS_AA 120 #include <dev/rasops/rasops_putchar.h> 121 122 /* rasops32_putchar_aa */ 123 #define RASOPS_AA 124 #include <dev/rasops/rasops_putchar.h> 125 #undef RASOPS_AA 126 127 #ifndef RASOPS_SMALL 128 /* 129 * Recompute the blitting stamp. 130 */ 131 static void 132 rasops32_makestamp(struct rasops_info *ri, long attr) 133 { 134 uint32_t fg, bg; 135 int i; 136 137 stamp_attr = attr; 138 stamp_ri = ri; 139 140 bg = ATTR_BG(ri, attr); 141 fg = ATTR_FG(ri, attr); 142 143 for (i = 0; i < 64; i += 4) { 144 stamp[i + 0] = i & 32 ? fg : bg; 145 stamp[i + 1] = i & 16 ? fg : bg; 146 stamp[i + 2] = i & 8 ? fg : bg; 147 stamp[i + 3] = i & 4 ? fg : bg; 148 } 149 } 150 151 /* 152 * Width-optimized putchar functions 153 */ 154 #define RASOPS_WIDTH 8 155 #include <dev/rasops/rasops_putchar_width.h> 156 #undef RASOPS_WIDTH 157 158 #define RASOPS_WIDTH 12 159 #include <dev/rasops/rasops_putchar_width.h> 160 #undef RASOPS_WIDTH 161 162 #define RASOPS_WIDTH 16 163 #include <dev/rasops/rasops_putchar_width.h> 164 #undef RASOPS_WIDTH 165 166 #endif /* !RASOPS_SMALL */ 167