rasops1.c revision 1.36 1 1.36 rin /* $NetBSD: rasops1.c,v 1.36 2019/08/09 12:05:51 rin Exp $ */
2 1.1 ad
3 1.5 ad /*-
4 1.5 ad * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.5 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.12 ad * by Andrew Doran.
9 1.5 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.5 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.5 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.5 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.5 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.5 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.5 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.5 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.5 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.5 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.5 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.5 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ad */
31 1.2 ad
32 1.14 lukem #include <sys/cdefs.h>
33 1.36 rin __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.36 2019/08/09 12:05:51 rin Exp $");
34 1.14 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 #include <machine/endian.h>
41 1.1 ad
42 1.1 ad #include <dev/wscons/wsdisplayvar.h>
43 1.3 ad #include <dev/wscons/wsconsio.h>
44 1.32 rin
45 1.32 rin #define _RASOPS_PRIVATE
46 1.34 rin #define RASOPS_DEPTH 1
47 1.1 ad #include <dev/rasops/rasops.h>
48 1.4 ad #include <dev/rasops/rasops_masks.h>
49 1.1 ad
50 1.16 perry static void rasops1_copycols(void *, int, int, int, int);
51 1.16 perry static void rasops1_erasecols(void *, int, int, int, long);
52 1.16 perry static void rasops1_do_cursor(struct rasops_info *);
53 1.16 perry static void rasops1_putchar(void *, int, int col, u_int, long);
54 1.10 ad #ifndef RASOPS_SMALL
55 1.16 perry static void rasops1_putchar8(void *, int, int col, u_int, long);
56 1.16 perry static void rasops1_putchar16(void *, int, int col, u_int, long);
57 1.10 ad #endif
58 1.1 ad
59 1.1 ad /*
60 1.13 wiz * Initialize rasops_info struct for this colordepth.
61 1.1 ad */
62 1.1 ad void
63 1.19 dsl rasops1_init(struct rasops_info *ri)
64 1.1 ad {
65 1.1 ad
66 1.29 rin if ((ri->ri_font->fontwidth & 7) != 0) {
67 1.29 rin ri->ri_ops.erasecols = rasops1_erasecols;
68 1.29 rin ri->ri_ops.copycols = rasops1_copycols;
69 1.29 rin ri->ri_do_cursor = rasops1_do_cursor;
70 1.29 rin }
71 1.29 rin
72 1.1 ad switch (ri->ri_font->fontwidth) {
73 1.10 ad #ifndef RASOPS_SMALL
74 1.1 ad case 8:
75 1.1 ad ri->ri_ops.putchar = rasops1_putchar8;
76 1.1 ad break;
77 1.1 ad case 16:
78 1.1 ad ri->ri_ops.putchar = rasops1_putchar16;
79 1.1 ad break;
80 1.10 ad #endif
81 1.1 ad default:
82 1.1 ad ri->ri_ops.putchar = rasops1_putchar;
83 1.1 ad break;
84 1.1 ad }
85 1.1 ad }
86 1.1 ad
87 1.1 ad /*
88 1.4 ad * Paint a single character. This is the generic version, this is ugly.
89 1.1 ad */
90 1.1 ad static void
91 1.20 dsl rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
92 1.1 ad {
93 1.23 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
94 1.23 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
95 1.29 rin uint32_t fs, rs, fb, bg, fg, lmask, rmask;
96 1.29 rin uint32_t height, width;
97 1.31 rin uint32_t *rp, *hp, tmp, tmp0, tmp1;
98 1.25 rin uint8_t *fr;
99 1.29 rin bool space;
100 1.29 rin
101 1.31 rin hp = NULL; /* XXX GCC */
102 1.11 pk
103 1.36 rin if (__predict_false(!CHAR_IN_FONT(uc, font)))
104 1.36 rin return;
105 1.36 rin
106 1.11 pk #ifdef RASOPS_CLIPPING
107 1.11 pk /* Catches 'row < 0' case too */
108 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
109 1.4 ad return;
110 1.4 ad
111 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
112 1.4 ad return;
113 1.4 ad #endif
114 1.4 ad
115 1.4 ad col *= ri->ri_font->fontwidth;
116 1.26 rin rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
117 1.26 rin ((col >> 3) & ~3));
118 1.21 macallan if (ri->ri_hwbits)
119 1.31 rin hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
120 1.21 macallan ((col >> 3) & ~3));
121 1.23 macallan height = font->fontheight;
122 1.23 macallan width = font->fontwidth;
123 1.29 rin col &= 31;
124 1.4 ad rs = ri->ri_stride;
125 1.11 pk
126 1.9 ad bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
127 1.9 ad fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
128 1.4 ad
129 1.4 ad /* If fg and bg match this becomes a space character */
130 1.29 rin if (uc == ' ' || fg == bg) {
131 1.29 rin space = true;
132 1.29 rin fr = NULL; /* XXX GCC */
133 1.29 rin fs = 0; /* XXX GCC */
134 1.4 ad } else {
135 1.29 rin space = false;
136 1.28 rin fr = FONT_GLYPH(uc, font, ri);
137 1.23 macallan fs = font->stride;
138 1.4 ad }
139 1.11 pk
140 1.29 rin if (col + width <= 32) {
141 1.29 rin /* Single word, only one mask */
142 1.29 rin
143 1.33 rin rmask = rasops_pmask[col][width & 31];
144 1.4 ad lmask = ~rmask;
145 1.11 pk
146 1.29 rin if (space) {
147 1.4 ad bg &= rmask;
148 1.4 ad while (height--) {
149 1.21 macallan tmp = (*rp & lmask) | bg;
150 1.21 macallan *rp = tmp;
151 1.26 rin DELTA(rp, rs, uint32_t *);
152 1.21 macallan if (ri->ri_hwbits) {
153 1.31 rin *hp = tmp;
154 1.31 rin DELTA(hp, rs, uint32_t *);
155 1.21 macallan }
156 1.4 ad }
157 1.4 ad } else {
158 1.29 rin while (height--) {
159 1.29 rin tmp = *rp & lmask;
160 1.30 rin fb = be32uatoh(fr);
161 1.29 rin fr += fs;
162 1.29 rin if (bg)
163 1.29 rin fb = ~fb;
164 1.29 rin tmp |= (MBE(fb >> col) & rmask);
165 1.29 rin *rp = tmp;
166 1.29 rin DELTA(rp, rs, uint32_t *);
167 1.29 rin if (ri->ri_hwbits) {
168 1.31 rin *hp = tmp;
169 1.31 rin DELTA(hp, rs, uint32_t *);
170 1.4 ad }
171 1.4 ad }
172 1.4 ad }
173 1.11 pk
174 1.4 ad /* Do underline */
175 1.24 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
176 1.35 rin DELTA(rp, - ri->ri_stride * ri->ri_ul.off, uint32_t *);
177 1.35 rin if (ri->ri_hwbits)
178 1.35 rin DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
179 1.35 rin uint32_t *);
180 1.35 rin for (height = ri->ri_ul.height; height; height--) {
181 1.35 rin DELTA(rp, - ri->ri_stride, uint32_t *);
182 1.35 rin tmp = (*rp & lmask) | (fg & rmask);
183 1.35 rin *rp = tmp;
184 1.35 rin if (ri->ri_hwbits) {
185 1.35 rin DELTA(hp, - ri->ri_stride, uint32_t *);
186 1.35 rin *hp = tmp;
187 1.35 rin }
188 1.21 macallan }
189 1.4 ad }
190 1.4 ad } else {
191 1.29 rin /* Word boundary, two masks needed */
192 1.29 rin
193 1.4 ad lmask = ~rasops_lmask[col];
194 1.4 ad rmask = ~rasops_rmask[(col + width) & 31];
195 1.11 pk
196 1.29 rin if (space) {
197 1.8 mouse width = bg & ~rmask;
198 1.4 ad bg = bg & ~lmask;
199 1.4 ad while (height--) {
200 1.29 rin tmp0 = (rp[0] & lmask) | bg;
201 1.29 rin tmp1 = (rp[1] & rmask) | width;
202 1.29 rin rp[0] = tmp0;
203 1.29 rin rp[1] = tmp1;
204 1.26 rin DELTA(rp, rs, uint32_t *);
205 1.21 macallan if (ri->ri_hwbits) {
206 1.31 rin hp[0] = tmp0;
207 1.31 rin hp[1] = tmp1;
208 1.31 rin DELTA(hp, rs, uint32_t *);
209 1.21 macallan }
210 1.4 ad }
211 1.4 ad } else {
212 1.4 ad width = 32 - col;
213 1.29 rin while (height--) {
214 1.29 rin tmp0 = rp[0] & lmask;
215 1.29 rin tmp1 = rp[1] & rmask;
216 1.30 rin fb = be32uatoh(fr);
217 1.29 rin fr += fs;
218 1.29 rin if (bg)
219 1.29 rin fb = ~fb;
220 1.29 rin tmp0 |= MBE(fb >> col);
221 1.29 rin tmp1 |= (MBE(fb << width) & ~rmask);
222 1.29 rin rp[0] = tmp0;
223 1.29 rin rp[1] = tmp1;
224 1.29 rin DELTA(rp, rs, uint32_t *);
225 1.29 rin if (ri->ri_hwbits) {
226 1.31 rin hp[0] = tmp0;
227 1.31 rin hp[1] = tmp1;
228 1.31 rin DELTA(hp, rs, uint32_t *);
229 1.4 ad }
230 1.4 ad }
231 1.4 ad }
232 1.1 ad
233 1.4 ad /* Do underline */
234 1.24 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
235 1.35 rin DELTA(rp, - ri->ri_stride * ri->ri_ul.off, uint32_t *);
236 1.35 rin if (ri->ri_hwbits)
237 1.35 rin DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
238 1.35 rin uint32_t *);
239 1.35 rin for (height = ri->ri_ul.height; height; height--) {
240 1.35 rin DELTA(rp, - ri->ri_stride, uint32_t *);
241 1.35 rin tmp0 = (rp[0] & lmask) | (fg & ~lmask);
242 1.35 rin tmp1 = (rp[1] & rmask) | (fg & ~rmask);
243 1.35 rin rp[0] = tmp0;
244 1.35 rin rp[1] = tmp1;
245 1.35 rin if (ri->ri_hwbits) {
246 1.35 rin DELTA(hp, - ri->ri_stride, uint32_t *);
247 1.35 rin hp[0] = tmp0;
248 1.35 rin hp[1] = tmp1;
249 1.35 rin }
250 1.21 macallan }
251 1.4 ad }
252 1.4 ad }
253 1.1 ad }
254 1.1 ad
255 1.10 ad #ifndef RASOPS_SMALL
256 1.1 ad
257 1.29 rin #define RASOPS_WIDTH 8
258 1.29 rin #include "rasops1_putchar_width.h"
259 1.29 rin #undef RASOPS_WIDTH
260 1.29 rin
261 1.29 rin #define RASOPS_WIDTH 16
262 1.29 rin #include "rasops1_putchar_width.h"
263 1.29 rin #undef RASOPS_WIDTH
264 1.1 ad
265 1.10 ad #endif /* !RASOPS_SMALL */
266 1.1 ad
267 1.1 ad /*
268 1.4 ad * Grab routines common to depths where (bpp < 8)
269 1.1 ad */
270 1.4 ad #include <dev/rasops/rasops_bitops.h>
271