rasops24.c revision 1.34 1 1.34 rin /* $NetBSD: rasops24.c,v 1.34 2019/07/25 03:02:44 rin Exp $ */
2 1.1 ad
3 1.6 ad /*-
4 1.6 ad * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.6 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.13 ad * by Andrew Doran.
9 1.6 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.6 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.6 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.6 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.6 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.6 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.6 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.6 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.6 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.6 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.6 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.6 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ad */
31 1.2 ad
32 1.15 lukem #include <sys/cdefs.h>
33 1.34 rin __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.34 2019/07/25 03:02:44 rin Exp $");
34 1.15 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.4 ad #include <machine/endian.h>
42 1.22 dsl #include <sys/bswap.h>
43 1.4 ad
44 1.1 ad #include <dev/wscons/wsdisplayvar.h>
45 1.1 ad #include <dev/wscons/wsconsio.h>
46 1.1 ad #include <dev/rasops/rasops.h>
47 1.1 ad
48 1.18 perry static void rasops24_erasecols(void *, int, int, int, long);
49 1.18 perry static void rasops24_eraserows(void *, int, int, long);
50 1.18 perry static void rasops24_putchar(void *, int, int, u_int, long attr);
51 1.9 ad #ifndef RASOPS_SMALL
52 1.18 perry static void rasops24_putchar8(void *, int, int, u_int, long attr);
53 1.18 perry static void rasops24_putchar12(void *, int, int, u_int, long attr);
54 1.18 perry static void rasops24_putchar16(void *, int, int, u_int, long attr);
55 1.18 perry static void rasops24_makestamp(struct rasops_info *, long);
56 1.1 ad
57 1.12 pk /*
58 1.12 pk * 4x1 stamp for optimized character blitting
59 1.4 ad */
60 1.32 rin static uint32_t stamp[64];
61 1.4 ad static long stamp_attr;
62 1.4 ad static int stamp_mutex; /* XXX see note in readme */
63 1.29 njoly #endif
64 1.4 ad
65 1.4 ad /*
66 1.4 ad * XXX this confuses the hell out of gcc2 (not egcs) which always insists
67 1.4 ad * that the shift count is negative.
68 1.4 ad *
69 1.4 ad * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
70 1.32 rin * destination uint32_t[0] = STAMP_READ(offset)
71 1.32 rin * destination uint32_t[1] = STAMP_READ(offset + 4)
72 1.32 rin * destination uint32_t[2] = STAMP_READ(offset + 8)
73 1.4 ad */
74 1.4 ad #define STAMP_SHIFT(fb,n) ((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4))
75 1.12 pk #define STAMP_MASK (0xf << 4)
76 1.32 rin #define STAMP_READ(o) (*(uint32_t *)((char *)stamp + (o)))
77 1.4 ad
78 1.1 ad /*
79 1.14 wiz * Initialize rasops_info struct for this colordepth.
80 1.1 ad */
81 1.1 ad void
82 1.26 dsl rasops24_init(struct rasops_info *ri)
83 1.1 ad {
84 1.1 ad
85 1.1 ad switch (ri->ri_font->fontwidth) {
86 1.9 ad #ifndef RASOPS_SMALL
87 1.1 ad case 8:
88 1.4 ad ri->ri_ops.putchar = rasops24_putchar8;
89 1.1 ad break;
90 1.1 ad case 12:
91 1.4 ad ri->ri_ops.putchar = rasops24_putchar12;
92 1.1 ad break;
93 1.1 ad case 16:
94 1.4 ad ri->ri_ops.putchar = rasops24_putchar16;
95 1.1 ad break;
96 1.9 ad #endif
97 1.1 ad default:
98 1.4 ad ri->ri_ops.putchar = rasops24_putchar;
99 1.1 ad break;
100 1.1 ad }
101 1.4 ad
102 1.1 ad if (ri->ri_rnum == 0) {
103 1.1 ad ri->ri_rnum = 8;
104 1.4 ad ri->ri_rpos = 0;
105 1.1 ad ri->ri_gnum = 8;
106 1.4 ad ri->ri_gpos = 8;
107 1.1 ad ri->ri_bnum = 8;
108 1.1 ad ri->ri_bpos = 16;
109 1.1 ad }
110 1.4 ad
111 1.4 ad ri->ri_ops.erasecols = rasops24_erasecols;
112 1.4 ad ri->ri_ops.eraserows = rasops24_eraserows;
113 1.1 ad }
114 1.1 ad
115 1.1 ad /*
116 1.4 ad * Put a single character. This is the generic version.
117 1.12 pk * XXX this bites - we should use masks.
118 1.1 ad */
119 1.4 ad static void
120 1.27 dsl rasops24_putchar(void *cookie, int row, int col, u_int uc, long attr)
121 1.1 ad {
122 1.9 ad int fb, width, height, cnt, clr[2];
123 1.28 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
124 1.28 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
125 1.31 rin uint8_t *dp, *rp, *fr;
126 1.12 pk
127 1.12 pk #ifdef RASOPS_CLIPPING
128 1.12 pk /* Catches 'row < 0' case too */
129 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
130 1.4 ad return;
131 1.1 ad
132 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
133 1.4 ad return;
134 1.4 ad #endif
135 1.12 pk
136 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
137 1.28 macallan height = font->fontheight;
138 1.28 macallan width = font->fontwidth;
139 1.12 pk
140 1.12 pk clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
141 1.12 pk clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
142 1.4 ad
143 1.4 ad if (uc == ' ') {
144 1.31 rin uint8_t c = clr[0];
145 1.4 ad while (height--) {
146 1.4 ad dp = rp;
147 1.4 ad rp += ri->ri_stride;
148 1.12 pk
149 1.4 ad for (cnt = width; cnt; cnt--) {
150 1.12 pk *dp++ = c >> 16;
151 1.12 pk *dp++ = c >> 8;
152 1.12 pk *dp++ = c;
153 1.4 ad }
154 1.12 pk }
155 1.4 ad } else {
156 1.34 rin fr = FONT_GLYPH(uc, font, ri);
157 1.1 ad
158 1.4 ad while (height--) {
159 1.4 ad dp = rp;
160 1.9 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
161 1.9 ad (fr[0] << 24);
162 1.28 macallan fr += font->stride;
163 1.4 ad rp += ri->ri_stride;
164 1.12 pk
165 1.4 ad for (cnt = width; cnt; cnt--, fb <<= 1) {
166 1.4 ad if ((fb >> 31) & 1) {
167 1.4 ad *dp++ = clr[1] >> 16;
168 1.4 ad *dp++ = clr[1] >> 8;
169 1.4 ad *dp++ = clr[1];
170 1.4 ad } else {
171 1.4 ad *dp++ = clr[0] >> 16;
172 1.4 ad *dp++ = clr[0] >> 8;
173 1.4 ad *dp++ = clr[0];
174 1.4 ad }
175 1.4 ad }
176 1.12 pk }
177 1.4 ad }
178 1.12 pk
179 1.4 ad /* Do underline */
180 1.30 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
181 1.31 rin uint8_t c = clr[1];
182 1.12 pk
183 1.4 ad rp -= ri->ri_stride << 1;
184 1.4 ad
185 1.4 ad while (width--) {
186 1.12 pk *rp++ = c >> 16;
187 1.12 pk *rp++ = c >> 8;
188 1.12 pk *rp++ = c;
189 1.1 ad }
190 1.12 pk }
191 1.1 ad }
192 1.1 ad
193 1.9 ad #ifndef RASOPS_SMALL
194 1.9 ad /*
195 1.9 ad * Recompute the blitting stamp.
196 1.9 ad */
197 1.9 ad static void
198 1.26 dsl rasops24_makestamp(struct rasops_info *ri, long attr)
199 1.9 ad {
200 1.9 ad u_int fg, bg, c1, c2, c3, c4;
201 1.9 ad int i;
202 1.12 pk
203 1.12 pk fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffffff;
204 1.12 pk bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffffff;
205 1.9 ad stamp_attr = attr;
206 1.12 pk
207 1.9 ad for (i = 0; i < 64; i += 4) {
208 1.9 ad #if BYTE_ORDER == LITTLE_ENDIAN
209 1.9 ad c1 = (i & 32 ? fg : bg);
210 1.9 ad c2 = (i & 16 ? fg : bg);
211 1.9 ad c3 = (i & 8 ? fg : bg);
212 1.9 ad c4 = (i & 4 ? fg : bg);
213 1.9 ad #else
214 1.9 ad c1 = (i & 8 ? fg : bg);
215 1.9 ad c2 = (i & 4 ? fg : bg);
216 1.9 ad c3 = (i & 16 ? fg : bg);
217 1.9 ad c4 = (i & 32 ? fg : bg);
218 1.9 ad #endif
219 1.9 ad stamp[i+0] = (c1 << 8) | (c2 >> 16);
220 1.9 ad stamp[i+1] = (c2 << 16) | (c3 >> 8);
221 1.9 ad stamp[i+2] = (c3 << 24) | c4;
222 1.9 ad
223 1.9 ad #if BYTE_ORDER == LITTLE_ENDIAN
224 1.9 ad if ((ri->ri_flg & RI_BSWAP) == 0) {
225 1.9 ad #else
226 1.9 ad if ((ri->ri_flg & RI_BSWAP) != 0) {
227 1.9 ad #endif
228 1.9 ad stamp[i+0] = bswap32(stamp[i+0]);
229 1.9 ad stamp[i+1] = bswap32(stamp[i+1]);
230 1.9 ad stamp[i+2] = bswap32(stamp[i+2]);
231 1.9 ad }
232 1.9 ad }
233 1.9 ad }
234 1.1 ad
235 1.1 ad /*
236 1.4 ad * Put a single character. This is for 8-pixel wide fonts.
237 1.1 ad */
238 1.1 ad static void
239 1.27 dsl rasops24_putchar8(void *cookie, int row, int col, u_int uc, long attr)
240 1.1 ad {
241 1.28 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
242 1.28 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
243 1.4 ad int height, so, fs;
244 1.32 rin uint32_t *rp;
245 1.31 rin uint8_t *fr;
246 1.12 pk
247 1.4 ad /* Can't risk remaking the stamp if it's already in use */
248 1.4 ad if (stamp_mutex++) {
249 1.4 ad stamp_mutex--;
250 1.4 ad rasops24_putchar(cookie, row, col, uc, attr);
251 1.4 ad return;
252 1.4 ad }
253 1.4 ad
254 1.12 pk #ifdef RASOPS_CLIPPING
255 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
256 1.4 ad stamp_mutex--;
257 1.1 ad return;
258 1.4 ad }
259 1.1 ad
260 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
261 1.4 ad stamp_mutex--;
262 1.4 ad return;
263 1.1 ad }
264 1.4 ad #endif
265 1.1 ad
266 1.4 ad /* Recompute stamp? */
267 1.4 ad if (attr != stamp_attr)
268 1.4 ad rasops24_makestamp(ri, attr);
269 1.12 pk
270 1.32 rin rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
271 1.28 macallan height = font->fontheight;
272 1.12 pk
273 1.4 ad if (uc == (u_int)-1) {
274 1.4 ad while (height--) {
275 1.33 rin rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] =
276 1.33 rin stamp[0];
277 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
278 1.12 pk }
279 1.4 ad } else {
280 1.34 rin fr = FONT_GLYPH(uc, font, ri);
281 1.28 macallan fs = font->stride;
282 1.12 pk
283 1.4 ad while (height--) {
284 1.4 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
285 1.4 ad rp[0] = STAMP_READ(so);
286 1.4 ad rp[1] = STAMP_READ(so + 4);
287 1.4 ad rp[2] = STAMP_READ(so + 8);
288 1.12 pk
289 1.4 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
290 1.4 ad rp[3] = STAMP_READ(so);
291 1.4 ad rp[4] = STAMP_READ(so + 4);
292 1.4 ad rp[5] = STAMP_READ(so + 8);
293 1.1 ad
294 1.4 ad fr += fs;
295 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
296 1.1 ad }
297 1.12 pk }
298 1.4 ad
299 1.4 ad /* Do underline */
300 1.30 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
301 1.32 rin DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
302 1.33 rin rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = STAMP_READ(52);
303 1.12 pk }
304 1.12 pk
305 1.4 ad stamp_mutex--;
306 1.1 ad }
307 1.1 ad
308 1.1 ad /*
309 1.4 ad * Put a single character. This is for 12-pixel wide fonts.
310 1.1 ad */
311 1.1 ad static void
312 1.27 dsl rasops24_putchar12(void *cookie, int row, int col, u_int uc, long attr)
313 1.1 ad {
314 1.28 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
315 1.28 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
316 1.4 ad int height, so, fs;
317 1.32 rin uint32_t *rp;
318 1.31 rin uint8_t *fr;
319 1.12 pk
320 1.4 ad /* Can't risk remaking the stamp if it's already in use */
321 1.4 ad if (stamp_mutex++) {
322 1.4 ad stamp_mutex--;
323 1.4 ad rasops24_putchar(cookie, row, col, uc, attr);
324 1.1 ad return;
325 1.1 ad }
326 1.4 ad
327 1.12 pk #ifdef RASOPS_CLIPPING
328 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
329 1.4 ad stamp_mutex--;
330 1.1 ad return;
331 1.4 ad }
332 1.1 ad
333 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
334 1.4 ad stamp_mutex--;
335 1.1 ad return;
336 1.4 ad }
337 1.1 ad #endif
338 1.4 ad
339 1.4 ad /* Recompute stamp? */
340 1.4 ad if (attr != stamp_attr)
341 1.4 ad rasops24_makestamp(ri, attr);
342 1.12 pk
343 1.32 rin rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
344 1.28 macallan height = font->fontheight;
345 1.1 ad
346 1.4 ad if (uc == (u_int)-1) {
347 1.4 ad while (height--) {
348 1.19 perry rp[0] = rp[1] = rp[2] = rp[3] =
349 1.33 rin rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = stamp[0];
350 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
351 1.12 pk }
352 1.4 ad } else {
353 1.34 rin fr = FONT_GLYPH(uc, font, ri);
354 1.28 macallan fs = font->stride;
355 1.12 pk
356 1.4 ad while (height--) {
357 1.4 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
358 1.4 ad rp[0] = STAMP_READ(so);
359 1.4 ad rp[1] = STAMP_READ(so + 4);
360 1.4 ad rp[2] = STAMP_READ(so + 8);
361 1.12 pk
362 1.4 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
363 1.4 ad rp[3] = STAMP_READ(so);
364 1.4 ad rp[4] = STAMP_READ(so + 4);
365 1.4 ad rp[5] = STAMP_READ(so + 8);
366 1.4 ad
367 1.4 ad so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
368 1.4 ad rp[6] = STAMP_READ(so);
369 1.4 ad rp[7] = STAMP_READ(so + 4);
370 1.4 ad rp[8] = STAMP_READ(so + 8);
371 1.1 ad
372 1.4 ad fr += fs;
373 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
374 1.1 ad }
375 1.12 pk }
376 1.4 ad
377 1.4 ad /* Do underline */
378 1.30 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
379 1.32 rin DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
380 1.12 pk rp[0] = rp[1] = rp[2] = rp[3] =
381 1.33 rin rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = STAMP_READ(52);
382 1.12 pk }
383 1.12 pk
384 1.4 ad stamp_mutex--;
385 1.1 ad }
386 1.1 ad
387 1.1 ad /*
388 1.4 ad * Put a single character. This is for 16-pixel wide fonts.
389 1.1 ad */
390 1.1 ad static void
391 1.27 dsl rasops24_putchar16(void *cookie, int row, int col, u_int uc, long attr)
392 1.1 ad {
393 1.28 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
394 1.28 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
395 1.4 ad int height, so, fs;
396 1.32 rin uint32_t *rp;
397 1.31 rin uint8_t *fr;
398 1.12 pk
399 1.4 ad /* Can't risk remaking the stamp if it's already in use */
400 1.4 ad if (stamp_mutex++) {
401 1.4 ad stamp_mutex--;
402 1.4 ad rasops24_putchar(cookie, row, col, uc, attr);
403 1.4 ad return;
404 1.4 ad }
405 1.4 ad
406 1.12 pk #ifdef RASOPS_CLIPPING
407 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
408 1.4 ad stamp_mutex--;
409 1.4 ad return;
410 1.4 ad }
411 1.4 ad
412 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
413 1.4 ad stamp_mutex--;
414 1.4 ad return;
415 1.4 ad }
416 1.4 ad #endif
417 1.4 ad
418 1.4 ad /* Recompute stamp? */
419 1.5 ad if (attr != stamp_attr)
420 1.4 ad rasops24_makestamp(ri, attr);
421 1.5 ad
422 1.32 rin rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
423 1.28 macallan height = font->fontheight;
424 1.12 pk
425 1.4 ad if (uc == (u_int)-1) {
426 1.4 ad while (height--) {
427 1.19 perry rp[0] = rp[1] = rp[2] = rp[3] =
428 1.19 perry rp[4] = rp[5] = rp[6] = rp[7] =
429 1.33 rin rp[8] = rp[9] = rp[10] = rp[11] = stamp[0];
430 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
431 1.12 pk }
432 1.4 ad } else {
433 1.34 rin fr = FONT_GLYPH(uc, font, ri);
434 1.28 macallan fs = font->stride;
435 1.12 pk
436 1.4 ad while (height--) {
437 1.4 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
438 1.4 ad rp[0] = STAMP_READ(so);
439 1.4 ad rp[1] = STAMP_READ(so + 4);
440 1.4 ad rp[2] = STAMP_READ(so + 8);
441 1.12 pk
442 1.4 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
443 1.4 ad rp[3] = STAMP_READ(so);
444 1.4 ad rp[4] = STAMP_READ(so + 4);
445 1.4 ad rp[5] = STAMP_READ(so + 8);
446 1.4 ad
447 1.4 ad so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
448 1.4 ad rp[6] = STAMP_READ(so);
449 1.4 ad rp[7] = STAMP_READ(so + 4);
450 1.4 ad rp[8] = STAMP_READ(so + 8);
451 1.12 pk
452 1.4 ad so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
453 1.4 ad rp[9] = STAMP_READ(so);
454 1.4 ad rp[10] = STAMP_READ(so + 4);
455 1.4 ad rp[11] = STAMP_READ(so + 8);
456 1.4 ad
457 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
458 1.4 ad fr += fs;
459 1.4 ad }
460 1.12 pk }
461 1.1 ad
462 1.4 ad /* Do underline */
463 1.30 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
464 1.32 rin DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
465 1.19 perry rp[0] = rp[1] = rp[2] = rp[3] =
466 1.19 perry rp[4] = rp[5] = rp[6] = rp[7] =
467 1.33 rin rp[8] = rp[9] = rp[10] = rp[11] = STAMP_READ(52);
468 1.12 pk }
469 1.12 pk
470 1.4 ad stamp_mutex--;
471 1.1 ad }
472 1.11 ad #endif /* !RASOPS_SMALL */
473 1.1 ad
474 1.1 ad /*
475 1.4 ad * Erase rows. This is nice and easy due to alignment.
476 1.1 ad */
477 1.1 ad static void
478 1.27 dsl rasops24_eraserows(void *cookie, int row, int num, long attr)
479 1.1 ad {
480 1.8 ad int n9, n3, n1, cnt, stride, delta;
481 1.31 rin uint32_t *dp, clr, xstamp[3];
482 1.1 ad struct rasops_info *ri;
483 1.12 pk
484 1.12 pk /*
485 1.4 ad * If the color is gray, we can cheat and use the generic routines
486 1.4 ad * (which are faster, hopefully) since the r,g,b values are the same.
487 1.4 ad */
488 1.30 mlelstv if ((attr & WSATTR_PRIVATE2) != 0) {
489 1.4 ad rasops_eraserows(cookie, row, num, attr);
490 1.4 ad return;
491 1.4 ad }
492 1.4 ad
493 1.1 ad ri = (struct rasops_info *)cookie;
494 1.1 ad
495 1.1 ad #ifdef RASOPS_CLIPPING
496 1.1 ad if (row < 0) {
497 1.1 ad num += row;
498 1.1 ad row = 0;
499 1.1 ad }
500 1.1 ad
501 1.1 ad if ((row + num) > ri->ri_rows)
502 1.1 ad num = ri->ri_rows - row;
503 1.12 pk
504 1.1 ad if (num <= 0)
505 1.1 ad return;
506 1.1 ad #endif
507 1.12 pk
508 1.12 pk clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
509 1.20 christos xstamp[0] = (clr << 8) | (clr >> 16);
510 1.20 christos xstamp[1] = (clr << 16) | (clr >> 8);
511 1.20 christos xstamp[2] = (clr << 24) | clr;
512 1.4 ad
513 1.4 ad #if BYTE_ORDER == LITTLE_ENDIAN
514 1.7 ad if ((ri->ri_flg & RI_BSWAP) == 0) {
515 1.4 ad #else
516 1.7 ad if ((ri->ri_flg & RI_BSWAP) != 0) {
517 1.4 ad #endif
518 1.20 christos xstamp[0] = bswap32(xstamp[0]);
519 1.20 christos xstamp[1] = bswap32(xstamp[1]);
520 1.20 christos xstamp[2] = bswap32(xstamp[2]);
521 1.4 ad }
522 1.4 ad
523 1.12 pk /*
524 1.7 ad * XXX the wsdisplay_emulops interface seems a little deficient in
525 1.12 pk * that there is no way to clear the *entire* screen. We provide a
526 1.12 pk * workaround here: if the entire console area is being cleared, and
527 1.7 ad * the RI_FULLCLEAR flag is set, clear the entire display.
528 1.12 pk */
529 1.7 ad if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
530 1.7 ad stride = ri->ri_stride;
531 1.7 ad num = ri->ri_height;
532 1.32 rin dp = (uint32_t *)ri->ri_origbits;
533 1.8 ad delta = 0;
534 1.7 ad } else {
535 1.7 ad stride = ri->ri_emustride;
536 1.7 ad num *= ri->ri_font->fontheight;
537 1.32 rin dp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale);
538 1.8 ad delta = ri->ri_delta;
539 1.7 ad }
540 1.7 ad
541 1.7 ad n9 = stride / 36;
542 1.1 ad cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
543 1.7 ad n3 = (stride - cnt) / 12;
544 1.1 ad cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
545 1.7 ad n1 = (stride - cnt) >> 2;
546 1.12 pk
547 1.4 ad while (num--) {
548 1.4 ad for (cnt = n9; cnt; cnt--) {
549 1.20 christos dp[0] = xstamp[0];
550 1.20 christos dp[1] = xstamp[1];
551 1.20 christos dp[2] = xstamp[2];
552 1.20 christos dp[3] = xstamp[0];
553 1.20 christos dp[4] = xstamp[1];
554 1.20 christos dp[5] = xstamp[2];
555 1.20 christos dp[6] = xstamp[0];
556 1.20 christos dp[7] = xstamp[1];
557 1.20 christos dp[8] = xstamp[2];
558 1.4 ad dp += 9;
559 1.4 ad }
560 1.1 ad
561 1.4 ad for (cnt = n3; cnt; cnt--) {
562 1.20 christos dp[0] = xstamp[0];
563 1.20 christos dp[1] = xstamp[1];
564 1.20 christos dp[2] = xstamp[2];
565 1.4 ad dp += 3;
566 1.4 ad }
567 1.12 pk
568 1.4 ad for (cnt = 0; cnt < n1; cnt++)
569 1.20 christos *dp++ = xstamp[cnt];
570 1.12 pk
571 1.32 rin DELTA(dp, delta, uint32_t *);
572 1.4 ad }
573 1.4 ad }
574 1.4 ad
575 1.4 ad /*
576 1.4 ad * Erase columns.
577 1.4 ad */
578 1.4 ad static void
579 1.27 dsl rasops24_erasecols(void *cookie, int row, int col, int num, long attr)
580 1.4 ad {
581 1.20 christos int n12, n4, height, cnt, slop, clr, xstamp[3];
582 1.4 ad struct rasops_info *ri;
583 1.32 rin uint32_t *dp, *rp;
584 1.31 rin uint8_t *dbp;
585 1.4 ad
586 1.12 pk /*
587 1.4 ad * If the color is gray, we can cheat and use the generic routines
588 1.4 ad * (which are faster, hopefully) since the r,g,b values are the same.
589 1.4 ad */
590 1.30 mlelstv if ((attr & WSATTR_PRIVATE2) != 0) {
591 1.4 ad rasops_erasecols(cookie, row, col, num, attr);
592 1.4 ad return;
593 1.4 ad }
594 1.12 pk
595 1.4 ad ri = (struct rasops_info *)cookie;
596 1.4 ad
597 1.12 pk #ifdef RASOPS_CLIPPING
598 1.12 pk /* Catches 'row < 0' case too */
599 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
600 1.4 ad return;
601 1.4 ad
602 1.4 ad if (col < 0) {
603 1.4 ad num += col;
604 1.4 ad col = 0;
605 1.4 ad }
606 1.4 ad
607 1.4 ad if ((col + num) > ri->ri_cols)
608 1.4 ad num = ri->ri_cols - col;
609 1.12 pk
610 1.4 ad if (num <= 0)
611 1.4 ad return;
612 1.4 ad #endif
613 1.12 pk
614 1.32 rin rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
615 1.4 ad num *= ri->ri_font->fontwidth;
616 1.4 ad height = ri->ri_font->fontheight;
617 1.4 ad
618 1.12 pk clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
619 1.20 christos xstamp[0] = (clr << 8) | (clr >> 16);
620 1.20 christos xstamp[1] = (clr << 16) | (clr >> 8);
621 1.20 christos xstamp[2] = (clr << 24) | clr;
622 1.4 ad
623 1.4 ad #if BYTE_ORDER == LITTLE_ENDIAN
624 1.7 ad if ((ri->ri_flg & RI_BSWAP) == 0) {
625 1.4 ad #else
626 1.7 ad if ((ri->ri_flg & RI_BSWAP) != 0) {
627 1.4 ad #endif
628 1.20 christos xstamp[0] = bswap32(xstamp[0]);
629 1.20 christos xstamp[1] = bswap32(xstamp[1]);
630 1.20 christos xstamp[2] = bswap32(xstamp[2]);
631 1.4 ad }
632 1.12 pk
633 1.12 pk /*
634 1.4 ad * The current byte offset mod 4 tells us the number of 24-bit pels
635 1.4 ad * we need to write for alignment to 32-bits. Once we're aligned on
636 1.4 ad * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
637 1.4 ad * the stamp does not need to be rotated. The following shows the
638 1.9 ad * layout of 4 pels in a 3 word region and illustrates this:
639 1.4 ad *
640 1.4 ad * aaab bbcc cddd
641 1.4 ad */
642 1.17 petrov slop = (int)(long)rp & 3; num -= slop;
643 1.4 ad n12 = num / 12; num -= (n12 << 3) + (n12 << 2);
644 1.4 ad n4 = num >> 2; num &= 3;
645 1.12 pk
646 1.4 ad while (height--) {
647 1.31 rin dbp = (uint8_t *)rp;
648 1.32 rin DELTA(rp, ri->ri_stride, uint32_t *);
649 1.4 ad
650 1.4 ad /* Align to 4 bytes */
651 1.7 ad /* XXX handle with masks, bring under control of RI_BSWAP */
652 1.4 ad for (cnt = slop; cnt; cnt--) {
653 1.4 ad *dbp++ = (clr >> 16);
654 1.4 ad *dbp++ = (clr >> 8);
655 1.12 pk *dbp++ = clr;
656 1.12 pk }
657 1.4 ad
658 1.32 rin dp = (uint32_t *)dbp;
659 1.12 pk
660 1.4 ad /* 12 pels per loop */
661 1.4 ad for (cnt = n12; cnt; cnt--) {
662 1.20 christos dp[0] = xstamp[0];
663 1.20 christos dp[1] = xstamp[1];
664 1.20 christos dp[2] = xstamp[2];
665 1.20 christos dp[3] = xstamp[0];
666 1.20 christos dp[4] = xstamp[1];
667 1.20 christos dp[5] = xstamp[2];
668 1.20 christos dp[6] = xstamp[0];
669 1.20 christos dp[7] = xstamp[1];
670 1.20 christos dp[8] = xstamp[2];
671 1.4 ad dp += 9;
672 1.1 ad }
673 1.1 ad
674 1.4 ad /* 4 pels per loop */
675 1.4 ad for (cnt = n4; cnt; cnt--) {
676 1.20 christos dp[0] = xstamp[0];
677 1.20 christos dp[1] = xstamp[1];
678 1.20 christos dp[2] = xstamp[2];
679 1.4 ad dp += 3;
680 1.4 ad }
681 1.12 pk
682 1.4 ad /* Trailing slop */
683 1.7 ad /* XXX handle with masks, bring under control of RI_BSWAP */
684 1.31 rin dbp = (uint8_t *)dp;
685 1.4 ad for (cnt = num; cnt; cnt--) {
686 1.4 ad *dbp++ = (clr >> 16);
687 1.4 ad *dbp++ = (clr >> 8);
688 1.12 pk *dbp++ = clr;
689 1.12 pk }
690 1.1 ad }
691 1.1 ad }
692