rasops.c revision 1.56.18.2 1 1.56.18.2 mjf /* $NetBSD: rasops.c,v 1.56.18.2 2007/07/28 20:28:58 mjf Exp $ */
2 1.56.18.2 mjf
3 1.56.18.2 mjf /*-
4 1.56.18.2 mjf * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.56.18.2 mjf * All rights reserved.
6 1.56.18.2 mjf *
7 1.56.18.2 mjf * This code is derived from software contributed to The NetBSD Foundation
8 1.56.18.2 mjf * by Andrew Doran.
9 1.56.18.2 mjf *
10 1.56.18.2 mjf * Redistribution and use in source and binary forms, with or without
11 1.56.18.2 mjf * modification, are permitted provided that the following conditions
12 1.56.18.2 mjf * are met:
13 1.56.18.2 mjf * 1. Redistributions of source code must retain the above copyright
14 1.56.18.2 mjf * notice, this list of conditions and the following disclaimer.
15 1.56.18.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
16 1.56.18.2 mjf * notice, this list of conditions and the following disclaimer in the
17 1.56.18.2 mjf * documentation and/or other materials provided with the distribution.
18 1.56.18.2 mjf * 3. All advertising materials mentioning features or use of this software
19 1.56.18.2 mjf * must display the following acknowledgement:
20 1.56.18.2 mjf * This product includes software developed by the NetBSD
21 1.56.18.2 mjf * Foundation, Inc. and its contributors.
22 1.56.18.2 mjf * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.56.18.2 mjf * contributors may be used to endorse or promote products derived
24 1.56.18.2 mjf * from this software without specific prior written permission.
25 1.56.18.2 mjf *
26 1.56.18.2 mjf * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.56.18.2 mjf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.56.18.2 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.56.18.2 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.56.18.2 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.56.18.2 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.56.18.2 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.56.18.2 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.56.18.2 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.56.18.2 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.56.18.2 mjf * POSSIBILITY OF SUCH DAMAGE.
37 1.56.18.2 mjf */
38 1.56.18.2 mjf
39 1.56.18.2 mjf #include <sys/cdefs.h>
40 1.56.18.2 mjf __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.56.18.2 2007/07/28 20:28:58 mjf Exp $");
41 1.56.18.2 mjf
42 1.56.18.2 mjf #include "opt_rasops.h"
43 1.56.18.2 mjf #include "rasops_glue.h"
44 1.56.18.2 mjf #include "opt_wsmsgattrs.h"
45 1.56.18.2 mjf
46 1.56.18.2 mjf #include <sys/param.h>
47 1.56.18.2 mjf #include <sys/systm.h>
48 1.56.18.2 mjf #include <sys/time.h>
49 1.56.18.2 mjf
50 1.56.18.2 mjf #include <sys/bswap.h>
51 1.56.18.2 mjf #include <machine/endian.h>
52 1.56.18.2 mjf
53 1.56.18.2 mjf #include <dev/wscons/wsdisplayvar.h>
54 1.56.18.2 mjf #include <dev/wscons/wsconsio.h>
55 1.56.18.2 mjf #include <dev/wsfont/wsfont.h>
56 1.56.18.2 mjf #include <dev/rasops/rasops.h>
57 1.56.18.2 mjf
58 1.56.18.2 mjf #ifndef _KERNEL
59 1.56.18.2 mjf #include <errno.h>
60 1.56.18.2 mjf #endif
61 1.56.18.2 mjf
62 1.56.18.2 mjf /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
63 1.56.18.2 mjf const u_char rasops_cmap[256*3] = {
64 1.56.18.2 mjf 0x00, 0x00, 0x00, /* black */
65 1.56.18.2 mjf 0x7f, 0x00, 0x00, /* red */
66 1.56.18.2 mjf 0x00, 0x7f, 0x00, /* green */
67 1.56.18.2 mjf 0x7f, 0x7f, 0x00, /* brown */
68 1.56.18.2 mjf 0x00, 0x00, 0x7f, /* blue */
69 1.56.18.2 mjf 0x7f, 0x00, 0x7f, /* magenta */
70 1.56.18.2 mjf 0x00, 0x7f, 0x7f, /* cyan */
71 1.56.18.2 mjf 0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
72 1.56.18.2 mjf
73 1.56.18.2 mjf 0x7f, 0x7f, 0x7f, /* black */
74 1.56.18.2 mjf 0xff, 0x00, 0x00, /* red */
75 1.56.18.2 mjf 0x00, 0xff, 0x00, /* green */
76 1.56.18.2 mjf 0xff, 0xff, 0x00, /* brown */
77 1.56.18.2 mjf 0x00, 0x00, 0xff, /* blue */
78 1.56.18.2 mjf 0xff, 0x00, 0xff, /* magenta */
79 1.56.18.2 mjf 0x00, 0xff, 0xff, /* cyan */
80 1.56.18.2 mjf 0xff, 0xff, 0xff, /* white */
81 1.56.18.2 mjf
82 1.56.18.2 mjf /*
83 1.56.18.2 mjf * For the cursor, we need at least the last (255th)
84 1.56.18.2 mjf * color to be white. Fill up white completely for
85 1.56.18.2 mjf * simplicity.
86 1.56.18.2 mjf */
87 1.56.18.2 mjf #define _CMWHITE 0xff, 0xff, 0xff,
88 1.56.18.2 mjf #define _CMWHITE16 _CMWHITE _CMWHITE _CMWHITE _CMWHITE \
89 1.56.18.2 mjf _CMWHITE _CMWHITE _CMWHITE _CMWHITE \
90 1.56.18.2 mjf _CMWHITE _CMWHITE _CMWHITE _CMWHITE \
91 1.56.18.2 mjf _CMWHITE _CMWHITE _CMWHITE _CMWHITE
92 1.56.18.2 mjf _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
93 1.56.18.2 mjf _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
94 1.56.18.2 mjf _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 /* but not the last one */
95 1.56.18.2 mjf #undef _CMWHITE16
96 1.56.18.2 mjf #undef _CMWHITE
97 1.56.18.2 mjf
98 1.56.18.2 mjf /*
99 1.56.18.2 mjf * For the cursor the fg/bg indices are bit inverted, so
100 1.56.18.2 mjf * provide complimentary colors in the upper 16 entries.
101 1.56.18.2 mjf */
102 1.56.18.2 mjf 0x7f, 0x7f, 0x7f, /* black */
103 1.56.18.2 mjf 0xff, 0x00, 0x00, /* red */
104 1.56.18.2 mjf 0x00, 0xff, 0x00, /* green */
105 1.56.18.2 mjf 0xff, 0xff, 0x00, /* brown */
106 1.56.18.2 mjf 0x00, 0x00, 0xff, /* blue */
107 1.56.18.2 mjf 0xff, 0x00, 0xff, /* magenta */
108 1.56.18.2 mjf 0x00, 0xff, 0xff, /* cyan */
109 1.56.18.2 mjf 0xff, 0xff, 0xff, /* white */
110 1.56.18.2 mjf
111 1.56.18.2 mjf 0x00, 0x00, 0x00, /* black */
112 1.56.18.2 mjf 0x7f, 0x00, 0x00, /* red */
113 1.56.18.2 mjf 0x00, 0x7f, 0x00, /* green */
114 1.56.18.2 mjf 0x7f, 0x7f, 0x00, /* brown */
115 1.56.18.2 mjf 0x00, 0x00, 0x7f, /* blue */
116 1.56.18.2 mjf 0x7f, 0x00, 0x7f, /* magenta */
117 1.56.18.2 mjf 0x00, 0x7f, 0x7f, /* cyan */
118 1.56.18.2 mjf 0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
119 1.56.18.2 mjf };
120 1.56.18.2 mjf
121 1.56.18.2 mjf /* True if color is gray */
122 1.56.18.2 mjf const u_char rasops_isgray[16] = {
123 1.56.18.2 mjf 1, 0, 0, 0,
124 1.56.18.2 mjf 0, 0, 0, 1,
125 1.56.18.2 mjf 1, 0, 0, 0,
126 1.56.18.2 mjf 0, 0, 0, 1
127 1.56.18.2 mjf };
128 1.56.18.2 mjf
129 1.56.18.2 mjf /* Generic functions */
130 1.56.18.2 mjf static void rasops_copyrows(void *, int, int, int);
131 1.56.18.2 mjf static int rasops_mapchar(void *, int, u_int *);
132 1.56.18.2 mjf static void rasops_cursor(void *, int, int, int);
133 1.56.18.2 mjf static int rasops_allocattr_color(void *, int, int, int, long *);
134 1.56.18.2 mjf static int rasops_allocattr_mono(void *, int, int, int, long *);
135 1.56.18.2 mjf static void rasops_do_cursor(struct rasops_info *);
136 1.56.18.2 mjf static void rasops_init_devcmap(struct rasops_info *);
137 1.56.18.2 mjf
138 1.56.18.2 mjf #if NRASOPS_ROTATION > 0
139 1.56.18.2 mjf static void rasops_copychar(void *, int, int, int, int);
140 1.56.18.2 mjf static void rasops_copycols_rotated(void *, int, int, int, int);
141 1.56.18.2 mjf static void rasops_copyrows_rotated(void *, int, int, int);
142 1.56.18.2 mjf static void rasops_erasecols_rotated(void *, int, int, int, long);
143 1.56.18.2 mjf static void rasops_eraserows_rotated(void *, int, int, long);
144 1.56.18.2 mjf static void rasops_putchar_rotated(void *, int, int, u_int, long);
145 1.56.18.2 mjf static void rasops_rotate_font(int *);
146 1.56.18.2 mjf
147 1.56.18.2 mjf /*
148 1.56.18.2 mjf * List of all rotated fonts
149 1.56.18.2 mjf */
150 1.56.18.2 mjf SLIST_HEAD(, rotatedfont) rotatedfonts = SLIST_HEAD_INITIALIZER(rotatedfonts);
151 1.56.18.2 mjf struct rotatedfont {
152 1.56.18.2 mjf SLIST_ENTRY(rotatedfont) rf_next;
153 1.56.18.2 mjf int rf_cookie;
154 1.56.18.2 mjf int rf_rotated;
155 1.56.18.2 mjf };
156 1.56.18.2 mjf #endif /* NRASOPS_ROTATION > 0 */
157 1.56.18.2 mjf
158 1.56.18.2 mjf /*
159 1.56.18.2 mjf * Initialize a 'rasops_info' descriptor.
160 1.56.18.2 mjf */
161 1.56.18.2 mjf int
162 1.56.18.2 mjf rasops_init(ri, wantrows, wantcols)
163 1.56.18.2 mjf struct rasops_info *ri;
164 1.56.18.2 mjf int wantrows, wantcols;
165 1.56.18.2 mjf {
166 1.56.18.2 mjf
167 1.56.18.2 mjf #ifdef _KERNEL
168 1.56.18.2 mjf /* Select a font if the caller doesn't care */
169 1.56.18.2 mjf if (ri->ri_font == NULL) {
170 1.56.18.2 mjf int cookie;
171 1.56.18.2 mjf
172 1.56.18.2 mjf wsfont_init();
173 1.56.18.2 mjf
174 1.56.18.2 mjf /* Want 8 pixel wide, don't care about aestethics */
175 1.56.18.2 mjf cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
176 1.56.18.2 mjf WSDISPLAY_FONTORDER_L2R);
177 1.56.18.2 mjf if (cookie <= 0)
178 1.56.18.2 mjf cookie = wsfont_find(NULL, 0, 0, 0,
179 1.56.18.2 mjf WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
180 1.56.18.2 mjf
181 1.56.18.2 mjf if (cookie <= 0) {
182 1.56.18.2 mjf printf("rasops_init: font table is empty\n");
183 1.56.18.2 mjf return (-1);
184 1.56.18.2 mjf }
185 1.56.18.2 mjf
186 1.56.18.2 mjf #if NRASOPS_ROTATION > 0
187 1.56.18.2 mjf /*
188 1.56.18.2 mjf * Pick the rotated version of this font. This will create it
189 1.56.18.2 mjf * if necessary.
190 1.56.18.2 mjf */
191 1.56.18.2 mjf if (ri->ri_flg & RI_ROTATE_CW)
192 1.56.18.2 mjf rasops_rotate_font(&cookie);
193 1.56.18.2 mjf #endif
194 1.56.18.2 mjf
195 1.56.18.2 mjf if (wsfont_lock(cookie, &ri->ri_font)) {
196 1.56.18.2 mjf printf("rasops_init: couldn't lock font\n");
197 1.56.18.2 mjf return (-1);
198 1.56.18.2 mjf }
199 1.56.18.2 mjf
200 1.56.18.2 mjf ri->ri_wsfcookie = cookie;
201 1.56.18.2 mjf }
202 1.56.18.2 mjf #endif
203 1.56.18.2 mjf
204 1.56.18.2 mjf /* This should never happen in reality... */
205 1.56.18.2 mjf #ifdef DEBUG
206 1.56.18.2 mjf if ((long)ri->ri_bits & 3) {
207 1.56.18.2 mjf printf("rasops_init: bits not aligned on 32-bit boundary\n");
208 1.56.18.2 mjf return (-1);
209 1.56.18.2 mjf }
210 1.56.18.2 mjf
211 1.56.18.2 mjf if ((int)ri->ri_stride & 3) {
212 1.56.18.2 mjf printf("rasops_init: stride not aligned on 32-bit boundary\n");
213 1.56.18.2 mjf return (-1);
214 1.56.18.2 mjf }
215 1.56.18.2 mjf #endif
216 1.56.18.2 mjf
217 1.56.18.2 mjf if (rasops_reconfig(ri, wantrows, wantcols))
218 1.56.18.2 mjf return (-1);
219 1.56.18.2 mjf
220 1.56.18.2 mjf rasops_init_devcmap(ri);
221 1.56.18.2 mjf return (0);
222 1.56.18.2 mjf }
223 1.56.18.2 mjf
224 1.56.18.2 mjf /*
225 1.56.18.2 mjf * Reconfigure (because parameters have changed in some way).
226 1.56.18.2 mjf */
227 1.56.18.2 mjf int
228 1.56.18.2 mjf rasops_reconfig(ri, wantrows, wantcols)
229 1.56.18.2 mjf struct rasops_info *ri;
230 1.56.18.2 mjf int wantrows, wantcols;
231 1.56.18.2 mjf {
232 1.56.18.2 mjf int bpp, s;
233 1.56.18.2 mjf
234 1.56.18.2 mjf s = splhigh();
235 1.56.18.2 mjf
236 1.56.18.2 mjf if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4)
237 1.56.18.2 mjf panic("rasops_init: fontwidth assumptions botched!");
238 1.56.18.2 mjf
239 1.56.18.2 mjf /* Need this to frob the setup below */
240 1.56.18.2 mjf bpp = (ri->ri_depth == 15 ? 16 : ri->ri_depth);
241 1.56.18.2 mjf
242 1.56.18.2 mjf if ((ri->ri_flg & RI_CFGDONE) != 0)
243 1.56.18.2 mjf ri->ri_bits = ri->ri_origbits;
244 1.56.18.2 mjf
245 1.56.18.2 mjf /* Don't care if the caller wants a hideously small console */
246 1.56.18.2 mjf if (wantrows < 10)
247 1.56.18.2 mjf wantrows = 10;
248 1.56.18.2 mjf
249 1.56.18.2 mjf if (wantcols < 20)
250 1.56.18.2 mjf wantcols = 20;
251 1.56.18.2 mjf
252 1.56.18.2 mjf /* Now constrain what they get */
253 1.56.18.2 mjf ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
254 1.56.18.2 mjf ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
255 1.56.18.2 mjf
256 1.56.18.2 mjf if (ri->ri_emuwidth > ri->ri_width)
257 1.56.18.2 mjf ri->ri_emuwidth = ri->ri_width;
258 1.56.18.2 mjf
259 1.56.18.2 mjf if (ri->ri_emuheight > ri->ri_height)
260 1.56.18.2 mjf ri->ri_emuheight = ri->ri_height;
261 1.56.18.2 mjf
262 1.56.18.2 mjf /* Reduce width until aligned on a 32-bit boundary */
263 1.56.18.2 mjf while ((ri->ri_emuwidth * bpp & 31) != 0)
264 1.56.18.2 mjf ri->ri_emuwidth--;
265 1.56.18.2 mjf
266 1.56.18.2 mjf #if NRASOPS_ROTATION > 0
267 1.56.18.2 mjf if (ri->ri_flg & RI_ROTATE_CW) {
268 1.56.18.2 mjf ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
269 1.56.18.2 mjf ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
270 1.56.18.2 mjf } else
271 1.56.18.2 mjf #endif
272 1.56.18.2 mjf {
273 1.56.18.2 mjf
274 1.56.18.2 mjf ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
275 1.56.18.2 mjf ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
276 1.56.18.2 mjf }
277 1.56.18.2 mjf ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
278 1.56.18.2 mjf ri->ri_delta = ri->ri_stride - ri->ri_emustride;
279 1.56.18.2 mjf ri->ri_ccol = 0;
280 1.56.18.2 mjf ri->ri_crow = 0;
281 1.56.18.2 mjf ri->ri_pelbytes = bpp >> 3;
282 1.56.18.2 mjf
283 1.56.18.2 mjf ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
284 1.56.18.2 mjf ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
285 1.56.18.2 mjf ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
286 1.56.18.2 mjf
287 1.56.18.2 mjf #ifdef DEBUG
288 1.56.18.2 mjf if ((ri->ri_delta & 3) != 0)
289 1.56.18.2 mjf panic("rasops_init: ri_delta not aligned on 32-bit boundary");
290 1.56.18.2 mjf #endif
291 1.56.18.2 mjf /* Clear the entire display */
292 1.56.18.2 mjf if ((ri->ri_flg & RI_CLEAR) != 0)
293 1.56.18.2 mjf memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
294 1.56.18.2 mjf
295 1.56.18.2 mjf /* Now centre our window if needs be */
296 1.56.18.2 mjf ri->ri_origbits = ri->ri_bits;
297 1.56.18.2 mjf
298 1.56.18.2 mjf if ((ri->ri_flg & RI_CENTER) != 0) {
299 1.56.18.2 mjf ri->ri_bits += (((ri->ri_width * bpp >> 3) -
300 1.56.18.2 mjf ri->ri_emustride) >> 1) & ~3;
301 1.56.18.2 mjf ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
302 1.56.18.2 mjf ri->ri_stride;
303 1.56.18.2 mjf
304 1.56.18.2 mjf ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits)
305 1.56.18.2 mjf / ri->ri_stride;
306 1.56.18.2 mjf ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits)
307 1.56.18.2 mjf % ri->ri_stride) * 8 / bpp);
308 1.56.18.2 mjf } else
309 1.56.18.2 mjf ri->ri_xorigin = ri->ri_yorigin = 0;
310 1.56.18.2 mjf
311 1.56.18.2 mjf /*
312 1.56.18.2 mjf * Fill in defaults for operations set. XXX this nukes private
313 1.56.18.2 mjf * routines used by accelerated fb drivers.
314 1.56.18.2 mjf */
315 1.56.18.2 mjf ri->ri_ops.mapchar = rasops_mapchar;
316 1.56.18.2 mjf ri->ri_ops.copyrows = rasops_copyrows;
317 1.56.18.2 mjf ri->ri_ops.copycols = rasops_copycols;
318 1.56.18.2 mjf ri->ri_ops.erasecols = rasops_erasecols;
319 1.56.18.2 mjf ri->ri_ops.eraserows = rasops_eraserows;
320 1.56.18.2 mjf ri->ri_ops.cursor = rasops_cursor;
321 1.56.18.2 mjf ri->ri_do_cursor = rasops_do_cursor;
322 1.56.18.2 mjf
323 1.56.18.2 mjf if (ri->ri_depth < 8 || (ri->ri_flg & RI_FORCEMONO) != 0) {
324 1.56.18.2 mjf ri->ri_ops.allocattr = rasops_allocattr_mono;
325 1.56.18.2 mjf ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_REVERSE;
326 1.56.18.2 mjf } else {
327 1.56.18.2 mjf ri->ri_ops.allocattr = rasops_allocattr_color;
328 1.56.18.2 mjf ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
329 1.56.18.2 mjf WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
330 1.56.18.2 mjf }
331 1.56.18.2 mjf
332 1.56.18.2 mjf switch (ri->ri_depth) {
333 1.56.18.2 mjf #if NRASOPS1 > 0
334 1.56.18.2 mjf case 1:
335 1.56.18.2 mjf rasops1_init(ri);
336 1.56.18.2 mjf break;
337 1.56.18.2 mjf #endif
338 1.56.18.2 mjf #if NRASOPS2 > 0
339 1.56.18.2 mjf case 2:
340 1.56.18.2 mjf rasops2_init(ri);
341 1.56.18.2 mjf break;
342 1.56.18.2 mjf #endif
343 1.56.18.2 mjf #if NRASOPS4 > 0
344 1.56.18.2 mjf case 4:
345 1.56.18.2 mjf rasops4_init(ri);
346 1.56.18.2 mjf break;
347 1.56.18.2 mjf #endif
348 1.56.18.2 mjf #if NRASOPS8 > 0
349 1.56.18.2 mjf case 8:
350 1.56.18.2 mjf rasops8_init(ri);
351 1.56.18.2 mjf break;
352 1.56.18.2 mjf #endif
353 1.56.18.2 mjf #if NRASOPS15 > 0 || NRASOPS16 > 0
354 1.56.18.2 mjf case 15:
355 1.56.18.2 mjf case 16:
356 1.56.18.2 mjf rasops15_init(ri);
357 1.56.18.2 mjf break;
358 1.56.18.2 mjf #endif
359 1.56.18.2 mjf #if NRASOPS24 > 0
360 1.56.18.2 mjf case 24:
361 1.56.18.2 mjf rasops24_init(ri);
362 1.56.18.2 mjf break;
363 1.56.18.2 mjf #endif
364 1.56.18.2 mjf #if NRASOPS32 > 0
365 1.56.18.2 mjf case 32:
366 1.56.18.2 mjf rasops32_init(ri);
367 1.56.18.2 mjf break;
368 1.56.18.2 mjf #endif
369 1.56.18.2 mjf default:
370 1.56.18.2 mjf ri->ri_flg &= ~RI_CFGDONE;
371 1.56.18.2 mjf splx(s);
372 1.56.18.2 mjf return (-1);
373 1.56.18.2 mjf }
374 1.56.18.2 mjf
375 1.56.18.2 mjf #if NRASOPS_ROTATION > 0
376 1.56.18.2 mjf if (ri->ri_flg & RI_ROTATE_CW) {
377 1.56.18.2 mjf ri->ri_real_ops = ri->ri_ops;
378 1.56.18.2 mjf ri->ri_ops.copycols = rasops_copycols_rotated;
379 1.56.18.2 mjf ri->ri_ops.copyrows = rasops_copyrows_rotated;
380 1.56.18.2 mjf ri->ri_ops.erasecols = rasops_erasecols_rotated;
381 1.56.18.2 mjf ri->ri_ops.eraserows = rasops_eraserows_rotated;
382 1.56.18.2 mjf ri->ri_ops.putchar = rasops_putchar_rotated;
383 1.56.18.2 mjf }
384 1.56.18.2 mjf #endif
385 1.56.18.2 mjf
386 1.56.18.2 mjf ri->ri_flg |= RI_CFGDONE;
387 1.56.18.2 mjf splx(s);
388 1.56.18.2 mjf return (0);
389 1.56.18.2 mjf }
390 1.56.18.2 mjf
391 1.56.18.2 mjf /*
392 1.56.18.2 mjf * Map a character.
393 1.56.18.2 mjf */
394 1.56.18.2 mjf static int
395 1.56.18.2 mjf rasops_mapchar(cookie, c, cp)
396 1.56.18.2 mjf void *cookie;
397 1.56.18.2 mjf int c;
398 1.56.18.2 mjf u_int *cp;
399 1.56.18.2 mjf {
400 1.56.18.2 mjf struct rasops_info *ri;
401 1.56.18.2 mjf
402 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
403 1.56.18.2 mjf
404 1.56.18.2 mjf #ifdef DIAGNOSTIC
405 1.56.18.2 mjf if (ri->ri_font == NULL)
406 1.56.18.2 mjf panic("rasops_mapchar: no font selected");
407 1.56.18.2 mjf #endif
408 1.56.18.2 mjf
409 1.56.18.2 mjf if (ri->ri_font->encoding != WSDISPLAY_FONTENC_ISO) {
410 1.56.18.2 mjf if ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) {
411 1.56.18.2 mjf *cp = ' ';
412 1.56.18.2 mjf return (0);
413 1.56.18.2 mjf
414 1.56.18.2 mjf }
415 1.56.18.2 mjf }
416 1.56.18.2 mjf
417 1.56.18.2 mjf if (c < ri->ri_font->firstchar) {
418 1.56.18.2 mjf *cp = ' ';
419 1.56.18.2 mjf return (0);
420 1.56.18.2 mjf }
421 1.56.18.2 mjf
422 1.56.18.2 mjf if (c - ri->ri_font->firstchar >= ri->ri_font->numchars) {
423 1.56.18.2 mjf *cp = ' ';
424 1.56.18.2 mjf return (0);
425 1.56.18.2 mjf }
426 1.56.18.2 mjf
427 1.56.18.2 mjf *cp = c;
428 1.56.18.2 mjf return (5);
429 1.56.18.2 mjf }
430 1.56.18.2 mjf
431 1.56.18.2 mjf /*
432 1.56.18.2 mjf * Allocate a color attribute.
433 1.56.18.2 mjf */
434 1.56.18.2 mjf static int
435 1.56.18.2 mjf rasops_allocattr_color(void *cookie, int fg, int bg, int flg,
436 1.56.18.2 mjf long *attr)
437 1.56.18.2 mjf {
438 1.56.18.2 mjf int swap;
439 1.56.18.2 mjf
440 1.56.18.2 mjf if (__predict_false((unsigned int)fg >= sizeof(rasops_isgray) ||
441 1.56.18.2 mjf (unsigned int)bg >= sizeof(rasops_isgray)))
442 1.56.18.2 mjf return (EINVAL);
443 1.56.18.2 mjf
444 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
445 1.56.18.2 mjf fg &= 7;
446 1.56.18.2 mjf bg &= 7;
447 1.56.18.2 mjf #endif
448 1.56.18.2 mjf if ((flg & WSATTR_BLINK) != 0)
449 1.56.18.2 mjf return (EINVAL);
450 1.56.18.2 mjf
451 1.56.18.2 mjf if ((flg & WSATTR_WSCOLORS) == 0) {
452 1.56.18.2 mjf #ifdef WS_DEFAULT_FG
453 1.56.18.2 mjf fg = WS_DEFAULT_FG;
454 1.56.18.2 mjf #else
455 1.56.18.2 mjf fg = WSCOL_WHITE;
456 1.56.18.2 mjf #endif
457 1.56.18.2 mjf #ifdef WS_DEFAULT_BG
458 1.56.18.2 mjf bg = WS_DEFAULT_BG;
459 1.56.18.2 mjf #else
460 1.56.18.2 mjf bg = WSCOL_BLACK;
461 1.56.18.2 mjf #endif
462 1.56.18.2 mjf }
463 1.56.18.2 mjf
464 1.56.18.2 mjf if ((flg & WSATTR_REVERSE) != 0) {
465 1.56.18.2 mjf swap = fg;
466 1.56.18.2 mjf fg = bg;
467 1.56.18.2 mjf bg = swap;
468 1.56.18.2 mjf }
469 1.56.18.2 mjf
470 1.56.18.2 mjf if ((flg & WSATTR_HILIT) != 0)
471 1.56.18.2 mjf fg += 8;
472 1.56.18.2 mjf
473 1.56.18.2 mjf flg = ((flg & WSATTR_UNDERLINE) ? 1 : 0);
474 1.56.18.2 mjf
475 1.56.18.2 mjf if (rasops_isgray[fg])
476 1.56.18.2 mjf flg |= 2;
477 1.56.18.2 mjf
478 1.56.18.2 mjf if (rasops_isgray[bg])
479 1.56.18.2 mjf flg |= 4;
480 1.56.18.2 mjf
481 1.56.18.2 mjf *attr = (bg << 16) | (fg << 24) | flg;
482 1.56.18.2 mjf return (0);
483 1.56.18.2 mjf }
484 1.56.18.2 mjf
485 1.56.18.2 mjf /*
486 1.56.18.2 mjf * Allocate a mono attribute.
487 1.56.18.2 mjf */
488 1.56.18.2 mjf static int
489 1.56.18.2 mjf rasops_allocattr_mono(void *cookie, int fg, int bg, int flg,
490 1.56.18.2 mjf long *attr)
491 1.56.18.2 mjf {
492 1.56.18.2 mjf int swap;
493 1.56.18.2 mjf
494 1.56.18.2 mjf if ((flg & (WSATTR_BLINK | WSATTR_HILIT | WSATTR_WSCOLORS)) != 0)
495 1.56.18.2 mjf return (EINVAL);
496 1.56.18.2 mjf
497 1.56.18.2 mjf fg = 1;
498 1.56.18.2 mjf bg = 0;
499 1.56.18.2 mjf
500 1.56.18.2 mjf if ((flg & WSATTR_REVERSE) != 0) {
501 1.56.18.2 mjf swap = fg;
502 1.56.18.2 mjf fg = bg;
503 1.56.18.2 mjf bg = swap;
504 1.56.18.2 mjf }
505 1.56.18.2 mjf
506 1.56.18.2 mjf *attr = (bg << 16) | (fg << 24) | ((flg & WSATTR_UNDERLINE) ? 7 : 6);
507 1.56.18.2 mjf return (0);
508 1.56.18.2 mjf }
509 1.56.18.2 mjf
510 1.56.18.2 mjf /*
511 1.56.18.2 mjf * Copy rows.
512 1.56.18.2 mjf */
513 1.56.18.2 mjf static void
514 1.56.18.2 mjf rasops_copyrows(cookie, src, dst, num)
515 1.56.18.2 mjf void *cookie;
516 1.56.18.2 mjf int src, dst, num;
517 1.56.18.2 mjf {
518 1.56.18.2 mjf int32_t *sp, *dp, *hp, *srp, *drp, *hrp;
519 1.56.18.2 mjf struct rasops_info *ri;
520 1.56.18.2 mjf int n8, n1, cnt, delta;
521 1.56.18.2 mjf
522 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
523 1.56.18.2 mjf hp = hrp = NULL;
524 1.56.18.2 mjf
525 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
526 1.56.18.2 mjf if (dst == src)
527 1.56.18.2 mjf return;
528 1.56.18.2 mjf
529 1.56.18.2 mjf if (src < 0) {
530 1.56.18.2 mjf num += src;
531 1.56.18.2 mjf src = 0;
532 1.56.18.2 mjf }
533 1.56.18.2 mjf
534 1.56.18.2 mjf if ((src + num) > ri->ri_rows)
535 1.56.18.2 mjf num = ri->ri_rows - src;
536 1.56.18.2 mjf
537 1.56.18.2 mjf if (dst < 0) {
538 1.56.18.2 mjf num += dst;
539 1.56.18.2 mjf dst = 0;
540 1.56.18.2 mjf }
541 1.56.18.2 mjf
542 1.56.18.2 mjf if ((dst + num) > ri->ri_rows)
543 1.56.18.2 mjf num = ri->ri_rows - dst;
544 1.56.18.2 mjf
545 1.56.18.2 mjf if (num <= 0)
546 1.56.18.2 mjf return;
547 1.56.18.2 mjf #endif
548 1.56.18.2 mjf
549 1.56.18.2 mjf num *= ri->ri_font->fontheight;
550 1.56.18.2 mjf n8 = ri->ri_emustride >> 5;
551 1.56.18.2 mjf n1 = (ri->ri_emustride >> 2) & 7;
552 1.56.18.2 mjf
553 1.56.18.2 mjf if (dst < src) {
554 1.56.18.2 mjf srp = (int32_t *)(ri->ri_bits + src * ri->ri_yscale);
555 1.56.18.2 mjf drp = (int32_t *)(ri->ri_bits + dst * ri->ri_yscale);
556 1.56.18.2 mjf if (ri->ri_hwbits)
557 1.56.18.2 mjf hrp = (int32_t *)(ri->ri_hwbits + dst *
558 1.56.18.2 mjf ri->ri_yscale);
559 1.56.18.2 mjf delta = ri->ri_stride;
560 1.56.18.2 mjf } else {
561 1.56.18.2 mjf src = ri->ri_font->fontheight * src + num - 1;
562 1.56.18.2 mjf dst = ri->ri_font->fontheight * dst + num - 1;
563 1.56.18.2 mjf srp = (int32_t *)(ri->ri_bits + src * ri->ri_stride);
564 1.56.18.2 mjf drp = (int32_t *)(ri->ri_bits + dst * ri->ri_stride);
565 1.56.18.2 mjf if (ri->ri_hwbits)
566 1.56.18.2 mjf hrp = (int32_t *)(ri->ri_hwbits + dst *
567 1.56.18.2 mjf ri->ri_stride);
568 1.56.18.2 mjf
569 1.56.18.2 mjf delta = -ri->ri_stride;
570 1.56.18.2 mjf }
571 1.56.18.2 mjf
572 1.56.18.2 mjf while (num--) {
573 1.56.18.2 mjf dp = drp;
574 1.56.18.2 mjf sp = srp;
575 1.56.18.2 mjf if (ri->ri_hwbits)
576 1.56.18.2 mjf hp = hrp;
577 1.56.18.2 mjf
578 1.56.18.2 mjf DELTA(drp, delta, int32_t *);
579 1.56.18.2 mjf DELTA(srp, delta, int32_t *);
580 1.56.18.2 mjf if (ri->ri_hwbits)
581 1.56.18.2 mjf DELTA(hrp, delta, int32_t *);
582 1.56.18.2 mjf
583 1.56.18.2 mjf for (cnt = n8; cnt; cnt--) {
584 1.56.18.2 mjf dp[0] = sp[0];
585 1.56.18.2 mjf dp[1] = sp[1];
586 1.56.18.2 mjf dp[2] = sp[2];
587 1.56.18.2 mjf dp[3] = sp[3];
588 1.56.18.2 mjf dp[4] = sp[4];
589 1.56.18.2 mjf dp[5] = sp[5];
590 1.56.18.2 mjf dp[6] = sp[6];
591 1.56.18.2 mjf dp[7] = sp[7];
592 1.56.18.2 mjf dp += 8;
593 1.56.18.2 mjf sp += 8;
594 1.56.18.2 mjf }
595 1.56.18.2 mjf if (ri->ri_hwbits) {
596 1.56.18.2 mjf sp -= (8 * n8);
597 1.56.18.2 mjf for (cnt = n8; cnt; cnt--) {
598 1.56.18.2 mjf hp[0] = sp[0];
599 1.56.18.2 mjf hp[1] = sp[1];
600 1.56.18.2 mjf hp[2] = sp[2];
601 1.56.18.2 mjf hp[3] = sp[3];
602 1.56.18.2 mjf hp[4] = sp[4];
603 1.56.18.2 mjf hp[5] = sp[5];
604 1.56.18.2 mjf hp[6] = sp[6];
605 1.56.18.2 mjf hp[7] = sp[7];
606 1.56.18.2 mjf hp += 8;
607 1.56.18.2 mjf sp += 8;
608 1.56.18.2 mjf }
609 1.56.18.2 mjf }
610 1.56.18.2 mjf
611 1.56.18.2 mjf for (cnt = n1; cnt; cnt--) {
612 1.56.18.2 mjf *dp++ = *sp++;
613 1.56.18.2 mjf if (ri->ri_hwbits)
614 1.56.18.2 mjf *hp++ = *(sp - 1);
615 1.56.18.2 mjf }
616 1.56.18.2 mjf }
617 1.56.18.2 mjf }
618 1.56.18.2 mjf
619 1.56.18.2 mjf /*
620 1.56.18.2 mjf * Copy columns. This is slow, and hard to optimize due to alignment,
621 1.56.18.2 mjf * and the fact that we have to copy both left->right and right->left.
622 1.56.18.2 mjf * We simply cop-out here and use memmove(), since it handles all of
623 1.56.18.2 mjf * these cases anyway.
624 1.56.18.2 mjf */
625 1.56.18.2 mjf void
626 1.56.18.2 mjf rasops_copycols(cookie, row, src, dst, num)
627 1.56.18.2 mjf void *cookie;
628 1.56.18.2 mjf int row, src, dst, num;
629 1.56.18.2 mjf {
630 1.56.18.2 mjf struct rasops_info *ri;
631 1.56.18.2 mjf u_char *sp, *dp, *hp;
632 1.56.18.2 mjf int height;
633 1.56.18.2 mjf
634 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
635 1.56.18.2 mjf hp = NULL;
636 1.56.18.2 mjf
637 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
638 1.56.18.2 mjf if (dst == src)
639 1.56.18.2 mjf return;
640 1.56.18.2 mjf
641 1.56.18.2 mjf /* Catches < 0 case too */
642 1.56.18.2 mjf if ((unsigned)row >= (unsigned)ri->ri_rows)
643 1.56.18.2 mjf return;
644 1.56.18.2 mjf
645 1.56.18.2 mjf if (src < 0) {
646 1.56.18.2 mjf num += src;
647 1.56.18.2 mjf src = 0;
648 1.56.18.2 mjf }
649 1.56.18.2 mjf
650 1.56.18.2 mjf if ((src + num) > ri->ri_cols)
651 1.56.18.2 mjf num = ri->ri_cols - src;
652 1.56.18.2 mjf
653 1.56.18.2 mjf if (dst < 0) {
654 1.56.18.2 mjf num += dst;
655 1.56.18.2 mjf dst = 0;
656 1.56.18.2 mjf }
657 1.56.18.2 mjf
658 1.56.18.2 mjf if ((dst + num) > ri->ri_cols)
659 1.56.18.2 mjf num = ri->ri_cols - dst;
660 1.56.18.2 mjf
661 1.56.18.2 mjf if (num <= 0)
662 1.56.18.2 mjf return;
663 1.56.18.2 mjf #endif
664 1.56.18.2 mjf
665 1.56.18.2 mjf num *= ri->ri_xscale;
666 1.56.18.2 mjf row *= ri->ri_yscale;
667 1.56.18.2 mjf height = ri->ri_font->fontheight;
668 1.56.18.2 mjf
669 1.56.18.2 mjf sp = ri->ri_bits + row + src * ri->ri_xscale;
670 1.56.18.2 mjf dp = ri->ri_bits + row + dst * ri->ri_xscale;
671 1.56.18.2 mjf if (ri->ri_hwbits)
672 1.56.18.2 mjf hp = ri->ri_hwbits + row + dst * ri->ri_xscale;
673 1.56.18.2 mjf
674 1.56.18.2 mjf while (height--) {
675 1.56.18.2 mjf memmove(dp, sp, num);
676 1.56.18.2 mjf if (ri->ri_hwbits) {
677 1.56.18.2 mjf memcpy(hp, sp, num);
678 1.56.18.2 mjf hp += ri->ri_stride;
679 1.56.18.2 mjf }
680 1.56.18.2 mjf dp += ri->ri_stride;
681 1.56.18.2 mjf sp += ri->ri_stride;
682 1.56.18.2 mjf }
683 1.56.18.2 mjf }
684 1.56.18.2 mjf
685 1.56.18.2 mjf /*
686 1.56.18.2 mjf * Turn cursor off/on.
687 1.56.18.2 mjf */
688 1.56.18.2 mjf static void
689 1.56.18.2 mjf rasops_cursor(cookie, on, row, col)
690 1.56.18.2 mjf void *cookie;
691 1.56.18.2 mjf int on, row, col;
692 1.56.18.2 mjf {
693 1.56.18.2 mjf struct rasops_info *ri;
694 1.56.18.2 mjf
695 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
696 1.56.18.2 mjf
697 1.56.18.2 mjf /* Turn old cursor off */
698 1.56.18.2 mjf if ((ri->ri_flg & RI_CURSOR) != 0)
699 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
700 1.56.18.2 mjf if ((ri->ri_flg & RI_CURSORCLIP) == 0)
701 1.56.18.2 mjf #endif
702 1.56.18.2 mjf ri->ri_do_cursor(ri);
703 1.56.18.2 mjf
704 1.56.18.2 mjf /* Select new cursor */
705 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
706 1.56.18.2 mjf ri->ri_flg &= ~RI_CURSORCLIP;
707 1.56.18.2 mjf
708 1.56.18.2 mjf if (row < 0 || row >= ri->ri_rows)
709 1.56.18.2 mjf ri->ri_flg |= RI_CURSORCLIP;
710 1.56.18.2 mjf else if (col < 0 || col >= ri->ri_cols)
711 1.56.18.2 mjf ri->ri_flg |= RI_CURSORCLIP;
712 1.56.18.2 mjf #endif
713 1.56.18.2 mjf ri->ri_crow = row;
714 1.56.18.2 mjf ri->ri_ccol = col;
715 1.56.18.2 mjf
716 1.56.18.2 mjf if (on) {
717 1.56.18.2 mjf ri->ri_flg |= RI_CURSOR;
718 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
719 1.56.18.2 mjf if ((ri->ri_flg & RI_CURSORCLIP) == 0)
720 1.56.18.2 mjf #endif
721 1.56.18.2 mjf ri->ri_do_cursor(ri);
722 1.56.18.2 mjf } else
723 1.56.18.2 mjf ri->ri_flg &= ~RI_CURSOR;
724 1.56.18.2 mjf }
725 1.56.18.2 mjf
726 1.56.18.2 mjf /*
727 1.56.18.2 mjf * Make the device colormap
728 1.56.18.2 mjf */
729 1.56.18.2 mjf static void
730 1.56.18.2 mjf rasops_init_devcmap(ri)
731 1.56.18.2 mjf struct rasops_info *ri;
732 1.56.18.2 mjf {
733 1.56.18.2 mjf const u_char *p;
734 1.56.18.2 mjf int i, c;
735 1.56.18.2 mjf
736 1.56.18.2 mjf switch (ri->ri_depth) {
737 1.56.18.2 mjf case 1:
738 1.56.18.2 mjf ri->ri_devcmap[0] = 0;
739 1.56.18.2 mjf for (i = 1; i < 16; i++)
740 1.56.18.2 mjf ri->ri_devcmap[i] = -1;
741 1.56.18.2 mjf return;
742 1.56.18.2 mjf
743 1.56.18.2 mjf case 2:
744 1.56.18.2 mjf for (i = 1; i < 15; i++)
745 1.56.18.2 mjf ri->ri_devcmap[i] = 0xaaaaaaaa;
746 1.56.18.2 mjf
747 1.56.18.2 mjf ri->ri_devcmap[0] = 0;
748 1.56.18.2 mjf ri->ri_devcmap[8] = 0x55555555;
749 1.56.18.2 mjf ri->ri_devcmap[15] = -1;
750 1.56.18.2 mjf return;
751 1.56.18.2 mjf
752 1.56.18.2 mjf case 8:
753 1.56.18.2 mjf for (i = 0; i < 16; i++)
754 1.56.18.2 mjf ri->ri_devcmap[i] = i | (i<<8) | (i<<16) | (i<<24);
755 1.56.18.2 mjf return;
756 1.56.18.2 mjf }
757 1.56.18.2 mjf
758 1.56.18.2 mjf p = rasops_cmap;
759 1.56.18.2 mjf
760 1.56.18.2 mjf for (i = 0; i < 16; i++) {
761 1.56.18.2 mjf if (ri->ri_rnum <= 8)
762 1.56.18.2 mjf c = (*p >> (8 - ri->ri_rnum)) << ri->ri_rpos;
763 1.56.18.2 mjf else
764 1.56.18.2 mjf c = (*p << (ri->ri_rnum - 8)) << ri->ri_rpos;
765 1.56.18.2 mjf p++;
766 1.56.18.2 mjf
767 1.56.18.2 mjf if (ri->ri_gnum <= 8)
768 1.56.18.2 mjf c |= (*p >> (8 - ri->ri_gnum)) << ri->ri_gpos;
769 1.56.18.2 mjf else
770 1.56.18.2 mjf c |= (*p << (ri->ri_gnum - 8)) << ri->ri_gpos;
771 1.56.18.2 mjf p++;
772 1.56.18.2 mjf
773 1.56.18.2 mjf if (ri->ri_bnum <= 8)
774 1.56.18.2 mjf c |= (*p >> (8 - ri->ri_bnum)) << ri->ri_bpos;
775 1.56.18.2 mjf else
776 1.56.18.2 mjf c |= (*p << (ri->ri_bnum - 8)) << ri->ri_bpos;
777 1.56.18.2 mjf p++;
778 1.56.18.2 mjf
779 1.56.18.2 mjf /* Fill the word for generic routines, which want this */
780 1.56.18.2 mjf if (ri->ri_depth == 24)
781 1.56.18.2 mjf c = c | ((c & 0xff) << 24);
782 1.56.18.2 mjf else if (ri->ri_depth <= 16)
783 1.56.18.2 mjf c = c | (c << 16);
784 1.56.18.2 mjf
785 1.56.18.2 mjf /* 24bpp does bswap on the fly. {32,16,15}bpp do it here. */
786 1.56.18.2 mjf if ((ri->ri_flg & RI_BSWAP) == 0)
787 1.56.18.2 mjf ri->ri_devcmap[i] = c;
788 1.56.18.2 mjf else if (ri->ri_depth == 32)
789 1.56.18.2 mjf ri->ri_devcmap[i] = bswap32(c);
790 1.56.18.2 mjf else if (ri->ri_depth == 16 || ri->ri_depth == 15)
791 1.56.18.2 mjf ri->ri_devcmap[i] = bswap16(c);
792 1.56.18.2 mjf else
793 1.56.18.2 mjf ri->ri_devcmap[i] = c;
794 1.56.18.2 mjf }
795 1.56.18.2 mjf }
796 1.56.18.2 mjf
797 1.56.18.2 mjf /*
798 1.56.18.2 mjf * Unpack a rasops attribute
799 1.56.18.2 mjf */
800 1.56.18.2 mjf void
801 1.56.18.2 mjf rasops_unpack_attr(attr, fg, bg, underline)
802 1.56.18.2 mjf long attr;
803 1.56.18.2 mjf int *fg, *bg, *underline;
804 1.56.18.2 mjf {
805 1.56.18.2 mjf
806 1.56.18.2 mjf *fg = ((u_int)attr >> 24) & 0xf;
807 1.56.18.2 mjf *bg = ((u_int)attr >> 16) & 0xf;
808 1.56.18.2 mjf if (underline != NULL)
809 1.56.18.2 mjf *underline = (u_int)attr & 1;
810 1.56.18.2 mjf }
811 1.56.18.2 mjf
812 1.56.18.2 mjf /*
813 1.56.18.2 mjf * Erase rows. This isn't static, since 24-bpp uses it in special cases.
814 1.56.18.2 mjf */
815 1.56.18.2 mjf void
816 1.56.18.2 mjf rasops_eraserows(cookie, row, num, attr)
817 1.56.18.2 mjf void *cookie;
818 1.56.18.2 mjf int row, num;
819 1.56.18.2 mjf long attr;
820 1.56.18.2 mjf {
821 1.56.18.2 mjf struct rasops_info *ri;
822 1.56.18.2 mjf int np, nw, cnt, delta;
823 1.56.18.2 mjf int32_t *dp, *hp, clr;
824 1.56.18.2 mjf int i;
825 1.56.18.2 mjf
826 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
827 1.56.18.2 mjf hp = NULL;
828 1.56.18.2 mjf
829 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
830 1.56.18.2 mjf if (row < 0) {
831 1.56.18.2 mjf num += row;
832 1.56.18.2 mjf row = 0;
833 1.56.18.2 mjf }
834 1.56.18.2 mjf
835 1.56.18.2 mjf if ((row + num) > ri->ri_rows)
836 1.56.18.2 mjf num = ri->ri_rows - row;
837 1.56.18.2 mjf
838 1.56.18.2 mjf if (num <= 0)
839 1.56.18.2 mjf return;
840 1.56.18.2 mjf #endif
841 1.56.18.2 mjf
842 1.56.18.2 mjf clr = ri->ri_devcmap[(attr >> 16) & 0xf];
843 1.56.18.2 mjf
844 1.56.18.2 mjf /*
845 1.56.18.2 mjf * XXX The wsdisplay_emulops interface seems a little deficient in
846 1.56.18.2 mjf * that there is no way to clear the *entire* screen. We provide a
847 1.56.18.2 mjf * workaround here: if the entire console area is being cleared, and
848 1.56.18.2 mjf * the RI_FULLCLEAR flag is set, clear the entire display.
849 1.56.18.2 mjf */
850 1.56.18.2 mjf if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
851 1.56.18.2 mjf np = ri->ri_stride >> 5;
852 1.56.18.2 mjf nw = (ri->ri_stride >> 2) & 7;
853 1.56.18.2 mjf num = ri->ri_height;
854 1.56.18.2 mjf dp = (int32_t *)ri->ri_origbits;
855 1.56.18.2 mjf if (ri->ri_hwbits)
856 1.56.18.2 mjf hp = (int32_t *)ri->ri_hwbits;
857 1.56.18.2 mjf delta = 0;
858 1.56.18.2 mjf } else {
859 1.56.18.2 mjf np = ri->ri_emustride >> 5;
860 1.56.18.2 mjf nw = (ri->ri_emustride >> 2) & 7;
861 1.56.18.2 mjf num *= ri->ri_font->fontheight;
862 1.56.18.2 mjf dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
863 1.56.18.2 mjf if (ri->ri_hwbits)
864 1.56.18.2 mjf hp = (int32_t *)(ri->ri_hwbits + row *
865 1.56.18.2 mjf ri->ri_yscale);
866 1.56.18.2 mjf delta = ri->ri_delta;
867 1.56.18.2 mjf }
868 1.56.18.2 mjf
869 1.56.18.2 mjf while (num--) {
870 1.56.18.2 mjf for (cnt = np; cnt; cnt--) {
871 1.56.18.2 mjf for (i = 0; i < 8; i++) {
872 1.56.18.2 mjf dp[i] = clr;
873 1.56.18.2 mjf if (ri->ri_hwbits)
874 1.56.18.2 mjf hp[i] = clr;
875 1.56.18.2 mjf }
876 1.56.18.2 mjf dp += 8;
877 1.56.18.2 mjf if (ri->ri_hwbits)
878 1.56.18.2 mjf hp += 8;
879 1.56.18.2 mjf }
880 1.56.18.2 mjf
881 1.56.18.2 mjf for (cnt = nw; cnt; cnt--) {
882 1.56.18.2 mjf *(int32_t *)dp = clr;
883 1.56.18.2 mjf DELTA(dp, 4, int32_t *);
884 1.56.18.2 mjf if (ri->ri_hwbits) {
885 1.56.18.2 mjf *(int32_t *)hp = clr;
886 1.56.18.2 mjf DELTA(hp, 4, int32_t *);
887 1.56.18.2 mjf }
888 1.56.18.2 mjf }
889 1.56.18.2 mjf
890 1.56.18.2 mjf DELTA(dp, delta, int32_t *);
891 1.56.18.2 mjf if (ri->ri_hwbits)
892 1.56.18.2 mjf DELTA(hp, delta, int32_t *);
893 1.56.18.2 mjf }
894 1.56.18.2 mjf }
895 1.56.18.2 mjf
896 1.56.18.2 mjf /*
897 1.56.18.2 mjf * Actually turn the cursor on or off. This does the dirty work for
898 1.56.18.2 mjf * rasops_cursor().
899 1.56.18.2 mjf */
900 1.56.18.2 mjf static void
901 1.56.18.2 mjf rasops_do_cursor(ri)
902 1.56.18.2 mjf struct rasops_info *ri;
903 1.56.18.2 mjf {
904 1.56.18.2 mjf int full1, height, cnt, slop1, slop2, row, col;
905 1.56.18.2 mjf u_char *dp, *rp, *hrp, *hp;
906 1.56.18.2 mjf
907 1.56.18.2 mjf hrp = hp = NULL;
908 1.56.18.2 mjf
909 1.56.18.2 mjf #if NRASOPS_ROTATION > 0
910 1.56.18.2 mjf if (ri->ri_flg & RI_ROTATE_CW) {
911 1.56.18.2 mjf /* Rotate rows/columns */
912 1.56.18.2 mjf row = ri->ri_ccol;
913 1.56.18.2 mjf col = ri->ri_rows - ri->ri_crow - 1;
914 1.56.18.2 mjf } else
915 1.56.18.2 mjf #endif
916 1.56.18.2 mjf {
917 1.56.18.2 mjf row = ri->ri_crow;
918 1.56.18.2 mjf col = ri->ri_ccol;
919 1.56.18.2 mjf }
920 1.56.18.2 mjf
921 1.56.18.2 mjf rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
922 1.56.18.2 mjf if (ri->ri_hwbits)
923 1.56.18.2 mjf hrp = ri->ri_hwbits + row * ri->ri_yscale + col
924 1.56.18.2 mjf * ri->ri_xscale;
925 1.56.18.2 mjf height = ri->ri_font->fontheight;
926 1.56.18.2 mjf slop1 = (4 - ((long)rp & 3)) & 3;
927 1.56.18.2 mjf
928 1.56.18.2 mjf if (slop1 > ri->ri_xscale)
929 1.56.18.2 mjf slop1 = ri->ri_xscale;
930 1.56.18.2 mjf
931 1.56.18.2 mjf slop2 = (ri->ri_xscale - slop1) & 3;
932 1.56.18.2 mjf full1 = (ri->ri_xscale - slop1 - slop2) >> 2;
933 1.56.18.2 mjf
934 1.56.18.2 mjf if ((slop1 | slop2) == 0) {
935 1.56.18.2 mjf /* A common case */
936 1.56.18.2 mjf while (height--) {
937 1.56.18.2 mjf dp = rp;
938 1.56.18.2 mjf rp += ri->ri_stride;
939 1.56.18.2 mjf if (ri->ri_hwbits) {
940 1.56.18.2 mjf hp = hrp;
941 1.56.18.2 mjf hrp += ri->ri_stride;
942 1.56.18.2 mjf }
943 1.56.18.2 mjf
944 1.56.18.2 mjf for (cnt = full1; cnt; cnt--) {
945 1.56.18.2 mjf *(int32_t *)dp ^= ~0;
946 1.56.18.2 mjf dp += 4;
947 1.56.18.2 mjf if (ri->ri_hwbits) {
948 1.56.18.2 mjf *(int32_t *)hp ^= ~0;
949 1.56.18.2 mjf hp += 4;
950 1.56.18.2 mjf }
951 1.56.18.2 mjf }
952 1.56.18.2 mjf }
953 1.56.18.2 mjf } else {
954 1.56.18.2 mjf /* XXX this is stupid.. use masks instead */
955 1.56.18.2 mjf while (height--) {
956 1.56.18.2 mjf dp = rp;
957 1.56.18.2 mjf rp += ri->ri_stride;
958 1.56.18.2 mjf if (ri->ri_hwbits) {
959 1.56.18.2 mjf hp = hrp;
960 1.56.18.2 mjf hrp += ri->ri_stride;
961 1.56.18.2 mjf }
962 1.56.18.2 mjf
963 1.56.18.2 mjf if (slop1 & 1) {
964 1.56.18.2 mjf *dp++ ^= ~0;
965 1.56.18.2 mjf if (ri->ri_hwbits)
966 1.56.18.2 mjf *hp++ ^= ~0;
967 1.56.18.2 mjf }
968 1.56.18.2 mjf
969 1.56.18.2 mjf if (slop1 & 2) {
970 1.56.18.2 mjf *(int16_t *)dp ^= ~0;
971 1.56.18.2 mjf dp += 2;
972 1.56.18.2 mjf if (ri->ri_hwbits) {
973 1.56.18.2 mjf *(int16_t *)hp ^= ~0;
974 1.56.18.2 mjf hp += 2;
975 1.56.18.2 mjf }
976 1.56.18.2 mjf }
977 1.56.18.2 mjf
978 1.56.18.2 mjf for (cnt = full1; cnt; cnt--) {
979 1.56.18.2 mjf *(int32_t *)dp ^= ~0;
980 1.56.18.2 mjf dp += 4;
981 1.56.18.2 mjf if (ri->ri_hwbits) {
982 1.56.18.2 mjf *(int32_t *)hp ^= ~0;
983 1.56.18.2 mjf hp += 4;
984 1.56.18.2 mjf }
985 1.56.18.2 mjf }
986 1.56.18.2 mjf
987 1.56.18.2 mjf if (slop2 & 1) {
988 1.56.18.2 mjf *dp++ ^= ~0;
989 1.56.18.2 mjf if (ri->ri_hwbits)
990 1.56.18.2 mjf *hp++ ^= ~0;
991 1.56.18.2 mjf }
992 1.56.18.2 mjf
993 1.56.18.2 mjf if (slop2 & 2) {
994 1.56.18.2 mjf *(int16_t *)dp ^= ~0;
995 1.56.18.2 mjf if (ri->ri_hwbits)
996 1.56.18.2 mjf *(int16_t *)hp ^= ~0;
997 1.56.18.2 mjf }
998 1.56.18.2 mjf }
999 1.56.18.2 mjf }
1000 1.56.18.2 mjf }
1001 1.56.18.2 mjf
1002 1.56.18.2 mjf /*
1003 1.56.18.2 mjf * Erase columns.
1004 1.56.18.2 mjf */
1005 1.56.18.2 mjf void
1006 1.56.18.2 mjf rasops_erasecols(cookie, row, col, num, attr)
1007 1.56.18.2 mjf void *cookie;
1008 1.56.18.2 mjf int row, col, num;
1009 1.56.18.2 mjf long attr;
1010 1.56.18.2 mjf {
1011 1.56.18.2 mjf int n8, height, cnt, slop1, slop2, clr;
1012 1.56.18.2 mjf struct rasops_info *ri;
1013 1.56.18.2 mjf int32_t *rp, *dp, *hrp, *hp;
1014 1.56.18.2 mjf int i;
1015 1.56.18.2 mjf
1016 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
1017 1.56.18.2 mjf hrp = hp = NULL;
1018 1.56.18.2 mjf
1019 1.56.18.2 mjf #ifdef RASOPS_CLIPPING
1020 1.56.18.2 mjf if ((unsigned)row >= (unsigned)ri->ri_rows)
1021 1.56.18.2 mjf return;
1022 1.56.18.2 mjf
1023 1.56.18.2 mjf if (col < 0) {
1024 1.56.18.2 mjf num += col;
1025 1.56.18.2 mjf col = 0;
1026 1.56.18.2 mjf }
1027 1.56.18.2 mjf
1028 1.56.18.2 mjf if ((col + num) > ri->ri_cols)
1029 1.56.18.2 mjf num = ri->ri_cols - col;
1030 1.56.18.2 mjf
1031 1.56.18.2 mjf if (num <= 0)
1032 1.56.18.2 mjf return;
1033 1.56.18.2 mjf #endif
1034 1.56.18.2 mjf
1035 1.56.18.2 mjf num = num * ri->ri_xscale;
1036 1.56.18.2 mjf rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
1037 1.56.18.2 mjf if (ri->ri_hwbits)
1038 1.56.18.2 mjf hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
1039 1.56.18.2 mjf col*ri->ri_xscale);
1040 1.56.18.2 mjf height = ri->ri_font->fontheight;
1041 1.56.18.2 mjf clr = ri->ri_devcmap[(attr >> 16) & 0xf];
1042 1.56.18.2 mjf
1043 1.56.18.2 mjf /* Don't bother using the full loop for <= 32 pels */
1044 1.56.18.2 mjf if (num <= 32) {
1045 1.56.18.2 mjf if (((num | ri->ri_xscale) & 3) == 0) {
1046 1.56.18.2 mjf /* Word aligned blt */
1047 1.56.18.2 mjf num >>= 2;
1048 1.56.18.2 mjf
1049 1.56.18.2 mjf while (height--) {
1050 1.56.18.2 mjf dp = rp;
1051 1.56.18.2 mjf DELTA(rp, ri->ri_stride, int32_t *);
1052 1.56.18.2 mjf if (ri->ri_hwbits) {
1053 1.56.18.2 mjf hp = hrp;
1054 1.56.18.2 mjf DELTA(hrp, ri->ri_stride, int32_t *);
1055 1.56.18.2 mjf }
1056 1.56.18.2 mjf
1057 1.56.18.2 mjf for (cnt = num; cnt; cnt--) {
1058 1.56.18.2 mjf *dp++ = clr;
1059 1.56.18.2 mjf if (ri->ri_hwbits)
1060 1.56.18.2 mjf *hp++ = clr;
1061 1.56.18.2 mjf }
1062 1.56.18.2 mjf }
1063 1.56.18.2 mjf } else if (((num | ri->ri_xscale) & 1) == 0) {
1064 1.56.18.2 mjf /*
1065 1.56.18.2 mjf * Halfword aligned blt. This is needed so the
1066 1.56.18.2 mjf * 15/16 bit ops can use this function.
1067 1.56.18.2 mjf */
1068 1.56.18.2 mjf num >>= 1;
1069 1.56.18.2 mjf
1070 1.56.18.2 mjf while (height--) {
1071 1.56.18.2 mjf dp = rp;
1072 1.56.18.2 mjf DELTA(rp, ri->ri_stride, int32_t *);
1073 1.56.18.2 mjf if (ri->ri_hwbits) {
1074 1.56.18.2 mjf hp = hrp;
1075 1.56.18.2 mjf DELTA(hrp, ri->ri_stride, int32_t *);
1076 1.56.18.2 mjf }
1077 1.56.18.2 mjf
1078 1.56.18.2 mjf for (cnt = num; cnt; cnt--) {
1079 1.56.18.2 mjf *(int16_t *)dp = clr;
1080 1.56.18.2 mjf DELTA(dp, 2, int32_t *);
1081 1.56.18.2 mjf if (ri->ri_hwbits) {
1082 1.56.18.2 mjf *(int16_t *)hp = clr;
1083 1.56.18.2 mjf DELTA(hp, 2, int32_t *);
1084 1.56.18.2 mjf }
1085 1.56.18.2 mjf }
1086 1.56.18.2 mjf }
1087 1.56.18.2 mjf } else {
1088 1.56.18.2 mjf while (height--) {
1089 1.56.18.2 mjf dp = rp;
1090 1.56.18.2 mjf DELTA(rp, ri->ri_stride, int32_t *);
1091 1.56.18.2 mjf if (ri->ri_hwbits) {
1092 1.56.18.2 mjf hp = hrp;
1093 1.56.18.2 mjf DELTA(hrp, ri->ri_stride, int32_t *);
1094 1.56.18.2 mjf }
1095 1.56.18.2 mjf
1096 1.56.18.2 mjf for (cnt = num; cnt; cnt--) {
1097 1.56.18.2 mjf *(u_char *)dp = clr;
1098 1.56.18.2 mjf DELTA(dp, 1, int32_t *);
1099 1.56.18.2 mjf if (ri->ri_hwbits) {
1100 1.56.18.2 mjf *(u_char *)hp = clr;
1101 1.56.18.2 mjf DELTA(hp, 1, int32_t *);
1102 1.56.18.2 mjf }
1103 1.56.18.2 mjf }
1104 1.56.18.2 mjf }
1105 1.56.18.2 mjf }
1106 1.56.18.2 mjf
1107 1.56.18.2 mjf return;
1108 1.56.18.2 mjf }
1109 1.56.18.2 mjf
1110 1.56.18.2 mjf slop1 = (4 - ((long)rp & 3)) & 3;
1111 1.56.18.2 mjf slop2 = (num - slop1) & 3;
1112 1.56.18.2 mjf num -= slop1 + slop2;
1113 1.56.18.2 mjf n8 = num >> 5;
1114 1.56.18.2 mjf num = (num >> 2) & 7;
1115 1.56.18.2 mjf
1116 1.56.18.2 mjf while (height--) {
1117 1.56.18.2 mjf dp = rp;
1118 1.56.18.2 mjf DELTA(rp, ri->ri_stride, int32_t *);
1119 1.56.18.2 mjf if (ri->ri_hwbits) {
1120 1.56.18.2 mjf hp = hrp;
1121 1.56.18.2 mjf DELTA(hrp, ri->ri_stride, int32_t *);
1122 1.56.18.2 mjf }
1123 1.56.18.2 mjf
1124 1.56.18.2 mjf /* Align span to 4 bytes */
1125 1.56.18.2 mjf if (slop1 & 1) {
1126 1.56.18.2 mjf *(u_char *)dp = clr;
1127 1.56.18.2 mjf DELTA(dp, 1, int32_t *);
1128 1.56.18.2 mjf if (ri->ri_hwbits) {
1129 1.56.18.2 mjf *(u_char *)hp = clr;
1130 1.56.18.2 mjf DELTA(hp, 1, int32_t *);
1131 1.56.18.2 mjf }
1132 1.56.18.2 mjf }
1133 1.56.18.2 mjf
1134 1.56.18.2 mjf if (slop1 & 2) {
1135 1.56.18.2 mjf *(int16_t *)dp = clr;
1136 1.56.18.2 mjf DELTA(dp, 2, int32_t *);
1137 1.56.18.2 mjf if (ri->ri_hwbits) {
1138 1.56.18.2 mjf *(int16_t *)hp = clr;
1139 1.56.18.2 mjf DELTA(hp, 2, int32_t *);
1140 1.56.18.2 mjf }
1141 1.56.18.2 mjf }
1142 1.56.18.2 mjf
1143 1.56.18.2 mjf /* Write 32 bytes per loop */
1144 1.56.18.2 mjf for (cnt = n8; cnt; cnt--) {
1145 1.56.18.2 mjf for (i = 0; i < 8; i++) {
1146 1.56.18.2 mjf dp[i] = clr;
1147 1.56.18.2 mjf if (ri->ri_hwbits)
1148 1.56.18.2 mjf hp[i] = clr;
1149 1.56.18.2 mjf }
1150 1.56.18.2 mjf dp += 8;
1151 1.56.18.2 mjf if (ri->ri_hwbits)
1152 1.56.18.2 mjf hp += 8;
1153 1.56.18.2 mjf }
1154 1.56.18.2 mjf
1155 1.56.18.2 mjf /* Write 4 bytes per loop */
1156 1.56.18.2 mjf for (cnt = num; cnt; cnt--) {
1157 1.56.18.2 mjf *dp++ = clr;
1158 1.56.18.2 mjf if (ri->ri_hwbits)
1159 1.56.18.2 mjf *hp++ = clr;
1160 1.56.18.2 mjf }
1161 1.56.18.2 mjf
1162 1.56.18.2 mjf /* Write unaligned trailing slop */
1163 1.56.18.2 mjf if (slop2 & 1) {
1164 1.56.18.2 mjf *(u_char *)dp = clr;
1165 1.56.18.2 mjf DELTA(dp, 1, int32_t *);
1166 1.56.18.2 mjf if (ri->ri_hwbits) {
1167 1.56.18.2 mjf *(u_char *)hp = clr;
1168 1.56.18.2 mjf DELTA(hp, 1, int32_t *);
1169 1.56.18.2 mjf }
1170 1.56.18.2 mjf }
1171 1.56.18.2 mjf
1172 1.56.18.2 mjf if (slop2 & 2) {
1173 1.56.18.2 mjf *(int16_t *)dp = clr;
1174 1.56.18.2 mjf if (ri->ri_hwbits)
1175 1.56.18.2 mjf *(int16_t *)hp = clr;
1176 1.56.18.2 mjf }
1177 1.56.18.2 mjf }
1178 1.56.18.2 mjf }
1179 1.56.18.2 mjf
1180 1.56.18.2 mjf #if NRASOPS_ROTATION > 0
1181 1.56.18.2 mjf /*
1182 1.56.18.2 mjf * Quarter clockwise rotation routines (originally intended for the
1183 1.56.18.2 mjf * built-in Zaurus C3x00 display in 16bpp).
1184 1.56.18.2 mjf */
1185 1.56.18.2 mjf
1186 1.56.18.2 mjf #include <sys/malloc.h>
1187 1.56.18.2 mjf
1188 1.56.18.2 mjf static void
1189 1.56.18.2 mjf rasops_rotate_font(int *cookie)
1190 1.56.18.2 mjf {
1191 1.56.18.2 mjf struct rotatedfont *f;
1192 1.56.18.2 mjf int ncookie;
1193 1.56.18.2 mjf
1194 1.56.18.2 mjf SLIST_FOREACH(f, &rotatedfonts, rf_next) {
1195 1.56.18.2 mjf if (f->rf_cookie == *cookie) {
1196 1.56.18.2 mjf *cookie = f->rf_rotated;
1197 1.56.18.2 mjf return;
1198 1.56.18.2 mjf }
1199 1.56.18.2 mjf }
1200 1.56.18.2 mjf
1201 1.56.18.2 mjf /*
1202 1.56.18.2 mjf * We did not find a rotated version of this font. Ask the wsfont
1203 1.56.18.2 mjf * code to compute one for us.
1204 1.56.18.2 mjf */
1205 1.56.18.2 mjf
1206 1.56.18.2 mjf f = malloc(sizeof(struct rotatedfont), M_DEVBUF, M_WAITOK);
1207 1.56.18.2 mjf if (f == NULL)
1208 1.56.18.2 mjf return;
1209 1.56.18.2 mjf
1210 1.56.18.2 mjf if ((ncookie = wsfont_rotate(*cookie)) == -1)
1211 1.56.18.2 mjf return;
1212 1.56.18.2 mjf
1213 1.56.18.2 mjf f->rf_cookie = *cookie;
1214 1.56.18.2 mjf f->rf_rotated = ncookie;
1215 1.56.18.2 mjf SLIST_INSERT_HEAD(&rotatedfonts, f, rf_next);
1216 1.56.18.2 mjf
1217 1.56.18.2 mjf *cookie = ncookie;
1218 1.56.18.2 mjf }
1219 1.56.18.2 mjf
1220 1.56.18.2 mjf static void
1221 1.56.18.2 mjf rasops_copychar(cookie, srcrow, dstrow, srccol, dstcol)
1222 1.56.18.2 mjf void *cookie;
1223 1.56.18.2 mjf int srcrow, dstrow, srccol, dstcol;
1224 1.56.18.2 mjf {
1225 1.56.18.2 mjf struct rasops_info *ri;
1226 1.56.18.2 mjf u_char *sp, *dp;
1227 1.56.18.2 mjf int height;
1228 1.56.18.2 mjf int r_srcrow, r_dstrow, r_srccol, r_dstcol;
1229 1.56.18.2 mjf
1230 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
1231 1.56.18.2 mjf
1232 1.56.18.2 mjf r_srcrow = srccol;
1233 1.56.18.2 mjf r_dstrow = dstcol;
1234 1.56.18.2 mjf r_srccol = ri->ri_rows - srcrow - 1;
1235 1.56.18.2 mjf r_dstcol = ri->ri_rows - dstrow - 1;
1236 1.56.18.2 mjf
1237 1.56.18.2 mjf r_srcrow *= ri->ri_yscale;
1238 1.56.18.2 mjf r_dstrow *= ri->ri_yscale;
1239 1.56.18.2 mjf height = ri->ri_font->fontheight;
1240 1.56.18.2 mjf
1241 1.56.18.2 mjf sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
1242 1.56.18.2 mjf dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
1243 1.56.18.2 mjf
1244 1.56.18.2 mjf while (height--) {
1245 1.56.18.2 mjf memmove(dp, sp, ri->ri_xscale);
1246 1.56.18.2 mjf dp += ri->ri_stride;
1247 1.56.18.2 mjf sp += ri->ri_stride;
1248 1.56.18.2 mjf }
1249 1.56.18.2 mjf }
1250 1.56.18.2 mjf
1251 1.56.18.2 mjf static void
1252 1.56.18.2 mjf rasops_putchar_rotated(cookie, row, col, uc, attr)
1253 1.56.18.2 mjf void *cookie;
1254 1.56.18.2 mjf int row, col;
1255 1.56.18.2 mjf u_int uc;
1256 1.56.18.2 mjf long attr;
1257 1.56.18.2 mjf {
1258 1.56.18.2 mjf struct rasops_info *ri;
1259 1.56.18.2 mjf u_char *rp;
1260 1.56.18.2 mjf int height;
1261 1.56.18.2 mjf
1262 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
1263 1.56.18.2 mjf
1264 1.56.18.2 mjf if (__predict_false((unsigned int)row > ri->ri_rows ||
1265 1.56.18.2 mjf (unsigned int)col > ri->ri_cols))
1266 1.56.18.2 mjf return;
1267 1.56.18.2 mjf
1268 1.56.18.2 mjf /* Avoid underflow */
1269 1.56.18.2 mjf if ((ri->ri_rows - row - 1) < 0)
1270 1.56.18.2 mjf return;
1271 1.56.18.2 mjf
1272 1.56.18.2 mjf /* Do rotated char sans (side)underline */
1273 1.56.18.2 mjf ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
1274 1.56.18.2 mjf attr & ~1);
1275 1.56.18.2 mjf
1276 1.56.18.2 mjf /* Do rotated underline */
1277 1.56.18.2 mjf rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) *
1278 1.56.18.2 mjf ri->ri_xscale;
1279 1.56.18.2 mjf height = ri->ri_font->fontheight;
1280 1.56.18.2 mjf
1281 1.56.18.2 mjf /* XXX this assumes 16-bit color depth */
1282 1.56.18.2 mjf if ((attr & 1) != 0) {
1283 1.56.18.2 mjf int16_t c = (int16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
1284 1.56.18.2 mjf
1285 1.56.18.2 mjf while (height--) {
1286 1.56.18.2 mjf *(int16_t *)rp = c;
1287 1.56.18.2 mjf rp += ri->ri_stride;
1288 1.56.18.2 mjf }
1289 1.56.18.2 mjf }
1290 1.56.18.2 mjf }
1291 1.56.18.2 mjf
1292 1.56.18.2 mjf static void
1293 1.56.18.2 mjf rasops_erasecols_rotated(cookie, row, col, num, attr)
1294 1.56.18.2 mjf void *cookie;
1295 1.56.18.2 mjf int row, col, num;
1296 1.56.18.2 mjf long attr;
1297 1.56.18.2 mjf {
1298 1.56.18.2 mjf struct rasops_info *ri;
1299 1.56.18.2 mjf int i;
1300 1.56.18.2 mjf
1301 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
1302 1.56.18.2 mjf
1303 1.56.18.2 mjf for (i = col; i < col + num; i++)
1304 1.56.18.2 mjf ri->ri_ops.putchar(cookie, row, i, ' ', attr);
1305 1.56.18.2 mjf }
1306 1.56.18.2 mjf
1307 1.56.18.2 mjf /* XXX: these could likely be optimised somewhat. */
1308 1.56.18.2 mjf static void
1309 1.56.18.2 mjf rasops_copyrows_rotated(cookie, src, dst, num)
1310 1.56.18.2 mjf void *cookie;
1311 1.56.18.2 mjf int src, dst, num;
1312 1.56.18.2 mjf {
1313 1.56.18.2 mjf struct rasops_info *ri = (struct rasops_info *)cookie;
1314 1.56.18.2 mjf int col, roff;
1315 1.56.18.2 mjf
1316 1.56.18.2 mjf if (src > dst)
1317 1.56.18.2 mjf for (roff = 0; roff < num; roff++)
1318 1.56.18.2 mjf for (col = 0; col < ri->ri_cols; col++)
1319 1.56.18.2 mjf rasops_copychar(cookie, src + roff, dst + roff,
1320 1.56.18.2 mjf col, col);
1321 1.56.18.2 mjf else
1322 1.56.18.2 mjf for (roff = num - 1; roff >= 0; roff--)
1323 1.56.18.2 mjf for (col = 0; col < ri->ri_cols; col++)
1324 1.56.18.2 mjf rasops_copychar(cookie, src + roff, dst + roff,
1325 1.56.18.2 mjf col, col);
1326 1.56.18.2 mjf }
1327 1.56.18.2 mjf
1328 1.56.18.2 mjf static void
1329 1.56.18.2 mjf rasops_copycols_rotated(cookie, row, src, dst, num)
1330 1.56.18.2 mjf void *cookie;
1331 1.56.18.2 mjf int row, src, dst, num;
1332 1.56.18.2 mjf {
1333 1.56.18.2 mjf int coff;
1334 1.56.18.2 mjf
1335 1.56.18.2 mjf if (src > dst)
1336 1.56.18.2 mjf for (coff = 0; coff < num; coff++)
1337 1.56.18.2 mjf rasops_copychar(cookie, row, row, src + coff, dst + coff);
1338 1.56.18.2 mjf else
1339 1.56.18.2 mjf for (coff = num - 1; coff >= 0; coff--)
1340 1.56.18.2 mjf rasops_copychar(cookie, row, row, src + coff, dst + coff);
1341 1.56.18.2 mjf }
1342 1.56.18.2 mjf
1343 1.56.18.2 mjf static void
1344 1.56.18.2 mjf rasops_eraserows_rotated(cookie, row, num, attr)
1345 1.56.18.2 mjf void *cookie;
1346 1.56.18.2 mjf int row, num;
1347 1.56.18.2 mjf long attr;
1348 1.56.18.2 mjf {
1349 1.56.18.2 mjf struct rasops_info *ri;
1350 1.56.18.2 mjf int col, rn;
1351 1.56.18.2 mjf
1352 1.56.18.2 mjf ri = (struct rasops_info *)cookie;
1353 1.56.18.2 mjf
1354 1.56.18.2 mjf for (rn = row; rn < row + num; rn++)
1355 1.56.18.2 mjf for (col = 0; col < ri->ri_cols; col++)
1356 1.56.18.2 mjf ri->ri_ops.putchar(cookie, rn, col, ' ', attr);
1357 1.56.18.2 mjf }
1358 1.56.18.2 mjf #endif /* NRASOPS_ROTATION */
1359