rasops1.c revision 1.29 1 /* $NetBSD: rasops1.c,v 1.29 2019/07/29 02:57:41 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.29 2019/07/29 02:57:41 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 #include <dev/rasops/rasops.h>
45 #include <dev/rasops/rasops_masks.h>
46
47 static void rasops1_copycols(void *, int, int, int, int);
48 static void rasops1_erasecols(void *, int, int, int, long);
49 static void rasops1_do_cursor(struct rasops_info *);
50 static void rasops1_putchar(void *, int, int col, u_int, long);
51 #ifndef RASOPS_SMALL
52 static void rasops1_putchar8(void *, int, int col, u_int, long);
53 static void rasops1_putchar16(void *, int, int col, u_int, long);
54 #endif
55
56 /*
57 * Initialize rasops_info struct for this colordepth.
58 */
59 void
60 rasops1_init(struct rasops_info *ri)
61 {
62
63 if ((ri->ri_font->fontwidth & 7) != 0) {
64 ri->ri_ops.erasecols = rasops1_erasecols;
65 ri->ri_ops.copycols = rasops1_copycols;
66 ri->ri_do_cursor = rasops1_do_cursor;
67 }
68
69 switch (ri->ri_font->fontwidth) {
70 #ifndef RASOPS_SMALL
71 case 8:
72 ri->ri_ops.putchar = rasops1_putchar8;
73 break;
74 case 16:
75 ri->ri_ops.putchar = rasops1_putchar16;
76 break;
77 #endif
78 default:
79 ri->ri_ops.putchar = rasops1_putchar;
80 break;
81 }
82 }
83
84 /*
85 * Paint a single character. This is the generic version, this is ugly.
86 */
87 static void
88 rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
89 {
90 struct rasops_info *ri = (struct rasops_info *)cookie;
91 struct wsdisplay_font *font = PICK_FONT(ri, uc);
92 uint32_t fs, rs, fb, bg, fg, lmask, rmask;
93 uint32_t height, width;
94 uint32_t *rp, *hrp, tmp, tmp0, tmp1;
95 uint8_t *fr;
96 bool space;
97
98 hrp = NULL; /* XXX GCC */
99
100 #ifdef RASOPS_CLIPPING
101 /* Catches 'row < 0' case too */
102 if ((unsigned)row >= (unsigned)ri->ri_rows)
103 return;
104
105 if ((unsigned)col >= (unsigned)ri->ri_cols)
106 return;
107 #endif
108
109 col *= ri->ri_font->fontwidth;
110 rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
111 ((col >> 3) & ~3));
112 if (ri->ri_hwbits)
113 hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
114 ((col >> 3) & ~3));
115 height = font->fontheight;
116 width = font->fontwidth;
117 col &= 31;
118 rs = ri->ri_stride;
119
120 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
121 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
122
123 /* If fg and bg match this becomes a space character */
124 if (uc == ' ' || fg == bg) {
125 space = true;
126 fr = NULL; /* XXX GCC */
127 fs = 0; /* XXX GCC */
128 } else {
129 space = false;
130 fr = FONT_GLYPH(uc, font, ri);
131 fs = font->stride;
132 }
133
134 if (col + width <= 32) {
135 /* Single word, only one mask */
136
137 rmask = rasops_pmask[col][width];
138 lmask = ~rmask;
139
140 if (space) {
141 bg &= rmask;
142 while (height--) {
143 tmp = (*rp & lmask) | bg;
144 *rp = tmp;
145 DELTA(rp, rs, uint32_t *);
146 if (ri->ri_hwbits) {
147 *hrp = tmp;
148 DELTA(hrp, rs, uint32_t *);
149 }
150 }
151 } else {
152 while (height--) {
153 tmp = *rp & lmask;
154 fb = fr[3] | (fr[2] << 8) |
155 (fr[1] << 16) | (fr[0] << 24);
156 fr += fs;
157 if (bg)
158 fb = ~fb;
159 tmp |= (MBE(fb >> col) & rmask);
160 *rp = tmp;
161 DELTA(rp, rs, uint32_t *);
162 if (ri->ri_hwbits) {
163 *hrp = tmp;
164 DELTA(hrp, rs, uint32_t *);
165 }
166 }
167 }
168
169 /* Do underline */
170 if ((attr & WSATTR_UNDERLINE) != 0) {
171 DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
172 tmp = (*rp & lmask) | (fg & rmask);
173 *rp = tmp;
174 if (ri->ri_hwbits) {
175 DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
176 *hrp = tmp;
177 }
178 }
179 } else {
180 /* Word boundary, two masks needed */
181
182 lmask = ~rasops_lmask[col];
183 rmask = ~rasops_rmask[(col + width) & 31];
184
185 if (space) {
186 width = bg & ~rmask;
187 bg = bg & ~lmask;
188 while (height--) {
189 tmp0 = (rp[0] & lmask) | bg;
190 tmp1 = (rp[1] & rmask) | width;
191 rp[0] = tmp0;
192 rp[1] = tmp1;
193 DELTA(rp, rs, uint32_t *);
194 if (ri->ri_hwbits) {
195 hrp[0] = tmp0;
196 hrp[1] = tmp1;
197 DELTA(hrp, rs, uint32_t *);
198 }
199 }
200 } else {
201 width = 32 - col;
202 while (height--) {
203 tmp0 = rp[0] & lmask;
204 tmp1 = rp[1] & rmask;
205 fb = fr[3] | (fr[2] << 8) |
206 (fr[1] << 16) | (fr[0] << 24);
207 fr += fs;
208 if (bg)
209 fb = ~fb;
210 tmp0 |= MBE(fb >> col);
211 tmp1 |= (MBE(fb << width) & ~rmask);
212 rp[0] = tmp0;
213 rp[1] = tmp1;
214 DELTA(rp, rs, uint32_t *);
215 if (ri->ri_hwbits) {
216 hrp[0] = tmp0;
217 hrp[1] = tmp1;
218 DELTA(hrp, rs, uint32_t *);
219 }
220 }
221 }
222
223 /* Do underline */
224 if ((attr & WSATTR_UNDERLINE) != 0) {
225 DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
226 tmp0 = (rp[0] & lmask) | (fg & ~lmask);
227 tmp1 = (rp[1] & rmask) | (fg & ~rmask);
228 rp[0] = tmp0;
229 rp[1] = tmp1;
230 if (ri->ri_hwbits) {
231 DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
232 hrp[0] = tmp0;
233 hrp[1] = tmp1;
234 }
235 }
236 }
237 }
238
239 #ifndef RASOPS_SMALL
240
241 #define RASOPS_WIDTH 8
242 #include "rasops1_putchar_width.h"
243 #undef RASOPS_WIDTH
244
245 #define RASOPS_WIDTH 16
246 #include "rasops1_putchar_width.h"
247 #undef RASOPS_WIDTH
248
249 #endif /* !RASOPS_SMALL */
250
251 /*
252 * Grab routines common to depths where (bpp < 8)
253 */
254 #define NAME(ident) rasops1_##ident
255 #define PIXEL_SHIFT 0
256
257 #include <dev/rasops/rasops_bitops.h>
258