rasops.c revision 1.114 1 1.114 rin /* $NetBSD: rasops.c,v 1.114 2019/08/07 11:08:44 rin Exp $ */
2 1.1 ad
3 1.9 ad /*-
4 1.9 ad * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.9 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.32 ad * by Andrew Doran.
9 1.9 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.9 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.9 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.9 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.9 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.9 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.9 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.9 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.9 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.9 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.9 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.9 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ad */
31 1.2 ad
32 1.1 ad #include <sys/cdefs.h>
33 1.114 rin __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.114 2019/08/07 11:08:44 rin Exp $");
34 1.1 ad
35 1.109 rin #ifdef _KERNEL_OPT
36 1.18 ad #include "opt_rasops.h"
37 1.109 rin #include "opt_wsmsgattrs.h"
38 1.109 rin #endif
39 1.109 rin
40 1.4 ad #include "rasops_glue.h"
41 1.1 ad
42 1.1 ad #include <sys/param.h>
43 1.89 rin #include <sys/bswap.h>
44 1.89 rin #include <sys/kmem.h>
45 1.1 ad #include <sys/systm.h>
46 1.1 ad #include <sys/time.h>
47 1.1 ad
48 1.4 ad #include <machine/endian.h>
49 1.3 ad
50 1.1 ad #include <dev/wscons/wsdisplayvar.h>
51 1.1 ad #include <dev/wscons/wsconsio.h>
52 1.1 ad #include <dev/wsfont/wsfont.h>
53 1.102 rin
54 1.102 rin #define _RASOPS_PRIVATE
55 1.1 ad #include <dev/rasops/rasops.h>
56 1.114 rin #include <dev/rasops/rasops_masks.h> /* XXX for MBE */
57 1.1 ad
58 1.11 ad #ifndef _KERNEL
59 1.11 ad #include <errno.h>
60 1.11 ad #endif
61 1.11 ad
62 1.70 macallan #ifdef RASOPS_DEBUG
63 1.88 rin #define DPRINTF(...) aprint_error(...)
64 1.70 macallan #else
65 1.88 rin #define DPRINTF(...) __nothing
66 1.70 macallan #endif
67 1.70 macallan
68 1.70 macallan struct rasops_matchdata {
69 1.70 macallan struct rasops_info *ri;
70 1.70 macallan int wantcols, wantrows;
71 1.70 macallan int bestscore;
72 1.70 macallan struct wsdisplay_font *pick;
73 1.70 macallan int ident;
74 1.70 macallan };
75 1.70 macallan
76 1.114 rin static const uint32_t rasops_lmask32[4 + 1] = {
77 1.114 rin MBE(0x00000000), MBE(0x00ffffff), MBE(0x0000ffff), MBE(0x000000ff),
78 1.114 rin MBE(0x00000000),
79 1.114 rin };
80 1.114 rin
81 1.114 rin static const uint32_t rasops_rmask32[4 + 1] = {
82 1.114 rin MBE(0x00000000), MBE(0xff000000), MBE(0xffff0000), MBE(0xffffff00),
83 1.114 rin MBE(0xffffffff),
84 1.114 rin };
85 1.114 rin
86 1.1 ad /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
87 1.89 rin const uint8_t rasops_cmap[256 * 3] = {
88 1.1 ad 0x00, 0x00, 0x00, /* black */
89 1.1 ad 0x7f, 0x00, 0x00, /* red */
90 1.1 ad 0x00, 0x7f, 0x00, /* green */
91 1.1 ad 0x7f, 0x7f, 0x00, /* brown */
92 1.1 ad 0x00, 0x00, 0x7f, /* blue */
93 1.1 ad 0x7f, 0x00, 0x7f, /* magenta */
94 1.1 ad 0x00, 0x7f, 0x7f, /* cyan */
95 1.1 ad 0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
96 1.1 ad
97 1.1 ad 0x7f, 0x7f, 0x7f, /* black */
98 1.1 ad 0xff, 0x00, 0x00, /* red */
99 1.1 ad 0x00, 0xff, 0x00, /* green */
100 1.1 ad 0xff, 0xff, 0x00, /* brown */
101 1.1 ad 0x00, 0x00, 0xff, /* blue */
102 1.1 ad 0xff, 0x00, 0xff, /* magenta */
103 1.1 ad 0x00, 0xff, 0xff, /* cyan */
104 1.1 ad 0xff, 0xff, 0xff, /* white */
105 1.23 drochner
106 1.23 drochner /*
107 1.23 drochner * For the cursor, we need at least the last (255th)
108 1.23 drochner * color to be white. Fill up white completely for
109 1.23 drochner * simplicity.
110 1.23 drochner */
111 1.23 drochner #define _CMWHITE 0xff, 0xff, 0xff,
112 1.23 drochner #define _CMWHITE16 _CMWHITE _CMWHITE _CMWHITE _CMWHITE \
113 1.23 drochner _CMWHITE _CMWHITE _CMWHITE _CMWHITE \
114 1.23 drochner _CMWHITE _CMWHITE _CMWHITE _CMWHITE \
115 1.23 drochner _CMWHITE _CMWHITE _CMWHITE _CMWHITE
116 1.23 drochner _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
117 1.23 drochner _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
118 1.44 uwe _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 /* but not the last one */
119 1.23 drochner #undef _CMWHITE16
120 1.23 drochner #undef _CMWHITE
121 1.44 uwe
122 1.44 uwe /*
123 1.44 uwe * For the cursor the fg/bg indices are bit inverted, so
124 1.44 uwe * provide complimentary colors in the upper 16 entries.
125 1.44 uwe */
126 1.44 uwe 0x7f, 0x7f, 0x7f, /* black */
127 1.44 uwe 0xff, 0x00, 0x00, /* red */
128 1.44 uwe 0x00, 0xff, 0x00, /* green */
129 1.44 uwe 0xff, 0xff, 0x00, /* brown */
130 1.44 uwe 0x00, 0x00, 0xff, /* blue */
131 1.44 uwe 0xff, 0x00, 0xff, /* magenta */
132 1.44 uwe 0x00, 0xff, 0xff, /* cyan */
133 1.44 uwe 0xff, 0xff, 0xff, /* white */
134 1.44 uwe
135 1.44 uwe 0x00, 0x00, 0x00, /* black */
136 1.44 uwe 0x7f, 0x00, 0x00, /* red */
137 1.44 uwe 0x00, 0x7f, 0x00, /* green */
138 1.44 uwe 0x7f, 0x7f, 0x00, /* brown */
139 1.44 uwe 0x00, 0x00, 0x7f, /* blue */
140 1.44 uwe 0x7f, 0x00, 0x7f, /* magenta */
141 1.44 uwe 0x00, 0x7f, 0x7f, /* cyan */
142 1.44 uwe 0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
143 1.1 ad };
144 1.1 ad
145 1.1 ad /* True if color is gray */
146 1.102 rin static const uint8_t rasops_isgray[16] = {
147 1.102 rin 1, 0, 0, 0, 0, 0, 0, 1,
148 1.102 rin 1, 0, 0, 0, 0, 0, 0, 1,
149 1.1 ad };
150 1.1 ad
151 1.91 rin #ifdef RASOPS_APPLE_PALETTE
152 1.91 rin /*
153 1.91 rin * Approximate ANSI colormap for legacy Apple color palettes
154 1.91 rin */
155 1.91 rin static const uint8_t apple8_devcmap[16] = {
156 1.91 rin 0xff, /* black 0x00, 0x00, 0x00 */
157 1.91 rin 0x6b, /* red 0x99, 0x00, 0x00 */
158 1.91 rin 0xc5, /* green 0x00, 0x99, 0x00 */
159 1.91 rin 0x59, /* yellow 0x99, 0x99, 0x00 */
160 1.91 rin 0xd4, /* blue 0x00, 0x00, 0x99 */
161 1.91 rin 0x68, /* magenta 0x99, 0x00, 0x99 */
162 1.91 rin 0xc2, /* cyan 0x00, 0x99, 0x99 */
163 1.91 rin 0x2b, /* white 0xcc, 0xcc, 0xcc */
164 1.91 rin
165 1.91 rin 0x56, /* black 0x99, 0x99, 0x99 */
166 1.91 rin 0x23, /* red 0xff, 0x00, 0x00 */
167 1.91 rin 0xb9, /* green 0x00, 0xff, 0x00 */
168 1.91 rin 0x05, /* yellow 0xff, 0xff, 0x00 */
169 1.91 rin 0xd2, /* blue 0x00, 0x00, 0xff */
170 1.91 rin 0x1e, /* magenta 0xff, 0x00, 0xff */
171 1.91 rin 0xb4, /* cyan 0x00, 0xff, 0xff */
172 1.91 rin 0x00, /* white 0xff, 0xff, 0xff */
173 1.91 rin };
174 1.91 rin
175 1.91 rin static const uint8_t apple4_devcmap[16] = {
176 1.91 rin 15, /* black */
177 1.91 rin 3, /* red */
178 1.91 rin 8, /* green */
179 1.91 rin 1, /* yellow */
180 1.91 rin 6, /* blue */
181 1.91 rin 4, /* magenta */
182 1.91 rin 7, /* cyan */
183 1.91 rin 12, /* light grey */
184 1.91 rin
185 1.91 rin 13, /* medium grey */
186 1.91 rin 3, /* red */
187 1.91 rin 8, /* green */
188 1.91 rin 1, /* yellow */
189 1.91 rin 6, /* blue */
190 1.91 rin 4, /* magenta */
191 1.91 rin 7, /* cyan */
192 1.91 rin 0, /* white */
193 1.91 rin };
194 1.91 rin #endif
195 1.91 rin
196 1.4 ad /* Generic functions */
197 1.45 perry static void rasops_copyrows(void *, int, int, int);
198 1.102 rin static void rasops_copycols(void *, int, int, int, int);
199 1.45 perry static int rasops_mapchar(void *, int, u_int *);
200 1.45 perry static void rasops_cursor(void *, int, int, int);
201 1.45 perry static int rasops_allocattr_color(void *, int, int, int, long *);
202 1.45 perry static int rasops_allocattr_mono(void *, int, int, int, long *);
203 1.45 perry static void rasops_do_cursor(struct rasops_info *);
204 1.45 perry static void rasops_init_devcmap(struct rasops_info *);
205 1.1 ad
206 1.55 ober #if NRASOPS_ROTATION > 0
207 1.62 nonaka static void rasops_rotate_font(int *, int);
208 1.55 ober static void rasops_copychar(void *, int, int, int, int);
209 1.62 nonaka
210 1.62 nonaka /* rotate clockwise */
211 1.62 nonaka static void rasops_copycols_rotated_cw(void *, int, int, int, int);
212 1.62 nonaka static void rasops_copyrows_rotated_cw(void *, int, int, int);
213 1.62 nonaka static void rasops_erasecols_rotated_cw(void *, int, int, int, long);
214 1.62 nonaka static void rasops_eraserows_rotated_cw(void *, int, int, long);
215 1.62 nonaka static void rasops_putchar_rotated_cw(void *, int, int, u_int, long);
216 1.62 nonaka
217 1.62 nonaka /* rotate counter-clockwise */
218 1.62 nonaka static void rasops_copychar_ccw(void *, int, int, int, int);
219 1.62 nonaka static void rasops_copycols_rotated_ccw(void *, int, int, int, int);
220 1.62 nonaka static void rasops_copyrows_rotated_ccw(void *, int, int, int);
221 1.62 nonaka #define rasops_erasecols_rotated_ccw rasops_erasecols_rotated_cw
222 1.62 nonaka #define rasops_eraserows_rotated_ccw rasops_eraserows_rotated_cw
223 1.62 nonaka static void rasops_putchar_rotated_ccw(void *, int, int, u_int, long);
224 1.55 ober
225 1.55 ober /*
226 1.55 ober * List of all rotated fonts
227 1.55 ober */
228 1.55 ober SLIST_HEAD(, rotatedfont) rotatedfonts = SLIST_HEAD_INITIALIZER(rotatedfonts);
229 1.55 ober struct rotatedfont {
230 1.55 ober SLIST_ENTRY(rotatedfont) rf_next;
231 1.55 ober int rf_cookie;
232 1.55 ober int rf_rotated;
233 1.55 ober };
234 1.55 ober #endif /* NRASOPS_ROTATION > 0 */
235 1.55 ober
236 1.63 macallan void rasops_make_box_chars_8(struct rasops_info *);
237 1.63 macallan void rasops_make_box_chars_16(struct rasops_info *);
238 1.63 macallan void rasops_make_box_chars_32(struct rasops_info *);
239 1.67 macallan void rasops_make_box_chars_alpha(struct rasops_info *);
240 1.63 macallan
241 1.1 ad /*
242 1.37 wiz * Initialize a 'rasops_info' descriptor.
243 1.1 ad */
244 1.1 ad int
245 1.60 dsl rasops_init(struct rasops_info *ri, int wantrows, int wantcols)
246 1.1 ad {
247 1.20 ad
248 1.94 rin memset(&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
249 1.30 pk #ifdef _KERNEL
250 1.1 ad /* Select a font if the caller doesn't care */
251 1.1 ad if (ri->ri_font == NULL) {
252 1.67 macallan int cookie = -1;
253 1.73 mlelstv int flags;
254 1.30 pk
255 1.1 ad wsfont_init();
256 1.1 ad
257 1.70 macallan /*
258 1.70 macallan * first, try to find something that's as close as possible
259 1.70 macallan * to the caller's requested terminal size
260 1.70 macallan */
261 1.70 macallan if (wantrows == 0)
262 1.70 macallan wantrows = RASOPS_DEFAULT_HEIGHT;
263 1.70 macallan if (wantcols == 0)
264 1.70 macallan wantcols = RASOPS_DEFAULT_WIDTH;
265 1.73 mlelstv
266 1.73 mlelstv flags = WSFONT_FIND_BESTWIDTH | WSFONT_FIND_BITMAP;
267 1.73 mlelstv if ((ri->ri_flg & RI_ENABLE_ALPHA) != 0)
268 1.73 mlelstv flags |= WSFONT_FIND_ALPHA;
269 1.75 macallan if ((ri->ri_flg & RI_PREFER_ALPHA) != 0)
270 1.75 macallan flags |= WSFONT_PREFER_ALPHA;
271 1.73 mlelstv cookie = wsfont_find(NULL,
272 1.73 mlelstv ri->ri_width / wantcols,
273 1.73 mlelstv 0,
274 1.73 mlelstv 0,
275 1.73 mlelstv WSDISPLAY_FONTORDER_L2R,
276 1.73 mlelstv WSDISPLAY_FONTORDER_L2R,
277 1.73 mlelstv flags);
278 1.1 ad
279 1.70 macallan /*
280 1.70 macallan * this means there is no supported font in the list
281 1.70 macallan */
282 1.7 ad if (cookie <= 0) {
283 1.89 rin aprint_error("%s: font table is empty\n", __func__);
284 1.88 rin return -1;
285 1.1 ad }
286 1.30 pk
287 1.55 ober #if NRASOPS_ROTATION > 0
288 1.55 ober /*
289 1.55 ober * Pick the rotated version of this font. This will create it
290 1.55 ober * if necessary.
291 1.55 ober */
292 1.62 nonaka if (ri->ri_flg & RI_ROTATE_MASK) {
293 1.62 nonaka if (ri->ri_flg & RI_ROTATE_CW)
294 1.62 nonaka rasops_rotate_font(&cookie, WSFONT_ROTATE_CW);
295 1.62 nonaka else if (ri->ri_flg & RI_ROTATE_CCW)
296 1.62 nonaka rasops_rotate_font(&cookie, WSFONT_ROTATE_CCW);
297 1.62 nonaka }
298 1.55 ober #endif
299 1.55 ober
300 1.39 ad if (wsfont_lock(cookie, &ri->ri_font)) {
301 1.89 rin aprint_error("%s: couldn't lock font\n", __func__);
302 1.88 rin return -1;
303 1.1 ad }
304 1.8 ad
305 1.5 ad ri->ri_wsfcookie = cookie;
306 1.1 ad }
307 1.4 ad #endif
308 1.30 pk
309 1.1 ad /* This should never happen in reality... */
310 1.89 rin if ((uintptr_t)ri->ri_bits & 3) {
311 1.89 rin aprint_error("%s: bits not aligned on 32-bit boundary\n",
312 1.89 rin __func__);
313 1.88 rin return -1;
314 1.1 ad }
315 1.1 ad
316 1.89 rin if (ri->ri_stride & 3) {
317 1.89 rin aprint_error("%s: stride not aligned on 32-bit boundary\n",
318 1.89 rin __func__);
319 1.88 rin return -1;
320 1.1 ad }
321 1.4 ad
322 1.13 ad if (rasops_reconfig(ri, wantrows, wantcols))
323 1.88 rin return -1;
324 1.46 perry
325 1.4 ad rasops_init_devcmap(ri);
326 1.88 rin return 0;
327 1.4 ad }
328 1.4 ad
329 1.4 ad /*
330 1.13 ad * Reconfigure (because parameters have changed in some way).
331 1.4 ad */
332 1.4 ad int
333 1.60 dsl rasops_reconfig(struct rasops_info *ri, int wantrows, int wantcols)
334 1.4 ad {
335 1.89 rin int bpp, s;
336 1.89 rin size_t len;
337 1.30 pk
338 1.13 ad s = splhigh();
339 1.30 pk
340 1.70 macallan if (wantrows == 0)
341 1.70 macallan wantrows = RASOPS_DEFAULT_HEIGHT;
342 1.70 macallan if (wantcols == 0)
343 1.70 macallan wantcols = RASOPS_DEFAULT_WIDTH;
344 1.70 macallan
345 1.63 macallan /* throw away old line drawing character bitmaps, if we have any */
346 1.63 macallan if (ri->ri_optfont.data != NULL) {
347 1.63 macallan kmem_free(ri->ri_optfont.data, ri->ri_optfont.stride *
348 1.63 macallan ri->ri_optfont.fontheight * ri->ri_optfont.numchars);
349 1.63 macallan ri->ri_optfont.data = NULL;
350 1.63 macallan }
351 1.63 macallan
352 1.63 macallan /* autogenerate box drawing characters */
353 1.64 macallan ri->ri_optfont.firstchar = WSFONT_FLAG_OPT;
354 1.64 macallan ri->ri_optfont.numchars = 16;
355 1.63 macallan ri->ri_optfont.fontwidth = ri->ri_font->fontwidth;
356 1.63 macallan ri->ri_optfont.fontheight = ri->ri_font->fontheight;
357 1.63 macallan ri->ri_optfont.stride = ri->ri_font->stride;
358 1.64 macallan len = ri->ri_optfont.fontheight * ri->ri_optfont.stride *
359 1.89 rin ri->ri_optfont.numchars;
360 1.89 rin
361 1.89 rin if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4) {
362 1.89 rin aprint_error("%s: fontwidth assumptions botched", __func__);
363 1.89 rin splx(s);
364 1.89 rin return -1;
365 1.89 rin }
366 1.64 macallan
367 1.77 chs if ((ri->ri_flg & RI_NO_AUTO) == 0) {
368 1.77 chs ri->ri_optfont.data = kmem_zalloc(len, KM_SLEEP);
369 1.89 rin if (FONT_IS_ALPHA(&ri->ri_optfont))
370 1.89 rin rasops_make_box_chars_alpha(ri);
371 1.89 rin else {
372 1.67 macallan switch (ri->ri_optfont.stride) {
373 1.67 macallan case 1:
374 1.67 macallan rasops_make_box_chars_8(ri);
375 1.67 macallan break;
376 1.67 macallan case 2:
377 1.67 macallan rasops_make_box_chars_16(ri);
378 1.67 macallan break;
379 1.67 macallan case 4:
380 1.67 macallan rasops_make_box_chars_32(ri);
381 1.67 macallan break;
382 1.89 rin default:
383 1.89 rin aprint_error(
384 1.89 rin "%s: font stride assumptions botched",
385 1.89 rin __func__);
386 1.89 rin splx(s);
387 1.89 rin return -1;
388 1.67 macallan }
389 1.63 macallan }
390 1.64 macallan } else
391 1.64 macallan memset(&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
392 1.63 macallan
393 1.4 ad /* Need this to frob the setup below */
394 1.4 ad bpp = (ri->ri_depth == 15 ? 16 : ri->ri_depth);
395 1.4 ad
396 1.74 nonaka if ((ri->ri_flg & RI_CFGDONE) != 0) {
397 1.4 ad ri->ri_bits = ri->ri_origbits;
398 1.74 nonaka ri->ri_hwbits = ri->ri_hworigbits;
399 1.74 nonaka }
400 1.30 pk
401 1.1 ad /* Don't care if the caller wants a hideously small console */
402 1.1 ad if (wantrows < 10)
403 1.13 ad wantrows = 10;
404 1.30 pk
405 1.1 ad if (wantcols < 20)
406 1.13 ad wantcols = 20;
407 1.30 pk
408 1.1 ad /* Now constrain what they get */
409 1.1 ad ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
410 1.1 ad ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
411 1.30 pk
412 1.1 ad if (ri->ri_emuwidth > ri->ri_width)
413 1.1 ad ri->ri_emuwidth = ri->ri_width;
414 1.30 pk
415 1.1 ad if (ri->ri_emuheight > ri->ri_height)
416 1.1 ad ri->ri_emuheight = ri->ri_height;
417 1.30 pk
418 1.1 ad /* Reduce width until aligned on a 32-bit boundary */
419 1.20 ad while ((ri->ri_emuwidth * bpp & 31) != 0)
420 1.1 ad ri->ri_emuwidth--;
421 1.30 pk
422 1.55 ober #if NRASOPS_ROTATION > 0
423 1.62 nonaka if (ri->ri_flg & (RI_ROTATE_CW|RI_ROTATE_CCW)) {
424 1.55 ober ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
425 1.55 ober ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
426 1.55 ober } else
427 1.55 ober #endif
428 1.55 ober {
429 1.55 ober ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
430 1.55 ober ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
431 1.55 ober }
432 1.4 ad ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
433 1.1 ad ri->ri_ccol = 0;
434 1.1 ad ri->ri_crow = 0;
435 1.4 ad ri->ri_pelbytes = bpp >> 3;
436 1.30 pk
437 1.4 ad ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
438 1.1 ad ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
439 1.1 ad ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
440 1.1 ad
441 1.75 macallan ri->ri_origbits = ri->ri_bits;
442 1.75 macallan ri->ri_hworigbits = ri->ri_hwbits;
443 1.75 macallan
444 1.1 ad /* Clear the entire display */
445 1.13 ad if ((ri->ri_flg & RI_CLEAR) != 0)
446 1.13 ad memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
447 1.30 pk
448 1.30 pk /* Now centre our window if needs be */
449 1.13 ad if ((ri->ri_flg & RI_CENTER) != 0) {
450 1.108 rin uint32_t xoff, yoff;
451 1.108 rin
452 1.108 rin xoff = ((ri->ri_width * bpp >> 3) - ri->ri_emustride) >> 1;
453 1.108 rin if (ri->ri_depth != 24) {
454 1.108 rin /*
455 1.108 rin * Truncate to word boundary.
456 1.108 rin */
457 1.108 rin xoff &= ~3;
458 1.108 rin } else {
459 1.108 rin /*
460 1.110 rin * Truncate to both word and 24-bit color boundary.
461 1.108 rin */
462 1.110 rin xoff -= xoff % 12;
463 1.108 rin }
464 1.108 rin
465 1.108 rin yoff = ((ri->ri_height - ri->ri_emuheight) >> 1) *
466 1.1 ad ri->ri_stride;
467 1.108 rin
468 1.108 rin ri->ri_bits += xoff;
469 1.108 rin ri->ri_bits += yoff;
470 1.61 macallan if (ri->ri_hwbits != NULL) {
471 1.108 rin ri->ri_hwbits += xoff;
472 1.108 rin ri->ri_hwbits += yoff;
473 1.61 macallan }
474 1.108 rin
475 1.89 rin ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits) /
476 1.89 rin ri->ri_stride;
477 1.89 rin ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits) %
478 1.89 rin ri->ri_stride) * 8 / bpp);
479 1.5 ad } else
480 1.5 ad ri->ri_xorigin = ri->ri_yorigin = 0;
481 1.4 ad
482 1.30 pk /*
483 1.4 ad * Fill in defaults for operations set. XXX this nukes private
484 1.4 ad * routines used by accelerated fb drivers.
485 1.4 ad */
486 1.1 ad ri->ri_ops.mapchar = rasops_mapchar;
487 1.1 ad ri->ri_ops.copyrows = rasops_copyrows;
488 1.1 ad ri->ri_ops.copycols = rasops_copycols;
489 1.4 ad ri->ri_ops.erasecols = rasops_erasecols;
490 1.4 ad ri->ri_ops.eraserows = rasops_eraserows;
491 1.1 ad ri->ri_ops.cursor = rasops_cursor;
492 1.4 ad ri->ri_do_cursor = rasops_do_cursor;
493 1.30 pk
494 1.76 macallan ri->ri_caps &= ~(WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
495 1.76 macallan WSSCREEN_WSCOLORS | WSSCREEN_REVERSE);
496 1.91 rin
497 1.91 rin if ((ri->ri_flg & RI_FORCEMONO) != 0 ||
498 1.112 rin #ifndef RASOPS_APPLE_PALETTE
499 1.112 rin ri->ri_depth < 8
500 1.91 rin #else
501 1.112 rin ri->ri_depth < 4
502 1.91 rin #endif
503 1.91 rin ) {
504 1.41 junyoung ri->ri_ops.allocattr = rasops_allocattr_mono;
505 1.76 macallan ri->ri_caps |= WSSCREEN_UNDERLINE | WSSCREEN_REVERSE;
506 1.4 ad } else {
507 1.41 junyoung ri->ri_ops.allocattr = rasops_allocattr_color;
508 1.76 macallan ri->ri_caps |= WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
509 1.24 drochner WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
510 1.4 ad }
511 1.4 ad
512 1.105 rin if (ri->ri_buf != NULL) {
513 1.105 rin kmem_free(ri->ri_buf, ri->ri_buflen);
514 1.105 rin ri->ri_buf = NULL;
515 1.105 rin }
516 1.105 rin len = (ri->ri_flg & RI_FULLCLEAR) ? ri->ri_stride : ri->ri_emustride;
517 1.105 rin ri->ri_buflen = len;
518 1.105 rin ri->ri_buf = kmem_alloc(len, KM_SLEEP);
519 1.105 rin
520 1.103 rin #ifndef RASOPS_SMALL
521 1.103 rin if (ri->ri_stamp != NULL) {
522 1.103 rin kmem_free(ri->ri_stamp, ri->ri_stamp_len);
523 1.103 rin ri->ri_stamp = NULL;
524 1.103 rin }
525 1.103 rin #endif
526 1.103 rin
527 1.1 ad switch (ri->ri_depth) {
528 1.20 ad #if NRASOPS1 > 0
529 1.1 ad case 1:
530 1.1 ad rasops1_init(ri);
531 1.1 ad break;
532 1.1 ad #endif
533 1.20 ad #if NRASOPS2 > 0
534 1.4 ad case 2:
535 1.4 ad rasops2_init(ri);
536 1.34 takemura break;
537 1.34 takemura #endif
538 1.34 takemura #if NRASOPS4 > 0
539 1.34 takemura case 4:
540 1.34 takemura rasops4_init(ri);
541 1.4 ad break;
542 1.4 ad #endif
543 1.20 ad #if NRASOPS8 > 0
544 1.1 ad case 8:
545 1.1 ad rasops8_init(ri);
546 1.1 ad break;
547 1.1 ad #endif
548 1.95 rin #if (NRASOPS15 + NRASOPS16) > 0
549 1.1 ad case 15:
550 1.1 ad case 16:
551 1.1 ad rasops15_init(ri);
552 1.1 ad break;
553 1.1 ad #endif
554 1.20 ad #if NRASOPS24 > 0
555 1.1 ad case 24:
556 1.1 ad rasops24_init(ri);
557 1.1 ad break;
558 1.1 ad #endif
559 1.20 ad #if NRASOPS32 > 0
560 1.1 ad case 32:
561 1.1 ad rasops32_init(ri);
562 1.1 ad break;
563 1.1 ad #endif
564 1.1 ad default:
565 1.13 ad ri->ri_flg &= ~RI_CFGDONE;
566 1.89 rin aprint_error("%s: depth not supported\n", __func__);
567 1.13 ad splx(s);
568 1.88 rin return -1;
569 1.1 ad }
570 1.30 pk
571 1.55 ober #if NRASOPS_ROTATION > 0
572 1.62 nonaka if (ri->ri_flg & RI_ROTATE_MASK) {
573 1.62 nonaka if (ri->ri_flg & RI_ROTATE_CW) {
574 1.62 nonaka ri->ri_real_ops = ri->ri_ops;
575 1.62 nonaka ri->ri_ops.copycols = rasops_copycols_rotated_cw;
576 1.62 nonaka ri->ri_ops.copyrows = rasops_copyrows_rotated_cw;
577 1.62 nonaka ri->ri_ops.erasecols = rasops_erasecols_rotated_cw;
578 1.62 nonaka ri->ri_ops.eraserows = rasops_eraserows_rotated_cw;
579 1.62 nonaka ri->ri_ops.putchar = rasops_putchar_rotated_cw;
580 1.62 nonaka } else if (ri->ri_flg & RI_ROTATE_CCW) {
581 1.62 nonaka ri->ri_real_ops = ri->ri_ops;
582 1.62 nonaka ri->ri_ops.copycols = rasops_copycols_rotated_ccw;
583 1.62 nonaka ri->ri_ops.copyrows = rasops_copyrows_rotated_ccw;
584 1.62 nonaka ri->ri_ops.erasecols = rasops_erasecols_rotated_ccw;
585 1.62 nonaka ri->ri_ops.eraserows = rasops_eraserows_rotated_ccw;
586 1.62 nonaka ri->ri_ops.putchar = rasops_putchar_rotated_ccw;
587 1.62 nonaka }
588 1.55 ober }
589 1.55 ober #endif
590 1.55 ober
591 1.13 ad ri->ri_flg |= RI_CFGDONE;
592 1.13 ad splx(s);
593 1.88 rin return 0;
594 1.1 ad }
595 1.1 ad
596 1.1 ad /*
597 1.1 ad * Map a character.
598 1.1 ad */
599 1.1 ad static int
600 1.59 dsl rasops_mapchar(void *cookie, int c, u_int *cp)
601 1.1 ad {
602 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
603 1.8 ad
604 1.88 rin KASSERT(ri->ri_font != NULL);
605 1.39 ad
606 1.89 rin if ((c = wsfont_map_unichar(ri->ri_font, c)) < 0 ||
607 1.89 rin c < ri->ri_font->firstchar) {
608 1.63 macallan *cp = ' ';
609 1.88 rin return 0;
610 1.35 marcus }
611 1.30 pk
612 1.89 rin #if 0 /* XXXRO */
613 1.89 rin if (CHAR_IN_FONT(c, ri->ri_font)) {
614 1.1 ad *cp = ' ';
615 1.88 rin return 0;
616 1.1 ad }
617 1.89 rin #endif
618 1.30 pk
619 1.1 ad *cp = c;
620 1.88 rin return 5;
621 1.1 ad }
622 1.1 ad
623 1.1 ad /*
624 1.1 ad * Allocate a color attribute.
625 1.1 ad */
626 1.1 ad static int
627 1.89 rin rasops_allocattr_color(void *cookie, int fg0, int bg0, int flg, long *attr)
628 1.1 ad {
629 1.89 rin uint32_t fg = fg0, bg = bg0;
630 1.1 ad
631 1.89 rin if (__predict_false(fg >= sizeof(rasops_isgray) ||
632 1.89 rin bg >= sizeof(rasops_isgray)))
633 1.88 rin return EINVAL;
634 1.56 mjf
635 1.1 ad #ifdef RASOPS_CLIPPING
636 1.1 ad fg &= 7;
637 1.1 ad bg &= 7;
638 1.1 ad #endif
639 1.17 ad if ((flg & WSATTR_BLINK) != 0)
640 1.88 rin return EINVAL;
641 1.23 drochner
642 1.23 drochner if ((flg & WSATTR_WSCOLORS) == 0) {
643 1.48 macallan #ifdef WS_DEFAULT_FG
644 1.48 macallan fg = WS_DEFAULT_FG;
645 1.48 macallan #else
646 1.48 macallan fg = WSCOL_WHITE;
647 1.48 macallan #endif
648 1.48 macallan #ifdef WS_DEFAULT_BG
649 1.48 macallan bg = WS_DEFAULT_BG;
650 1.48 macallan #else
651 1.48 macallan bg = WSCOL_BLACK;
652 1.48 macallan #endif
653 1.23 drochner }
654 1.23 drochner
655 1.98 rin if ((flg & WSATTR_HILIT) != 0)
656 1.98 rin fg += 8;
657 1.98 rin
658 1.17 ad if ((flg & WSATTR_REVERSE) != 0) {
659 1.89 rin uint32_t swap = fg;
660 1.1 ad fg = bg;
661 1.1 ad bg = swap;
662 1.1 ad }
663 1.1 ad
664 1.98 rin flg &= WSATTR_USERMASK;
665 1.30 pk
666 1.1 ad if (rasops_isgray[fg])
667 1.79 mlelstv flg |= WSATTR_PRIVATE1;
668 1.1 ad
669 1.1 ad if (rasops_isgray[bg])
670 1.79 mlelstv flg |= WSATTR_PRIVATE2;
671 1.1 ad
672 1.1 ad *attr = (bg << 16) | (fg << 24) | flg;
673 1.88 rin return 0;
674 1.1 ad }
675 1.1 ad
676 1.1 ad /*
677 1.1 ad * Allocate a mono attribute.
678 1.1 ad */
679 1.1 ad static int
680 1.89 rin rasops_allocattr_mono(void *cookie, int fg0, int bg0, int flg, long *attr)
681 1.1 ad {
682 1.89 rin uint32_t fg = fg0, bg = bg0;
683 1.1 ad
684 1.23 drochner if ((flg & (WSATTR_BLINK | WSATTR_HILIT | WSATTR_WSCOLORS)) != 0)
685 1.88 rin return EINVAL;
686 1.23 drochner
687 1.111 rin fg = 0xff;
688 1.23 drochner bg = 0;
689 1.23 drochner
690 1.17 ad if ((flg & WSATTR_REVERSE) != 0) {
691 1.89 rin uint32_t swap = fg;
692 1.1 ad fg = bg;
693 1.1 ad bg = swap;
694 1.1 ad }
695 1.1 ad
696 1.95 rin *attr = (bg << 16) | (fg << 24) | flg;
697 1.88 rin return 0;
698 1.1 ad }
699 1.1 ad
700 1.1 ad /*
701 1.1 ad * Copy rows.
702 1.1 ad */
703 1.1 ad static void
704 1.60 dsl rasops_copyrows(void *cookie, int src, int dst, int num)
705 1.1 ad {
706 1.90 rin struct rasops_info *ri = (struct rasops_info *)cookie;
707 1.90 rin uint8_t *sp, *dp, *hp;
708 1.99 rin int n, stride;
709 1.30 pk
710 1.90 rin hp = NULL; /* XXX GCC */
711 1.1 ad
712 1.100 rin if (__predict_false(dst == src))
713 1.1 ad return;
714 1.30 pk
715 1.100 rin #ifdef RASOPS_CLIPPING
716 1.1 ad if (src < 0) {
717 1.1 ad num += src;
718 1.1 ad src = 0;
719 1.1 ad }
720 1.1 ad
721 1.89 rin if (src + num > ri->ri_rows)
722 1.1 ad num = ri->ri_rows - src;
723 1.1 ad
724 1.1 ad if (dst < 0) {
725 1.1 ad num += dst;
726 1.1 ad dst = 0;
727 1.1 ad }
728 1.1 ad
729 1.89 rin if (dst + num > ri->ri_rows)
730 1.1 ad num = ri->ri_rows - dst;
731 1.30 pk
732 1.1 ad if (num <= 0)
733 1.1 ad return;
734 1.1 ad #endif
735 1.1 ad
736 1.1 ad num *= ri->ri_font->fontheight;
737 1.90 rin n = ri->ri_emustride;
738 1.99 rin stride = ri->ri_stride;
739 1.30 pk
740 1.113 rin src *= ri->ri_yscale;
741 1.113 rin dst *= ri->ri_yscale;
742 1.113 rin
743 1.113 rin if (src < dst) {
744 1.113 rin /* backward copy */
745 1.113 rin src += (num - 1) * stride;
746 1.113 rin dst += (num - 1) * stride;
747 1.113 rin stride *= -1;
748 1.113 rin }
749 1.113 rin
750 1.113 rin sp = ri->ri_bits + src;
751 1.113 rin dp = ri->ri_bits + dst;
752 1.90 rin if (ri->ri_hwbits)
753 1.113 rin hp = ri->ri_hwbits + dst;
754 1.30 pk
755 1.18 ad while (num--) {
756 1.100 rin memcpy(dp, sp, n);
757 1.113 rin sp += stride;
758 1.52 jmcneill if (ri->ri_hwbits) {
759 1.113 rin memcpy(hp, dp, n);
760 1.99 rin hp += stride;
761 1.51 jmcneill }
762 1.113 rin dp += stride;
763 1.1 ad }
764 1.1 ad }
765 1.1 ad
766 1.1 ad /*
767 1.1 ad * Copy columns. This is slow, and hard to optimize due to alignment,
768 1.1 ad * and the fact that we have to copy both left->right and right->left.
769 1.43 uwe * We simply cop-out here and use memmove(), since it handles all of
770 1.1 ad * these cases anyway.
771 1.1 ad */
772 1.102 rin static void
773 1.60 dsl rasops_copycols(void *cookie, int row, int src, int dst, int num)
774 1.1 ad {
775 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
776 1.81 rin uint8_t *sp, *dp, *hp;
777 1.1 ad int height;
778 1.30 pk
779 1.89 rin hp = NULL; /* XXX GCC */
780 1.1 ad
781 1.100 rin if (__predict_false(dst == src))
782 1.1 ad return;
783 1.30 pk
784 1.100 rin #ifdef RASOPS_CLIPPING
785 1.3 ad /* Catches < 0 case too */
786 1.3 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
787 1.1 ad return;
788 1.30 pk
789 1.1 ad if (src < 0) {
790 1.1 ad num += src;
791 1.1 ad src = 0;
792 1.1 ad }
793 1.1 ad
794 1.89 rin if (src + num > ri->ri_cols)
795 1.1 ad num = ri->ri_cols - src;
796 1.1 ad
797 1.1 ad if (dst < 0) {
798 1.1 ad num += dst;
799 1.1 ad dst = 0;
800 1.1 ad }
801 1.1 ad
802 1.89 rin if (dst + num > ri->ri_cols)
803 1.1 ad num = ri->ri_cols - dst;
804 1.30 pk
805 1.1 ad if (num <= 0)
806 1.1 ad return;
807 1.1 ad #endif
808 1.30 pk
809 1.1 ad num *= ri->ri_xscale;
810 1.1 ad row *= ri->ri_yscale;
811 1.1 ad height = ri->ri_font->fontheight;
812 1.30 pk
813 1.1 ad sp = ri->ri_bits + row + src * ri->ri_xscale;
814 1.1 ad dp = ri->ri_bits + row + dst * ri->ri_xscale;
815 1.51 jmcneill if (ri->ri_hwbits)
816 1.51 jmcneill hp = ri->ri_hwbits + row + dst * ri->ri_xscale;
817 1.30 pk
818 1.1 ad while (height--) {
819 1.106 rin memmove(dp, sp, num);
820 1.51 jmcneill if (ri->ri_hwbits) {
821 1.106 rin memcpy(hp, dp, num);
822 1.51 jmcneill hp += ri->ri_stride;
823 1.51 jmcneill }
824 1.106 rin dp += ri->ri_stride;
825 1.1 ad sp += ri->ri_stride;
826 1.1 ad }
827 1.1 ad }
828 1.1 ad
829 1.1 ad /*
830 1.1 ad * Turn cursor off/on.
831 1.1 ad */
832 1.1 ad static void
833 1.60 dsl rasops_cursor(void *cookie, int on, int row, int col)
834 1.1 ad {
835 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
836 1.30 pk
837 1.1 ad /* Turn old cursor off */
838 1.13 ad if ((ri->ri_flg & RI_CURSOR) != 0)
839 1.30 pk #ifdef RASOPS_CLIPPING
840 1.13 ad if ((ri->ri_flg & RI_CURSORCLIP) == 0)
841 1.1 ad #endif
842 1.1 ad ri->ri_do_cursor(ri);
843 1.1 ad
844 1.1 ad /* Select new cursor */
845 1.1 ad #ifdef RASOPS_CLIPPING
846 1.13 ad ri->ri_flg &= ~RI_CURSORCLIP;
847 1.30 pk
848 1.1 ad if (row < 0 || row >= ri->ri_rows)
849 1.13 ad ri->ri_flg |= RI_CURSORCLIP;
850 1.1 ad else if (col < 0 || col >= ri->ri_cols)
851 1.13 ad ri->ri_flg |= RI_CURSORCLIP;
852 1.1 ad #endif
853 1.1 ad ri->ri_crow = row;
854 1.1 ad ri->ri_ccol = col;
855 1.1 ad
856 1.1 ad if (on) {
857 1.13 ad ri->ri_flg |= RI_CURSOR;
858 1.30 pk #ifdef RASOPS_CLIPPING
859 1.13 ad if ((ri->ri_flg & RI_CURSORCLIP) == 0)
860 1.1 ad #endif
861 1.1 ad ri->ri_do_cursor(ri);
862 1.30 pk } else
863 1.13 ad ri->ri_flg &= ~RI_CURSOR;
864 1.1 ad }
865 1.1 ad
866 1.1 ad /*
867 1.1 ad * Make the device colormap
868 1.1 ad */
869 1.4 ad static void
870 1.59 dsl rasops_init_devcmap(struct rasops_info *ri)
871 1.1 ad {
872 1.89 rin int i;
873 1.89 rin uint32_t c;
874 1.81 rin const uint8_t *p;
875 1.30 pk
876 1.4 ad switch (ri->ri_depth) {
877 1.4 ad case 1:
878 1.4 ad ri->ri_devcmap[0] = 0;
879 1.4 ad for (i = 1; i < 16; i++)
880 1.4 ad ri->ri_devcmap[i] = -1;
881 1.4 ad return;
882 1.4 ad
883 1.4 ad case 2:
884 1.4 ad for (i = 1; i < 15; i++)
885 1.89 rin ri->ri_devcmap[i] = 0xaaaaaaaa;
886 1.30 pk
887 1.4 ad ri->ri_devcmap[0] = 0;
888 1.89 rin ri->ri_devcmap[8] = 0x55555555;
889 1.4 ad ri->ri_devcmap[15] = -1;
890 1.4 ad return;
891 1.4 ad
892 1.91 rin #ifdef RASOPS_APPLE_PALETTE
893 1.91 rin case 4:
894 1.91 rin for (i = 0; i < 16; i++) {
895 1.91 rin c = apple4_devcmap[i];
896 1.91 rin ri->ri_devcmap[i] =
897 1.91 rin (c << 0) | (c << 4) | (c << 8) | (c << 12) |
898 1.91 rin (c << 16) | (c << 20) | (c << 24) | (c << 28);
899 1.91 rin }
900 1.91 rin return;
901 1.91 rin #else
902 1.91 rin /* XXXRO What should we do here? */
903 1.91 rin #endif
904 1.91 rin
905 1.4 ad case 8:
906 1.68 macallan if ((ri->ri_flg & RI_8BIT_IS_RGB) == 0) {
907 1.89 rin for (i = 0; i < 16; i++) {
908 1.91 rin #ifdef RASOPS_APPLE_PALETTE
909 1.91 rin c = apple8_devcmap[i];
910 1.91 rin #else
911 1.89 rin c = i;
912 1.91 rin #endif
913 1.68 macallan ri->ri_devcmap[i] =
914 1.89 rin c | (c << 8) | (c << 16) | (c << 24);
915 1.89 rin }
916 1.68 macallan return;
917 1.68 macallan }
918 1.4 ad }
919 1.30 pk
920 1.1 ad p = rasops_cmap;
921 1.30 pk
922 1.29 nathanw for (i = 0; i < 16; i++) {
923 1.1 ad if (ri->ri_rnum <= 8)
924 1.89 rin c = (uint32_t)(*p >> (8 - ri->ri_rnum)) << ri->ri_rpos;
925 1.30 pk else
926 1.89 rin c = (uint32_t)(*p << (ri->ri_rnum - 8)) << ri->ri_rpos;
927 1.29 nathanw p++;
928 1.1 ad
929 1.1 ad if (ri->ri_gnum <= 8)
930 1.89 rin c |= (uint32_t)(*p >> (8 - ri->ri_gnum)) << ri->ri_gpos;
931 1.30 pk else
932 1.89 rin c |= (uint32_t)(*p << (ri->ri_gnum - 8)) << ri->ri_gpos;
933 1.29 nathanw p++;
934 1.1 ad
935 1.1 ad if (ri->ri_bnum <= 8)
936 1.89 rin c |= (uint32_t)(*p >> (8 - ri->ri_bnum)) << ri->ri_bpos;
937 1.30 pk else
938 1.89 rin c |= (uint32_t)(*p << (ri->ri_bnum - 8)) << ri->ri_bpos;
939 1.29 nathanw p++;
940 1.4 ad
941 1.108 rin /*
942 1.108 rin * Swap byte order if necessary. Then, fill the word for
943 1.108 rin * generic routines, which want this.
944 1.108 rin */
945 1.108 rin switch (ri->ri_depth) {
946 1.108 rin case 8:
947 1.89 rin c |= c << 8;
948 1.89 rin c |= c << 16;
949 1.108 rin break;
950 1.108 rin case 15:
951 1.108 rin case 16:
952 1.108 rin if ((ri->ri_flg & RI_BSWAP) != 0)
953 1.108 rin c = bswap16(c);
954 1.69 macallan c |= c << 16;
955 1.108 rin break;
956 1.108 rin case 24:
957 1.96 rin #if BYTE_ORDER == LITTLE_ENDIAN
958 1.108 rin if ((ri->ri_flg & RI_BSWAP) == 0)
959 1.97 rin #else
960 1.108 rin if ((ri->ri_flg & RI_BSWAP) != 0)
961 1.96 rin #endif
962 1.108 rin {
963 1.108 rin /*
964 1.108 rin * Convert to ``big endian'' if not RI_BSWAP.
965 1.108 rin */
966 1.108 rin c = (c & 0x0000ff) << 16|
967 1.108 rin (c & 0x00ff00) |
968 1.108 rin (c & 0xff0000) >> 16;
969 1.108 rin }
970 1.108 rin
971 1.108 rin /*
972 1.108 rin * No worries, we use generic routines only for
973 1.108 rin * gray colors, where all 3 bytes are same.
974 1.108 rin */
975 1.89 rin c |= (c & 0xff) << 24;
976 1.108 rin break;
977 1.108 rin case 32:
978 1.108 rin if ((ri->ri_flg & RI_BSWAP) != 0)
979 1.108 rin c = bswap32(c);
980 1.108 rin break;
981 1.96 rin }
982 1.1 ad
983 1.108 rin ri->ri_devcmap[i] = c;
984 1.1 ad }
985 1.1 ad }
986 1.1 ad
987 1.1 ad /*
988 1.1 ad * Unpack a rasops attribute
989 1.1 ad */
990 1.1 ad void
991 1.60 dsl rasops_unpack_attr(long attr, int *fg, int *bg, int *underline)
992 1.1 ad {
993 1.30 pk
994 1.89 rin *fg = ((uint32_t)attr >> 24) & 0xf;
995 1.89 rin *bg = ((uint32_t)attr >> 16) & 0xf;
996 1.25 ad if (underline != NULL)
997 1.89 rin *underline = (uint32_t)attr & WSATTR_UNDERLINE;
998 1.4 ad }
999 1.4 ad
1000 1.4 ad /*
1001 1.4 ad * Erase rows. This isn't static, since 24-bpp uses it in special cases.
1002 1.4 ad */
1003 1.4 ad void
1004 1.60 dsl rasops_eraserows(void *cookie, int row, int num, long attr)
1005 1.4 ad {
1006 1.90 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1007 1.105 rin uint32_t *buf = (uint32_t *)ri->ri_buf;
1008 1.105 rin uint32_t *rp, *hp, clr;
1009 1.105 rin int stride, cnt;
1010 1.30 pk
1011 1.90 rin hp = NULL; /* XXX GCC */
1012 1.4 ad
1013 1.4 ad #ifdef RASOPS_CLIPPING
1014 1.4 ad if (row < 0) {
1015 1.4 ad num += row;
1016 1.4 ad row = 0;
1017 1.4 ad }
1018 1.4 ad
1019 1.89 rin if (row + num > ri->ri_rows)
1020 1.4 ad num = ri->ri_rows - row;
1021 1.30 pk
1022 1.4 ad if (num <= 0)
1023 1.4 ad return;
1024 1.4 ad #endif
1025 1.4 ad
1026 1.94 rin clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
1027 1.4 ad
1028 1.30 pk /*
1029 1.20 ad * XXX The wsdisplay_emulops interface seems a little deficient in
1030 1.30 pk * that there is no way to clear the *entire* screen. We provide a
1031 1.30 pk * workaround here: if the entire console area is being cleared, and
1032 1.13 ad * the RI_FULLCLEAR flag is set, clear the entire display.
1033 1.30 pk */
1034 1.13 ad if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
1035 1.105 rin stride = ri->ri_stride;
1036 1.13 ad num = ri->ri_height;
1037 1.101 rin rp = (uint32_t *)ri->ri_origbits;
1038 1.51 jmcneill if (ri->ri_hwbits)
1039 1.82 rin hp = (uint32_t *)ri->ri_hworigbits;
1040 1.13 ad } else {
1041 1.105 rin stride = ri->ri_emustride;
1042 1.13 ad num *= ri->ri_font->fontheight;
1043 1.101 rin rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale);
1044 1.51 jmcneill if (ri->ri_hwbits)
1045 1.101 rin hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale);
1046 1.13 ad }
1047 1.30 pk
1048 1.105 rin for (cnt = 0; cnt < stride >> 2; cnt++)
1049 1.105 rin buf[cnt] = clr;
1050 1.105 rin
1051 1.4 ad while (num--) {
1052 1.105 rin memcpy(rp, buf, stride);
1053 1.101 rin if (ri->ri_hwbits) {
1054 1.105 rin memcpy(hp, buf, stride);
1055 1.101 rin DELTA(hp, ri->ri_stride, uint32_t *);
1056 1.30 pk }
1057 1.101 rin DELTA(rp, ri->ri_stride, uint32_t *);
1058 1.4 ad }
1059 1.4 ad }
1060 1.4 ad
1061 1.4 ad /*
1062 1.4 ad * Actually turn the cursor on or off. This does the dirty work for
1063 1.4 ad * rasops_cursor().
1064 1.4 ad */
1065 1.4 ad static void
1066 1.59 dsl rasops_do_cursor(struct rasops_info *ri)
1067 1.4 ad {
1068 1.84 rin int full, height, cnt, slop1, slop2, row, col;
1069 1.114 rin uint32_t mask1, mask2, *dp;
1070 1.114 rin uint8_t tmp8, *rp, *hp;
1071 1.51 jmcneill
1072 1.101 rin hp = NULL; /* XXX GCC */
1073 1.30 pk
1074 1.55 ober #if NRASOPS_ROTATION > 0
1075 1.62 nonaka if (ri->ri_flg & RI_ROTATE_MASK) {
1076 1.62 nonaka if (ri->ri_flg & RI_ROTATE_CW) {
1077 1.62 nonaka /* Rotate rows/columns */
1078 1.62 nonaka row = ri->ri_ccol;
1079 1.62 nonaka col = ri->ri_rows - ri->ri_crow - 1;
1080 1.62 nonaka } else if (ri->ri_flg & RI_ROTATE_CCW) {
1081 1.62 nonaka /* Rotate rows/columns */
1082 1.62 nonaka row = ri->ri_cols - ri->ri_ccol - 1;
1083 1.62 nonaka col = ri->ri_crow;
1084 1.62 nonaka } else { /* upside-down */
1085 1.62 nonaka row = ri->ri_crow;
1086 1.62 nonaka col = ri->ri_ccol;
1087 1.62 nonaka }
1088 1.55 ober } else
1089 1.55 ober #endif
1090 1.55 ober {
1091 1.55 ober row = ri->ri_crow;
1092 1.55 ober col = ri->ri_ccol;
1093 1.55 ober }
1094 1.30 pk
1095 1.4 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
1096 1.51 jmcneill if (ri->ri_hwbits)
1097 1.101 rin hp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
1098 1.4 ad height = ri->ri_font->fontheight;
1099 1.30 pk
1100 1.80 rin /*
1101 1.80 rin * For ri_xscale = 1:
1102 1.80 rin *
1103 1.80 rin * Logic below does not work for ri_xscale = 1, e.g.,
1104 1.80 rin * fontwidth = 8 and bpp = 1. So we take care of it.
1105 1.80 rin */
1106 1.80 rin if (ri->ri_xscale == 1) {
1107 1.80 rin while (height--) {
1108 1.84 rin tmp8 = ~*rp;
1109 1.80 rin
1110 1.80 rin *rp = tmp8;
1111 1.80 rin rp += ri->ri_stride;
1112 1.30 pk
1113 1.80 rin if (ri->ri_hwbits) {
1114 1.101 rin *hp = tmp8;
1115 1.101 rin hp += ri->ri_stride;
1116 1.80 rin }
1117 1.80 rin }
1118 1.80 rin return;
1119 1.80 rin }
1120 1.80 rin
1121 1.80 rin /*
1122 1.80 rin * For ri_xscale = 2, 3, 4, ...:
1123 1.80 rin *
1124 1.80 rin * Note that siop1 <= ri_xscale even for ri_xscale = 2,
1125 1.84 rin * since rp % 3 = 0 or 2 (ri_stride % 4 = 0).
1126 1.80 rin */
1127 1.80 rin slop1 = (4 - ((uintptr_t)rp & 3)) & 3;
1128 1.4 ad slop2 = (ri->ri_xscale - slop1) & 3;
1129 1.89 rin full = (ri->ri_xscale - slop1 /* - slop2 */) >> 2;
1130 1.30 pk
1131 1.84 rin rp = (uint8_t *)((uintptr_t)rp & ~3);
1132 1.101 rin hp = (uint8_t *)((uintptr_t)hp & ~3);
1133 1.30 pk
1134 1.114 rin mask1 = rasops_lmask32[4 - slop1];
1135 1.114 rin mask2 = rasops_rmask32[slop2];
1136 1.85 rin
1137 1.84 rin while (height--) {
1138 1.114 rin dp = (uint32_t *)rp;
1139 1.78 macallan
1140 1.84 rin if (slop1) {
1141 1.114 rin *dp = *dp ^ mask1;
1142 1.114 rin dp++;
1143 1.84 rin }
1144 1.30 pk
1145 1.84 rin for (cnt = full; cnt; cnt--) {
1146 1.114 rin *dp = ~*(uint32_t *)dp;
1147 1.114 rin dp++;
1148 1.84 rin }
1149 1.30 pk
1150 1.114 rin if (slop2)
1151 1.114 rin *dp = *dp ^ mask2;
1152 1.101 rin
1153 1.101 rin if (ri->ri_hwbits) {
1154 1.101 rin memcpy(hp, rp, ((slop1 != 0) + full +
1155 1.101 rin (slop2 != 0)) << 2);
1156 1.101 rin hp += ri->ri_stride;
1157 1.101 rin }
1158 1.101 rin rp += ri->ri_stride;
1159 1.4 ad }
1160 1.4 ad }
1161 1.4 ad
1162 1.4 ad /*
1163 1.4 ad * Erase columns.
1164 1.4 ad */
1165 1.4 ad void
1166 1.60 dsl rasops_erasecols(void *cookie, int row, int col, int num, long attr)
1167 1.4 ad {
1168 1.90 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1169 1.107 rin uint32_t *buf = ri->ri_buf;
1170 1.107 rin int height, cnt, clr;
1171 1.105 rin uint32_t *dp, *rp, *hp;
1172 1.30 pk
1173 1.101 rin hp = NULL; /* XXX GCC */
1174 1.30 pk
1175 1.30 pk #ifdef RASOPS_CLIPPING
1176 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
1177 1.4 ad return;
1178 1.4 ad
1179 1.4 ad if (col < 0) {
1180 1.4 ad num += col;
1181 1.4 ad col = 0;
1182 1.4 ad }
1183 1.4 ad
1184 1.101 rin if (col + num > ri->ri_cols)
1185 1.4 ad num = ri->ri_cols - col;
1186 1.30 pk
1187 1.4 ad if (num <= 0)
1188 1.4 ad return;
1189 1.4 ad #endif
1190 1.30 pk
1191 1.90 rin num *= ri->ri_xscale;
1192 1.82 rin rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
1193 1.51 jmcneill if (ri->ri_hwbits)
1194 1.101 rin hp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
1195 1.51 jmcneill col*ri->ri_xscale);
1196 1.4 ad height = ri->ri_font->fontheight;
1197 1.94 rin clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
1198 1.30 pk
1199 1.105 rin dp = buf;
1200 1.30 pk
1201 1.105 rin /* Write 4 bytes per loop */
1202 1.107 rin for (cnt = num >> 2; cnt; cnt--)
1203 1.105 rin *dp++ = clr;
1204 1.30 pk
1205 1.105 rin /* Write unaligned trailing slop */
1206 1.107 rin for (cnt = num & 3; cnt; cnt--) {
1207 1.105 rin *(uint8_t *)dp = clr;
1208 1.105 rin DELTA(dp, 1, uint32_t *);
1209 1.105 rin }
1210 1.30 pk
1211 1.105 rin while (height--) {
1212 1.105 rin memcpy(rp, buf, num);
1213 1.105 rin DELTA(rp, ri->ri_stride, uint32_t *);
1214 1.101 rin if (ri->ri_hwbits) {
1215 1.105 rin memcpy(hp, buf, num);
1216 1.101 rin DELTA(hp, ri->ri_stride, uint32_t *);
1217 1.51 jmcneill }
1218 1.4 ad }
1219 1.1 ad }
1220 1.55 ober
1221 1.55 ober #if NRASOPS_ROTATION > 0
1222 1.55 ober /*
1223 1.55 ober * Quarter clockwise rotation routines (originally intended for the
1224 1.55 ober * built-in Zaurus C3x00 display in 16bpp).
1225 1.55 ober */
1226 1.55 ober
1227 1.55 ober static void
1228 1.62 nonaka rasops_rotate_font(int *cookie, int rotate)
1229 1.55 ober {
1230 1.55 ober struct rotatedfont *f;
1231 1.55 ober int ncookie;
1232 1.55 ober
1233 1.55 ober SLIST_FOREACH(f, &rotatedfonts, rf_next) {
1234 1.55 ober if (f->rf_cookie == *cookie) {
1235 1.55 ober *cookie = f->rf_rotated;
1236 1.55 ober return;
1237 1.55 ober }
1238 1.55 ober }
1239 1.55 ober
1240 1.55 ober /*
1241 1.55 ober * We did not find a rotated version of this font. Ask the wsfont
1242 1.55 ober * code to compute one for us.
1243 1.55 ober */
1244 1.55 ober
1245 1.89 rin f = kmem_alloc(sizeof(*f), KM_SLEEP);
1246 1.55 ober
1247 1.62 nonaka if ((ncookie = wsfont_rotate(*cookie, rotate)) == -1)
1248 1.89 rin goto fail;
1249 1.55 ober
1250 1.55 ober f->rf_cookie = *cookie;
1251 1.55 ober f->rf_rotated = ncookie;
1252 1.55 ober SLIST_INSERT_HEAD(&rotatedfonts, f, rf_next);
1253 1.55 ober
1254 1.55 ober *cookie = ncookie;
1255 1.72 riastrad return;
1256 1.72 riastrad
1257 1.93 martin fail: kmem_free(f, sizeof(*f));
1258 1.72 riastrad return;
1259 1.55 ober }
1260 1.55 ober
1261 1.55 ober static void
1262 1.60 dsl rasops_copychar(void *cookie, int srcrow, int dstrow, int srccol, int dstcol)
1263 1.55 ober {
1264 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1265 1.55 ober int height;
1266 1.55 ober int r_srcrow, r_dstrow, r_srccol, r_dstcol;
1267 1.89 rin uint8_t *sp, *dp;
1268 1.55 ober
1269 1.55 ober r_srcrow = srccol;
1270 1.55 ober r_dstrow = dstcol;
1271 1.55 ober r_srccol = ri->ri_rows - srcrow - 1;
1272 1.55 ober r_dstcol = ri->ri_rows - dstrow - 1;
1273 1.55 ober
1274 1.55 ober r_srcrow *= ri->ri_yscale;
1275 1.55 ober r_dstrow *= ri->ri_yscale;
1276 1.55 ober height = ri->ri_font->fontheight;
1277 1.55 ober
1278 1.55 ober sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
1279 1.55 ober dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
1280 1.55 ober
1281 1.55 ober while (height--) {
1282 1.55 ober memmove(dp, sp, ri->ri_xscale);
1283 1.55 ober dp += ri->ri_stride;
1284 1.55 ober sp += ri->ri_stride;
1285 1.55 ober }
1286 1.55 ober }
1287 1.55 ober
1288 1.55 ober static void
1289 1.62 nonaka rasops_putchar_rotated_cw(void *cookie, int row, int col, u_int uc, long attr)
1290 1.55 ober {
1291 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1292 1.89 rin int height;
1293 1.81 rin uint8_t *rp;
1294 1.55 ober
1295 1.56 mjf if (__predict_false((unsigned int)row > ri->ri_rows ||
1296 1.56 mjf (unsigned int)col > ri->ri_cols))
1297 1.56 mjf return;
1298 1.56 mjf
1299 1.56 mjf /* Avoid underflow */
1300 1.89 rin if (ri->ri_rows - row - 1 < 0)
1301 1.56 mjf return;
1302 1.56 mjf
1303 1.55 ober /* Do rotated char sans (side)underline */
1304 1.55 ober ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
1305 1.79 mlelstv attr & ~WSATTR_UNDERLINE);
1306 1.55 ober
1307 1.55 ober /* Do rotated underline */
1308 1.55 ober rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) *
1309 1.55 ober ri->ri_xscale;
1310 1.55 ober height = ri->ri_font->fontheight;
1311 1.55 ober
1312 1.55 ober /* XXX this assumes 16-bit color depth */
1313 1.79 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
1314 1.82 rin uint16_t c =
1315 1.94 rin (uint16_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
1316 1.55 ober
1317 1.55 ober while (height--) {
1318 1.82 rin *(uint16_t *)rp = c;
1319 1.55 ober rp += ri->ri_stride;
1320 1.55 ober }
1321 1.55 ober }
1322 1.55 ober }
1323 1.55 ober
1324 1.55 ober static void
1325 1.62 nonaka rasops_erasecols_rotated_cw(void *cookie, int row, int col, int num, long attr)
1326 1.55 ober {
1327 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1328 1.55 ober int i;
1329 1.55 ober
1330 1.55 ober for (i = col; i < col + num; i++)
1331 1.55 ober ri->ri_ops.putchar(cookie, row, i, ' ', attr);
1332 1.55 ober }
1333 1.55 ober
1334 1.55 ober /* XXX: these could likely be optimised somewhat. */
1335 1.55 ober static void
1336 1.62 nonaka rasops_copyrows_rotated_cw(void *cookie, int src, int dst, int num)
1337 1.55 ober {
1338 1.55 ober struct rasops_info *ri = (struct rasops_info *)cookie;
1339 1.55 ober int col, roff;
1340 1.55 ober
1341 1.55 ober if (src > dst)
1342 1.55 ober for (roff = 0; roff < num; roff++)
1343 1.55 ober for (col = 0; col < ri->ri_cols; col++)
1344 1.55 ober rasops_copychar(cookie, src + roff, dst + roff,
1345 1.55 ober col, col);
1346 1.55 ober else
1347 1.55 ober for (roff = num - 1; roff >= 0; roff--)
1348 1.55 ober for (col = 0; col < ri->ri_cols; col++)
1349 1.55 ober rasops_copychar(cookie, src + roff, dst + roff,
1350 1.55 ober col, col);
1351 1.55 ober }
1352 1.55 ober
1353 1.55 ober static void
1354 1.62 nonaka rasops_copycols_rotated_cw(void *cookie, int row, int src, int dst, int num)
1355 1.55 ober {
1356 1.55 ober int coff;
1357 1.55 ober
1358 1.55 ober if (src > dst)
1359 1.55 ober for (coff = 0; coff < num; coff++)
1360 1.88 rin rasops_copychar(cookie, row, row, src + coff,
1361 1.88 rin dst + coff);
1362 1.55 ober else
1363 1.55 ober for (coff = num - 1; coff >= 0; coff--)
1364 1.88 rin rasops_copychar(cookie, row, row, src + coff,
1365 1.88 rin dst + coff);
1366 1.55 ober }
1367 1.55 ober
1368 1.55 ober static void
1369 1.62 nonaka rasops_eraserows_rotated_cw(void *cookie, int row, int num, long attr)
1370 1.55 ober {
1371 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1372 1.55 ober int col, rn;
1373 1.55 ober
1374 1.55 ober for (rn = row; rn < row + num; rn++)
1375 1.55 ober for (col = 0; col < ri->ri_cols; col++)
1376 1.55 ober ri->ri_ops.putchar(cookie, rn, col, ' ', attr);
1377 1.55 ober }
1378 1.62 nonaka
1379 1.62 nonaka /*
1380 1.62 nonaka * Quarter counter-clockwise rotation routines (originally intended for the
1381 1.62 nonaka * built-in Sharp W-ZERO3 display in 16bpp).
1382 1.62 nonaka */
1383 1.62 nonaka static void
1384 1.88 rin rasops_copychar_ccw(void *cookie, int srcrow, int dstrow, int srccol,
1385 1.88 rin int dstcol)
1386 1.62 nonaka {
1387 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1388 1.89 rin int height, r_srcrow, r_dstrow, r_srccol, r_dstcol;
1389 1.81 rin uint8_t *sp, *dp;
1390 1.62 nonaka
1391 1.62 nonaka r_srcrow = ri->ri_cols - srccol - 1;
1392 1.62 nonaka r_dstrow = ri->ri_cols - dstcol - 1;
1393 1.62 nonaka r_srccol = srcrow;
1394 1.62 nonaka r_dstcol = dstrow;
1395 1.62 nonaka
1396 1.62 nonaka r_srcrow *= ri->ri_yscale;
1397 1.62 nonaka r_dstrow *= ri->ri_yscale;
1398 1.62 nonaka height = ri->ri_font->fontheight;
1399 1.62 nonaka
1400 1.62 nonaka sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
1401 1.62 nonaka dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
1402 1.62 nonaka
1403 1.62 nonaka while (height--) {
1404 1.62 nonaka memmove(dp, sp, ri->ri_xscale);
1405 1.62 nonaka dp += ri->ri_stride;
1406 1.62 nonaka sp += ri->ri_stride;
1407 1.62 nonaka }
1408 1.62 nonaka }
1409 1.62 nonaka
1410 1.62 nonaka static void
1411 1.62 nonaka rasops_putchar_rotated_ccw(void *cookie, int row, int col, u_int uc, long attr)
1412 1.62 nonaka {
1413 1.89 rin struct rasops_info *ri = (struct rasops_info *)cookie;
1414 1.89 rin int height;
1415 1.81 rin uint8_t *rp;
1416 1.62 nonaka
1417 1.62 nonaka if (__predict_false((unsigned int)row > ri->ri_rows ||
1418 1.62 nonaka (unsigned int)col > ri->ri_cols))
1419 1.62 nonaka return;
1420 1.62 nonaka
1421 1.62 nonaka /* Avoid underflow */
1422 1.89 rin if (ri->ri_cols - col - 1 < 0)
1423 1.62 nonaka return;
1424 1.62 nonaka
1425 1.62 nonaka /* Do rotated char sans (side)underline */
1426 1.62 nonaka ri->ri_real_ops.putchar(cookie, ri->ri_cols - col - 1, row, uc,
1427 1.79 mlelstv attr & ~WSATTR_UNDERLINE);
1428 1.62 nonaka
1429 1.62 nonaka /* Do rotated underline */
1430 1.62 nonaka rp = ri->ri_bits + (ri->ri_cols - col - 1) * ri->ri_yscale +
1431 1.65 tsutsui row * ri->ri_xscale +
1432 1.65 tsutsui (ri->ri_font->fontwidth - 1) * ri->ri_pelbytes;
1433 1.62 nonaka height = ri->ri_font->fontheight;
1434 1.62 nonaka
1435 1.62 nonaka /* XXX this assumes 16-bit color depth */
1436 1.79 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
1437 1.82 rin uint16_t c =
1438 1.94 rin (uint16_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
1439 1.62 nonaka
1440 1.62 nonaka while (height--) {
1441 1.82 rin *(uint16_t *)rp = c;
1442 1.62 nonaka rp += ri->ri_stride;
1443 1.62 nonaka }
1444 1.62 nonaka }
1445 1.62 nonaka }
1446 1.62 nonaka
1447 1.62 nonaka /* XXX: these could likely be optimised somewhat. */
1448 1.62 nonaka static void
1449 1.62 nonaka rasops_copyrows_rotated_ccw(void *cookie, int src, int dst, int num)
1450 1.62 nonaka {
1451 1.62 nonaka struct rasops_info *ri = (struct rasops_info *)cookie;
1452 1.62 nonaka int col, roff;
1453 1.62 nonaka
1454 1.62 nonaka if (src > dst)
1455 1.62 nonaka for (roff = 0; roff < num; roff++)
1456 1.62 nonaka for (col = 0; col < ri->ri_cols; col++)
1457 1.62 nonaka rasops_copychar_ccw(cookie,
1458 1.62 nonaka src + roff, dst + roff, col, col);
1459 1.62 nonaka else
1460 1.62 nonaka for (roff = num - 1; roff >= 0; roff--)
1461 1.62 nonaka for (col = 0; col < ri->ri_cols; col++)
1462 1.62 nonaka rasops_copychar_ccw(cookie,
1463 1.62 nonaka src + roff, dst + roff, col, col);
1464 1.62 nonaka }
1465 1.62 nonaka
1466 1.62 nonaka static void
1467 1.62 nonaka rasops_copycols_rotated_ccw(void *cookie, int row, int src, int dst, int num)
1468 1.62 nonaka {
1469 1.62 nonaka int coff;
1470 1.62 nonaka
1471 1.62 nonaka if (src > dst)
1472 1.62 nonaka for (coff = 0; coff < num; coff++)
1473 1.62 nonaka rasops_copychar_ccw(cookie, row, row,
1474 1.62 nonaka src + coff, dst + coff);
1475 1.62 nonaka else
1476 1.62 nonaka for (coff = num - 1; coff >= 0; coff--)
1477 1.62 nonaka rasops_copychar_ccw(cookie, row, row,
1478 1.62 nonaka src + coff, dst + coff);
1479 1.62 nonaka }
1480 1.55 ober #endif /* NRASOPS_ROTATION */
1481 1.63 macallan
1482 1.63 macallan void
1483 1.63 macallan rasops_make_box_chars_16(struct rasops_info *ri)
1484 1.63 macallan {
1485 1.89 rin int c, i, mid;
1486 1.63 macallan uint16_t vert_mask, hmask_left, hmask_right;
1487 1.63 macallan uint16_t *data = (uint16_t *)ri->ri_optfont.data;
1488 1.63 macallan
1489 1.89 rin vert_mask = 0xc000U >> ((ri->ri_font->fontwidth >> 1) - 1);
1490 1.89 rin hmask_left = 0xff00U << (8 - (ri->ri_font->fontwidth >> 1));
1491 1.88 rin hmask_right = hmask_left >> ((ri->ri_font->fontwidth + 1) >> 1);
1492 1.63 macallan mid = (ri->ri_font->fontheight + 1) >> 1;
1493 1.63 macallan
1494 1.63 macallan /* 0x00 would be empty anyway so don't bother */
1495 1.63 macallan for (c = 1; c < 16; c++) {
1496 1.63 macallan data += ri->ri_font->fontheight;
1497 1.63 macallan if (c & 1) {
1498 1.63 macallan /* upper segment */
1499 1.63 macallan for (i = 0; i < mid; i++)
1500 1.63 macallan data[i] = vert_mask;
1501 1.63 macallan }
1502 1.63 macallan if (c & 4) {
1503 1.63 macallan /* lower segment */
1504 1.63 macallan for (i = mid; i < ri->ri_font->fontheight; i++)
1505 1.63 macallan data[i] = vert_mask;
1506 1.63 macallan }
1507 1.63 macallan if (c & 2) {
1508 1.63 macallan /* right segment */
1509 1.63 macallan i = ri->ri_font->fontheight >> 1;
1510 1.63 macallan data[mid - 1] |= hmask_right;
1511 1.63 macallan data[mid] |= hmask_right;
1512 1.63 macallan }
1513 1.63 macallan if (c & 8) {
1514 1.63 macallan /* left segment */
1515 1.63 macallan data[mid - 1] |= hmask_left;
1516 1.63 macallan data[mid] |= hmask_left;
1517 1.63 macallan }
1518 1.63 macallan }
1519 1.63 macallan }
1520 1.63 macallan
1521 1.63 macallan void
1522 1.63 macallan rasops_make_box_chars_8(struct rasops_info *ri)
1523 1.63 macallan {
1524 1.89 rin int c, i, mid;
1525 1.63 macallan uint8_t vert_mask, hmask_left, hmask_right;
1526 1.63 macallan uint8_t *data = (uint8_t *)ri->ri_optfont.data;
1527 1.63 macallan
1528 1.89 rin vert_mask = 0xc0U >> ((ri->ri_font->fontwidth >> 1) - 1);
1529 1.89 rin hmask_left = 0xf0U << (4 - (ri->ri_font->fontwidth >> 1));
1530 1.88 rin hmask_right = hmask_left >> ((ri->ri_font->fontwidth + 1) >> 1);
1531 1.63 macallan mid = (ri->ri_font->fontheight + 1) >> 1;
1532 1.63 macallan
1533 1.63 macallan /* 0x00 would be empty anyway so don't bother */
1534 1.63 macallan for (c = 1; c < 16; c++) {
1535 1.63 macallan data += ri->ri_font->fontheight;
1536 1.63 macallan if (c & 1) {
1537 1.63 macallan /* upper segment */
1538 1.63 macallan for (i = 0; i < mid; i++)
1539 1.63 macallan data[i] = vert_mask;
1540 1.63 macallan }
1541 1.63 macallan if (c & 4) {
1542 1.63 macallan /* lower segment */
1543 1.63 macallan for (i = mid; i < ri->ri_font->fontheight; i++)
1544 1.63 macallan data[i] = vert_mask;
1545 1.63 macallan }
1546 1.63 macallan if (c & 2) {
1547 1.63 macallan /* right segment */
1548 1.63 macallan i = ri->ri_font->fontheight >> 1;
1549 1.63 macallan data[mid - 1] |= hmask_right;
1550 1.63 macallan data[mid] |= hmask_right;
1551 1.63 macallan }
1552 1.63 macallan if (c & 8) {
1553 1.63 macallan /* left segment */
1554 1.63 macallan data[mid - 1] |= hmask_left;
1555 1.63 macallan data[mid] |= hmask_left;
1556 1.63 macallan }
1557 1.63 macallan }
1558 1.63 macallan }
1559 1.63 macallan
1560 1.63 macallan void
1561 1.63 macallan rasops_make_box_chars_32(struct rasops_info *ri)
1562 1.63 macallan {
1563 1.89 rin int c, i, mid;
1564 1.63 macallan uint32_t vert_mask, hmask_left, hmask_right;
1565 1.63 macallan uint32_t *data = (uint32_t *)ri->ri_optfont.data;
1566 1.63 macallan
1567 1.88 rin vert_mask = 0xc0000000U >> ((ri->ri_font->fontwidth >> 1) - 1);
1568 1.88 rin hmask_left = 0xffff0000U << (16 - (ri->ri_font->fontwidth >> 1));
1569 1.88 rin hmask_right = hmask_left >> ((ri->ri_font->fontwidth + 1) >> 1);
1570 1.63 macallan mid = (ri->ri_font->fontheight + 1) >> 1;
1571 1.63 macallan
1572 1.63 macallan /* 0x00 would be empty anyway so don't bother */
1573 1.63 macallan for (c = 1; c < 16; c++) {
1574 1.63 macallan data += ri->ri_font->fontheight;
1575 1.63 macallan if (c & 1) {
1576 1.63 macallan /* upper segment */
1577 1.63 macallan for (i = 0; i < mid; i++)
1578 1.63 macallan data[i] = vert_mask;
1579 1.63 macallan }
1580 1.63 macallan if (c & 4) {
1581 1.63 macallan /* lower segment */
1582 1.63 macallan for (i = mid; i < ri->ri_font->fontheight; i++)
1583 1.63 macallan data[i] = vert_mask;
1584 1.63 macallan }
1585 1.63 macallan if (c & 2) {
1586 1.63 macallan /* right segment */
1587 1.63 macallan i = ri->ri_font->fontheight >> 1;
1588 1.63 macallan data[mid - 1] |= hmask_right;
1589 1.63 macallan data[mid] |= hmask_right;
1590 1.63 macallan }
1591 1.63 macallan if (c & 8) {
1592 1.63 macallan /* left segment */
1593 1.63 macallan data[mid - 1] |= hmask_left;
1594 1.63 macallan data[mid] |= hmask_left;
1595 1.63 macallan }
1596 1.63 macallan }
1597 1.63 macallan }
1598 1.67 macallan
1599 1.67 macallan void
1600 1.67 macallan rasops_make_box_chars_alpha(struct rasops_info *ri)
1601 1.67 macallan {
1602 1.89 rin int c, i, hmid, vmid, wi, he;
1603 1.67 macallan uint8_t *data = (uint8_t *)ri->ri_optfont.data;
1604 1.67 macallan uint8_t *ddata;
1605 1.67 macallan
1606 1.89 rin he = ri->ri_font->fontheight;
1607 1.67 macallan wi = ri->ri_font->fontwidth;
1608 1.67 macallan
1609 1.67 macallan vmid = (he + 1) >> 1;
1610 1.67 macallan hmid = (wi + 1) >> 1;
1611 1.67 macallan
1612 1.67 macallan /* 0x00 would be empty anyway so don't bother */
1613 1.67 macallan for (c = 1; c < 16; c++) {
1614 1.67 macallan data += ri->ri_fontscale;
1615 1.67 macallan if (c & 1) {
1616 1.67 macallan /* upper segment */
1617 1.67 macallan ddata = data + hmid;
1618 1.67 macallan for (i = 0; i <= vmid; i++) {
1619 1.67 macallan *ddata = 0xff;
1620 1.67 macallan ddata += wi;
1621 1.67 macallan }
1622 1.67 macallan }
1623 1.67 macallan if (c & 4) {
1624 1.67 macallan /* lower segment */
1625 1.67 macallan ddata = data + wi * vmid + hmid;
1626 1.67 macallan for (i = vmid; i < he; i++) {
1627 1.67 macallan *ddata = 0xff;
1628 1.67 macallan ddata += wi;
1629 1.67 macallan }
1630 1.67 macallan }
1631 1.67 macallan if (c & 2) {
1632 1.67 macallan /* right segment */
1633 1.67 macallan ddata = data + wi * vmid + hmid;
1634 1.67 macallan for (i = hmid; i < wi; i++) {
1635 1.67 macallan *ddata = 0xff;
1636 1.67 macallan ddata++;
1637 1.67 macallan }
1638 1.67 macallan }
1639 1.67 macallan if (c & 8) {
1640 1.67 macallan /* left segment */
1641 1.67 macallan ddata = data + wi * vmid;
1642 1.67 macallan for (i = 0; i <= hmid; i++) {
1643 1.67 macallan *ddata = 0xff;
1644 1.67 macallan ddata++;
1645 1.67 macallan }
1646 1.67 macallan }
1647 1.67 macallan }
1648 1.67 macallan }
1649 1.75 macallan
1650 1.71 macallan /*
1651 1.71 macallan * Return a colour map appropriate for the given struct rasops_info in the
1652 1.71 macallan * same form used by rasops_cmap[]
1653 1.71 macallan * For now this is either a copy of rasops_cmap[] or an R3G3B2 map, it should
1654 1.71 macallan * probably be a linear ( or gamma corrected? ) ramp for higher depths.
1655 1.71 macallan */
1656 1.71 macallan int
1657 1.71 macallan rasops_get_cmap(struct rasops_info *ri, uint8_t *palette, size_t bytes)
1658 1.71 macallan {
1659 1.88 rin
1660 1.89 rin if ((ri->ri_depth == 8) && ((ri->ri_flg & RI_8BIT_IS_RGB) != 0)) {
1661 1.71 macallan /* generate an R3G3B2 palette */
1662 1.71 macallan int i, idx = 0;
1663 1.71 macallan uint8_t tmp;
1664 1.71 macallan
1665 1.71 macallan if (bytes < 768)
1666 1.71 macallan return EINVAL;
1667 1.71 macallan for (i = 0; i < 256; i++) {
1668 1.71 macallan tmp = i & 0xe0;
1669 1.71 macallan /*
1670 1.71 macallan * replicate bits so 0xe0 maps to a red value of 0xff
1671 1.71 macallan * in order to make white look actually white
1672 1.71 macallan */
1673 1.71 macallan tmp |= (tmp >> 3) | (tmp >> 6);
1674 1.71 macallan palette[idx] = tmp;
1675 1.71 macallan idx++;
1676 1.71 macallan
1677 1.71 macallan tmp = (i & 0x1c) << 3;
1678 1.71 macallan tmp |= (tmp >> 3) | (tmp >> 6);
1679 1.71 macallan palette[idx] = tmp;
1680 1.71 macallan idx++;
1681 1.71 macallan
1682 1.71 macallan tmp = (i & 0x03) << 6;
1683 1.71 macallan tmp |= tmp >> 2;
1684 1.71 macallan tmp |= tmp >> 4;
1685 1.71 macallan palette[idx] = tmp;
1686 1.71 macallan idx++;
1687 1.71 macallan }
1688 1.88 rin } else
1689 1.89 rin memcpy(palette, rasops_cmap, uimin(bytes, sizeof(rasops_cmap)));
1690 1.71 macallan return 0;
1691 1.71 macallan }
1692 1.103 rin
1693 1.103 rin #ifndef RASOPS_SMALL
1694 1.103 rin void
1695 1.103 rin rasops_allocstamp(struct rasops_info *ri, size_t len)
1696 1.103 rin {
1697 1.103 rin
1698 1.103 rin KASSERT(ri->ri_stamp == NULL);
1699 1.103 rin ri->ri_stamp_len = len;
1700 1.103 rin ri->ri_stamp = kmem_zalloc(len, KM_SLEEP);
1701 1.103 rin ri->ri_stamp_attr = 0;
1702 1.103 rin }
1703 1.103 rin #endif
1704