rasops1.c revision 1.30 1 /* $NetBSD: rasops1.c,v 1.30 2019/07/29 08:13:50 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.30 2019/07/29 08:13:50 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 = be32uatoh(fr);
155 fr += fs;
156 if (bg)
157 fb = ~fb;
158 tmp |= (MBE(fb >> col) & rmask);
159 *rp = tmp;
160 DELTA(rp, rs, uint32_t *);
161 if (ri->ri_hwbits) {
162 *hrp = tmp;
163 DELTA(hrp, rs, uint32_t *);
164 }
165 }
166 }
167
168 /* Do underline */
169 if ((attr & WSATTR_UNDERLINE) != 0) {
170 DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
171 tmp = (*rp & lmask) | (fg & rmask);
172 *rp = tmp;
173 if (ri->ri_hwbits) {
174 DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
175 *hrp = tmp;
176 }
177 }
178 } else {
179 /* Word boundary, two masks needed */
180
181 lmask = ~rasops_lmask[col];
182 rmask = ~rasops_rmask[(col + width) & 31];
183
184 if (space) {
185 width = bg & ~rmask;
186 bg = bg & ~lmask;
187 while (height--) {
188 tmp0 = (rp[0] & lmask) | bg;
189 tmp1 = (rp[1] & rmask) | width;
190 rp[0] = tmp0;
191 rp[1] = tmp1;
192 DELTA(rp, rs, uint32_t *);
193 if (ri->ri_hwbits) {
194 hrp[0] = tmp0;
195 hrp[1] = tmp1;
196 DELTA(hrp, rs, uint32_t *);
197 }
198 }
199 } else {
200 width = 32 - col;
201 while (height--) {
202 tmp0 = rp[0] & lmask;
203 tmp1 = rp[1] & rmask;
204 fb = be32uatoh(fr);
205 fr += fs;
206 if (bg)
207 fb = ~fb;
208 tmp0 |= MBE(fb >> col);
209 tmp1 |= (MBE(fb << width) & ~rmask);
210 rp[0] = tmp0;
211 rp[1] = tmp1;
212 DELTA(rp, rs, uint32_t *);
213 if (ri->ri_hwbits) {
214 hrp[0] = tmp0;
215 hrp[1] = tmp1;
216 DELTA(hrp, rs, uint32_t *);
217 }
218 }
219 }
220
221 /* Do underline */
222 if ((attr & WSATTR_UNDERLINE) != 0) {
223 DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
224 tmp0 = (rp[0] & lmask) | (fg & ~lmask);
225 tmp1 = (rp[1] & rmask) | (fg & ~rmask);
226 rp[0] = tmp0;
227 rp[1] = tmp1;
228 if (ri->ri_hwbits) {
229 DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
230 hrp[0] = tmp0;
231 hrp[1] = tmp1;
232 }
233 }
234 }
235 }
236
237 #ifndef RASOPS_SMALL
238
239 #define RASOPS_WIDTH 8
240 #include "rasops1_putchar_width.h"
241 #undef RASOPS_WIDTH
242
243 #define RASOPS_WIDTH 16
244 #include "rasops1_putchar_width.h"
245 #undef RASOPS_WIDTH
246
247 #endif /* !RASOPS_SMALL */
248
249 /*
250 * Grab routines common to depths where (bpp < 8)
251 */
252 #define NAME(ident) rasops1_##ident
253 #define PIXEL_SHIFT 0
254
255 #include <dev/rasops/rasops_bitops.h>
256