rasops2.c revision 1.16
1/* $NetBSD: rasops2.c,v 1.16 2010/05/04 12:36:37 nonaka Exp $ */ 2 3/*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.16 2010/05/04 12:36:37 nonaka Exp $"); 34 35#include "opt_rasops.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/time.h> 40#include <machine/endian.h> 41 42#include <dev/wscons/wsdisplayvar.h> 43#include <dev/wscons/wsconsio.h> 44#include <dev/rasops/rasops.h> 45#include <dev/rasops/rasops_masks.h> 46 47static void rasops2_copycols(void *, int, int, int, int); 48static void rasops2_erasecols(void *, int, int, int, long); 49static void rasops2_do_cursor(struct rasops_info *); 50static void rasops2_putchar(void *, int, int col, u_int, long); 51#ifndef RASOPS_SMALL 52static void rasops2_putchar8(void *, int, int col, u_int, long); 53static void rasops2_putchar12(void *, int, int col, u_int, long); 54static void rasops2_putchar16(void *, int, int col, u_int, long); 55static void rasops2_makestamp(struct rasops_info *, long); 56 57/* 58 * 4x1 stamp for optimized character blitting 59 */ 60static int8_t stamp[16]; 61static long stamp_attr; 62static int stamp_mutex; /* XXX see note in README */ 63#endif 64 65/* 66 * Initialize rasops_info struct for this colordepth. 67 */ 68void 69rasops2_init(struct rasops_info *ri) 70{ 71 72 switch (ri->ri_font->fontwidth) { 73#ifndef RASOPS_SMALL 74 case 8: 75 ri->ri_ops.putchar = rasops2_putchar8; 76 break; 77 case 12: 78 ri->ri_ops.putchar = rasops2_putchar12; 79 break; 80 case 16: 81 ri->ri_ops.putchar = rasops2_putchar16; 82 break; 83#endif /* !RASOPS_SMALL */ 84 default: 85 panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!"); 86 ri->ri_ops.putchar = rasops2_putchar; 87 break; 88 } 89 90 if ((ri->ri_font->fontwidth & 3) != 0) { 91 ri->ri_ops.erasecols = rasops2_erasecols; 92 ri->ri_ops.copycols = rasops2_copycols; 93 ri->ri_do_cursor = rasops2_do_cursor; 94 } 95} 96 97#ifdef notyet 98/* 99 * Paint a single character. This is the generic version, this is ugly. 100 */ 101static void 102rasops2_putchar(void *cookie, int row, int col, u_int uc, long attr) 103{ 104 int height, width, fs, rs, fb, bg, fg, lmask, rmask; 105 struct rasops_info *ri = (struct rasops_info *)cookie; 106 struct wsdisplay_font *font = PICK_FONT(ri, uc); 107 int32_t *rp; 108 u_char *fr; 109 110 ri = (struct rasops_info *)cookie; 111 112#ifdef RASOPS_CLIPPING 113 /* Catches 'row < 0' case too */ 114 if ((unsigned)row >= (unsigned)ri->ri_rows) 115 return; 116 117 if ((unsigned)col >= (unsigned)ri->ri_cols) 118 return; 119#endif 120 121 width = font->fontwidth << 1; 122 height = font->fontheight; 123 col *= width; 124 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 125 col = col & 31; 126 rs = ri->ri_stride; 127 128 bg = ri->ri_devcmap[(attr >> 16) & 0xf]; 129 fg = ri->ri_devcmap[(attr >> 24) & 0xf]; 130 131 /* If fg and bg match this becomes a space character */ 132 if (fg == bg || uc == ' ') { 133 uc = (u_int)-1; 134 fr = 0; /* shutup gcc */ 135 fs = 0; /* shutup gcc */ 136 } else { 137 uc -= font->firstchar; 138 fr = (u_char *)font->data + uc * ri->ri_fontscale; 139 fs = font->stride; 140 } 141 142 /* Single word, one mask */ 143 if ((col + width) <= 32) { 144 rmask = rasops_pmask[col][width]; 145 lmask = ~rmask; 146 147 if (uc == (u_int)-1) { 148 bg &= rmask; 149 150 while (height--) { 151 *rp = (*rp & lmask) | bg; 152 DELTA(rp, rs, int32_t *); 153 } 154 } else { 155 while (height--) { 156 /* get bits, mask */ 157 /* compose sl */ 158 /* mask sl */ 159 /* put word */ 160 } 161 } 162 163 /* Do underline */ 164 if (attr & 1) { 165 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 166 *rp = (*rp & lmask) | (fg & rmask); 167 } 168 } else { 169 lmask = ~rasops_lmask[col]; 170 rmask = ~rasops_rmask[(col + width) & 31]; 171 172 if (uc == (u_int)-1) { 173 bg = bg & ~lmask; 174 width = bg & ~rmask; 175 176 while (height--) { 177 rp[0] = (rp[0] & lmask) | bg; 178 rp[1] = (rp[1] & rmask) | width; 179 DELTA(rp, rs, int32_t *); 180 } 181 } else { 182 width = 32 - col; 183 184 /* NOT fontbits if bg is white */ 185 while (height--) { 186 fb = ~(fr[3] | (fr[2] << 8) | 187 (fr[1] << 16) | (fr[0] << 24)); 188 189 rp[0] = (rp[0] & lmask) 190 | MBE((u_int)fb >> col); 191 192 rp[1] = (rp[1] & rmask) 193 | (MBE((u_int)fb << width) & ~rmask); 194 195 fr += fs; 196 DELTA(rp, rs, int32_t *); 197 } 198 } 199 200 /* Do underline */ 201 if (attr & 1) { 202 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 203 rp[0] = (rp[0] & lmask) | (fg & ~lmask); 204 rp[1] = (rp[1] & rmask) | (fg & ~rmask); 205 } 206 } 207} 208#endif 209 210/* 211 * Put a single character. This is the generic version. 212 */ 213static void 214rasops2_putchar(void *cookie, int row, int col, u_int uc, long attr) 215{ 216 217 /* XXX punt */ 218} 219 220#ifndef RASOPS_SMALL 221/* 222 * Recompute the blitting stamp. 223 */ 224static void 225rasops2_makestamp(struct rasops_info *ri, long attr) 226{ 227 int i, fg, bg; 228 229 fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 3; 230 bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 3; 231 stamp_attr = attr; 232 233 for (i = 0; i < 16; i++) { 234 stamp[i] = (i & 1 ? fg : bg); 235 stamp[i] |= (i & 2 ? fg : bg) << 2; 236 stamp[i] |= (i & 4 ? fg : bg) << 4; 237 stamp[i] |= (i & 8 ? fg : bg) << 6; 238 } 239} 240 241/* 242 * Put a single character. This is for 8-pixel wide fonts. 243 */ 244static void 245rasops2_putchar8(void *cookie, int row, int col, u_int uc, long attr) 246{ 247 struct rasops_info *ri = (struct rasops_info *)cookie; 248 struct wsdisplay_font *font = PICK_FONT(ri, uc); 249 int height, fs, rs; 250 u_char *fr, *rp; 251 252 /* Can't risk remaking the stamp if it's already in use */ 253 if (stamp_mutex++) { 254 stamp_mutex--; 255 rasops2_putchar(cookie, row, col, uc, attr); 256 return; 257 } 258 259 ri = (struct rasops_info *)cookie; 260 261#ifdef RASOPS_CLIPPING 262 /* Catches 'row < 0' case too */ 263 if ((unsigned)row >= (unsigned)ri->ri_rows) { 264 stamp_mutex--; 265 return; 266 } 267 268 if ((unsigned)col >= (unsigned)ri->ri_cols) { 269 stamp_mutex--; 270 return; 271 } 272#endif 273 274 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 275 height = font->fontheight; 276 rs = ri->ri_stride; 277 278 /* Recompute stamp? */ 279 if (attr != stamp_attr) 280 rasops2_makestamp(ri, attr); 281 282 if (uc == ' ') { 283 int8_t c = stamp[0]; 284 while (height--) { 285 *(int16_t *)rp = c; 286 rp += rs; 287 } 288 } else { 289 uc -= font->firstchar; 290 fr = (u_char *)font->data + uc * ri->ri_fontscale; 291 fs = font->stride; 292 293 while (height--) { 294 rp[0] = stamp[(*fr >> 4) & 0xf]; 295 rp[1] = stamp[*fr & 0xf]; 296 fr += fs; 297 rp += rs; 298 } 299 } 300 301 /* Do underline */ 302 if ((attr & 1) != 0) 303 *(int16_t *)(rp - (ri->ri_stride << 1)) = stamp[15]; 304 305 stamp_mutex--; 306} 307 308/* 309 * Put a single character. This is for 12-pixel wide fonts. 310 */ 311static void 312rasops2_putchar12(void *cookie, int row, int col, u_int uc, long attr) 313{ 314 struct rasops_info *ri = (struct rasops_info *)cookie; 315 struct wsdisplay_font *font = PICK_FONT(ri, uc); 316 int height, fs, rs; 317 u_char *fr, *rp; 318 319 /* Can't risk remaking the stamp if it's already in use */ 320 if (stamp_mutex++) { 321 stamp_mutex--; 322 rasops2_putchar(cookie, row, col, uc, attr); 323 return; 324 } 325 326 ri = (struct rasops_info *)cookie; 327 328#ifdef RASOPS_CLIPPING 329 /* Catches 'row < 0' case too */ 330 if ((unsigned)row >= (unsigned)ri->ri_rows) { 331 stamp_mutex--; 332 return; 333 } 334 335 if ((unsigned)col >= (unsigned)ri->ri_cols) { 336 stamp_mutex--; 337 return; 338 } 339#endif 340 341 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 342 height = font->fontheight; 343 rs = ri->ri_stride; 344 345 /* Recompute stamp? */ 346 if (attr != stamp_attr) 347 rasops2_makestamp(ri, attr); 348 349 if (uc == ' ') { 350 int8_t c = stamp[0]; 351 while (height--) { 352 rp[0] = rp[1] = rp[2] = c; 353 rp += rs; 354 } 355 } else { 356 uc -= font->firstchar; 357 fr = (u_char *)font->data + uc * ri->ri_fontscale; 358 fs = font->stride; 359 360 while (height--) { 361 rp[0] = stamp[(fr[0] >> 4) & 0xf]; 362 rp[1] = stamp[fr[0] & 0xf]; 363 rp[2] = stamp[(fr[1] >> 4) & 0xf]; 364 fr += fs; 365 rp += rs; 366 } 367 } 368 369 /* Do underline */ 370 if ((attr & 1) != 0) { 371 rp -= ri->ri_stride << 1; 372 rp[0] = rp[1] = rp[2] = stamp[15]; 373 } 374 375 stamp_mutex--; 376} 377 378/* 379 * Put a single character. This is for 16-pixel wide fonts. 380 */ 381static void 382rasops2_putchar16(void *cookie, int row, int col, u_int uc, long attr) 383{ 384 struct rasops_info *ri = (struct rasops_info *)cookie; 385 struct wsdisplay_font *font = PICK_FONT(ri, uc); 386 int height, fs, rs; 387 u_char *fr, *rp; 388 389 /* Can't risk remaking the stamp if it's already in use */ 390 if (stamp_mutex++) { 391 stamp_mutex--; 392 rasops2_putchar(cookie, row, col, uc, attr); 393 return; 394 } 395 396 ri = (struct rasops_info *)cookie; 397 398#ifdef RASOPS_CLIPPING 399 /* Catches 'row < 0' case too */ 400 if ((unsigned)row >= (unsigned)ri->ri_rows) { 401 stamp_mutex--; 402 return; 403 } 404 405 if ((unsigned)col >= (unsigned)ri->ri_cols) { 406 stamp_mutex--; 407 return; 408 } 409#endif 410 411 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 412 height = font->fontheight; 413 rs = ri->ri_stride; 414 415 /* Recompute stamp? */ 416 if (attr != stamp_attr) 417 rasops2_makestamp(ri, attr); 418 419 if (uc == ' ') { 420 int8_t c = stamp[0]; 421 while (height--) { 422 *(int32_t *)rp = c; 423 rp += rs; 424 } 425 } else { 426 uc -= font->firstchar; 427 fr = (u_char *)font->data + uc * ri->ri_fontscale; 428 fs = font->stride; 429 430 while (height--) { 431 rp[0] = stamp[(fr[0] >> 4) & 0xf]; 432 rp[1] = stamp[fr[0] & 0xf]; 433 rp[2] = stamp[(fr[1] >> 4) & 0xf]; 434 rp[3] = stamp[fr[1] & 0xf]; 435 fr += fs; 436 rp += rs; 437 } 438 } 439 440 /* Do underline */ 441 if ((attr & 1) != 0) 442 *(int32_t *)(rp - (ri->ri_stride << 1)) = stamp[15]; 443 444 stamp_mutex--; 445} 446#endif /* !RASOPS_SMALL */ 447 448/* 449 * Grab routines common to depths where (bpp < 8) 450 */ 451#define NAME(ident) rasops2_##ident 452#define PIXEL_SHIFT 1 453 454#include <dev/rasops/rasops_bitops.h> 455