rasops2.c revision 1.13
1/* $NetBSD: rasops2.c,v 1.13 2009/03/14 15:36:20 dsl 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.13 2009/03/14 15:36:20 dsl 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(cookie, row, col, uc, attr) 103 void *cookie; 104 int row, col; 105 u_int uc; 106 long attr; 107{ 108 int height, width, fs, rs, fb, bg, fg, lmask, rmask; 109 struct rasops_info *ri; 110 int32_t *rp; 111 u_char *fr; 112 113 ri = (struct rasops_info *)cookie; 114 115#ifdef RASOPS_CLIPPING 116 /* Catches 'row < 0' case too */ 117 if ((unsigned)row >= (unsigned)ri->ri_rows) 118 return; 119 120 if ((unsigned)col >= (unsigned)ri->ri_cols) 121 return; 122#endif 123 124 width = ri->ri_font->fontwidth << 1; 125 height = ri->ri_font->fontheight; 126 col *= width; 127 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 128 col = col & 31; 129 rs = ri->ri_stride; 130 131 bg = ri->ri_devcmap[(attr >> 16) & 0xf]; 132 fg = ri->ri_devcmap[(attr >> 24) & 0xf]; 133 134 /* If fg and bg match this becomes a space character */ 135 if (fg == bg || uc == ' ') { 136 uc = (u_int)-1; 137 fr = 0; /* shutup gcc */ 138 fs = 0; /* shutup gcc */ 139 } else { 140 uc -= ri->ri_font->firstchar; 141 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 142 fs = ri->ri_font->stride; 143 } 144 145 /* Single word, one mask */ 146 if ((col + width) <= 32) { 147 rmask = rasops_pmask[col][width]; 148 lmask = ~rmask; 149 150 if (uc == (u_int)-1) { 151 bg &= rmask; 152 153 while (height--) { 154 *rp = (*rp & lmask) | bg; 155 DELTA(rp, rs, int32_t *); 156 } 157 } else { 158 while (height--) { 159 /* get bits, mask */ 160 /* compose sl */ 161 /* mask sl */ 162 /* put word */ 163 } 164 } 165 166 /* Do underline */ 167 if (attr & 1) { 168 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 169 *rp = (*rp & lmask) | (fg & rmask); 170 } 171 } else { 172 lmask = ~rasops_lmask[col]; 173 rmask = ~rasops_rmask[(col + width) & 31]; 174 175 if (uc == (u_int)-1) { 176 bg = bg & ~lmask; 177 width = bg & ~rmask; 178 179 while (height--) { 180 rp[0] = (rp[0] & lmask) | bg; 181 rp[1] = (rp[1] & rmask) | width; 182 DELTA(rp, rs, int32_t *); 183 } 184 } else { 185 width = 32 - col; 186 187 /* NOT fontbits if bg is white */ 188 while (height--) { 189 fb = ~(fr[3] | (fr[2] << 8) | 190 (fr[1] << 16) | (fr[0] << 24)); 191 192 rp[0] = (rp[0] & lmask) 193 | MBE((u_int)fb >> col); 194 195 rp[1] = (rp[1] & rmask) 196 | (MBE((u_int)fb << width) & ~rmask); 197 198 fr += fs; 199 DELTA(rp, rs, int32_t *); 200 } 201 } 202 203 /* Do underline */ 204 if (attr & 1) { 205 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 206 rp[0] = (rp[0] & lmask) | (fg & ~lmask); 207 rp[1] = (rp[1] & rmask) | (fg & ~rmask); 208 } 209 } 210} 211#endif 212 213/* 214 * Put a single character. This is the generic version. 215 */ 216static void 217rasops2_putchar(cookie, row, col, uc, attr) 218 void *cookie; 219 int row, col; 220 u_int uc; 221 long attr; 222{ 223 224 /* XXX punt */ 225} 226 227#ifndef RASOPS_SMALL 228/* 229 * Recompute the blitting stamp. 230 */ 231static void 232rasops2_makestamp(struct rasops_info *ri, long attr) 233{ 234 int i, fg, bg; 235 236 fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 3; 237 bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 3; 238 stamp_attr = attr; 239 240 for (i = 0; i < 16; i++) { 241 stamp[i] = (i & 1 ? fg : bg); 242 stamp[i] |= (i & 2 ? fg : bg) << 2; 243 stamp[i] |= (i & 4 ? fg : bg) << 4; 244 stamp[i] |= (i & 8 ? fg : bg) << 6; 245 } 246} 247 248/* 249 * Put a single character. This is for 8-pixel wide fonts. 250 */ 251static void 252rasops2_putchar8(cookie, row, col, uc, attr) 253 void *cookie; 254 int row, col; 255 u_int uc; 256 long attr; 257{ 258 struct rasops_info *ri; 259 int height, fs, rs; 260 u_char *fr, *rp; 261 262 /* Can't risk remaking the stamp if it's already in use */ 263 if (stamp_mutex++) { 264 stamp_mutex--; 265 rasops2_putchar(cookie, row, col, uc, attr); 266 return; 267 } 268 269 ri = (struct rasops_info *)cookie; 270 271#ifdef RASOPS_CLIPPING 272 /* Catches 'row < 0' case too */ 273 if ((unsigned)row >= (unsigned)ri->ri_rows) { 274 stamp_mutex--; 275 return; 276 } 277 278 if ((unsigned)col >= (unsigned)ri->ri_cols) { 279 stamp_mutex--; 280 return; 281 } 282#endif 283 284 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 285 height = ri->ri_font->fontheight; 286 rs = ri->ri_stride; 287 288 /* Recompute stamp? */ 289 if (attr != stamp_attr) 290 rasops2_makestamp(ri, attr); 291 292 if (uc == ' ') { 293 int8_t c = stamp[0]; 294 while (height--) { 295 *(int16_t *)rp = c; 296 rp += rs; 297 } 298 } else { 299 uc -= ri->ri_font->firstchar; 300 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 301 fs = ri->ri_font->stride; 302 303 while (height--) { 304 rp[0] = stamp[(*fr >> 4) & 0xf]; 305 rp[1] = stamp[*fr & 0xf]; 306 fr += fs; 307 rp += rs; 308 } 309 } 310 311 /* Do underline */ 312 if ((attr & 1) != 0) 313 *(int16_t *)(rp - (ri->ri_stride << 1)) = stamp[15]; 314 315 stamp_mutex--; 316} 317 318/* 319 * Put a single character. This is for 12-pixel wide fonts. 320 */ 321static void 322rasops2_putchar12(cookie, row, col, uc, attr) 323 void *cookie; 324 int row, col; 325 u_int uc; 326 long attr; 327{ 328 struct rasops_info *ri; 329 int height, fs, rs; 330 u_char *fr, *rp; 331 332 /* Can't risk remaking the stamp if it's already in use */ 333 if (stamp_mutex++) { 334 stamp_mutex--; 335 rasops2_putchar(cookie, row, col, uc, attr); 336 return; 337 } 338 339 ri = (struct rasops_info *)cookie; 340 341#ifdef RASOPS_CLIPPING 342 /* Catches 'row < 0' case too */ 343 if ((unsigned)row >= (unsigned)ri->ri_rows) { 344 stamp_mutex--; 345 return; 346 } 347 348 if ((unsigned)col >= (unsigned)ri->ri_cols) { 349 stamp_mutex--; 350 return; 351 } 352#endif 353 354 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 355 height = ri->ri_font->fontheight; 356 rs = ri->ri_stride; 357 358 /* Recompute stamp? */ 359 if (attr != stamp_attr) 360 rasops2_makestamp(ri, attr); 361 362 if (uc == ' ') { 363 int8_t c = stamp[0]; 364 while (height--) { 365 rp[0] = rp[1] = rp[2] = c; 366 rp += rs; 367 } 368 } else { 369 uc -= ri->ri_font->firstchar; 370 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 371 fs = ri->ri_font->stride; 372 373 while (height--) { 374 rp[0] = stamp[(fr[0] >> 4) & 0xf]; 375 rp[1] = stamp[fr[0] & 0xf]; 376 rp[2] = stamp[(fr[1] >> 4) & 0xf]; 377 fr += fs; 378 rp += rs; 379 } 380 } 381 382 /* Do underline */ 383 if ((attr & 1) != 0) { 384 rp -= ri->ri_stride << 1; 385 rp[0] = rp[1] = rp[2] = stamp[15]; 386 } 387 388 stamp_mutex--; 389} 390 391/* 392 * Put a single character. This is for 16-pixel wide fonts. 393 */ 394static void 395rasops2_putchar16(cookie, row, col, uc, attr) 396 void *cookie; 397 int row, col; 398 u_int uc; 399 long attr; 400{ 401 struct rasops_info *ri; 402 int height, fs, rs; 403 u_char *fr, *rp; 404 405 /* Can't risk remaking the stamp if it's already in use */ 406 if (stamp_mutex++) { 407 stamp_mutex--; 408 rasops2_putchar(cookie, row, col, uc, attr); 409 return; 410 } 411 412 ri = (struct rasops_info *)cookie; 413 414#ifdef RASOPS_CLIPPING 415 /* Catches 'row < 0' case too */ 416 if ((unsigned)row >= (unsigned)ri->ri_rows) { 417 stamp_mutex--; 418 return; 419 } 420 421 if ((unsigned)col >= (unsigned)ri->ri_cols) { 422 stamp_mutex--; 423 return; 424 } 425#endif 426 427 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 428 height = ri->ri_font->fontheight; 429 rs = ri->ri_stride; 430 431 /* Recompute stamp? */ 432 if (attr != stamp_attr) 433 rasops2_makestamp(ri, attr); 434 435 if (uc == ' ') { 436 int8_t c = stamp[0]; 437 while (height--) { 438 *(int32_t *)rp = c; 439 rp += rs; 440 } 441 } else { 442 uc -= ri->ri_font->firstchar; 443 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 444 fs = ri->ri_font->stride; 445 446 while (height--) { 447 rp[0] = stamp[(fr[0] >> 4) & 0xf]; 448 rp[1] = stamp[fr[0] & 0xf]; 449 rp[2] = stamp[(fr[1] >> 4) & 0xf]; 450 rp[3] = stamp[fr[1] & 0xf]; 451 fr += fs; 452 rp += rs; 453 } 454 } 455 456 /* Do underline */ 457 if ((attr & 1) != 0) 458 *(int32_t *)(rp - (ri->ri_stride << 1)) = stamp[15]; 459 460 stamp_mutex--; 461} 462#endif /* !RASOPS_SMALL */ 463 464/* 465 * Grab routines common to depths where (bpp < 8) 466 */ 467#define NAME(ident) rasops2_##ident 468#define PIXEL_SHIFT 1 469 470#include <dev/rasops/rasops_bitops.h> 471